diff --git a/.replit b/.replit index ba2f351..d234c98 100644 --- a/.replit +++ b/.replit @@ -27,6 +27,10 @@ externalPort = 3002 localPort = 41343 externalPort = 3001 +[[ports]] +localPort = 43431 +externalPort = 3003 + [workflows] runButton = "Project" diff --git a/attached_assets/image_1758554462272.png b/attached_assets/image_1758554462272.png new file mode 100644 index 0000000..9014731 Binary files /dev/null and b/attached_assets/image_1758554462272.png differ diff --git a/client/src/pages/Analytics.tsx b/client/src/pages/Analytics.tsx index dcd2554..b190313 100644 --- a/client/src/pages/Analytics.tsx +++ b/client/src/pages/Analytics.tsx @@ -20,10 +20,10 @@ export default function Analytics() { const { user } = useAuthUnified(); const { selectedStoreId } = useStore(); - // États des filtres + // États des filtres - élargir la période par défaut pour inclure plus de données const [dateRange, setDateRange] = useState({ - from: startOfMonth(new Date()), - to: endOfMonth(new Date()) + from: addDays(new Date(), -365), // Dernière année + to: new Date() }); const [selectedSuppliers, setSelectedSuppliers] = useState([]); const [selectedStores, setSelectedStores] = useState([]); @@ -56,11 +56,17 @@ export default function Analytics() { const { data: summary, isLoading: summaryLoading } = useQuery({ queryKey: ['/api/analytics/summary', queryParams], queryFn: async () => { + console.log('📊 [ANALYTICS] Fetching summary with params:', queryParams); const response = await fetch(`/api/analytics/summary?${queryParams}`, { credentials: 'include' }); - if (!response.ok) throw new Error('Failed to fetch summary'); - return response.json(); + if (!response.ok) { + console.error('❌ [ANALYTICS] Summary fetch failed:', response.status, response.statusText); + throw new Error('Failed to fetch summary'); + } + const data = await response.json(); + console.log('✅ [ANALYTICS] Summary data received:', data); + return data; }, refetchInterval: isRefreshing ? 30000 : false }); @@ -68,11 +74,18 @@ export default function Analytics() { const { data: timeseries } = useQuery({ queryKey: ['/api/analytics/timeseries', queryParams, granularity], queryFn: async () => { - const response = await fetch(`/api/analytics/timeseries?${queryParams}&granularity=${granularity}`, { + const url = `/api/analytics/timeseries?${queryParams}&granularity=${granularity}`; + console.log('📊 [ANALYTICS] Fetching timeseries:', url); + const response = await fetch(url, { credentials: 'include' }); - if (!response.ok) throw new Error('Failed to fetch timeseries'); - return response.json(); + if (!response.ok) { + console.error('❌ [ANALYTICS] Timeseries fetch failed:', response.status, response.statusText); + throw new Error('Failed to fetch timeseries'); + } + const data = await response.json(); + console.log('✅ [ANALYTICS] Timeseries data received:', data?.length || 0, 'entries'); + return data; } }); @@ -271,7 +284,7 @@ export default function Analytics() { Tous les fournisseurs - {suppliers?.map((supplier: any) => ( + {Array.isArray(suppliers) && suppliers.map((supplier: any) => ( {selectedSuppliers.includes(supplier.id) ? "✓ " : ""}{supplier.name} @@ -304,7 +317,7 @@ export default function Analytics() { Tous les magasins - {stores?.map((store: any) => ( + {Array.isArray(stores) && stores.map((store: any) => ( {selectedStores.includes(store.id) ? "✓ " : ""}{store.name} @@ -391,17 +404,27 @@ export default function Analytics() { Commandes vs Livraisons - - - - - - - - - - - + {Array.isArray(timeseries) && timeseries.length > 0 ? ( + + + + + + + + + + + + ) : ( +
+
+ +

Aucune donnée temporelle

+

Vérifiez la période sélectionnée

+
+
+ )}
@@ -415,25 +438,35 @@ export default function Analytics() { Top 5 fournisseurs - - - entry.supplierName} - outerRadius={80} - fill="#8884d8" - dataKey="deliveries" - > - {bySupplier?.slice(0, 5).map((entry: any, index: number) => ( - - ))} - - - - + {Array.isArray(bySupplier) && bySupplier.length > 0 ? ( + + + entry.supplierName} + outerRadius={80} + fill="#8884d8" + dataKey="deliveries" + > + {bySupplier.slice(0, 5).map((entry: any, index: number) => ( + + ))} + + + + + ) : ( +
+
+ +

Aucune donnée fournisseur

+

Aucune livraison trouvée

+
+
+ )}
@@ -447,17 +480,27 @@ export default function Analytics() { Commandes et livraisons - - - - - - - - - - - + {Array.isArray(byStore) && byStore.length > 0 ? ( + + + + + + + + + + + + ) : ( +
+
+ +

Aucune donnée magasin

+

Aucune activité détectée

+
+
+ )}
@@ -472,25 +515,33 @@ export default function Analytics() {
- {summary?.topSuppliers?.map((supplier: any, index: number) => ( -
-
- - {index + 1} - -
-

{supplier.name}

-

- {supplier.count} livraisons • {supplier.amount.toFixed(2)}€ -

+ {Array.isArray(summary?.topSuppliers) && summary.topSuppliers.length > 0 ? ( + summary.topSuppliers.map((supplier: any, index: number) => ( +
+
+ + {index + 1} + +
+

{supplier.name}

+

+ {supplier.count} livraisons • {supplier.amount.toFixed(2)}€ +

+
+
+
+
{supplier.count}
+
livraisons
-
-
{supplier.count}
-
livraisons
-
+ )) + ) : ( +
+ +

Aucune donnée disponible pour la période sélectionnée

+

Essayez d'élargir la plage de dates

- ))} + )}