Add license information.
[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 { NotFoundError, UnsupportedFeatureError } from '../core/Errors';
9 import { undefinedToZero } from '../core/Math';
10
11 import Form1040 from './Form1040';
12
13 export interface Schedule1Input {
14 // Additional Income
15 stateAndLocalTaxableRefunds?: number;
16 alimonyReceived?: number;
17 businessIncome?: number;
18 otherGainsOrLosses?: number
19 rentalRealEstateRoyaltiesPartnershipsSCorps?: number;
20 farmIncome?: number;
21 unemploymentCompensation?: number;
22 otherIncome?: number;
23
24 // Adjustments
25 educatorExpenses?: number;
26 businessExpensesForm2106?: number;
27 hsaDeduction?: number;
28 armedForcesMovingExpenses?: number;
29 deductibleSelfEmploymentTax?: number;
30 selfEmployedSepSimpleQualifiedPlans?: number;
31 selfEmployedHealthInsuranceDeduction?: number;
32 penaltyOnEarlyWithdrawal?: number;
33 alimonyPaid?: number;
34 iraDeduction?: number;
35 studentLoanInterestDeduction?: number;
36 tuitionAndFees?: number;
37 };
38
39 class Input<T extends keyof Schedule1Input> extends InputLine<Schedule1Input, T> {
40 private _predicate: (value: Schedule1Input[T]) => void;
41
42 constructor(input: T, predicate?: (value: Schedule1Input[T]) => void) {
43 super(input);
44 this._predicate = predicate;
45 }
46
47 value(tr: TaxReturn): Schedule1Input[T] {
48 let value: Schedule1Input[T] = undefined;
49 try {
50 value = super.value(tr);
51 } catch (NotFoundError) {
52 }
53 if (this._predicate)
54 this._predicate(value);
55 return value;
56 }
57 };
58
59 export default class Schedule1 extends Form<Schedule1['_lines'], Schedule1Input> {
60 readonly name = 'Schedule 1';
61
62 readonly _lines = {
63 // Part 1
64 '1': new Input('stateAndLocalTaxableRefunds'),
65 '2': new Input('alimonyReceived'),
66 '3': new Input('businessIncome', (value: number) => {
67 if (value !== undefined)
68 throw new UnsupportedFeatureError('Schedule C not supported');
69 }),
70 '4': new Input('otherGainsOrLosses', (value: number) => {
71 if (value !== undefined)
72 throw new UnsupportedFeatureError('Form 4797 not supported');
73 }),
74 '5': new Input('rentalRealEstateRoyaltiesPartnershipsSCorps', (value: number) => {
75 if (value !== undefined)
76 throw new UnsupportedFeatureError('Schedule E not supported');
77 }),
78 '6': new Input('farmIncome', (value: number) => {
79 if (value !== undefined)
80 throw new UnsupportedFeatureError('Schedule F not supported');
81 }),
82 '7': new Input('unemploymentCompensation'),
83 '8': new Input('otherIncome'),
84 '9': new ComputedLine((tr): number => {
85 return undefinedToZero(this.getValue(tr, '1')) +
86 undefinedToZero(this.getValue(tr, '2')) +
87 undefinedToZero(this.getValue(tr, '3')) +
88 undefinedToZero(this.getValue(tr, '4')) +
89 undefinedToZero(this.getValue(tr, '5')) +
90 undefinedToZero(this.getValue(tr, '6')) +
91 undefinedToZero(this.getValue(tr, '7')) +
92 undefinedToZero(this.getValue(tr, '8'));
93 }),
94
95 // Part 2
96 '10': new Input('educatorExpenses'),
97 '11': new Input('businessExpensesForm2106', (value: number) => {
98 if (value !== undefined)
99 throw new UnsupportedFeatureError('Form 2106 not supported');
100 }),
101 '12': new Input('hsaDeduction', (value: number) => {
102 if (value !== undefined)
103 throw new UnsupportedFeatureError('Form 8889 not supported');
104 }),
105 '13': new Input('armedForcesMovingExpenses', (value: number) => {
106 if (value !== undefined)
107 throw new UnsupportedFeatureError('Form 3903 not supported');
108 }),
109 '14': new Input('deductibleSelfEmploymentTax', (value: number) => {
110 if (value !== undefined)
111 throw new UnsupportedFeatureError('Schedule SE not supported');
112 }),
113 '15': new Input('selfEmployedSepSimpleQualifiedPlans'),
114 '16': new Input('selfEmployedHealthInsuranceDeduction'),
115 '17': new Input('penaltyOnEarlyWithdrawal'),
116 '18': new Input('alimonyPaid'),
117 '19': new Input('iraDeduction'),
118 '20': new Input('studentLoanInterestDeduction'),
119 '21': new Input('tuitionAndFees', (value: number) => {
120 if (value !== undefined)
121 throw new UnsupportedFeatureError('Form 8917 not supported');
122 }),
123 '22': new ComputedLine((tr): number => {
124 return undefinedToZero(this.getValue(tr, '10')) +
125 undefinedToZero(this.getValue(tr, '11')) +
126 undefinedToZero(this.getValue(tr, '12')) +
127 undefinedToZero(this.getValue(tr, '13')) +
128 undefinedToZero(this.getValue(tr, '14')) +
129 undefinedToZero(this.getValue(tr, '15')) +
130 undefinedToZero(this.getValue(tr, '16')) +
131 undefinedToZero(this.getValue(tr, '17')) +
132 undefinedToZero(this.getValue(tr, '18')) +
133 undefinedToZero(this.getValue(tr, '19')) +
134 undefinedToZero(this.getValue(tr, '20')) +
135 undefinedToZero(this.getValue(tr, '21'));
136 }),
137 };
138 };