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
6 import { Form, TaxReturn } from '../core';
7 import { ComputedLine, InputLine } from '../core/Line';
8 import * as Trace from '../core/Trace';
9 import { NotFoundError, UnsupportedFeatureError } from '../core/Errors';
10 import { undefinedToZero } from '../core/Math';
12 import { FilingStatus } from './Form1040';
14 export interface Schedule1Input {
16 stateAndLocalTaxableRefunds?: number;
17 alimonyReceived?: number;
18 businessIncome?: number;
19 otherGainsOrLosses?: number
20 rentalRealEstateRoyaltiesPartnershipsSCorps?: number;
22 unemploymentCompensation?: number;
26 educatorExpenses?: number;
27 businessExpensesForm2106?: number;
28 hsaDeduction?: number;
29 armedForcesMovingExpenses?: number;
30 deductibleSelfEmploymentTax?: number;
31 selfEmployedSepSimpleQualifiedPlans?: number;
32 selfEmployedHealthInsuranceDeduction?: number;
33 penaltyOnEarlyWithdrawal?: number;
35 iraDeduction?: number;
36 studentLoanInterestDeduction?: number;
37 tuitionAndFees?: number;
40 class Input<T extends keyof Schedule1Input> extends InputLine<Schedule1Input, T> {
41 private _predicate: (value: Schedule1Input[T]) => void;
43 constructor(input: T, predicate?: (value: Schedule1Input[T]) => void) {
45 this._predicate = predicate;
48 value(tr: TaxReturn): Schedule1Input[T] {
49 let value: Schedule1Input[T] = undefined;
51 value = super.value(tr);
52 } catch (NotFoundError) {
56 this._predicate(value);
61 export default class Schedule1 extends Form<Schedule1Input> {
62 readonly name = 'Schedule 1';
66 '1': new ComputedLine((tr): number => {
67 if (this.hasInput('stateAndLocalTaxableRefunds'))
68 return tr.getForm(SALTWorksheet).getValue(tr, '9');
70 }, 'Taxable refunds, credits, or offsets of state and local income taxes'),
71 '2': new Input('alimonyReceived'),
72 '3': new Input('businessIncome', (value: number) => {
73 if (value !== undefined)
74 throw new UnsupportedFeatureError('Schedule C not supported');
76 '4': new Input('otherGainsOrLosses', (value: number) => {
77 if (value !== undefined)
78 throw new UnsupportedFeatureError('Form 4797 not supported');
80 '5': new Input('rentalRealEstateRoyaltiesPartnershipsSCorps', (value: number) => {
81 if (value !== undefined)
82 throw new UnsupportedFeatureError('Schedule E not supported');
84 '6': new Input('farmIncome', (value: number) => {
85 if (value !== undefined)
86 throw new UnsupportedFeatureError('Schedule F not supported');
88 '7': new Input('unemploymentCompensation'),
89 '8': new Input('otherIncome'),
90 '9': new ComputedLine((tr): number => {
91 return undefinedToZero(this.getValue(tr, '1')) +
92 undefinedToZero(this.getValue(tr, '2')) +
93 undefinedToZero(this.getValue(tr, '3')) +
94 undefinedToZero(this.getValue(tr, '4')) +
95 undefinedToZero(this.getValue(tr, '5')) +
96 undefinedToZero(this.getValue(tr, '6')) +
97 undefinedToZero(this.getValue(tr, '7')) +
98 undefinedToZero(this.getValue(tr, '8'));
102 '10': new Input('educatorExpenses'),
103 '11': new Input('businessExpensesForm2106', (value: number) => {
104 if (value !== undefined)
105 throw new UnsupportedFeatureError('Form 2106 not supported');
107 '12': new Input('hsaDeduction', (value: number) => {
108 if (value !== undefined)
109 throw new UnsupportedFeatureError('Form 8889 not supported');
111 '13': new Input('armedForcesMovingExpenses', (value: number) => {
112 if (value !== undefined)
113 throw new UnsupportedFeatureError('Form 3903 not supported');
115 '14': new Input('deductibleSelfEmploymentTax', (value: number) => {
116 if (value !== undefined)
117 throw new UnsupportedFeatureError('Schedule SE not supported');
119 '15': new Input('selfEmployedSepSimpleQualifiedPlans'),
120 '16': new Input('selfEmployedHealthInsuranceDeduction'),
121 '17': new Input('penaltyOnEarlyWithdrawal'),
122 '18': new Input('alimonyPaid'),
123 '19': new Input('iraDeduction'),
124 '20': new Input('studentLoanInterestDeduction'),
125 '21': new Input('tuitionAndFees', (value: number) => {
126 if (value !== undefined)
127 throw new UnsupportedFeatureError('Form 8917 not supported');
129 '22': new ComputedLine((tr): number => {
130 return undefinedToZero(this.getValue(tr, '10')) +
131 undefinedToZero(this.getValue(tr, '11')) +
132 undefinedToZero(this.getValue(tr, '12')) +
133 undefinedToZero(this.getValue(tr, '13')) +
134 undefinedToZero(this.getValue(tr, '14')) +
135 undefinedToZero(this.getValue(tr, '15')) +
136 undefinedToZero(this.getValue(tr, '16')) +
137 undefinedToZero(this.getValue(tr, '17')) +
138 undefinedToZero(this.getValue(tr, '18')) +
139 undefinedToZero(this.getValue(tr, '19')) +
140 undefinedToZero(this.getValue(tr, '20')) +
141 undefinedToZero(this.getValue(tr, '21'));
146 export interface SALTWorksheetInput {
147 prevYearSalt: number; // ScheduleA@5d.
148 limitedPrevYearSalt: number; // ScheduleA@5e.
149 prevYearItemizedDeductions?: number; // ScheduleA@17.
150 prevYearFilingStatus?: FilingStatus;
153 export class SALTWorksheet extends Form<SALTWorksheetInput> {
154 readonly name = 'SALT Refund Worksheet';
157 '1': new ComputedLine((tr): number => {
158 const refunds = tr.findForm(Schedule1).getInput('stateAndLocalTaxableRefunds');
159 const prevYear = this.getInput('prevYearSalt');
160 return refunds > prevYear ? prevYear : refunds;
162 '2': new ComputedLine((tr): [number, boolean] => {
163 const prevYearSalt = this.getInput('prevYearSalt');
164 const limitedPrevYearSalt = this.getInput('limitedPrevYearSalt');
165 if (prevYearSalt > limitedPrevYearSalt) {
166 return [prevYearSalt - limitedPrevYearSalt, true];
168 return [this.getValue(tr, '1'), false];
169 }, 'Remainder of SALT limitation'),
170 '3': new ComputedLine((tr): number => {
171 const l1 = this.getValue(tr, '1');
172 const l2 = this.getValue(tr, '2');
177 // Else: none of refund is taxable.
180 '4': new InputLine<SALTWorksheetInput>('prevYearItemizedDeductions'),
181 '5': new ComputedLine((tr): number => {
182 const fs = this.getInput('prevYearFilingStatus');
183 return tr.constants.prevYearStandardDeduction[fs];
184 }, 'Previous year standard deduction'),
185 '6': new ComputedLine((tr): number => 0, 'Special situations'), // Not supported
186 '7': new ComputedLine((tr): number => this.getValue(tr, '5') + this.getValue(tr, '6')),
187 '8': new ComputedLine((tr): number => {
188 const l4 = this.getValue(tr, '4');
189 const l7 = this.getValue(tr, '7');
192 // Else: none of refund is taxable.
195 '9': new ComputedLine((tr): number => Math.min(this.getValue(tr, '3'), this.getValue(tr, '8')), 'Taxable refund')