donnykurnia

Untitled

Jan 29th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.28 KB | None | 0 0
  1. <?php
  2. // controler
  3.  
  4. public function saveTrans1(){
  5.     $path   = './xls223/';
  6.     $config ['file_name']='data.xlsx';
  7.     $config['upload_path']=$path;
  8.  
  9.     $config['allowed_types']='xlsx';
  10.     $config['max_size']='200000';
  11.     $config['max_width']='202400';
  12.     $config['max_height']='146800';
  13.     $config['overwrite']=true;
  14.  
  15.     $this->load->library('upload',$config);
  16.     $this->upload->initialize($config);
  17.     if ($config) {
  18.         $this->load->library('form_validation');
  19.  
  20.         $this->form_validation->set_rules('product_id', 'Product', 'trim|required|xss_clean');
  21.         $this->form_validation->set_rules('fullname[]', 'Name', 'trim|required|xss_clean');
  22.         $this->form_validation->set_rules('email[]', 'Email', 'trim|required|xss_clean');
  23.  
  24.         if($this->input->post('status')==0) {
  25.             $this->form_validation->set_rules('company[]', 'Company', 'trim|required|xss_clean');
  26.             $this->form_validation->set_rules('jobtitle[]', 'Job Title', 'trim|required|xss_clean');
  27.             $this->form_validation->set_rules('industry[]', 'Industry', 'trim|required|xss_clean');
  28.  
  29.         }
  30.         if ($this->form_validation->run() == FALSE) {
  31.             $message=$this->v2->alert('warning',validation_errors());
  32.             $response=array('error',$message);
  33.         } else {
  34.             $product = $this->input->post('product');
  35.             $product_id = $this->input->post('product_id');
  36.             $salutation = $this->input->post('salutation');
  37.             $fullname = $this->input->post('fullname');
  38.             $email = $this->input->post('email');  
  39.             $company = $this->input->post('company');
  40.             $jobtitle = $this->input->post('jobtitle');
  41.             $address = $this->input->post('address');
  42.             $phonenumber = $this->input->post('phonenumber');
  43.             $personal = $this->input->post('personal');
  44.             $industry = $this->input->post('industry');
  45.  
  46.             $y = count($salutation);
  47.             $nom=0;
  48.             $nom++;
  49.             for ($i = 0; $i < $y; $i++) {
  50.  
  51.  
  52.  
  53.                 $postData['salutation'] = $salutation[$i];
  54.                 $postData['fullname'] =    $fullname[$i];
  55.                 $postData['email'] = $email[$i];
  56.                 $postData['company'] = $company[$i];
  57.  
  58.                 $postData['jobtitle'] = $jobtitle[$i];
  59.                 $postData['address'] = $address[$i];
  60.                 $postData['phonenumber'] = $phonenumber[$i];
  61.                 $postData['personal'] =    $personal[$i];
  62.                 $postData['industry'] =    $industry[$i];  
  63.  
  64.                 $postData['product_name']=$product;
  65.                 $postData['product_id']=$product_id;
  66.                 $postData['password']=$this->randomKey(6);  
  67.                 print ($i);
  68.                 $this->v2->inject_transaction_member($postData);
  69.             }
  70.         }
  71.  
  72.         $message=$this->v2->alert('success','Success input data');
  73.         $response=array('success',$message);
  74.  
  75.         // $message=json_encode($_POST);
  76.         echo json_encode($response);
  77.     } else {
  78.         redirect('admin/Trans/detail/');
  79.     }
  80. }
  81. ?>
  82. <!-- view -->
  83. <div class="content-wrapper" id="detailOfflineTrans">
  84.     <section class="content-header">
  85.         <Center> <h1>Add Transaction</h1> </Center><br>
  86.         <ol class="breadcrumb">
  87.             <li><a href="#"><i class="fa fa-dashboard"></i>History Order</a></li>
  88.             <li class="active">List</li>
  89.         </ol>
  90.     </section>
  91.     <div class="row" id="msgsaveOfflineTrans">
  92.     </div>
  93.     <section>
  94.         <div class="row">
  95.             <div class="col-lg-12">
  96.                 <form  id="addOfflineTransForm" method="post" accept-charset="utf-8">
  97.                     <div class="col-md-12">
  98.                         <div class="row" id="msgsaveOfflineTrans">
  99.                         </div>
  100.                     </div>
  101.                     <div class="col-md-12">
  102.                         <div class="row">
  103.                             <div class="col-lg-12"><label>Product <span class="required">*</span></label></div>
  104.                             <div class="col-lg-10">
  105.                                 <div class="form-group">
  106.                                     <input type="hidden" name="product_id" >
  107.                                     <input type="text" class="form-control" required="" name="product" readonly>
  108.                                 </div>
  109.                             </div>
  110.                             <div class="col-lg-2">
  111.                                 <div class="form-group">
  112.                                     <button class="btn btn-success" type ="button" data-toggle="modal" data-target="#newTransModal">Select Product</button>
  113.                                 </div>
  114.                             </div>
  115.                         </div>
  116.                     </div>            
  117.                     <div class="col-md-12" style="margin-top: 20px;">
  118.                         <div class="box box-primary">
  119.                             <div class="box-header with-border">
  120.                                 <h3 class="box-title">Detail Transaction</h3>
  121.                             </div>
  122.                             <div class="box-body">
  123.                                 <div class="col-md-12" style="margin-top: 20px;">
  124.                                     <div class="col-md-12" style="margin-top: 20px;">
  125.                                         <?php
  126.                                         require_once 'PHPExcel/PHPExcel.php';
  127.                                         $path   = './xls223/';
  128.                                         $nama_file_baru='data.xlsx';
  129.                                         $excelreader = new PHPExcel_Reader_Excel2007();
  130.                                         $loadexcel = $excelreader->load($path.$nama_file_baru); // Load file yang tadi diupload ke folder tmp
  131.                                         $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
  132.                                         ?>
  133.                                         <table class='table table-bordered'>
  134.                                             <tr>
  135.                                                 <th>Salutation</th>
  136.                                                 <th>Full Name</th>
  137.                                                 <th>Email</th>
  138.                                                 <th>Company</th>
  139.                                                 <th>Job Title</th>
  140.                                                 <th>Address</th>
  141.                                                 <th>Mobile Phone</th>
  142.                                                 <th>Personal</th>
  143.                                                 <th>Industry</th>
  144.                                             </tr>
  145.                                             <?php
  146.                                             $numrow = 1;
  147.                                             $kosong = 0;
  148.  
  149.                                             foreach($sheet as $row) { // Lakukan perulangan dari data yang ada di excel
  150.                                                 // Ambil data pada excel sesuai Kolom
  151.                                                 $salutation = $row['A'];
  152.                                                 $fullname = $row['B']; // Ambil data NIS
  153.                                                 $email = $row['C'];
  154.                                                 $company = $row['D'];
  155.                                                 $jobtitle = $row['E'];
  156.                                                 $address = $row['F'];
  157.                                                 $mobilephone = $row['G'];
  158.                                                 $personal = $row['H'];
  159.                                                 $industry = $row['I'];
  160.                                                 // Cek jika semua data tidak diisi
  161.                                                 if(empty($salutation) && empty($fullname) && empty($email) && empty($company) && empty($jobtitle) && empty($address) && empty($mobilephone) && empty($personal) && empty($industy)) continue;  // Lewat data pada baris ini (masuk ke looping selanjutnya / baris selanjutnya)
  162.                                                 if($numrow > 1) {
  163.                                                     // Validasi apakah semua data telah diisi
  164.                                                     $salutation_td = ( ! empty($salutation))? "" : " style='background: red;'"; // Jika NIS kosong, beri warna merah
  165.                                                     $fullname_td = ( ! empty($fullname))? "" : " style='background: red;'"; // Jika NIS kosong, beri warna merah
  166.                                                     $email_td = ( ! empty($email))? "" : " style='background: red ;'";// Jika Nama kosong, beri warna merah
  167.                                                     $company_td = ( ! empty($company))? "" : " style='background: red;'";
  168.                                                     $jobtitle_td = ( ! empty($jobtitle))? "" : " style='background: red;'";
  169.                                                     $address_td = ( ! empty($address))? "" : " style='background: red;'";
  170.                                                     $mobilephone_td = ( ! empty($mobilephone))? "" : " style='background: red;'";
  171.                                                     $personal_td = ( ! empty($personal))? "" : " style='background: red ;'";// Jika Nama kosong, beri warna merah
  172.                                                     $industry_td = ( ! empty($industry))? "" : " style='background: red ;'";// Jika Nama kosong, beri warna merah
  173.                                                     // Jika salah satu data ada yang kosong
  174.                                                     if(empty($fullname) or empty($email)or empty($company)or empty($jobtitle)or empty($address)or empty($mobilephone)
  175.                                                         or empty($personal)or empty($industry)) {
  176.                                                         $kosong++; // Tambah 1 variabel $kosong
  177.                                                     }
  178.                                                     echo "<tr>";
  179.                                                     echo "<td".$salutation_td."><input".$salutation_td." type='text' class='form-control' name='salutation[]'   value='$salutation'></td>";
  180.                                                     echo "<td".$fullname_td."><input".$fullname_td." type='text' class='form-control' name='fullname[]' value='$fullname'></td>";
  181.                                                     echo "<td".$email_td."><input".$email_td." type='email' class='form-control' name='email[]' value='$email'></td>";
  182.                                                     echo "<td".$company_td."><input".$company_td." type='text' class='form-control' name='company[]'    value='$company'></td>";
  183.                                                     echo "<td".$jobtitle_td."><input".$jobtitle_td." type='text' class='form-control' name='jobtitle[]' value='$jobtitle'></td>";
  184.                                                     echo "<td".$address_td."><input".$address_td." type='text' class='form-control' name='address[]'    value='$address'></td>";
  185.                                                     echo "<td".$mobilephone_td."><input".$mobilephone_td." type='text' class='form-control' name='phonenumber[]'    value='$mobilephone'></td>";
  186.  
  187.                                                     echo "<td".$personal_td."><input".$personal_td." type='text' class='form-control' name='personal[]' value='$personal'></td>";  
  188.                                                     echo "<td".$industry_td."><input".$industry_td." type='text' class='form-control' name='industry[]' value='$industry'></td>";                                  
  189.                                                     echo "</tr>";
  190.                                                 }
  191.                                                 $numrow++; // Tambah 1 setiap kali looping
  192.                                             }
  193.                                             ?>
  194.                                         </table>
  195.                                     </div>
  196.                                     <div class="col-md-12">
  197.                                     </div>
  198.                                 </div>
  199.                             </div>
  200.                             <div class="box-footer">
  201.                                 <div class="form-group col-sm-12">
  202.                                     <button type="button" class="form-control btn btn-primary main-button" id="submitBtn" onclick="saveOfflineTrans()" >Save</button>
  203.                                     <button style="display:none" type="button" class="form-control btn btn-primary main-button" id="loadingBtn"><i class="fa fa-circle-o-notch fa-spin"></i> Processing</button>
  204.                                 </div>
  205.                                 <!--
  206.                                 <div class="form-group col-sm-4">
  207.                                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  208.                                 </div>
  209.                                 -->
  210.                             </div>  
  211.                         </div>
  212.                     </div>
  213.                 </form>
  214.             </div>
  215.         </div>
  216.     </section>
  217. </div>
  218. <!-- Modal -->
  219. <div id="newTransModal" class="modal fade" role="dialog">
  220.     <div class="modal-dialog">
  221.         <!-- Modal content-->
  222.         <div class="modal-content">
  223.             <div class="modal-header">
  224.                 <button type="button" class="close" data-dismiss="modal">&times;</button>
  225.                 <h4 class="modal-title">Add Transaction</h4>
  226.             </div>
  227.             <div class="modal-body">
  228.                 <div class="container-fluid">
  229.                     <div class="box-body table-responsive">
  230.                         <table id="tabelproduct" class="table table-bordered table-striped">
  231.                             <thead>
  232.                                 <tr>
  233.                                     <th>ID</th>
  234.                                     <th>Name</th>
  235.                                     <!-- <th>Stock</th> -->
  236.                                     <th>Type</th>
  237.                                     <!-- <th>Diskon Price</th>-->
  238.                                     <!-- <th>Weight</th>-->
  239.                                     <th>Category</th>
  240.                                     <!-- <th>Timestamp</th> -->
  241.                                     <th style="width:100px">Action</th>
  242.                                 </tr>
  243.                             </thead>
  244.                             <tbody>
  245.                                 <?php foreach ($products as $product): ?>
  246.                                     <tr>
  247.                                         <td><?php echo $product->product_id; ?></td>
  248.                                         <td width="150px">
  249.                                             <?php
  250.                                             $location=$this->mProduct->getAttribute3($product->product_id,46);
  251.                                             $dateStart=$this->mProduct->getAttribute3($product->product_id,49);
  252.                                             if($location->row()){
  253.                                                 $newDate=date('d M Y',strtotime($dateStart->row()->product_attr_value));
  254.                                                 echo "<span style='font-size:11px;font-weight: 700;color:#ec028d;'>".$location->row()->product_attr_value. " - ".$newDate."</span><br>";
  255.                                             }
  256.                                             echo "<a href='#' data-id='".$product->product_id."' class='get-detail'>".$product->product_name."</a>"; ?>
  257.                                             <?php if($product->status==2) echo "<span style='color: red;font-size: 10px;'>Draft</span>";?>
  258.                                         </td>
  259.                                         <!--  <td><?php echo $product->product_stock; ?></td> -->
  260.                                         <td width="150px">
  261.                                             <?php echo (strlen($product->lms_slug)>=3?'Online Training':'No Slug Found'); ?>
  262.                                         </td>
  263.                                         <!-- <td width="150px">--><?php //echo formatRupiah($product->disc_price); ?><!--</td>-->
  264.                                         <!-- <td>--><?php //echo $product->product_weight; ?><!--</td>-->
  265.                                         <td><?php echo $product->category; ?></td>
  266.                                         <!-- <td><?php echo date('d M Y',strtotime($product->timestamp)); ?></td> -->
  267.                                         <td style="width:100px">
  268.                                             <a onClick="selectProduct(<?php echo $product->product_id; ?>,'<?php echo $product->product_name; ?>')" class="btn btn-danger">Select Product</a>
  269.                                         </td>
  270.                                     </tr>
  271.                                     <?php $no++; ?>
  272.                                 <?php endforeach; ?>
  273.                             </tbody>
  274.                         </table>
  275.                     </div>
  276.                 </div>
  277.             </div>
  278.         </div>
  279.     </div>
  280. </div>
Advertisement
Add Comment
Please, Sign In to add comment