|
|
|
|
@ -85,6 +85,7 @@
|
|
|
|
|
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
|
|
|
|
|
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
|
|
|
|
|
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
|
|
|
|
<option value="Cancelled" <?= $jobs['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
@ -130,9 +131,10 @@
|
|
|
|
|
<tr>
|
|
|
|
|
<th hidden></th>
|
|
|
|
|
<th>Item Details</th>
|
|
|
|
|
<th>Qty</th>
|
|
|
|
|
<th>Rate</th>
|
|
|
|
|
<th>Tax</th>
|
|
|
|
|
<th hidden></th>
|
|
|
|
|
<th>Qty</th>
|
|
|
|
|
<th>Tax (%)</th>
|
|
|
|
|
<th>Amount</th>
|
|
|
|
|
<th style="width: 10px;">Action</th>
|
|
|
|
|
<th hidden></th>
|
|
|
|
|
@ -311,22 +313,22 @@ $(document).ready(async function() {
|
|
|
|
|
// console.log(servicearray);
|
|
|
|
|
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>
|
|
|
|
|
<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>`;
|
|
|
|
|
<td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;">`;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < servicearray.length; 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 += '</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 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 hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" 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 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 hidden><input name="id" value="'+value.job_card_service_id+'"></td>' +
|
|
|
|
|
'</tr>';
|
|
|
|
|
@ -336,7 +338,7 @@ $(document).ready(async function() {
|
|
|
|
|
initializeSelect2();
|
|
|
|
|
/** APPEND CHILD 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) {
|
|
|
|
|
complaint = <?php echo json_encode($complaint) ?>;
|
|
|
|
|
// 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++)
|
|
|
|
|
{
|
|
|
|
|
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 += '</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 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 hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" 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 hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></td>' +
|
|
|
|
|
'<td><div style="display: inline-block;">'+
|
|
|
|
|
'<center><i class="fa fa-trash remove-item"></i></center>'+
|
|
|
|
|
'</div>'+
|
|
|
|
|
@ -377,7 +380,7 @@ $(document).ready(async function() {
|
|
|
|
|
initializeSelect2();
|
|
|
|
|
/** APPEND CHILD 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) {
|
|
|
|
|
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>' +
|
|
|
|
|
'<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 style="width:10%;"><input hidden type="text" class="form-control item-rate1" 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 hidden type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" /></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;">'+
|
|
|
|
|
'<center><i class="fa fa-trash remove-item"></i></center>'+
|
|
|
|
|
'</div>'+
|
|
|
|
|
@ -408,21 +411,21 @@ $(document).ready(async function() {
|
|
|
|
|
initializeSelect2();
|
|
|
|
|
/** APPEND CHILD PRODUCT */
|
|
|
|
|
await edit_product_data(value.product);
|
|
|
|
|
editlabourcost(value.labour_cost)
|
|
|
|
|
editlabourcost(value,'custom_complaint_lb')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function editlabourcost(data) {
|
|
|
|
|
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>' +
|
|
|
|
|
'<td style="width:10%;"></td>' +
|
|
|
|
|
'<td style="width:10%;"></td>' +
|
|
|
|
|
'<td style="width:8%;"></td>' +
|
|
|
|
|
'<td style="width:12%;"><input type="text" class="form-control item-amount1" name="amount1[]" value="' + data + '" readonly/></td>' +
|
|
|
|
|
function editlabourcost(data,cls) {
|
|
|
|
|
total_wih_tax = parseInt(data.labour_cost) + (parseInt(data.labour_cost) * (data.tax / 100));
|
|
|
|
|
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%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="'+data.labour_cost+'" /></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: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>' +
|
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
|
|
|
// $(newRow).insertAfter(tr);
|
|
|
|
|
initializeSelect2();
|
|
|
|
|
@ -431,16 +434,17 @@ $(document).ready(async function() {
|
|
|
|
|
function edit_product_data(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>
|
|
|
|
|
<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 += '</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="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: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" name="id" value="'+product.job_card_product_id+'"></td>' +
|
|
|
|
|
'</tr>';
|
|
|
|
|
@ -568,9 +572,9 @@ $(document).ready(async function() {
|
|
|
|
|
tableRows.forEach(function(row) {
|
|
|
|
|
var firstTd = row.querySelector("td:nth-child(1)");
|
|
|
|
|
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 sixthTd = row.querySelector("td:nth-child(6)");
|
|
|
|
|
var sixthTd = row.querySelector("td:nth-child(3)");
|
|
|
|
|
var eigthTd = row.querySelector("td:nth-child(8)");
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
var unitPrice = parseInt(service_data.price); // Convert to float if necessary
|
|
|
|
|
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));
|
|
|
|
|
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'))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculateAmount($(this).closest('tr'),className);
|
|
|
|
|
calculateAmount($(this).closest('tr'),className,'parent');
|
|
|
|
|
updateCalculations();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -732,22 +737,21 @@ $(document).ready(async function() {
|
|
|
|
|
|
|
|
|
|
// Access unit price from product and set it as rate
|
|
|
|
|
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));
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Function to calculate amount based on rate and quantity
|
|
|
|
|
function calculateAmount(row,type) {
|
|
|
|
|
// console.log(row);
|
|
|
|
|
function calculateAmount(row,type,action) {
|
|
|
|
|
console.log(type);
|
|
|
|
|
var rate = $(row).find('.item-rate').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
|
|
|
|
|
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
|
|
|
|
|
var tax = cgst + sgst;
|
|
|
|
|
$(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")) {
|
|
|
|
|
var productId = $(row).find('select[name="service_details[]"]').val();
|
|
|
|
|
var product = services.find(function(item) {
|
|
|
|
|
return item.service_id == productId;
|
|
|
|
|
});
|
|
|
|
|
var cgst = parseFloat(product.cgst);
|
|
|
|
|
var igst = parseFloat(product.sgst);
|
|
|
|
|
// var productId = $(row).find('select[name="service_details[]"]').val();
|
|
|
|
|
// var product = services.find(function(item) {
|
|
|
|
|
// return item.service_id == productId;
|
|
|
|
|
// });
|
|
|
|
|
// var cgst = parseFloat(product.cgst);
|
|
|
|
|
// var igst = parseFloat(product.sgst);
|
|
|
|
|
|
|
|
|
|
// Calculate total tax by adding CGST and SGST
|
|
|
|
|
var tax = cgst + igst;
|
|
|
|
|
console.log(tax);
|
|
|
|
|
$(row).find('.item-tax').val(tax.toFixed(2));
|
|
|
|
|
// // Calculate total tax by adding CGST and SGST
|
|
|
|
|
// var tax = cgst + igst;
|
|
|
|
|
// console.log(tax);
|
|
|
|
|
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")) {
|
|
|
|
|
var productId = $(row).find('select[name="complaint_details[]"]').val();
|
|
|
|
|
var product = complaint.find(function(item) {
|
|
|
|
|
return item.complaint_id == productId;
|
|
|
|
|
});
|
|
|
|
|
console.log(product);
|
|
|
|
|
var cgst = parseFloat(product.cgst);
|
|
|
|
|
var igst = parseFloat(product.sgst);
|
|
|
|
|
// var productId = $(row).find('select[name="complaint_details[]"]').val();
|
|
|
|
|
// var product = complaint.find(function(item) {
|
|
|
|
|
// return item.complaint_id == productId;
|
|
|
|
|
// });
|
|
|
|
|
// console.log(product);
|
|
|
|
|
// var cgst = parseFloat(product.cgst);
|
|
|
|
|
// var igst = parseFloat(product.sgst);
|
|
|
|
|
|
|
|
|
|
// Calculate total tax by adding CGST and SGST
|
|
|
|
|
var tax = cgst + igst;
|
|
|
|
|
$(row).find('.item-tax').val(tax.toFixed(2));
|
|
|
|
|
// // Calculate total tax by adding CGST and SGST
|
|
|
|
|
// var tax = cgst + igst;
|
|
|
|
|
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) => {
|
|
|
|
|
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>' +
|
|
|
|
|
'<td style="width:10%;"></td>' +
|
|
|
|
|
'<td style="width:10%;"></td>' +
|
|
|
|
|
'<td style="width:8%;"></td>' +
|
|
|
|
|
'<td style="width:12%;"><input type="text" class="form-control item-amount1" name="amount1[]" value="' + data + '" readonly/></td>' +
|
|
|
|
|
const labourcost = async (cost,tax,tr,cls) => {
|
|
|
|
|
total_wih_tax = parseInt(cost) + (parseInt(cost) * (tax / 100));
|
|
|
|
|
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%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="'+cost+'" /></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: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>' +
|
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $('#productItemTable tbody').append(newRow);
|
|
|
|
|
$(newRow).insertAfter(tr);
|
|
|
|
|
initializeSelect2();
|
|
|
|
|
}
|
|
|
|
|
@ -820,14 +852,14 @@ $(document).ready(async function() {
|
|
|
|
|
var sgst = parseFloat(product.sgst);
|
|
|
|
|
// Calculate total tax by adding CGST and 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;">';
|
|
|
|
|
newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
|
|
|
|
|
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="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: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" name="id" value=""></td>' +
|
|
|
|
|
'</tr>';
|
|
|
|
|
@ -841,19 +873,15 @@ $(document).ready(async function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Event listener for quantity change
|
|
|
|
|
$(document).on('input change', '.item-quantity', async function() {
|
|
|
|
|
calculateAmount($(this).closest('tr'));
|
|
|
|
|
updateCalculations();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).on('click', '.item-quantity', async function() {
|
|
|
|
|
$(document).on('input', '.item-quantity', async function() {
|
|
|
|
|
calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child');
|
|
|
|
|
updateCalculations();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Function to calculate subtotal
|
|
|
|
|
function calculateSubtotal() {
|
|
|
|
|
var subtotal = 0;
|
|
|
|
|
$('.item-amount').each(function() {
|
|
|
|
|
$('.item-rate').each(function() {
|
|
|
|
|
subtotal += parseFloat($(this).val()) || 0;
|
|
|
|
|
});
|
|
|
|
|
return subtotal;
|
|
|
|
|
@ -861,14 +889,16 @@ $(document).ready(async function() {
|
|
|
|
|
|
|
|
|
|
// Function to calculate total tax
|
|
|
|
|
function calculateTax() {
|
|
|
|
|
var tax = 0;
|
|
|
|
|
$('.item-tax').each(function() {
|
|
|
|
|
var taxPercentage = 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;
|
|
|
|
|
var subtotal = 0;
|
|
|
|
|
$('.item-rate').each(function() {
|
|
|
|
|
subtotal += parseFloat($(this).val()) || 0;
|
|
|
|
|
});
|
|
|
|
|
return tax;
|
|
|
|
|
|
|
|
|
|
var total = 0;
|
|
|
|
|
$('.item-amount').each(function() {
|
|
|
|
|
total += parseFloat($(this).val()) || 0;
|
|
|
|
|
});
|
|
|
|
|
return total - subtotal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Function to calculate total discount
|
|
|
|
|
@ -890,12 +920,11 @@ $(document).ready(async function() {
|
|
|
|
|
|
|
|
|
|
// Function to calculate total
|
|
|
|
|
function calculateTotal() {
|
|
|
|
|
var subtotal = calculateSubtotal();
|
|
|
|
|
var tax = calculateTax();
|
|
|
|
|
var discount = calculateDiscount();
|
|
|
|
|
var total = subtotal + tax - discount;
|
|
|
|
|
// return total;
|
|
|
|
|
return Math.round(total);
|
|
|
|
|
var total = 0;
|
|
|
|
|
$('.item-amount').each(function() {
|
|
|
|
|
total += parseFloat($(this).val()) || 0;
|
|
|
|
|
});
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update subtotal, tax, and total
|
|
|
|
|
@ -928,8 +957,8 @@ $(document).ready(async function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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="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: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>' +
|
|
|
|
|
@ -955,10 +984,10 @@ $(document).ready(async function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 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 style="width:10%;"><input hidden type="text" class="form-control item-rate1" 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 hidden type="text" class="form-control item-tax" name="item-tax[]" readonly /></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 hidden><input type="hidden" name="id"></td>' +
|
|
|
|
|
'</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() {
|
|
|
|
|
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>';
|
|
|
|
|
@ -982,10 +1024,10 @@ $(document).ready(async function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 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 style="width:10%;"><input hidden type="text" class="form-control item-rate1" 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 hidden type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
|
|
|
|
'<td style="width:12%;"><input hidden type="text" class="form-control item-amount1" name="amount[]"/></td>' +
|
|
|
|
|
'<td><div style="display: inline-block;">'+
|
|
|
|
|
'<center><i class="fa fa-trash remove-item"></i></center>'+
|
|
|
|
|
'</div>'+
|
|
|
|
|
@ -1001,14 +1043,26 @@ $(document).ready(async function() {
|
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
|
|
|
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() {
|
|
|
|
|
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>' +
|
|
|
|
|
'<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[]" /></td>' +
|
|
|
|
|
'<td style="width:8%;"><input 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:10%;"><input hidden type="text" class="form-control item-rate1" 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 hidden type="text" class="form-control item-tax" name="item-tax[]" /></td>' +
|
|
|
|
|
'<td style="width:12%;"><input hidden type="text" class="form-control item-amount1" 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>'+
|
|
|
|
|
@ -1023,38 +1077,52 @@ $(document).ready(async function() {
|
|
|
|
|
'<td hidden><input type="hidden" name="id" value=""></td>' +
|
|
|
|
|
'</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>' +
|
|
|
|
|
'<td style="width:10%;"></td>' +
|
|
|
|
|
'<td style="width:10%;"></td>' +
|
|
|
|
|
'<td style="width:8%;"></td>' +
|
|
|
|
|
'<td style="width:12%;"><input type="text" class="form-control item-amount1 item_dummy" name="amount1[]" value="0"/></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%;"><input type="text" class="form-control item-rate item-rate_cc" name="unit-price[]" value="" /></td>' +
|
|
|
|
|
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]" value="'+1+'" /></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-amount item-amount_cc" name="amount1[]" value=""/></td>' +
|
|
|
|
|
'<td hidden></td>' +
|
|
|
|
|
'<td hidden></td>' +
|
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
|
|
|
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() {
|
|
|
|
|
var row = $(this).closest('tr');
|
|
|
|
|
var labourCostInput = row.prevAll('.custom_complaint_class:first').find('.labour_cost');
|
|
|
|
|
@ -1062,7 +1130,9 @@ $(document).ready(async function() {
|
|
|
|
|
labourCostInput.val(dummyValue);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** REMOVE ITEMS FROM THE TABLE **/
|
|
|
|
|
/**
|
|
|
|
|
* REMOVE ITEMS FROM THE TABLE
|
|
|
|
|
* **/
|
|
|
|
|
delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [] }];
|
|
|
|
|
$(document).on('click', '.remove-item', function() {
|
|
|
|
|
var $closestTR = $(this).closest('tr');
|
|
|
|
|
@ -1082,7 +1152,7 @@ $(document).ready(async function() {
|
|
|
|
|
else if($closestTR.attr('class') == "custom_complaint_class")
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|