Add transaction detail dialog, clickable from both ledger tabs
TransactionDetailDialog: shared modal showing full transaction info: - Header: Tx#, balanced/unbalanced chip - Date, description, currency - Dependency link (Expense Claim #N, Invoice #N, etc.) - Blockchain hash if present - Documentation indicator - Row table: account name, debit, credit, foreign currency, totals Wired into both tabs: - Account Ledger: Tx# column is now clickable (blue, underline on hover) - General Journal: transaction header row is clickable (hover highlight) Both tabs load account name map from /inspect/accounts-tree for the dialog's account name resolution. Also updated TransactionDetail API type to include hasDocumentation, dependency, and foreign currency fields on rows. Made-with: Cursor
This commit is contained in:
@@ -121,7 +121,7 @@ export interface ProfitLoss { year: number; totalIncomeCents: number; totalCosts
|
||||
|
||||
export interface LedgerRow { financialTransactionRowId: number; financialTransactionId: number; financialAccountId: number; amountCents: number; createdDateTime: string; foreignCurrencyCode: string; foreignCurrencyAmountCents: number; runningBalance: number }
|
||||
export interface LedgerData { accountId: number; from: string; to: string; rows: LedgerRow[] }
|
||||
export interface TransactionDetail { financialTransactionId: number; organizationSequenceId: number; dateTime: string; comment: string; blockchainHash: string; rows: { financialTransactionRowId: number; financialAccountId: number; amountCents: number }[] }
|
||||
export interface TransactionDetail { financialTransactionId: number; organizationSequenceId: number; dateTime: string; comment: string; blockchainHash: string; hasDocumentation: boolean; dependency: { typeId: number; foreignId: number } | null; rows: { financialTransactionRowId: number; financialAccountId: number; amountCents: number; foreignCurrencyCode: string; foreignCurrencyAmountCents: number }[] }
|
||||
|
||||
export interface ExpenseClaim { expenseClaimId: number; organizationSequenceId: number; claimingUserId: number; expenseDate: string; description: string; amountCents: number; vatCents: number; attested: boolean; validated: boolean; open: boolean }
|
||||
export interface InboundInvoice { inboundInvoiceId: number; organizationSequenceId: number; supplier: string; dueDate: string; amountCents: number; vatCents: number; attested: boolean; open: boolean; description: string }
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import {
|
||||
Dialog, DialogTitle, DialogContent, DialogActions, Button,
|
||||
Table, TableBody, TableCell, TableContainer, TableHead, TableRow,
|
||||
Paper, Typography, Box, Chip, Skeleton, Divider,
|
||||
} from '@mui/material'
|
||||
import { AttachFile, Link as LinkIcon } from '@mui/icons-material'
|
||||
import { api, type TransactionDetail } from '../api/client'
|
||||
import { formatCents } from '../utils/money'
|
||||
|
||||
const DEP_TYPE_NAMES: Record<number, string> = {
|
||||
1: 'Expense Claim',
|
||||
2: 'Inbound Invoice',
|
||||
3: 'Salary',
|
||||
4: 'Outbound Invoice',
|
||||
5: 'Cash Advance',
|
||||
6: 'Payout',
|
||||
7: 'Payment Group',
|
||||
8: 'Cash Advance Payback',
|
||||
9: 'Financial Transaction',
|
||||
10: 'Cash Advance Payback',
|
||||
11: 'VAT Report',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
transactionId: number | null
|
||||
orgId: number
|
||||
accountNames: Record<number, string>
|
||||
currencyCode?: string
|
||||
}
|
||||
|
||||
export default function TransactionDetailDialog({
|
||||
open, onClose, transactionId, orgId, accountNames, currencyCode,
|
||||
}: Props) {
|
||||
const [tx, setTx] = useState<TransactionDetail | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !transactionId) return
|
||||
setLoading(true)
|
||||
api.ledger(orgId).transaction(transactionId)
|
||||
.then(setTx)
|
||||
.catch(() => setTx(null))
|
||||
.finally(() => setLoading(false))
|
||||
}, [open, transactionId, orgId])
|
||||
|
||||
const totalDebit = tx?.rows.reduce((s, r) => s + (r.amountCents > 0 ? r.amountCents : 0), 0) ?? 0
|
||||
const totalCredit = tx?.rows.reduce((s, r) => s + (r.amountCents < 0 ? -r.amountCents : 0), 0) ?? 0
|
||||
const isBalanced = totalDebit === totalCredit
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth>
|
||||
<DialogTitle sx={{ pb: 1 }}>
|
||||
{loading ? (
|
||||
<Skeleton width={300} />
|
||||
) : tx ? (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 700 }}>
|
||||
Transaction #{tx.organizationSequenceId}
|
||||
</Typography>
|
||||
{isBalanced ? (
|
||||
<Chip label="Balanced" size="small" color="success" variant="outlined" />
|
||||
) : (
|
||||
<Chip label="UNBALANCED" size="small" color="error" />
|
||||
)}
|
||||
</Box>
|
||||
) : (
|
||||
'Transaction'
|
||||
)}
|
||||
</DialogTitle>
|
||||
|
||||
<DialogContent>
|
||||
{loading ? (
|
||||
<Skeleton height={200} />
|
||||
) : tx ? (
|
||||
<>
|
||||
{/* Header info */}
|
||||
<Box sx={{ display: 'flex', gap: 4, mb: 2, flexWrap: 'wrap' }}>
|
||||
<Box>
|
||||
<Typography variant="caption" color="text.secondary">Date</Typography>
|
||||
<Typography variant="body2" sx={{ fontWeight: 600 }}>
|
||||
{new Date(tx.dateTime).toLocaleDateString('sv-SE')}
|
||||
{' '}
|
||||
{new Date(tx.dateTime).toLocaleTimeString('sv-SE', { hour: '2-digit', minute: '2-digit' })}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<Typography variant="caption" color="text.secondary">Description</Typography>
|
||||
<Typography variant="body2" sx={{ fontWeight: 600 }}>
|
||||
{tx.comment}
|
||||
</Typography>
|
||||
</Box>
|
||||
{currencyCode && (
|
||||
<Box>
|
||||
<Typography variant="caption" color="text.secondary">Currency</Typography>
|
||||
<Typography variant="body2">{currencyCode}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{/* Dependency */}
|
||||
{tx.dependency && (
|
||||
<Box sx={{ mb: 2, display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<LinkIcon sx={{ fontSize: 16, color: 'text.secondary' }} />
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
Linked to:
|
||||
</Typography>
|
||||
<Chip
|
||||
label={`${DEP_TYPE_NAMES[tx.dependency.typeId] || `Type ${tx.dependency.typeId}`} #${tx.dependency.foreignId}`}
|
||||
size="small"
|
||||
color="primary"
|
||||
variant="outlined"
|
||||
sx={{ cursor: 'pointer' }}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Blockchain hash */}
|
||||
{tx.blockchainHash && (
|
||||
<Box sx={{ mb: 2, display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<Typography variant="body2" color="text.secondary">Blockchain:</Typography>
|
||||
<Typography variant="body2" sx={{ fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{tx.blockchainHash}
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Documentation indicator */}
|
||||
{tx.hasDocumentation && (
|
||||
<Box sx={{ mb: 2, display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<AttachFile sx={{ fontSize: 16, color: 'text.secondary' }} />
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
This transaction has attached documentation
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
<Divider sx={{ mb: 2 }} />
|
||||
|
||||
{/* Transaction rows */}
|
||||
<TableContainer component={Paper} variant="outlined">
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow sx={{ bgcolor: 'grey.50' }}>
|
||||
<TableCell sx={{ fontWeight: 600 }}>Account</TableCell>
|
||||
<TableCell align="right" sx={{ fontWeight: 600, width: 120 }}>Debit</TableCell>
|
||||
<TableCell align="right" sx={{ fontWeight: 600, width: 120 }}>Credit</TableCell>
|
||||
{tx.rows.some(r => r.foreignCurrencyCode) && (
|
||||
<TableCell sx={{ fontWeight: 600, width: 150 }}>Foreign</TableCell>
|
||||
)}
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{tx.rows.map(row => {
|
||||
const debit = row.amountCents > 0 ? row.amountCents : 0
|
||||
const credit = row.amountCents < 0 ? -row.amountCents : 0
|
||||
const hasForeign = tx.rows.some(r => r.foreignCurrencyCode)
|
||||
|
||||
return (
|
||||
<TableRow key={row.financialTransactionRowId} hover>
|
||||
<TableCell>
|
||||
{accountNames[row.financialAccountId] || `Account #${row.financialAccountId}`}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
color: debit > 0 ? 'text.primary' : 'text.disabled',
|
||||
}}>
|
||||
{debit > 0 ? formatCents(debit) : ''}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{
|
||||
fontFamily: '"Roboto Mono", monospace',
|
||||
color: credit > 0 ? 'error.main' : 'text.disabled',
|
||||
}}>
|
||||
{credit > 0 ? formatCents(credit) : ''}
|
||||
</TableCell>
|
||||
{hasForeign && (
|
||||
<TableCell sx={{ fontSize: 12, color: 'text.secondary' }}>
|
||||
{row.foreignCurrencyCode && (
|
||||
`${row.foreignCurrencyCode} ${formatCents(Math.abs(row.foreignCurrencyAmountCents))}`
|
||||
)}
|
||||
</TableCell>
|
||||
)}
|
||||
</TableRow>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Totals */}
|
||||
<TableRow sx={{ bgcolor: 'grey.50' }}>
|
||||
<TableCell sx={{ fontWeight: 700 }}>Total</TableCell>
|
||||
<TableCell align="right" sx={{ fontWeight: 700, fontFamily: '"Roboto Mono", monospace' }}>
|
||||
{formatCents(totalDebit)}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{ fontWeight: 700, fontFamily: '"Roboto Mono", monospace', color: 'error.main' }}>
|
||||
{formatCents(totalCredit)}
|
||||
</TableCell>
|
||||
{tx.rows.some(r => r.foreignCurrencyCode) && <TableCell />}
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</>
|
||||
) : (
|
||||
<Typography color="text.secondary">Transaction not found.</Typography>
|
||||
)}
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions>
|
||||
<Button onClick={onClose}>Close</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import { useOrg } from '../../contexts/OrgContext'
|
||||
import { api } from '../../api/client'
|
||||
import { formatCents } from '../../utils/money'
|
||||
import TransactionDetailDialog from '../../components/TransactionDetailDialog'
|
||||
|
||||
interface AccountOption {
|
||||
id: number; name: string; parentId: number; accountType: string; open: boolean
|
||||
@@ -49,6 +50,19 @@ export default function AccountLedgerTab() {
|
||||
const [data, setData] = useState<LedgerResponse | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [ownOnly, setOwnOnly] = useState(false)
|
||||
const [selectedTxId, setSelectedTxId] = useState<number | null>(null)
|
||||
const [accountNames, setAccountNames] = useState<Record<number, string>>({})
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeOrg) return
|
||||
api.get<{ id: number; name: string }[]>(`/organizations/${activeOrg.organizationId}/inspect/accounts-tree`)
|
||||
.then(accts => {
|
||||
const map: Record<number, string> = {}
|
||||
for (const a of accts) map[a.id] = a.name
|
||||
setAccountNames(map)
|
||||
})
|
||||
.catch(() => {})
|
||||
}, [activeOrg])
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeOrg) return
|
||||
@@ -231,7 +245,10 @@ export default function AccountLedgerTab() {
|
||||
|
||||
{data.entries.map(entry => (
|
||||
<TableRow key={entry.rowId} hover sx={{ cursor: 'pointer' }}>
|
||||
<TableCell sx={{ fontFamily: 'monospace', color: 'text.secondary', fontSize: 12 }}>
|
||||
<TableCell
|
||||
sx={{ fontFamily: 'monospace', color: 'primary.main', fontSize: 12, cursor: 'pointer', '&:hover': { textDecoration: 'underline' } }}
|
||||
onClick={() => setSelectedTxId(entry.transactionId)}
|
||||
>
|
||||
{entry.sequenceId || entry.transactionId}
|
||||
</TableCell>
|
||||
<TableCell sx={{ fontSize: 12 }}>
|
||||
@@ -323,6 +340,17 @@ export default function AccountLedgerTab() {
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeOrg && (
|
||||
<TransactionDetailDialog
|
||||
open={selectedTxId !== null}
|
||||
onClose={() => setSelectedTxId(null)}
|
||||
transactionId={selectedTxId}
|
||||
orgId={activeOrg.organizationId}
|
||||
accountNames={accountNames}
|
||||
currencyCode={activeOrg.currencyCode}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { AttachFile } from '@mui/icons-material'
|
||||
import { useOrg } from '../../contexts/OrgContext'
|
||||
import { api } from '../../api/client'
|
||||
import { formatCents } from '../../utils/money'
|
||||
import TransactionDetailDialog from '../../components/TransactionDetailDialog'
|
||||
|
||||
interface JournalRow {
|
||||
rowId: number; accountId: number; accountName: string; accountType: string
|
||||
@@ -45,6 +46,19 @@ export default function GeneralJournalTab() {
|
||||
const [month, setMonth] = useState(new Date().getMonth() + 1)
|
||||
const [data, setData] = useState<JournalResponse | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [selectedTxId, setSelectedTxId] = useState<number | null>(null)
|
||||
const [accountNames, setAccountNames] = useState<Record<number, string>>({})
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeOrg) return
|
||||
api.get<{ id: number; name: string }[]>(`/organizations/${activeOrg.organizationId}/inspect/accounts-tree`)
|
||||
.then(accounts => {
|
||||
const map: Record<number, string> = {}
|
||||
for (const a of accounts) map[a.id] = a.name
|
||||
setAccountNames(map)
|
||||
})
|
||||
.catch(() => {})
|
||||
}, [activeOrg])
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeOrg) return
|
||||
@@ -111,14 +125,17 @@ export default function GeneralJournalTab() {
|
||||
<TableBody>
|
||||
{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',
|
||||
}}
|
||||
>
|
||||
<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={() => setSelectedTxId(tx.transactionId)}
|
||||
>
|
||||
<TableCell sx={{ fontWeight: 700, fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{tx.sequenceId || tx.transactionId}
|
||||
</TableCell>
|
||||
@@ -201,6 +218,17 @@ export default function GeneralJournalTab() {
|
||||
<Typography color="text.secondary">No transactions for this period.</Typography>
|
||||
</Paper>
|
||||
) : null}
|
||||
|
||||
{activeOrg && (
|
||||
<TransactionDetailDialog
|
||||
open={selectedTxId !== null}
|
||||
onClose={() => setSelectedTxId(null)}
|
||||
transactionId={selectedTxId}
|
||||
orgId={activeOrg.organizationId}
|
||||
accountNames={accountNames}
|
||||
currencyCode={activeOrg.currencyCode}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user