CHANGE_jobcard_view_calculations:ss

This commit is contained in:
sriramv 2024-05-04 17:22:07 +05:30
parent c8d877f52b
commit 17118912c3
7 changed files with 215 additions and 144 deletions

View File

@ -406,7 +406,7 @@ class Jobcard extends BaseController
$product['product_id'] = $pt->p_id; $product['product_id'] = $pt->p_id;
$product['qty'] = $pt->qty; $product['qty'] = $pt->qty;
$product['tax'] = $pt->tax; $product['tax'] = $pt->tax;
$product['amount'] = $pt->amount; $product['amount'] = $pt->amount / $pt->qty;
if(empty($pt->id)) { if(empty($pt->id)) {
$JobcardProductModel->insert($product); $JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID(); $job_card_product_id = $JobcardProductModel->getInsertID();

View File

@ -36,7 +36,7 @@ class Products extends BaseController
return view('product_list',$data); return view('product_list',$data);
} else { } else {
$ProductModel = new ProductModel(); $ProductModel = new ProductModel();
$products = $ProductModel->where('branch_id',$this->session->get('logged_user_branch_id'))->orderBy('product_name')->findAll(); $products = $ProductModel->get_products($this->session->get('logged_user_branch_id'));
$data['products']=$products; $data['products']=$products;
// echo "<pre>"; // echo "<pre>";
// print_r($products);die; // print_r($products);die;

View File

@ -353,7 +353,7 @@ public function delete_sales_product()
// return view('invoice_pdf_template', ['sales' => $data,'items'=>$items, 'business' => $business , 'vehicle' => $vehicle,'bike_model'=>$bike_model,'bike_make'=>$bike_make]); // return view('invoice_pdf_template', ['sales' => $data,'items'=>$items, 'business' => $business , 'vehicle' => $vehicle,'bike_model'=>$bike_model,'bike_make'=>$bike_make]);
// Generate the PDF content (HTML) with data // Generate the PDF content (HTML) with data
$html = view('invoice_pdf_template', ['sales' => $data,'company_address'=>$company_address,'items'=>$items, 'business' => $business , 'vehicle' => $vehicle,'bike_model'=>$bike_model,'bike_make'=>$bike_make]); $html = view('invoice_pdf_template', ['sales' => $data,'company_address'=>$company_address,'items'=>$items, 'business' => $business , 'vehicle' => $vehicle,'bike_model'=>$bike_model,'bike_make'=>$bike_make]);
// echo $html;die;
// Load HTML into the mPDF instance // Load HTML into the mPDF instance
$mpdf->WriteHTML($html); $mpdf->WriteHTML($html);

View File

@ -33,6 +33,7 @@ class ProductModel extends Model
$this->select('products.*, manufacturer.manufacturer_name'); $this->select('products.*, manufacturer.manufacturer_name');
$this->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id'); $this->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id');
$this->where('products.branch_id', $branch_id); $this->where('products.branch_id', $branch_id);
$this->orderBy('products.product_name');
return $this->findAll(); return $this->findAll();
} }

View File

