Commit Graph
179 Commits
Author SHA1 Message Date
Claude a45e09777b feat(api): métriques Qlik + gamme serveur à jour, et doc de connexion dans Paramètres
L'instantané grid_rows fige la ligne au moment du calcul, mais deux données
évoluent indépendamment et doivent refléter l'état courant :

- Métriques réseau Qlik : qlik_network_metrics est alimentée par les syncs et
  les recherches réseau, hors du calcul de grille. Relues à chaque appel et
  exposées dans `network` (null quand le produit n'en a pas). Les colonnes
  caReseau/qteReseau/... de la ligne sont réalignées dessus.
- Gamme serveur : codeGamme peut être surchargée par un snapshot de session.
  L'API expose `codeGammeServeur`, la gamme NON modifiée telle qu'elle est en
  base PostgreSQL, relue à chaque appel. codeGammeInit est gardé aligné.

Ajout de pgGetGammesByCodeins() : variante sans jointure artfou1, nécessaire
car la recherche de l'API est transversale (pas de fournisseur connu).

Ce n'est pas un recalcul : deux lectures indexées bornées à la page courante
(500 lignes max). Mesuré à ~20 ms, soit le même coût que sans enrichissement.
Paramètre enrich=0 pour servir l'instantané brut.

Paramètres → nouvelle section « API CollectFlow — Connexion » : URL de base
déduite de l'origine, en-têtes d'authentification, liste des endpoints et des
paramètres, exemples curl copiables, lien vers openapi.json.

Vérifié sur PostgreSQL local avec un instantané volontairement périmé :
gamme snapshot A → serveur C, caReseau 111 → 990000, produit sans données
réseau → network null, produit sans gamme → codeGammeServeur null, enrich=0
redonnant bien les valeurs figées, et toujours zéro recalcul.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y26nRZxTR57K7h8yqsF675
2026-08-05 10:14:21 +00:00
Claude e79d7e51da feat(api): API CollectFlow /api/v1 — lecture de la grille et recherche
Les données de la grille (ventes 12 mois, stock, marges, gammes, métriques
réseau Qlik) n'étaient accessibles par aucun moyen programmatique, et
getProductRows() exige un fournisseur : chercher un produit sans le connaître
était impossible.

Contrainte de conception : l'API ne recalcule jamais rien. La grille était
reconstruite en direct et gardée seulement 10 min en mémoire ; une API qui
appellerait getProductRows() serait lente et imprévisible. On persiste donc
le résultat d'un calcul qui a déjà lieu, et on le sert.

- Table grid_rows : colonnes scalaires (filtre/tri/recherche en SQL) +
  payload jsonb du ProductRow complet. Remplie en effet de bord NON bloquant
  par getProductRows(), purge des articles disparus via computed_at. Survit
  aux redémarrages, contrairement au cache mémoire.
- Endpoints /api/v1 : fournisseurs, grid, products/search (transversale, tous
  fournisseurs), products/:codein, network/:codeCentrale, openapi.json.
  Pagination, tri sur liste blanche, projection de champs, validation zod.
  202 not_ready si un fournisseur n'a pas encore d'instantané.
- Authentification double : clé d'API (X-API-Key ou Bearer, SHA-256 en base,
  révocable) ou session existante. Le middleware exempte /api/v1 — sans quoi
  un script recevait une redirection 302 vers /login au lieu d'un 401 JSON.
- Gestion des clés dans /settings (server actions, clé affichée une seule fois).

Vérifié contre une base PostgreSQL locale : 401 JSON sans clé, 401 sur clé
révoquée, recherche renvoyant plusieurs fournisseurs, upsert + purge, et
24 appels /api/v1 sans déclencher un seul recalcul (l'ancienne route
/api/grid/rows en déclenche un à chaque appel).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y26nRZxTR57K7h8yqsF675
2026-08-05 10:14:21 +00:00
Claude 1633d5e407 fix(qlik-sync): message explicite quand le serveur Qlik est en OOM
Quand l'app Qlik ne peut pas se charger faute de RAM serveur (code 6
'Not enough memory to load file' / code 3002 'File corrupted' / 'Out of
memory'), le job affiche un message clair ('Serveur Qlik saturé…') au
lieu de l'erreur technique. Ce n'est pas un bug CollectFlow : le sync
échoue à l'ouverture de l'app, avant toute requête.
2026-07-24 08:11:58 +00:00
Claude b7de347a99 fix(grid,hit-parade): convention de signe nette + lint React Compiler
- Grille (fallback API mensuel) : Math.abs remplacé par la négation sur
  qte_vendue/ca_ht (négatifs côté API) — les retours clients restent
  déduits au lieu d'être inversés en positif, même convention que le SQL.
