Use Math helpers in more forms.
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 10 Mar 2020 05:17:44 +0000 (01:17 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 10 Mar 2020 05:17:44 +0000 (01:17 -0400)
src/fed2019/Form1040.ts
src/fed2019/Form1116.ts
src/fed2019/Form8606.ts
src/fed2019/Form8960.ts

index 504c839410150cd9308d4cdc69e20884712e73ae..f6fdc94d0607b00954b9867a875b1e0e8658ef5f 100644 (file)
@@ -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<Form1040['_lines'], Form1040Input> {
       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<Form1040['_lines'], Form1040Input> {
     '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<Form1040['_lines'], Form1040Input> {
     }, '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'),
   };
 };
index 7e90a868f34cfa09521b9c8317d4adc2e89c2266..919be2a0b24073413063be641a66cacebfe52a56 100644 (file)
@@ -78,7 +78,7 @@ export default class Form1116 extends Form<Form1116['_lines'], Form1116Input> {
     }),
     '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') */),
index 0aa2604826d0be6884503a6cafa9966709c1a7e5..0e9d1ce6acbb344cc6c8f67fdfa68ac940d8b3b1 100644 (file)
@@ -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<Form8606['_lines'], Form8606Input> {
     '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<Form8606['_lines'], Form8606Input> {
     }, '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
index 86524f0c2f66af6bb6d320ede4f8a1a139f29ecc..ea24d3474e581c3a23a6890e43a12ae893313bff 100644 (file)
@@ -15,7 +15,7 @@ export default class Form8960 extends Form<Form8960['_lines']> {
     '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) +