-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathprint.tsx
More file actions
298 lines (260 loc) · 8.25 KB
/
print.tsx
File metadata and controls
298 lines (260 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import React from "react";
import { format } from 'd3-format';
import {
PrintButton,
Message,
H3,
H2
} from "../components";
import {useUserState, UserState, EarningsRecord} from '../library/user-state-context'
import styled from "@emotion/styled";
import { colors, fontSizes, radii, spacing } from "../constants";
export const BoxDisplay = styled('div')`
background-color: ${colors.whiteSmoke};
color: ${colors.black};
font-size: ${fontSizes[1]};
line-height: 50px;
text-align: center;
width: 150px;
height: 50px;
grid-column-start: 2;
grid-column-end: 3;
justify-self: center;
align-self: end;
margin: 5px;
`;
export const ResultsCard = styled('div')`
border: 1px solid ${colors.darkGreen};
border-radius: ${radii[0]};
padding: ${spacing[1]};
margin: ${spacing[1]} 0;
display: block;
flex-direction: row;
padding: 10px 25px;
@media (max-width: 768px) {
padding: 10px 15px;
margin: 5px;
}
overflow: scroll;
`;
const Row = styled.div`
display: flex;
justify-content: space-between;
`;
const Title = styled.div`
display: flex;
justify-content: center;
`;
export const DisplayTable = styled("table")`
table-layout: fixed;
border-radius: ${radii[0]};
margin: ${spacing[0]};
padding: 8px;
margin: auto;
`;
export const TableHeader = styled("th")`
background-color: #dddddd;
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
`;
export const TableRow= styled("tr")`
border: 1px solid #dddddd;
text-align: center;
padding: 8px;
`;
const PageContainer = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
width: 60vw;
@media (max-width: 768px) {
width: 70vw;
}
`;
const PrintArea = styled.div`
display: block;
`;
var blankLines = {
gridColumnStart: 2,
gridColumnEnd: 3,
alignSelf: 'end',
justifySelf: 'center',
marginBottom: '20px'
};
interface PrintEarningsProps {
earnings: EarningsRecord
}
class PrintEarnings extends React.Component<PrintEarningsProps> {
constructor(props, context) {
super(props, context)
this.state = {
tableRows: undefined
}
}
componentDidMount() {
if (this.state.tableRows === undefined) {
this.makeRows()
}
}
makeRows() {
const {earnings} = this.props
var testEarnings = earnings;
var earningsDict = {};
var tablesize = Math.ceil(Object.keys(earnings).length / 10);
var columnLength = 10;
var newRows = Object.keys(earnings).map((year, i) => {
return(
<React.Fragment key={"earning" + i}>
<td key={"earningYear" + i}><label>{year}</label></td>
<td key={"earningAmount" + i}><label id={year} >{format(",.2r")(earnings[year])}</label></td>
</React.Fragment>
)
})
if (tablesize >= 5) {
tablesize = Math.ceil(Object.keys(earnings).length / 15)
columnLength = 15;
}
this.headers = Array(tablesize).fill(null).map((header, index) => {
return(
<React.Fragment key={"header" + index}>
<TableHeader>Year</TableHeader ><TableHeader>Amount</TableHeader>
</React.Fragment>
)
})
var sizedRows = []
while (newRows.length > 0) {
if (newRows.length > columnLength) {
sizedRows.push(newRows.splice(0, columnLength))
} else {
var remLength = columnLength - newRows.length
var smallArr = newRows.splice(0, newRows.length)
for (var i=0; i < remLength; i++) {
smallArr.push(<React.Fragment key={"Filler" + i}></React.Fragment>)
}
sizedRows.push(smallArr)
}
}
var finalRows = sizedRows[0].map(function(record, index) {
var restofArray = sizedRows.slice(1, sizedRows.length)
var len = restofArray.length
var finalRecord = []
finalRecord.push(record)
for (var i=0; i < len; i++) {
finalRecord.push(restofArray[i][index])
};
var completeRow = <TableRow key={"row" + index}>{finalRecord}</TableRow>
return completeRow
});
this.setState({
tableRows: finalRows
})
}
render() {
return(
<DisplayTable>
<tbody>
<tr>{this.headers}</tr>
{this.state.tableRows}
</tbody>
</DisplayTable>
)
}
}
interface PrintProps {
userState: UserState
}
class Print extends React.Component<PrintProps> {
printPage = () => {
var printContents = document.getElementById("printArea").innerHTML;
var originalContents = document.body.innerHTML;
// TODO Dangerous with React
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
render() {
const {userState: {earnings, userProfile, birthDate, retireDate}} = this.props
if (!userProfile) return null
/* AIME does not have $format, has a comma */
const userAIME = format(",.4r")(userProfile.aime)
const userFRD = userProfile.fullRetireDate
const userYSE = userProfile.yearsSubstantialEarnings
/* Pension has $format, no cents */
const userPension = userProfile.pensionNonCoveredMonthly && format('$,.2r')(userProfile.pensionNonCoveredMonthly)
/* SPIA has $format, has cents */
const userStandardPIA = format('$,.2f')(userProfile["Standard PIA"])
/* MPB has $format, has cents */
const userMPB = format('$,.2f')(userProfile["MPB"])
return(
<PageContainer>
<PrintArea id="printArea">
<H2>Retirement benefit factors</H2>
<Message>
Please review the information below for accuracy. If the information you provided does not match
your letters from the Social Security Administration, you may want to consider contacting your local
Social Security office. Bring this sheet and any supporting evidence (for example, W-2's, pension
fund statements) with you.
<br/>
<br/>
To find your local Social Security Office, please call the Social Security Administration at
<a href="tel:1-800-772-1213">1-800-772-1213</a> or <a href="https://secure.ssa.gov/ICON/main.jsp" target="_new">use this tool to locate your office</a>.
</Message>
<ResultsCard >
<Title><H3>Beneficiary Information</H3></Title>
<Row>Name: <div style={blankLines}>____________________________</div></Row>
<Row>Social Security Number: <div style={blankLines}>______-______-_________</div></Row>
{birthDate && (
<Row>Date of Birth: <BoxDisplay><strong>{birthDate.toLocaleDateString('en-US')}</strong></BoxDisplay></Row>
)}
</ResultsCard>
<ResultsCard>
<Title><H3>Retirement information</H3></Title>
<Row>Monthly non-covered pension amount:<BoxDisplay><strong>{userPension}</strong></BoxDisplay></Row>
{retireDate && (
<Row>Date of Full Retirement Age:<BoxDisplay><strong>{userFRD}</strong></BoxDisplay></Row>
)}
</ResultsCard>
{earnings && (
<ResultsCard>
<Title><H3 >Earnings Record</H3></Title>
<div><PrintEarnings earnings={earnings}/></div>
</ResultsCard>
)}
<ResultsCard>
<Title><H3>Calculation results</H3></Title>
<Row>
Average Indexed Monthly Earnings:
<BoxDisplay>
<strong>{userAIME}</strong>
</BoxDisplay>
</Row>
<Row>
Years of Substantial Earnings:
<BoxDisplay>
<strong>{userYSE}</strong>
</BoxDisplay>
</Row>
<Row>
Primary Insurance Amount:
<BoxDisplay>
<strong>{userStandardPIA}</strong>
</BoxDisplay>
</Row>
<Row>
Maximum Payable Benefit at Full Retirement Age:
<BoxDisplay>
<strong>{userMPB}</strong>
</BoxDisplay>
</Row>
</ResultsCard>
</PrintArea>
<PrintButton onClick={this.printPage}>PRINT RESULTS</PrintButton>
</PageContainer>
)
}
}
export default function PrintWrapper(): JSX.Element {
const userState = useUserState()
return <Print userState={userState} />
}