I have a table of products like this:
As I mentioned in the image, I have specified a field called VAT which stands for Value Added Tax and I need the sum of all VAT fields to be showed on page with jQuery, so here is my try:
var total_price = parseInt($('#total-price').html().replace(/\,/g,''));
$('#total-price').html(parseInt(total_price + (price*cnt)).toLocaleString());
var total_discount = parseInt($('#total-discount').html().replace(/\,/g,''));
$('#total-discount').html(parseInt(total_discount + (discount*cnt)).toLocaleString());
var total_final = parseInt($('#total-final').html().replace(/\,/g,''));
$('#total-final').html(parseInt(total_final + (price_final*cnt)).toLocaleString());
var total_vat = parseInt($('#total-vat').html().replace(/\,/g,''));
$('#total-vat').html(parseInt(total_final + (price_final*cnt) + value_added_tax).toLocaleString());
And the result of these variables goes here:
But now the problem is sum of vats
returns the same value of total-final
. So instead of 12,350,00 it should be showing 13,286,000 (because the sum of value_added_tax
must be added to total_final
).
And the line that does this calculation goes here:
$('#total-vat').html(parseInt(total_final + (price_final*cnt) + value_added_tax).toLocaleString());
Something is missing here, or I'm doing it in a wrong way. So if you know how to calculate properly the final price of a product (total_final
+ value_added_tax
), please let me know...
I would really appreciate any idea or suggestion from you guys...
Thanks in advance.
from How to calculate sum of a custom value
No comments:
Post a Comment