Add Form 1099-INT.
[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
5 export enum FilingStatus {
6 Single,
7 MarriedFilingSingle,
8 MarriedFilingJoint,
9 };
10
11 export interface Form1040Input {
12 filingStatus: FilingStatus;
13 };
14
15 const reduceBySum = (list: number[]) => list.reduce((acc, curr) => acc + curr, 0);
16
17 export default class Form1040 extends Form<Form1040['_lines'], Form1040Input> {
18 readonly name = '1040';
19
20 protected readonly _lines = {
21 '1': new AccumulatorLine('W-2', '1', 'Wages, salaries, tips, etc.'),
22 '2a': new AccumulatorLine('1099-INT', '8', 'Tax-exempt interest'),
23 '2b': new AccumulatorLine('1099-INT', '1', 'Taxable interest'),
24 '3a': new AccumulatorLine('1099-DIV', '1b', 'Qualified dividends'),
25 '3b': new AccumulatorLine('1099-DIV', '1a', 'Ordinary dividends'),
26 // 4a and 4b are complex
27 // 4c and 4d are not supported
28 // 5a and 5b are not supported
29 // 6 - Sched D
30 '7a': new ReferenceLine<number>('Schedule 1', '9', 'Other income from Schedule 1'),
31
32 '7b': new ComputedLine<number>((tr: TaxReturn): number => {
33 const lineIds = ['1', '2b', '3b', '4b', '4d', '5b', '6', '7a'];
34 const lines: number[] = lineIds.map(l => this.getValue(tr, l as keyof Form1040['_lines']));
35 return reduceBySum(lines);
36 }, 'Total income'),
37
38 '8a': new ReferenceLine<number>('Schedule 1', '22', 'Adjustments to income'),
39
40 '8b': new ComputedLine<number>((tr: TaxReturn): number => {
41 return this.getValue(tr, '7b') - this.getValue(tr, '8a');
42 }, 'Adjusted gross income'),
43
44 // TODO - Deduction
45 '9': new ComputedLine<number>(() => 0, 'Deduction'),
46
47 '10': new ComputedLine<number>((tr: TaxReturn): number => {
48 const taxableIncome = this.getValue(tr, '8b');
49 let use8995a = false;
50 switch (this.getInput('filingStatus')) {
51 case FilingStatus.Single: use8995a = taxableIncome <= 160700; break;
52 case FilingStatus.MarriedFilingSingle: use8995a = taxableIncome <= 160725; break;
53 case FilingStatus.MarriedFilingJoint: use8995a = taxableIncome <= 321400; break;
54 };
55 return 0;
56 }, 'Qualified business income deduction'),
57
58 '11a': new ComputedLine<number>((tr: TaxReturn): number => {
59 return this.getValue(tr, '9') + this.getValue(tr, '10');
60 }),
61 '11b': new ComputedLine<number>((tr: TaxReturn): number => {
62 const value = this.getValue(tr, '8b') - this.getValue(tr, '11a');
63 return value < 0 ? 0 : value;
64 }, 'Taxable income'),
65
66 '16': new ComputedLine<number>((tr: TaxReturn): number => {
67 return 0;
68 }, 'Total tax'),
69
70 '17': new ComputedLine<number>((tr: TaxReturn): number => {
71 const fedTaxWithheldBoxes = [
72 ['W-2', '2'], ['1099-R', '4'], ['1099-DIV', '4'], ['1099-INT', '4']
73 ];
74 const withholding = fedTaxWithheldBoxes.map(b => (new AccumulatorLine(b[0], b[1])).value(tr));
75
76 let additionalMedicare = 0;
77 const f8959 = tr.maybeGetForm('8595')
78 if (f8959) {
79 additionalMedicare = f8959.getValue(tr, '24');
80 }
81
82 return reduceBySum(withholding) + additionalMedicare;
83 }, 'Federal income tax withheld'),
84
85 // 18 not supported
86
87 '19': new ReferenceLine<number>('1040', '17', 'Total payments'),
88
89 '20': new ComputedLine<number>((tr: TaxReturn): number => {
90 const l16 = this.getValue(tr, '16');
91 const l19 = this.getValue(tr, '19');
92 if (l19 > l16)
93 return l19 - l16;
94 return 0;
95 }, 'Amount overpaid'),
96
97 '23': new ComputedLine<number>((tr: TaxReturn): number => {
98 const l16 = this.getValue(tr, '16');
99 const l19 = this.getValue(tr, '19');
100 if (l19 < l16)
101 return l16 - l19;
102 return 0;
103 }, 'Amount you owe'),
104 };
105 };