Home › Forums › CSS › Editable Invoice –including tax to total › Re: Editable Invoice –including tax to total
November 17, 2010 at 11:08 pm
#74744
mbarandao
Member
jfreehill, thank you so much for your post and time in assiting me to resolve my issue. As I was studing you suggestions and reading several articles on google, I decided to re structure the function. Here’s what I have come up with –which thus far is providing the desired outcomes. I’m still trying to work out some other issues. I’ll post final code once completed.
var taxRate = 0.0575;
function update() {
var subtotal = 0;
$('.price').each(function(i) {
price = $(this).html().fromCurrency();
if (!isNaN(price)) subtotal += price;
});
$('#subtotal').html(subtotal.toCurrency());
//doMath
var tax = ($('#taxbox').click(update)) ? (subtotal * taxRate) : 0;
$('#tax').val(tax.toCurrency());
var total = subtotal + tax;
$('#total').html(total.toCurrency());
//update_balance
var due = total - $('#paid').val().fromCurrency();
$('.due').html(due.toCurrency());
}
function update_price() {//This could also be migrated into update
var row = $(this).parents('.item-row');
var price = row.find('.cost').val().fromCurrency() * Number(row.find('.qty').val());
isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html(price.toCurrency());
update();
}
function bind() {
$('.cost').blur(update_price);
$('.cost').keyup(update_price);//added
$('.qty').blur(update_price);
$('.qty').keyup(update_price);//added
}
Again, I thank you very much for your time and thoughts.
Mossa