"use client"; import { useState } from "react"; import { AlertTriangle, MapPin, MapPinned } from "lucide-react"; import { SiteIncomeView } from "@/components/SiteIncomeView"; import { SitesView } from "@/components/SitesView"; import type { SiteIncomeRow } from "@/lib/site-income"; import type { SiteSummary } from "@/lib/sites"; import { ZAR2 } from "@/lib/utils"; export function SitesOverview({ postedRows, billedRows, year, invoiceCount, monthIndex }: { postedRows: SiteIncomeRow[]; billedRows: SiteSummary[]; year: number; invoiceCount: number; monthIndex: number; }) { const [view, setView] = useState<"posted" | "billed">("posted"); const totalIncl = billedRows.reduce((sum, row) => sum + row.revenueIncl, 0); const totalExcl = billedRows.reduce((sum, row) => sum + row.revenueExcl, 0); const totalVat = billedRows.reduce((sum, row) => sum + row.vat, 0); const outstanding = billedRows.reduce((sum, row) => sum + row.unbookedCount, 0); const unpinned = billedRows.filter((row) => !row.pinned).length; return ( <>

Sites

{([ ["posted", "Posted income"], ["billed", "Billed invoices"], ] as const).map(([value, label]) => ( ))}
{view === "posted" ? (

Posted income · {year}

Income attributed to the historical site on each invoice. External income and unallocated workbook income remain included.

} /> ) : ( <>

Internal billed invoices · {year}

What each site was billed per month from {invoiceCount} imported internal invoice{invoiceCount === 1 ? "" : "s"}.

Billing includes unbooked lines. External billing is outside this view.

Billed (ex VAT)
{ZAR2(totalExcl)}
+ {ZAR2(totalVat)} VAT
Billed (incl VAT)
{ZAR2(totalIncl)}
{unpinned > 0 && (
)} {outstanding > 0 && (
)} {billedRows.length ? : (

No internal site billing recorded for {year}.

Sites appear here as internal invoices are imported.

)} )}
); }