]> src.bluestatic.org Git - ustaxlib.git/blob - src/fed2019/Schedule1.ts
Fix some bugs in tracing, and add a reset() function.
[ustaxlib.git] / src / fed2019 / Schedule1.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, InputLine } from '../core/Line';
8 import * as Trace from '../core/Trace';
9 import { NotFoundError, UnsupportedFeatureError } from '../core/Errors';
10 import { undefinedToZero } from '../core/Math';
11
12 import Form1040 from './Form1040';
13
14 export interface Schedule1Input {
15 // Additional Income
16 stateAndLocalTaxableRefunds?: number;
17 alimonyReceived?: number;
18 businessIncome?: number;
19 otherGainsOrLosses?: number
20 rentalRealEstateRoyaltiesPartnershipsSCorps?: number;
21 farmIncome?: number;
22 unemploymentCompensation?: number;
23 otherIncome?: number;
24
25 // Adjustments
26 educatorExpenses?: number;
27 businessExpensesForm2106?: number;
28 hsaDeduction?: number;
29 armedForcesMovingExpenses?: number;
30 deductibleSelfEmploymentTax?: number;
31 selfEmployedSepSimpleQualifiedPlans?: number;
32 selfEmployedHealthInsuranceDeduction?: number;
33 penaltyOnEarlyWithdrawal?: number;
34 alimonyPaid?: number;
35 iraDeduction?: number;
36 studentLoanInterestDeduction?: number;
37 tuitionAndFees?: number;
38 };
39
40 class Input<T extends keyof Schedule1Input> extends InputLine<Schedule1Input, T> {
41 private _predicate: (value: Schedule1Input[T]) => void;
42
43 constructor(input: T, predicate?: (value: Schedule1Input[T]) => void) {
44 super(input);
45 this._predicate = predicate;
46 }
47
48 value(tr: TaxReturn): Schedule1Input[T] {
49 let value: Schedule1Input[T] = undefined;
50 try {
51 value = super.value(tr);
52 } catch (NotFoundError) {
53 Trace.end();
54 }
55 if (this._predicate)
56 this._predicate(value);
57 return value;
58 }
59 };
60
61 export default class Schedule1 extends Form<Schedule1['_lines'], Schedule1Input> {
62 readonly name = 'Schedule 1';
63
64 readonly _lines = {
65 // Part 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');
71 }),
72 '4': new Input('otherGainsOrLosses', (value: number) => {
73 if (value !== undefined)
74 throw new UnsupportedFeatureError('Form 4797 not supported');
75 }),
76 '5': new Input('rentalRealEstateRoyaltiesPartnershipsSCorps', (value: number) => {
77 if (value !== undefined)
78 throw new UnsupportedFeatureError('Schedule E not supported');
79 }),
80 '6': new Input('farmIncome', (value: number) => {
81 if (value !== undefined)
82 throw new UnsupportedFeatureError('Schedule F not supported');
83 }),
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'));
95 }),
96
97 // Part 2
98 '10': new Input('educatorExpenses'),
99 '11': new Input('businessExpensesForm2106', (value: number) => {
100 if (value !== undefined)
101 throw new UnsupportedFeatureError('Form 2106 not supported');
102 }),
103 '12': new Input('hsaDeduction', (value: number) => {
104 if (value !== undefined)
105 throw new UnsupportedFeatureError('Form 8889 not supported');
106 }),
107 '13': new Input('armedForcesMovingExpenses', (value: number) => {
108 if (value !== undefined)
109 throw new UnsupportedFeatureError('Form 3903 not supported');
110 }),
111 '14': new Input('deductibleSelfEmploymentTax', (value: number) => {
112 if (value !== undefined)
113 throw new UnsupportedFeatureError('Schedule SE not supported');
114 }),
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');
124 }),
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'));
138 }),
139 };
140 };