Implement Form.person() on fed2019 forms.
[ustaxlib.git] / src / fed2019 / Form8606.ts
1 import { Form, Person, TaxReturn } from '../core';
2 import { Line, AccumulatorLine, ComputedLine, InputLine, ReferenceLine } from '../core/Line';
3 import { clampToZero, undefinedToZero } from '../core/Math';
4
5 export interface Form8606Input {
6 person: Person;
7 nondeductibleContributions: number;
8 traditionalIraBasis: number;
9 distributionFromTradSepOrSimpleIraOrMadeRothConversion: boolean;
10 contributionsMadeInCurrentYear?: number;
11 valueOfAllTradSepSimpleIras?: number;
12 distributionsFromAllTradSepSimpleIras?: number;
13 amountConvertedFromTradSepSimpleToRoth?: number;
14 };
15
16 class Input<T extends keyof Form8606Input> extends InputLine<Form8606Input, T> {};
17
18 export default class Form8606 extends Form<Form8606['_lines'], Form8606Input> {
19 readonly name = '8606';
20
21 readonly supportsMultipleCopies = true;
22
23 person() { return this.getInput('person'); }
24
25 protected readonly _lines = {
26 'person': new Input('person'),
27
28 // Part 1
29 '1': new Input('nondeductibleContributions'),
30 '2': new Input('traditionalIraBasis'),
31 '3': new ComputedLine((tr): number => this.getValue(tr, '1') + this.getValue(tr, '2')),
32 '4': new Input('contributionsMadeInCurrentYear'),
33 '5': new ComputedLine((tr): number => this.getValue(tr, '3') - this.getValue(tr, '4')),
34 '6': new Input('valueOfAllTradSepSimpleIras'),
35 '7': new Input('distributionsFromAllTradSepSimpleIras'),
36 '8': new Input('amountConvertedFromTradSepSimpleToRoth'),
37 '9': new ComputedLine((tr): number => {
38 return undefinedToZero(this.getValue(tr, '6')) +
39 undefinedToZero(this.getValue(tr, '7')) +
40 undefinedToZero(this.getValue(tr, '8'));
41 }),
42 '10': new ComputedLine((tr): number => this.getValue(tr, '5') / this.getValue(tr, '9')),
43 '11': new ComputedLine((tr): number => this.getValue(tr, '8') * this.getValue(tr, '10'), 'Nontaxable portion converted to Roth'),
44 '12': new ComputedLine((tr): number => this.getValue(tr, '7') * this.getValue(tr, '10'), 'Nontaxable portion of distributions not converted to Roth'),
45 '13': new ComputedLine((tr): number => this.getValue(tr, '11') + this.getValue(tr, '12'), 'Nontaxable portion of all distributions'),
46 '14': new ComputedLine((tr): number => {
47 const l3 = this.getValue(tr, '3');
48 if (!this.getInput('distributionFromTradSepOrSimpleIraOrMadeRothConversion'))
49 return l3;
50 return l3 - this.getValue(tr, '13');
51 }, 'Total basis in Traditional IRAs'),
52 '15a': new ComputedLine((tr): number => this.getValue(tr, '7') - this.getValue(tr, '12')),
53 '15b': new ComputedLine((): number => 0, 'Amount attributable to qualified disaster distributions'),
54 // 15b not supported - amount on line 15a attributable
55 '15c': new ComputedLine((tr): number => this.getValue(tr, '15a') - this.getValue(tr, '15b'), 'Taxable amount'),
56
57 // Part 2
58 '16': new ReferenceLine(Form8606 as any, '8'),
59 '17': new ReferenceLine(Form8606 as any, '11'),
60 '18': new ComputedLine((tr): number => this.getValue(tr, '16') - this.getValue(tr, '17')),
61 };
62 };