From 16792094e3fe95abe5f339069856409943dd5625 Mon Sep 17 00:00:00 2001 From: Xor290 Date: Sat, 16 May 2026 12:16:29 +0200 Subject: [PATCH] chore: build --- backend/gestion/handlers/stats.go | 26 ++++++++++++------- backend/gestion/models/stats.go | 12 +++++---- frontend-admin/src/api/api_admin.ts | 2 ++ .../src/screens/admin/StatsScreen.tsx | 9 ++----- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/backend/gestion/handlers/stats.go b/backend/gestion/handlers/stats.go index ccdd1966..cd08295e 100644 --- a/backend/gestion/handlers/stats.go +++ b/backend/gestion/handlers/stats.go @@ -114,14 +114,18 @@ func GetAdminStats(c *gin.Context) { gdb.Raw(` SELECT ci.product_id, - ci.produit AS name, - SUM(ci.quantite) AS total_quantity, - COUNT(DISTINCT ci.command_id) AS order_count, - SUM(ci.prix * ci.quantite) AS revenue + ci.produit AS name, + SUM(ci.quantite) AS total_quantity, + COUNT(DISTINCT ci.command_id) AS order_count, + SUM(ci.prix * ci.quantite) AS revenue, + COALESCE(p.category, '') AS category, + COALESCE(cat.color, '#7c3aed') AS category_color FROM command_items ci JOIN commandes c ON c.id = ci.command_id + LEFT JOIN products p ON p.id = ci.product_id + LEFT JOIN categories cat ON cat.name = p.category WHERE c.status != 'cancelled' - GROUP BY ci.product_id, ci.produit + GROUP BY ci.product_id, ci.produit, p.category, cat.color ORDER BY total_quantity DESC LIMIT 15 `).Scan(&prodRows) @@ -130,11 +134,13 @@ func GetAdminStats(c *gin.Context) { topProductName := "" for i, r := range prodRows { topProducts[i] = gin.H{ - "product_id": r.ProductID, - "name": r.Name, - "quantity": r.Quantity, - "order_count": r.OrderCount, - "revenue": r.Revenue, + "product_id": r.ProductID, + "name": r.Name, + "quantity": r.Quantity, + "order_count": r.OrderCount, + "revenue": r.Revenue, + "category": r.Category, + "category_color": r.CategoryColor, } if i == 0 { topProductName = r.Name diff --git a/backend/gestion/models/stats.go b/backend/gestion/models/stats.go index 2a1a260a..2b707688 100644 --- a/backend/gestion/models/stats.go +++ b/backend/gestion/models/stats.go @@ -13,11 +13,13 @@ type DayRow struct { } type ProductRow struct { - ProductID int `gorm:"column:product_id"` - Name string `gorm:"column:name"` - Quantity float64 `gorm:"column:total_quantity"` - OrderCount int `gorm:"column:order_count"` - Revenue float64 `gorm:"column:revenue"` + ProductID int `gorm:"column:product_id"` + Name string `gorm:"column:name"` + Quantity float64 `gorm:"column:total_quantity"` + OrderCount int `gorm:"column:order_count"` + Revenue float64 `gorm:"column:revenue"` + Category string `gorm:"column:category"` + CategoryColor string `gorm:"column:category_color"` } type HourRow struct { diff --git a/frontend-admin/src/api/api_admin.ts b/frontend-admin/src/api/api_admin.ts index faa8f4fb..4ca2cab5 100644 --- a/frontend-admin/src/api/api_admin.ts +++ b/frontend-admin/src/api/api_admin.ts @@ -86,6 +86,8 @@ export interface ProductStat { quantity: number; order_count: number; revenue: number; + category: string; + category_color: string; } export interface AdminStats { diff --git a/frontend-admin/src/screens/admin/StatsScreen.tsx b/frontend-admin/src/screens/admin/StatsScreen.tsx index 1c25556f..7c6d8447 100644 --- a/frontend-admin/src/screens/admin/StatsScreen.tsx +++ b/frontend-admin/src/screens/admin/StatsScreen.tsx @@ -402,7 +402,7 @@ export default function StatsScreen() { {sortedProducts.length === 0 ? ( Aucune donnée produit ) : ( - sortedProducts.map((p, i) => { + sortedProducts.map((p) => { const val = prodSort === "orders" ? p.order_count : prodSort === "revenue" ? p.revenue @@ -411,18 +411,13 @@ export default function StatsScreen() { prodSort === "revenue" ? fmtEuro(p.revenue) : prodSort === "orders" ? `${p.order_count} cmd` : `×${fmtNum(p.quantity)}`; - const color = - i === 0 ? CHART_AMBER - : i === 1 ? "#94a3b8" - : i === 2 ? "#b45309" - : CHART_ACCENT; return ( );