diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 96553a6..2a3b444 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -87,7 +87,9 @@ class Jobcard extends BaseController // Using '&' to reference the original array element foreach ($servicedata as &$value) { $product_ids = json_decode($value['product_id'], true); - $product = $JobcardProductModel->whereIn('job_card_product_id', $product_ids)->findAll(); + $product = $JobcardProductModel->select('job_card_product.* , products.product_name as pname') + ->join('products', 'products.product_id = job_card_product.product_id') + ->whereIn('job_card_product.job_card_product_id', $product_ids)->findAll(); $value['product'] = $product; } $data['editservicedata'] = $servicedata; @@ -96,7 +98,9 @@ class Jobcard extends BaseController // Using '&' to reference the original array element foreach ($complaintdata as &$value) { $product_ids = json_decode($value['product_id'], true); - $product = $JobcardProductModel->whereIn('job_card_product_id', $product_ids)->findAll(); + $product = $JobcardProductModel->select('job_card_product.* , products.product_name as pname') + ->join('products', 'products.product_id = job_card_product.product_id') + ->whereIn('job_card_product_id', $product_ids)->findAll(); $value['product'] = $product; } $data['editcomplaintdata'] = $complaintdata; @@ -106,7 +110,9 @@ class Jobcard extends BaseController // Using '&' to reference the original array element foreach ($ccomplaintdata as &$value) { $product_ids = json_decode($value['product_id'], true); - $product = $JobcardProductModel->whereIn('job_card_product_id', $product_ids)->findAll(); + $product = $JobcardProductModel->select('job_card_product.* , products.product_name as pname') + ->join('products', 'products.product_id = job_card_product.product_id') + ->whereIn('job_card_product_id', $product_ids)->findAll(); $value['product'] = $product; } $data['editccomplaintdata'] = $ccomplaintdata; @@ -137,7 +143,7 @@ class Jobcard extends BaseController $data['make_model'] = $make_name['make'].' ' . $model_name['model_name']; // Encode the modelId before searching $encodedModelId = json_encode([$modelId]); - +// echo $encodedModelId;die; // Load the ProductModel @@ -147,6 +153,8 @@ class Jobcard extends BaseController ->findAll(); $data['product']=$product; + // echo json_encode($product);die; + // Load the ServiceModel $ServiceModel = new ServiceModel(); $encodedMakeId = json_encode([$makeId]); @@ -231,7 +239,8 @@ class Jobcard extends BaseController $service['qty'] = $item->quality; $service['tax'] = $item->tax; $service['amount'] = $item->amount; - if($item->id == '') { + // echo empty($item->id);die; + if(empty($item->id)) { $JobcardServiceModel->insert($service); $service_id = $JobcardServiceModel->getInsertID(); } @@ -248,13 +257,13 @@ class Jobcard extends BaseController $product['qty'] = $pt->qty; $product['tax'] = $pt->tax; $product['amount'] = $pt->amount; - if($pt->id == '') { + if(empty($pt->id)) { $JobcardProductModel->insert($product); $job_card_product_id = $JobcardProductModel->getInsertID(); } else { - $JobcardProductModel->update($pt->id, $service); - $job_card_product_id = $item->id; + $JobcardProductModel->update($pt->id, $product); + $job_card_product_id = $pt->id; } array_push($id, $job_card_product_id); } @@ -274,7 +283,7 @@ class Jobcard extends BaseController $service['qty'] = $item->quality; $service['tax'] = $item->tax; $service['amount'] = $item->amount; - if($item->id == '') { + if(empty($item->id)) { $JobcardComplaintModel->insert($service); $complaint_id = $JobcardComplaintModel->getInsertID(); } @@ -291,13 +300,13 @@ class Jobcard extends BaseController $product['qty'] = $pt->qty; $product['tax'] = $pt->tax; $product['amount'] = $pt->amount; - if($pt->id == '') { + if(empty($pt->id)) { $JobcardProductModel->insert($product); $job_card_product_id = $JobcardProductModel->getInsertID(); } else { - $JobcardProductModel->update($pt->id, $service); - $job_card_product_id = $item->id; + $JobcardProductModel->update($pt->id, $product); + $job_card_product_id = $pt->id; } array_push($id, $job_card_product_id); } @@ -317,7 +326,7 @@ class Jobcard extends BaseController $service['qty'] = $item->quality; $service['tax'] = $item->tax; $service['amount'] = $item->amount; - if($item->id == '') { + if(empty($item->id)) { $JobcardCustomComplaintModel->insert($service); $cc_complaint_id = $JobcardCustomComplaintModel->getInsertID(); } @@ -334,13 +343,13 @@ class Jobcard extends BaseController $product['qty'] = $pt->qty; $product['tax'] = $pt->tax; $product['amount'] = $pt->amount; - if($pt->id == '') { + if(empty($pt->id)) { $JobcardProductModel->insert($product); $job_card_product_id = $JobcardProductModel->getInsertID(); } else { - $JobcardProductModel->update($pt->id, $service); - $job_card_product_id = $item->id; + $JobcardProductModel->update($pt->id, $product); + $job_card_product_id = $pt->id; } array_push($id, $job_card_product_id); } diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php index d5330b7..bb82189 100644 --- a/app/Controllers/Service.php +++ b/app/Controllers/Service.php @@ -22,7 +22,7 @@ class Service extends BaseController { $ServiceModel = new ServiceModel(); - $services = $ServiceModel->where('branch_id',$this->session->get('logged_user_business_id'))->findAll(); + $services = $ServiceModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); foreach ($services as &$service) { // Convert JSON strings to arrays @@ -169,7 +169,7 @@ class Service extends BaseController $ServiceModel->update($service_id, $data); } else { - $data['branch_id'] = $this->session->get('logged_user_business_id'); + $data['branch_id'] = $this->session->get('logged_user_branch_id'); $ServiceModel->insert($data); } diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php index 6fbcbc3..c9000dd 100644 --- a/app/Views/job_card_form.php +++ b/app/Views/job_card_form.php @@ -328,7 +328,7 @@ /***** APPEND DATA ONLY EDIT ******/ $(document).ready(async function() { /** SERVICE */ - var edit_service_data = ; + var edit_service_data = ; // console.log(edit_service_data); if(edit_service_data.length > 0) { for (const value of edit_service_data) { @@ -365,7 +365,7 @@ $(document).ready(async function() { } /** COMPLAINT */ - var edit_complaint_data = ; + var edit_complaint_data = ; if(edit_complaint_data.length > 0) { for (const value of edit_complaint_data) { complaint = ; @@ -405,7 +405,7 @@ $(document).ready(async function() { } /** CUSTOM COMPLAINT */ - var edit_ccomplaint_data = ; + var edit_ccomplaint_data = ; console.log(edit_ccomplaint_data); if(edit_ccomplaint_data.length > 0) { for (const value of edit_ccomplaint_data) { @@ -443,7 +443,7 @@ $(document).ready(async function() { ' + '' + '' + @@ -493,7 +493,7 @@ $(document).ready(async function() { vehicle_id: vehicleId }, success: function(response) { - // console.log(response); + console.log(response); productarray = response.product; makeAndModel = response.makeName+' '+response.modelName; $('#makeAndModel').val(makeAndModel); @@ -911,6 +911,11 @@ $(document).ready(async function() { // Event listener for "Add More Item" button $(document).on('click', '#addProduct', function() { + console.log(productarray.length); + if(productarray.length == 0) { + productarray = ; + console.log(productarray); + } var newRow = '