0.2.25: batch historical eNAV backfill + collapsible investor chart

Add POST /api/import/capital-accounts/batch: upload several of a fund's
eNAV workbooks at once; each file's ALLOC SI roster is auto-matched to
existing members (by fund-admin investor ID, else name/username) and their
capital statement is saved at that file's own as-of date, building
trend-lines without replacing the latest figures. Members not already in
the portal are skipped and reported per file (never created). Capital
statements only -- holdings/NAV are untouched. One bad file (wrong
password, no ALLOC SI, unreadable date) is reported per-file and does not
abort the rest.

Import page gains a "Backfill historical capital" batch section (fund
picker, multi-file .xlsx input, shared password, per-file results table).

Investor portal "Capital over time" chart is now collapsed by default and
expands per fund (first login opens clean); applies to InvestorHome and
the admin Investor View via the shared component.

Tests: backend/tests/test_capital_batch.py (2). Full suite 17 passed;
frontend tsc clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jonathan Kirkwood
2026-07-01 18:47:01 -05:00
co-authored by Claude Opus 4.8
parent 33776d42f4
commit 099459b2f3
10 changed files with 447 additions and 8 deletions
+137 -2
View File
@@ -1,7 +1,10 @@
import { useEffect, useState } from "react";
import { api, isAdmin, type Entity, type EntityType, type CapitalImportPreview } from "../api";
import {
api, isAdmin,
type Entity, type EntityType, type CapitalImportPreview, type BatchCapitalImportResult,
} from "../api";
import { useAuth } from "../context/AuthContext";
import { formatMoneyExact } from "../format";
import { formatDate, formatMoneyExact } from "../format";
type EntityMode = "existing" | "from_file";
@@ -377,6 +380,8 @@ export default function Import() {
</div>
)}
{!memberPv && !result && <BatchBackfill entities={entities} />}
{confirmReplace && (
<div className="fixed inset-0 bg-black/40 flex items-center justify-center p-4 z-50">
<div className="bg-white rounded-lg p-6 max-w-md w-full">
@@ -406,3 +411,133 @@ export default function Import() {
</div>
);
}
// Backfill several past quarters of investor capital in one shot. Each eNAV file's ALLOC SI
// roster is auto-matched to existing members and their statement is written at the file's own
// as-of date, so older files add trend-line history without disturbing the latest figures.
// Members not already in the system are skipped (never created here) and reported per file.
function BatchBackfill({ entities }: { entities: Entity[] }) {
const [entityId, setEntityId] = useState("");
const [files, setFiles] = useState<File[]>([]);
const [password, setPassword] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
const [result, setResult] = useState<BatchCapitalImportResult | null>(null);
const inputCls = "w-full px-3 py-2 border border-gray-300 rounded text-sm";
async function run() {
if (!entityId || files.length === 0) {
setError("Pick a fund and at least one eNAV file.");
return;
}
setError("");
setResult(null);
setBusy(true);
try {
setResult(await api.capitalImportBatch(Number(entityId), files, password || undefined));
} catch (e: any) {
setError(e.message || "Batch import failed");
} finally {
setBusy(false);
}
}
return (
<div className="mt-10 border-t border-gray-200 pt-8">
<h2 className="text-lg font-semibold text-gray-900 mb-1">Backfill historical capital</h2>
<p className="text-sm text-gray-500 mb-4 max-w-3xl">
Load several past quarters at once to build investors' trend-lines. Drop the eNAV
workbooks for one fund; each file's members are matched to existing accounts and their
capital statement is saved at that file's own as-of date. The latest figures are never
replaced, and members not already in the portal are skipped (not created).
</p>
{error && <div className="p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700 mb-4">{error}</div>}
<div className="bg-white border border-gray-200 rounded-lg p-4 space-y-3">
<div>
<label className="block text-sm text-gray-700 mb-1">Fund</label>
<select value={entityId} onChange={(e) => setEntityId(e.target.value)} className={inputCls}>
<option value="">Select fund</option>
{entities.map((e) => <option key={e.id} value={e.id}>{e.name}</option>)}
</select>
</div>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="block text-xs text-gray-500 mb-1">eNAV workbooks (.xlsx select several)</label>
<input
type="file"
accept=".xlsx"
multiple
onChange={(e) => { setFiles(Array.from(e.target.files ?? [])); setResult(null); }}
className="text-sm"
/>
{files.length > 0 && <p className="text-xs text-gray-400 mt-1">{files.length} file(s) selected</p>}
</div>
<div>
<label className="block text-xs text-gray-500 mb-1">Spreadsheet password</label>
<input
type="text"
className={inputCls}
value={password}
placeholder="Shared open password, if protected"
autoComplete="off"
onChange={(e) => setPassword(e.target.value)}
/>
</div>
</div>
<div className="flex justify-end">
<button
onClick={run}
disabled={busy || !entityId || files.length === 0}
className="px-3 py-1.5 bg-gray-900 text-white text-sm rounded hover:bg-gray-800 disabled:opacity-50"
>
{busy ? "Loading history…" : "Load history"}
</button>
</div>
</div>
{result && (
<div className="mt-4 bg-white border border-gray-200 rounded-lg overflow-hidden">
<div className="px-4 py-2 bg-gray-50 text-sm text-gray-600 border-b border-gray-100">
{result.total_statements} statement(s) written across {result.files.length} file(s)
</div>
<table className="w-full text-sm">
<thead className="text-gray-500 text-left">
<tr>
<th className="px-4 py-2 font-medium">File</th>
<th className="px-4 py-2 font-medium">As-of</th>
<th className="px-4 py-2 font-medium text-right">Loaded</th>
<th className="px-4 py-2 font-medium">Skipped (no account)</th>
</tr>
</thead>
<tbody>
{result.files.map((f, i) => (
<tr key={i} className="border-t border-gray-100 align-top">
<td className="px-4 py-2 text-gray-900">{f.filename}</td>
<td className="px-4 py-2 text-gray-600">{f.as_of_date ? formatDate(f.as_of_date) : "—"}</td>
<td className="px-4 py-2 text-right text-gray-900">
{f.error ? "—" : f.statements_written}
</td>
<td className="px-4 py-2 text-gray-500">
{f.error ? (
<span className="text-red-600">{f.error}</span>
) : f.skipped.length === 0 ? (
<span className="text-gray-400">none</span>
) : (
<span title={f.skipped.join(", ")}>
{f.skipped.length}: {f.skipped.slice(0, 3).join(", ")}
{f.skipped.length > 3 ? "…" : ""}
</span>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
}