Level 1
Jan 4, 2024
2
Level 1
Calculate Subtotal
"I want to calculate the subtotal value by multiplying the net unit price with the total square feet."
- My Function
function calculateRowProductData(quantity) {
if(product_type[pos] == 'standard')
unitConversion();
else
row_product_price = product_price[rowindex];
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.discount').text((product_discount[rowindex] * quantity).toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.discount-value').val((product_discount[rowindex] * quantity).toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax-rate').val(tax_rate[rowindex].toFixed({{$general_setting->decimal}}));
var totalSquareFeet = parseFloat($('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.total-square-feet').val()) || 0;
if (tax_method[rowindex] == 1) {
var net_unit_price = row_product_price - product_discount[rowindex];
var tax = net_unit_price * quantity * (tax_rate[rowindex] / 100);
var sub_total = (net_unit_price * quantity) + tax;
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.net_unit_price').text(net_unit_price.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.net_unit_price').val(net_unit_price.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax').text(tax.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax-value').val(tax.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.sub-total').text(sub_total.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.subtotal-value').val(sub_total.toFixed({{$general_setting->decimal}}));
} else {
var sub_total_unit = row_product_price - product_discount[rowindex];
var net_unit_price = (100 / (100 + tax_rate[rowindex])) * sub_total_unit;
var tax = (sub_total_unit - net_unit_price) * totalSquareFeet;
var sub_total = sub_total_unit * totalSquareFeet; // Update the subtotal calculation
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.net_unit_price').text(net_unit_price.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.net_unit_price').val(net_unit_price.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax').text(tax.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.tax-value').val(tax.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.sub-total').text(sub_total.toFixed({{$general_setting->decimal}}));
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.subtotal-value').val(sub_total.toFixed({{$general_setting->decimal}}));
}
calculateTotal();
}
Please or to participate in this conversation.