mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-24 15:38:09 +02:00
feat: Add PostgreSQL client for FF Nancy data, replacing HTTP API calls with bulk SQL queries for improved performance.
This commit is contained in:
1 parent
d5b518477a
commit
b4f583415b
2 files changed
+7
-12
No files matched your search
@@ -121,12 +121,10 @@ export async function getProductRows(input: GetProductRowsInput): Promise<Produc
|
|||||||
p.marge += Number(row.marge) || 0;
|
p.marge += Number(row.marge) || 0;
|
||||||
p.receptions += Number(row.qte_recue) || 0;
|
p.receptions += Number(row.qte_recue) || 0;
|
||||||
|
|
||||||
// Suivi magasins actifs (pour workingStores)
|
// Suivi magasins actifs (pour workingStores) : 1 vente suffit
|
||||||
if (Number(row.qte_vendue) > 0) {
|
if (Number(row.qte_vendue) > 0) {
|
||||||
if (!storeMonthsByCodein.has(row.codein)) storeMonthsByCodein.set(row.codein, new Map());
|
if (!storeMonthsByCodein.has(row.codein)) storeMonthsByCodein.set(row.codein, new Map());
|
||||||
const storeMonths = storeMonthsByCodein.get(row.codein)!;
|
storeMonthsByCodein.get(row.codein)!.set(row.site, new Set()); // on garde juste le site
|
||||||
if (!storeMonths.has(row.site)) storeMonths.set(row.site, new Set());
|
|
||||||
storeMonths.get(row.site)!.add(periode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,13 +153,10 @@ export async function getProductRows(input: GetProductRowsInput): Promise<Produc
|
|||||||
|
|
||||||
product.tauxMarge = product.totalCa > 0 ? (product.totalMarge / product.totalCa) * 100 : 0;
|
product.tauxMarge = product.totalCa > 0 ? (product.totalMarge / product.totalCa) * 100 : 0;
|
||||||
|
|
||||||
// workingStores : sites avec ventes sur ≥ 3 mois distincts
|
// workingStores : sites avec au moins 1 vente sur les 12 derniers mois
|
||||||
const storeMonths = storeMonthsByCodein.get(codein);
|
const storeMonths = storeMonthsByCodein.get(codein);
|
||||||
if (storeMonths) {
|
if (storeMonths) {
|
||||||
product.workingStores = [...storeMonths.entries()]
|
product.workingStores = [...storeMonths.keys()].sort();
|
||||||
.filter(([, periods]) => periods.size >= 3)
|
|
||||||
.map(([site]) => site)
|
|
||||||
.sort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commandes en cours
|
// Commandes en cours
|
||||||
|
|||||||
@@ -172,9 +172,9 @@ export async function pgGetMensuelByFournisseur(
|
|||||||
TO_CHAR(m.datmvt, 'YYYY-MM') AS mois,
|
TO_CHAR(m.datmvt, 'YYYY-MM') AS mois,
|
||||||
-- genremvt=3 : vente → qtemvt négatif, retour → qtemvt positif
|
-- genremvt=3 : vente → qtemvt négatif, retour → qtemvt positif
|
||||||
-- qte_vendue nette = SUM(-qtemvt) : ventes moins retours
|
-- qte_vendue nette = SUM(-qtemvt) : ventes moins retours
|
||||||
SUM(CASE WHEN m.genremvt = 3 THEN -m.qtemvt ELSE 0 END)::float AS qte_vendue,
|
SUM(CASE WHEN m.genremvt = 3 THEN -m.qtemvt ELSE 0 END)::float AS qte_vendue,
|
||||||
SUM(CASE WHEN m.genremvt = 3 THEN m.mntmvtttc ELSE 0 END)::float AS ca_ht,
|
SUM(CASE WHEN m.genremvt = 3 THEN -m.mntmvtttc ELSE 0 END)::float AS ca_ht,
|
||||||
SUM(CASE WHEN m.genremvt = 3 THEN m.margemvt ELSE 0 END)::float AS marge,
|
SUM(CASE WHEN m.genremvt = 3 THEN -m.margemvt ELSE 0 END)::float AS marge,
|
||||||
MAX(m.qtestock)::float AS stock_fin_mois,
|
MAX(m.qtestock)::float AS stock_fin_mois,
|
||||||
SUM(CASE WHEN m.genremvt IN (1, 2) THEN -m.qtemvt ELSE 0 END)::float AS qte_recue
|
SUM(CASE WHEN m.genremvt IN (1, 2) THEN -m.qtemvt ELSE 0 END)::float AS qte_recue
|
||||||
FROM mvtart m
|
FROM mvtart m
|
||||||
|
|||||||
Reference in new issue
Block a user