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 Form1040 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<Schedule1['_lines'], Schedule1Input> {
62 readonly name = 'Schedule 1';
66 '1': new Input('stateAndLocalTaxableRefunds'),
67 '2': new Input('alimonyReceived'),
68 '3': new Input('businessIncome', (value: number) => {
69 if (value !== undefined)
70 throw new UnsupportedFeatureError('Schedule C not supported');
72 '4': new Input('otherGainsOrLosses', (value: number) => {
73 if (value !== undefined)
74 throw new UnsupportedFeatureError('Form 4797 not supported');
76 '5': new Input('rentalRealEstateRoyaltiesPartnershipsSCorps', (value: number) => {
77 if (value !== undefined)
78 throw new UnsupportedFeatureError('Schedule E not supported');
80 '6': new Input('farmIncome', (value: number) => {
81 if (value !== undefined)
82 throw new UnsupportedFeatureError('Schedule F not supported');
84 '7': new Input('unemploymentCompensation'),
85 '8': new Input('otherIncome'),
86 '9': new ComputedLine((tr): number => {
87 return undefinedToZero(this.getValue(tr, '1')) +
88 undefinedToZero(this.getValue(tr, '2')) +
89 undefinedToZero(this.getValue(tr, '3')) +
90 undefinedToZero(this.getValue(tr, '4')) +
91 undefinedToZero(this.getValue(tr, '5')) +
92 undefinedToZero(this.getValue(tr, '6')) +
93 undefinedToZero(this.getValue(tr, '7')) +
94 undefinedToZero(this.getValue(tr, '8'));
98 '10': new Input('educatorExpenses'),
99 '11': new Input('businessExpensesForm2106', (value: number) => {
100 if (value !== undefined)
101 throw new UnsupportedFeatureError('Form 2106 not supported');
103 '12': new Input('hsaDeduction', (value: number) => {
104 if (value !== undefined)
105 throw new UnsupportedFeatureError('Form 8889 not supported');
107 '13': new Input('armedForcesMovingExpenses', (value: number) => {
108 if (value !== undefined)
109 throw new UnsupportedFeatureError('Form 3903 not supported');
111 '14': new Input('deductibleSelfEmploymentTax', (value: number) => {
112 if (value !== undefined)
113 throw new UnsupportedFeatureError('Schedule SE not supported');
115 '15': new Input('selfEmployedSepSimpleQualifiedPlans'),
116 '16': new Input('selfEmployedHealthInsuranceDeduction'),
117 '17': new Input('penaltyOnEarlyWithdrawal'),
118 '18': new Input('alimonyPaid'),
119 '19': new Input('iraDeduction'),
120 '20': new Input('studentLoanInterestDeduction'),
121 '21': new Input('tuitionAndFees', (value: number) => {
122 if (value !== undefined)
123 throw new UnsupportedFeatureError('Form 8917 not supported');
125 '22': new ComputedLine((tr): number => {
126 return undefinedToZero(this.getValue(tr, '10')) +
127 undefinedToZero(this.getValue(tr, '11')) +
128 undefinedToZero(this.getValue(tr, '12')) +
129 undefinedToZero(this.getValue(tr, '13')) +
130 undefinedToZero(this.getValue(tr, '14')) +
131 undefinedToZero(this.getValue(tr, '15')) +
132 undefinedToZero(this.getValue(tr, '16')) +
133 undefinedToZero(this.getValue(tr, '17')) +
134 undefinedToZero(this.getValue(tr, '18')) +
135 undefinedToZero(this.getValue(tr, '19')) +
136 undefinedToZero(this.getValue(tr, '20')) +
137 undefinedToZero(this.getValue(tr, '21'));