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 * as Trace from '../core/Trace';
7 import { Form, Person, TaxReturn } from '../core';
8 import { Line, InputLine, ComputedLine, sumLineOfForms } from '../core/Line';
10 import Form1099B, { GainType } from './Form1099B';
12 export enum Form8949Box {
13 A = 'A', // Short-term transactions reported on Form(s) 1099-B showing basis was reported to the IRS
14 B = 'B', // Short-term transactions reported on Form(s) 1099-B showing basis wasn’t reported to the IRS
15 C = 'C', // Short-term transactions not reported to you on Form 1099-B
16 D = 'D', // Long-term transactions reported on Form(s) 1099-B showing basis was reported to the IRS
17 E = 'E', // Long-term transactions reported on Form(s) 1099-B showing basis wasn’t reported to the IRS
18 F = 'F', // Long-term transactions not reported to you on Form 1099-B
21 export interface Adjustment {
27 export interface Form8949Input {
28 adjustments?: Adjustment[];
31 export interface Form8949Total {
38 function matching1099Bs(tr: TaxReturn, box: Form8949Box): Form1099B[] {
39 return tr.findForms(Form1099B).filter(f => {
40 const gainType: GainType = f.getValue(tr, '2');
41 const basisReported: boolean = f.getValue(tr, '12');
45 return gainType == GainType.ShortTerm && basisReported;
47 return gainType == GainType.ShortTerm && !basisReported;
49 return gainType == GainType.LongTerm && basisReported;
51 return gainType == GainType.LongTerm && !basisReported;
58 class Form8949Line extends Line<Form8949Total> {
59 private _box: Form8949Box;
60 private _line: keyof Form1099B['lines'];
62 constructor(box: Form8949Box) {
63 super(`Form 8949 Box ${box} Total`);
67 value(tr: TaxReturn): Form8949Total {
69 const f1099bs = matching1099Bs(tr, this._box);
70 const proceeds = sumLineOfForms(tr, f1099bs, '1d');
71 const costBasis = sumLineOfForms(tr, f1099bs, '1e');
72 const f8949 = tr.getForm(Form8949);
73 const adjustments = !f8949.hasInput('adjustments') ? 0 :
74 f8949.getInput('adjustments')
75 .filter(a => f1099bs.includes(a.entry))
76 .reduce((acc, curr) => acc + curr.amount, 0);
82 gainOrLoss: proceeds - costBasis + adjustments,
87 export default class Form8949 extends Form<Form8949['_lines'], Form8949Input> {
88 readonly name = '8949';
90 readonly supportsMultipleCopies = true;
92 protected readonly _lines = {
93 'boxA': new Form8949Line(Form8949Box.A),
94 'boxB': new Form8949Line(Form8949Box.B),
95 'boxC': new Form8949Line(Form8949Box.C),
96 'boxD': new Form8949Line(Form8949Box.D),
97 'boxE': new Form8949Line(Form8949Box.E),
98 'boxF': new Form8949Line(Form8949Box.F),