Remove the need to self-reference Form['lines'] in Form subclasses.
[ustaxlib.git] / src / fed2019 / Schedule2.ts
1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
5
6 import { Form, TaxReturn } from '../core';
7 import { ComputedLine, UnsupportedLine, sumFormLines } from '../core/Line';
8 import { UnsupportedFeatureError } from '../core/Errors';
9
10 import Form1040, { FilingStatus } from './Form1040';
11 import Form1099DIV from './Form1099DIV';
12 import Form1099INT from './Form1099INT';
13 import Form6251 from './Form6251';
14 import Form8959 from './Form8959';
15 import Form8960 from './Form8960';
16
17 export default class Schedule2 extends Form {
18 readonly name = 'Schedule 2';
19
20 readonly lines = {
21 '1': new ComputedLine((tr): number => {
22 const f6251 = tr.findForm(Form6251);
23 if (f6251)
24 return f6251.getValue(tr, '11');
25 return 0;
26 }, 'AMT'),
27 '2': new UnsupportedLine('Excess advance premium tax credit repayment'),
28 '3': new ComputedLine((tr): number => {
29 return this.getValue(tr, '1') + this.getValue(tr, '2');
30 }),
31
32 '4': new UnsupportedLine('Self-employment tax.'),
33 '5': new UnsupportedLine('Unreported social security and Medicare tax from'),
34 '6': new UnsupportedLine('Additional tax on IRAs, other qualified retirement plans, and other tax-favored accounts'),
35 '7': new UnsupportedLine('Household employment taxes.'),
36 '8': new ComputedLine((tr): number => {
37 const f1040 = tr.getForm(Form1040);
38 const wages = f1040.getLine('1').value(tr);
39 const filingStatus = f1040.filingStatus;
40
41 let value = 0;
42
43 // Additional medicare tax.
44 if (wages > Form8959.filingStatusLimit(filingStatus)) {
45 value += tr.getForm(Form8959).getValue(tr, '18');
46 }
47
48 // Net investment income tax.
49 if (wages > Form8960.filingStatusLimit(filingStatus) &&
50 (tr.findForms(Form1099DIV).length || tr.findForms(Form1099INT).length)) {
51 value += tr.getForm(Form8960).getValue(tr, '17');
52 }
53
54 return value;
55 }),
56 '9': new UnsupportedLine('Section 965 net tax liability installment from Form 965-A'),
57
58 '10': new ComputedLine((tr): number => {
59 return sumFormLines(tr, this, ['4', '5', '6', '7', '8']);
60 })
61 };
62 };