68 Commits
Author SHA1 Message Date
MichaelandClaude Opus 4.8 adc8d357c9 fix: dedupe cube_pa rows by artnoid before full refresh
Cube_PA is a heap in SQL Server with no primary key, while the
PostgreSQL cube_pa table uses artnoid as PRIMARY KEY. The cube
normally emits one row per article, but for 3 articles supplied by
two vendors it emitted both vendor prices, so fullRefresh hit:

  duplicate key value violates unique constraint "cube_pa_pkey"

These are not exact duplicates: the two rows carry different PA
values, so the choice changes the article's purchase price. Resolve
by keeping the price whose last change is the most recent, read from
the dated history packed into ARTFOU2.PRIXACHAT
("[01/01/1901,0.990:16/05/2018,1.010]"). SUIVIDATEMODIF cannot be
used alone: it is not touched when only the price changes (S028 shows
modif 2017 but a price change in 2025). It only breaks ties.

The lookup runs solely when duplicates are present, so the nightly
sync is unaffected in the normal case.

Verified against the live 427 752-row Cube_PA: 427 749 rows out, all
artnoid distinct, no fallback triggered. Parsing PRIXACHAT over 20 000
ARTFOU2 rows: 19 999 parsed, 1 empty, 0 failures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 12:30:49 +02:00
Michael 950539472f Merge remote-tracking branch 'origin/claude/gallant-edison-i5bg90' 2026-07-09 09:13:35 +02:00
MichaelandClaude Opus 4.8 f00b9c4b14 feat(articles): expose and filter code centrale (artcentrale)
The code centrale is LaFoir'Fouille's 11-digit product identifier
(prefix 1000x). Only products referenced by the central purchasing
office have one: ~355 800 of 427 700 articles.

The column was already synced from SQL Server and returned by the
detail route via `a.*`, but was absent from the list route and could
not be filtered on.

- list route: select artcentrale, add `artcentrale` (partial match)
  and `has_artcentrale=1|0` query params
- filter matches on prefix AND length 11, so malformed values with a
  valid prefix ('10000', '10000192289P') are excluded
- COALESCE in the predicate: without it, NOT (NULL LIKE '1000%') is
  NULL and the 61 442 NULL rows would vanish from has_artcentrale=0
- normalise '' to null in both routes so they agree
- sync: use safeStr so empty values are stored as NULL, not ''

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-09 09:09:25 +02:00
Michael 62249e6c13 docs: update API documentation with missing endpoints and schema corrections 2026-05-28 16:45:14 +02:00
MichaelandClaude Sonnet 4.6 f16e2efe0b fix: use preference = 1 (integer) instead of true (boolean) in artfou1 joins
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 16:14:52 +02:00
MichaelandClaude Sonnet 4.6 329a4c018c feat: add fournisseur filter to hitparade endpoint
Add codefou query param (ILIKE partial match) to /api/performance/hitparade.
Also return CODE_FOURNISSEUR and FOURNISSEUR (nom) columns in each result row.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 15:55:45 +02:00
Michael f83a090cfb feat: add article management routes with search, detail, and referential data endpoints 2026-05-06 11:43:15 +02:00
Michael ab8ed85c84 feat: add photos route with sitemap indexing and status endpoints 2026-05-06 11:31:48 +02:00
Michael 95799add1d feat: initialize Postgres schema and set up core API routing for articles and photos 2026-05-06 11:30:03 +02:00
Michael 79c7628b99 feat: implement article routes and product photo resolution service 2026-05-06 11:04:09 +02:00
Michael 6bbfc1696b feat: implement articles route with product search, detail, and referential data endpoints 2026-05-06 10:00:44 +02:00
MichaelandClaude Sonnet 4.6 57e9449a58 fix: nomenclature CA - valeurs absolues, GenreMvt IN(3,4,9), traversée hiérarchie
- CA était négatif (MntMvtTTC brut) → filtre mntmvtttc < 0 + ABS comme le endpoint /ca
- GenreMvt=3 uniquement → IN(3,4,9)
- Niveau 1/2 retournait vide (articles au niveau 3) → remontée via chemin_pere
  chemin_pere = "no_id_niv1.no_id_niv2" → SPLIT_PART + JOIN NOMENCLATURE parent
