fadlyshafa

Untitled

Jun 21st, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.49 KB | None | 0 0
  1. public function editSales() {
  2.     $id = $this->input->post('sales_id');
  3.     $submit = $this->input->post('submit');
  4.     if ($submit == "Update") {
  5.       $status = 0;
  6.     } else {
  7.       $status = 4;
  8.     }
  9.  
  10.     $this->form_validation->set_rules('customer', 'Customer', 'trim|required');
  11.     if ($this->form_validation->run() == false) {
  12.       $this->edit($id);
  13.     } else {
  14.       $warehouse_id = $this->input->post('warehouse');
  15.       $old_warehouse_id = $this->input->post('old_warehouse_id');
  16.       $warehouse_change = $this->input->post('warehouse_change');
  17.       $data = array(
  18.           "currentdate" => $this->input->post('sales_date'),
  19.           "date" => $this->input->post('cust_date'),
  20.           "cc_holder" => $this->input->post('taxx'),
  21.           "po_cust" => $this->input->post('po_cust'),
  22.           "warehouse_id" => $this->input->post('warehouse'),
  23.           "ketnama" => $this->input->post('reference'),
  24.           "biller_id" => $this->input->post('biller_id'),
  25.           "customer_id" => $this->input->post('customer'),
  26.           "upcc" => $this->input->post('main'),
  27.           "upcc2" => $this->input->post('cc'),
  28.           "total" => $this->input->post('grand_total'),
  29.           "discount_value" => $this->input->post('total_discount'),
  30.           "tax_value" => $this->input->post('total_tax'),
  31.           "note" => $this->input->post('note'),
  32.           "shipping_city_id" => $this->input->post('city'),
  33.           "shipping_state_id" => $this->input->post('state'),
  34.           "shipping_country_id" => $this->input->post('country'),
  35.           "shipping_address" => $this->input->post('address'),
  36.           "shipping_charge" => $this->input->post('shipping_charge'),
  37.           "internal_note" => $this->input->post('internal_note'),
  38.           "mode_of_transport" => $this->input->post('mode_of_transport'),
  39.           "transporter_name" => $this->input->post('transporter_name'),
  40.           "transporter_code" => $this->input->post('transporter_code'),
  41.           "vehicle_regn_no" => $this->input->post('vehicle_regn_no'),
  42.           "l_r_no" => $this->input->post('l_r_no'),
  43.           "chalan_no" => $this->input->post('chalan_no'),
  44.           "indent_no" => $this->input->post('indent_no'),
  45.           "credit_days" => $this->input->post('credit_days'),
  46.           "date_of_supply" => $this->input->post('date_of_supply'),
  47.           "electronic_ref_no" => $this->input->post('electronic_ref_no'),
  48.           "gst_payable" => $this->input->post('gst_payable'),
  49.           "broker" => $this->input->post('broker'),
  50.           "user" => $this->session->userdata('user_id'),
  51.           "term_and_condition" => $this->input->post('term_and_condition'),
  52.           "sales_id" => $this->input->post('sales_id'),
  53.           "user_name" => $this->session->userdata('identity'),
  54.           "kurs_id" => $this->input->post('kursdata'),
  55.           "nominalcurrency" => $this->input->post('grand_currency'),
  56.           "ATTN" => $this->input->post('tax'),
  57.           "shipto" => $this->input->post('shipto'),
  58.           "billto" => $this->input->post('billto'),
  59.           "dateestimate" => $this->input->post('dateestimate'),
  60.           "salesdesc" => $this->input->post('others'),
  61.           "paid_by" => $this->input->post('paymenterms') ?: 'advance',
  62.           "additional_description" => $this->input->post('additional_description'),
  63.           "service_description" => $this->input->post('service_description'),
  64.           "diskonpersen" => $this->input->post('DiscountPersen'),
  65.           "diskon" => $this->input->post('diskonfix'),
  66.           "status_rev" => $status
  67.       );
  68.  
  69.       if ($this->sales_model->editModel($id, $data)) {
  70.         $log_data = array(
  71.             'user_id' => $this->session->userdata('user_id'),
  72.             'table_id' => $id,
  73.             'message' => 'Sales Updated'
  74.         );
  75.         $this->log_model->insert_log($log_data);
  76.  
  77.  
  78.         $this->sales_model->deleteTerminModel($id);
  79.  
  80.         $jumlahtermin = $this->input->post('terminnumber');
  81.  
  82.         if (!empty($jumlahtermin)) {
  83.           $termins = $this->input->post('terminvalue');
  84.           $tanggaltermins = $this->input->post('tanggalterminvalue');
  85.           $ket = $this->input->post('terminket');
  86.           if (!empty($termins)) {
  87.             $im = 0;
  88.             $i = 1;
  89.             foreach ($termins as $quan) {
  90.               $value = $this->input->post('grand_total');
  91.               $nominal = ($value * $quan) / 100;
  92.               $nominal = number_format((float) $nominal, 2, '.', '');
  93.               if (!empty($tanggaltermins[$im])) {
  94.                 $datetermin = $tanggaltermins[$im];
  95.               } else {
  96.                 $datetermin = date('Y-m-d');
  97.               }
  98.  
  99.               $datatermin = array(
  100.                   "sales_id" => $id,
  101.                   "persen" => $quan,
  102.                   "nominal" => $nominal,
  103.                   "tanggalbayar" => $datetermin,
  104.                   "keterangan" => $ket[$i]
  105.               );
  106.  
  107.               $this->sales_model->addTerminModel($datatermin);
  108.               $i++;
  109.               $im++;
  110.             }
  111.           } else {
  112.            
  113.           }
  114.         }
  115.  
  116.  
  117.         // $this->sales_model->deleteSalesItemsAll($id);
  118.  
  119.         // $product_id = $this->input->post('product_id');
  120.         // $quantity = $this->input->post('qty');
  121.         // $price = $this->input->post('price');
  122.         // $gross_total = $this->input->post('linetotal');
  123.         // $discount_id = $this->input->post('discount_id');
  124.         // $discount_value = $this->input->post('discount_value');
  125.         // $discount = $this->input->post('discount');
  126.         // $serial_no = $this->input->post('serial_no');
  127.         // $sales_id = $id;
  128.  
  129.         // foreach ($product_id as $e => $pd) {
  130.  
  131.         //       $a['product_id'] = $pd;
  132.         //       $a['quantity'] = $quantity[$e];
  133.         //       $a['price'] = $price[$e];
  134.         //       $a['gross_total'] = $gross_total[$e];
  135.         //       $a['discount_id'] = $discount_id[$e];
  136.         //       $a['discount_value'] = $discount_value[$e];
  137.         //       $a['discount'] = $discount[$e];
  138.         //       $a['serial_no'] = $serial_no[$e];
  139.         //       $a['sales_id'] = $sales_id;
  140.              
  141.         //       $this->db->insert('sales_items', $a);
  142.  
  143.         // }
  144.  
  145.         $js_data = json_decode($this->input->post('table_data'));
  146.         $js_data1 = json_decode($this->input->post('tableadditional_data'));
  147.         $js_data2 = json_decode($this->input->post('tableservice_data'));
  148.  
  149.         $this->sales_model->deleteSalesItemsAll($id);
  150.  
  151.         $id_product = $this->input->post('idProducts');
  152.         $quantity = $this->input->post('quantitys');
  153.         $price = $this->input->post('prices');
  154.         $total = $this->input->post('totals');
  155.         // $discount_id = $this->input->post('hidden_discount');
  156.         $discount_value = $this->input->post('discount_values');
  157.         // $serial_no =
  158.         $sales_id = $id;
  159.  
  160.         foreach ($id_product as $e => $pd) {
  161.           $a['product_id'] = $pd;
  162.           // $a['quantity'] = $quantity[$e];
  163.           // $a['price'] = $price[$e];
  164.           // $a['gross_total'] = $total[$e];
  165.           // // $a['discount_id'] = $discount_id[$e];
  166.           // $a['discount_value'] = $discount_value[$e];
  167.           // $a['sales_id'] = $id;
  168.  
  169.           $a['quantity'] = $this->input->post('qty'.$e);
  170.           $a['price'] = $this->input->post('price'.$e);
  171.           $a['gross_total'] = $this->input->post('linetotal'.$e);
  172.           $a['serial_no'] = $this->input->post('description'.$e);
  173.           $a['discount_id'] = $this->input->post('item_discount'.$e);
  174.  
  175.           $dk = $this->db->where('discount_id = ',$a['discount_id'])->get('discount')->row();
  176.           $diskon = $dk->discount_value / 100 * $a['price'];
  177.  
  178.           $a['discount_value'] = $dk->discount_value;
  179.           $a['discount'] = $diskon;
  180.          
  181.           $a['sales_id'] = $id;
  182.  
  183.           $this->db->insert('sales_items', $a);
  184.         }
  185.  
  186.         // foreach ($js_data as $key => $value) {
  187.         //   if (!empty($value) and ! empty($value->product_id)) {
  188.            
  189.         //     $data = array(
  190.         //         "product_id" => $value->product_id,
  191.         //         "quantity" => (!empty($value->quantity)) ? $value->quantity : 0,
  192.         //         "price" => (!empty($value->price)) ? $value->price : 0,
  193.         //         "gross_total" => (!empty($value->total)) ? $value->total : 0,
  194.         //         "discount_id" => (!empty($value->discount_id)) ? $value->discount_id : 0,
  195.         //         "discount_value" => (!empty($value->discount_value)) ? $value->discount_value : 0,
  196.         //         "discount" => (!empty($value->discount)) ? $value->discount : 0,
  197.  
  198.         //         "serial_no" => (!empty($value->desc)) ? $value->desc : 0,
  199.         //         "sales_id" => $id
  200.         //     );
  201.            
  202.         //     $this->db->insert('sales_items', $data);
  203.         //   }
  204.         // }
  205.  
  206.         $this->sales_model->deleteSalesAdditionalAll($id);
  207.         foreach ($js_data1 as $key => $value) {
  208.           if ($value != null || !empty($value->additional_id)) {
  209.            
  210.             $data = array(
  211.                 "product_id" => $value->additional_id,
  212.                 "quantity" => $value->quantity,
  213.                 "price" => $value->price,
  214.                 "gross_total" => $value->total,
  215.                 "discount_id" => @$value->discount_id,
  216.                 "discount_value" => @$value->discount_value,
  217.                 "discount" => $value->discount,
  218.                 "desc" => $value->desc,
  219.                 "sales_id" => $id
  220.             );
  221.            
  222.             $this->db->insert('sales_additional_items' ,$data);
  223.           }
  224.         }
  225.  
  226.         $this->sales_model->deleteSalesServiceItemsAll($id);
  227.         if (!empty($js_data2)) {
  228.           foreach ($js_data2 as $key => $value) {
  229.             if ($value != null || !empty($value->service_id)) {
  230.  
  231.               $data = array(
  232.                   "service_id" => $value->service_id,
  233.                   "quantity" => $value->quantity,
  234.                   "price" => $value->price,
  235.                   "gross_total" => $value->total,
  236.                   "discount_id" => @$value->discount_id,
  237.                   "discount_value" => @$value->discount_value,
  238.                   "discount" => $value->discount,
  239.                   "sales_id" => $id
  240.               );
  241.              
  242.               $this->sales_model->addSalesServiceItem($data);
  243.             }
  244.           }
  245.         }
  246.  
  247.         redirect('sales/view/' . $id);
  248.       } else {
  249.         redirect('sales', 'refresh');
  250.       }
  251.     }
  252.   }
Add Comment
Please, Sign In to add comment