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