]>
git.scottworley.com Git - inverse-tax/blob - tax_ui.js
4f2b625d47311f1554860c97c0abd0460376f5eb
1 function load_tax_table(table_id
, deductible_id
) {
2 return apply_deductible(parse_tax_table(document
.getElementById(table_id
).value
),
3 parseFloat(document
.getElementById(deductible_id
).value
));
6 function format_number(n
) {
7 return n
.toLocaleString('en', {useGrouping:true, style: 'currency', currency: 'USD'});
10 function calculate() {
11 const table1
= load_tax_table('tax_table_1', 'deductible_1');
12 const table2
= load_tax_table('tax_table_2', 'deductible_2');
13 const after_tax
= parseFloat(document
.getElementById('after_tax').value
);
15 const before_tax
= invert(merge_tax_tables(table1
, table2
))(after_tax
);
17 const tax1
= tax(table1
, before_tax
);
18 const tax2
= tax(table2
, before_tax
);
20 document
.getElementById('before_tax').textContent
= format_number(before_tax
);
21 document
.getElementById('tax_1').textContent
= format_number(tax1
);
22 document
.getElementById('tax_2').textContent
= format_number(tax2
);
23 document
.getElementById('after_tax_verification').textContent
= format_number(before_tax
- (tax1
+ tax2
));