- Hit Parade (client) : ColHeader extrait hors du composant (erreur
  'Cannot create components during render'), useMemo déplacés avant
  exportToExcel pour préserver la mémoïsation React Compiler, variable
  idx inutilisée supprimée. ESLint 0 erreur, build OK.
2026-07-06 20:28:03 +00:00
Claude d733755659 fix(hit-parade): ventes nettes par magasin — corrige les chiffres faussés (579)
La requête Hit Parade divergeait du calcul canonique de la Grille :
- SUM(ABS(qtemvt)) additionnait les retours clients comme des ventes au
  lieu de les déduire → quantités et CA gonflés sur le magasin ayant des
  retours/avoirs sur la période (visible sur 579).
- ABS(SUM(mntmvtttc)) inversait le signe d'un CA net négatif.
- GROUP BY no_id + jointure artfou1 preference=1 non dédupliquée pouvait
  produire plusieurs lignes par (codein, site), écrasées par le pivot.

Corrections :
- Hit Parade : ventes nettes SUM(-qtemvt) / SUM(-mntmvtttc), agrégation
  par (codein, site), fournisseur préféré via LATERAL ... LIMIT 1,
  stock agrégé par codein ; pivot en accumulation (+=) par sécurité.
- Analytics (même classe de bug) : pgGetCaByFournisseur et
  pgGetCaByNomenclature passent en CA net ; jointure fournisseur
  dédupliquée (LATERAL LIMIT 1) pour éviter le double comptage.
- Gestion de stock : pgGetStockNegatif et pgGetSansVente6Mois dédupliquent
  le fournisseur préféré (LATERAL LIMIT 1) pour éviter les lignes en double.

Audit complet du mapping par magasin (292/579) côté client : aucun champ
inversé (hit-parade, analytics, dashboard, grid, heatmap). Build OK.
2026-07-06 15:55:43 +00:00
R0m1k3 abac5c5ee5 perf(qlik): optimize network sync extraction 2026-06-22 09:58:49 +00:00
R0m1k3 850852912f fix(qlik): track async sync job status 2026-06-21 19:08:04 +00:00
R0m1k3 6d27c7935d fix: align qlik grid extraction date range 2026-06-21 11:26:49 +00:00
MichaelandClaude Opus 4.8 d54c3ae520 feat(qlik): add step-by-step logging to sync extraction
Logs each stage (PG codes -> NTLM session -> chromium -> csrf token
-> in-page ws -> OpenDoc -> SelectValues -> cube size -> rows) so a
hanging sync reveals where it stalls. Forwards in-page browser console
to the node logger.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 08:14:12 +02:00
MichaelandClaude Opus 4.8 694b780160 feat(qlik): extract network data via Playwright (in-page ws)
The Qlik proxy refuses a raw server-side websocket (403, even internally), so
extraction now runs through headless Chromium (NTLM via httpCredentials, like
the hermes agent) and opens the Engine websocket in-page — same origin, which
the proxy accepts. Efficient: selects the supplier's article codes on the
"Article Code" field so the hypercube returns only those rows.

- qlik-playwright.ts: browser singleton, in-page hypercube extraction (paginated)
- /api/qlik/sync: use the Playwright extractor
- Dockerfile: install chromium + headless deps, PLAYWRIGHT_CHROMIUM_PATH, copy playwright-core
- deps: playwright-core (lockfiles synced)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 23:54:03 +02:00
MichaelandClaude Opus 4.8 abed369bfb feat(settings): configure Qlik credentials in the UI
Add a "Qlik Sense — Données réseau" section in Paramètres (host/user/password
+ Save & Test buttons), stored in data/.db-config.json. qlik-client reads this
file first (env fallback), so no env vars needed for the sync.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 23:28:55 +02:00
MichaelandClaude Opus 4.8 aee968d30f feat(grid): replace ranking/AI/score with Qlik network data
Remove ranking, AI analysis (routes + ai-copilot module), and score-engine
from the grid. Add Qlik Sense network metrics (CA, Qte, nb magasins per
product) joined by code centrale (articles.artcentrale).

