diff --git a/client/src/pages/Dashboard.tsx b/client/src/pages/Dashboard.tsx index 79726a9..463854a 100644 --- a/client/src/pages/Dashboard.tsx +++ b/client/src/pages/Dashboard.tsx @@ -224,6 +224,15 @@ export default function Dashboard() { return (dateB ? dateB.getTime() : 0) - (dateA ? dateA.getTime() : 0); }) .slice(0, 4) : []; // Afficher les 4 dernières commandes + + // Toutes les commandes en attente (peu importe la date) + const pendingOrders = Array.isArray(allOrders) ? allOrders + .filter((order: any) => order.status === 'pending') + .sort((a: any, b: any) => { + const dateA = safeDate(a.createdAt); + const dateB = safeDate(b.createdAt); + return (dateB ? dateB.getTime() : 0) - (dateA ? dateA.getTime() : 0); + }) : []; const upcomingDeliveries = Array.isArray(allDeliveries) ? allDeliveries .filter((d: any) => { @@ -237,16 +246,7 @@ export default function Dashboard() { console.log('🚚 Dashboard - Upcoming deliveries result:', upcomingDeliveries.length, upcomingDeliveries); // Calculs pour les statistiques - const pendingOrdersCount = Array.isArray(allOrders) ? allOrders.filter((order: any) => { - if (order.status !== 'pending') return false; - - // Vérifier si la commande est en pending depuis plus de 10 jours - const orderDate = safeDate(order.createdAt); - if (!orderDate) return false; - - const daysDiff = Math.floor((new Date().getTime() - orderDate.getTime()) / (1000 * 60 * 60 * 24)); - return daysDiff > 10; - }).length : 0; + const pendingOrdersCount = Array.isArray(allOrders) ? allOrders.filter((order: any) => order.status === 'pending').length : 0; const averageDeliveryTime = Math.round(stats?.averageDeliveryTime || 0); const deliveredThisMonth = Array.isArray(allDeliveries) ? allDeliveries.filter((delivery: any) => { const deliveryDate = safeDate(delivery.deliveredDate || delivery.createdAt); @@ -440,38 +440,52 @@ export default function Dashboard() { {/* Main Content Grid */}
- {/* Dernières Commandes */} + {/* Commandes en Attente */} - - Dernières Commandes + + Commandes en Attente + {pendingOrders.length > 0 && ( + + {pendingOrders.length} + + )} - {recentOrders.length > 0 ? recentOrders.map((order: any) => ( -
-
-
-
-

{order.supplier?.name}

-

{order.group?.name}

+ {pendingOrders.length > 0 ? pendingOrders.map((order: any) => { + // Calculer le nombre de jours en attente + const orderDate = safeDate(order.createdAt); + const daysPending = orderDate ? Math.floor((new Date().getTime() - orderDate.getTime()) / (1000 * 60 * 60 * 24)) : 0; + const isOverdue = daysPending > 10; + + return ( +
+
+
+
+

{order.supplier?.name}

+

{order.group?.name}

+
+
+
+ + {daysPending} jour{daysPending > 1 ? 's' : ''} + +

+ {safeFormat(order.plannedDate, "d MMM")} +

-
- - {order.status === 'delivered' ? 'Livrée' : order.status === 'planned' ? 'Planifiée' : 'En attente'} - -

- {safeFormat(order.plannedDate, "d MMM")} -

-
-
- )) : ( -

Aucune commande récente

+ ); + }) : ( +

Aucune commande en attente

)} @@ -554,18 +568,23 @@ export default function Dashboard() { Aucun magasin ) : (
- {participatingStores.map((participation: any) => ( - - {participation.group.name} - - ))} + {participatingStores.map((participation: any) => { + const isCurrentStore = selectedStoreId && participation.groupId === parseInt(selectedStoreId.toString()); + const groupColor = participation.group?.color || '#1976D2'; + + return ( + + {participation.group.name} + + ); + })}
)}