Opening Balances: fix duplicate earnings accounts; recognize name variants

The auto-provision effect could fire twice and create duplicate "Current Year
Earnings" accounts (seen on Village Grove). Use the idempotent
coa_get_or_create RPC with a once-per-company ref guard, and match existing
name variants (Current Year Income / Net Income / Retained Earnings) so it
won't create redundant accounts. Balance sheet now also folds
"Current Year Income"/"Net Income" equity accounts into the Net Income line.
Removed the existing Village Grove duplicate (zero activity).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 19:04:51 -04:00
parent 7fd8ad2c52
commit aa94622a78
2 changed files with 15 additions and 15 deletions
@@ -1179,7 +1179,7 @@ function buildBalanceSheet(d: any, p?: any, useCompare?: boolean): StructuredRep
// calculated prior-years and Net Income lines (instead of separate lines) so the
// figures the user enters in Opening Balances show up where expected.
const reAccts = equityAccs.filter((a) => /retained\s+earnings/i.test(String(a.name || "")));
const cyeAccts = equityAccs.filter((a) => /current\s*year\s*earnings/i.test(String(a.name || "")));
const cyeAccts = equityAccs.filter((a) => /current\s*year\s*(earnings|income)/i.test(String(a.name || "")) || /^\s*net\s*income\s*$/i.test(String(a.name || "")));
const foldedIds = new Set([...reAccts, ...cyeAccts].map((a) => a.id));
const otherEquity = equityAccs.filter((a) => !foldedIds.has(a.id));
for (const a of otherEquity) rows.push({ kind: "sub", label: a.name, code: a.code ?? undefined, amount: balOf(a), compare: cmp(balOfP(a)), accountId: a.id });