fadlyshafa

Untitled

Jun 17th, 2020
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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('idProduct');
  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. // foreach ($js_data as $key => $value) {
  150. // if (!empty($value) and ! empty($value->product_id)) {
  151.  
  152. // $data = array(
  153. // "product_id" => $value->product_id,
  154. // "quantity" => (!empty($value->quantity)) ? $value->quantity : 0,
  155. // "price" => (!empty($value->price)) ? $value->price : 0,
  156. // "gross_total" => (!empty($value->total)) ? $value->total : 0,
  157. // "discount_id" => (!empty(@$value->discount_id)) ? @$value->discount_id : 0,
  158. // "discount_value" => (!empty(@$value->discount_value)) ? @$value->discount_value : 0,
  159. // "discount" => (!empty($value->discount)) ? $value->discount : 0,
  160.  
  161. // "serial_no" => (!empty($value->desc)) ? $value->desc : 0,
  162. // "sales_id" => $id
  163. // );
  164.  
  165. // $this->db->insert('sales_items', $data);
  166. // }
  167. // }
  168.  
  169. $this->sales_model->deleteSalesAdditionalAll($id);
  170. foreach ($js_data1 as $key => $value) {
  171. if ($value != null || !empty($value->additional_id)) {
  172.  
  173. $data = array(
  174. "product_id" => $value->additional_id,
  175. "quantity" => $value->quantity,
  176. "price" => $value->price,
  177. "gross_total" => $value->total,
  178. "discount_id" => @$value->discount_id,
  179. "discount_value" => @$value->discount_value,
  180. "discount" => $value->discount,
  181. "desc" => $value->desc,
  182. "sales_id" => $id
  183. );
  184.  
  185. $this->db->insert('sales_additional_items' ,$data);
  186. }
  187. }
  188.  
  189. $this->sales_model->deleteSalesServiceItemsAll($id);
  190. if (!empty($js_data2)) {
  191. foreach ($js_data2 as $key => $value) {
  192. if ($value != null || !empty($value->service_id)) {
  193.  
  194. $data = array(
  195. "service_id" => $value->service_id,
  196. "quantity" => $value->quantity,
  197. "price" => $value->price,
  198. "gross_total" => $value->total,
  199. "discount_id" => @$value->discount_id,
  200. "discount_value" => @$value->discount_value,
  201. "discount" => $value->discount,
  202. "sales_id" => $id
  203. );
  204.  
  205. $this->sales_model->addSalesServiceItem($data);
  206. }
  207. }
  208. }
  209.  
  210. redirect('sales/view/' . $id);
  211. } else {
  212. redirect('sales', 'refresh');
  213. }
  214. }
  215. }
  216.  
  217. public function edit($id) {
  218.  
  219. $kursdata = $this->company_setting_model->getCurrency();
  220.  
  221. $data['brands'] = $this->brand_model->getBrand();
  222. $data['customer'] = $this->sales_model->getCustomer();
  223. $data['biller'] = $this->sales_model->getBiller();
  224. $data['product2'] = $this->sales_model->getProducts2();
  225. $data['service'] = $this->sales_model->getService();
  226. $data['additional'] = $this->sales_model->getAdditional($id);
  227. $data['discount'] = $this->sales_model->getDiscount();
  228. $data['bonus'] = $this->sales_model->getBonus($id);
  229. $data['tax'] = $this->sales_model->getTax();
  230. $data['data'] = $this->sales_model->getRecord($id);
  231. $data['country'] = $this->customer_model->getCountry();
  232. $data['kursdata'] = $kursdata;
  233. $data['state'] = $this->customer_model->getState($data['data'][0]->shipping_country_id);
  234. $data['city'] = $this->customer_model->getCity($data['data'][0]->shipping_state_id);
  235. $data['product'] = $this->sales_model->getProducts($data['data'][0]->warehouse_id);
  236. $data['items'] = $this->sales_model->getSalesItems($id);
  237.  
  238. $data['items2_old'] = $this->sales_model->getProducts99($id);
  239. $data['total_items'] = count($data['items2_old']);
  240. // echo '<pre>' . var_export($data, true) . '</pre>';
  241. // die;
  242. $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
  243. $data['termin'] = $this->sales_model->getTerminSalesId($data['data'][0]->sales_id);
  244.  
  245. $this->load->view('sales/edit', $data);
  246. }
RAW Paste Data