- Ajout taux_marge dans la réponse

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 09:28:51 +02:00
MichaelandClaude Sonnet 4.6 c1d6f87a7e feat: publicites - add total/pages to list, add /historique endpoint
- List endpoint now returns total count and pages for pagination
- Added statut filter (en_cours/passees/futures) to list endpoint
- Added GET /historique using pub_entetes for complete pub history
  (pub_ecoulement only has recent data; pub_entetes has all 95 pubs)
- /historique returns nb_sites, ca_total, qte_totale via LEFT JOIN

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 13:10:22 +02:00
Michael 408dcc61bb feat: add statut filter and statut field to publicites endpoint 2026-04-24 13:00:13 +02:00
Michael a6a86f680a fix: show suppliers with qtepropo=0 if active (datecdeauto recent), fixes B008 missing 2026-04-24 12:43:30 +02:00
Michael d9b4c1eb44 fix: filter commandes-auto by datecdeauto within 7 days to exclude deactivated suppliers 2026-04-24 12:35:22 +02:00
Michael c278a931f8 fix: remove foucad.actif filter, qtepropo=0 is the source of truth for exclusion 2026-04-24 12:21:38 +02:00
Michael 30440be275 fix: use IS NOT FALSE to keep suppliers without foucad entry in commandes-auto 2026-04-24 12:16:13 +02:00
Michael 6d7b1fb44d fix: exclude suppliers with foucad.actif=false from commandes-auto 2026-04-24 12:13:35 +02:00
Michael a68e706805 feat: add GET /api/fournisseurs/:code/franco endpoint 2026-04-24 12:05:47 +02:00
Michael 7312b84233 fix: resolve duplicate rows in commandes-auto caused by fouport multi-site join 2026-04-24 11:44:26 +02:00
Michael 2f920d8623 fix: use fouident.nom instead of FOUADR1.RAISONSOCIALE for supplier names in articles routes 2026-04-24 11:06:34 +02:00
Michael e15852a6aa feat: implement API routes for article search, details, and movement history 2026-04-24 10:54:11 +02:00
Michael 6f2b98864e feat: implement express route handlers for movements, articles, and suppliers data retrieval 2026-04-24 10:49:53 +02:00
Michael 204fd97d7d Merge branch 'main' of https://github.com/R0m1k3/Apiflow 2026-04-24 10:05:39 +02:00
Michael d3052a6235 feat: implement movement and article route handlers and register them in the main application entry point 2026-04-24 10:05:37 +02:00
MichaelandClaude Sonnet 4.6 c75fd5c56d fix: utiliser FOUPORT2.SEUIL comme source principale du franco fournisseur
FOUCAD ne couvre que 53/153 fournisseurs actifs (commande auto uniquement).
FOUPORT2.SEUIL est la source officielle de l'ERP et couvre 108 fournisseurs.
4 fournisseurs dans COMMANDE_AUTO_QTEPROPO n'avaient pas de franco visible
(IMDIFA, MYCANDYSHOP, PTIT CLOWN, PUCKATOR BV).

