1 import Form from '../Form';
2 import Person from '../Person';
3 import TaxReturn from '../TaxReturn';
4 import { Line, InputLine, ComputedLine, sumLineOfForms } from '../Line';
6 import Form1099B, { GainType } from './Form1099B';
8 export enum Form8949Box {
9 A = 'A', // Short-term transactions reported on Form(s) 1099-B showing basis was reported to the IRS
10 B = 'B', // Short-term transactions reported on Form(s) 1099-B showing basis wasn’t reported to the IRS
11 C = 'C', // Short-term transactions not reported to you on Form 1099-B
12 D = 'D', // Long-term transactions reported on Form(s) 1099-B showing basis was reported to the IRS
13 E = 'E', // Long-term transactions reported on Form(s) 1099-B showing basis wasn’t reported to the IRS
14 F = 'F', // Long-term transactions not reported to you on Form 1099-B
17 export interface Adjustment {
23 export interface Form8949Input {
24 adjustments?: Adjustment[];
27 export interface Form8949Total {
34 function matching1099Bs(tr: TaxReturn, box: Form8949Box): Form1099B[] {
35 return tr.findForms(Form1099B).filter(f => {
36 const gainType: GainType = f.getValue(tr, '2');
37 const basisReported: boolean = f.getValue(tr, '12');
41 return gainType == GainType.ShortTerm && basisReported;
43 return gainType == GainType.ShortTerm && !basisReported;
45 return gainType == GainType.LongTerm && basisReported;
47 return gainType == GainType.LongTerm && !basisReported;
54 class Form8949Line extends Line<Form8949Total> {
55 private _box: Form8949Box;
56 private _line: keyof Form1099B['lines'];
58 constructor(box: Form8949Box) {
59 super(`Form 8949 Box ${box} Total`);
63 value(tr: TaxReturn): Form8949Total {
64 const f1099bs = matching1099Bs(tr, this._box);
65 const proceeds = sumLineOfForms(tr, f1099bs, '1d');
66 const costBasis = sumLineOfForms(tr, f1099bs, '1e');
67 const f8949 = tr.getForm(Form8949);
68 const adjustments = !f8949.hasInput('adjustments') ? 0 :
69 f8949.getInput('adjustments')
70 .filter(a => f1099bs.includes(a.entry))
71 .reduce((acc, curr) => acc + curr.amount, 0);
76 gainOrLoss: proceeds - costBasis + adjustments,
81 export default class Form8949 extends Form<Form8949['_lines'], Form8949Input> {
82 readonly name = '8949';
84 readonly supportsMultipleCopies = true;
86 protected readonly _lines = {
87 'boxA': new Form8949Line(Form8949Box.A),
88 'boxB': new Form8949Line(Form8949Box.B),
89 'boxC': new Form8949Line(Form8949Box.C),
90 'boxD': new Form8949Line(Form8949Box.D),
91 'boxE': new Form8949Line(Form8949Box.E),
92 'boxF': new Form8949Line(Form8949Box.F),