-import { Line, InputLine, ReferenceLine, ComputedLine } from './Line';
-import Form from './Form';
+import { Line, AccumulatorLine, InputLine, ReferenceLine, ComputedLine } from './Line';
+import Form, { SupportsMultipleCopies } from './Form';
import TaxReturn from './TaxReturn';
import { NotFoundError } from './Errors';
const l = new ReferenceLine<number>('32', 'Z-2', '2c');
expect(l.value(tr)).toBe(20);
});
+
+test('accumulator line', () => {
+ class TestForm extends Form implements SupportsMultipleCopies {
+ get name() { return 'Form B'; }
+
+ aggregate() { return null; }
+
+ protected getLines() {
+ return [ new ConstantLine<number>('g', 100.25) ]
+ }
+ };
+
+ const tr = new TaxReturn(2019);
+ tr.addForm(new TestForm());
+ tr.addForm(new TestForm());
+ tr.addForm(new TestForm());
+
+ const l = new AccumulatorLine('line', 'Form B', 'g');
+ expect(l.value(tr)).toBe(300.75);
+});
return this.form.getInput(this._input) as any;
}
};
+
+export class AccumulatorLine extends Line<number> {
+ private _form: string;
+ private _line: string;
+
+ constructor(id: string, form: string, line: string, description?: string) {
+ super(id, description || `Accumulator F${form}.L${line}`);
+ this._form = form;
+ this._line = line;
+ }
+
+ value(tr: TaxReturn): number {
+ const forms = tr.getForms(this._form);
+ const reducer = (acc: number, curr: Form) => acc + curr.getValue<number>(tr, this._line);
+ return forms.reduce(reducer, 0);
+ }
+};