- Sync : ajout de FOUPORT et FOUPORT2 dans le pipeline de synchronisation
- API : franco = COALESCE(fouport2.seuil, foucad.franco) dans les deux routes
- Schema PG : création des tables fouport et fouport2

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 15:58:15 +02:00
Michael b4a9331fa8 chore: update ff_sync environment variables in docker-compose.yml to support dynamic configuration 2026-04-09 08:42:44 +02:00
Michael ef4734ff39 refactor: migrate sync service environment variables to .env.docker file 2026-04-09 08:22:18 +02:00
Michael 5a5bc8b6f3 feat: add sync script for procurement tables including orders, lines, and reordering plans 2026-04-09 08:19:55 +02:00
Michael d74cdeb7b3 feat: implement automated procurement synchronization and API endpoints for supply chain management 2026-04-09 08:18:10 +02:00
MichaelandClaude Sonnet 4.6 6e5bc3bc07 feat: ajout endpoint /api/commandes-auto avec franco fournisseur
- Nouvelle route GET /api/commandes-auto : propositions par site et fournisseur
  avec comparaison au franco (franco_atteint, ecart_franco)
- Nouvelle route GET /api/commandes-auto/:codefou : détail articles d'un fournisseur
- Sync FOUCAD (config commande auto + franco) vers PostgreSQL
- Ajout table foucad dans init.sql

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-08 15:24:51 +02:00
Michael 42f7c9bac6 feat: add sync script for advertising tables from MSSQL to PostgreSQL 2026-04-07 11:10:42 +02:00
Michael 9e993b3559 feat: implement advertising data synchronization and API endpoints for performance tracking 2026-04-07 10:34:36 +02:00
Michael de69370d9e feat: add web dashboard for monitoring sync status and logs 2026-04-01 10:52:02 +02:00
Michael cb0b608edb feat: implement synchronization logic for mouvements and statopca tables from MSSQL to PostgreSQL 2026-04-01 10:18:12 +02:00
Michael 90d1b1675c feat: implement movement synchronization logic and initialize PostgreSQL schema tables 2026-04-01 10:04:17 +02:00
Michael 7df3025fd8 feat: add performance route for sales analytics, hit parades, and dashboard metrics 2026-04-01 09:56:05 +02:00
Michael 5fb99dc7f5 feat: add performance analytics routes for sales, hit parades, and dashboard metrics 2026-04-01 09:31:13 +02:00
Michael 2839a615fd feat: implement automated sync service with cron scheduling and web dashboard 2026-04-01 09:18:36 +02:00
Michael e20c253df8 feat: add sync module for supplier data including artfou1, artfou2, and fouadr1 tables 2026-03-31 13:51:34 +02:00
Michael d885f51bdb feat: add sync script for appro tables including commande_fou, cdefou_ligne, commande_auto_qtepropo, and plan_reappro 2026-03-30 18:34:24 +02:00
Michael e629a1c699 feat: implement provisioning and synchronization logic for procurement tables 2026-03-30 17:59:51 +02:00
Michael 624d9ab851 feat: add sync logic for procurement tables including orders, lines, and reappro plans 2026-03-30 13:11:49 +02:00
Michael 3f23f181f4 feat: Implement initial PostgreSQL schema and synchronization scripts for various data tables. 2026-03-30 12:43:41 +02:00
MichaelandClaude Sonnet 4.6 52c47acc67 feat: add stat_dispoperm and phenix_quantite_conseille to sync pipeline
- Add ARTCENTRALE column to articles sync
- Add stat_dispoperm table (gamme conseillée, joins via ARTCENTRALE)
- Add phenix_quantite_conseille table (journal de commande ERP)
- Register both tables in sync/index.js steps

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 08:13:14 +01:00
Michael c5faddde1f feat: Add synchronization of articles, article supplementary information, GTINs, and permanent availability statistics from MSSQL to PostgreSQL. 2026-03-27 08:10:21 +01:00
Michael a8acba554f feat: Add performance API routes for turnover, hit parade, nomenclature, product range, and a daily dashboard. 2026-03-22 10:55:05 +01:00
Michael 371f80c844 Dashboard top10: rank per site instead of global 2026-03-21 11:50:23 +01:00
Michael 9675a243b7 feat: Implement initial API backend with a comprehensive PostgreSQL schema, Express application, and data synchronization for articles and ranking. 2026-03-21 10:01:02 +01:00
MichaelandClaude Opus 4.6 e189cc3045 fix(sync): ranking dedup + copy logs over HTTP
- ranking.js: déduplique par (gencod, site) avant batchUpsert pour éviter
  "ON CONFLICT DO UPDATE command cannot affect row a second time"
