Add Reporting Suite: Trial Balance, P&L, Balance Sheet, Aged AR/AP
Each report is served off the existing posted-ledger data (no schema changes) and respects the existing Main/branch scope selector, same as every other module. Balance Sheet computes a live "Current Year Earnings" equity line from unclosed P&L, since there's no year-end close step yet. Backed by a new integration test suite that verifies the trial balance and balance sheet stay in balance under real posted AR/AP activity, that P&L correctly scopes income to its period, and that aging buckets customers/suppliers by days overdue. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JWqiUSojMLUoN7mrJqdEbN
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
b137176c40
commit
eb42eb8fc8
@@ -0,0 +1,46 @@
|
||||
import { apiClient } from './client';
|
||||
import type { AgedReport, BalanceSheetReport, ProfitAndLossReport, TrialBalanceReport } from '../types/api';
|
||||
import type { BranchSelection } from '../store/branchStore';
|
||||
|
||||
function branchParam(branchScope: BranchSelection): string {
|
||||
return branchScope === 'MAIN' ? 'MAIN' : String(branchScope);
|
||||
}
|
||||
|
||||
export async function fetchTrialBalance(branchScope: BranchSelection, asOfDate?: string): Promise<TrialBalanceReport> {
|
||||
const response = await apiClient.get<TrialBalanceReport>('/reports/trial-balance', {
|
||||
params: { branchScope: branchParam(branchScope), asOfDate },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function fetchProfitAndLoss(
|
||||
branchScope: BranchSelection,
|
||||
fromDate?: string,
|
||||
toDate?: string,
|
||||
): Promise<ProfitAndLossReport> {
|
||||
const response = await apiClient.get<ProfitAndLossReport>('/reports/profit-and-loss', {
|
||||
params: { branchScope: branchParam(branchScope), fromDate, toDate },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function fetchBalanceSheet(branchScope: BranchSelection, asOfDate?: string): Promise<BalanceSheetReport> {
|
||||
const response = await apiClient.get<BalanceSheetReport>('/reports/balance-sheet', {
|
||||
params: { branchScope: branchParam(branchScope), asOfDate },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function fetchAgedReceivables(branchScope: BranchSelection, asOfDate?: string): Promise<AgedReport> {
|
||||
const response = await apiClient.get<AgedReport>('/reports/aged-receivables', {
|
||||
params: { branchScope: branchParam(branchScope), asOfDate },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function fetchAgedPayables(branchScope: BranchSelection, asOfDate?: string): Promise<AgedReport> {
|
||||
const response = await apiClient.get<AgedReport>('/reports/aged-payables', {
|
||||
params: { branchScope: branchParam(branchScope), asOfDate },
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, Card, TextField, Typography } from '@mui/material';
|
||||
import { useAgedPayables } from '../../hooks/useReports';
|
||||
import { useBranchStore } from '../../store/branchStore';
|
||||
import { AgedReportTable } from './AgedReportTable';
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function AgedPayablesPage() {
|
||||
const selected = useBranchStore((state) => state.selected);
|
||||
const [asOfDate, setAsOfDate] = useState(today());
|
||||
const { data, isLoading } = useAgedPayables(selected, asOfDate);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5" sx={{ mb: 0.5 }}>
|
||||
Aged Payables
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Outstanding supplier balances by age bucket, as at the selected date.
|
||||
</Typography>
|
||||
|
||||
<Card sx={{ p: 2, mb: 2 }}>
|
||||
<TextField
|
||||
label="As at"
|
||||
type="date"
|
||||
size="small"
|
||||
value={asOfDate}
|
||||
onChange={(e) => setAsOfDate(e.target.value)}
|
||||
slotProps={{ inputLabel: { shrink: true } }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<AgedReportTable data={data} isLoading={isLoading} linkBase="/ap/suppliers" />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, Card, TextField, Typography } from '@mui/material';
|
||||
import { useAgedReceivables } from '../../hooks/useReports';
|
||||
import { useBranchStore } from '../../store/branchStore';
|
||||
import { AgedReportTable } from './AgedReportTable';
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function AgedReceivablesPage() {
|
||||
const selected = useBranchStore((state) => state.selected);
|
||||
const [asOfDate, setAsOfDate] = useState(today());
|
||||
const { data, isLoading } = useAgedReceivables(selected, asOfDate);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5" sx={{ mb: 0.5 }}>
|
||||
Aged Receivables
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Outstanding customer balances by age bucket, as at the selected date.
|
||||
</Typography>
|
||||
|
||||
<Card sx={{ p: 2, mb: 2 }}>
|
||||
<TextField
|
||||
label="As at"
|
||||
type="date"
|
||||
size="small"
|
||||
value={asOfDate}
|
||||
onChange={(e) => setAsOfDate(e.target.value)}
|
||||
slotProps={{ inputLabel: { shrink: true } }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<AgedReportTable data={data} isLoading={isLoading} linkBase="/ar/customers" />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import { Box, Card, CircularProgress, Link as MuiLink, Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material';
|
||||
import { Link as RouterLink } from 'react-router-dom';
|
||||
import { MoneyCell } from '../../components/common/MoneyCell';
|
||||
import type { AgedReport } from '../../types/api';
|
||||
|
||||
export function AgedReportTable({
|
||||
data,
|
||||
isLoading,
|
||||
linkBase,
|
||||
}: {
|
||||
data: AgedReport | undefined;
|
||||
isLoading: boolean;
|
||||
linkBase: string;
|
||||
}) {
|
||||
return (
|
||||
<Card>
|
||||
{isLoading ? (
|
||||
<Box sx={{ p: 4, display: 'flex', justifyContent: 'center' }}>
|
||||
<CircularProgress size={24} />
|
||||
</Box>
|
||||
) : (
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Account</TableCell>
|
||||
<TableCell align="right">Current</TableCell>
|
||||
<TableCell align="right">1–30 days</TableCell>
|
||||
<TableCell align="right">31–60 days</TableCell>
|
||||
<TableCell align="right">61–90 days</TableCell>
|
||||
<TableCell align="right">90+ days</TableCell>
|
||||
<TableCell align="right">Total</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data?.rows.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7}>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
No outstanding balances as at this date.
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{data?.rows.map((row) => (
|
||||
<TableRow key={row.partyId}>
|
||||
<TableCell>
|
||||
<MuiLink component={RouterLink} to={`${linkBase}/${row.partyId}`} underline="hover">
|
||||
{row.code} — {row.name}
|
||||
</MuiLink>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.current} />
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.d1to30} />
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.d31to60} />
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.d61to90} />
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.d90plus} />
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={row.total} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{data && (
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<strong>Total</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totals.current} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totals.d1to30} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totals.d31to60} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totals.d61to90} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totals.d90plus} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totals.total} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
Chip,
|
||||
CircularProgress,
|
||||
Stack,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TextField,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import { useBalanceSheet } from '../../hooks/useReports';
|
||||
import { useBranchStore } from '../../store/branchStore';
|
||||
import { MoneyCell } from '../../components/common/MoneyCell';
|
||||
import type { BalanceSheetLineItem } from '../../types/api';
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function Section({ title, rows, total }: { title: string; rows: BalanceSheetLineItem[]; total: number }) {
|
||||
return (
|
||||
<>
|
||||
<TableRow>
|
||||
<TableCell colSpan={3}>
|
||||
<Typography variant="overline" color="text.secondary">
|
||||
{title}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{rows.map((row) => (
|
||||
<TableRow key={row.accountId ?? row.accountName}>
|
||||
<TableCell sx={{ fontFamily: 'monospace' }}>{row.accountCode ?? ''}</TableCell>
|
||||
<TableCell>{row.accountName}</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.amount} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
<TableRow>
|
||||
<TableCell colSpan={2}>
|
||||
<strong>Total {title}</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={total} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function BalanceSheetPage() {
|
||||
const selected = useBranchStore((state) => state.selected);
|
||||
const [asOfDate, setAsOfDate] = useState(today());
|
||||
const { data, isLoading } = useBalanceSheet(selected, asOfDate);
|
||||
|
||||
const balanced = data ? Math.abs(data.balanceCheck) < 0.01 : false;
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack direction="row" sx={{ alignItems: 'center', justifyContent: 'space-between', mb: 0.5 }}>
|
||||
<Typography variant="h5">Balance Sheet</Typography>
|
||||
{data && <Chip label={balanced ? 'Balanced' : 'Out of balance'} color={balanced ? 'success' : 'error'} size="small" />}
|
||||
</Stack>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Assets, liabilities, and equity as at the selected date. Equity includes current-year
|
||||
earnings computed live from unclosed income and expense — this app has no year-end
|
||||
close step, so the P&L feeds straight into equity here.
|
||||
</Typography>
|
||||
|
||||
<Card sx={{ p: 2, mb: 2 }}>
|
||||
<TextField
|
||||
label="As at"
|
||||
type="date"
|
||||
size="small"
|
||||
value={asOfDate}
|
||||
onChange={(e) => setAsOfDate(e.target.value)}
|
||||
slotProps={{ inputLabel: { shrink: true } }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
{isLoading ? (
|
||||
<Box sx={{ p: 4, display: 'flex', justifyContent: 'center' }}>
|
||||
<CircularProgress size={24} />
|
||||
</Box>
|
||||
) : (
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Code</TableCell>
|
||||
<TableCell>Account</TableCell>
|
||||
<TableCell align="right">Amount</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data && <Section title="Assets" rows={data.assets} total={data.totalAssets} />}
|
||||
{data && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} sx={{ pt: 3 }} />
|
||||
</TableRow>
|
||||
)}
|
||||
{data && <Section title="Liabilities" rows={data.liabilities} total={data.totalLiabilities} />}
|
||||
{data && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} sx={{ pt: 3 }} />
|
||||
</TableRow>
|
||||
)}
|
||||
{data && <Section title="Equity" rows={data.equity} total={data.totalEquity} />}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, Card, CircularProgress, Stack, Table, TableBody, TableCell, TableHead, TableRow, TextField, Typography } from '@mui/material';
|
||||
import { useProfitAndLoss } from '../../hooks/useReports';
|
||||
import { useBranchStore } from '../../store/branchStore';
|
||||
import { MoneyCell } from '../../components/common/MoneyCell';
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function startOfYear(): string {
|
||||
return `${new Date().getFullYear()}-01-01`;
|
||||
}
|
||||
|
||||
export function ProfitAndLossPage() {
|
||||
const selected = useBranchStore((state) => state.selected);
|
||||
const [fromDate, setFromDate] = useState(startOfYear());
|
||||
const [toDate, setToDate] = useState(today());
|
||||
const { data, isLoading } = useProfitAndLoss(selected, fromDate, toDate);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5" sx={{ mb: 0.5 }}>
|
||||
Profit & Loss Statement
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Income and expense performance for the selected period.
|
||||
</Typography>
|
||||
|
||||
<Card sx={{ p: 2, mb: 2 }}>
|
||||
<Stack direction="row" spacing={2}>
|
||||
<TextField
|
||||
label="From"
|
||||
type="date"
|
||||
size="small"
|
||||
value={fromDate}
|
||||
onChange={(e) => setFromDate(e.target.value)}
|
||||
slotProps={{ inputLabel: { shrink: true } }}
|
||||
/>
|
||||
<TextField
|
||||
label="To"
|
||||
type="date"
|
||||
size="small"
|
||||
value={toDate}
|
||||
onChange={(e) => setToDate(e.target.value)}
|
||||
slotProps={{ inputLabel: { shrink: true } }}
|
||||
/>
|
||||
</Stack>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
{isLoading ? (
|
||||
<Box sx={{ p: 4, display: 'flex', justifyContent: 'center' }}>
|
||||
<CircularProgress size={24} />
|
||||
</Box>
|
||||
) : (
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Code</TableCell>
|
||||
<TableCell>Account</TableCell>
|
||||
<TableCell align="right">Amount</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
<TableRow>
|
||||
<TableCell colSpan={3}>
|
||||
<Typography variant="overline" color="text.secondary">
|
||||
Income
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{data?.income.map((row) => (
|
||||
<TableRow key={row.accountId}>
|
||||
<TableCell sx={{ fontFamily: 'monospace' }}>{row.accountCode}</TableCell>
|
||||
<TableCell>{row.accountName}</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.amount} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
<TableRow>
|
||||
<TableCell colSpan={2}>
|
||||
<strong>Total Income</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data?.totalIncome} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} sx={{ pt: 3 }}>
|
||||
<Typography variant="overline" color="text.secondary">
|
||||
Expense
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{data?.expense.map((row) => (
|
||||
<TableRow key={row.accountId}>
|
||||
<TableCell sx={{ fontFamily: 'monospace' }}>{row.accountCode}</TableCell>
|
||||
<TableCell>{row.accountName}</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.amount} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
<TableRow>
|
||||
<TableCell colSpan={2}>
|
||||
<strong>Total Expense</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data?.totalExpense} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
{data && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={2}>
|
||||
<Typography sx={{ fontWeight: 700 }}>Net Profit</Typography>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<Typography sx={{ fontWeight: 700, color: data.netProfit >= 0 ? 'success.main' : 'error.main' }}>
|
||||
{data.netProfit.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -1,32 +1,38 @@
|
||||
import { Box, Card, Chip, Stack, Typography } from '@mui/material';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import DescriptionOutlinedIcon from '@mui/icons-material/DescriptionOutlined';
|
||||
|
||||
interface ReportDef {
|
||||
name: string;
|
||||
description: string;
|
||||
path?: string;
|
||||
}
|
||||
|
||||
const CATEGORIES: { title: string; reports: ReportDef[] }[] = [
|
||||
{
|
||||
title: 'Financial',
|
||||
reports: [
|
||||
{ name: 'Trial Balance', description: 'Debit and credit balances for every account, Main or per-branch.' },
|
||||
{ name: 'Profit & Loss Statement', description: 'Income and expense performance for a selected period.' },
|
||||
{ name: 'Balance Sheet', description: 'Assets, liabilities, and equity as at a selected date.' },
|
||||
{ name: 'General Ledger', description: 'Full transaction detail for any account and date range.' },
|
||||
{ name: 'Trial Balance', description: 'Debit and credit balances for every account, Main or per-branch.', path: '/reports/trial-balance' },
|
||||
{
|
||||
name: 'Profit & Loss Statement',
|
||||
description: 'Income and expense performance for a selected period.',
|
||||
path: '/reports/profit-and-loss',
|
||||
},
|
||||
{ name: 'Balance Sheet', description: 'Assets, liabilities, and equity as at a selected date.', path: '/reports/balance-sheet' },
|
||||
{ name: 'General Ledger', description: 'Full transaction detail for any account and date range.', path: '/gl/journal-entries' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Receivables',
|
||||
reports: [
|
||||
{ name: 'Aged Receivables', description: 'Outstanding customer balances by age bucket.' },
|
||||
{ name: 'Aged Receivables', description: 'Outstanding customer balances by age bucket.', path: '/reports/aged-receivables' },
|
||||
{ name: 'Customer Statement', description: 'Transaction history and running balance per customer.' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Payables',
|
||||
reports: [
|
||||
{ name: 'Aged Payables', description: 'Outstanding supplier balances by age bucket.' },
|
||||
{ name: 'Aged Payables', description: 'Outstanding supplier balances by age bucket.', path: '/reports/aged-payables' },
|
||||
{ name: 'Payment Run', description: 'Supplier invoices selected for the next payment batch.' },
|
||||
],
|
||||
},
|
||||
@@ -35,12 +41,13 @@ const CATEGORIES: { title: string; reports: ReportDef[] }[] = [
|
||||
reports: [
|
||||
{ name: 'Budget vs Actual', description: 'Budgeted figures compared against actual GL movement.' },
|
||||
{ name: 'Branch Performance', description: 'Key metrics compared across branches.' },
|
||||
{ name: 'Stock Valuation', description: 'On-hand stock quantities and value by warehouse.' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export function ReportsPage() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5" sx={{ mb: 0.5 }}>
|
||||
@@ -60,11 +67,13 @@ export function ReportsPage() {
|
||||
{category.reports.map((report) => (
|
||||
<Card
|
||||
key={report.name}
|
||||
onClick={() => report.path && navigate(report.path)}
|
||||
sx={{
|
||||
p: 2,
|
||||
width: 280,
|
||||
opacity: 0.6,
|
||||
cursor: 'not-allowed',
|
||||
opacity: report.path ? 1 : 0.6,
|
||||
cursor: report.path ? 'pointer' : 'not-allowed',
|
||||
'&:hover': report.path ? { borderColor: 'primary.main' } : undefined,
|
||||
}}
|
||||
>
|
||||
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'flex-start', mb: 1 }}>
|
||||
@@ -76,7 +85,7 @@ export function ReportsPage() {
|
||||
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1.5 }}>
|
||||
{report.description}
|
||||
</Typography>
|
||||
<Chip label="Coming soon" size="small" />
|
||||
{!report.path && <Chip label="Coming soon" size="small" />}
|
||||
</Card>
|
||||
))}
|
||||
</Stack>
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
Chip,
|
||||
CircularProgress,
|
||||
Stack,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TextField,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import { useTrialBalance } from '../../hooks/useReports';
|
||||
import { useBranchStore } from '../../store/branchStore';
|
||||
import { MoneyCell } from '../../components/common/MoneyCell';
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function TrialBalancePage() {
|
||||
const selected = useBranchStore((state) => state.selected);
|
||||
const [asOfDate, setAsOfDate] = useState(today());
|
||||
const { data, isLoading } = useTrialBalance(selected, asOfDate);
|
||||
|
||||
const balanced = data ? data.totalDebit === data.totalCredit : false;
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack direction="row" sx={{ alignItems: 'center', justifyContent: 'space-between', mb: 0.5 }}>
|
||||
<Typography variant="h5">Trial Balance</Typography>
|
||||
{data && <Chip label={balanced ? 'Balanced' : 'Out of balance'} color={balanced ? 'success' : 'error'} size="small" />}
|
||||
</Stack>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Debit and credit balances for every account with posted activity, as at the selected date.
|
||||
</Typography>
|
||||
|
||||
<Card sx={{ p: 2, mb: 2 }}>
|
||||
<TextField
|
||||
label="As at"
|
||||
type="date"
|
||||
size="small"
|
||||
value={asOfDate}
|
||||
onChange={(e) => setAsOfDate(e.target.value)}
|
||||
slotProps={{ inputLabel: { shrink: true } }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
{isLoading ? (
|
||||
<Box sx={{ p: 4, display: 'flex', justifyContent: 'center' }}>
|
||||
<CircularProgress size={24} />
|
||||
</Box>
|
||||
) : (
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Code</TableCell>
|
||||
<TableCell>Account</TableCell>
|
||||
<TableCell align="right">Debit</TableCell>
|
||||
<TableCell align="right">Credit</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data?.rows.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4}>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
No posted activity as at this date.
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{data?.rows.map((row) => (
|
||||
<TableRow key={row.accountId}>
|
||||
<TableCell sx={{ fontFamily: 'monospace' }}>{row.accountCode}</TableCell>
|
||||
<TableCell>{row.accountName}</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.debit} />
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<MoneyCell value={row.credit} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{data && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={2}>
|
||||
<strong>Total</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totalDebit} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<strong>
|
||||
<MoneyCell value={data.totalCredit} />
|
||||
</strong>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
fetchAgedPayables,
|
||||
fetchAgedReceivables,
|
||||
fetchBalanceSheet,
|
||||
fetchProfitAndLoss,
|
||||
fetchTrialBalance,
|
||||
} from '../api/reports.api';
|
||||
import type { BranchSelection } from '../store/branchStore';
|
||||
|
||||
export function useTrialBalance(branchScope: BranchSelection, asOfDate: string) {
|
||||
return useQuery({
|
||||
queryKey: ['reports', 'trial-balance', branchScope, asOfDate],
|
||||
queryFn: () => fetchTrialBalance(branchScope, asOfDate),
|
||||
});
|
||||
}
|
||||
|
||||
export function useProfitAndLoss(branchScope: BranchSelection, fromDate: string, toDate: string) {
|
||||
return useQuery({
|
||||
queryKey: ['reports', 'profit-and-loss', branchScope, fromDate, toDate],
|
||||
queryFn: () => fetchProfitAndLoss(branchScope, fromDate, toDate),
|
||||
});
|
||||
}
|
||||
|
||||
export function useBalanceSheet(branchScope: BranchSelection, asOfDate: string) {
|
||||
return useQuery({
|
||||
queryKey: ['reports', 'balance-sheet', branchScope, asOfDate],
|
||||
queryFn: () => fetchBalanceSheet(branchScope, asOfDate),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAgedReceivables(branchScope: BranchSelection, asOfDate: string) {
|
||||
return useQuery({
|
||||
queryKey: ['reports', 'aged-receivables', branchScope, asOfDate],
|
||||
queryFn: () => fetchAgedReceivables(branchScope, asOfDate),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAgedPayables(branchScope: BranchSelection, asOfDate: string) {
|
||||
return useQuery({
|
||||
queryKey: ['reports', 'aged-payables', branchScope, asOfDate],
|
||||
queryFn: () => fetchAgedPayables(branchScope, asOfDate),
|
||||
});
|
||||
}
|
||||
@@ -35,6 +35,11 @@ import { PaymentFormPage } from '../features/ap/payments/PaymentFormPage';
|
||||
import { PaymentDetailPage } from '../features/ap/payments/PaymentDetailPage';
|
||||
import { AdminWarehousesPage } from '../features/admin/warehouses/AdminWarehousesPage';
|
||||
import { StockItemsListPage } from '../features/stock/items/StockItemsListPage';
|
||||
import { TrialBalancePage } from '../features/reports/TrialBalancePage';
|
||||
import { ProfitAndLossPage } from '../features/reports/ProfitAndLossPage';
|
||||
import { BalanceSheetPage } from '../features/reports/BalanceSheetPage';
|
||||
import { AgedReceivablesPage } from '../features/reports/AgedReceivablesPage';
|
||||
import { AgedPayablesPage } from '../features/reports/AgedPayablesPage';
|
||||
|
||||
export function AppRouter() {
|
||||
return (
|
||||
@@ -45,6 +50,11 @@ export function AppRouter() {
|
||||
<Route element={<MainLayout />}>
|
||||
<Route path="/" element={<DashboardPage />} />
|
||||
<Route path="/reports" element={<ReportsPage />} />
|
||||
<Route path="/reports/trial-balance" element={<TrialBalancePage />} />
|
||||
<Route path="/reports/profit-and-loss" element={<ProfitAndLossPage />} />
|
||||
<Route path="/reports/balance-sheet" element={<BalanceSheetPage />} />
|
||||
<Route path="/reports/aged-receivables" element={<AgedReceivablesPage />} />
|
||||
<Route path="/reports/aged-payables" element={<AgedPayablesPage />} />
|
||||
|
||||
<Route path="/gl/journal-entries" element={<JournalEntryListPage />} />
|
||||
<Route path="/gl/journal-entries/:id" element={<JournalEntryDetailPage />} />
|
||||
|
||||
@@ -408,3 +408,76 @@ export interface StockItem {
|
||||
stockLevels?: StockLevel[];
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Reports
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export interface TrialBalanceRow {
|
||||
accountId: number;
|
||||
accountCode: string;
|
||||
accountName: string;
|
||||
accountType: GLAccountType;
|
||||
debit: number;
|
||||
credit: number;
|
||||
}
|
||||
|
||||
export interface TrialBalanceReport {
|
||||
asOfDate: string;
|
||||
rows: TrialBalanceRow[];
|
||||
totalDebit: number;
|
||||
totalCredit: number;
|
||||
}
|
||||
|
||||
export interface PLLineItem {
|
||||
accountId: number;
|
||||
accountCode: string;
|
||||
accountName: string;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export interface ProfitAndLossReport {
|
||||
fromDate: string;
|
||||
toDate: string;
|
||||
income: PLLineItem[];
|
||||
expense: PLLineItem[];
|
||||
totalIncome: number;
|
||||
totalExpense: number;
|
||||
netProfit: number;
|
||||
}
|
||||
|
||||
export interface BalanceSheetLineItem {
|
||||
accountId: number | null;
|
||||
accountCode: string | null;
|
||||
accountName: string;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export interface BalanceSheetReport {
|
||||
asOfDate: string;
|
||||
assets: BalanceSheetLineItem[];
|
||||
liabilities: BalanceSheetLineItem[];
|
||||
equity: BalanceSheetLineItem[];
|
||||
totalAssets: number;
|
||||
totalLiabilities: number;
|
||||
totalEquity: number;
|
||||
balanceCheck: number;
|
||||
}
|
||||
|
||||
export interface AgedBucketRow {
|
||||
partyId: number;
|
||||
code: string;
|
||||
name: string;
|
||||
current: number;
|
||||
d1to30: number;
|
||||
d31to60: number;
|
||||
d61to90: number;
|
||||
d90plus: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface AgedReport {
|
||||
asOfDate: string;
|
||||
rows: AgedBucketRow[];
|
||||
totals: Omit<AgedBucketRow, 'partyId' | 'code' | 'name'>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user