diff --git a/src/app/admin/analytics/page.tsx b/src/app/admin/analytics/page.tsx index 5d894f9..28ae351 100644 --- a/src/app/admin/analytics/page.tsx +++ b/src/app/admin/analytics/page.tsx @@ -1,20 +1,30 @@ -import { getAnalyticsByYear, getMonthlyCollected, getAvailableYears } from "@/lib/analytics-queries"; +import { + getAnalyticsByYear, + getMonthlyCollected, + getAvailableYears, + getTimeByClient, + getTotalTrackedHours, +} from "@/lib/analytics-queries"; import { YearSelector, MonthlyChart } from "@/components/admin/YearSelector"; export const revalidate = 0; -function fmt(n: number) { +function fmtEur(n: number) { return n.toLocaleString("it-IT", { style: "currency", currency: "EUR", minimumFractionDigits: 2 }); } -interface MetricCardProps { - label: string; - value: string; - sub?: string; - accent?: boolean; +function fmtSeconds(s: number): string { + const h = Math.floor(s / 3600); + const m = Math.floor((s % 3600) / 60); + if (h > 0) return `${h}h ${m}m`; + return `${m}m`; } -function MetricCard({ label, value, sub, accent }: MetricCardProps) { +function MetricCard({ + label, value, sub, accent, +}: { + label: string; value: string; sub?: string; accent?: boolean; +}) { return (
@@ -38,60 +48,116 @@ export default async function AnalyticsPage({ const { year: yearParam } = await searchParams; const year = parseInt(yearParam ?? "") || new Date().getFullYear(); - const [data, monthly, availableYears] = await Promise.all([ + const [data, monthly, availableYears, timeByClient, totalHours] = await Promise.all([ getAnalyticsByYear(year), getMonthlyCollected(year), getAvailableYears(), + getTimeByClient(year), + getTotalTrackedHours(year), ]); - const collectedPct = data.contracted > 0 - ? Math.round((data.collected / data.contracted) * 100) - : 0; + const collectedPct = + data.contracted > 0 ? Math.round((data.collected / data.contracted) * 100) : 0; + + const maxClientSeconds = timeByClient[0]?.totalSeconds ?? 1; return ( -
Panoramica finanziaria per anno
+Panoramica per anno
+ Nessun cliente registrato nel {year}. +
+ )}- Nessun cliente registrato nel {year}. -
- )} ++ Nessuna sessione registrata nel {year}. + Usa il timer ▶ nella lista clienti per iniziare. +
+{client.brand_name}
+{client.brand_name}
+ {client.archived && ( + + Archiviato + + )} +Nessun cliente ancora.
-- - Crea il primo cliente - -
+{showArchived ? "Nessun cliente archiviato." : "Nessun cliente ancora."}
+ {!showArchived && ( ++ + Crea il primo cliente + +
+ )}| - Cliente - | -- Totale - | -- Acconto - | -- Saldo - | -- Link - | +Cliente | +Totale | +Acconto | +Saldo | +Timer | +Link |
|---|---|---|---|---|---|---|---|---|---|---|
|
{client.name}
- {client.brand_name} +{client.brand_name} + {client.archived && ( + + Archiviato + + )} |
- - €{" "} - {parseFloat(client.accepted_total).toLocaleString("it-IT", { - minimumFractionDigits: 2, - })} + | + €{parseFloat(client.accepted_total).toLocaleString("it-IT", { minimumFractionDigits: 2 })} |
{acconto && (
- |
{saldo && (
- |
+
+ |
- /c/{client.token.slice(0, 10)}… + /c/{client.token.slice(0, 8)}… |