-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
568 lines (512 loc) · 35.3 KB
/
index.html
File metadata and controls
568 lines (512 loc) · 35.3 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PSH Rent Calculator</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.9/babel.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f5f5f5; }
input, select, button { font-family: inherit; }
input:focus, select:focus { outline: 2px solid #1a73e8; border-color: #1a73e8; }
button:hover { opacity: 0.92; }
@media print {
* { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
.no-print { display: none !important; }
body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
body * { visibility: hidden; }
#print-sheet, #print-sheet * { visibility: visible; }
#print-sheet { display: block !important; position: absolute !important; top: 0 !important; left: 0 !important; width: 100% !important; }
@page { size: letter portrait; margin: 0.65in 0.75in; }
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useCallback } = React;
/* ── Default FMR Data (2025 HUD Rates) ── */
const DEFAULT_FMR = [
{ bedrooms: 0, paymentStandard: 2734, fmr: 2485 },
{ bedrooms: 1, paymentStandard: 3275, fmr: 2977 },
{ bedrooms: 2, paymentStandard: 3964, fmr: 3604 },
{ bedrooms: 3, paymentStandard: 5064, fmr: 4604 },
{ bedrooms: 4, paymentStandard: 5249, fmr: 4772 },
{ bedrooms: 5, paymentStandard: 0, fmr: 0 },
];
/* ── Calculation Engine ── */
function calculate(inputs, fmrTable) {
const rent = Number(inputs.rentToOwner) || 0;
const ua = Number(inputs.utilityAllowance) || 0;
const ttp = Math.max(Number(inputs.ttp) || 0, 50);
const voucherSize = Number(inputs.voucherSize) || 0;
const brLeased = Number(inputs.brLeased) || 0;
const eligible = Number(inputs.numEligible) || 1;
const ineligible = Number(inputs.numIneligible) || 0;
const grossRent = rent + ua;
const fmrBedroom = Math.min(voucherSize, brLeased);
const fmrRow = fmrTable.find(r => r.bedrooms === fmrBedroom);
const fmr = fmrRow ? fmrRow.fmr : 0;
const lowerFmrOrGr = Math.min(fmr, grossRent);
const amountAboveFmr = Math.max(0, grossRent - fmr);
const totalHap = grossRent - ttp;
const totalFamilyShare = ttp;
const hapToOwner = Math.min(rent, totalHap);
const tenantRent = Math.max(0, rent - totalHap);
const utilityReimbursement = Math.max(0, ua - ttp);
const totalMembers = eligible + ineligible;
const isMixedFamily = ineligible > 0;
const proratePct = totalMembers > 0 ? eligible / totalMembers : 1;
const normalHap = hapToOwner;
const proratedHap = isMixedFamily ? Math.floor(proratePct * normalHap) : normalHap;
const mixedFamilyRent = isMixedFamily ? Math.floor(rent - proratedHap) : tenantRent;
return { grossRent, fmr, fmrBedroom, lowerFmrOrGr, amountAboveFmr, ttp, totalHap, totalFamilyShare, hapToOwner, tenantRent, utilityReimbursement, normalHap, totalMembers, isMixedFamily, proratePct, proratedHap, mixedFamilyRent };
}
const fmt = n => "$" + Math.round(Number(n) || 0).toLocaleString();
/* ── Progress Bar ── */
function ProgressBar({ currentStep, steps }) {
return (
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 32px", background: "#fff", borderBottom: "1px solid #e5e7eb" }}>
{steps.map((s, i) => {
const done = i < currentStep, cur = i === currentStep, fut = i > currentStep;
return (
<div key={i} style={{ display: "flex", alignItems: "center", gap: 8, flex: 1 }}>
<div style={{ width: 32, height: 32, borderRadius: "50%", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 14, fontWeight: 700, flexShrink: 0, background: done ? "#0d7a3f" : cur ? "#1a73e8" : "#e5e7eb", color: fut ? "#9ca3af" : "#fff" }}>
{done ? "✓" : i + 1}
</div>
<span style={{ fontSize: 13, fontWeight: cur ? 700 : 400, color: done ? "#0d7a3f" : cur ? "#1a73e8" : "#9ca3af", whiteSpace: "nowrap" }}>{s}</span>
{i < steps.length - 1 && <div style={{ flex: 1, height: 2, background: done ? "#0d7a3f" : "#e5e7eb", marginLeft: 8 }} />}
</div>
);
})}
</div>
);
}
/* ── Field ── */
function Field({ label, hint, children }) {
return (
<div style={{ marginBottom: 20 }}>
<label style={{ display: "block", fontSize: 14, fontWeight: 600, color: "#1f2937", marginBottom: 4 }}>{label}</label>
{hint && <p style={{ fontSize: 12, color: "#6b7280", fontStyle: "italic", margin: "0 0 6px 0" }}>{hint}</p>}
{children}
</div>
);
}
const inputStyle = { width: "100%", maxWidth: 320, padding: "10px 12px", fontSize: 15, border: "1px solid #d1d5db", borderRadius: 6, outline: "none", boxSizing: "border-box" };
/* ── Alert Box ── */
function AlertBox({ type, children }) {
const m = { error: { bg: "#fef2f2", bd: "#fca5a5", c: "#991b1b", i: "⚠" }, warning: { bg: "#fffbeb", bd: "#fcd34d", c: "#92400e", i: "⚠" }, success: { bg: "#f0fdf4", bd: "#86efac", c: "#166534", i: "✓" }, info: { bg: "#eff6ff", bd: "#93c5fd", c: "#1e40af", i: "ℹ" } };
const s = m[type] || m.info;
return <div style={{ padding: "12px 16px", background: s.bg, border: "1px solid " + s.bd, borderRadius: 8, color: s.c, fontSize: 14, lineHeight: 1.5, marginTop: 12 }}><span style={{ marginRight: 8 }}>{s.i}</span>{children}</div>;
}
/* ── Nav Buttons ── */
function NavButtons({ onBack, onNext, nextLabel, nextColor }) {
return (
<div style={{ display: "flex", justifyContent: "space-between", paddingTop: 24, borderTop: "1px solid #e5e7eb", marginTop: 24 }}>
{onBack ? <button onClick={onBack} style={{ padding: "10px 20px", fontSize: 14, background: "#6b7280", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>← Back</button> : <div />}
<button onClick={onNext} style={{ padding: "12px 28px", fontSize: 15, fontWeight: 700, background: nextColor || "#1a73e8", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>{nextLabel || "Next →"}</button>
</div>
);
}
/* ── Step 1: Household ── */
function Step1({ data, onChange, onNext, fmrTable }) {
const [error, setError] = useState("");
const fmrBr = Math.min(Number(data.voucherSize) || 0, Number(data.brLeased) || 0);
const fmrRow = fmrTable.find(r => r.bedrooms === fmrBr);
const fmrAmt = fmrRow ? fmrRow.fmr : 0;
const go = () => {
if (!data.headOfHousehold.trim()) { setError("Please enter the Head of Household name."); return; }
setError(""); onNext();
};
return (
<div>
<h2 style={{ fontSize: 20, fontWeight: 700, color: "#1a73e8", margin: "0 0 20px 0" }}>Household Information</h2>
<Field label="Head of Household Name" hint="Full legal name (required)">
<input style={{ ...inputStyle, borderColor: error ? "#ef4444" : "#d1d5db" }} value={data.headOfHousehold} onChange={e => onChange("headOfHousehold", e.target.value)} placeholder="Enter name..." autoFocus />
</Field>
<div style={{ display: "flex", gap: 24, flexWrap: "wrap" }}>
<Field label="Voucher Bedroom Size" hint="Bedroom size authorized on the housing voucher">
<select style={{ ...inputStyle, maxWidth: 140 }} value={data.voucherSize} onChange={e => onChange("voucherSize", e.target.value)}>
{[0,1,2,3,4,5].map(n => <option key={n} value={n}>{n}</option>)}
</select>
</Field>
<Field label="Actual Bedrooms in Unit" hint="Number of bedrooms in the leased unit">
<select style={{ ...inputStyle, maxWidth: 140 }} value={data.brLeased} onChange={e => onChange("brLeased", e.target.value)}>
{[0,1,2,3,4,5].map(n => <option key={n} value={n}>{n}</option>)}
</select>
</Field>
</div>
{fmrAmt > 0 && <AlertBox type="info">FMR will be based on <strong>{fmrBr}-bedroom</strong> rate: <strong>{fmt(fmrAmt)}</strong></AlertBox>}
{error && <AlertBox type="error">{error}</AlertBox>}
<NavButtons onNext={go} />
</div>
);
}
/* ── Step 2: Finances ── */
function Step2({ data, onChange, onBack, onNext, fmrTable }) {
const [error, setError] = useState("");
const rent = Number(data.rentToOwner) || 0, ua = Number(data.utilityAllowance) || 0, ttp = Number(data.ttp) || 0;
const grossRent = rent + ua;
const fmrBr = Math.min(Number(data.voucherSize) || 0, Number(data.brLeased) || 0);
const fmrRow = fmrTable.find(r => r.bedrooms === fmrBr);
const fmr = fmrRow ? fmrRow.fmr : 0;
const aboveFmr = grossRent > fmr && fmr > 0;
const go = () => {
if (rent <= 0) { setError("Rent to Owner must be greater than $0."); return; }
if (ua < 0) { setError("Utility Allowance cannot be negative."); return; }
if (isNaN(rent) || isNaN(ua) || isNaN(ttp)) { setError("Please enter valid numbers."); return; }
setError(""); if (ttp < 50) onChange("ttp", "50"); onNext();
};
return (
<div>
<h2 style={{ fontSize: 20, fontWeight: 700, color: "#1a73e8", margin: "0 0 20px 0" }}>Financial Information</h2>
<Field label="Rent to Owner ($)" hint="Monthly contract rent paid to the property owner">
<input style={inputStyle} type="number" min="0" value={data.rentToOwner} onChange={e => onChange("rentToOwner", e.target.value)} autoFocus />
</Field>
<Field label="Utility Allowance ($)" hint="Monthly allowance for tenant-paid utilities per PHA schedule">
<input style={inputStyle} type="number" min="0" value={data.utilityAllowance} onChange={e => onChange("utilityAllowance", e.target.value)} />
</Field>
<Field label="Total Tenant Payment / TTP ($)" hint="Household's share of rent based on income — minimum $50 for PSH">
<input style={inputStyle} type="number" min="0" value={data.ttp} onChange={e => onChange("ttp", e.target.value)} />
</Field>
{ttp < 50 && ttp >= 0 && <AlertBox type="warning">TTP minimum is $50 per HUD rules. Value will be set to $50 when you proceed.</AlertBox>}
<div style={{ background: "#f8fafc", borderRadius: 8, padding: 16, marginTop: 16, border: "1px solid #e2e8f0" }}>
<div style={{ fontSize: 13, color: "#64748b" }}>Gross Rent (Rent + UA)</div>
<div style={{ fontSize: 28, fontWeight: 700, color: "#1a73e8" }}>{fmt(grossRent)}</div>
{fmr > 0 && <div style={{ fontSize: 13, color: "#64748b", marginTop: 4 }}>FMR for {fmrBr}-BR: {fmt(fmr)}</div>}
</div>
{aboveFmr && <AlertBox type="error"><strong>Gross Rent exceeds FMR by {fmt(grossRent - fmr)}</strong> — Supervisor approval will be required.</AlertBox>}
{error && <AlertBox type="error">{error}</AlertBox>}
<NavButtons onBack={onBack} onNext={go} />
</div>
);
}
/* ── Step 3: Family ── */
function Step3({ data, onChange, onBack, onNext }) {
const [error, setError] = useState("");
const eligible = Number(data.numEligible) || 0, ineligible = Number(data.numIneligible) || 0, total = eligible + ineligible;
const go = () => { if (eligible < 1) { setError("Number Eligible must be at least 1."); return; } setError(""); onNext(); };
return (
<div>
<h2 style={{ fontSize: 20, fontWeight: 700, color: "#1a73e8", margin: "0 0 20px 0" }}>Family Composition</h2>
<div style={{ display: "flex", gap: 24, flexWrap: "wrap" }}>
<Field label="Number Eligible" hint="Family members with eligible immigration status">
<input style={{ ...inputStyle, maxWidth: 120 }} type="number" min="1" max="20" value={data.numEligible} onChange={e => onChange("numEligible", e.target.value)} autoFocus />
</Field>
<Field label="Number Ineligible" hint="Members without eligible immigration status">
<input style={{ ...inputStyle, maxWidth: 120 }} type="number" min="0" max="20" value={data.numIneligible} onChange={e => onChange("numIneligible", e.target.value)} />
</Field>
</div>
<div style={{ background: "#f8fafc", borderRadius: 8, padding: 16, border: "1px solid #e2e8f0", marginBottom: 12 }}>
<div style={{ fontSize: 13, color: "#64748b" }}>Total Family Members</div>
<div style={{ fontSize: 28, fontWeight: 700, color: "#1a73e8" }}>{total}</div>
</div>
{ineligible > 0 ? <AlertBox type="warning"><strong>MIXED FAMILY DETECTED</strong><br/>Proration: {eligible}/{total} = {total > 0 ? ((eligible/total)*100).toFixed(1) : 0}% of HAP. Assistance will be reduced proportionally.</AlertBox> : total > 0 && <AlertBox type="success">All family members are eligible. No proration needed.</AlertBox>}
{error && <AlertBox type="error">{error}</AlertBox>}
<NavButtons onBack={onBack} onNext={go} />
</div>
);
}
/* ── Step 4: Staff ── */
function Step4({ data, onChange, onBack, onCalculate, fmrTable }) {
const [error, setError] = useState("");
const grossRent = (Number(data.rentToOwner) || 0) + (Number(data.utilityAllowance) || 0);
const fmrBr = Math.min(Number(data.voucherSize) || 0, Number(data.brLeased) || 0);
const fmrRow = fmrTable.find(r => r.bedrooms === fmrBr);
const fmr = fmrRow ? fmrRow.fmr : 0;
const needsSup = grossRent > fmr && fmr > 0;
const go = () => {
if (!data.haStaff.trim()) { setError("Please enter HA Staff Name."); return; }
if (needsSup && !data.supervisorName.trim()) { setError("Supervisor Name is required (Gross Rent exceeds FMR)."); return; }
setError(""); onCalculate();
};
return (
<div>
<h2 style={{ fontSize: 20, fontWeight: 700, color: "#1a73e8", margin: "0 0 20px 0" }}>Staff & Sign-off</h2>
<Field label="HA Staff Name" hint="Required"><input style={inputStyle} value={data.haStaff} onChange={e => onChange("haStaff", e.target.value)} placeholder="Staff name..." autoFocus /></Field>
<Field label="Calculation Date"><input style={{ ...inputStyle, maxWidth: 180 }} type="date" value={data.calcDate} onChange={e => onChange("calcDate", e.target.value)} /></Field>
{needsSup ? (<>
<AlertBox type="error"><strong>SUPERVISOR APPROVAL REQUIRED</strong> — Gross rent exceeds Fair Market Rent.</AlertBox>
<div style={{ marginTop: 16 }}>
<Field label="Supervisor Name" hint="Required for FMR override"><input style={inputStyle} value={data.supervisorName} onChange={e => onChange("supervisorName", e.target.value)} placeholder="Supervisor name..." /></Field>
<Field label="Supervisor Date"><input style={{ ...inputStyle, maxWidth: 180 }} type="date" value={data.supervisorDate} onChange={e => onChange("supervisorDate", e.target.value)} /></Field>
</div>
</>) : <AlertBox type="success">Rent is within FMR limits. No supervisor approval needed.</AlertBox>}
{error && <AlertBox type="error">{error}</AlertBox>}
<NavButtons onBack={onBack} onNext={go} nextLabel="Calculate" nextColor="#0d7a3f" />
</div>
);
}
/* ── Step 5: Dashboard Results ── */
function Step5({ data, results, onNewCalc }) {
const r = results;
const copyText = () => {
const lines = [
"=".repeat(60), "PSH RENT CALCULATION SUMMARY", "=".repeat(60), "",
"Head of Household: " + data.headOfHousehold,
"Date: " + data.calcDate + " Staff: " + data.haStaff,
data.supervisorName ? "Supervisor: " + data.supervisorName : "",
"", "-".repeat(60),
"1. Rent to Owner: " + fmt(data.rentToOwner),
"2. Utility Allowance: " + fmt(data.utilityAllowance),
"3. Gross Rent: " + fmt(r.grossRent),
"4. 2025 Payment Standard: " + fmt(r.fmr),
"5. Lower of FMR or GR: " + fmt(r.lowerFmrOrGr),
"6. Amount Above FMR: " + fmt(r.amountAboveFmr) + (r.amountAboveFmr > 0 ? " [SUPERVISOR REQUIRED]" : ""),
"7. TTP ($50 Minimum): " + fmt(r.ttp),
"8. Total HAP: " + fmt(r.totalHap),
"9. Total Family Share: " + fmt(r.totalFamilyShare),
"10. HAP to Owner: " + fmt(r.hapToOwner),
"11. Tenant Rent: " + fmt(r.tenantRent),
"12. Utility Reimbursement: " + fmt(r.utilityReimbursement),
"", "--- PRORATED ASSISTANCE ---",
"13. Normal HAP: " + fmt(r.normalHap),
"14. Number Eligible: " + data.numEligible,
"15. Number Ineligible: " + data.numIneligible,
"16. Total Family Members: " + r.totalMembers,
"17. Prorate %: " + (r.proratePct * 100).toFixed(2) + "%",
"18. Prorated HAP: " + fmt(r.proratedHap),
"19. Mixed Family Rent: " + fmt(r.mixedFamilyRent),
"=".repeat(60),
].filter(Boolean).join("\n");
navigator.clipboard.writeText(lines).then(() => alert("Copied to clipboard!"));
};
const printPage = () => {
const existing = document.getElementById("print-sheet");
if (existing) existing.remove();
const dateStr = data.calcDate ? new Date(data.calcDate + "T12:00:00").toLocaleDateString("en-US") : "";
const supDateStr = data.supervisorDate ? new Date(data.supervisorDate + "T12:00:00").toLocaleDateString("en-US") : "";
const rawFmt = v => { const n = Math.round(Number(v) || 0); return n.toLocaleString(); };
const GRAY = "background:linear-gradient(to bottom,#b8b8b8,#d8d8d8,#c8c8c8);border:1px solid #888;";
// Value cell renderers
const grayBox = val => `<div style="${GRAY}padding:2px 6px;text-align:right;width:100%;box-sizing:border-box;">${val}</div>`;
const greenBox = val => `<div style="background:#c6efce;border:1px solid #888;padding:2px 6px;text-align:right;width:100%;box-sizing:border-box;font-weight:bold;">${val}</div>`;
const redBox = val => `<div style="background:#ff0000;border:1px solid #cc0000;padding:2px 6px;text-align:right;width:100%;box-sizing:border-box;color:#fff;font-weight:bold;">${val}</div>`;
const redText = val => `<div style="text-align:right;padding:2px 6px;color:#cc0000;font-weight:bold;">${val}</div>`;
const plain = val => `<div style="text-align:right;padding:2px 6px;">${val}</div>`;
// Row: number embedded in label, two columns only (label | value)
const row = (label, valueHtml, labelBold, extraCell) => `
<tr>
<td style="border:1px solid #333;padding:2px 8px;font-size:8.5pt;${labelBold ? "font-weight:bold;" : ""}">${label}</td>
<td style="border:1px solid #333;padding:0;font-size:8.5pt;width:90px;">${valueHtml}</td>
${extraCell ? `<td style="border:none;padding:2px 6px;font-size:8pt;color:#333;white-space:nowrap;">${extraCell}</td>` : `<td style="border:none;"></td>`}
</tr>`;
const sectionRow = () => `
<tr>
<td colspan="3" style="border:1px solid #333;padding:3px 8px;font-size:8.5pt;font-weight:bold;background:#ffeb9c;">PRORATED ASSISTANCE</td>
</tr>`;
const sheet = document.createElement("div");
sheet.id = "print-sheet";
sheet.style.cssText = "display:none;position:fixed;top:0;left:0;width:100%;background:#fff;z-index:9999;padding:0;";
sheet.innerHTML = `
<style>
#print-sheet { font-family: Arial, sans-serif; font-size: 8.5pt; background: #fff; padding: 0; }
#print-sheet table { border-collapse: collapse; width: 100%; }
</style>
<!-- Title -->
<div style="font-size:13pt;font-weight:bold;margin-bottom:10px;">PSH RENT CALCULATION</div>
<!-- Header: HOH left, Voucher BR Size + # BR Leased stacked on right -->
<table style="margin-bottom:4px;">
<tr>
<td style="border:1px solid #333;padding:3px 8px;font-size:8.5pt;width:120px;">Head of Household:</td>
<td style="border:1px solid #333;padding:3px 8px;font-size:8.5pt;${GRAY}min-width:160px;">${data.headOfHousehold}</td>
<td style="border:none;width:16px;"></td>
<td style="border:1px solid #333;padding:0;font-size:8.5pt;">
<table style="width:100%;border-collapse:collapse;">
<tr>
<td style="padding:2px 6px;font-size:8.5pt;white-space:nowrap;">Voucher BR Size</td>
<td style="border-left:1px solid #333;${GRAY}padding:2px 6px;width:30px;text-align:center;font-size:8.5pt;">${data.voucherSize}</td>
</tr>
<tr>
<td style="border-top:1px solid #333;padding:2px 6px;font-size:8.5pt;white-space:nowrap;"># BR Leased</td>
<td style="border-top:1px solid #333;border-left:1px solid #333;${GRAY}padding:2px 6px;text-align:center;font-size:8.5pt;">${data.brLeased}</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- Main table - NO number column, number is part of label -->
<table>
${row("1 RENT TO OWNER", grayBox(rawFmt(data.rentToOwner)))}
${row("2 UTILITY ALLOWANCE", grayBox(rawFmt(data.utilityAllowance)))}
${row("3 GROSS RENT", plain(rawFmt(r.grossRent)))}
${row("4 2025 FMR", plain(rawFmt(r.fmr)))}
${row("5 LOWER OF FMR OR GR", plain(rawFmt(r.lowerFmrOrGr)))}
${row("6 AMOUNT ABOVE FMR", r.amountAboveFmr > 0 ? redBox(rawFmt(r.amountAboveFmr)) : plain("0"), false, r.amountAboveFmr > 0 ? "Red - See Supervisor" : "")}
${row("7 TTP ($50 MINIMUM)", grayBox(rawFmt(r.ttp)))}
${row("8 TOTAL HAP", plain(rawFmt(r.totalHap)))}
${row("9 TOTAL FAMILY SHARE", plain(rawFmt(r.totalFamilyShare)))}
${row("10 HAP TO OWNER", greenBox(rawFmt(r.hapToOwner)), true)}
${row("11 TENANT RENT", plain(rawFmt(r.tenantRent)))}
${row("12 UTILITY REIMBURSEMENT", plain(rawFmt(r.utilityReimbursement)))}
${sectionRow()}
${row("13 NORMAL HAP", plain(rawFmt(r.normalHap)), true)}
${row("14 NUMBER ELIGIBLE", grayBox(data.numEligible))}
${row("15 NUMBER INELIGIBLE", grayBox(data.numIneligible))}
${row("16 TOTAL FAMILY MEMBERS",grayBox(r.totalMembers))}
${row("17 PRORATE %", plain((r.proratePct).toFixed(2)))}
${row("18 PRORATED HAP", plain(rawFmt(r.proratedHap)))}
${row("19 MIXED FAMILY RENT", r.isMixedFamily ? redText(rawFmt(r.mixedFamilyRent)) : plain(rawFmt(r.mixedFamilyRent)), true)}
</table>
<!-- Footer: HA STAFF row + SUPERVISOR row always shown -->
<table style="margin-top:14px;width:100%;">
<tr>
<td style="font-size:8.5pt;padding:2px 6px;width:75px;white-space:nowrap;">HA STAFF:</td>
<td style="${GRAY}border:1px solid #333;font-size:8.5pt;padding:3px 10px;min-width:150px;">${data.haStaff}</td>
<td style="width:24px;"></td>
<td style="font-size:8.5pt;padding:2px 6px;width:38px;">DATE:</td>
<td style="${GRAY}border:1px solid #333;font-size:8.5pt;padding:3px 10px;width:85px;text-align:center;">${dateStr}</td>
</tr>
<tr style="height:8px;"><td colspan="5"></td></tr>
<tr>
<td style="font-size:8.5pt;padding:2px 6px;white-space:nowrap;">SUPERVISOR:</td>
<td style="border-bottom:1px solid #333;font-size:8.5pt;padding:3px 10px;">${data.supervisorName || ""}</td>
<td></td>
<td style="font-size:8.5pt;padding:2px 6px;">DATE:</td>
<td style="border-bottom:1px solid #333;font-size:8.5pt;padding:3px 10px;text-align:center;">${data.supervisorDate ? supDateStr : ""}</td>
</tr>
</table>
`;
document.body.appendChild(sheet);
window.print();
setTimeout(() => { const s = document.getElementById("print-sheet"); if(s) s.remove(); }, 2000);
};
const rows = [
{ n: "1", label: "Rent to Owner", val: fmt(data.rentToOwner) },
{ n: "2", label: "Utility Allowance", val: fmt(data.utilityAllowance) },
{ n: "3", label: "Gross Rent", val: fmt(r.grossRent) },
{ n: "4", label: "2025 FMR", val: fmt(r.fmr) },
{ n: "5", label: "Lower of FMR or GR", val: fmt(r.lowerFmrOrGr) },
{ n: "6", label: "Amount Above FMR", val: fmt(r.amountAboveFmr), hl: r.amountAboveFmr > 0 ? "red" : null },
{ n: "7", label: "TTP ($50 Minimum)", val: fmt(r.ttp) },
{ n: "8", label: "Total HAP", val: fmt(r.totalHap) },
{ n: "9", label: "Total Family Share", val: fmt(r.totalFamilyShare) },
{ n: "10", label: "HAP to Owner", val: fmt(r.hapToOwner), hl: "green" },
{ n: "11", label: "Tenant Rent", val: fmt(r.tenantRent) },
{ n: "12", label: "Utility Reimbursement", val: fmt(r.utilityReimbursement) },
{ n: "", label: "PRORATED ASSISTANCE", val: "", section: true },
{ n: "13", label: "Normal HAP", val: fmt(r.normalHap) },
{ n: "14", label: "Number Eligible", val: data.numEligible },
{ n: "15", label: "Number Ineligible", val: data.numIneligible },
{ n: "16", label: "Total Family Members", val: r.totalMembers },
{ n: "17", label: "Prorate %", val: (r.proratePct * 100).toFixed(2) + "%" },
{ n: "18", label: "Prorated HAP", val: fmt(r.proratedHap) },
{ n: "19", label: "Mixed Family Rent", val: fmt(r.mixedFamilyRent) },
];
const card = bg => ({ flex: "1 1 200px", background: bg, borderRadius: 10, padding: "20px 16px", textAlign: "center", color: "#fff", minWidth: 160 });
return (
<div>
<h2 style={{ fontSize: 20, fontWeight: 700, color: "#1a73e8", margin: "0 0 16px 0" }}>Results — {data.headOfHousehold}</h2>
<div style={{ display: "flex", gap: 12, flexWrap: "wrap", marginBottom: 16 }}>
<div style={card("#0d7a3f")}><div style={{ fontSize: 12, opacity: 0.9, letterSpacing: 0.5 }}>HAP TO OWNER</div><div style={{ fontSize: 32, fontWeight: 800, marginTop: 4 }}>{fmt(r.hapToOwner)}</div></div>
<div style={card("#1a73e8")}><div style={{ fontSize: 12, opacity: 0.9, letterSpacing: 0.5 }}>TENANT RENT</div><div style={{ fontSize: 32, fontWeight: 800, marginTop: 4 }}>{fmt(r.tenantRent)}</div></div>
<div style={card("#6366f1")}><div style={{ fontSize: 12, opacity: 0.9, letterSpacing: 0.5 }}>UTILITY REIMB.</div><div style={{ fontSize: 32, fontWeight: 800, marginTop: 4 }}>{fmt(r.utilityReimbursement)}</div></div>
</div>
{r.amountAboveFmr > 0 && <div style={{ background: "#dc2626", color: "#fff", padding: "12px 16px", borderRadius: 8, fontSize: 14, fontWeight: 700, marginBottom: 12 }}>⚠ ABOVE FMR BY {fmt(r.amountAboveFmr)} — SUPERVISOR APPROVAL REQUIRED</div>}
{r.isMixedFamily && <div style={{ background: "#fbbf24", color: "#78350f", padding: "12px 16px", borderRadius: 8, fontSize: 14, marginBottom: 12 }}><strong>MIXED FAMILY:</strong> Prorated HAP = {fmt(r.proratedHap)} ({(r.proratePct*100).toFixed(1)}%) | Mixed Family Rent = {fmt(r.mixedFamilyRent)}</div>}
<div style={{ border: "1px solid #e5e7eb", borderRadius: 8, overflow: "hidden", marginBottom: 16 }}>
<div style={{ display: "grid", gridTemplateColumns: "48px 1fr 120px", background: "#f1f5f9", padding: "8px 12px", fontWeight: 700, fontSize: 13, color: "#475569" }}>
<span>#</span><span>Item</span><span style={{ textAlign: "right" }}>Amount</span>
</div>
{rows.map((row, i) => row.section ? (
<div key={i} style={{ padding: "10px 12px", background: "#f8fafc", fontSize: 12, fontWeight: 700, color: "#64748b", letterSpacing: 0.5, borderTop: "2px solid #e2e8f0" }}>{row.label}</div>
) : (
<div key={i} style={{ display: "grid", gridTemplateColumns: "48px 1fr 120px", padding: "8px 12px", fontSize: 14, background: row.hl === "green" ? "#f0fdf4" : row.hl === "red" ? "#fef2f2" : i % 2 === 0 ? "#fff" : "#f9fafb", borderTop: "1px solid #f1f5f9", color: row.hl === "red" ? "#dc2626" : row.hl === "green" ? "#166534" : "#1f2937", fontWeight: row.hl ? 700 : 400 }}>
<span style={{ color: "#9ca3af" }}>{row.n}</span><span>{row.label}</span><span style={{ textAlign: "right", fontWeight: 600 }}>{row.val}</span>
</div>
))}
</div>
<div style={{ background: "#f8fafc", borderRadius: 8, padding: 12, fontSize: 13, color: "#64748b", marginBottom: 16 }}>
<strong>Staff:</strong> {data.haStaff} | <strong>Date:</strong> {data.calcDate}
{data.supervisorName && <> | <strong>Supervisor:</strong> {data.supervisorName}</>}
</div>
<div className="no-print" style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
<button onClick={onNewCalc} style={{ padding: "10px 20px", fontSize: 14, background: "#6b7280", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>New Calculation</button>
<button onClick={copyText} style={{ padding: "10px 20px", fontSize: 14, background: "#1a73e8", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>Copy to Clipboard</button>
<button onClick={printPage} style={{ padding: "10px 20px", fontSize: 14, background: "#7c3aed", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>Print</button>
</div>
</div>
);
}
/* ── FMR Settings Modal ── */
function FMRModal({ fmrTable, onClose, onUpdateFMR }) {
const [editing, setEditing] = useState(null);
const [editValues, setEditValues] = useState({});
const startEdit = idx => { setEditing(idx); setEditValues({ ps: fmrTable[idx].paymentStandard, fmr: fmrTable[idx].fmr }); };
const saveEdit = idx => { const u = [...fmrTable]; u[idx] = { ...u[idx], paymentStandard: Number(editValues.ps) || 0, fmr: Number(editValues.fmr) || 0 }; onUpdateFMR(u); setEditing(null); };
return (
<div style={{ position: "fixed", inset: 0, background: "rgba(0,0,0,0.4)", display: "flex", alignItems: "center", justifyContent: "center", zIndex: 1000 }}>
<div style={{ background: "#fff", borderRadius: 12, width: "90%", maxWidth: 560, padding: 24, maxHeight: "80vh", overflow: "auto" }}>
<h3 style={{ fontSize: 18, fontWeight: 700, color: "#1a73e8", margin: "0 0 16px 0" }}>FMR & Payment Standard Management</h3>
<p style={{ fontSize: 13, color: "#6b7280", marginBottom: 16 }}>Click Edit on any row to update rates. Changes apply immediately.</p>
<table style={{ width: "100%", borderCollapse: "collapse", fontSize: 14 }}>
<thead><tr style={{ background: "#f1f5f9" }}><th style={{ padding: 8, textAlign: "left" }}>BR</th><th style={{ padding: 8, textAlign: "right" }}>Payment Standard</th><th style={{ padding: 8, textAlign: "right" }}>FMR</th><th style={{ padding: 8, width: 60 }}></th></tr></thead>
<tbody>{fmrTable.map((row, i) => (
<tr key={i} style={{ borderTop: "1px solid #e5e7eb" }}>
<td style={{ padding: 8 }}>{row.bedrooms}</td>
<td style={{ padding: 8, textAlign: "right" }}>{editing === i ? <input type="number" value={editValues.ps} onChange={e => setEditValues({...editValues, ps: e.target.value})} style={{ width: 100, padding: 4, textAlign: "right" }} /> : fmt(row.paymentStandard)}</td>
<td style={{ padding: 8, textAlign: "right" }}>{editing === i ? <input type="number" value={editValues.fmr} onChange={e => setEditValues({...editValues, fmr: e.target.value})} style={{ width: 100, padding: 4, textAlign: "right" }} /> : fmt(row.fmr)}</td>
<td style={{ padding: 8, textAlign: "center" }}>{editing === i ? <button onClick={() => saveEdit(i)} style={{ fontSize: 12, background: "#0d7a3f", color: "#fff", border: "none", borderRadius: 4, padding: "4px 8px", cursor: "pointer" }}>Save</button> : <button onClick={() => startEdit(i)} style={{ fontSize: 12, background: "#e5e7eb", border: "none", borderRadius: 4, padding: "4px 8px", cursor: "pointer" }}>Edit</button>}</td>
</tr>
))}</tbody>
</table>
<div style={{ display: "flex", gap: 10, marginTop: 20, justifyContent: "space-between" }}>
<button onClick={() => onUpdateFMR([...DEFAULT_FMR])} style={{ padding: "8px 16px", fontSize: 13, background: "#fbbf24", color: "#78350f", border: "none", borderRadius: 6, cursor: "pointer" }}>Reset to 2025 Defaults</button>
<button onClick={onClose} style={{ padding: "8px 20px", fontSize: 13, background: "#6b7280", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>Close</button>
</div>
</div>
</div>
);
}
/* ── Main App ── */
function App() {
const [step, setStep] = useState(0);
const [showFMR, setShowFMR] = useState(false);
const [fmrTable, setFmrTable] = useState([...DEFAULT_FMR]);
const [results, setResults] = useState(null);
const today = new Date().toISOString().split("T")[0];
const [data, setData] = useState({
headOfHousehold: "", voucherSize: "0", brLeased: "0",
rentToOwner: "", utilityAllowance: "", ttp: "50",
numEligible: "1", numIneligible: "0",
haStaff: "", calcDate: today, supervisorName: "", supervisorDate: "",
});
const onChange = useCallback((field, value) => setData(prev => ({ ...prev, [field]: value })), []);
const handleCalc = () => { setResults(calculate(data, fmrTable)); setStep(4); };
const handleNew = () => {
if (!confirm("Clear all data and start a new calculation?")) return;
setData({ headOfHousehold: "", voucherSize: "0", brLeased: "0", rentToOwner: "", utilityAllowance: "", ttp: "50", numEligible: "1", numIneligible: "0", haStaff: "", calcDate: today, supervisorName: "", supervisorDate: "" });
setResults(null); setStep(0);
};
const stepNames = ["Household", "Finances", "Family", "Staff", "Results"];
return (
<div style={{ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', background: "#f5f5f5", minHeight: "100vh" }}>
<div style={{ background: "#fff", padding: "16px 32px", display: "flex", justifyContent: "space-between", alignItems: "center", borderBottom: "1px solid #e5e7eb" }} className="no-print">
<div>
<h1 style={{ fontSize: 20, fontWeight: 800, color: "#1a73e8", margin: 0, letterSpacing: -0.5 }}>PSH RENT CALCULATOR</h1>
<p style={{ fontSize: 12, color: "#6b7280", margin: "2px 0 0 0" }}>Permanent Supportive Housing Rent Assistance</p>
</div>
<div style={{ display: "flex", gap: 8 }}>
<a href="https://github.com/bbuxton0823/PSH_Calc/archive/refs/heads/main.zip" style={{ padding: "8px 16px", fontSize: 13, background: "#0d7a3f", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer", textDecoration: "none", display: "inline-flex", alignItems: "center", gap: 6 }}>⬇ Download ZIP</a>
<button onClick={() => setShowFMR(true)} style={{ padding: "8px 16px", fontSize: 13, background: "#1a73e8", color: "#fff", border: "none", borderRadius: 6, cursor: "pointer" }}>FMR Settings</button>
</div>
</div>
<ProgressBar currentStep={step} steps={stepNames} />
<div style={{ maxWidth: 720, margin: "24px auto", background: "#fff", borderRadius: 12, padding: "28px 32px", boxShadow: "0 1px 3px rgba(0,0,0,0.08)" }}>
{step === 0 && <Step1 data={data} onChange={onChange} onNext={() => setStep(1)} fmrTable={fmrTable} />}
{step === 1 && <Step2 data={data} onChange={onChange} onBack={() => setStep(0)} onNext={() => setStep(2)} fmrTable={fmrTable} />}
{step === 2 && <Step3 data={data} onChange={onChange} onBack={() => setStep(1)} onNext={() => setStep(3)} />}
{step === 3 && <Step4 data={data} onChange={onChange} onBack={() => setStep(2)} onCalculate={handleCalc} fmrTable={fmrTable} />}
{step === 4 && results && <Step5 data={data} results={results} onNewCalc={handleNew} />}
</div>
{showFMR && <FMRModal fmrTable={fmrTable} onClose={() => setShowFMR(false)} onUpdateFMR={updated => setFmrTable(updated)} />}
</div>
);
}
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
</script>
</body>
</html>