diff --git a/src/pages/accounting/AccountingReportsPage.tsx b/src/pages/accounting/AccountingReportsPage.tsx index 37d86d6..abc8635 100644 --- a/src/pages/accounting/AccountingReportsPage.tsx +++ b/src/pages/accounting/AccountingReportsPage.tsx @@ -1171,8 +1171,16 @@ function buildBalanceSheet(d: any, p?: any, useCompare?: boolean): StructuredRep // Equity — equity accounts + calculated RE / current-year earnings rows.push({ kind: "section", label: "Equity" }); const equityAccs = byType("equity"); - for (const a of equityAccs) rows.push({ kind: "sub", label: a.name, code: a.code ?? undefined, amount: balOf(a), compare: cmp(balOfP(a)), accountId: a.id }); - rows.push({ kind: "sub", label: "Retained Earnings (prior years)", amount: cur.rePrior, compare: cmp(prev?.rePrior) }); + // A real "Retained Earnings" equity account is postable via journal entries. + // Fold its posted balance into the calculated "Retained Earnings (prior years)" + // line so manual JE adjustments show there instead of as a separate line. + const reAccts = equityAccs.filter((a) => /retained\s+earnings/i.test(String(a.name || ""))); + const reIds = new Set(reAccts.map((a) => a.id)); + const otherEquity = equityAccs.filter((a) => !reIds.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 }); + const rePosted = reAccts.reduce((s, a) => s + balOf(a), 0); + const rePostedP = prev ? reAccts.reduce((s, a) => s + (prev.glByAcct.get(a.id) ?? 0), 0) : undefined; + rows.push({ kind: "sub", label: "Retained Earnings (prior years)", amount: cur.rePrior + rePosted, compare: cmp(prev ? prev.rePrior + (rePostedP ?? 0) : undefined) }); rows.push({ kind: "sub", label: "Net Income", amount: cur.cye, compare: cmp(prev?.cye) }); const totalE = sumBal(equityAccs) + cur.rePrior + cur.cye; const totalEP = prev ? (sumBalP(equityAccs)! + prev.rePrior + prev.cye) : undefined;