I"° (function() { accounting.settings = { number: { precision: 2, thousand: " ", decimal: "," } }; window.str2num = function(str) { return parseFloat(String(str).replace(",", ".").replace(" ", "")) || 0.0; }; window.num2str = function(num) { num = parseFloat(num); return accounting.formatNumber(num); }; $(document).on("ready page:load cocoon:after-insert", function() { $("#invoice-form input.number").keyup(function() { var advance, balance, commercial_discount, discount_rate, raw_total_excluding_taxes, total_excluding_taxes, total_including_taxes, vat_amount; total_excluding_taxes = 0.0; $("#invoice-form .invoice_line").map(function() { var line_total, quantity, unit_price; quantity = str2num($(this).find(".invoice_line-quantity input").val()); unit_price = str2num($(this).find(".invoice_line-unit_price input").val()); line_total = unit_price * quantity; $(this).find(".invoice_line-total input").val(num2str(line_total)); return total_excluding_taxes += line_total; }); commercial_discount = str2num($("#invoice_commercial_discount").val()); raw_total_excluding_taxes = total_excluding_taxes; total_excluding_taxes = raw_total_excluding_taxes - commercial_discount; $("#invoice_total_excluding_taxes").val(num2str(total_excluding_taxes)); discount_rate = commercial_discount / raw_total_excluding_taxes; vat_amount = 0.0; $("#invoice-form .invoice_line").map(function() { var discounted_line_total, line_total, line_vat_amount, vat_rate; if ($(this).find(".invoice_line-vat_rate input").length > 0) { vat_rate = str2num($(this).find(".invoice_line-vat_rate input").val()); } else { vat_rate = str2num($("#invoice_vat_rate").val()); } line_total = str2num($(this).find(".invoice_line-total input").val()); discounted_line_total = line_total - (line_total * discount_rate); line_vat_amount = discounted_line_total * vat_rate / 100; return vat_amount += line_vat_amount; }); $("#invoice_vat_amount").val(num2str(vat_amount)); total_including_taxes = total_excluding_taxes + vat_amount; $("#invoice_total_including_taxes").val(num2str(total_including_taxes)); if ($("#invoice_advance").length > 0 && $("#invoice_balance").length > 0) { advance = str2num($("#invoice_advance").val()); balance = total_including_taxes - advance; return $("#invoice_balance").val(num2str(balance)); } }); $("#invoice-form input").keyup(); $("#invoice-form input.number").blur(function() { return $("#invoice-form input.number").map(function() { var formatted_number; formatted_number = num2str(str2num($(this).val())); return $(this).val(formatted_number); }); }); return $("#invoice-form input.number").blur(); }); }).call(this); :ET