Initial work on Schedule D, Form 8949, and 1099-B.
[ustaxlib.git] / src / fed2019 / ScheduleD.ts
1 import Form from '../Form';
2 import Person from '../Person';
3 import TaxReturn from '../TaxReturn';
4 import { Line, AccumulatorLine, ComputedLine, sumLineOfForms } from '../Line';
5
6 import Form8949, { Form8949Box } from './Form8949';
7 import Form1099DIV from './Form1099DIV';
8 import Form1040, { FilingStatus } from './Form1040';
9
10 class ScheduleDTotal extends Line<number> {
11 private _line: keyof Form8949['lines'];
12 private _box: Form8949Box;
13
14 constructor(description: string, line: keyof Form8949['lines'], box: Form8949Box) {
15 super(description);
16 this._line = line;
17 this._box = box;
18 }
19
20 value(tr: TaxReturn): number {
21 const forms: Form8949[] = tr.findForms(Form8949).filter(f => f.getValue(tr, 'Box') == this._box);
22 return sumLineOfForms(tr, forms, this._line);
23 }
24 };
25
26 export default class ScheduleD extends Form<ScheduleD['_lines']> {
27 readonly name = 'Schedule D';
28
29 protected readonly _lines = {
30 // 1a not supported (Totals for all short-term transactions reported on Form 1099-B for which basis was reported to the IRS and for which you have no adjustments)
31
32 '1b(d)': new ScheduleDTotal('Proceeds of short-term basis reported', '2(d)', Form8949Box.A),
33 '1b(e)': new ScheduleDTotal('Cost basis of short-term basis-reported', '2(e)', Form8949Box.A),
34 '1b(g)': new ScheduleDTotal('Adjustments to short-term basis-reported', '2(g)', Form8949Box.A),
35 '1b(h)': new ComputedLine((tr: TaxReturn): number => {
36 return (this.getValue(tr, '1b(d)') - this.getValue(tr, '1b(e)')) + this.getValue(tr, '1b(g)');
37 }, 'Gain of short-term basis reported'),
38
39 '2(d)': new ScheduleDTotal('Proceeds of short-term basis NOT reported', '2(d)', Form8949Box.B),
40 '2(e)': new ScheduleDTotal('Cost basis of short-term NOT basis-reported', '2(e)', Form8949Box.B),
41 '2(g)': new ScheduleDTotal('Adjustments to short-term NOT basis-reported', '2(g)', Form8949Box.B),
42 '2(h)': new ComputedLine((tr: TaxReturn): number => {
43 return (this.getValue(tr, '2(d)') - this.getValue(tr, '2(e)')) + this.getValue(tr, '2(g)');
44 }, 'Gain of short-term basis NOT reported'),
45
46 '3(d)': new ScheduleDTotal('Proceeds of short-term basis unreported', '2(d)', Form8949Box.C),
47 '3(e)': new ScheduleDTotal('Cost basis of short-term unreported', '2(e)', Form8949Box.C),
48 '3(g)': new ScheduleDTotal('Adjustments to short-term unreported', '2(g)', Form8949Box.C),
49 '3(h)': new ComputedLine((tr: TaxReturn): number => {
50 return (this.getValue(tr, '3(d)') - this.getValue(tr, '3(e)')) + this.getValue(tr, '3(g)');
51 }, 'Gain of short-term unreported'),
52
53 // 4 is not supported (Short-term gain from Form 6252 and short-term gain or (loss) from Forms 4684, 6781, and 8824)
54 // 5 is not supported (Net short-term gain or (loss) from partnerships, S corporations, estates, and trusts from Schedule(s) K-1)
55 // 6 is not supported (Short-term capital loss carryover. Enter the amount, if any, from line 8 of your Capital Loss Carryover Worksheet in the instructions)
56
57 '7': new ComputedLine((tr: TaxReturn): number => {
58 // 4-6 should be included.
59 return this.getValue(tr, '1b(h)') + this.getValue(tr, '2(h)'), this.getValue(tr, '3(h)');
60 }, 'Net short-term capital gain or (loss)'),
61
62 // 8a is not supported.
63
64 '8b(d)': new ScheduleDTotal('Proceeds of long-term basis reported', '2(d)', Form8949Box.D),
65 '8b(e)': new ScheduleDTotal('Cost basis of long-term basis-reported', '2(e)', Form8949Box.D),
66 '8b(g)': new ScheduleDTotal('Adjustments to long-term basis-reported', '2(g)', Form8949Box.D),
67 '8b(h)': new ComputedLine((tr: TaxReturn): number => {
68 return (this.getValue(tr, '8b(d)') - this.getValue(tr, '8b(e)')) + this.getValue(tr, '8b(g)');
69 }, 'Gain of long-term basis reported'),
70
71 '9(d)': new ScheduleDTotal('Proceeds of long-term basis NOT reported', '2(d)', Form8949Box.E),
72 '9(e)': new ScheduleDTotal('Cost basis of long-term NOT basis-reported', '2(e)', Form8949Box.E),
73 '9(g)': new ScheduleDTotal('Adjustments to long-term NOT basis-reported', '2(g)', Form8949Box.E),
74 '9(h)': new ComputedLine((tr: TaxReturn): number => {
75 return (this.getValue(tr, '9(d)') - this.getValue(tr, '9(e)')) + this.getValue(tr, '9(g)');
76 }, 'Gain of long-term basis NOT reported'),
77
78 '10(d)': new ScheduleDTotal('Proceeds of long-term basis unreported', '2(d)', Form8949Box.F),
79 '10(e)': new ScheduleDTotal('Cost basis of long-term unreported', '2(e)', Form8949Box.F),
80 '10(g)': new ScheduleDTotal('Adjustments to long-term unreported', '2(g)', Form8949Box.F),
81 '10(h)': new ComputedLine((tr: TaxReturn): number => {
82 return (this.getValue(tr, '10(d)') - this.getValue(tr, '10(e)')) + this.getValue(tr, '10(g)');
83 }, 'Gain of long-term unreported'),
84
85 // 11 is not supported (Gain from Form 4797, Part I; long-term gain from Forms 2439 and 6252; and long-term gain or (loss) from Forms 4684, 6781, and 8824)
86 // 12 is not supported (Net long-term gain or (loss) from partnerships, S corporations, estates, and trusts from Schedule(s) K-1)
87
88 '13': new AccumulatorLine(Form1099DIV, '2a', 'Capital gain distributions'),
89
90 // 14 is not supported (Long-term capital loss carryover. Enter the amount, if any, from line 13 of your Capital Loss Carryover Worksheet in the instructions)
91
92 '15': new ComputedLine((tr: TaxReturn): number => {
93 // 11-14 should be included.
94 return this.getValue(tr, '8b(h)') + this.getValue(tr, '9(h)') + this.getValue(tr, '10(h)') +
95 this.getValue(tr, '13');
96 }, 'Net long-term capital gain or (loss)'),
97
98 '16': new ComputedLine((tr: TaxReturn): number => {
99 return this.getValue(tr, '7') + this.getValue(tr, '15');
100 }),
101
102 '17': new ComputedLine((tr: TaxReturn): boolean => {
103 return this.getValue(tr, '15') > 0 && this.getValue(tr, '16') > 0;
104 }, 'Both ST and LT are gains'),
105
106 '18': new ComputedLine((tr: TaxReturn): number | undefined => {
107 if (!this.getValue(tr, '17'))
108 return undefined;
109 // TODO
110 return 0;
111 }, '28% Rate Gain Worksheet Value'),
112
113 // 19 is not supported (Unrecaptured Section 1250 Gain Worksheet)
114
115 '20': new ComputedLine((tr: TaxReturn): boolean | undefined => {
116 if (!this.getValue(tr, '17'))
117 return undefined;
118 const l18 = this.getValue(tr, '18');
119 const l19 = undefined; //this.getValue(tr, '19');
120 return (l18 === 0 || l18 === undefined) || (l19 === 0 || l19 === undefined);
121 }, 'Line 18 and 19 both 0 or blank?'),
122
123 '21': new ComputedLine((tr: TaxReturn): number | undefined => {
124 if (!this.getValue(tr, '17'))
125 return undefined;
126 const filingStatus = tr.getForm(Form1040).getInput('filingStatus');
127 const limit = filingStatus == FilingStatus.MarriedFilingSeparate ? -1500 : -3000;
128 return Math.min(this.getValue(tr, '16'), limit);
129 }, 'Net capital loss'),
130 };
131 };