CHANGE_service_module:ss

This commit is contained in:
sriramv 2024-04-29 11:05:56 +05:30
parent 96ddbcad49
commit ad7775387d
3 changed files with 77 additions and 83 deletions

View File

@ -86,7 +86,7 @@ class Jobcard extends BaseController
$servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id'));
// Using '&' to reference the original array element
foreach ($servicedata as &$value) {
$product_ids = json_decode($value['product_id'], true);
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$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();
@ -97,7 +97,7 @@ class Jobcard extends BaseController
$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) {
$product_ids = json_decode($value['product_id'], true);
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$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();
@ -109,7 +109,7 @@ class Jobcard extends BaseController
$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) {
$product_ids = json_decode($value['product_id'], true);
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$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();
@ -249,6 +249,7 @@ class Jobcard extends BaseController
$service_id = $item->id;
}
if(isset($item->product)) {
// Insert into the product table
$id = [];
foreach ($item->product as $pt) {
@ -272,6 +273,7 @@ class Jobcard extends BaseController
$this->product_data_maintanence($id, $status);
}
}
}
/********** INSERT COMPLAINT DATA ************/
$complaint_data = $data[0]->complaint;
@ -292,6 +294,7 @@ class Jobcard extends BaseController
$complaint_id = $item->id;
}
if(isset($item->product)) {
// Insert into the product table
$id = [];
foreach ($item->product as $pt) {
@ -315,6 +318,7 @@ class Jobcard extends BaseController
$this->product_data_maintanence($id, $status);
}
}
}
/********** INSERT CUSTOM COMPLAINT DATA ************/
$c_complaint_data = $data[0]->custom_complaint;
@ -326,7 +330,7 @@ class Jobcard extends BaseController
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
if(empty($item->id)) {
if(empty($item->id) || $item->id == "product") {
$JobcardCustomComplaintModel->insert($service);
$cc_complaint_id = $JobcardCustomComplaintModel->getInsertID();
}
@ -335,6 +339,7 @@ class Jobcard extends BaseController
$cc_complaint_id = $item->id;
}
if(isset($item->product)) {
// Insert into the product table
$id = [];
foreach ($item->product as $pt) {
@ -358,6 +363,7 @@ class Jobcard extends BaseController
$this->product_data_maintanence($id, $status);
}
}
}
return redirect()->to('job_card_index');
}

View File

@ -14,25 +14,13 @@ class JobcardModel extends Model
public function getJobCardsWithProductsAndService($logged_user_branch_id)
{
// Select required fields from both tables
// $this->select('job_card.*, COUNT(sales_order_product.job_card_id) AS product_count,vehicle.reg_no');
// $this->select('job_card.*, COUNT(job_card_service.job_card_id) AS product_count, COUNT(job_card_service.job_card_id) AS service_count,vehicle.reg_no');
$this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, vehicle.reg_no');
// Join the sales_order_product table based on job_card_id
$this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
$this->join('job_card_product', 'job_card_product.job_card_id = job_card.job_card_id');
$this->join('vehicle', 'vehicle.vehicle_id = job_card.vehicle_id');
// Group by job_card_id to get count of products per sales order
$this->join('job_card_product', 'job_card_product.job_card_id = job_card.job_card_id', 'left');
$this->join('vehicle', 'vehicle.vehicle_id = job_card.vehicle_id', 'left');
$this->groupBy('job_card.job_card_id');
// Add condition to fetch only active sales orders
$this->where('job_card_service.isactive', 1);
// $this->where('job_card_service.isactive', 1);
$this->where('job_card.isactive', 1);
$this->where('job_card.branch_id',$logged_user_branch_id);
$this->orderBy('job_card.job_card_id','DESC');
// Get the results
return $this->findAll();
}

View File

@ -360,7 +360,7 @@ $(document).ready(async function() {
tr = $('#productItemTable tbody').append(newRow);
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product,tr);
await edit_product_data(value.product);
}
}
@ -400,7 +400,7 @@ $(document).ready(async function() {
$('#productItemTable tbody').append(newRow);
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product,tr);
await edit_product_data(value.product);
}
}
@ -431,11 +431,11 @@ $(document).ready(async function() {
$('#productItemTable tbody').append(newRow);
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product,tr);
await edit_product_data(value.product);
}
}
function edit_product_data(products,tr) {
function edit_product_data(products) {
for (const product of products) {
var newRow = `<tr><td hidden style="width:10%;">
@ -1024,7 +1024,7 @@ $(document).ready(async function() {
'</a>'+
'</div>'+
'</td>' +
'<td hidden><input type="hidden" name="id"></td>' +
'<td hidden><input type="hidden" name="id" value=""></td>' +
'</tr>';