1 import Form from '../Form';
2 import TaxReturn from '../TaxReturn';
3 import { Line, AccumulatorLine, ComputedLine, ReferenceLine } from '../Line';
4 import { UnsupportedFeatureError } from '../Errors';
6 export enum FilingStatus {
12 export interface Form1040Input {
13 filingStatus: FilingStatus;
16 const reduceBySum = (list: number[]) => list.reduce((acc, curr) => acc + curr, 0);
18 export default class Form1040 extends Form<Form1040['_lines'], Form1040Input> {
19 readonly name = '1040';
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),
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);
41 '8a': new ReferenceLine<number>('Schedule 1', '22', 'Adjustments to income', 0),
43 '8b': new ComputedLine((tr: TaxReturn): number => {
44 return this.getValue(tr, '7b') - this.getValue(tr, '8a');
45 }, 'Adjusted gross income'),
48 '9': new ComputedLine(() => 0, 'Deduction'),
50 '10': new ComputedLine((tr: TaxReturn): number => {
51 const taxableIncome = this.getValue(tr, '8b');
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;
59 }, 'Qualified business income deduction'),
61 '11a': new ComputedLine((tr: TaxReturn): number => {
62 return this.getValue(tr, '9') + this.getValue(tr, '10');
64 '11b': new ComputedLine((tr: TaxReturn): number => {
65 const value = this.getValue(tr, '8b') - this.getValue(tr, '11a');
66 return value < 0 ? 0 : value;
69 '12a': new ComputedLine((tr: TaxReturn): number => {
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');
77 const l11b = this.getValue(tr, '11b');
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;
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;
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;
108 return (l11b * 0.37) - 30930.00;
110 throw new UnsupportedFeatureError('Unexpected return type');
113 '12b': new ComputedLine((tr: TaxReturn): number => {
114 // TODO: add Sched 2.L3
115 return this.getValue(tr, '12a');
118 // Not supported: 13a - child tax credit
120 '13b': new ComputedLine((tr: TaxReturn): number => {
121 // TODO: add Sched 3.L7
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;
132 '15': new ReferenceLine<number>('Schedule 2', '10', undefined, 0),
134 '16': new ComputedLine((tr: TaxReturn): number => {
135 return this.getValue(tr, '14') + this.getValue(tr, '15');
138 '17': new ComputedLine((tr: TaxReturn): number => {
139 const fedTaxWithheldBoxes = [
140 ['W-2', '2'], ['1099-R', '4'], ['1099-DIV', '4'], ['1099-INT', '4']
142 const withholding = fedTaxWithheldBoxes.map(b => (new AccumulatorLine(b[0], b[1])).value(tr));
144 let additionalMedicare = 0;
145 const f8959 = tr.maybeGetForm('8595')
147 additionalMedicare = f8959.getValue(tr, '24');
150 return reduceBySum(withholding) + additionalMedicare;
151 }, 'Federal income tax withheld'),
155 '19': new ReferenceLine<number>('1040', '17', 'Total payments'),
157 '20': new ComputedLine((tr: TaxReturn): number => {
158 const l16 = this.getValue(tr, '16');
159 const l19 = this.getValue(tr, '19');
163 }, 'Amount overpaid'),
165 '23': new ComputedLine((tr: TaxReturn): number => {
166 const l16 = this.getValue(tr, '16');
167 const l19 = this.getValue(tr, '19');
171 }, 'Amount you owe'),