From e5d77022c428d3097eea08b9dfa7d472991abbc5 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 9 Apr 2026 13:06:14 +0200 Subject: [PATCH] General Journal: per-row balance, wider date, remove collapse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added per-account running balance column: each row shows the account's balance after this specific row's delta is applied. Balance accounts (Asset/Debt) start from dawn-of-time prior balance; result accounts (Income/Cost) start from fiscal year start. - Removed collapse/expand on transaction headers — they're just headers, not collapsible parents. Eliminates whitespace issue. - Widened date column to 145px with whiteSpace: nowrap to prevent date wrapping across lines. - Simplified component by removing all collapse state and animation code. Made-with: Cursor --- .../src/pages/inspect/GeneralJournalTab.tsx | 203 +++++++----------- .../Endpoints/InspectLedgerEndpoints.cs | 42 +++- 2 files changed, 114 insertions(+), 131 deletions(-) diff --git a/frontend/src/pages/inspect/GeneralJournalTab.tsx b/frontend/src/pages/inspect/GeneralJournalTab.tsx index 5ee05ba9..069cd81e 100644 --- a/frontend/src/pages/inspect/GeneralJournalTab.tsx +++ b/frontend/src/pages/inspect/GeneralJournalTab.tsx @@ -4,14 +4,14 @@ import { TableHead, TableRow, Paper, Select, MenuItem, FormControl, InputLabel, Skeleton, Chip, Tooltip, } from '@mui/material' -import { ChevronRight, AttachFile } from '@mui/icons-material' +import { AttachFile } from '@mui/icons-material' import { useOrg } from '../../contexts/OrgContext' import { api } from '../../api/client' import { formatCents } from '../../utils/money' interface JournalRow { rowId: number; accountId: number; accountName: string; accountType: string - debitCents: number; creditCents: number + debitCents: number; creditCents: number; balanceCents: number foreignCurrencyCode: string; foreignCurrencyAmountCents: number } @@ -39,17 +39,12 @@ const MONTHS = [ const currentYear = new Date().getFullYear() const YEARS = Array.from({ length: 15 }, (_, i) => currentYear - i) -const TYPE_ABBREV: Record = { - Asset: 'Asset', Debt: 'Debt', Income: 'Income', Cost: 'Cost', -} - export default function GeneralJournalTab() { const { activeOrg } = useOrg() const [year, setYear] = useState(currentYear) const [month, setMonth] = useState(new Date().getMonth() + 1) const [data, setData] = useState(null) const [loading, setLoading] = useState(false) - const [collapsedTxs, setCollapsedTxs] = useState>(new Set()) useEffect(() => { if (!activeOrg) return @@ -62,15 +57,6 @@ export default function GeneralJournalTab() { .finally(() => setLoading(false)) }, [activeOrg, year, month]) - const toggleTx = (txId: number) => { - setCollapsedTxs(prev => { - const next = new Set(prev) - if (next.has(txId)) next.delete(txId) - else next.add(txId) - return next - }) - } - if (!activeOrg) return null return ( @@ -105,131 +91,104 @@ export default function GeneralJournalTab() { - - + + - Tx# Date Description / Account Debit Credit + Balance - {data.transactions.map(tx => { - const isCollapsed = collapsedTxs.has(tx.transactionId) + {data.transactions.map(tx => [ + // Transaction header row + + + {tx.sequenceId || tx.transactionId} + + + {new Date(tx.dateTime).toLocaleDateString('sv-SE')} + + {new Date(tx.dateTime).toLocaleTimeString('sv-SE', { hour: '2-digit', minute: '2-digit' })} + + + + {tx.description} + {tx.hasDocumentation && ( + + )} + + + + + , - return [ - // Transaction header row - toggleTx(tx.transactionId)} - > - - - - + // Transaction row entries + ...tx.rows.map(row => ( + + + + - - {tx.sequenceId || tx.transactionId} - - - {new Date(tx.dateTime).toLocaleDateString('sv-SE')} - - {new Date(tx.dateTime).toLocaleTimeString('sv-SE', { hour: '2-digit', minute: '2-digit' })} - - - - {tx.description} - {tx.hasDocumentation && ( - + + + + {row.accountName} + + + {row.foreignCurrencyCode && ( + )} - - - , - - // Transaction row entries (collapsible) - ...tx.rows.map(row => ( - *': { - maxHeight: isCollapsed ? 0 : 30, - overflow: 'hidden', - opacity: isCollapsed ? 0 : 1, - transition: 'max-height 0.3s ease, opacity 0.25s ease', - }, - }} - > - - - - - - - - - {row.accountName} - - - {row.foreignCurrencyCode && ( - - )} - - 0 ? 'text.primary' : 'text.disabled', - }}> - {row.debitCents > 0 ? formatCents(row.debitCents) : ''} - - 0 ? 'error.main' : 'text.disabled', - }}> - {row.creditCents > 0 ? formatCents(row.creditCents) : ''} - - - )), - ] - })} + 0 ? 'text.primary' : 'text.disabled', + }}> + {row.debitCents > 0 ? formatCents(row.debitCents) : ''} + + 0 ? 'error.main' : 'text.disabled', + }}> + {row.creditCents > 0 ? formatCents(row.creditCents) : ''} + + + {formatCents(row.balanceCents)} + + + )), + ])}
diff --git a/src/UsingCash.Api/Endpoints/InspectLedgerEndpoints.cs b/src/UsingCash.Api/Endpoints/InspectLedgerEndpoints.cs index 1922b418..c1ff38a4 100644 --- a/src/UsingCash.Api/Endpoints/InspectLedgerEndpoints.cs +++ b/src/UsingCash.Api/Endpoints/InspectLedgerEndpoints.cs @@ -171,6 +171,22 @@ public static class InspectLedgerEndpoints } } + // Compute per-account running balances (prior balance + each row's delta) + var runningBalances = new Dictionary(); + var balanceStart = new DateTime(1, 1, 1); + var profitLossStart = new DateTime(from.Year, 1, 1); + + foreach (var acct in allAccounts) + { + var isBalanceAccount = acct.AccountType == UsingCash.Common.Enums.FinancialAccountType.Asset + || acct.AccountType == UsingCash.Common.Enums.FinancialAccountType.Debt; + var priorStart = isBalanceAccount ? balanceStart : profitLossStart; + if (priorStart < from) + runningBalances[acct.FinancialAccountId] = await repo.GetAccountBalanceCents(acct.FinancialAccountId, from); + else + runningBalances[acct.FinancialAccountId] = 0; + } + var grouped = allRows .GroupBy(r => r.Row.FinancialTransactionId) .Where(g => txCache.ContainsKey(g.Key)) @@ -187,16 +203,24 @@ public static class InspectLedgerEndpoints description = tx.Comment, blockchainHash = tx.BlockchainHash, hasDocumentation = tx.HasDocumentation, - rows = g.Select(r => new + rows = g.Select(r => { - rowId = r.Row.FinancialTransactionRowId, - accountId = r.AccountId, - accountName = AccountPath(r.AccountId), - accountType = accountMap.TryGetValue(r.AccountId, out var a) ? a.AccountType.ToString() : "", - debitCents = r.Row.AmountCents > 0 ? r.Row.AmountCents : 0, - creditCents = r.Row.AmountCents < 0 ? -r.Row.AmountCents : 0, - foreignCurrencyCode = r.Row.ForeignCurrencyCode, - foreignCurrencyAmountCents = r.Row.ForeignCurrencyAmountCents, + if (!runningBalances.ContainsKey(r.AccountId)) + runningBalances[r.AccountId] = 0; + runningBalances[r.AccountId] += r.Row.AmountCents; + + return new + { + rowId = r.Row.FinancialTransactionRowId, + accountId = r.AccountId, + accountName = AccountPath(r.AccountId), + accountType = accountMap.TryGetValue(r.AccountId, out var a) ? a.AccountType.ToString() : "", + debitCents = r.Row.AmountCents > 0 ? r.Row.AmountCents : 0, + creditCents = r.Row.AmountCents < 0 ? -r.Row.AmountCents : 0, + balanceCents = runningBalances[r.AccountId], + foreignCurrencyCode = r.Row.ForeignCurrencyCode, + foreignCurrencyAmountCents = r.Row.ForeignCurrencyAmountCents, + }; }).ToList(), }; }).ToList();