Restructuring in prep for being a usable package.
[ustaxlib.git] / src / fed2019 / Schedule2.ts
1 import { Form } from '../core';
2 import { TaxReturn } from '../core';
3 import { ComputedLine } from '../core/Line';
4 import { UnsupportedFeatureError } from '../core/Errors';
5
6 import Form1040, { FilingStatus } from './Form1040';
7 import Form1099DIV from './Form1099DIV';
8 import Form1099INT from './Form1099INT';
9 import Form8959 from './Form8959';
10 import Form8960 from './Form8960';
11
12 export default class Schedule2 extends Form<Schedule2['_lines']> {
13 readonly name = 'Schedule 2';
14
15 protected readonly _lines = {
16 '1': new ComputedLine((tr): number => {
17 // TODO - this is just using Taxable Income, rather than AMT-limited
18 // income
19 const f1040 = tr.getForm(Form1040);
20 const taxableIncome = f1040.getValue(tr, '11b');
21 switch (f1040.getInput('filingStatus')) {
22 case FilingStatus.Single:
23 if (taxableIncome < 510300)
24 return 0;
25 case FilingStatus.MarriedFilingJoint:
26 if (taxableIncome < 1020600)
27 return 0;
28 case FilingStatus.MarriedFilingSeparate:
29 if (taxableIncome < 510300)
30 return 0;
31 }
32 throw new UnsupportedFeatureError('The AMT is not supported');
33 }, 'AMT'),
34 '2': new ComputedLine(() => 0, 'Excess advance premium tax credit repayment'), // Not supported.
35 '3': new ComputedLine((tr): number => {
36 // Should include line 2.
37 return this.getValue(tr, '1');
38 }),
39
40 // 4 is not supported (Self-employment tax.)
41 // 5 is not supported (Unreported social security and Medicare tax from)
42 // 6 is not supported (Additional tax on IRAs, other qualified retirement plans, and other tax-favored accounts)
43 // 7 is not supported (Household employment taxes.)
44 '8': new ComputedLine((tr): number => {
45 const f1040 = tr.getForm(Form1040);
46 const wages = f1040.getLine('1').value(tr);
47 const filingStatus = f1040.getInput('filingStatus');
48
49 let value = 0;
50
51 // Additional medicare tax.
52 if (wages > Form8959.filingStatusLimit(filingStatus)) {
53 value += tr.getForm(Form8959).getValue(tr, '18');
54 }
55
56 // Net investment income tax.
57 if (wages > Form8960.filingStatusLimit(filingStatus) &&
58 (tr.findForms(Form1099DIV).length || tr.findForms(Form1099INT).length)) {
59 value += tr.getForm(Form8960).getValue(tr, '17');
60 }
61
62 return value;
63 }),
64 // 9 is not supported (Section 965 net tax liability installment from Form 965-A)
65
66 '10': new ComputedLine((tr): number => {
67 // Should be lines 4 - 8.
68 return this.getValue(tr, '8');
69 })
70 };
71 };