- qlik-client.ts: NTLM + ticket SSO auth, QIX hypercube extraction (master items)
- qlik-network-cache.ts + qlik_network_metrics table (db-init): cache layer
- POST /api/qlik/sync?fournisseur=: per-supplier sync into cache
- SyncQlikButton: per-supplier sync, grid reload, last-update date display
- get-product-rows Phase 8: enrich rows with cached network metrics
- heatmap-grid: CA reseau / Qte reseau / Magasins (/270) / % presence columns
- discovery: app 9872ee6e, master items CA N / Quantite N / Magasin Ventes Nb N
- deps: httpntlm, ws

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 22:52:39 +02:00
Claude 26976ccea2 fix(build): supprime la dépendance réseau à Google Fonts au build + rend /commandes-auto dynamique
Le build Docker échouait sur le fetch de la police Inter via next/font/google
(accès réseau/TLS indisponible pendant 'next build').

- layout.tsx : charge Inter via <link> côté navigateur (plus de fetch au build),
  avec fallback système ; --font-sans défini dans globals.css (@theme).
- /commandes-auto : export dynamic = 'force-dynamic' (données live DB + API,
  jamais prérendues au build).
- listCadences : résilient si la DB est injoignable (retourne []).
2026-06-03 08:35:44 +00:00
Claude ae0d8d3a4c feat(commandes-auto): cadencier d'alertes de commande par fournisseur et magasin
Ajoute un onglet "Cadencier / Alertes" dans la page Commandes auto.
Depuis la liste des fournisseurs, on active un fournisseur en alerte de
commande sur un magasin (292/579) avec une fréquence en X semaines,
gérée indépendamment par magasin.

L'échéance est calculée à partir de la dernière réception réelle
(mvtart, genremvt 1/2, fournisseur principal artfou1.preference=1) +
X semaines. Statut: à commander / bientôt / OK, avec temps restant.

