mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-22 06:28:09 +02:00
feat: implement high-performance PostgreSQL bulk fetchers to replace per-article HTTP API calls
This commit is contained in:
1 parent
038e87f554
commit
5a3ac3ed7f
1 file changed
+13
-14
+13
-14
@@ -633,7 +633,9 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
|
|||||||
}
|
}
|
||||||
const refData = await refRes.json();
|
const refData = await refRes.json();
|
||||||
|
|
||||||
// --- Supplier: exclude known depot platform codes, pick best real supplier ---
|
// --- Supplier: pick the last fournisseur who entered stock ---
|
||||||
|
// Business rule: attribute the article to the most recently active supplier
|
||||||
|
// = non-depot fournisseur with suspendu=null (currently active delivery relationship)
|
||||||
type FouEntry = { codefou: string; nom_fou: string | null; preference: number | null; suspendu: string | null };
|
type FouEntry = { codefou: string; nom_fou: string | null; preference: number | null; suspendu: string | null };
|
||||||
let fou = '—';
|
let fou = '—';
|
||||||
|
|
||||||
@@ -642,30 +644,27 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
|
|||||||
|
|
||||||
if (refData.fournisseurs && Array.isArray(refData.fournisseurs)) {
|
if (refData.fournisseurs && Array.isArray(refData.fournisseurs)) {
|
||||||
const fous = refData.fournisseurs as FouEntry[];
|
const fous = refData.fournisseurs as FouEntry[];
|
||||||
|
|
||||||
const pickLabel = (f: FouEntry): string => f.nom_fou?.trim() || f.codefou.trim();
|
const pickLabel = (f: FouEntry): string => f.nom_fou?.trim() || f.codefou.trim();
|
||||||
|
|
||||||
// Epoch sentinel 1901 = never actually suspended in this system
|
// Truly active = suspendu is null or the 1901 epoch sentinel (never suspended)
|
||||||
const isActive = (f: FouEntry): boolean =>
|
const isTrulyActive = (f: FouEntry): boolean =>
|
||||||
!f.suspendu || f.suspendu.startsWith('1901');
|
!f.suspendu || f.suspendu.startsWith('1901');
|
||||||
|
|
||||||
// Filter out known depot platform codes only (not all D* codes — DART FRANCE etc. are real suppliers)
|
// Non-depot fournisseurs only (exclude known platform/depot codes)
|
||||||
const realFous = fous.filter(f => !DEPOT_CODES.has(f.codefou.trim()));
|
const realFous = fous.filter(f => !DEPOT_CODES.has(f.codefou.trim()));
|
||||||
|
|
||||||
if (realFous.length > 0) {
|
if (realFous.length > 0) {
|
||||||
// Priority 1: preference=1 AND active
|
// Priority 1: currently active (suspendu=null) non-depot — most likely to have made last reception
|
||||||
const p1Active = realFous.find(f => f.preference === 1 && isActive(f));
|
const activeNow = realFous.find(f => isTrulyActive(f));
|
||||||
// Priority 2: preference=1 (even if suspended — at least declared as main)
|
// Priority 2: preference=1 (declared main supplier, even if suspended)
|
||||||
const p1Any = realFous.find(f => f.preference === 1);
|
const p1 = realFous.find(f => f.preference === 1);
|
||||||
// Priority 3: any active non-depot supplier
|
// Priority 3: first non-depot available (last resort)
|
||||||
const anyActive = realFous.find(f => isActive(f));
|
|
||||||
// Priority 4: first non-depot (last resort)
|
|
||||||
const first = realFous[0];
|
const first = realFous[0];
|
||||||
|
|
||||||
const best = p1Active ?? p1Any ?? anyActive ?? first;
|
const best = activeNow ?? p1 ?? first;
|
||||||
fou = pickLabel(best);
|
fou = pickLabel(best);
|
||||||
} else {
|
} else {
|
||||||
// Only depot codes found — this article is sourced through the depot platform
|
// Only depot codes found → article sourced exclusively through depot
|
||||||
fou = 'Dépôt';
|
fou = 'Dépôt';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user