X-Git-Url: http://git.scottworley.com/inverse-tax/blobdiff_plain/a3217513164a82c3c60cb199333541d331eeff98..d0678fe5d5c229220e1b4e7e7cbd470b157c3261:/tax_ui.js?ds=inline diff --git a/tax_ui.js b/tax_ui.js new file mode 100644 index 0000000..4f2b625 --- /dev/null +++ b/tax_ui.js @@ -0,0 +1,24 @@ +function load_tax_table(table_id, deductible_id) { + return apply_deductible(parse_tax_table(document.getElementById(table_id).value), + parseFloat(document.getElementById(deductible_id).value)); +} + +function format_number(n) { + return n.toLocaleString('en', {useGrouping:true, style: 'currency', currency: 'USD'}); +} + +function calculate() { + const table1 = load_tax_table('tax_table_1', 'deductible_1'); + const table2 = load_tax_table('tax_table_2', 'deductible_2'); + const after_tax = parseFloat(document.getElementById('after_tax').value); + + const before_tax = invert(merge_tax_tables(table1, table2))(after_tax); + + const tax1 = tax(table1, before_tax); + const tax2 = tax(table2, before_tax); + + document.getElementById('before_tax').textContent = format_number(before_tax); + document.getElementById('tax_1').textContent = format_number(tax1); + document.getElementById('tax_2').textContent = format_number(tax2); + document.getElementById('after_tax_verification').textContent = format_number(before_tax - (tax1 + tax2)); +}