From 20294b3b3f83fae1efdd76cb25a699afcc56c699 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 10 Mar 2020 01:17:44 -0400 Subject: [PATCH] Use Math helpers in more forms. --- src/fed2019/Form1040.ts | 22 +++++----------------- src/fed2019/Form1116.ts | 2 +- src/fed2019/Form8606.ts | 12 +++++------- src/fed2019/Form8960.ts | 2 +- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/fed2019/Form1040.ts b/src/fed2019/Form1040.ts index 504c839..f6fdc94 100644 --- a/src/fed2019/Form1040.ts +++ b/src/fed2019/Form1040.ts @@ -1,7 +1,7 @@ import { Form, TaxReturn } from '../core'; import { Line, AccumulatorLine, ComputedLine, ReferenceLine, sumLineOfForms } from '../core/Line'; import { UnsupportedFeatureError } from '../core/Errors'; -import { reduceBySum } from '../core/Math'; +import { clampToZero, reduceBySum } from '../core/Math'; import Form8606 from './Form8606'; import Form8959 from './Form8959'; @@ -101,8 +101,7 @@ export default class Form1040 extends Form { return this.getValue(tr, '9') + this.getValue(tr, '10'); }), '11b': new ComputedLine((tr): number => { - const value = this.getValue(tr, '8b') - this.getValue(tr, '11a'); - return value < 0 ? 0 : value; + return clampToZero(this.getValue(tr, '8b') - this.getValue(tr, '11a')); }, 'Taxable income'), '12a': new ComputedLine((tr): number => { @@ -130,10 +129,7 @@ export default class Form1040 extends Form { '13b': new ReferenceLine(Schedule3, '7', 'Additional credits', 0), '14': new ComputedLine((tr): number => { - const l12b = this.getValue(tr, '12b'); - const l13b = this.getValue(tr, '13b'); - const value = l12b - l13b; - return value < 0 ? 0 : value; + return clampToZero(this.getValue(tr, '12b') - this.getValue(tr, '13b')); }), '15': new ReferenceLine(Schedule2, '10', undefined, 0), @@ -174,19 +170,11 @@ export default class Form1040 extends Form { }, 'Total payments'), '20': new ComputedLine((tr): number => { - const l16: number = this.getValue(tr, '16'); - const l19: number = this.getValue(tr, '19'); - if (l19 > l16) - return l19 - l16; - return 0; + return clampToZero(this.getValue(tr, '19') - this.getValue(tr, '16')); }, 'Amount overpaid'), '23': new ComputedLine((tr): number => { - const l16 = this.getValue(tr, '16'); - const l19 = this.getValue(tr, '19'); - if (l19 < l16) - return l16 - l19; - return 0; + return clampToZero(this.getValue(tr, '16') - this.getValue(tr, '19')); }, 'Amount you owe'), }; }; diff --git a/src/fed2019/Form1116.ts b/src/fed2019/Form1116.ts index 7e90a86..919be2a 100644 --- a/src/fed2019/Form1116.ts +++ b/src/fed2019/Form1116.ts @@ -78,7 +78,7 @@ export default class Form1116 extends Form { }), '7': new ComputedLine((tr): number => this.getValue(tr, '1a') - this.getValue(tr, '6')), // Skip the complicated Part II matrix and just use the input value. - '8': new Input('totalForeignTaxesPaidOrAccrued'), + '8': new Input('totalForeignTaxesPaidOrAccrued'), '9': new ReferenceLine(Form1116 as any, '8'), // 10 not supported - Carryback or carryover '11': new ComputedLine((tr): number => this.getValue(tr, '9') /* + this.getValue(tr, '10') */), diff --git a/src/fed2019/Form8606.ts b/src/fed2019/Form8606.ts index 0aa2604..0e9d1ce 100644 --- a/src/fed2019/Form8606.ts +++ b/src/fed2019/Form8606.ts @@ -1,6 +1,6 @@ import { Form, Person, TaxReturn } from '../core'; import { Line, AccumulatorLine, ComputedLine, InputLine, ReferenceLine } from '../core/Line'; -import { clampToZero } from '../core/Math'; +import { clampToZero, undefinedToZero } from '../core/Math'; export interface Form8606Input { person: Person; @@ -33,11 +33,9 @@ export default class Form8606 extends Form { '7': new Input('distributionsFromAllTradSepSimpleIras'), '8': new Input('amountConvertedFromTradSepSimpleToRoth'), '9': new ComputedLine((tr): number => { - let value = 0; - value += this.getValue(tr, '6') || 0; - value += this.getValue(tr, '7') || 0; - value += this.getValue(tr, '8') || 0; - return value; + return undefinedToZero(this.getValue(tr, '6')) + + undefinedToZero(this.getValue(tr, '7')) + + undefinedToZero(this.getValue(tr, '8')); }), '10': new ComputedLine((tr): number => this.getValue(tr, '5') / this.getValue(tr, '9')), '11': new ComputedLine((tr): number => this.getValue(tr, '8') * this.getValue(tr, '10'), 'Nontaxable portion converted to Roth'), @@ -51,7 +49,7 @@ export default class Form8606 extends Form { }, 'Total basis in Traditional IRAs'), '15a': new ComputedLine((tr): number => this.getValue(tr, '7') - this.getValue(tr, '12')), '15b': new ComputedLine((): number => 0, 'Amount attributable to qualified disaster distributions'), - // 15b not supported - amount on line 15a attributable + // 15b not supported - amount on line 15a attributable '15c': new ComputedLine((tr): number => this.getValue(tr, '15a') - this.getValue(tr, '15b'), 'Taxable amount'), // Part 2 diff --git a/src/fed2019/Form8960.ts b/src/fed2019/Form8960.ts index 86524f0..ea24d34 100644 --- a/src/fed2019/Form8960.ts +++ b/src/fed2019/Form8960.ts @@ -15,7 +15,7 @@ export default class Form8960 extends Form { '2': new ReferenceLine(Form1040, '3b', 'Ordinary dividends'), // 3 not supported - Annuities // 4a not supported - Rental real estate, royalties, partnerships, S corporations, trusts, etc - // 4b not supported - Adjustment for net income or loss derived in the ordinary course of a nonsection 1411 trade or business + // 4b not supported - Adjustment for net income or loss derived in the ordinary course of a nonsection 1411 trade or business // 4c not supported - 4a+4b '5a': new ComputedLine((tr): number => { return (new ReferenceLine(Form1040, '6')).value(tr) + -- 2.22.5