General Journal: per-row balance, wider date, remove collapse
- 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
This commit is contained in:
@@ -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<string, string> = {
|
||||
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<JournalResponse | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [collapsedTxs, setCollapsedTxs] = useState<Set<number>>(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() {
|
||||
<TableContainer component={Paper} elevation={2}>
|
||||
<Table size="small" sx={{ tableLayout: 'fixed', '& td, & th': { py: 0.4, fontSize: 13 } }}>
|
||||
<colgroup>
|
||||
<col style={{ width: 30 }} />
|
||||
<col style={{ width: 60 }} />
|
||||
<col style={{ width: 120 }} />
|
||||
<col style={{ width: 145 }} />
|
||||
<col />
|
||||
<col style={{ width: 100 }} />
|
||||
<col style={{ width: 100 }} />
|
||||
<col style={{ width: 110 }} />
|
||||
</colgroup>
|
||||
<TableHead>
|
||||
<TableRow sx={{ bgcolor: 'primary.main' }}>
|
||||
<TableCell sx={{ color: 'white' }} />
|
||||
<TableCell sx={{ color: 'white', fontWeight: 600 }}>Tx#</TableCell>
|
||||
<TableCell sx={{ color: 'white', fontWeight: 600 }}>Date</TableCell>
|
||||
<TableCell sx={{ color: 'white', fontWeight: 600 }}>Description / Account</TableCell>
|
||||
<TableCell align="right" sx={{ color: 'white', fontWeight: 600 }}>Debit</TableCell>
|
||||
<TableCell align="right" sx={{ color: 'white', fontWeight: 600 }}>Credit</TableCell>
|
||||
<TableCell align="right" sx={{ color: 'white', fontWeight: 600 }}>Balance</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data.transactions.map(tx => {
|
||||
const isCollapsed = collapsedTxs.has(tx.transactionId)
|
||||
{data.transactions.map(tx => [
|
||||
// Transaction header row
|
||||
<TableRow
|
||||
key={`tx-${tx.transactionId}`}
|
||||
sx={{
|
||||
bgcolor: 'rgba(25, 118, 210, 0.04)',
|
||||
borderTop: '1px solid',
|
||||
borderColor: 'divider',
|
||||
}}
|
||||
>
|
||||
<TableCell sx={{ fontWeight: 700, fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{tx.sequenceId || tx.transactionId}
|
||||
</TableCell>
|
||||
<TableCell sx={{ fontWeight: 600, fontSize: 12, whiteSpace: 'nowrap' }}>
|
||||
{new Date(tx.dateTime).toLocaleDateString('sv-SE')}
|
||||
<Typography component="span" sx={{ ml: 0.5, fontSize: 11, color: 'text.disabled' }}>
|
||||
{new Date(tx.dateTime).toLocaleTimeString('sv-SE', { hour: '2-digit', minute: '2-digit' })}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell sx={{ fontWeight: 600 }}>
|
||||
{tx.description}
|
||||
{tx.hasDocumentation && (
|
||||
<AttachFile sx={{ fontSize: 14, ml: 0.5, color: 'text.secondary', verticalAlign: 'middle' }} />
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell />
|
||||
<TableCell />
|
||||
<TableCell />
|
||||
</TableRow>,
|
||||
|
||||
return [
|
||||
// Transaction header row
|
||||
<TableRow
|
||||
key={`tx-${tx.transactionId}`}
|
||||
sx={{
|
||||
bgcolor: 'rgba(25, 118, 210, 0.04)',
|
||||
borderTop: '1px solid',
|
||||
borderColor: 'divider',
|
||||
cursor: 'pointer',
|
||||
'&:hover': { bgcolor: 'rgba(25, 118, 210, 0.08)' },
|
||||
}}
|
||||
onClick={() => toggleTx(tx.transactionId)}
|
||||
>
|
||||
<TableCell sx={{ p: '0 !important', textAlign: 'center' }}>
|
||||
<Box sx={{
|
||||
display: 'inline-flex',
|
||||
transition: 'transform 0.2s ease',
|
||||
transform: isCollapsed ? 'rotate(0deg)' : 'rotate(90deg)',
|
||||
}}>
|
||||
<ChevronRight sx={{ fontSize: 16, color: 'text.secondary' }} />
|
||||
</Box>
|
||||
// Transaction row entries
|
||||
...tx.rows.map(row => (
|
||||
<TableRow key={`row-${row.rowId}`} hover>
|
||||
<TableCell />
|
||||
<TableCell>
|
||||
<Chip
|
||||
label={row.accountType}
|
||||
size="small"
|
||||
variant="outlined"
|
||||
sx={{ fontSize: 10, height: 18, minWidth: 48 }}
|
||||
color={
|
||||
row.accountType === 'Asset' ? 'success' :
|
||||
row.accountType === 'Debt' ? 'error' :
|
||||
row.accountType === 'Income' ? 'info' : 'warning'
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell sx={{ fontWeight: 700, fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{tx.sequenceId || tx.transactionId}
|
||||
</TableCell>
|
||||
<TableCell sx={{ fontWeight: 600, fontSize: 12 }}>
|
||||
{new Date(tx.dateTime).toLocaleDateString('sv-SE')}
|
||||
<Typography component="span" sx={{ ml: 0.5, fontSize: 11, color: 'text.disabled' }}>
|
||||
{new Date(tx.dateTime).toLocaleTimeString('sv-SE', { hour: '2-digit', minute: '2-digit' })}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell sx={{ fontWeight: 600 }}>
|
||||
{tx.description}
|
||||
{tx.hasDocumentation && (
|
||||
<AttachFile sx={{ fontSize: 14, ml: 0.5, color: 'text.secondary', verticalAlign: 'middle' }} />
|
||||
<TableCell sx={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
<Tooltip title={row.accountName} placement="top-start">
|
||||
<Typography component="span" variant="body2" sx={{ fontSize: 13, color: 'text.secondary' }}>
|
||||
{row.accountName}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
{row.foreignCurrencyCode && (
|
||||
<Chip label={`${row.foreignCurrencyCode} ${formatCents(Math.abs(row.foreignCurrencyAmountCents))}`}
|
||||
size="small" variant="outlined" sx={{ ml: 1, fontSize: 10, height: 18 }} />
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell />
|
||||
<TableCell />
|
||||
</TableRow>,
|
||||
|
||||
// Transaction row entries (collapsible)
|
||||
...tx.rows.map(row => (
|
||||
<TableRow
|
||||
key={`row-${row.rowId}`}
|
||||
hover
|
||||
sx={{
|
||||
'& td': {
|
||||
overflow: 'hidden',
|
||||
paddingTop: isCollapsed ? '0px !important' : undefined,
|
||||
paddingBottom: isCollapsed ? '0px !important' : undefined,
|
||||
borderBottom: isCollapsed ? 'none' : undefined,
|
||||
transition: 'padding-top 0.3s ease, padding-bottom 0.3s ease',
|
||||
},
|
||||
'& td > *': {
|
||||
maxHeight: isCollapsed ? 0 : 30,
|
||||
overflow: 'hidden',
|
||||
opacity: isCollapsed ? 0 : 1,
|
||||
transition: 'max-height 0.3s ease, opacity 0.25s ease',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<TableCell />
|
||||
<TableCell />
|
||||
<TableCell>
|
||||
<Chip
|
||||
label={TYPE_ABBREV[row.accountType] || row.accountType}
|
||||
size="small"
|
||||
variant="outlined"
|
||||
sx={{ fontSize: 10, height: 18, minWidth: 48 }}
|
||||
color={
|
||||
row.accountType === 'Asset' ? 'success' :
|
||||
row.accountType === 'Debt' ? 'error' :
|
||||
row.accountType === 'Income' ? 'info' : 'warning'
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell sx={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
<Tooltip title={row.accountName} placement="top-start">
|
||||
<Typography component="span" variant="body2" sx={{ fontSize: 13, color: 'text.secondary' }}>
|
||||
{row.accountName}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
{row.foreignCurrencyCode && (
|
||||
<Chip label={`${row.foreignCurrencyCode} ${formatCents(Math.abs(row.foreignCurrencyAmountCents))}`}
|
||||
size="small" variant="outlined" sx={{ ml: 1, fontSize: 10, height: 18 }} />
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
color: row.debitCents > 0 ? 'text.primary' : 'text.disabled',
|
||||
}}>
|
||||
<span>{row.debitCents > 0 ? formatCents(row.debitCents) : ''}</span>
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
color: row.creditCents > 0 ? 'error.main' : 'text.disabled',
|
||||
}}>
|
||||
<span>{row.creditCents > 0 ? formatCents(row.creditCents) : ''}</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)),
|
||||
]
|
||||
})}
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
color: row.debitCents > 0 ? 'text.primary' : 'text.disabled',
|
||||
}}>
|
||||
{row.debitCents > 0 ? formatCents(row.debitCents) : ''}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
color: row.creditCents > 0 ? 'error.main' : 'text.disabled',
|
||||
}}>
|
||||
{row.creditCents > 0 ? formatCents(row.creditCents) : ''}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
fontSize: 12,
|
||||
color: row.balanceCents < 0 ? 'error.main' : 'text.secondary',
|
||||
}}>
|
||||
{formatCents(row.balanceCents)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)),
|
||||
])}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
|
||||
@@ -171,6 +171,22 @@ public static class InspectLedgerEndpoints
|
||||
}
|
||||
}
|
||||
|
||||
// Compute per-account running balances (prior balance + each row's delta)
|
||||
var runningBalances = new Dictionary<int, long>();
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user