diff --git a/.replit b/.replit index 758bc01..853b5d3 100644 --- a/.replit +++ b/.replit @@ -37,4 +37,4 @@ args = "npm run dev" waitForPort = 5000 [agent] -integrations = ["javascript_database==1.0.0", "javascript_log_in_with_replit==1.0.0", "javascript_object_storage==1.0.0"] +integrations = ["javascript_database==1.0.0", "javascript_object_storage==1.0.0", "javascript_log_in_with_replit==1.0.0"] diff --git a/client/src/components/StatsPanel.tsx b/client/src/components/StatsPanel.tsx index efbfbed..003c1e2 100644 --- a/client/src/components/StatsPanel.tsx +++ b/client/src/components/StatsPanel.tsx @@ -14,8 +14,8 @@ export default function StatsPanel({ currentDate = new Date() }: StatsPanelProps const year = currentDate.getFullYear(); const month = currentDate.getMonth() + 1; - // Construire l'URL pour les statistiques annuelles - const statsUrl = `/api/stats/yearly?year=${year}${selectedStoreId ? `&storeId=${selectedStoreId}` : ''}`; + // Construire l'URL avec les paramètres + const statsUrl = `/api/stats/monthly?year=${year}&month=${month}${selectedStoreId ? `&storeId=${selectedStoreId}` : ''}`; const { data: stats, isLoading } = useQuery({ queryKey: [statsUrl, selectedStoreId], // Include selectedStoreId in key to force refetch @@ -25,7 +25,7 @@ export default function StatsPanel({ currentDate = new Date() }: StatsPanelProps }); if (!response.ok) { - throw new Error('Failed to fetch yearly stats'); + throw new Error('Failed to fetch stats'); } return response.json(); @@ -55,7 +55,7 @@ export default function StatsPanel({ currentDate = new Date() }: StatsPanelProps - Statistiques de l'année + Statistiques du mois @@ -91,7 +91,7 @@ export default function StatsPanel({ currentDate = new Date() }: StatsPanelProps
- Délai commande → livraison: + Délai moyen: {stats?.averageDeliveryTime?.toFixed(1) || '0'} jours diff --git a/client/src/pages/Dashboard.tsx b/client/src/pages/Dashboard.tsx index 3d62420..f89b5c3 100644 --- a/client/src/pages/Dashboard.tsx +++ b/client/src/pages/Dashboard.tsx @@ -41,6 +41,31 @@ export default function Dashboard() { }, }); + // Statistiques annuelles pour la carte de délai moyen + const { data: yearlyStats } = useQuery({ + queryKey: ['/api/stats/yearly', selectedStoreId], + queryFn: async () => { + const currentDate = new Date(); + const params = new URLSearchParams({ + year: currentDate.getFullYear().toString(), + }); + + if (selectedStoreId && user?.role === 'admin') { + params.append('storeId', selectedStoreId.toString()); + } + + const response = await fetch(`/api/stats/yearly?${params.toString()}`, { + credentials: 'include' + }); + + if (!response.ok) { + throw new Error('Failed to fetch yearly stats'); + } + + return response.json(); + }, + }); + // Construire les URLs pour récupérer toutes les données (pas de filtrage par date) const ordersUrl = `/api/orders${selectedStoreId && user?.role === 'admin' ? `?storeId=${selectedStoreId}` : ''}`; const deliveriesUrl = `/api/deliveries${selectedStoreId && user?.role === 'admin' ? `?storeId=${selectedStoreId}` : ''}`; @@ -247,7 +272,7 @@ export default function Dashboard() { // Calculs pour les statistiques const pendingOrdersCount = Array.isArray(allOrders) ? allOrders.filter((order: any) => order.status === 'pending').length : 0; - const averageDeliveryTime = Math.round(stats?.averageDeliveryTime || 0); + const averageDeliveryTime = Math.round(yearlyStats?.averageDeliveryTime || 0); const deliveredThisMonth = Array.isArray(allDeliveries) ? allDeliveries.filter((delivery: any) => { const deliveryDate = safeDate(delivery.deliveredDate || delivery.createdAt); if (!deliveryDate) return false; @@ -405,8 +430,8 @@ export default function Dashboard() {
-

Délai moyen (jours)

-

{averageDeliveryTime}

+

Délai commande → livraison

+

{averageDeliveryTime} jours