Add overlay forms for fed2020.
[ustaxlib.git] / src / fed2019 / Form6251.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 { AccumulatorLine, ComputedLine, ReferenceLine, UnsupportedLine, sumFormLines } from '../core/Line';
8 import { Literal, clampToZero } from '../core/Math';
9
10 import Form1040, { QDCGTaxWorksheet, FilingStatus } from './Form1040';
11 import Form1099INT from './Form1099INT';
12 import Schedule1 from './Schedule1';
13 import Schedule2 from './Schedule2';
14 import Schedule3 from './Schedule3';
15 import ScheduleD, { ScheduleDTaxWorksheet } from './ScheduleD';
16
17 export default class Form6251 extends Form {
18 readonly name = '6251';
19
20 readonly lines = {
21 // Part I
22 '1': new ComputedLine((tr): number => {
23 const f1040 = tr.getForm(Form1040);
24 const income = f1040.taxableIncome(tr);
25 if (income > 0)
26 return income;
27 return f1040.adjustedGrossIncome(tr) - f1040.deduction(tr) - f1040.qualifiedBusinessIncomeDeduction(tr);
28 }),
29 '2a': new ComputedLine((tr): number => {
30 // Not supported: Schedule A, line 7.
31 return tr.getForm(Form1040).deduction(tr);
32 }),
33 '2b': new ReferenceLine(Schedule1, '1', 'Tax refund', 0), // Not supported - line 8 SALT.
34 '2c': new UnsupportedLine('Investment interest expense'),
35 '2d': new UnsupportedLine('Depletion'),
36 '2e': new UnsupportedLine('Net operating loss deduction'),
37 '2f': new UnsupportedLine('Alternative tax net operating loss deduction'),
38 '2g': new AccumulatorLine(Form1099INT, '9', 'Interest from specified private activity bonds exempt from the regular tax'),
39 '2h': new UnsupportedLine('Qualified small business stock'),
40 '2i': new UnsupportedLine('Exercise of incentive stock options'),
41 '2j': new UnsupportedLine('Estates and trusts (amount from Schedule K-1 (Form 1041), box 12, code A)'),
42 '2k': new UnsupportedLine('Disposition of property'),
43 '2l': new UnsupportedLine('Depreciation on assets placed in service after 1986'),
44 '2m': new UnsupportedLine('Passive activities'),
45 '2n': new UnsupportedLine('Loss limitations'),
46 '2o': new UnsupportedLine('Circulation costs'),
47 '2p': new UnsupportedLine('Long-term contracts'),
48 '2q': new UnsupportedLine('Mining costs'),
49 '2r': new UnsupportedLine('Research and experimental costs'),
50 '2s': new UnsupportedLine('Income from certain installment sales before January 1, 1987'),
51 '2t': new UnsupportedLine('Intangible drilling costs preference'),
52 '3': new UnsupportedLine('Other adjustments'),
53 '4': new ComputedLine((tr): number => {
54 return sumFormLines(tr, this, ['1', '2a', '2b', '2c', '2d', '2e', '2f', '2g', '2h', '2i', '2j', '2k', '2l', '2m', '2n', '2o', '2p', '2q', '2r', '2s', '2t', '3']);
55 }, 'Alternative minimum taxable income'),
56
57 // Part II
58 '5': new ComputedLine((tr): number => {
59 const fs = tr.getForm(Form1040).filingStatus;
60 const exemption = tr.constants.amt.exemption[fs];
61 const phaseout = tr.constants.amt.phaseout[fs];
62
63 const l4 = this.getValue(tr, '4');
64 if (l4 < phaseout)
65 return exemption;
66
67 // Exemption worksheet:
68 const wl1 = exemption;
69 const wl2 = l4;
70 const wl3 = phaseout;
71 const wl4 = clampToZero(wl2 - wl3);
72 const wl5 = wl4 * Literal(0.25);
73 const wl6 = clampToZero(wl1 - wl5);
74 return wl6;
75 }),
76 '6': new ComputedLine((tr): number => {
77 return clampToZero(this.getValue(tr, '4') - this.getValue(tr, '5'));
78 }),
79 '7': new ComputedLine((tr): number => {
80 // Not supported - Form 2555.
81 // Not supported - Form1040 directly reporting cap gains on line 6.
82
83 const f1040 = tr.getForm(Form1040);
84
85 let part3 = f1040.qualifiedDividends(tr) > 0;
86
87 const schedD = tr.findForm(ScheduleD);
88 if (schedD) {
89 const flag = schedD.getValue(tr, '15') > 0 && schedD.getValue(tr, '16') > 0;
90 part3 = part3 || flag;
91 }
92
93 if (part3)
94 return this.getValue(tr, '40');
95
96 return computeAmtTax(tr, this.getValue(tr, '6'));
97 }),
98 '8': new ReferenceLine(Schedule3, '1', 'Alternative minimum tax foreign tax credit'), // Not supported - AMT FTC recalculation
99 '9': new ComputedLine((tr): number => {
100 return this.getValue(tr, '7') - this.getValue(tr, '8');
101 }, 'Tentative minimum tax'),
102 '10': new ComputedLine((tr): number => {
103 let value = tr.getForm(Form1040).tax(tr);
104 const sched2 = tr.findForm(Schedule2);
105 if (sched2) {
106 value += sched2.getValue(tr, '2');
107 }
108 // Not supported - subtracting Schedule3@1 for the AMT FTC.
109 return value;
110 }),
111 '11': new ComputedLine((tr): number => {
112 return clampToZero(this.getValue(tr, '9') - this.getValue(tr, '10'));
113 }, 'AMT'),
114
115 // Part III
116 '12': new ReferenceLine(Form6251 as any, '6'),
117 '13': new ComputedLine((tr): number => {
118 const schedDTW = tr.findForm(ScheduleDTaxWorksheet);
119 if (schedDTW)
120 return schedDTW.getValue(tr, '13');
121
122 return tr.getForm(QDCGTaxWorksheet).dividendsAndCapitalGains(tr);
123 }),
124 '14': new ReferenceLine(ScheduleD, '19', undefined, 0),
125 '15': new ComputedLine((tr): number => {
126 const value = this.getValue(tr, '13') + this.getValue(tr, '14');
127 const schedDTW = tr.findForm(ScheduleDTaxWorksheet);
128 if (schedDTW)
129 return Math.min(value, schedDTW.getValue(tr, '10'));
130
131 return value;
132 }),
133 '16': new ComputedLine((tr): number => Math.min(this.getValue(tr, '12'), this.getValue(tr, '15'))),
134 '17': new ComputedLine((tr): number => this.getValue(tr, '12') - this.getValue(tr, '16')),
135 '18': new ComputedLine((tr): number => computeAmtTax(tr, this.getValue(tr, '17'))),
136 '19': new ComputedLine((tr): number => {
137 const fs = tr.getForm(Form1040).filingStatus;
138 return tr.constants.capitalGains.rate0MaxIncome[fs];
139 }),
140 '20': new ComputedLine((tr): number => {
141 const schedDTW = tr.findForm(ScheduleDTaxWorksheet);
142 if (schedDTW)
143 return clampToZero(schedDTW.getValue(tr, '14'));
144
145 return clampToZero(tr.getForm(QDCGTaxWorksheet).taxableIncomeLessDividendsAndCapitalGains(tr));
146 }),
147 '21': new ComputedLine((tr): number => clampToZero(this.getValue(tr, '19') - this.getValue(tr, '20'))),
148 '22': new ComputedLine((tr): number => Math.min(this.getValue(tr, '12'), this.getValue(tr, '13'))),
149 '23': new ComputedLine((tr): number => Math.min(this.getValue(tr, '21'), this.getValue(tr, '22'))),
150 '24': new ComputedLine((tr): number => this.getValue(tr, '22') - this.getValue(tr, '23')),
151 '25': new ComputedLine((tr): number => {
152 const fs = tr.getForm(Form1040).filingStatus;
153 return tr.constants.capitalGains.rate15MaxIncome[fs];
154 }),
155 '26': new ReferenceLine(Form6251 as any, '21'),
156 '27': new ComputedLine((tr): number => {
157 const schedDTW = tr.findForm(ScheduleDTaxWorksheet);
158 if (schedDTW)
159 return clampToZero(schedDTW.getValue(tr, '21'));
160
161 return clampToZero(tr.getForm(QDCGTaxWorksheet).taxableIncomeLessDividendsAndCapitalGains(tr));
162 }),
163 '28': new ComputedLine((tr): number => this.getValue(tr, '26') + this.getValue(tr, '27')),
164 '29': new ComputedLine((tr): number => clampToZero(this.getValue(tr, '25') - this.getValue(tr, '28'))),
165 '30': new ComputedLine((tr): number => Math.min(this.getValue(tr, '24'), this.getValue(tr, '29'))),
166 '31': new ComputedLine((tr): number => this.getValue(tr, '30') * 0.15),
167 '32': new ComputedLine((tr): number => this.getValue(tr, '23') + this.getValue(tr, '30')),
168 '33': new ComputedLine((tr): number => clampToZero(this.getValue(tr, '22') - this.getValue(tr, '32'))),
169 '34': new ComputedLine((tr): number => this.getValue(tr, '33') * 0.20),
170 '35': new ComputedLine((tr): number => this.getValue(tr, '17') + this.getValue(tr, '32') + this.getValue(tr, '33')),
171 '36': new ComputedLine((tr): number => clampToZero(this.getValue(tr, '12') - this.getValue(tr, '35'))),
172 '37': new ComputedLine((tr): number => this.getValue(tr, '36') * 0.25),
173 '38': new ComputedLine((tr): number => sumFormLines(tr, this, ['18', '31', '34', '37'])),
174 '39': new ComputedLine((tr): number => computeAmtTax(tr, this.getValue(tr, '12'))),
175 '40': new ComputedLine((tr): number => Math.min(this.getValue(tr, '38'), this.getValue(tr, '39'))),
176 };
177 };
178
179 function computeAmtTax(tr: TaxReturn, amount) {
180 const fs = tr.getForm(Form1040).filingStatus;
181 const limit = tr.constants.amt.limitForRate28Percent[fs];
182 const sub = limit * 0.02; // Difference between the two rates.
183
184 if (amount < limit)
185 return amount * Literal(0.26);
186 return (amount * Literal(0.28)) - sub;
187 }