From 5a13640884143b0da9004aceb105a19b93a3edc9 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Tue, 7 Apr 2026 17:36:27 +0200 Subject: [PATCH] feat: implement pg-ff-client to replace per-article HTTP calls with bulk PostgreSQL queries --- src/app/(dashboard)/stock-negatif/client.tsx | 10 ++++++---- src/lib/pg-ff-client.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/(dashboard)/stock-negatif/client.tsx b/src/app/(dashboard)/stock-negatif/client.tsx index 9401e2a..673a1f3 100644 --- a/src/app/(dashboard)/stock-negatif/client.tsx +++ b/src/app/(dashboard)/stock-negatif/client.tsx @@ -66,15 +66,15 @@ function TabStockNegatif({ rows, magasin }: { rows: PgStockNegatifRow[]; magasin const ExcelJS = (await import("exceljs")).default; const wb = new ExcelJS.Workbook(); const ws = wb.addWorksheet("Stock Négatif"); - ws.addRow(["Code article", "Libellé", "Fournisseur", "Stock négatif"]); + ws.addRow(["Code article", "Libellé", "Fournisseur", "Magasin", "Stock négatif", "Dernière vente", "Dernière entrée en stock"]); ws.getRow(1).eachCell(cell => { cell.fill = { type: "pattern", pattern: "solid", fgColor: { argb: "FF1E293B" } }; cell.font = { color: { argb: "FFFFFFFF" }, bold: true }; cell.alignment = { vertical: "middle", horizontal: "center" }; }); ws.getRow(1).height = 22; - for (const r of sorted) ws.addRow([r.codein, r.libelle1, r.fournisseur, r.stockdispo]); - ws.columns = [{ width: 16 }, { width: 40 }, { width: 30 }, { width: 14 }]; + for (const r of sorted) ws.addRow([r.codein, r.libelle1, r.fournisseur, r.site, r.stockdispo, fmtDate(r.dernierevente), fmtDate(r.derniereentree)]); + ws.columns = [{ width: 16 }, { width: 40 }, { width: 30 }, { width: 10 }, { width: 14 }, { width: 16 }, { width: 22 }]; const buffer = await wb.xlsx.writeBuffer(); const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); const url = URL.createObjectURL(blob); @@ -103,11 +103,12 @@ function TabStockNegatif({ rows, magasin }: { rows: PgStockNegatifRow[]; magasin {th("site", "Magasin")} {th("stockdispo", "Stock")} {th("dernierevente", "Dernière vente")} + {th("derniereentree", "Dernière entrée")} {sorted.length === 0 && ( - Aucun article en stock négatif + Aucun article en stock négatif )} {sorted.map((row, i) => ( @@ -119,6 +120,7 @@ function TabStockNegatif({ rows, magasin }: { rows: PgStockNegatifRow[]; magasin {row.stockdispo} {fmtDate(row.dernierevente)} + {fmtDate(row.derniereentree)} ))} diff --git a/src/lib/pg-ff-client.ts b/src/lib/pg-ff-client.ts index bf23158..784e61e 100644 --- a/src/lib/pg-ff-client.ts +++ b/src/lib/pg-ff-client.ts @@ -840,6 +840,7 @@ export interface PgStockNegatifRow { site: string; stockdispo: number; dernierevente: string | null; + derniereentree: string | null; } /** @@ -899,7 +900,14 @@ export async function pgGetStockNegatif(site?: string): Promise