The previous ::boolean cast caused query failure when suspendu column
is not a native boolean type. Casting to ::text first handles all
column types (char, varchar, int, boolean).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add WHERE NOT COALESCE(af.suspendu::boolean, false) AND NOT COALESCE(a.suspendu::boolean, false)
to pgGetArticlesByFournisseur — products flagged as suspended in artfou1
or articles table are no longer shown in the grid.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Instead of unreliable preference=1, use artfou1.no_id DESC (most recently
added artfou1 entry) to identify the last supplier for each product.
Shows an amber warning icon in the Désignation column when the last
supplier ≠ current supplier view, with tooltip showing who to attribute
the sales to.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- FloatingSummaryBar: hide BulkAiAnalyzer button for non-admins
- AiInsightBlock: hide individual Analyser button for non-admins
- Both use useSession() to check role === "admin"
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- BulkAiAnalyzer: set isAnalyzing=true immediately on click (before
context fetch), so the spinner appears instantly instead of after
1-2 seconds of silence
- analyze/route.ts: if configured model returns 400/404 (e.g., deprecated
google/gemini-flash-1.5), automatically retry with google/gemini-2.0-flash-001
- batch-analyze/route.ts: same fallback logic
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove infinite grid loading, useInfiniteGrid hook, and server-side
pagination API route. Revert grid components to the simpler version
that avoids 2MB+ cache failures from unstable_cache.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace month dropdown with date picker (Du/Au) + Appliquer button
- Add fournisseur filter dropdown (client-side, all suppliers from current data)
- Totals update live when fournisseur filter changes
- SQL: use BETWEEN date range instead of TO_CHAR month match
- Create user button: proper 3-col form layout so button stays on one line
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Non-admin users see gamme as read-only badge (no select)
- Export button hidden for non-admin in grid
- Save drafts button hidden for non-admin
- Exports page hidden in sidebar for non-admin
- Create user button: explicit blue style (was unreadable with apple-btn-primary)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace last_reception CTE with direct LEFT JOIN artfou1 WHERE preference=true (fournisseur
principal de l'article). Use ABS(SUM(mntmvtttc)) instead of SUM(-mntmvtttc). Both fournisseur
and nomenclature queries now use LEFT JOIN to include all sold articles.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fouident is the canonical supplier identity table with correct names:
- D005 = 'DEPOT' (not 'BAZAR 5000' which was a historical fouadr1 alias)
- B0071 = 'BAZAR 5000' (suspended, actif=false)
- M0341 = 'MOREL' (not 'MOREL LORY')
Updated: pgGetFournisseurs, pgGetArticlesByFournisseur, pgGetCaByFournisseur
Removed the D005 CASE WHEN hardcode override (no longer needed).
Also remove fouadr1 JOIN from analytics query (replaced by fouident).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
D005 is the main active supplier (95k+ articles, fournisseur principal)
but its historical name in the FF Nancy ERP is 'BAZAR 5000' since 2004.
The store no longer associates this code with BAZAR 5000 — it is their
Dépôt. Override via CASE WHEN in SQL since the ERP name cannot be changed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previous approach (artfou1 DISTINCT ON no_id DESC) picked the most recent
artfou1 record, but artfou1 is a commercial reference table that may not
reflect actual current sourcing.
New approach: for each article, find the most recent reception movement
(genremvt IN (1,2)) in mvtart — this is the actual last delivery. Join
artfou1 to get the supplier code (ORDER BY datmvt DESC, af.no_id DESC to
break ties). This correctly attributes CA to whoever last physically
delivered the goods, not to a historical commercial reference.
Articles with no reception history are excluded (no INNER JOIN fallback
needed as all sold articles must have been received at least once).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DISTINCT ON with ORDER BY no_id ASC was picking the oldest supplier entry
(BAZAR 5000 historically), attributing CA to a supplier the store no longer
uses. Changing to DESC picks the most recently inserted artfou1 row, which
represents the current active supplier for each article.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
artfou1 has multiple rows per article (multi-supplier), causing each mvtart
movement to be counted N times in the JOIN. Use a CTE with DISTINCT ON
(art_no_id) ORDER BY no_id to pick one canonical supplier per article,
matching the same pattern used in pgGetArticlesByFournisseur.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- page.tsx: move formatCA into client component (functions not serializable
across server→client boundary in Next.js — root cause of 500)
- client.tsx: remove unused BarChart2 import
- client.tsx: replace useSearchParams() with direct URL construction to
avoid Suspense boundary requirement
- pg-ff-client: use OR conditions instead of IN() for Drizzle compatibility
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- pg-ff-client: replace ANY(ARRAY[...]) with IN(...) for Drizzle compatibility
- sidebar: change Analytics icon from BarChart2 (duplicate) to TrendingUp
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
EOF
- pg-ff-client: add pgGetCaByFournisseur() and pgGetCaByNomenclature()
returning CA TTC per site and month for monthly N vs N-1 comparison
- analytics/page.tsx: server component with pivot logic to reshape raw
query data into store-separated columns (292/579/total) with evolution %
- analytics/client.tsx: client controls (mode dropdown, month selector)
and responsive table with color-coded evolution badges
- sidebar: add "Analytics" link to navigation
Features:
- Switch between "Fournisseur" and "Nomenclature" views
- Select any month for comparison vs same month prior year
- Columns split by store: Frouard/Nancy (292), Houdemont (579), Total
- Each store shows: CA this month, CA N-1, evolution %
- Footer totals row matching sum of detail rows
- FR locale currency formatting (€)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- score-engine: add hard guard (wQty=0 && wCa=0 → score=0) before any
calculation to prevent edge cases (residual margin, percentile rank)
from producing non-zero scores on unsold articles
- score-engine: set inactivity=24 when product has never sold, so the
regularityMultiplier penalty (0.3) is correctly applied instead of 1
- pg-ff-client: remove erroneous negation on qte_recue — entry movements
have positive qtemvt in the DB, negating them produced negative values
that failed the > 0 check, hiding all entrées in tooltips and modals
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>