1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
6 import { Form, Person, TaxReturn } from '../core';
7 import { Line, InputLine, ComputedLine, sumLineOfForms } from '../core/Line';
9 import Form1099B, { GainType } from './Form1099B';
11 export enum Form8949Box {
12 A = 'A', // Short-term transactions reported on Form(s) 1099-B showing basis was reported to the IRS
13 B = 'B', // Short-term transactions reported on Form(s) 1099-B showing basis wasn’t reported to the IRS
14 C = 'C', // Short-term transactions not reported to you on Form 1099-B
15 D = 'D', // Long-term transactions reported on Form(s) 1099-B showing basis was reported to the IRS
16 E = 'E', // Long-term transactions reported on Form(s) 1099-B showing basis wasn’t reported to the IRS
17 F = 'F', // Long-term transactions not reported to you on Form 1099-B
20 export interface Adjustment {
26 export interface Form8949Input {
27 adjustments?: Adjustment[];
30 export interface Form8949Total {
37 function matching1099Bs(tr: TaxReturn, box: Form8949Box): Form1099B[] {
38 return tr.findForms(Form1099B).filter(f => {
39 const gainType: GainType = f.getValue(tr, '2');
40 const basisReported: boolean = f.getValue(tr, '12');
44 return gainType == GainType.ShortTerm && basisReported;
46 return gainType == GainType.ShortTerm && !basisReported;
48 return gainType == GainType.LongTerm && basisReported;
50 return gainType == GainType.LongTerm && !basisReported;
57 class Form8949Line extends Line<Form8949Total> {
58 private _box: Form8949Box;
59 private _line: keyof Form1099B['lines'];
61 constructor(box: Form8949Box) {
62 super(`Form 8949 Box ${box} Total`);
66 value(tr: TaxReturn): Form8949Total {
67 const f1099bs = matching1099Bs(tr, this._box);
68 const proceeds = sumLineOfForms(tr, f1099bs, '1d');
69 const costBasis = sumLineOfForms(tr, f1099bs, '1e');
70 const f8949 = tr.getForm(Form8949);
71 const adjustments = !f8949.hasInput('adjustments') ? 0 :
72 f8949.getInput('adjustments')
73 .filter(a => f1099bs.includes(a.entry))
74 .reduce((acc, curr) => acc + curr.amount, 0);
79 gainOrLoss: proceeds - costBasis + adjustments,
84 export default class Form8949 extends Form<Form8949['_lines'], Form8949Input> {
85 readonly name = '8949';
87 readonly supportsMultipleCopies = true;
89 protected readonly _lines = {
90 'boxA': new Form8949Line(Form8949Box.A),
91 'boxB': new Form8949Line(Form8949Box.B),
92 'boxC': new Form8949Line(Form8949Box.C),
93 'boxD': new Form8949Line(Form8949Box.D),
94 'boxE': new Form8949Line(Form8949Box.E),
95 'boxF': new Form8949Line(Form8949Box.F),