feat: sort analytics by name (fournisseur) or code asc (nomenclature); show code in nomenclature label; remove diag-fournisseurs endpoint

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Sonnet 4.6 committed 2026-04-01 08:42:21 +02:00
1 parent 65b55b1343
commit bc76237f48
2 files changed
+9 -42

No files matched your search

+9 -5
View File
@@ -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(
-37
View File
@@ -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 });
}
}