@ -161,7 +161,7 @@
<td style="border-right: 0.5px solid black;"><?= $item->product_name ?></td> <td style="border-right: 0.5px solid black;"><?= $item->product_name ?></td>
<td style="border-right: 0.5px solid black;"> <?php echo number_format($amountWithoutTax, 2, '.', ','); ?></td> <td style="border-right: 0.5px solid black;"> <?php echo number_format($amountWithoutTax, 2, '.', ','); ?></td>
<td style="border-right: 0.5px solid black;"><?= $item->qty ?></td> <td style="border-right: 0.5px solid black;"><?= $item->qty ?></td>
<td style="border-right: 0.5px solid black;"></td> <td style="border-right: 0.5px solid black;">nos</td>
<td style="border-right: 0.5px solid black;"><?= $item->tax ?>%</td> <td style="border-right: 0.5px solid black;"><?= $item->tax ?>%</td>
<td style="border-right: 0.5px solid black;"><?php echo $value_tax /2;?> <td style="border-right: 0.5px solid black;"><?php echo $value_tax /2;?>
</td> </td>
@ -174,22 +174,22 @@
<tr> <tr>
<td colspan="6" style="border-top: 0.5px solid black;border-left: 0.5px solid black;"></td> <td colspan="6" style="border-top: 0.5px solid black;border-left: 0.5px solid black;"></td>
<td colspan="3" style="text-align:center;border: 0.5px solid black;">Total Taxable Value</td> <td colspan="3" style="text-align:center;border: 0.5px solid black;">Total Taxable Value</td>
<td style="border: 0.5px solid black;"></td> <td style="border: 0.5px solid black;"><?= $sales[0]->tax ?></td>
</tr> </tr>
<tr> <tr>
<td colspan="6" style="border-left: 0.5px solid black;"></td> <td colspan="6" style="border-left: 0.5px solid black;"></td>
<td colspan="3" style="text-align:center;border: 0.5px solid black;">CGST</td> <td colspan="3" style="text-align:center;border: 0.5px solid black;">CGST</td>
<td style="border: 0.5px solid black;"></td> <td style="border: 0.5px solid black;"><?= $sales[0]->tax / 2 ?></td>
</tr> </tr>
<tr> <tr>
<td colspan="6" style="border-left: 0.5px solid black;"></td> <td colspan="6" style="border-left: 0.5px solid black;"></td>
<td colspan="3" style="text-align:center;border: 0.5px solid black;">SGST</td> <td colspan="3" style="text-align:center;border: 0.5px solid black;">SGST</td>
<td style="border: 0.5px solid black;"></td> <td style="border: 0.5px solid black;"><?= $sales[0]->tax / 2 ?></td>
</tr> </tr>
<tr> <tr>
<td colspan="6" style="border-left: 0.5px solid black;"></td> <td colspan="6" style="border-left: 0.5px solid black;"></td>
<td colspan="3" style="text-align:center;border: 0.5px solid black;">Total</td> <td colspan="3" style="text-align:center;border: 0.5px solid black;">Total</td>
<td style="border: 0.5px solid black;"></td> <td style="border: 0.5px solid black;"><?= $sales[0]->total ?></td>
</tr> </tr>
<tr> <tr>
<td colspan="10" style="border: 0.5px solid black;">Amount Chargeable (in words)</td> <td colspan="10" style="border: 0.5px solid black;">Amount Chargeable (in words)</td>

View File

