Drop explicit type parameter in ComputedLine, since it can be inferred.
[ustaxlib.git] / src / fed2019 / Form1040.ts
1 import Form from '../Form';
2 import TaxReturn from '../TaxReturn';
3 import { Line, AccumulatorLine, ComputedLine, ReferenceLine } from '../Line';
4 import { UnsupportedFeatureError } from '../Errors';
5
6 export enum FilingStatus {
7 Single,
8 MarriedFilingSeparate,
9 MarriedFilingJoint,
10 };
11
12 export interface Form1040Input {
13 filingStatus: FilingStatus;
14 };
15
16 const reduceBySum = (list: number[]) => list.reduce((acc, curr) => acc + curr, 0);
17
18 export default class Form1040 extends Form<Form1040['_lines'], Form1040Input> {
19 readonly name = '1040';
20
21 protected readonly _lines = {
22 '1': new AccumulatorLine('W-2', '1', 'Wages, salaries, tips, etc.'),
23 '2a': new AccumulatorLine('1099-INT', '8', 'Tax-exempt interest'),
24 '2b': new AccumulatorLine('1099-INT', '1', 'Taxable interest'),
25 '3a': new AccumulatorLine('1099-DIV', '1b', 'Qualified dividends'),
26 '3b': new AccumulatorLine('1099-DIV', '1a', 'Ordinary dividends'),
27 // 4a and 4b are complex
28 '4b': new ComputedLine(() => 0),
29 '4d': new ComputedLine(() => 0),
30 // 4c and 4d are not supported
31 // 5a and 5b are not supported
32 '6': new ReferenceLine<number>('Schedule D', '21', 'Capital gain/loss', 0),
33 '7a': new ReferenceLine<number>('Schedule 1', '9', 'Other income from Schedule 1', 0),
34
35 '7b': new ComputedLine((tr: TaxReturn): number => {
36 const lineIds = ['1', '2b', '3b', '4b', '4d', /*'5b',*/ '6', '7a'];
37 const lines: number[] = lineIds.map(l => this.getValue(tr, l as keyof Form1040['_lines']));
38 return reduceBySum(lines);
39 }, 'Total income'),
40
41 '8a': new ReferenceLine<number>('Schedule 1', '22', 'Adjustments to income', 0),
42
43 '8b': new ComputedLine((tr: TaxReturn): number => {
44 return this.getValue(tr, '7b') - this.getValue(tr, '8a');
45 }, 'Adjusted gross income'),
46
47 // TODO - Deduction
48 '9': new ComputedLine(() => 0, 'Deduction'),
49
50 '10': new ComputedLine((tr: TaxReturn): number => {
51 const taxableIncome = this.getValue(tr, '8b');
52 let use8995a = false;
53 switch (this.getInput('filingStatus')) {
54 case FilingStatus.Single: use8995a = taxableIncome <= 160700; break;
55 case FilingStatus.MarriedFilingSeparate: use8995a = taxableIncome <= 160725; break;
56 case FilingStatus.MarriedFilingJoint: use8995a = taxableIncome <= 321400; break;
57 };
58 return 0;
59 }, 'Qualified business income deduction'),
60
61 '11a': new ComputedLine((tr: TaxReturn): number => {
62 return this.getValue(tr, '9') + this.getValue(tr, '10');
63 }),
64 '11b': new ComputedLine((tr: TaxReturn): number => {
65 const value = this.getValue(tr, '8b') - this.getValue(tr, '11a');
66 return value < 0 ? 0 : value;
67 }, 'Taxable income'),
68
69 '12a': new ComputedLine((tr: TaxReturn): number => {
70 // Not supported:
71 // Form 8814 (election to report child's interest or dividends)
72 // Form 4972 (relating to lump-sum distributions)
73 const taxableIncome = this.getValue(tr, '11b');
74 if (taxableIncome < 100000)
75 throw new UnsupportedFeatureError('Tax-table tax liability not supported');
76
77 const l11b = this.getValue(tr, '11b');
78
79 switch (this.getInput('filingStatus')) {
80 case FilingStatus.Single:
81 if (taxableIncome < 160725)
82 return (l11b * 0.24) - 5825.50;
83 else if (taxableIncome < 204100)
84 return (l11b * 0.32) - 18683.50;
85 else if (taxableIncome < 510300)
86 return (l11b * 0.35) - 24806.50;
87 else
88 return (l11b * 0.38) - 35012.50;
89 case FilingStatus.MarriedFilingJoint:
90 if (taxableIncome < 168400)
91 return (l11b * 0.22) - 8283.00;
92 else if (taxableIncome < 321450)
93 return (l11b * 0.24) - 11651.00;
94 else if (taxableIncome < 408200)
95 return (l11b * 0.32) - 37367.00;
96 else if (taxableIncome < 612350)
97 return (l11b * 0.35) - 49613.00;
98 else
99 return (l11b * 0.37) - 61860.00;
100 case FilingStatus.MarriedFilingSeparate:
101 if (taxableIncome < 160725)
102 return (l11b * 0.24) - 5825.50;
103 else if (taxableIncome < 204100)
104 return (l11b * 0.32) - 18683.50;
105 else if (taxableIncome < 306175)
106 return (l11b * 0.35) - 24806.50;
107 else
108 return (l11b * 0.37) - 30930.00;
109 }
110 throw new UnsupportedFeatureError('Unexpected return type');
111 }, 'Tax'),
112
113 '12b': new ComputedLine((tr: TaxReturn): number => {
114 // TODO: add Sched 2.L3
115 return this.getValue(tr, '12a');
116 }),
117
118 // Not supported: 13a - child tax credit
119
120 '13b': new ComputedLine((tr: TaxReturn): number => {
121 // TODO: add Sched 3.L7
122 return 0;
123 }),
124
125 '14': new ComputedLine((tr: TaxReturn): number => {
126 const l12b = this.getValue(tr, '12b');
127 const l13b = this.getValue(tr, '13b');
128 const value = l12b - l13b;
129 return value < 0 ? 0 : value;
130 }),
131
132 '15': new ReferenceLine<number>('Schedule 2', '10', undefined, 0),
133
134 '16': new ComputedLine((tr: TaxReturn): number => {
135 return this.getValue(tr, '14') + this.getValue(tr, '15');
136 }, 'Total tax'),
137
138 '17': new ComputedLine((tr: TaxReturn): number => {
139 const fedTaxWithheldBoxes = [
140 ['W-2', '2'], ['1099-R', '4'], ['1099-DIV', '4'], ['1099-INT', '4']
141 ];
142 const withholding = fedTaxWithheldBoxes.map(b => (new AccumulatorLine(b[0], b[1])).value(tr));
143
144 let additionalMedicare = 0;
145 const f8959 = tr.maybeGetForm('8595')
146 if (f8959) {
147 additionalMedicare = f8959.getValue(tr, '24');
148 }
149
150 return reduceBySum(withholding) + additionalMedicare;
151 }, 'Federal income tax withheld'),
152
153 // 18 not supported
154
155 '19': new ReferenceLine<number>('1040', '17', 'Total payments'),
156
157 '20': new ComputedLine((tr: TaxReturn): number => {
158 const l16 = this.getValue(tr, '16');
159 const l19 = this.getValue(tr, '19');
160 if (l19 > l16)
161 return l19 - l16;
162 return 0;
163 }, 'Amount overpaid'),
164
165 '23': new ComputedLine((tr: TaxReturn): number => {
166 const l16 = this.getValue(tr, '16');
167 const l19 = this.getValue(tr, '19');
168 if (l19 < l16)
169 return l16 - l19;
170 return 0;
171 }, 'Amount you owe'),
172 };
173
174 };