CHANGE_jobcard_module_edit:ss

This commit is contained in:
sriramv 2024-04-29 08:57:58 +05:30
parent 38783d6957
commit b7e1a0314d
3 changed files with 262 additions and 40 deletions

View File

@ -80,19 +80,45 @@ class Jobcard extends BaseController
$JobcardServiceModel = new JobcardServiceModel();
$JobcardComplaintModel = new JobcardComplaintModel();
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
$ComplaintModel = new ComplaintModel();
/*** SERVICE DATA ***/
$servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id'));
foreach ($servicedata as $key => $value) {
// 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();
echo json_encode($product);die;
$value['product'] = $product;
}
$data['editservicedata'] = $servicedata;
/*** 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) {
$product_ids = json_decode($value['product_id'], true);
$product = $JobcardProductModel->whereIn('job_card_product_id', $product_ids)->findAll();
$value['product'] = $product;
}
$data['editcomplaintdata'] = $complaintdata;
/*** 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) {
$product_ids = json_decode($value['product_id'], true);
$product = $JobcardProductModel->whereIn('job_card_product_id', $product_ids)->findAll();
$value['product'] = $product;
}
$data['editccomplaintdata'] = $ccomplaintdata;
$complaint=$ComplaintModel->where('isactive',1)->findAll();
$data['complaint']= $complaint;
$data['page_name']="Edit Job Card";
$ClientModel = new ClientModel();
$client=$ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$JobcardModel = new JobcardModel();
$productdata = $JobcardModel->job_card_edit($job_card_id, $this->session->get('logged_user_branch_id'));
$jobs=$JobcardModel->where('job_card_id', $job_card_id)->get()->getRowArray();
$data['jobs']=$jobs;
@ -130,6 +156,7 @@ class Jobcard extends BaseController
// ->findAll();
$service = $ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
->where('models_id LIKE \'%"' . $modelId . '"%\'', null, false)
->orWhere('category', 0)
->findAll();
$data['product']=$product;
$data['service']=$service;
@ -155,7 +182,7 @@ class Jobcard extends BaseController
public function add_jobs()
{
// echo json_encode($this->request->getPost());die;
// echo $this->request->getPost('products');die;
$JobcardModel = new JobcardModel();
$JobcardProductModel = new JobcardProductModel();
$JobcardServiceModel = new JobcardServiceModel();
@ -185,11 +212,12 @@ class Jobcard extends BaseController
} else {
$JobcardModel->insert($job_card_data);
$job_card_id = $JobcardModel->getInsertID(); // Get the last inserted ID
$orderNumber = 'JC-' . date('md') . '-' . str_pad($job_card_id, 5, '0', STR_PAD_LEFT);
// print_r($orderNumber);die;
// Update sales order with generated order number
$JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
}
$orderNumber = 'JC-' . date('md') . '-' . str_pad($job_card_id, 5, '0', STR_PAD_LEFT);
// print_r($orderNumber);die;
// Update sales order with generated order number
$JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
/********** INSERT SERVICE DATA ************/
$data = json_decode($_POST['products']);
@ -203,8 +231,14 @@ class Jobcard extends BaseController
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
$JobcardServiceModel->insert($service);
$service_id = $JobcardServiceModel->getInsertID();
if($item->id == '') {
$JobcardServiceModel->insert($service);
$service_id = $JobcardServiceModel->getInsertID();
}
else {
$JobcardServiceModel->update($item->id, $service);
$service_id = $item->id;
}
// Insert into the product table
$id = [];
@ -214,8 +248,14 @@ class Jobcard extends BaseController
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount;
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
if($pt->id == '') {
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
}
else {
$JobcardProductModel->update($pt->id, $service);
$job_card_product_id = $item->id;
}
array_push($id, $job_card_product_id);
}
$res = $JobcardServiceModel->update($service_id, ['product_id' => json_encode($id) ]);
@ -234,8 +274,14 @@ class Jobcard extends BaseController
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
$JobcardComplaintModel->insert($service);
$complaint_id = $JobcardComplaintModel->getInsertID();
if($item->id == '') {
$JobcardComplaintModel->insert($service);
$complaint_id = $JobcardComplaintModel->getInsertID();
}
else {
$JobcardComplaintModel->update($item->id, $service);
$complaint_id = $item->id;
}
// Insert into the product table
$id = [];
@ -245,8 +291,14 @@ class Jobcard extends BaseController
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount;
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
if($pt->id == '') {
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
}
else {
$JobcardProductModel->update($pt->id, $service);
$job_card_product_id = $item->id;
}
array_push($id, $job_card_product_id);
}
$res =$JobcardComplaintModel->update($complaint_id, ['product_id' => json_encode($id) ]);
@ -265,8 +317,14 @@ class Jobcard extends BaseController
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
$JobcardCustomComplaintModel->insert($service);
$cc_complaint_id = $JobcardCustomComplaintModel->getInsertID();
if($item->id == '') {
$JobcardCustomComplaintModel->insert($service);
$cc_complaint_id = $JobcardCustomComplaintModel->getInsertID();
}
else {
$JobcardCustomComplaintModel->update($item->id, $service);
$cc_complaint_id = $item->id;
}
// Insert into the product table
$id = [];
@ -276,8 +334,14 @@ class Jobcard extends BaseController
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount;
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
if($pt->id == '') {
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
}
else {
$JobcardProductModel->update($pt->id, $service);
$job_card_product_id = $item->id;
}
array_push($id, $job_card_product_id);
}
$res =$JobcardCustomComplaintModel->update($cc_complaint_id, ['product_id' => json_encode($id) ]);

