diff --git a/src/app/(dashboard)/analytics/page.tsx b/src/app/(dashboard)/analytics/page.tsx index 8649a65..1bbe515 100644 --- a/src/app/(dashboard)/analytics/page.tsx +++ b/src/app/(dashboard)/analytics/page.tsx @@ -12,7 +12,8 @@ function getMoisN1(mois: string): string { function pivotData( rows: Array<{ code: string; label: string; site: string; mois: string; ca_ttc: number }>, mois: string, - moisN1: string + moisN1: string, + mode: string ): Array<{ key: string; label: string; @@ -58,8 +59,11 @@ function pivotData( }; }); - // Trier par CA Total décroissant - result.sort((a, b) => b.caTotal - a.caTotal); + if (mode === "nomenclature") { + result.sort((a, b) => a.key.localeCompare(b.key)); + } else { + result.sort((a, b) => a.label.localeCompare(b.label, "fr")); + } return result; } @@ -92,14 +96,14 @@ export default async function AnalyticsPage(props: { const result = await pgGetCaByNomenclature(mois, moisN1); rows = result.map((r) => ({ code: r.code, - label: r.libelle, + label: `${r.code} — ${r.libelle}`, site: r.site, mois: r.mois, ca_ttc: r.ca_ttc, })); } - const pivotted = pivotData(rows, mois, moisN1); + const pivotted = pivotData(rows, mois, moisN1, mode); // Calcul des totaux const totals = pivotted.reduce( diff --git a/src/app/api/diag-fournisseurs/route.ts b/src/app/api/diag-fournisseurs/route.ts deleted file mode 100644 index d65eaf4..0000000 --- a/src/app/api/diag-fournisseurs/route.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { NextResponse } from "next/server"; -import { db } from "@/db"; -import { sql } from "drizzle-orm"; - -export async function GET() { - try { - // 1. Colonnes de fouident - const cols = await db.execute(sql` - SELECT column_name, data_type - FROM information_schema.columns - WHERE table_name = 'fouident' - ORDER BY ordinal_position - `); - - // 2. Sample fouident - const sample = await db.execute(sql`SELECT * FROM fouident LIMIT 10`); - - // 3. D005 dans fouident - const d005 = await db.execute(sql`SELECT * FROM fouident WHERE code = 'D005' LIMIT 5`); - - // 4. Nos fournisseurs clés pour comparer les noms - const known = await db.execute(sql` - SELECT * FROM fouident - WHERE code IN ('D005','J009','M0341','L0091','S053','B0071','T015','C024','S025','C023') - ORDER BY code - `); - - return NextResponse.json({ - fouident_columns: cols.rows, - fouident_sample: sample.rows, - fouident_d005: d005.rows, - fouident_known: known.rows, - }); - } catch (e) { - return NextResponse.json({ error: String(e) }, { status: 500 }); - } -}