]> git.scottworley.com Git - inverse-tax/blame_incremental - tax_ui.js
Add Business Tax
[inverse-tax] / tax_ui.js
... / ...
CommitLineData
1"use strict";
2
3function 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);
6}
7
8function format_number(n) {
9 return n.toLocaleString('en', {useGrouping:true, style: 'currency', currency: 'USD'});
10}
11
12function calculate() {
13 const tax_tables = [
14 load_tax_table('tax_table_1', 'deductible_1'),
15 load_tax_table('tax_table_2', 'deductible_2'),
16 load_tax_table('tax_table_3'),
17 load_tax_table('tax_table_4'),
18 load_tax_table('tax_table_5')
19 ];
20 const after_tax = parseFloat(document.getElementById('after_tax').value);
21
22 const merged_tax_table = tax_tables.reduce(merge_tax_tables);
23 const before_tax = invert(merged_tax_table)(after_tax);
24 const taxes = tax_tables.map(t => tax(t, before_tax));
25
26 document.getElementById('before_tax').textContent = format_number(before_tax);
27 document.getElementById('tax_1').textContent = format_number(taxes[0]);
28 document.getElementById('tax_2').textContent = format_number(taxes[1]);
29 document.getElementById('tax_3').textContent = format_number(taxes[2]);
30 document.getElementById('tax_4').textContent = format_number(taxes[3]);
31 document.getElementById('tax_5').textContent = format_number(taxes[4]);
32 document.getElementById('after_tax_verification').textContent = format_number(before_tax - sum(taxes));
33}