GWM : JC calculation

This commit is contained in:
Gowtham M 2025-04-10 16:27:13 +05:30
parent f2f818a62b
commit d93b7c68d5
2 changed files with 83 additions and 30 deletions

View File

@ -657,7 +657,7 @@ class Jobcard extends BaseController
$data['logged_user_role'] = $this->session->get('logged_user_role');
if($rework == 're-work') { $data['rework']= true; }
// dd($data);
@ -677,6 +677,9 @@ class Jobcard extends BaseController
public function add_jobs()
{
// $data = json_decode($_POST['products']);
// $service_data = $data[0]->service;
// dd($service_data);
if($this->session->get('logged_user_role') == "Store Manager") {
$data['status'] = $this->request->getPost('status');

View File

@ -716,7 +716,7 @@ $(document).ready(async function() {
<?php } ?>
newRow += '<td> <input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + product.tax + '" readonly /></td>' +
'<td><input type="text" class="form-control total-tax-amount" value="'+total_tax_amt.toFixed(2)+'" readonly /></td>' +
'<td><input type="text" class="form-control item-amount" name="amount[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" readonly/></center></td>' +
'<td><input type="text" class="form-control item-amount" name="amount[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" /></center></td>' +
'<td>'+
action+
'<input value="product" name="item_type" hidden>'+
@ -969,6 +969,8 @@ $(document).ready(function() {
$('form').submit(function() {
return validateProductAdded();
});
$(document).on('keyup change', '.item-amount', function() {
amount = $(this).val();
@ -1030,6 +1032,9 @@ $(document).ready(function() {
display_rate = $(this).closest('tr').find('.rate-d-only');
display_rate.val(actual_amount.toFixed(2));
}else if(className == 'product'){
row = $(this).closest('tr');
calculateTotalAmount(row);
}
// Calculate amount and update amount input field
updateCalculations();
@ -1325,14 +1330,16 @@ $(document).ready(function() {
// console.log(item);
return item.product_id == productId;
});
console.log(product,'product');
$(quantity).attr('max', product.qty_stock);
tax = parseFloat(product.cgst) + parseFloat(product.sgst);
// Access unit price from product and set it as rate
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
$(this).closest('tr').find('.rate-d-only').val(unitPrice);
$(this).closest('tr').find('.item-rate').val(unitPrice);
$(this).closest('tr').find('.rate-d-only').val(unitPrice).attr('value', unitPrice);
$(this).closest('tr').find('.item-rate').val(unitPrice).attr('value', unitPrice);
$(this).closest('tr').find('.item-tax').val(tax).attr('value', tax);
// Calculate amount and update amount input field
// calculateAmount($(this).closest('tr'));
@ -1453,33 +1460,38 @@ $(document).ready(function() {
// Retrieve CGST and SGST values from the database for the selected product
var productId = $(row).find('select[name="item_details[]"]').val();
if (type.includes("product")) {
// var product = products.find(function(item) {
var product = productarray.find(function(item) {
return item.product_id == productId;
});
console.log(product);
if (product !== undefined) {
var cgst = parseFloat(product.cgst);
var sgst = parseFloat(product.sgst);
// if (product !== undefined) {
// var cgst = parseFloat(product.cgst);
// var sgst = parseFloat(product.sgst);
// // Calculate total tax by adding CGST and SGST
// var tax = cgst + sgst;
// $(row).find('.item-tax').val(tax.toFixed(0));
// finrate = Number(product.unit_price) * quantity;
// $(row).find('.item-rate').val(finrate);
// // rate = Number(product.unit_price);
// rate = Number(product.total_amount);
// var amount = rate * quantity;
// total_tax_amt = amount - finrate;
// }
taxPercentage = $(row).find('.item-tax').val();
itemRate = $(row).find('.item-rate').val();
subtotal = itemRate * quantity;
taxAmount = subtotal * taxPercentage / 100;
totalAmount = subtotal + taxAmount;
$(row).find('.total-tax-amount').val(taxAmount.toFixed(2)).attr('value', taxAmount.toFixed(2));
$(row).find('.item-amount').val(totalAmount.toFixed(2)).attr('value', totalAmount.toFixed(2));
// Calculate total tax by adding CGST and SGST
var tax = cgst + sgst;
$(row).find('.item-tax').val(tax.toFixed(0));
finrate = Number(product.unit_price) * quantity;
$(row).find('.item-rate').val(finrate);
// rate = Number(product.unit_price);
rate = Number(product.total_amount);
var amount = rate * quantity;
total_tax_amt = amount - finrate;
}else{
tax1 = $(row).find('.item-tax').val();
rate1 = $(row).find('.rate-d-only').val();
var amount = rate1 * quantity;
total_tax_amt = amount;
}
$(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
$(row).find('.item-amount').val(amount.toFixed(2));
}
else if(type.includes("service")) {
if(action == 'parent') var $previousRow = row;
@ -1536,6 +1548,29 @@ $(document).ready(function() {
}
function calculateTotalAmount(row) {
var tax = $(row).find('.item-tax').val();
var quantity = $(row).find('.item-quantity').val();
var final_amount = $(row).find('.item-amount').val();
var taxRate = tax/100;
var amt = final_amount/((1+taxRate));
$(row).find('.item-result').val(parseFloat(amt).toFixed(2)).attr('value', amt.toFixed(2));
var taxAmount = final_amount-amt;
console.log(taxAmount);
$(row).find('.tax-amount').val(parseFloat(taxAmount).toFixed(2)).attr('value', taxAmount.toFixed(2));
var rate = amt / quantity;
$(row).find('.item-rate').val(parseFloat(rate).toFixed(2)).attr('value', parseFloat(rate).toFixed(2));
$(row).find('.rate-d-only').val(parseFloat(rate).toFixed(2)).attr('value', parseFloat(rate).toFixed(2));
}
const labourcost = async (cost,tax,tr,cls) => {
console.log(cost,tax,tr,cls);
console.log('cost,tax,tr,cls');
@ -1580,7 +1615,7 @@ $(document).ready(function() {
'<td><input type="number" class="form-control item-quantity" min="0" max="'+Number(product.qty_stock)+'" value="1" name="quantity[]"/></td>' +
'<td><input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' +
'<td><input type="text" class="form-control total-tax-amount" value="'+ total_tax_amt.toFixed(2) +'" readonly /></td>' +
'<td><input type="text" class="form-control item-amount" name="amount1[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" readonly/></td>' +
'<td><input type="text" class="form-control item-amount" name="amount1[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" /></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" value=""></td>' +
'<td hidden><input value="'+product.product_name+'" name="name"></td>' +
@ -1641,6 +1676,21 @@ $(document).ready(function() {
updateCalculations();
});
//gwm
$(document).on('keyup change', '.rate-d-only', function() {
alert();
className = $(this).closest('tr').attr('class');
if(className == 'product') {
calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child');
}
// Calculate amount and update amount input field
updateCalculations();
});
// Function to calculate subtotal
function calculateSubtotal() {
var subtotal = 0;