feat: implement dashboard page displaying KPIs, site statistics, top items, and monthly evolution using a new PostgreSQL client.

This commit is contained in:
Michael committed 2026-03-21 00:22:14 +01:00
1 parent 7cb96966aa
commit 966b13cdf0
2 files changed
+12 -7

No files matched your search

+3 -1
View File
@@ -300,10 +300,12 @@ export default async function DashboardPage() {
try {
data = await pgGetDashboardData();
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
console.error("[Dashboard] pgGetDashboardData failed:", e);
return (
<div className="p-8 text-center">
<p className="text-sm" style={{ color: "var(--text-muted)" }}>
Impossible de charger le tableau de bord : {(e as Error).message?.slice(0, 200)}
Impossible de charger le tableau de bord : {msg.slice(0, 500)}
</p>
</div>
);
+9 -6
View File
@@ -532,7 +532,10 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
AND s.site IN ('292', '579')
GROUP BY s.site
ORDER BY s.site
`),
`).catch((err) => {
console.error("[pg-ff] statopcajour query failed:", err.message);
return { rows: [] };
}),
// QTE + Marge + Lignes par site depuis mvtart (cumstat = 1)
pgNoParallel(sql`
SELECT
@@ -547,7 +550,7 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
AND m.site IN ('292', '579')
GROUP BY m.site
ORDER BY m.site
`),
`).catch((err) => { console.error("[pg-ff] mvtSites query failed:", err.message); return { rows: [] }; }),
// Top 10 CA réseau hier (cumstat = 1)
pgNoParallel(sql`
SELECT
@@ -565,7 +568,7 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
GROUP BY a.codein, a.libelle1
ORDER BY ca DESC
LIMIT 10
`),
`).catch((err) => { console.error("[pg-ff] top10Ca query failed:", err.message); return { rows: [] }; }),
// Top 10 QTE réseau hier (cumstat = 1)
pgNoParallel(sql`
SELECT
@@ -583,7 +586,7 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
GROUP BY a.codein, a.libelle1
ORDER BY qte DESC
LIMIT 10
`),
`).catch((err) => { console.error("[pg-ff] top10Qte query failed:", err.message); return { rows: [] }; }),
// Top 10 Marge réseau hier (cumstat = 1)
pgNoParallel(sql`
SELECT
@@ -601,7 +604,7 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
GROUP BY a.codein, a.libelle1
ORDER BY marge DESC
LIMIT 10
`),
`).catch((err) => { console.error("[pg-ff] top10Marge query failed:", err.message); return { rows: [] }; }),
// Évolution mensuelle sur 25 mois (cumstat = 1)
pgNoParallel(sql`
SELECT
@@ -617,7 +620,7 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
AND m.site IN ('292', '579')
GROUP BY TO_CHAR(m.datmvt, 'YYYY-MM')
ORDER BY mois
`),
`).catch((err) => { console.error("[pg-ff] evolution query failed:", err.message); return { rows: [] }; }),
]);
// Fusionner CA+tickets (statopcajour) avec QTE+marge (mvtart) par site