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