diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index f3993035..adaaa9b7 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -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 } diff --git a/frontend/src/components/TransactionDetailDialog.tsx b/frontend/src/components/TransactionDetailDialog.tsx new file mode 100644 index 00000000..e573b174 --- /dev/null +++ b/frontend/src/components/TransactionDetailDialog.tsx @@ -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 = { + 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 + currencyCode?: string +} + +export default function TransactionDetailDialog({ + open, onClose, transactionId, orgId, accountNames, currencyCode, +}: Props) { + const [tx, setTx] = useState(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 ( + + + {loading ? ( + + ) : tx ? ( + + + Transaction #{tx.organizationSequenceId} + + {isBalanced ? ( + + ) : ( + + )} + + ) : ( + 'Transaction' + )} + + + + {loading ? ( + + ) : tx ? ( + <> + {/* Header info */} + + + Date + + {new Date(tx.dateTime).toLocaleDateString('sv-SE')} + {' '} + {new Date(tx.dateTime).toLocaleTimeString('sv-SE', { hour: '2-digit', minute: '2-digit' })} + + + + Description + + {tx.comment} + + + {currencyCode && ( + + Currency + {currencyCode} + + )} + + + {/* Dependency */} + {tx.dependency && ( + + + + Linked to: + + + + )} + + {/* Blockchain hash */} + {tx.blockchainHash && ( + + Blockchain: + + {tx.blockchainHash} + + + )} + + {/* Documentation indicator */} + {tx.hasDocumentation && ( + + + + This transaction has attached documentation + + + )} + + + + {/* Transaction rows */} + + + + + Account + Debit + Credit + {tx.rows.some(r => r.foreignCurrencyCode) && ( + Foreign + )} + + + + {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 ( + + + {accountNames[row.financialAccountId] || `Account #${row.financialAccountId}`} + + 0 ? 'text.primary' : 'text.disabled', + }}> + {debit > 0 ? formatCents(debit) : ''} + + 0 ? 'error.main' : 'text.disabled', + }}> + {credit > 0 ? formatCents(credit) : ''} + + {hasForeign && ( + + {row.foreignCurrencyCode && ( + `${row.foreignCurrencyCode} ${formatCents(Math.abs(row.foreignCurrencyAmountCents))}` + )} + + )} + + ) + })} + + {/* Totals */} + + Total + + {formatCents(totalDebit)} + + + {formatCents(totalCredit)} + + {tx.rows.some(r => r.foreignCurrencyCode) && } + + +
+
+ + ) : ( + Transaction not found. + )} +
+ + + + +
+ ) +} diff --git a/frontend/src/pages/inspect/AccountLedgerTab.tsx b/frontend/src/pages/inspect/AccountLedgerTab.tsx index 16f882d6..4361cc9d 100644 --- a/frontend/src/pages/inspect/AccountLedgerTab.tsx +++ b/frontend/src/pages/inspect/AccountLedgerTab.tsx @@ -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(null) const [loading, setLoading] = useState(false) const [ownOnly, setOwnOnly] = useState(false) + const [selectedTxId, setSelectedTxId] = useState(null) + const [accountNames, setAccountNames] = useState>({}) + + useEffect(() => { + if (!activeOrg) return + api.get<{ id: number; name: string }[]>(`/organizations/${activeOrg.organizationId}/inspect/accounts-tree`) + .then(accts => { + const map: Record = {} + 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 => ( - + setSelectedTxId(entry.transactionId)} + > {entry.sequenceId || entry.transactionId} @@ -323,6 +340,17 @@ export default function AccountLedgerTab() { ) : null} )} + + {activeOrg && ( + setSelectedTxId(null)} + transactionId={selectedTxId} + orgId={activeOrg.organizationId} + accountNames={accountNames} + currencyCode={activeOrg.currencyCode} + /> + )} ) } diff --git a/frontend/src/pages/inspect/GeneralJournalTab.tsx b/frontend/src/pages/inspect/GeneralJournalTab.tsx index 14f3b479..1c0a10f2 100644 --- a/frontend/src/pages/inspect/GeneralJournalTab.tsx +++ b/frontend/src/pages/inspect/GeneralJournalTab.tsx @@ -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(null) const [loading, setLoading] = useState(false) + const [selectedTxId, setSelectedTxId] = useState(null) + const [accountNames, setAccountNames] = useState>({}) + + useEffect(() => { + if (!activeOrg) return + api.get<{ id: number; name: string }[]>(`/organizations/${activeOrg.organizationId}/inspect/accounts-tree`) + .then(accounts => { + const map: Record = {} + 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() { {data.transactions.map(tx => [ // Transaction header row - + setSelectedTxId(tx.transactionId)} + > {tx.sequenceId || tx.transactionId} @@ -201,6 +218,17 @@ export default function GeneralJournalTab() { No transactions for this period. ) : null} + + {activeOrg && ( + setSelectedTxId(null)} + transactionId={selectedTxId} + orgId={activeOrg.organizationId} + accountNames={accountNames} + currencyCode={activeOrg.currencyCode} + /> + )} ) }