Calculation I want to add a function to 'calculaterowproductdata'. The 'sub_total' should be calculated by adding 'lens' and 'cutting_charge' multiplied by 'quantity', and then updating 'lens', 'cutting_charge' value to the field.
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}}));
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) * quantity;
var sub_total = sub_total_unit * quantity;
$('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();
}
You have not provided reference to lens or cutting_charge in your code. Look at these lines where your sub total is calculated. Here you will add that extra logic in.
var sub_total = (net_unit_price * quantity) + tax;
var sub_total = sub_total_unit * quantity;
Please sign in or create an account to participate in this conversation.