chore: build

This commit is contained in:
2026-05-16 12:16:29 +02:00
parent f00b3a981d
commit 16792094e3
4 changed files with 27 additions and 22 deletions
+16 -10
View File
@@ -114,14 +114,18 @@ func GetAdminStats(c *gin.Context) {
gdb.Raw(` gdb.Raw(`
SELECT SELECT
ci.product_id, ci.product_id,
ci.produit AS name, ci.produit AS name,
SUM(ci.quantite) AS total_quantity, SUM(ci.quantite) AS total_quantity,
COUNT(DISTINCT ci.command_id) AS order_count, COUNT(DISTINCT ci.command_id) AS order_count,
SUM(ci.prix * ci.quantite) AS revenue SUM(ci.prix * ci.quantite) AS revenue,
COALESCE(p.category, '') AS category,
COALESCE(cat.color, '#7c3aed') AS category_color
FROM command_items ci FROM command_items ci
JOIN commandes c ON c.id = ci.command_id 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' 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 ORDER BY total_quantity DESC
LIMIT 15 LIMIT 15
`).Scan(&prodRows) `).Scan(&prodRows)
@@ -130,11 +134,13 @@ func GetAdminStats(c *gin.Context) {
topProductName := "" topProductName := ""
for i, r := range prodRows { for i, r := range prodRows {
topProducts[i] = gin.H{ topProducts[i] = gin.H{
"product_id": r.ProductID, "product_id": r.ProductID,
"name": r.Name, "name": r.Name,
"quantity": r.Quantity, "quantity": r.Quantity,
"order_count": r.OrderCount, "order_count": r.OrderCount,
"revenue": r.Revenue, "revenue": r.Revenue,
"category": r.Category,
"category_color": r.CategoryColor,
} }
if i == 0 { if i == 0 {
topProductName = r.Name topProductName = r.Name
+7 -5
View File
@@ -13,11 +13,13 @@ type DayRow struct {
} }
type ProductRow struct { type ProductRow struct {
ProductID int `gorm:"column:product_id"` ProductID int `gorm:"column:product_id"`
Name string `gorm:"column:name"` Name string `gorm:"column:name"`
Quantity float64 `gorm:"column:total_quantity"` Quantity float64 `gorm:"column:total_quantity"`
OrderCount int `gorm:"column:order_count"` OrderCount int `gorm:"column:order_count"`
Revenue float64 `gorm:"column:revenue"` Revenue float64 `gorm:"column:revenue"`
Category string `gorm:"column:category"`
CategoryColor string `gorm:"column:category_color"`
} }
type HourRow struct { type HourRow struct {
+2
View File
@@ -86,6 +86,8 @@ export interface ProductStat {
quantity: number; quantity: number;
order_count: number; order_count: number;
revenue: number; revenue: number;
category: string;
category_color: string;
} }
export interface AdminStats { export interface AdminStats {
@@ -402,7 +402,7 @@ export default function StatsScreen() {
{sortedProducts.length === 0 ? ( {sortedProducts.length === 0 ? (
<Text style={styles.emptyText}>Aucune donnée produit</Text> <Text style={styles.emptyText}>Aucune donnée produit</Text>
) : ( ) : (
sortedProducts.map((p, i) => { sortedProducts.map((p) => {
const val = const val =
prodSort === "orders" ? p.order_count prodSort === "orders" ? p.order_count
: prodSort === "revenue" ? p.revenue : prodSort === "revenue" ? p.revenue
@@ -411,18 +411,13 @@ export default function StatsScreen() {
prodSort === "revenue" ? fmtEuro(p.revenue) prodSort === "revenue" ? fmtEuro(p.revenue)
: prodSort === "orders" ? `${p.order_count} cmd` : prodSort === "orders" ? `${p.order_count} cmd`
: `×${fmtNum(p.quantity)}`; : `×${fmtNum(p.quantity)}`;
const color =
i === 0 ? CHART_AMBER
: i === 1 ? "#94a3b8"
: i === 2 ? "#b45309"
: CHART_ACCENT;
return ( return (
<HBar <HBar
key={p.product_id} key={p.product_id}
label={p.name} label={p.name}
value={val} value={val}
max={prodMax} max={prodMax}
color={color} color={p.category_color || CHART_ACCENT}
right={rightLabel} right={rightLabel}
/> />
); );