- server.js: bouton "Copier les logs" utilise execCommand fallback quand
  navigator.clipboard indisponible (accès HTTP sans HTTPS)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 12:06:27 +01:00
MichaelandClaude Opus 4.6 5ce480ade3 fix: mssql requestTimeout 5min + try/catch par étape sync
- requestTimeout 300000ms pour éviter timeout sur grosses tables (MvtArt)
- Chaque étape sync est wrappée en try/catch pour ne pas bloquer les suivantes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 11:34:36 +01:00
MichaelandClaude Opus 4.6 cf6a7aa0b2 feat: dashboard logs copiables + bouton copier + ranking dans TABLES_ORDER
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 11:16:32 +01:00
MichaelandClaude Opus 4.6 cbfaee2dfb fix: mvtart sync ON CONFLICT DO NOTHING + doc ranking API
- Add ON CONFLICT DO NOTHING to mvtart insert to work with unique index
- Document ranking endpoints in API_DOCUMENTATION.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 11:03:28 +01:00
MichaelandClaude Opus 4.6 792ddc71d2 feat: add ranking table sync and API endpoints
Sync Ranking table from SQL Server to PostgreSQL with ranking_ca,
ranking_qte, ranking_mag_* metrics. Expose via /api/ranking and
integrate into /api/articles/:id/referentiel response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 10:54:04 +01:00
Michael 8cafc196cf feat: add API routes for sales performance metrics including turnover, hit parade, nomenclature, and product range analysis. 2026-03-19 10:30:56 +01:00
MichaelandClaude Sonnet 4.6 9bc372c959 fix: taux_marge toujours 0 - MntMvtTTC négatif pour les ventes, utiliser ABS(MntMvtHt)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 19:42:58 +01:00
MichaelandClaude Sonnet 4.6 f052529db6 fix: mouvements/types - grouper par GenreMvt uniquement (évite 28MB pour les tickets)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 16:52:45 +01:00
Michael c98f6834a8 feat: Implement article list, detail, and referential endpoints, and document the monthly article analysis endpoint. 2026-03-18 16:46:46 +01:00
Michael 2101606bb4 feat: implement stock management API endpoints and update the API documentation. 2026-03-18 12:03:18 +01:00
Michael 6dbfa2b32d Fix commandes: filter NULL artfou1_no_id, BIT->SMALLINT for recpb/recpbok 2026-03-18 11:05:22 +01:00
Michael 984ed4da5f Fix sync: null bytes, BIT→SMALLINT, DECIMAL complex types, NbJours safe int, error_msg column 2026-03-18 11:03:29 +01:00
Michael 20a1396810 Add dotenv to sync dependencies 2026-03-18 10:57:40 +01:00
Michael e66dff8420 Add sync dashboard (port 3001) with real-time progress tracking 2026-03-18 10:54:15 +01:00
Michael ab7a34253a Expose API port 3000 to host 2026-03-18 10:43:25 +01:00
Michael f1c5928152 Regenerate package-lock.json with pg dependency 2026-03-18 10:41:17 +01:00
Michael 80e8df7deb Add package-lock.json files for reproducible Docker builds 2026-03-18 10:40:35 +01:00
MichaelandClaude Sonnet 4.6 d565ed9f10 Initial commit : API Node.js + PostgreSQL + sync service Docker
- API Express/pg connectée à PostgreSQL (converti depuis mssql)
- 8 routes : articles, fournisseurs, commandes, stock, mouvements, performance, schema, sync
- Service sync nightly (mssql → pg, cron 3h00)
- Docker Compose : postgres + api + sync + frpc (tunnel sortant)
- Schéma PostgreSQL 17 tables dans postgres/init.sql

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 10:10:47 +01:00