mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
Improve handling of yearly data to correctly process all years
Update year calculations to accurately reflect week and month assignments, particularly for transitional periods between years, and enhance API logging for debugging. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 0ec86cdf-a5be-4b0e-84a3-07b926f5cc80 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/0ec86cdf-a5be-4b0e-84a3-07b926f5cc80/ZJYssQp
This commit is contained in:
1 parent
55afb8eb70
commit
19c41f11c3
3 files changed
+40
-56
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useState } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Plus, Calendar, Edit, Trash2, Eye, Filter, Grid, List } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -166,62 +166,40 @@ export default function Publicities() {
|
||||
|
||||
// Year overview - Generate weeks for the selected year
|
||||
const getYearWeeks = () => {
|
||||
try {
|
||||
// SAFE: Use simple Date constructor to avoid issues with specific years
|
||||
const yearStart = new Date(selectedYear, 0, 1); // 1er janvier
|
||||
const yearEnd = new Date(selectedYear, 11, 31); // 31 décembre
|
||||
const yearStart = startOfYear(new Date(selectedYear, 0, 1));
|
||||
const yearEnd = endOfYear(new Date(selectedYear, 11, 31));
|
||||
|
||||
const weeks = eachWeekOfInterval(
|
||||
{ start: yearStart, end: yearEnd },
|
||||
{ weekStartsOn: 1 }
|
||||
);
|
||||
|
||||
return weeks.map((weekStart, index) => {
|
||||
const weekEnd = endOfWeek(weekStart, { weekStartsOn: 1 });
|
||||
const weekNumber = index + 1;
|
||||
|
||||
const weeks = eachWeekOfInterval(
|
||||
{ start: yearStart, end: yearEnd },
|
||||
{ weekStartsOn: 1 }
|
||||
);
|
||||
|
||||
// SAFE: Limit the number of weeks to prevent performance issues
|
||||
const limitedWeeks = weeks.slice(0, 54); // Maximum 54 semaines par année
|
||||
|
||||
console.log(`📅 getYearWeeks debug pour ${selectedYear}:`, {
|
||||
yearStart: format(yearStart, 'yyyy-MM-dd', { locale: fr }),
|
||||
yearEnd: format(yearEnd, 'yyyy-MM-dd', { locale: fr }),
|
||||
totalWeeks: limitedWeeks.length
|
||||
});
|
||||
|
||||
return limitedWeeks.map((weekStart, index) => {
|
||||
const weekEnd = endOfWeek(weekStart, { weekStartsOn: 1 });
|
||||
const weekNumber = index + 1;
|
||||
|
||||
// SIMPLE: Use week midpoint to determine month
|
||||
const weekMidpoint = new Date(weekStart.getTime() + (3 * 24 * 60 * 60 * 1000));
|
||||
const month = weekMidpoint.getMonth();
|
||||
|
||||
const participation = getWeekParticipation(weekStart, weekEnd);
|
||||
|
||||
return {
|
||||
weekStart,
|
||||
weekEnd,
|
||||
weekNumber,
|
||||
month,
|
||||
...participation
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`❌ Erreur getYearWeeks pour ${selectedYear}:`, error);
|
||||
return []; // Retourner un tableau vide en cas d'erreur
|
||||
}
|
||||
const weekMidpoint = new Date(weekStart.getTime() + (3.5 * 24 * 60 * 60 * 1000));
|
||||
let month = getMonth(weekMidpoint);
|
||||
|
||||
if (weekStart.getFullYear() < selectedYear && weekEnd.getFullYear() === selectedYear) {
|
||||
month = 0; // Janvier
|
||||
} else if (weekStart.getFullYear() === selectedYear && weekEnd.getFullYear() > selectedYear) {
|
||||
month = 11; // Décembre
|
||||
}
|
||||
|
||||
const participation = getWeekParticipation(weekStart, weekEnd);
|
||||
|
||||
return {
|
||||
weekStart,
|
||||
weekEnd,
|
||||
weekNumber,
|
||||
month,
|
||||
...participation
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
// SAFE: Only calculate yearWeeks if we have valid data
|
||||
const yearWeeks = useMemo(() => {
|
||||
try {
|
||||
if (!selectedYear || selectedYear < 1900 || selectedYear > 2100) {
|
||||
console.warn(`📅 Année invalide ignorée: ${selectedYear}`);
|
||||
return [];
|
||||
}
|
||||
return getYearWeeks();
|
||||
} catch (error) {
|
||||
console.error(`❌ Erreur calcul yearWeeks pour ${selectedYear}:`, error);
|
||||
return [];
|
||||
}
|
||||
}, [selectedYear, publicities]);
|
||||
const yearWeeks = getYearWeeks();
|
||||
|
||||
const handleView = (publicity: PublicityWithRelations) => {
|
||||
setSelectedPublicity(publicity);
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
# https://curl.se/docs/http-cookies.html
|
||||
# This file was generated by libcurl! Edit at your own risk.
|
||||
|
||||
#HttpOnly_localhost FALSE / FALSE 1755606176 connect.sid s%3AaJqqQRoUNbNkfzL7lhGGCPnIthRcKZfm.4pgA1BroGpVAnDGDfxkttSFwdekQMijVK6pPdmJ3KSY
|
||||
#HttpOnly_localhost FALSE / FALSE 1755861696 connect.sid s%3AI3ww2VSYnJCTbvhTLFfsKWucSCgLEXnH.Q%2FZB%2FqjpNIGDgcSjAp4O%2BHP03Qrmj71qIb8njdhnrK4
|
||||
+7
-1
@@ -2224,6 +2224,9 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
const { year, storeId } = req.query;
|
||||
const filterYear = year ? parseInt(year as string) : undefined;
|
||||
|
||||
// DEBUG: Log pour identifier le problème avec 2025
|
||||
console.log(`📋 API PUBLICITIES REQUEST:`, { year, filterYear, storeId, userRole: user.role });
|
||||
|
||||
let groupIds: number[] | undefined;
|
||||
|
||||
if (user.role === 'admin') {
|
||||
@@ -2234,10 +2237,13 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
groupIds = user.userGroups.map(ug => ug.groupId);
|
||||
}
|
||||
|
||||
console.log(`📋 CALLING storage.getPublicities:`, { filterYear, groupIds });
|
||||
const publicities = await storage.getPublicities(filterYear, groupIds);
|
||||
console.log(`📋 PUBLICITIES RETURNED:`, { count: publicities.length });
|
||||
|
||||
res.json(publicities);
|
||||
} catch (error) {
|
||||
console.error("Error fetching publicities:", error);
|
||||
console.error(`❌ ERROR fetching publicities for year ${year}:`, error);
|
||||
res.status(500).json({ message: "Failed to fetch publicities", error: (error as Error).message });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user