mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: restore reference, gtin, gamme initiale and nomenclature
api-ff-client.ts: - FfArticle: add reference (ref_fou_principale) and gtin fields - getArticlesByFournisseur: map ref_fou_principale → reference, gtin → gtin get-product-rows.ts: - ProductRow seeded with reference and gtin from API articles - Phase 6: read codeGamme, codeGammeInit, code3, libelle3 from ventesProduits (read-only, DISTINCT ON codein ordered by updated_at DESC) - Phase 7 snapshot still overrides DB gammes when a snapshot exists Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
58f17152a1
commit
47e617afd3
2 files changed
+40
-12
No files matched your search
@@ -9,8 +9,8 @@ import {
|
||||
buildLast12MonthsRange,
|
||||
} from "@/lib/api-ff-client";
|
||||
import { db } from "@/db";
|
||||
import { sessionSnapshots } from "@/db/schema";
|
||||
import { eq, desc } from "drizzle-orm";
|
||||
import { sessionSnapshots, ventesProduits } from "@/db/schema";
|
||||
import { eq, desc, sql } from "drizzle-orm";
|
||||
|
||||
interface GetProductRowsInput {
|
||||
codeFournisseur: string;
|
||||
@@ -53,8 +53,8 @@ export async function getProductRows(input: GetProductRowsInput): Promise<Produc
|
||||
codeFournisseur: art.codefou ?? codeFournisseur,
|
||||
nomFournisseur: art.nomfou ?? "",
|
||||
libelle1: art.libelle1 ?? "",
|
||||
gtin: "",
|
||||
reference: "",
|
||||
gtin: art.gtin ?? "",
|
||||
reference: art.reference ?? "",
|
||||
code1: "", libelleNiveau1: "",
|
||||
code2: "", libelleNiveau2: "",
|
||||
code3: "", libelle3: "",
|
||||
@@ -151,7 +151,31 @@ export async function getProductRows(input: GetProductRowsInput): Promise<Produc
|
||||
if (cmdQty) product.commandesEnCours = cmdQty;
|
||||
}
|
||||
|
||||
// ─── Phase 6 : Restaurer gammes depuis dernier snapshot ──────────────
|
||||
// ─── Phase 6 : Classification depuis ventesProduits (lecture seule) ──
|
||||
// Source de vérité pour : codeGamme initial, codeGammeInit, code3, libelle3
|
||||
try {
|
||||
const classifRows = await db.execute(sql`
|
||||
SELECT DISTINCT ON (codein)
|
||||
codein, code_gamme, code_gamme_init, code3, libelle3
|
||||
FROM ventes_produits
|
||||
WHERE code_fournisseur = ${codeFournisseur}
|
||||
ORDER BY codein, updated_at DESC
|
||||
`);
|
||||
for (const row of classifRows.rows) {
|
||||
const product = productMap.get(row.codein as string);
|
||||
if (product) {
|
||||
product.codeGamme = (row.code_gamme as string | null) ?? null;
|
||||
product.codeGammeInit = (row.code_gamme_init as string | null) ?? null;
|
||||
product.code3 = (row.code3 as string | null) ?? "";
|
||||
product.libelle3 = (row.libelle3 as string | null) ?? "";
|
||||
}
|
||||
}
|
||||
console.log(`[getProductRows] Classification chargée pour ${classifRows.rows.length} lignes`);
|
||||
} catch (classifErr) {
|
||||
console.warn("[getProductRows] ventesProduits classification non disponible:", classifErr);
|
||||
}
|
||||
|
||||
// ─── Phase 7 : Restaurer gammes depuis dernier snapshot ──────────────
|
||||
try {
|
||||
const snaps = await db
|
||||
.select()
|
||||
|
||||
@@ -27,7 +27,9 @@ export interface FfArticle {
|
||||
nomfou?: string;
|
||||
pcb?: number; // conditionnement
|
||||
pv_central?: number; // prix de vente central
|
||||
noid?: number; // SQL Server internal ID
|
||||
noid?: number; // SQL Server internal ID (pour endpoint /mensuel)
|
||||
reference?: string; // référence fournisseur (ref_fou_principale)
|
||||
gtin?: string; // code-barres EAN/GTIN
|
||||
}
|
||||
|
||||
export interface FfMouvement {
|
||||
@@ -203,13 +205,15 @@ export async function getArticlesByFournisseur(
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return raw.map((r: any): FfArticle => ({
|
||||
codein: r.codein ?? r.Codein ?? r.code_article ?? r.codeArticle ?? String(r.id ?? ""),
|
||||
libelle1: r.libelle1 ?? r.Libelle1 ?? r.libelle ?? r.designation ?? r.nom ?? "",
|
||||
codefou: r.codefou_principal ?? r.codefou ?? r.Codefou ?? r.code_fournisseur ?? r.codeFournisseur ?? codefou,
|
||||
nomfou: r.nom_fou_principal ?? r.nomfou ?? r.Nomfou ?? r.nom_fournisseur ?? r.nomFournisseur ?? "",
|
||||
pcb: r.pcb_principal ?? r.pcb ?? r.Pcb ?? r.conditionnement ?? r.colisage,
|
||||
pv_central: r.pv_central ?? r.PvCentral ?? r.pv ?? r.prixVente,
|
||||
codein: r.codein ?? r.Codein ?? r.code_article ?? r.codeArticle ?? String(r.id ?? ""),
|
||||
libelle1: r.libelle1 ?? r.Libelle1 ?? r.libelle ?? r.designation ?? r.nom ?? "",
|
||||
codefou: r.codefou_principal ?? r.codefou ?? r.Codefou ?? r.code_fournisseur ?? r.codeFournisseur ?? codefou,
|
||||
nomfou: r.nom_fou_principal ?? r.nomfou ?? r.Nomfou ?? r.nom_fournisseur ?? r.nomFournisseur ?? "",
|
||||
pcb: r.pcb_principal ?? r.pcb ?? r.Pcb ?? r.conditionnement ?? r.colisage,
|
||||
pv_central: r.pv_central ?? r.PvCentral ?? r.pv ?? r.prixVente,
|
||||
noid: r.no_id ?? r.noid ?? r.NoId,
|
||||
reference: r.ref_fou_principale ?? r.reference ?? r.ref_fournisseur ?? undefined,
|
||||
gtin: r.gtin ?? r.Gtin ?? r.ean ?? r.barcode ?? undefined,
|
||||
})).filter(a => a.codein);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user