ok
Direktori : /home2/selectio/www/mm-tailor-billing/app/models/ |
Current File : /home2/selectio/www/mm-tailor-billing/app/models/Sales-model-copy.php |
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } class Sales_model extends CI_Model { public function __construct() { parent::__construct(); } public function addPayment($data = []) { if ($this->db->insert('payments', $data)) { if ($data['paid_by'] == 'gift_card') { $gc = $this->site->getGiftCard($data['gc_no']); $this->db->update('gift_cards', ['balance' => ($gc->balance - $data['amount'])], ['card_no' => $data['gc_no']]); } $this->syncSalePayments($data['sale_id']); error_log("1111"); return true; } return false; } public function addPaymentStatus($status, $id) { error_log("Sale IDS:".$id); error_log("Status:".$status); if ($this->db->update('sales', ['status' => $status], ['id' => $id])) { return true; } return false; } public function get_all_cutting_staffs() { $q = $this->db->get('users'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // Filter Sales Starts Here public function getAllCustomers() { $q = $this->db->get('customers'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllStaff() { $q = $this->db->get('users'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllSaleDC() { $q = $this->db->get('sales'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getTotalCustomerSales($customer_id, $user = null, $start_date = null, $end_date = null, $hold_ref = null, $status= null, $payment = null) { $this->db->select('COUNT(id) as number, sum(grand_total) as amount, sum(paid) as paid'); if ($start_date && $end_date) { $this->db->where('date >=', $start_date); $this->db->where('date <=', $end_date); } if ($user) { $this->db->where('created_by', $user); } if ($hold_ref) { $this->db->where('hold_ref', $hold_ref); } if ($payment) { $this->db->where('status', $payment); } if ($status) { $this->db->where('unit_process_status', $status); } //$this->db->get_where('sales', ['hold_ref' => $hold_ref]); if ($this->session->userdata('store_id')) { $this->db->where('store_id', $this->session->userdata('store_id')); } $q = $this->db->get_where('sales', ['customer_id' => $customer_id]); if ($q->num_rows() > 0) { return $q->row(); } return false; } // Filter Sales Ends Here // New Function Starts Here public function getSaleByCusID($cus_id) { $this->db->select("(SELECT FORMAT((SUM(tec_sale_items.quantity)),0) from tec_sale_items where tec_sale_items.sale_id=tec_sales.id and tec_sale_items.product_id=1) as pant_count,(SELECT FORMAT((SUM(tec_sale_items.quantity)),0) from tec_sale_items where tec_sale_items.sale_id=tec_sales.id and tec_sale_items.product_id=2 or tec_sale_items.sale_id=tec_sales.id and tec_sale_items.product_id=3) as shirt_count, due_date, hold_ref, DATE_FORMAT(due_date, '%d-%m-%Y') as due_date, deliver_date, bill_cancel_status, bill_status"); $sq = $this->db->get_where('sales', array('id' => $cus_id), 1); if( $sq->num_rows() > 0 ) { return $sq->row(); } return FALSE; } public function getSaleIemsBySaleID($sales_id) { $this->db->select('sale_items.sale_id,sale_items.quantity,sale_items.product_name,sale_items.product_type,sale_items.cutting_status,sale_items.stitching_status,sale_items.ready_products_status,sale_items.delivery_date_status,sale_items.product_id,sale_items.id,(SELECT sum(tec_work_units.quantity) from tec_work_units where tec_work_units.sale_id=tec_sale_items.sale_id and tec_work_units.type=1 and tec_work_units.assign_or_not="assign" and tec_work_units.product_id=tec_sale_items.product_id) as cutting_assigned, (tec_sale_items.quantity-(SELECT sum(tec_work_units.quantity) from tec_work_units where tec_work_units.sale_id=tec_sale_items.sale_id and tec_work_units.type=1 and tec_work_units.assign_or_not="assign" and tec_work_units.product_id=tec_sale_items.product_id)) as remaing_cutting_qty'); $sq = $this->db->get_where('sale_items', ['sale_id' => $sales_id]); if($sq->num_rows() > 0) { foreach (($sq->result()) as $row) { $data[] = $row; } return $data; } return FALSE; } public function getSaleWorkUnitsTable($sales_id) { /*$this->db->select('sale_items.*, users.last_name as user_lname, users.first_name as user_fname, products.name as product_name') ->join('users', 'sale_items.cutting_user=users.id', 'left') ->join('products', 'sale_items.product_id=products.id', 'left');*/ $sq = $this->db->get_where('work_units', ['sale_id' => $sales_id]); if($sq->num_rows() > 0) { foreach (($sq->result()) as $row) { $data[] = $row; } return $data; } return FALSE; } public function getSaleIemsBySaleIDWithWorksTable($s_id) { $sq = $this->db->get_where('works', ['sale_id' => $s_id]); if($sq->num_rows() > 0) { foreach (($sq->result()) as $row) { $data[] = $row; } return $data; } return FALSE; } public function getSaleMainTable($s_id) { $sq = $this->db->get_where('sales', ['id' => $s_id]); if($sq->num_rows() > 0) { foreach (($sq->result()) as $row) { $data[] = $row; } return $data; } return FALSE; } public function getSaleDetailsByID($sale_id) { $sq = $this->db->get_where('sales', ['id' => $sale_id]); if($sq->num_rows() > 0) { foreach (($sq->result()) as $row) { $data[] = $row; } return $data; } return FALSE; } // New Function Ends Here public function deleteInvoice($id) { $osale = $this->getSaleByID($id); $oitems = $this->getAllSaleItems($id); foreach ($oitems as $oitem) { $product = $this->site->getProductByID($oitem->product_id, $osale->store_id); if ($product->type == 'standard') { $this->db->update('product_store_qty', ['quantity' => ($product->quantity + $oitem->quantity)], ['product_id' => $product->id, 'store_id' => $osale->store_id]); } elseif ($product->type == 'combo') { $combo_items = $this->getComboItemsByPID($product->id); foreach ($combo_items as $combo_item) { $cpr = $this->site->getProductByID($combo_item->id, $osale->store_id); if ($cpr->type == 'standard') { $qty = $combo_item->qty * $oitem->quantity; $this->db->update('product_store_qty', ['quantity' => ($cpr->quantity + $qty)], ['product_id' => $cpr->id, 'store_id' => $osale->store_id]); } } } } if ($this->db->delete('sale_items', ['sale_id' => $id]) && $this->db->delete('sales', ['id' => $id]) && $this->db->delete('payments', ['sale_id' => $id])) { return true; } return false; } public function deleteAssignList($id) { if ($this->db->delete('work_units', ['id' => $id])) { return true; } return false; } public function deleteOpenedSale($id) { if ($this->db->delete('suspended_items', ['suspend_id' => $id]) && $this->db->delete('suspended_sales', ['id' => $id])) { return true; } return false; } public function deletePayment($id) { $payment = $this->getPaymentByID($id); if ($payment->paid_by == 'gift_card') { $gc = $this->site->getGiftCard($payment->gc_no); $this->db->update('gift_cards', ['balance' => ($gc->balance + $payment->amount)], ['card_no' => $payment->gc_no]); } if ($this->db->delete('payments', ['id' => $id])) { $this->syncSalePayments($payment->sale_id); return true; } return false; } public function getAllSaleItems($sale_id) { $j = "(SELECT id, code, name, tax_method from {$this->db->dbprefix('products')}) P"; $this->db->select("sale_items.*, (CASE WHEN {$this->db->dbprefix('sale_items')}.product_code IS NULL THEN {$this->db->dbprefix('products')}.code ELSE {$this->db->dbprefix('sale_items')}.product_code END) as product_code, (CASE WHEN {$this->db->dbprefix('sale_items')}.product_name IS NULL THEN {$this->db->dbprefix('products')}.name ELSE {$this->db->dbprefix('sale_items')}.product_name END) as product_name, {$this->db->dbprefix('products')}.tax_method as tax_method", false) ->join('products', 'products.id=sale_items.product_id', 'left outer') ->order_by('sale_items.id'); $q = $this->db->get_where('sale_items', ['sale_id' => $sale_id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllSalePayments($sale_id) { $q = $this->db->get_where('payments', ['sale_id' => $sale_id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getComboItemsByPID($product_id) { $this->db->select($this->db->dbprefix('products') . '.id as id, ' . $this->db->dbprefix('products') . '.code as code, ' . $this->db->dbprefix('combo_items') . '.quantity as qty, ' . $this->db->dbprefix('products') . '.name as name, ' . $this->db->dbprefix('products') . '.quantity as quantity') ->join('products', 'products.code=combo_items.item_code', 'left') ->group_by('combo_items.id'); $q = $this->db->get_where('combo_items', ['product_id' => $product_id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getCustomerByID($id) { $q = $this->db->get_where('customers', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getPaymentByID($id) { $q = $this->db->get_where('payments', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getSaleByID($id) { $q = $this->db->get_where('sales', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getSalePayments($sale_id) { $this->db->order_by('id', 'asc'); $q = $this->db->get_where('payments', ['sale_id' => $sale_id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } } public function syncSalePayments($id) { $sale = $this->getSaleByID($id); $payments = $this->getSalePayments($id); $paid = 0; if ($payments) { foreach ($payments as $payment) { $paid += $payment->amount; } } $status = $paid <= 0 ? 'due' : ($sale->grand_total <= $paid ? 'paid' : 'partial'); if ($this->db->update('sales', ['paid' => $paid, 'status' => $status], ['id' => $id])) { return true; } return false; } public function updatePayment($id, $data = []) { $payment = $this->getPaymentByID($id); if ($payment->paid_by == 'gift_card') { $gc = $this->site->getGiftCard($payment->gc_no); $this->db->update('gift_cards', ['balance' => ($gc->balance + $payment->amount)], ['card_no' => $payment->gc_no]); } if ($this->db->update('payments', $data, ['id' => $id])) { if ($data['paid_by'] == 'gift_card') { $gc = $this->site->getGiftCard($data['gc_no']); $this->db->update('gift_cards', ['balance' => ($gc->balance - $data['amount'])], ['card_no' => $data['gc_no']]); } $this->syncSalePayments($data['sale_id']); return true; } return false; } public function updateStatus($id, $status) { if ($this->db->update('sales', ['status' => $status], ['id' => $id])) { return true; } return false; } // **************************** Latest Unit Process Status Starts Here ****************************************** // public function overAllDeliveryStatus($sale_id, $full_delivery_date, $full_delivery_date_status) { if($full_delivery_date_status==9){ if($full_delivery_date==""){ $this->db->update('tec_sales', ['unit_process_status' => '9'], ['id' => $sale_id]); error_log(99); }else{ $this->db->update('tec_sales', ['unit_process_status' => '9', 'deliver_date' => $full_delivery_date], ['id' => $sale_id]); error_log($full_delivery_date); } } } public function billCancelStatus($sale_id, $bill_cancel_status, $bill_cancell_done) { if($bill_cancel_status==10){ if($bill_cancell_done==""){ }else{ $this->db->update('tec_sales', ['bill_status' => $bill_cancell_done], ['id' => $sale_id]); error_log($bill_cancell_done); } } } public function readyToDeliveryStatus($sale_id, $products, $products_name, $quantity, $total_quantity, $ready_or_not_ready, $update_work_id, $measurement_status_insert, $measurement_status_update, $not_assign_quantity, $ready_products_not_assign_products,$ready_products_not_assign_products_name,$ready_products_not_assign_total_qty) { error_log("Sale Id: ".$sale_id); error_log("Ready To Delivery Measurements Insert: ".$measurement_status_insert); error_log("Ready To Delivery Measurements Update: ".$measurement_status_update); if(in_array("not_ready", $ready_or_not_ready)) { if($measurement_status_insert==6){ $this->db->update('tec_sales', ['unit_process_status' => '6'], ['id' => $sale_id]); $this->db->update('tec_sale_items', ['ready_products_status' => '0'], ['sale_id' => $sale_id]); error_log("Ready To Delivery Not Ready"); } }else{ if($measurement_status_insert==6){ $this->db->update('tec_sales', ['unit_process_status' => '7'], ['id' => $sale_id]); $this->db->update('tec_sale_items', ['ready_products_status' => '0'], ['sale_id' => $sale_id]); error_log("All Ready Ready To Delivery"); } } /* $ready_products_not_assign_products,$ready_products_not_assign_products_name,$ready_products_not_assign_total_qty*/ for($c=0;$c<count($not_assign_quantity);$c++){ if($measurement_status_insert==6){ if($not_assign_quantity[$c]=="0" || $not_assign_quantity[$c]=="") { }else{ $this->db->insert('tec_work_units', ['type' => '3', 'assign_or_not' => 'assign', 'quantity' => $not_assign_quantity[$c], 'sale_id' => $sale_id, 'product_id' => $ready_products_not_assign_products[$c], 'product_name' => $ready_products_not_assign_products_name[$c], 'total_qty' => $ready_products_not_assign_total_qty[$c]]); } } } for($w=0;$w<count($products);$w++) { error_log("Sale Id: ".$sale_id); error_log("Product Id: ".$products[$w]); error_log("Product Name: ".$products_name[$w]); error_log("Quantity: ".$quantity[$w]); error_log("Total Quantity: ".$total_quantity[$w]); error_log("Measurements Insert: ".$measurement_status_insert); error_log("Measurements Update: ".$measurement_status_update); error_log("Ready Or Not Ready: ".$ready_or_not_ready[$w]); error_log("Update Work ID: ".$update_work_id[$w]); if($measurement_status_insert==6){ $this->db->insert('tec_work_units', ['type' => '3', 'assign_or_not' => 'assign', 'sale_id' => $sale_id, 'product_id' => $products[$w], 'product_name' => $products_name[$w], 'quantity' => $quantity[$w], 'total_qty' => $total_quantity[$w], 'ready_or_not_ready' => $ready_or_not_ready[$w]]); } if($measurement_status_update==66){ $this->db->update('tec_work_units', ['assign_or_not' => 'assign', 'ready_or_not_ready' => $ready_or_not_ready[$w]], ['id' => $update_work_id[$w]]); } } return true; } // **************************** Latest Unit Process Status Endss Here ****************************************** // public function stitchingggStatuss($sale_id, $products, $products_name, $quantity, $total_quantity, $stitching_user, $stitching_assign_date, $update_work_id, $measurement_status_insert,$measurement_status_update) { if(in_array("", $stitching_assign_date)) { if($measurement_status_insert==4){ $this->db->update('tec_sales', ['unit_process_status' => '4'], ['id' => $sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $sale_id]); } }else{ if($measurement_status_update==4){ $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $sale_id]); } } for($w=0;$w<count($products);$w++) { error_log("Sale Id: ".$sale_id); error_log("Product Id: ".$products[$w]); error_log("Product Name: ".$products_name[$w]); error_log("Quantity: ".$quantity[$w]); error_log("Total Quantity: ".$total_quantity[$w]); error_log("Measurements: ".$measurement_status); error_log("Stitching User:".$stitching_user); error_log("Stitching Assign Date: ".$stitching_assign_date[$w]); error_log("Update Work ID: ".$update_work_id[$w]); if($measurement_status_insert==4){ $this->db->insert('tec_work_units', ['type' => '2', 'sale_id' => $sale_id, 'product_id' => $products[$w], 'product_name' => $products_name[$w], 'quantity' => $quantity[$w], 'total_qty' => $total_quantity[$w], 'stitching_user_id' => $stitching_user[$w], 'stitching_assign_date' => $stitching_assign_date[$w]]); } if($measurement_status_update==44){ $this->db->insert('tec_work_units', ['stitching_user_id' => $stitching_user[$w], 'stitching_assign_date' => $stitching_assign_date[$w]], ['id' => $update_work_id[$w]]); } } return true; } // **************************** Latest Delivery Date Unit Process Status Starts Here ****************************************** // public function deliveryDateStatus($sale_id, $products, $products_name, $quantity, $total_quantity, $measurement_status, $delivery_date, $update_work_id) { if(in_array("", $delivery_date)) { if($measurement_status==8){ $this->db->update('tec_sales', ['unit_process_status' => '8'], ['id' => $sale_id]); $this->db->update('tec_sale_items', ['delivery_date_status' => '0'], ['sale_id' => $sale_id]); } }else{ if($measurement_status==8){ $this->db->update('tec_sales', ['unit_process_status' => '9'], ['id' => $sale_id]); $this->db->update('tec_sale_items', ['delivery_date_status' => '0'], ['sale_id' => $sale_id]); } } for($w=0;$w<count($products);$w++) { error_log("Sale Id: ".$sale_id); error_log("Product Id: ".$products[$w]); error_log("Product Name: ".$products_name[$w]); error_log("Quantity: ".$quantity[$w]); error_log("Total Quantity: ".$total_quantity[$w]); error_log("Measurements: ".$measurement_status); error_log("Delivery Date: ".$delivery_date[$w]); error_log("Update Work ID: ".$update_work_id[$w]); if($measurement_status==8){ $this->db->insert('tec_work_units', ['type' => '4', 'sale_id' => $sale_id, 'product_id' => $products[$w], 'product_name' => $products_name[$w], 'quantity' => $quantity[$w], 'total_qty' => $total_quantity[$w], 'delivery_date' => $delivery_date[$w]]); } if($measurement_status==88){ $this->db->insert('tec_work_units', ['delivery_date' => $delivery_date[$w]], ['id' => $update_work_id[$w]]); } } return true; } // **************************** Latest Delivery Date Unit Process Status Endss Here ****************************************** // // New Cutting Assign Starts Here public function cuttingUnitStatus($cutting_sale_id, $cutting_products, $cutting_products_name, $cutting_username, $cutting_assign_date,$cutting_quantity, $cutting_total_quantity, $cutting_status, $overall_delivery_date, $update_work_id,$new_status,$works_cutting_products,$works_cutting_products_name,$works_cutting_username,$works_cutting_assign_date,$works_cutting_quantity) { if(in_array("0", $cutting_username) || in_array("", $cutting_assign_date)) { if($cutting_status==2){ $this->db->update('tec_sales', ['unit_process_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sales', ['cutting_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sale_items', ['cutting_status' => '0'], ['sale_id' => $cutting_sale_id]); } }else{ if($cutting_status==2){ $this->db->update('tec_sales', ['unit_process_status' => '3'], ['id' => $cutting_sale_id]); $this->db->update('tec_sales', ['cutting_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sale_items', ['cutting_status' => '0'], ['sale_id' => $cutting_sale_id]); } if($cutting_status==22){ $this->db->update('tec_sales', ['unit_process_status' => '3'], ['id' => $cutting_sale_id]); $this->db->update('tec_sales', ['cutting_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sale_items', ['cutting_status' => '0'], ['sale_id' => $cutting_sale_id]); } } for($w=0;$w<count($cutting_products);$w++) { if($cutting_status==2){ if($cutting_quantity[$w]==$cutting_total_quantity[$w]){ $this->db->update('tec_sales', ['unit_process_status' => '3'], ['id' => $cutting_sale_id]); }else{ $this->db->update('tec_sales', ['unit_process_status' => '2'], ['id' => $cutting_sale_id]); } } } /*for($c=0;$c<count($not_assign_cutting_quantity);$c++){ if($cutting_status==2){ if($not_assign_cutting_quantity[$c]=="0" || $not_assign_cutting_quantity[$c]=="") { }else{ $this->db->insert('tec_work_units', ['type' => '1', 'assign_or_not' => 'not_assign', 'quantity' => $not_assign_cutting_quantity[$c], 'sale_id' => $cutting_sale_id, 'product_id' => $cutting_not_assign_products[$c], 'product_name' => $cutting_not_assign_products_name[$c], 'total_qty' => $cutting_not_assign_total_qty[$c]]); } } }*/ /*'total_ass_quantity' => $total_assigned_quantity[$w],*/ for($w=0;$w<count($cutting_products);$w++) { if($cutting_status==2){ $this->db->insert('tec_work_units', ['type' => '1', 'assign_or_not' => 'assign', 'sale_id' => $cutting_sale_id, 'product_id' => $cutting_products[$w], 'product_name' => $cutting_products_name[$w], 'quantity' => $cutting_quantity[$w], 'total_qty' => $cutting_total_quantity[$w], 'cutting_user_id' => $cutting_username[$w], 'cutting_assign_date' => $cutting_assign_date[$w]]); } if($cutting_status==22){ $this->db->update('tec_work_units', ['assign_or_not' => 'assign', 'quantity' => $cutting_quantity[$w],'cutting_user_id' => $cutting_username[$w], 'cutting_assign_date' => $cutting_assign_date[$w]], ['id' => $update_work_id[$w]]); } if($new_status[$w]=="0"){ if($cutting_status==22){ $this->db->insert('tec_work_units', ['type' => '1', 'assign_or_not' => 'assign', 'sale_id' => $cutting_sale_id, 'product_id' => $works_cutting_products[$w], 'product_name' => $works_cutting_products_name[$w], 'quantity' => $works_cutting_quantity[$w], 'total_qty' => $works_cutting_total_quantity[$w], 'cutting_user_id' => $works_cutting_username[$w], 'cutting_assign_date' => $works_cutting_assign_date[$w]]); } } } return true; } // New Cutting Assign Ends Here // New Stithching Like Cutting Assign Starts Here public function stitchingStatus($cutting_sale_id, $cutting_products, $cutting_products_name, $cutting_username, $cutting_assign_date,$cutting_quantity, $cutting_total_quantity, $cutting_status, $overall_delivery_date, $update_work_id,$new_status,$works_cutting_products,$works_cutting_products_name,$works_cutting_username,$works_cutting_assign_date,$works_cutting_quantity) { error_log("Stitching Update Working"); error_log("SAle Id".$cutting_sale_id); if(in_array("0", $cutting_username) || in_array("", $cutting_assign_date)) { if($cutting_status==4){ $this->db->update('tec_sales', ['unit_process_status' => '4'], ['id' => $cutting_sale_id]); $this->db->update('tec_sales', ['stitching_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $cutting_sale_id]); } }else{ if($cutting_status==4){ $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $cutting_sale_id]); $this->db->update('tec_sales', ['stitching_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $cutting_sale_id]); } if($cutting_status==44){ $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $cutting_sale_id]); $this->db->update('tec_sales', ['stitching_status' => '2'], ['id' => $cutting_sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $cutting_sale_id]); } } for($w=0;$w<count($cutting_products);$w++) { if($cutting_status==4){ if($cutting_quantity[$w]==$cutting_total_quantity[$w]){ $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $cutting_sale_id]); }else{ $this->db->update('tec_sales', ['unit_process_status' => '4'], ['id' => $cutting_sale_id]); } } } for($w=0;$w<count($cutting_products);$w++) { if($cutting_status==4){ $this->db->insert('tec_work_units', ['type' => '2', 'assign_or_not' => 'assign', 'sale_id' => $cutting_sale_id, 'product_id' => $cutting_products[$w], 'product_name' => $cutting_products_name[$w], 'quantity' => $cutting_quantity[$w], 'total_qty' => $cutting_total_quantity[$w], 'stitching_user_id' => $cutting_username[$w], 'stitching_assign_date' => $cutting_assign_date[$w]]); } if($cutting_status==44){ $this->db->update('tec_work_units', ['assign_or_not' => 'assign', 'quantity' => $cutting_quantity[$w],'stitching_user_id' => $cutting_username[$w], 'stitching_assign_date' => $cutting_assign_date[$w]], ['id' => $update_work_id[$w]]); } if($new_status[$w]=="0"){ if($cutting_status==44){ $this->db->insert('tec_work_units', ['type' => '2', 'assign_or_not' => 'assign', 'sale_id' => $cutting_sale_id, 'product_id' => $works_cutting_products[$w], 'product_name' => $works_cutting_products_name[$w], 'quantity' => $works_cutting_quantity[$w], 'total_qty' => $works_cutting_total_quantity[$w], 'stitching_user_id' => $works_cutting_username[$w], 'stitching_assign_date' => $works_cutting_assign_date[$w]]); } } } return true; } // New Stitching Like Cutting Assign Ends Here // New Stitching Assign Starts Here public function stitchingStatuss($stitching_sale_id, $stitching_products, $stitching_products_name, $stitching_username, $stitching_assign_date, $stitching_quantity, $stitching_total_quantity, $overall_d_date, $update_work_id, $not_assign_stitching_quantity,$stitching_not_assign_products,$stitching_not_assign_products_name,$stitching_not_assign_total_qty,$new_status, $works_stitching_products,$works_stitching_products_name,$works_stitching_username,$works_stitching_assign_date,$works_stitching_quantity,$works_stitching_total_quantity,$measurement_status_insert,$measurement_status_update) { error_log("Stitching Working"); error_log($stitching_sale_id); error_log($measurement_status_insert); error_log($measurement_status_update); if(in_array("0", $stitching_username) || in_array("", $stitching_assign_date)) { if($measurement_status_insert==4){ error_log("Stitching User Name 0 and Date Null Working"); $this->db->update('tec_sales', ['unit_process_status' => '4'], ['id' => $stitching_sale_id]); $this->db->update('tec_sales', ['stitching_status' => '2'], ['id' => $stitching_sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $stitching_sale_id]); } }else{ if($measurement_status_insert==4){ error_log("Stitching Fully Assigned Working"); $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $stitching_sale_id]); $this->db->update('tec_sales', ['stitching_status' => '2'], ['id' => $stitching_sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $stitching_sale_id]); } if($measurement_status_update==44){ error_log("Stitching Fully Assigned Working"); $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $stitching_sale_id]); $this->db->update('tec_sales', ['stitching_status' => '2'], ['id' => $stitching_sale_id]); $this->db->update('tec_sale_items', ['stitching_status' => '0'], ['sale_id' => $stitching_sale_id]); } } for($c=0;$c<count($not_assign_stitching_quantity);$c++){ if($measurement_status_insert==4){ if($not_assign_stitching_quantity[$c]=="0" || $not_assign_stitching_quantity[$c]=="") { }else{ $this->db->insert('tec_work_units', ['type' => '2', 'assign_or_not' => 'not_assign', 'quantity' => $not_assign_stitching_quantity[$c], 'sale_id' => $stitching_sale_id, 'product_id' => $stitching_not_assign_products[$c], 'product_name' => $stitching_not_assign_products_name[$c], 'total_qty' => $stitching_not_assign_total_qty[$c]]); } } } for($w=0;$w<count($stitching_products);$w++) { error_log($new_status[$w]); if($measurement_status_insert==4){ $this->db->insert('tec_work_units', ['type' => '2', 'assign_or_not' => 'assign', 'sale_id' => $stitching_sale_id, 'product_id' => $stitching_products[$w], 'product_name' => $stitching_products_name[$w], 'quantity' => $stitching_quantity[$w], 'total_qty' => $stitching_total_quantity[$w], 'stitching_user_id' => $stitching_username[$w], 'stitching_assign_date' => $stitching_assign_date[$w]]); } if($measurement_status_update==44){ $this->db->update('tec_work_units', ['assign_or_not' => 'assign', 'quantity' => $stitching_quantity[$w],'stitching_user_id' => $stitching_username[$w], 'stitching_assign_date' => $stitching_assign_date[$w]], ['id' => $update_work_id[$w]]); } if($new_status[$w]=="0"){ if($measurement_status_update==44){ $this->db->insert('tec_work_units', ['type' => '2', 'assign_or_not' => 'assign', 'sale_id' => $stitching_sale_id, 'product_id' => $works_stitching_products[$w], 'product_name' => $works_stitching_products_name[$w], 'quantity' => $works_stitching_quantity[$w], 'total_qty' => $works_stitching_total_quantity[$w], 'stitching_user_id' => $works_stitching_username[$w], 'stitching_assign_date' => $works_stitching_assign_date[$w]]); } } } return true; } // New Stitching Assign Ends Here /******************** Old Method Starts Here DB Name (tec_works) ***************************/ public function updateupStatusNew($works_id, $id, $status, $product_id, $user_name, $assign_date, $s_products, $s_username, $s_assign_date, $ready_products, $delivery_date, $items_delivery_date) { error_log($status); if(in_array("0", $user_name) || in_array("", $assign_date)) { if($status==2){ $this->db->update('tec_sales', ['unit_process_status' => '2'], ['id' => $id]); } }else{ if($status==2){ $this->db->update('tec_sales', ['unit_process_status' => '3'], ['id' => $id]); } } if(in_array("0", $s_username) || in_array("", $s_assign_date)) { if($status==4){ $this->db->update('tec_sales', ['unit_process_status' => '4'], ['id' => $id]); } }else{ if($status==4){ $this->db->update('tec_sales', ['unit_process_status' => '5'], ['id' => $id]); } } if(in_array("not_ready", $ready_products)) { if($status==6){ $this->db->update('tec_sales', ['unit_process_status' => '6'], ['id' => $id]); } }else{ if($status==6){ $this->db->update('tec_sales', ['unit_process_status' => '7'], ['id' => $id]); } } if(in_array("", $items_delivery_date)) { if($status==8){ $this->db->update('tec_sales', ['unit_process_status' => '8'], ['id' => $id]); } }else{ if($status==8){ $this->db->update('tec_sales', ['unit_process_status' => '9'], ['id' => $id]); } } if($status==9){ if($delivery_date=="0000-00-00"){ $this->db->update('tec_sales', ['unit_process_status' => '9'], ['id' => $id]); }else{ $this->db->update('tec_sales', ['unit_process_status' => '9', 'deliver_date' => $delivery_date], ['id' => $id]); } } error_log("Works ID Count:".count($works_id)); for($w=0;$w<count($works_id);$w++) { error_log("Count:".$w); if($status==2){ if($user_name[$w]=="0" || $assign_date[$w]==""){ $this->db->update('tec_works', ['cutting_status' => '1[$w]'], ['id' =>$works_id[$w]]); $this->db->update('tec_works', ['cutting_user_id' => $user_name[$w],'cutting_assign_date' => $assign_date[$w]], ['id' =>$works_id[$w]]); $this->db->update('tec_sales', ['unit_process_status' => '2'], ['id' => $id]); }else{ $this->db->update('tec_works', ['cutting_user_id' => $user_name[$w],'cutting_assign_date' => $assign_date[$w]], ['id' =>$works_id[$w]]); $this->db->update('tec_works', ['cutting_status' => '2[$w]'], ['id' =>$works_id[$w]]); } } if($status==4){ if($s_username[$w]=="0" || $s_assign_date[$w]=="0000-00-00"){ $this->db->update('tec_works', ['stitching_status' => '1[$w]'], ['id' =>$works_id[$w]]); $this->db->update('tec_works', ['stitching_user_id' => $s_username[$w],'stitching_assign_date' => $s_assign_date[$w]], ['id' =>$works_id[$w]]); $this->db->update('tec_sales', ['unit_process_status' => '4'], ['id' => $id]); error_log($s_assign_date[$w]); }else{ $this->db->update('tec_works', ['stitching_user_id' => $s_username[$w],'stitching_assign_date' => $s_assign_date[$w]], ['id' =>$works_id[$w]]); $this->db->update('tec_works', ['stitching_status' => '2[$w]'], ['id' =>$works_id[$w]]); } } if($status==6){ if($ready_products[$w]=="not_ready"){ $this->db->update('tec_works', ['ready_or_not_ready' => $ready_products[$w]], ['id' =>$works_id[$w]]); $this->db->update('tec_sales', ['unit_process_status' => '6'], ['id' => $id]); }else{ $this->db->update('tec_works', ['ready_or_not_ready' => $ready_products[$w]], ['id' =>$works_id[$w]]); } } if($status==8){ if($items_delivery_date[$w]==""){ $this->db->update('tec_works', ['delivery_date' => $items_delivery_date[$w]], ['id' =>$works_id[$w]]); $this->db->update('tec_sales', ['unit_process_status' => '8'], ['id' => $id]); }else{ $this->db->update('tec_works', ['delivery_date' => $items_delivery_date[$w]], ['id' =>$works_id[$w]]); } } } return true; } /******************** Old Method Endss Here DB Name (tec_works) ***************************/ }