@ -85,6 +85,7 @@
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option> <option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option> <option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
<?php else: ?> <?php else: ?>
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option> <option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
<option value="Cancelled" <?= $jobs['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option> <option value="Cancelled" <?= $jobs['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
<?php endif; ?> <?php endif; ?>
@ -130,9 +131,10 @@
<tr> <tr>
<th hidden></th> <th hidden></th>
<th>Item Details</th> <th>Item Details</th>
<th>Qty</th>
<th>Rate</th> <th>Rate</th>
<th>Tax</th> <th hidden></th>
<th>Qty</th>
<th>Tax (%)</th>
<th>Amount</th> <th>Amount</th>
<th style="width: 10px;">Action</th> <th style="width: 10px;">Action</th>
<th hidden></th> <th hidden></th>
@ -311,22 +313,22 @@ $(document).ready(async function() {
// console.log(servicearray); // console.log(servicearray);
var newRow = `<tr class="service_class"><td hidden style="width:10%;"> var newRow = `<tr class="service_class"><td hidden style="width:10%;">
<input type="number" class="form-control labour_cost" name="labour_cost" value="${value.labour_cost}"></td> <input type="number" class="form-control labour_cost" name="labour_cost" value="${value.labour_cost}"></td>
<td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;"> <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++) for (var i = 0; i < servicearray.length; i++)
{ {
var service = servicearray[i]; var service = servicearray[i];
if(value.service_id == service.service_id)
newRow += '<option value="' + service.service_id + '" ' + (value.service_id == service.service_id ? "selected" : "") + '>' + service.service_name + '</option>'; newRow += '<option value="' + service.service_id + '" ' + (value.service_id == service.service_id ? "selected" : "") + '>' + service.service_name + '</option>';
} }
newRow += '</select></td>' + 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 hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" 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:10%;"><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" 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:8%;"><input hidden 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 style="width:12%;"><input hidden type="text" class="form-control item-amount1" 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><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>' + '<td hidden><input name="id" value="'+value.job_card_service_id+'"></td>' +
'</tr>'; '</tr>';
@ -336,7 +338,7 @@ $(document).ready(async function() {
initializeSelect2(); initializeSelect2();
/** APPEND CHILD PRODUCT */ /** APPEND CHILD PRODUCT */
await edit_product_data(value.product); await edit_product_data(value.product);
editlabourcost(value.labour_cost); editlabourcost(value,'service_lb');
} }
} }
@ -346,19 +348,20 @@ $(document).ready(async function() {
for (const value of edit_complaint_data) { for (const value of edit_complaint_data) {
complaint = <?php echo json_encode($complaint) ?>; complaint = <?php echo json_encode($complaint) ?>;
// console.log(productarray); // console.log(productarray);
var newRow = '<tr class="complaint_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour_cost" name="labour_cost" value="'+value.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>'; var newRow = '<tr class="complaint_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour_cost" name="labour_cost" value="'+value.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;">';
for (var i = 0; i < complaint.length; i++) for (var i = 0; i < complaint.length; i++)
{ {
var complaints = complaint[i]; var complaints = complaint[i];
if(value.complaint_id == complaints.complaint_id)
newRow += '<option value="' + complaints.complaint_id + '" ' + (value.complaint_id == complaints.complaint_id ? "selected" : "") + '>' + complaints.name + '</option>'; newRow += '<option value="' + complaints.complaint_id + '" ' + (value.complaint_id == complaints.complaint_id ? "selected" : "") + '>' + complaints.name + '</option>';
} }
newRow += '</select></td>' + 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 hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" 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:10%;"><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" 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:8%;"><input hidden 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 style="width:12%;"><input hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></td>' +
'<td><div style="display: inline-block;">'+ '<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+ '<center><i class="fa fa-trash remove-item"></i></center>'+
'</div>'+ '</div>'+
@ -377,7 +380,7 @@ $(document).ready(async function() {
initializeSelect2(); initializeSelect2();
/** APPEND CHILD PRODUCT */ /** APPEND CHILD PRODUCT */
await edit_product_data(value.product); await edit_product_data(value.product);
editlabourcost(value.labour_cost) editlabourcost(value,'complaint_lb')
} }
} }
@ -386,10 +389,10 @@ $(document).ready(async function() {
if(edit_ccomplaint_data.length > 0) { if(edit_ccomplaint_data.length > 0) {
for (const value of edit_ccomplaint_data) { for (const value of edit_ccomplaint_data) {
var newRow = '<tr class="custom_complaint_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour_cost" name="labour_cost" value="'+value.labour_cost+'"></td><td><textarea class="form-control custom-comp" id="custom_complaint_detail" rows="5">'+value.name+'</textarea></td>' + var newRow = '<tr class="custom_complaint_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour_cost" name="labour_cost" value="'+value.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 hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" /></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" value="'+value.amount+'" name="unit-price[]" /></td>' + '<td style="width:10%;"><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" /></td>' + '<td style="width:8%;"><input hidden 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 style="width:12%;"><input hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></td>' +
'<td><div style="display: inline-block;">'+ '<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+ '<center><i class="fa fa-trash remove-item"></i></center>'+
'</div>'+ '</div>'+
@ -408,21 +411,21 @@ $(document).ready(async function() {
initializeSelect2(); initializeSelect2();
/** APPEND CHILD PRODUCT */ /** APPEND CHILD PRODUCT */
await edit_product_data(value.product); await edit_product_data(value.product);
editlabourcost(value.labour_cost) editlabourcost(value,'custom_complaint_lb')
} }
} }
function editlabourcost(data) { function editlabourcost(data,cls) {
var newRow = '<tr class="dummy"><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><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' + total_wih_tax = parseInt(data.labour_cost) + (parseInt(data.labour_cost) * (data.tax / 100));
'<td style="width:10%;"></td>' + var newRow = '<tr class="'+cls+'"><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><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' +
'<td style="width:10%;"></td>' + '<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="'+data.labour_cost+'" /></td>' +
'<td style="width:8%;"></td>' + '<td style="width:10%;"><input type="number" class="form-control item-quantity-'+cls+' item-quantity" min="0" name="quantity[]" value="'+1+'" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount1" name="amount1[]" value="' + data + '" readonly/></td>' + '<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" value="'+data.tax+'" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + total_wih_tax + '"/></td>' +
'<td hidden></td>' + '<td hidden></td>' +
'<td hidden></td>' + '<td hidden></td>' +
'</tr>'; '</tr>';
$('#productItemTable tbody').append(newRow); $('#productItemTable tbody').append(newRow);
// $(newRow).insertAfter(tr); // $(newRow).insertAfter(tr);
initializeSelect2(); initializeSelect2();
@ -431,16 +434,17 @@ $(document).ready(async function() {
function edit_product_data(products) { function edit_product_data(products) {
for (const product of products) { 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> total_wih_tax = parseInt(product.amount) + (parseInt(product.amount) * (product.tax / 100));
var newRow = `<tr class="product"><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> <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;">`; <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.pname + '</option>'; newRow += '<option value="' + product.product_id + '" selected>' + product.pname + '</option>';
newRow += '</select></td>' + 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:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="' + product.amount + '" readonly /></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="' + product.qty + '" name="quantity[]"/></td>' +
'<td style="width:8%;"> <input type="text" class="form-control item-tax" name="item-tax[]" value="' + product.tax + '" 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 style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + total_wih_tax + '" readonly/></td>' +
'<td hidden><input type="hidden"></td>' + '<td hidden><input type="hidden"></td>' +
'<td hidden><input type="hidden" name="id" value="'+product.job_card_product_id+'"></td>' + '<td hidden><input type="hidden" name="id" value="'+product.job_card_product_id+'"></td>' +
'</tr>'; '</tr>';
@ -568,9 +572,9 @@ $(document).ready(async function() {
tableRows.forEach(function(row) { tableRows.forEach(function(row) {
var firstTd = row.querySelector("td:nth-child(1)"); var firstTd = row.querySelector("td:nth-child(1)");
var secondTd = row.querySelector("td:nth-child(2)"); var secondTd = row.querySelector("td:nth-child(2)");
var thirdTd = row.querySelector("td:nth-child(3)"); var thirdTd = row.querySelector("td:nth-child(4)");
var fifthTd = row.querySelector("td:nth-child(5)"); var fifthTd = row.querySelector("td:nth-child(5)");
var sixthTd = row.querySelector("td:nth-child(6)"); var sixthTd = row.querySelector("td:nth-child(3)");
var eigthTd = row.querySelector("td:nth-child(8)"); var eigthTd = row.querySelector("td:nth-child(8)");
// Check if the second <td> element contains a <select> element // Check if the second <td> element contains a <select> element
@ -707,13 +711,14 @@ $(document).ready(async function() {
// Access unit price from product and set it as rate // Access unit price from product and set it as rate
var unitPrice = parseInt(service_data.price); // Convert to float if necessary var unitPrice = parseInt(service_data.price); // Convert to float if necessary
console.log(service_data); console.log(service_data);
$(this).closest('tr').find('.item-rate').val(unitPrice); $(this).closest('tr').find('.item-rate1').val(unitPrice);
$(this).closest('tr').find('.item-tax').val(Number(service_data.tax));
$(this).closest('tr').find('.labour_cost').val(parseInt(service_data.labour_cost)); $(this).closest('tr').find('.labour_cost').val(parseInt(service_data.labour_cost));
await labourcost(service_data.labour_cost,$(this).closest('tr')); await labourcost(service_data.labour_cost,service_data.tax,$(this).closest('tr'),'service_lb');
service_child_products(service_data,$(this).closest('tr')) service_child_products(service_data,$(this).closest('tr'))
} }
calculateAmount($(this).closest('tr'),className); calculateAmount($(this).closest('tr'),className,'parent');
updateCalculations(); updateCalculations();
}); });
@ -732,22 +737,21 @@ $(document).ready(async function() {
// Access unit price from product and set it as rate // Access unit price from product and set it as rate
var unitPrice = parseInt(complaint_data.labour_charge); // Convert to float if necessary var unitPrice = parseInt(complaint_data.labour_charge); // Convert to float if necessary
$(this).closest('tr').find('.item-rate').val(unitPrice); $(this).closest('tr').find('.item-rate1').val(unitPrice);
$(this).closest('tr').find('.item-tax').val(Number(complaint_data.tax));
$(this).closest('tr').find('.labour_cost').val(parseInt(complaint_data.labour_charge)); $(this).closest('tr').find('.labour_cost').val(parseInt(complaint_data.labour_charge));
await labourcost(complaint_data.labour_charge,$(this).closest('tr')); await labourcost(complaint_data.labour_charge,complaint_data.tax,$(this).closest('tr'),'complaint_lb');
} }
calculateAmount($(this).closest('tr'),className); calculateAmount($(this).closest('tr'),'complaint','parent');
updateCalculations(); updateCalculations();
}); });
// Function to calculate amount based on rate and quantity // Function to calculate amount based on rate and quantity
function calculateAmount(row,type) { function calculateAmount(row,type,action) {
// console.log(row); console.log(type);
var rate = $(row).find('.item-rate').val(); var rate = $(row).find('.item-rate').val();
var quantity = $(row).find('.item-quantity').val(); var quantity = $(row).find('.item-quantity').val();
var amount = rate * quantity;
$(row).find('.item-amount').val(amount);
// Retrieve CGST and SGST values from the database for the selected product // Retrieve CGST and SGST values from the database for the selected product
var productId = $(row).find('select[name="item_details[]"]').val(); var productId = $(row).find('select[name="item_details[]"]').val();
@ -762,48 +766,76 @@ $(document).ready(async function() {
// Calculate total tax by adding CGST and SGST // Calculate total tax by adding CGST and SGST
var tax = cgst + sgst; var tax = cgst + sgst;
$(row).find('.item-tax').val(tax.toFixed(2)); $(row).find('.item-tax').val(tax.toFixed(2));
finrate = Number(product.unit_price) * quantity;
$(row).find('.item-rate').val(finrate);
rate = Number(product.unit_price);
var amount = (parseInt(rate) + (parseInt(rate) * tax / 100)) * quantity;
$(row).find('.item-amount').val(amount);
} }
else if(type.includes("service")) { else if(type.includes("service")) {
var productId = $(row).find('select[name="service_details[]"]').val(); // var productId = $(row).find('select[name="service_details[]"]').val();
var product = services.find(function(item) { // var product = services.find(function(item) {
return item.service_id == productId; // return item.service_id == productId;
}); // });
var cgst = parseFloat(product.cgst); // var cgst = parseFloat(product.cgst);
var igst = parseFloat(product.sgst); // var igst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST // // Calculate total tax by adding CGST and SGST
var tax = cgst + igst; // var tax = cgst + igst;
console.log(tax); // console.log(tax);
$(row).find('.item-tax').val(tax.toFixed(2)); if(action == 'parent') var $previousRow = row;
else var $previousRow = row.prevAll(".service_class").first();
var tax = $previousRow.find('.item-tax').val();
$(row).find('.item-tax').val(parseInt(tax).toFixed(2));
var $targetField = $previousRow.find('.item-rate1');
finrate = parseInt($targetField.val()) * quantity;
rate = $targetField.val();
$(row).find('.item-rate').val(finrate);
var amount = (parseInt(rate) + (parseInt(rate) * tax / 100)) *quantity;
$(row).find('.item-amount').val(amount);
} }
else if(type.includes("complaint")) { else if(type.includes("complaint")) {
var productId = $(row).find('select[name="complaint_details[]"]').val(); // var productId = $(row).find('select[name="complaint_details[]"]').val();
var product = complaint.find(function(item) { // var product = complaint.find(function(item) {
return item.complaint_id == productId; // return item.complaint_id == productId;
}); // });
console.log(product); // console.log(product);
var cgst = parseFloat(product.cgst); // var cgst = parseFloat(product.cgst);
var igst = parseFloat(product.sgst); // var igst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST // // Calculate total tax by adding CGST and SGST
var tax = cgst + igst; // var tax = cgst + igst;
$(row).find('.item-tax').val(tax.toFixed(2)); if(action == 'parent') var $previousRow = row;
else var $previousRow = row.prevAll(".complaint_class").first();
var tax = $previousRow.find('.item-tax').val();
$(row).find('.item-tax').val(parseInt(tax).toFixed(2));
var $targetField = $previousRow.find('.item-rate1');
finrate = parseInt($targetField.val()) * quantity;
$(row).find('.item-rate').val(finrate);
rate = $targetField.val();
var amount = (parseInt(rate) + (parseInt(rate) * tax / 100)) *quantity;
$(row).find('.item-amount').val(amount);
} }
} }
const labourcost = async (data,tr) => { const labourcost = async (cost,tax,tr,cls) => {
var newRow = '<tr class="dummy"><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><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' + total_wih_tax = parseInt(cost) + (parseInt(cost) * (tax / 100));
'<td style="width:10%;"></td>' + var newRow = '<tr class="'+cls+'"><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><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' +
'<td style="width:10%;"></td>' + '<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="'+cost+'" /></td>' +
'<td style="width:8%;"></td>' + '<td style="width:10%;"><input type="number" class="form-control item-quantity-'+cls+' item-quantity" min="0" name="quantity[]" value="'+1+'" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount1" name="amount1[]" value="' + data + '" readonly/></td>' + '<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" value="'+tax+'" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + total_wih_tax + '"/></td>' +
'<td hidden></td>' + '<td hidden></td>' +
'<td hidden></td>' + '<td hidden></td>' +
'</tr>'; '</tr>';
// $('#productItemTable tbody').append(newRow);
$(newRow).insertAfter(tr); $(newRow).insertAfter(tr);
initializeSelect2(); initializeSelect2();
} }
@ -820,14 +852,14 @@ $(document).ready(async function() {
var sgst = parseFloat(product.sgst); var sgst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST // Calculate total tax by adding CGST and SGST
var tax = cgst + sgst; var tax = cgst + sgst;
total_wih_tax = parseInt(product.unit_price) + (parseInt(product.unit_price) * (tax / 100));
var newRow = '<tr class="product"><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;">'; var newRow = '<tr class="product"><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 + '">' + product.product_name + '</option>'; newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
newRow += '</select></td>' + newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="' + product.unit_price + '" readonly /></td>' + '<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="' + product.unit_price + '" readonly /></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' +
'<td style="width:8%;"> <input type="text" class="form-control item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' + '<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-amount1" name="amount1[]" value="' + product.unit_price + '" readonly/></td>' + '<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount1[]" value="' + total_wih_tax + '" readonly/></td>' +
'<td hidden><input type="hidden"></td>' + '<td hidden><input type="hidden"></td>' +
'<td hidden><input type="hidden" name="id" value=""></td>' + '<td hidden><input type="hidden" name="id" value=""></td>' +
'</tr>'; '</tr>';
@ -841,19 +873,15 @@ $(document).ready(async function() {
} }
// Event listener for quantity change // Event listener for quantity change
$(document).on('input change', '.item-quantity', async function() { $(document).on('input', '.item-quantity', async function() {
calculateAmount($(this).closest('tr')); calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child');
updateCalculations();
});
$(document).on('click', '.item-quantity', async function() {
updateCalculations(); updateCalculations();
}); });
// Function to calculate subtotal // Function to calculate subtotal
function calculateSubtotal() { function calculateSubtotal() {
var subtotal = 0; var subtotal = 0;
$('.item-amount').each(function() { $('.item-rate').each(function() {
subtotal += parseFloat($(this).val()) || 0; subtotal += parseFloat($(this).val()) || 0;
}); });
return subtotal; return subtotal;
@ -861,14 +889,16 @@ $(document).ready(async function() {
// Function to calculate total tax // Function to calculate total tax
function calculateTax() { function calculateTax() {
var tax = 0; var subtotal = 0;
$('.item-tax').each(function() { $('.item-rate').each(function() {
var taxPercentage = parseFloat($(this).val()) || 0; subtotal += parseFloat($(this).val()) || 0;
var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value
tax += taxValue;
}); });
return tax;
var total = 0;
$('.item-amount').each(function() {
total += parseFloat($(this).val()) || 0;
});
return total - subtotal;
} }
// Function to calculate total discount // Function to calculate total discount
@ -890,12 +920,11 @@ $(document).ready(async function() {
// Function to calculate total // Function to calculate total
function calculateTotal() { function calculateTotal() {
var subtotal = calculateSubtotal(); var total = 0;
var tax = calculateTax(); $('.item-amount').each(function() {
var discount = calculateDiscount(); total += parseFloat($(this).val()) || 0;
var total = subtotal + tax - discount; });
// return total; return total;
return Math.round(total);
} }
// Update subtotal, tax, and total // Update subtotal, tax, and total
@ -928,8 +957,8 @@ $(document).ready(async function() {
} }
newRow += '</select></td>' + newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' + '<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" 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 style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' + '<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
@ -955,10 +984,10 @@ $(document).ready(async function() {
} }
newRow += '</select></td>' + newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' + '<td style="width:10%;"><input hidden type="text" class="form-control item-rate1" name="unit-price[]" readonly /></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' + '<td style="width:10%;"><input hidden type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' + '<td style="width:8%;"><input hidden 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 style="width:12%;"><input hidden type="text" class="form-control item-amount1" name="amount[]"/></td>' +
'<td><center><i class="fa fa-trash remove-item" id="remove-item"></i></center><input value="service" name="item_type" hidden></td>' + '<td><center><i class="fa fa-trash remove-item" id="remove-item"></i></center><input value="service" name="item_type" hidden></td>' +
'<td hidden><input type="hidden" name="id"></td>' + '<td hidden><input type="hidden" name="id"></td>' +
'</tr>'; '</tr>';
@ -971,6 +1000,19 @@ $(document).ready(async function() {
} }
}); });
/** To achieve this functionality where entering a value in one input field automatically populates another input field
* ONLY APPLICABLE IN COMPLAINT ONLY
*/
$(document).ready(function() {
/** TAX FIELD */
$(document).on('input change', '.item-quantity-service_lb', async function() {
var enteredValue = $(this).val();
var $previousRow = $(this).closest("tr").prevAll(".service_class").first();
var $targetField = $previousRow.find('.item-quantity');
$targetField.val(enteredValue);
});
});
$('#addcomplaint').click(function() { $('#addcomplaint').click(function() {
complaint = <?php echo json_encode($complaint) ?>; complaint = <?php echo json_encode($complaint) ?>;
var newRow = '<tr class="complaint_class"><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>'; var newRow = '<tr class="complaint_class"><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>';
@ -982,10 +1024,10 @@ $(document).ready(async function() {
} }
newRow += '</select></td>' + newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' + '<td style="width:10%;"><input hidden type="text" class="form-control item-rate1" name="unit-price[]" readonly /></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' + '<td style="width:10%;"><input hidden type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' + '<td style="width:8%;"><input hidden 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 style="width:12%;"><input hidden type="text" class="form-control item-amount1" name="amount[]"/></td>' +
'<td><div style="display: inline-block;">'+ '<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+ '<center><i class="fa fa-trash remove-item"></i></center>'+
'</div>'+ '</div>'+
@ -1001,14 +1043,26 @@ $(document).ready(async function() {
$('#productItemTable tbody').append(newRow); $('#productItemTable tbody').append(newRow);
initializeSelect2(); initializeSelect2();
}); });
/** To achieve this functionality where entering a value in one input field automatically populates another input field
* ONLY APPLICABLE IN COMPLAINT ONLY
*/
$(document).ready(function() {
/** TAX FIELD */
$(document).on('input change', '.item-quantity-complaint_lb', async function() {
var enteredValue = $(this).val();
var $previousRow = $(this).closest("tr").prevAll(".complaint_class").first();
var $targetField = $previousRow.find('.item-quantity');
$targetField.val(enteredValue);
});
});
$('#addCustomComplaint').click(function() { $('#addCustomComplaint').click(function() {
complaint = <?php echo json_encode($complaint) ?>; complaint = <?php echo json_encode($complaint) ?>;
var newRow = '<tr class="custom_complaint_class"><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"></textarea></td>' + var newRow = '<tr class="custom_complaint_class"><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"></textarea></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' + '<td style="width:10%;"><input hidden type="text" class="form-control item-rate1" name="unit-price[]" /></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" /></td>' + '<td style="width:10%;"><input hidden type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" /></td>' + '<td style="width:8%;"><input hidden type="text" class="form-control item-tax" name="item-tax[]" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' + '<td style="width:12%;"><input hidden type="text" class="form-control item-amount1" name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' + '<td hidden><input type="hidden"></td>' +
'<td><div style="display: inline-block;">'+ '<td><div style="display: inline-block;">'+
'<center><i class="fa fa-trash remove-item"></i></center>'+ '<center><i class="fa fa-trash remove-item"></i></center>'+
@ -1023,38 +1077,52 @@ $(document).ready(async function() {
'<td hidden><input type="hidden" name="id" value=""></td>' + '<td hidden><input type="hidden" name="id" value=""></td>' +
'</tr>'; '</tr>';
newRow += '<tr class="dummy"><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><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' + newRow += '<tr class="custom_complaint_lb"><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><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' +
'<td style="width:10%;"></td>' + '<td style="width:10%;"><input type="text" class="form-control item-rate item-rate_cc" name="unit-price[]" value="" /></td>' +
'<td style="width:10%;"></td>' + '<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]" value="'+1+'" /></td>' +
'<td style="width:8%;"></td>' + '<td style="width:8%;"><input type="text" class="form-control item-tax item-tax_cc" name="item-tax[]" /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount1 item_dummy" name="amount1[]" value="0"/></td>' + '<td style="width:12%;"><input type="text" class="form-control item-amount item-amount_cc" name="amount1[]" value=""/></td>' +
'<td hidden></td>' + '<td hidden></td>' +
'<td hidden></td>' + '<td hidden></td>' +
'</tr>'; '</tr>';
$('#productItemTable tbody').append(newRow); $('#productItemTable tbody').append(newRow);
initializeSelect2(); initializeSelect2();
// Function to increment class name And this Class name for for remove the parent Custom Comlaint is remove the child to remove
function incrementClassName(className) {
var classNumber = parseInt(className.match(/\d+/)[0]);
return className.replace(/\d+/, classNumber + 1);
}
// Initial class name
var initialClassName = 'custom_complaint_class';
var currentClassName;
// Loop to check for existence of subsequent classes
for (var i = 2000; i <= 2100; i++) {
currentClassName = initialClassName + '_' + i;
if ($('.' + currentClassName).length === 0) {
// If the class doesn't exist, increment the last found class
$('.' + initialClassName).removeClass(initialClassName).addClass(currentClassName);
break;
}
}
}); });
/** To achieve this functionality where entering a value in one input field automatically populates another input field
* ONLY APPLICABLE IN CUSTOM COMPLAINT ONLY
*/
$(document).ready(function() {
/** RATE FIELD */
$(document).on('input change', '.item-rate_cc', async function() {
var enteredValue = $(this).val();
var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
var $targetField = $previousRow.find('.item-rate1');
$targetField.val(enteredValue);
var $targetField2 = $previousRow.find('.labour_cost');
$targetField2.val(enteredValue);
updateCalculations();
});
/** TAX FIELD */
$(document).on('input change', '.item-tax_cc', async function() {
var enteredValue = $(this).val();
var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
var $targetField = $previousRow.find('.item-tax');
$targetField.val(enteredValue);
updateCalculations();
});
/** AMOUNT FIELD */
$(document).on('input change', '.item-amount_cc', async function() {
var enteredValue = $(this).val();
var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
var $targetField = $previousRow.find('.item-amount1');
$targetField.val(enteredValue);
updateCalculations();
});
});
$(document).on('input', '.item_dummy', function() { $(document).on('input', '.item_dummy', function() {
var row = $(this).closest('tr'); var row = $(this).closest('tr');
var labourCostInput = row.prevAll('.custom_complaint_class:first').find('.labour_cost'); var labourCostInput = row.prevAll('.custom_complaint_class:first').find('.labour_cost');
@ -1062,7 +1130,9 @@ $(document).ready(async function() {
labourCostInput.val(dummyValue); labourCostInput.val(dummyValue);
}); });
/** REMOVE ITEMS FROM THE TABLE **/ /**
* REMOVE ITEMS FROM THE TABLE
* **/
delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [] }]; delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [] }];
$(document).on('click', '.remove-item', function() { $(document).on('click', '.remove-item', function() {
var $closestTR = $(this).closest('tr'); var $closestTR = $(this).closest('tr');
@ -1082,7 +1152,7 @@ $(document).ready(async function() {
else if($closestTR.attr('class') == "custom_complaint_class") else if($closestTR.attr('class') == "custom_complaint_class")
{ {
id = $closestTR.find('input[name="id"]').val(); id = $closestTR.find('input[name="id"]').val();
delete_items_id[0].complaint.push(id); delete_items_id[0].custom_complaint.push(id);
console.log(delete_items_id); console.log(delete_items_id);
} }

View File

@ -42,7 +42,7 @@
<div class="form-group col-md-3" id="model_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>> <div class="form-group col-md-3" id="model_hide" <?= (!isset($services['category']) || $services['category'] == 0) ? 'style="display: none;"' : '' ?>>
<label for="model" class="col-form-label">Model<span class="text-danger">*</span></label> <label for="model" class="col-form-label">Model<span class="text-danger">*</span></label>
<select class="form-control SelExample" id="model" name="model[]" required multiple> <select class="form-control SelExample" id="model" name="model[]" required multiple>
<!-- <option value="0">Custom</option> --> <option value="0">Custom</option>
<?php foreach ($models as $make_models): ?> <?php foreach ($models as $make_models): ?>
<?php foreach ($make_models as $model): ?> <?php foreach ($make_models as $model): ?>
<option value="<?= $model['model_id'] ?>" <?= isset($services['models_id']) && in_array($model['model_id'], $services['models_id']) ? 'selected' : '' ?>><?= $model['model_name'] ?></option> <option value="<?= $model['model_id'] ?>" <?= isset($services['models_id']) && in_array($model['model_id'], $services['models_id']) ? 'selected' : '' ?>><?= $model['model_name'] ?></option>
@ -61,8 +61,8 @@
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label for="model" class="col-form-label">Product</label> <label for="model" class="col-form-label">Product</label>
<select class="form-control SelExample" id="productSelect" name="product_id[]" multiple> <select class="form-control SelExample" id="productSelect" name="product_id[]" multiple>
<!-- <option value="">Select a Product</option> --> <option value="">Select a Product</option>
<!-- <option value="0" <?= isset($services['product_id']) && in_array(0, json_decode($services['product_id'])) ? 'selected' : '' ?>>None</option> --> <option value="0" <?= isset($services['product_id']) && in_array(0, json_decode($services['product_id'])) ? 'selected' : '' ?>>None</option>
<?php foreach ($product as $value) : ?> <?php foreach ($product as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?> <?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["product_id"] ?>" <?= isset($services['product_id']) && in_array($value['product_id'], json_decode($services['product_id'])) ? 'selected' : '' ?>> <option value="<?= $value["product_id"] ?>" <?= isset($services['product_id']) && in_array($value['product_id'], json_decode($services['product_id'])) ? 'selected' : '' ?>>