- Table commande_cadences (schema + db-init)
- pgGetDerniereReceptionParFournisseur (mvtart par fournisseur/site)
- Server actions CRUD (list/upsert/toggle/remove)
- UI à onglets + cadencier (ajout, édition intervalle, activer/supprimer)
2026-06-03 08:19:50 +00:00
Michael e6f40d3d81 feat(grid): implement product streaming with JSON chunks for grid client 2026-05-26 13:31:26 +02:00
MichaelandClaude Sonnet 4.6 b67da87b3e feat: add Excel export button to hit parade page
Exports the currently filtered and sorted table (including totals row) to an .xlsx file named with the selected date range. Uses the xlsx library.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 10:14:52 +02:00
Michael e1d79e66ed feat: implement client-side dashboard for publicites with filtering, sorting, and pagination views 2026-04-24 13:22:16 +02:00
Michael bd8339b27d feat: add pg-ff-client to replace HTTP API calls with bulk PostgreSQL queries 2026-04-23 10:36:37 +02:00
MichaelandClaude Opus 4.7 42e39a1c2b feat: add stock and supplier info to dashboard top 10 cards
Enrich DashboardTopItem with stock and fournisseur fields via PostgreSQL,
then display them under each article in the dashboard top CA/Qte/Marge tables.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 10:10:52 +02:00
MichaelandClaude Sonnet 4.6 fedfbadc35 fix: use derniere_vente instead of derniere_entree in Excel export of 6-month tab
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:37:31 +02:00
MichaelandClaude Sonnet 4.6 dbf2164880 fix: align Excel export format of "Sans vente 6 mois" with "Entrées sans vente"
Columns: CODEIN | GENCODE (empty) | QTE | CODMV (412) | Dernière entrée

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:35:55 +02:00
MichaelandClaude Sonnet 4.6 9a9b881d19 feat: add derniere_entree column and filter recent stock entries on 6-month tab
- Exclude products with a stock entry in the last 6 months (NOT EXISTS subquery)
- Add derniere_entree subquery to SQL (last genremvt 1/2 movement date)
- Display derniere_entree column in table and Excel export

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:25:17 +02:00
MichaelandClaude Sonnet 4.6 71241fe0e6 feat: add "Sans vente 6 mois" tab to Gestion de Stock page
New SQL query pgGetSansVente6Mois returns products with available
stock (qte > 0) whose last sale was over 6 months ago or never.
Third tab added with filtering by supplier, search, sort, and Excel export.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:17:56 +02:00
Michael d955c17af2 feat: add probe for N/A suppliers to retrieve franco details in GET route 2026-04-13 15:47:14 +02:00
Michael 33ff92aec0 feat: add commandes-auto audit with franco_ht filtering to GET route 2026-04-13 15:43:37 +02:00
Michael 2cbf8a753a feat: add foucad sample retrieval and columns to franco diagnostic 2026-04-13 15:40:56 +02:00
Michael 457903a611 feat: add franco diagnostic and raw commandes-auto retrieval in GET route 2026-04-13 15:34:26 +02:00
Michael 462eef182e feat: enhance FrancoCell logic and add mapping function for PgCommandeAutoRow 2026-04-13 15:31:25 +02:00
Michael fdc2d0ed39 feat: update Excel export headers and data formatting in stock management tabs 2026-04-13 11:27:45 +02:00
Michael 3027a8ab19 feat: add search functionality to stock management tabs 2026-04-13 11:06:42 +02:00
MichaelandClaude Sonnet 4.6 228c8ef20c feat: admin AI chat — FF Nancy API integration, Google AI support, markdown rendering
- Replace SQL tools with call_api tool hitting FF Nancy REST endpoints
- Add Google AI Studio provider support alongside OpenRouter
- Load AI provider config (openrouter/google) from saved settings
- Add model selector loaded dynamically from OpenRouter and Google AI APIs
- Add HTML-to-Markdown conversion for models that return HTML
- Enrich system prompt with full FF Nancy API docs, PA/PRMP field locations
- Fix streaming: single generateContentStream pass for Google AI (no double call)
- Increase max_tokens to 8192 and tool loop to 10 rounds

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 16:12:37 +02:00
Michael 8dd2394893 feat: implement admin AI chat route with SQL execution and database schema context 2026-04-10 16:03:00 +02:00
Michael 6e10364922 feat: implement admin AI chat API with SQL execution tools and database schema context 2026-04-10 15:44:59 +02:00
Michael 0c1d3c10bd feat: implement admin AI chat API with SQL execution and schema retrieval tools 2026-04-10 15:23:46 +02:00
Michael 4994d55ffc feat: implement admin AI chat route with SQL execution tools and multi-provider support 2026-04-10 15:16:34 +02:00
Michael ade120a9da feat: add settings page with database configuration, AI provider management, and FF API status tracking. 2026-04-10 15:05:51 +02:00
Michael d0ca0c3602 feat: implement database and AI provider configuration settings with Google GenAI integration 2026-04-10 15:00:47 +02:00
Michael 7372885e48 feat: implement AI chat interface with markdown support and model cost tracking 2026-04-10 13:55:56 +02:00
Michael 9f05eb9bc9 feat: implement admin AI chat API with SQL execution and database schema tools 2026-04-10 13:51:18 +02:00
Michael 6891aff668 feat: implement admin AI chat route with SQL execution and database schema access tools 2026-04-10 13:38:26 +02:00
Michael 63d89e5029 feat: add API endpoint to fetch and format OpenRouter models list 2026-04-10 13:35:54 +02:00
Michael d9859ff9e0 feat: add API route to fetch and format OpenRouter models with pricing data 2026-04-10 13:29:31 +02:00
Michael 78cdc608d0 feat: implement admin AI chat interface with model selection and real-time cost tracking 2026-04-10 13:23:35 +02:00
Michael f21f38f805 feat: add client-side component to display and filter automatic order data by site 2026-04-08 16:47:39 +02:00
Michael 638c4b5f3b feat: implement direct PostgreSQL data access and API proxy for automated orders 2026-04-08 16:37:42 +02:00
Michael 70c425befb feat: implement sidebar navigation and automated order management module with PostgreSQL client integration 2026-04-08 15:53:59 +02:00
Michael ff81bc1fc4 feat: implement interactive stock negative and no-sales data table with filtering, sorting, and Excel export functionality 2026-04-08 09:59:14 +02:00
Michael 5a13640884 feat: implement pg-ff-client to replace per-article HTTP calls with bulk PostgreSQL queries 2026-04-07 17:36:27 +02:00
Michael e8fb472a9f feat: implement shared LoadingModal component and integrate into dashboard route loading states 2026-04-07 17:16:33 +02:00
Michael 2264ced494 feat: add client-side data table components for negative stock and stagnant inventory with sorting and Excel export capabilities 2026-04-07 16:56:57 +02:00