Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function editSales() {
- $id = $this->input->post('sales_id');
- $submit = $this->input->post('submit');
- if ($submit == "Update") {
- $status = 0;
- } else {
- $status = 4;
- }
- $this->form_validation->set_rules('customer', 'Customer', 'trim|required');
- if ($this->form_validation->run() == false) {
- $this->edit($id);
- } else {
- $warehouse_id = $this->input->post('warehouse');
- $old_warehouse_id = $this->input->post('old_warehouse_id');
- $warehouse_change = $this->input->post('warehouse_change');
- $data = array(
- "currentdate" => $this->input->post('sales_date'),
- "date" => $this->input->post('cust_date'),
- "cc_holder" => $this->input->post('taxx'),
- "po_cust" => $this->input->post('po_cust'),
- "warehouse_id" => $this->input->post('warehouse'),
- "ketnama" => $this->input->post('reference'),
- "biller_id" => $this->input->post('biller_id'),
- "customer_id" => $this->input->post('customer'),
- "upcc" => $this->input->post('main'),
- "upcc2" => $this->input->post('cc'),
- "total" => $this->input->post('grand_total'),
- "discount_value" => $this->input->post('total_discount'),
- "tax_value" => $this->input->post('total_tax'),
- "note" => $this->input->post('note'),
- "shipping_city_id" => $this->input->post('city'),
- "shipping_state_id" => $this->input->post('state'),
- "shipping_country_id" => $this->input->post('country'),
- "shipping_address" => $this->input->post('address'),
- "shipping_charge" => $this->input->post('shipping_charge'),
- "internal_note" => $this->input->post('internal_note'),
- "mode_of_transport" => $this->input->post('mode_of_transport'),
- "transporter_name" => $this->input->post('transporter_name'),
- "transporter_code" => $this->input->post('transporter_code'),
- "vehicle_regn_no" => $this->input->post('vehicle_regn_no'),
- "l_r_no" => $this->input->post('l_r_no'),
- "chalan_no" => $this->input->post('chalan_no'),
- "indent_no" => $this->input->post('indent_no'),
- "credit_days" => $this->input->post('credit_days'),
- "date_of_supply" => $this->input->post('date_of_supply'),
- "electronic_ref_no" => $this->input->post('electronic_ref_no'),
- "gst_payable" => $this->input->post('gst_payable'),
- "broker" => $this->input->post('broker'),
- "user" => $this->session->userdata('user_id'),
- "term_and_condition" => $this->input->post('term_and_condition'),
- "sales_id" => $this->input->post('sales_id'),
- "user_name" => $this->session->userdata('identity'),
- "kurs_id" => $this->input->post('kursdata'),
- "nominalcurrency" => $this->input->post('grand_currency'),
- "ATTN" => $this->input->post('tax'),
- "shipto" => $this->input->post('shipto'),
- "billto" => $this->input->post('billto'),
- "dateestimate" => $this->input->post('dateestimate'),
- "salesdesc" => $this->input->post('others'),
- "paid_by" => $this->input->post('paymenterms') ?: 'advance',
- "additional_description" => $this->input->post('additional_description'),
- "service_description" => $this->input->post('service_description'),
- "diskonpersen" => $this->input->post('DiscountPersen'),
- "diskon" => $this->input->post('diskonfix'),
- "status_rev" => $status
- );
- if ($this->sales_model->editModel($id, $data)) {
- $log_data = array(
- 'user_id' => $this->session->userdata('user_id'),
- 'table_id' => $id,
- 'message' => 'Sales Updated'
- );
- $this->log_model->insert_log($log_data);
- $this->sales_model->deleteTerminModel($id);
- $jumlahtermin = $this->input->post('terminnumber');
- if (!empty($jumlahtermin)) {
- $termins = $this->input->post('terminvalue');
- $tanggaltermins = $this->input->post('tanggalterminvalue');
- $ket = $this->input->post('terminket');
- if (!empty($termins)) {
- $im = 0;
- $i = 1;
- foreach ($termins as $quan) {
- $value = $this->input->post('grand_total');
- $nominal = ($value * $quan) / 100;
- $nominal = number_format((float) $nominal, 2, '.', '');
- if (!empty($tanggaltermins[$im])) {
- $datetermin = $tanggaltermins[$im];
- } else {
- $datetermin = date('Y-m-d');
- }
- $datatermin = array(
- "sales_id" => $id,
- "persen" => $quan,
- "nominal" => $nominal,
- "tanggalbayar" => $datetermin,
- "keterangan" => $ket[$i]
- );
- $this->sales_model->addTerminModel($datatermin);
- $i++;
- $im++;
- }
- } else {
- }
- }
- $this->sales_model->deleteSalesItemsAll($id);
- $product_id = $this->input->post('idProduct');
- $quantity = $this->input->post('qty');
- $price = $this->input->post('price');
- $gross_total = $this->input->post('linetotal');
- $discount_id = $this->input->post('discount_id');
- $discount_value = $this->input->post('discount_value');
- $discount = $this->input->post('discount');
- $serial_no = $this->input->post('serial_no');
- $sales_id = $id;
- foreach ($product_id as $e => $pd) {
- $a['product_id'] = $pd;
- $a['quantity'] = $quantity[$e];
- $a['price'] = $price[$e];
- $a['gross_total'] = $gross_total[$e];
- $a['discount_id'] = $discount_id[$e];
- $a['discount_value'] = $discount_value[$e];
- $a['discount'] = $discount[$e];
- $a['serial_no'] = $serial_no[$e];
- $a['sales_id'] = $sales_id;
- $this->db->insert('sales_items', $a);
- }
- $js_data = json_decode($this->input->post('table_data'));
- $js_data1 = json_decode($this->input->post('tableadditional_data'));
- $js_data2 = json_decode($this->input->post('tableservice_data'));
- // foreach ($js_data as $key => $value) {
- // if (!empty($value) and ! empty($value->product_id)) {
- // $data = array(
- // "product_id" => $value->product_id,
- // "quantity" => (!empty($value->quantity)) ? $value->quantity : 0,
- // "price" => (!empty($value->price)) ? $value->price : 0,
- // "gross_total" => (!empty($value->total)) ? $value->total : 0,
- // "discount_id" => (!empty(@$value->discount_id)) ? @$value->discount_id : 0,
- // "discount_value" => (!empty(@$value->discount_value)) ? @$value->discount_value : 0,
- // "discount" => (!empty($value->discount)) ? $value->discount : 0,
- // "serial_no" => (!empty($value->desc)) ? $value->desc : 0,
- // "sales_id" => $id
- // );
- // $this->db->insert('sales_items', $data);
- // }
- // }
- $this->sales_model->deleteSalesAdditionalAll($id);
- foreach ($js_data1 as $key => $value) {
- if ($value != null || !empty($value->additional_id)) {
- $data = array(
- "product_id" => $value->additional_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "desc" => $value->desc,
- "sales_id" => $id
- );
- $this->db->insert('sales_additional_items' ,$data);
- }
- }
- $this->sales_model->deleteSalesServiceItemsAll($id);
- if (!empty($js_data2)) {
- foreach ($js_data2 as $key => $value) {
- if ($value != null || !empty($value->service_id)) {
- $data = array(
- "service_id" => $value->service_id,
- "quantity" => $value->quantity,
- "price" => $value->price,
- "gross_total" => $value->total,
- "discount_id" => @$value->discount_id,
- "discount_value" => @$value->discount_value,
- "discount" => $value->discount,
- "sales_id" => $id
- );
- $this->sales_model->addSalesServiceItem($data);
- }
- }
- }
- redirect('sales/view/' . $id);
- } else {
- redirect('sales', 'refresh');
- }
- }
- }
- public function edit($id) {
- $kursdata = $this->company_setting_model->getCurrency();
- $data['brands'] = $this->brand_model->getBrand();
- $data['customer'] = $this->sales_model->getCustomer();
- $data['biller'] = $this->sales_model->getBiller();
- $data['product2'] = $this->sales_model->getProducts2();
- $data['service'] = $this->sales_model->getService();
- $data['additional'] = $this->sales_model->getAdditional($id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['bonus'] = $this->sales_model->getBonus($id);
- $data['tax'] = $this->sales_model->getTax();
- $data['data'] = $this->sales_model->getRecord($id);
- $data['country'] = $this->customer_model->getCountry();
- $data['kursdata'] = $kursdata;
- $data['state'] = $this->customer_model->getState($data['data'][0]->shipping_country_id);
- $data['city'] = $this->customer_model->getCity($data['data'][0]->shipping_state_id);
- $data['product'] = $this->sales_model->getProducts($data['data'][0]->warehouse_id);
- $data['items'] = $this->sales_model->getSalesItems($id);
- $data['items2_old'] = $this->sales_model->getProducts99($id);
- $data['total_items'] = count($data['items2_old']);
- // echo '<pre>' . var_export($data, true) . '</pre>';
- // die;
- $data['serviceitems'] = $this->sales_model->getServiceItems($data['data'][0]->sales_id);
- $data['termin'] = $this->sales_model->getTerminSalesId($data['data'][0]->sales_id);
- $this->load->view('sales/edit', $data);
- }
- public function getProduct($product_id,$sales_id) {
- $datas = $this->sales_model->getProducts21($product_id);
- // print_r(var_dump($this->db->last_query()));
- for ($i=0; $i < count($datas) ; $i++) {
- if ($datas[$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($datas[$i]->list));
- $arlist = json_decode($arlist);
- $max = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $qtyp = $this->db->select('quantity')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->quantity;
- $count = ($qtyp / intval($arlist[$ilist]->ql));
- array_push($max, $count);
- }
- $min = min($max);
- $datas[$i]->quantity = intval($min);
- }
- }
- $data['items'] = $this->sales_model->getProducts99($sales_id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['bonus'] = $this->sales_model->getBonus($product_id);
- $data['bonus1'] = $this->sales_model->getBonus12();
- $data['tax'] = $this->sales_model->getTax();
- echo json_encode($data);
- }
- public function getProduct_old($product_id) {
- $data = $this->sales_model->getProducts21($product_id);
- // print_r(var_dump($this->db->last_query()));
- for ($i=0; $i < count($data) ; $i++) {
- if ($data[$i]->product_grouping != NULL) {
- $arlist = json_encode(unserialize($data[$i]->list));
- $arlist = json_decode($arlist);
- $max = array();
- for ($ilist = 0; $ilist < count($arlist); $ilist++) {
- $qtyp = $this->db->select('quantity')->from('products')->where('product_id', $arlist[$ilist]->pl)->get()->result()[0]->quantity;
- $count = ($qtyp / intval($arlist[$ilist]->ql));
- array_push($max, $count);
- }
- $min = min($max);
- $data[$i]->quantity = intval($min);
- }
- }
- // $data['items'] = $this->sales_model->getProducts99($sales_id);
- $data['discount'] = $this->sales_model->getDiscount();
- $data['bonus'] = $this->sales_model->getBonus($product_id);
- $data['bonus1'] = $this->sales_model->getBonus12();
- $data['tax'] = $this->sales_model->getTax();
- echo json_encode($data);
- }
Add Comment
Please, Sign In to add comment