import { getOverheadsBySection } from "@/lib/data"; import { ZAR } from "@/lib/utils"; import { ArrowLeft } from "lucide-react"; import Link from "next/link"; import { ReactNode } from "react"; type Props = { section: string; title: string; subtitle: string; icon: ReactNode; gradient: string; iconBg: string; iconColor: string; }; export async function ExpenseSectionPage({ section, title, subtitle, icon, gradient, iconBg, iconColor, }: Props) { const items = await getOverheadsBySection(section); const totalIncl = items.reduce((s, o) => s + (o.amount_incl || 0), 0); const totalExcl = items.reduce((s, o) => s + (o.amount_excl || 0), 0); const totalVat = items.reduce((s, o) => s + (o.vat || 0), 0); const byGl = new Map(); for (const o of items) { const g = o.gl_account || "—"; if (!byGl.has(g)) byGl.set(g, []); byGl.get(g)!.push(o); } const glBreakdown = Array.from(byGl.entries()) .map(([gl, list]) => ({ gl, total: list.reduce((s, o) => s + (o.amount_incl || 0), 0), count: list.length, })) .sort((a, b) => b.total - a.total); return (
Back to Expenses
{icon}

{title}

{subtitle}

Monthly total (incl VAT)
{ZAR(totalIncl)}
{glBreakdown.length > 1 && (

By GL account

{glBreakdown.map((g) => { const pct = totalIncl ? (g.total / totalIncl) * 100 : 0; return (
{g.gl} {ZAR(g.total)} · {g.count} item{g.count !== 1 && "s"} · {pct.toFixed(0)}%
); })}
)} {/* Part B.1: empty state must say so plainly, not render a table of zeros */} {items.length === 0 ? (
No {section} entries in PocketBase.
This category either doesn't apply yet or lives elsewhere — see round-3 brief.
) : (

Line items

{items.length} entries
{items.map((o) => ( ))}
Description GL Account Supplier Excl VAT VAT Incl VAT
{o.description} {o.gl_account ? ( {o.gl_account} ) : ( — )} {o.supplier || "—"} {o.amount_excl ? ZAR(o.amount_excl) : "—"} {o.vat ? ZAR(o.vat) : "—"} {o.amount_incl ? ZAR(o.amount_incl) : "—"}
Total {ZAR(totalExcl)} {ZAR(totalVat)} {ZAR(totalIncl)}
)}
); } function StatCard({ label, value, color }: { label: string; value: string; color: string }) { return (
{label}
{value}
); }