]>
Commit | Line | Data |
---|---|---|
2d75ab3b SW |
1 | "use strict"; |
2 | ||
e6606316 SW |
3 | function load_tax_table(table_id, deductible_id = null) { |
4 | const deductible = deductible_id == null ? 0.0 : parseFloat(document.getElementById(deductible_id).value); | |
5 | return apply_deductible(parse_tax_table(document.getElementById(table_id).value), deductible); | |
d0678fe5 SW |
6 | } |
7 | ||
8 | function format_number(n) { | |
9 | return n.toLocaleString('en', {useGrouping:true, style: 'currency', currency: 'USD'}); | |
10 | } | |
11 | ||
12 | function calculate() { | |
13 | const table1 = load_tax_table('tax_table_1', 'deductible_1'); | |
14 | const table2 = load_tax_table('tax_table_2', 'deductible_2'); | |
15 | const after_tax = parseFloat(document.getElementById('after_tax').value); | |
16 | ||
17 | const before_tax = invert(merge_tax_tables(table1, table2))(after_tax); | |
18 | ||
19 | const tax1 = tax(table1, before_tax); | |
20 | const tax2 = tax(table2, before_tax); | |
21 | ||
22 | document.getElementById('before_tax').textContent = format_number(before_tax); | |
23 | document.getElementById('tax_1').textContent = format_number(tax1); | |
24 | document.getElementById('tax_2').textContent = format_number(tax2); | |
25 | document.getElementById('after_tax_verification').textContent = format_number(before_tax - (tax1 + tax2)); | |
26 | } |