View File

@ -38,12 +38,32 @@ class JobcardModel extends Model
public function service_data($job_card_id, $logged_user_branch_id)
{
$this->select('job_card.*, job_card_service.*');
$this->select('job_card.job_card_id, job_card_service.*');
$this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
$this->where('job_card_service.isactive', 1);
$this ->where('job_card.job_card_id',$job_card_id);
$this ->where('job_card.branch_id',$logged_user_branch_id);
return $this->findAll();
}
public function complaint_data($job_card_id, $logged_user_branch_id)
{
$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);
return $this->findAll();
}
public function ccomplaint_data($job_card_id, $logged_user_branch_id)
{
$this->select('job_card.job_card_id, job_card_custom_complaint.* , job_card_custom_complaint.complaint_name as name');
$this->join('job_card_custom_complaint', 'job_card_custom_complaint.job_card_id = job_card.job_card_id');
$this->where('job_card_custom_complaint.isactive', 1);
$this ->where('job_card.job_card_id',$job_card_id);
$this ->where('job_card.branch_id',$logged_user_branch_id);
return $this->findAll();
}
}

View File

@ -106,10 +106,9 @@
<th>Qty</th>
<th>Rate</th>
<th>Tax</th>
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
<th>Amount</th>
<th hidden></th>
<th></th>
<th hidden></th>
</tr>
</thead>
<tbody>
@ -326,6 +325,142 @@
<script>
/***** APPEND DATA ONLY EDIT ******/
$(document).ready(async function() {
/** SERVICE */
var edit_service_data = <?php echo isset($editservicedata) ? json_encode($editservicedata) : '' ?>;
// console.log(edit_service_data);
if(edit_service_data.length > 0) {
for (const value of edit_service_data) {
servicearray = <?php echo isset($service_1) ? json_encode($service_1) : json_encode($service) ?>;
// console.log(servicearray);
var newRow = `<tr><td hidden style="width:10%;">
<input type="number" class="form-control labour-cost" name="labour_cost[]"></td>
<td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;">
<option value="">Select a Service</option>`;
for (var i = 0; i < servicearray.length; i++)
{
var service = servicearray[i];
newRow += '<option value="' + service.service_id + '" ' + (value.service_id == service.service_id ? "selected" : "") + '>' + service.service_name + '</option>';
}
newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" value="'+value.amount+'" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" value="'+value.amount+'" name="amount[]"/></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="service" name="item_type" hidden></td>' +
'<td hidden><input name="id" value="'+value.job_card_service_id+'"></td>' +
'</tr>';
tr = $('#productItemTable tbody').append(newRow);
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product,tr);
}
}
/** COMPLAINT */
var edit_complaint_data = <?php echo isset($editcomplaintdata) ? json_encode($editcomplaintdata) : '' ?>;
if(edit_complaint_data.length > 0) {
for (const value of edit_complaint_data) {
complaint = <?php echo json_encode($complaint) ?>;
// console.log(productarray);
var newRow = '<tr><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample complaint" id="complaint_detail" name="complaint_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Complaint</option>';
for (var i = 0; i < complaint.length; i++)
{
var complaints = complaint[i];
newRow += '<option value="' + complaints.complaint_id + '" ' + (value.complaint_id == complaints.complaint_id ? "selected" : "") + '>' + complaints.name + '</option>';
}
newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" value="'+value.amount+'" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" value="'+value.amount+'" name="amount[]"/></td>' +
'<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+
'</div>'+
'<div style="display: inline-block; margin-left: 10px;">'+
'<input value="product" name="item_type" hidden>'+
'<a class="complaint_detail" id="addProduct" title="Add Product">'+
'<i class="fa fa-plus" aria-hidden="true"></i>'+
'</a>'+
'</div>'+
'</td>' +
'<td hidden><input type="hidden" name="id" value="'+value.job_card_complaint_id+'"></td>' +
'</tr>';
$('#productItemTable tbody').append(newRow);
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product,tr);
}
}
/** CUSTOM COMPLAINT */
var edit_ccomplaint_data = <?php echo isset($editcomplaintdata) ? json_encode($editccomplaintdata) : '' ?>;
console.log(edit_ccomplaint_data);
if(edit_ccomplaint_data.length > 0) {
for (const value of edit_ccomplaint_data) {
var newRow = '<tr><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><textarea class="form-control custom-comp" id="custom_complaint_detail" rows="5">'+value.name+'</textarea></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" value="'+value.amount+'" name="unit-price[]" /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" value="'+value.amount+'" name="amount[]"/></td>' +
'<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+
'</div>'+
'<div style="display: inline-block; margin-left: 10px;">'+
'<input value="product" name="item_type" hidden>'+
'<a class="custom_complaint_detail" id="addProduct" title="Add Product">'+
'<i class="fa fa-plus" aria-hidden="true"></i>'+
'</a>'+
'</div>'+
'</td>' +
'<td hidden><input type="hidden" name="id" value="'+value.job_card_cc_id+'"></td>' +
'</tr>';
$('#productItemTable tbody').append(newRow);
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product,tr);
}
}
function edit_product_data(products,tr) {
for (const product of products) {
var newRow = `<tr><td hidden style="width:10%;">
<input type="number" class="form-control labour-cost" name="labour_cost[]"></td>
<td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i>
<select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" style="width: 249px !important;">`;
newRow += '<option value="' + product.product_id + '" selected>' + product.name + '</option>';
newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="' + product.qty + '" name="quantity[]"/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="' + product.amount + '" readonly /></td>' +
'<td style="width:8%;"> <input type="text" class="form-control item-tax" name="item-tax[]" value="' + product.tax + '" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + product.amount + '" readonly/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td hidden><input type="hidden" name="id" value="'+product.job_card_product_id+'"></td>' +
'</tr>';
$('#productItemTable tbody').append(newRow);
// $(newRow).insertAfter(tr);
initializeSelect2();
}
}
});
productarray = [];
servicearray = [];
@ -397,8 +532,8 @@
});
<?php
$product_json = json_encode($product_1);
$service_json = json_encode($service_1);
$product_json = isset($product_1) ? json_encode($product_1) : json_encode($product);
$service_json = isset($service_1) ? json_encode($service_1) : json_encode($service);
?>
@ -441,12 +576,14 @@
var thirdTd = row.querySelector("td:nth-child(3)");
var fifthTd = row.querySelector("td:nth-child(5)");
var sixthTd = row.querySelector("td:nth-child(6)");
var eigthTd = row.querySelector("td:nth-child(8)");
// Check if the second <td> element contains a <select> element
var selectElement = secondTd.querySelector("select, textarea");
var selectThirdElement = thirdTd.querySelector("input");
var selectFifthElement = fifthTd.querySelector("input");
var selectsixthElement = sixthTd.querySelector("input");
var selecteightElement = eigthTd.querySelector("input");
if (selectElement) {
// Get the class name of the <select> element
@ -457,36 +594,36 @@
var quality = selectThirdElement.value;
var tax = selectFifthElement.value;
var amount = selectsixthElement.value;
var id = selecteightElement.value;
// Output the class name and selected value
// console.log("Class Name: " + className + ", Selected Value: " + selectedValue);
if (className.includes("product"))
{
if(mapTable == "service") {
addProductToLastObjectByKey(dataMapArray, "service", [{ 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
addProductToLastObjectByKey(dataMapArray, "service", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
}
else if(mapTable == "complaint") {
addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
}
else if(mapTable == "custom-comp") {
addProductToLastObjectByKey(dataMapArray, "custom_complaint", [{ 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
addProductToLastObjectByKey(dataMapArray, "custom_complaint", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
}
}
else if(className.includes("service"))
{
mapTable = "service";
dataMapArray[0].service.push({ 'service_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
dataMapArray[0].service.push({'id': id, 'service_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
}
else if(className.includes("complaint"))
{
mapTable = "complaint";
dataMapArray[0].complaint.push({ 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
dataMapArray[0].complaint.push({ 'id': id, 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
}
else if(className.includes("custom-comp"))
{
mapTable = "custom-comp";
dataMapArray[0].custom_complaint.push({ 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
dataMapArray[0].custom_complaint.push({ 'id': id, 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
}
}
});
@ -677,7 +814,7 @@
'<td style="width:8%;"> <input type="text" class="form-control item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + product.unit_price + '" readonly/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td></td>' +
'<td hidden><input type="hidden" name="id" value=""></td>' +
'</tr>';
@ -773,7 +910,6 @@
// Event listener for "Add More Item" button
$(document).on('click', '#addProduct', function() {
var newRow = '<tr><td hidden style="width:10%;"><input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
for (var i = 0; i < productarray.length; i++)
@ -787,8 +923,8 @@
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
'<td hidden><input type="hidden" name="id"></td>' +
'</tr>';
@ -800,7 +936,8 @@
});
$('#addService').click(function() {
servicearray = <?php echo json_encode($service_1) ?>;
alert('dzfaf')
servicearray = <?php echo isset($service_1) ? json_encode($service_1) : json_encode($service) ?>;
// console.log(servicearray);
var newRow = '<tr><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Service</option>';
@ -815,8 +952,8 @@
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td hidden></td><td hidden><input type="hidden"></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="service" name="item_type" hidden></td>' +
'<td hidden><input type="hidden" name="id"></td>' +
'</tr>';
@ -842,7 +979,6 @@
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+
'</div>'+
@ -852,7 +988,8 @@
'<i class="fa fa-plus" aria-hidden="true"></i>'+
'</a>'+
'</div>'+
'</td>' +
'</td>' +
'<td hidden><input type="hidden" name="id"></td>' +
'</tr>';
@ -880,7 +1017,8 @@
'<i class="fa fa-plus" aria-hidden="true"></i>'+
'</a>'+
'</div>'+
'</td>' +
'</td>' +
'<td hidden><input type="hidden" name="id"></td>' +
'</tr>';