diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7d2f325..79dd85e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -95,7 +95,8 @@ $routes->post("add_client", "Client::add_client"); $routes->get("new_client/(:any)", "Client::new_client/$1"); $routes->get("delete_client/(:any)", "Client::delete_client/$1"); $routes->post("save_client", "Client::client_quick_create"); -//end clent +//end client + //Vendor// $routes->get('vendor_index/', 'Vendor::vendor_index'); $routes->post("add_vendor", "Vendor::add_vendor"); diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 243be8d..203a6f1 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -93,7 +93,7 @@ class Jobcard extends BaseController $value['product'] = $product; } $data['editservicedata'] = $servicedata; - /*** COMPLAINT DATA ***/ + /*** COMPLAINT DATA ***/ $complaintdata = $JobcardModel->complaint_data($job_card_id, $this->session->get('logged_user_branch_id')); // Using '&' to reference the original array element foreach ($complaintdata as &$value) { @@ -105,7 +105,7 @@ class Jobcard extends BaseController } $data['editcomplaintdata'] = $complaintdata; - /*** CUSTOM COMPLAINT DATA ***/ + /*** CUSTOM COMPLAINT DATA ***/ $ccomplaintdata = $JobcardModel->ccomplaint_data($job_card_id, $this->session->get('logged_user_branch_id')); // Using '&' to reference the original array element foreach ($ccomplaintdata as &$value) { @@ -193,6 +193,8 @@ class Jobcard extends BaseController public function add_jobs() { // echo $this->request->getPost('products');die; + // echo $this->request->getPost('delete_items');die; + $this->delete_items($this->request->getPost('delete_items')); $JobcardModel = new JobcardModel(); $JobcardProductModel = new JobcardProductModel(); $JobcardServiceModel = new JobcardServiceModel(); @@ -228,7 +230,7 @@ class Jobcard extends BaseController // Update sales order with generated order number $JobcardModel->update($job_card_id, ['order_number' => $orderNumber]); } - + /********** INSERT SERVICE DATA ************/ $data = json_decode($_POST['products']); $service_data = $data[0]->service; @@ -331,6 +333,7 @@ class Jobcard extends BaseController // Insert into the service table $service['job_card_id'] = $job_card_id; $service['complaint_name'] = $item->complaint_id; + $service['labour_cost'] = $item->labour_cost; $service['qty'] = $item->quality; $service['tax'] = $item->tax; $service['amount'] = $item->amount; @@ -372,6 +375,56 @@ class Jobcard extends BaseController return redirect()->to('job_card_index'); } + public function delete_items($delArr) + { + $JobcardServiceModel = new JobcardServiceModel(); + $JobcardComplaintModel = new JobcardComplaintModel(); + $JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); + $data = json_decode($delArr); + + $service_data = $data[0]->service; + if(!empty($service_data)) { + foreach ($service_data as $item) { + $conditions = [ 'job_card_service_id' => $item ]; + $service_deleted_data = $JobcardServiceModel->where($conditions)->findAll(); + $this->product_delete($service_deleted_data[0]['product_id']); + $JobcardServiceModel->where($conditions)->delete(); + } + } + + $complaint_data = $data[0]->complaint; + if(!empty($complaint_data)) { + foreach ($complaint_data as $item) { + $conditions = [ 'job_card_complaint_id' => $item ]; + $complaint_deleted_data = $JobcardComplaintModel->where($conditions)->findAll(); + $this->product_delete($complaint_deleted_data[0]['product_id']); + $JobcardComplaintModel->where($conditions)->delete(); + } + } + + $ccomplaint_data = $data[0]->custom_complaint; + if(!empty($ccomplaint_data)) { + foreach ($ccomplaint_data as $item) { + $conditions = [ 'job_card_cc_id' => $item ]; + $cc_deleted_data = $JobcardCustomComplaintModel->where($conditions)->findAll(); + $this->product_delete($cc_deleted_data[0]['product_id']); + $JobcardCustomComplaintModel->where($conditions)->delete(); + } + } + } + + /** DELETE JOB CARD-PRODUCT */ + public function product_delete($product) { + $JobcardProductModel = new JobcardProductModel(); + $product_ids = json_decode($product, true); + if (empty($product_ids)) return true; + foreach ($product_ids as $item) { + $conditions = [ 'job_card_product_id' => $item ]; + $JobcardProductModel->where($conditions)->delete(); + } + return true; + } + public function product_data_maintanence($id_array,$status) { $ProductModel = new ProductModel(); @@ -380,7 +433,7 @@ class Jobcard extends BaseController foreach ($id_array as $key => $product_id) { $product = $JobcardProductModel->find($product_id); $qty = isset($product['qty']) ? $product['qty'] : 0; - if ($status == 'Created') { + if ($status == 'Paid') { $this->updateProductQuantity($ProductModel, $product['product_id'], $qty); }elseif ($status == 'Cancelled'){ $this->addBackProductQuantity($ProductModel, $product['product_id'], $qty); diff --git a/app/Models/JobcardCustomComplaintModel.php b/app/Models/JobcardCustomComplaintModel.php index ad9af96..20afff1 100644 --- a/app/Models/JobcardCustomComplaintModel.php +++ b/app/Models/JobcardCustomComplaintModel.php @@ -5,5 +5,5 @@ class JobcardCustomComplaintModel extends Model { protected $table = 'job_card_custom_complaint'; protected $primaryKey = 'job_card_cc_id'; - protected $allowedFields = ['job_card_cc_id', 'job_card_id','complaint_name', 'product_id', 'qty', 'tax', 'amount','isactive']; + protected $allowedFields = ['job_card_cc_id', 'job_card_id','complaint_name', 'labour_cost','product_id', 'qty', 'tax', 'amount','isactive']; } \ No newline at end of file diff --git a/app/Models/JobcardModel.php b/app/Models/JobcardModel.php index 0cce0cb..b0ccff8 100644 --- a/app/Models/JobcardModel.php +++ b/app/Models/JobcardModel.php @@ -39,8 +39,8 @@ class JobcardModel extends Model $this->select('job_card.job_card_id, job_card_complaint.*'); $this->join('job_card_complaint', 'job_card_complaint.job_card_id = job_card.job_card_id'); $this->where('job_card_complaint.isactive', 1); - $this ->where('job_card.job_card_id',$job_card_id); - $this ->where('job_card.branch_id',$logged_user_branch_id); + $this->where('job_card.job_card_id',$job_card_id); + $this->where('job_card.branch_id',$logged_user_branch_id); return $this->findAll(); } diff --git a/app/Views/complaint_list.php b/app/Views/complaint_list.php index 690b86c..b4caab5 100644 --- a/app/Views/complaint_list.php +++ b/app/Views/complaint_list.php @@ -21,7 +21,7 @@