mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-21 14:08:08 +02:00
feat: Add PostgreSQL client for FF Nancy data, replacing per-article HTTP API calls with bulk SQL queries for improved performance.
This commit is contained in:
1 parent
4b84b56aa6
commit
750017de14
1 file changed
+12
-8
+12
-8
@@ -81,6 +81,8 @@ export async function pgGetFournisseurs(search?: string): Promise<{ code: string
|
|||||||
WHERE fa.sit_code = '000'
|
WHERE fa.sit_code = '000'
|
||||||
AND fa.raisonsociale IS NOT NULL
|
AND fa.raisonsociale IS NOT NULL
|
||||||
AND fa.code IS NOT NULL
|
AND fa.code IS NOT NULL
|
||||||
|
-- Exclure les raisonsociales qui commencent par un chiffre (adresses postales)
|
||||||
|
AND fa.raisonsociale !~ '^\s*\d'
|
||||||
${search ? sql`AND (fa.raisonsociale ILIKE ${'%' + search + '%'} OR fa.code ILIKE ${'%' + search + '%'})` : sql``}
|
${search ? sql`AND (fa.raisonsociale ILIKE ${'%' + search + '%'} OR fa.code ILIKE ${'%' + search + '%'})` : sql``}
|
||||||
ORDER BY fa.raisonsociale
|
ORDER BY fa.raisonsociale
|
||||||
`);
|
`);
|
||||||
@@ -160,6 +162,9 @@ export async function pgGetMensuelByFournisseur(
|
|||||||
dateDebut: string,
|
dateDebut: string,
|
||||||
dateFin: string
|
dateFin: string
|
||||||
): Promise<PgMensuelRow[]> {
|
): Promise<PgMensuelRow[]> {
|
||||||
|
// IMPORTANT : utiliser DISTINCT sur artfou1 pour éviter les doublons de mouvements.
|
||||||
|
// Un article peut avoir plusieurs lignes artfou1 pour le même fournisseur (pcb/ref différents),
|
||||||
|
// ce qui multiplierait chaque mouvement et gonflerait les totaux.
|
||||||
const result = await db.execute(sql`
|
const result = await db.execute(sql`
|
||||||
SELECT
|
SELECT
|
||||||
a.codein,
|
a.codein,
|
||||||
@@ -171,10 +176,10 @@ export async function pgGetMensuelByFournisseur(
|
|||||||
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 ABS(m.qtemvt) ELSE 0 END)::float AS qte_recue
|
SUM(CASE WHEN m.genremvt IN (1, 2) THEN ABS(m.qtemvt) ELSE 0 END)::float AS qte_recue
|
||||||
FROM mvtart m
|
FROM mvtart m
|
||||||
JOIN articles a
|
JOIN articles a ON a.no_id = m.artnoid
|
||||||
ON a.no_id = m.artnoid
|
-- Sous-requête dédupliquée : 1 seule ligne par article/fournisseur
|
||||||
JOIN artfou1 af
|
JOIN (SELECT DISTINCT art_no_id FROM artfou1 WHERE code = ${codefou}) af
|
||||||
ON af.art_no_id = a.no_id AND af.code = ${codefou}
|
ON af.art_no_id = a.no_id
|
||||||
WHERE m.datmvt BETWEEN ${dateDebut}::date AND ${dateFin}::date
|
WHERE m.datmvt BETWEEN ${dateDebut}::date AND ${dateFin}::date
|
||||||
AND m.site IN ('292', '579')
|
AND m.site IN ('292', '579')
|
||||||
GROUP BY a.codein, m.site, TO_CHAR(m.datmvt, 'YYYY-MM')
|
GROUP BY a.codein, m.site, TO_CHAR(m.datmvt, 'YYYY-MM')
|
||||||
@@ -317,10 +322,9 @@ export async function pgGetStockByFournisseur(codefou: string): Promise<Map<stri
|
|||||||
cs.dernierevente::text,
|
cs.dernierevente::text,
|
||||||
cs.dernierereception::text
|
cs.dernierereception::text
|
||||||
FROM cube_stock cs
|
FROM cube_stock cs
|
||||||
JOIN articles a
|
JOIN articles a ON a.no_id = cs.artnoid
|
||||||
ON a.no_id = cs.artnoid
|
JOIN (SELECT DISTINCT art_no_id FROM artfou1 WHERE code = ${codefou}) af
|
||||||
JOIN artfou1 af
|
ON af.art_no_id = a.no_id
|
||||||
ON af.art_no_id = a.no_id AND af.code = ${codefou}
|
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const map = new Map<string, PgStockRow[]>();
|
const map = new Map<string, PgStockRow[]>();
|
||||||
|
|||||||
Reference in new issue
Block a user