Improve order and delivery synchronization for accurate status tracking

Update the calendar page to fetch all orders and deliveries without date filters, enriching them for accurate analysis and specifically targeting CMD-55 to diagnose and fix status discrepancies.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: a8a78c07-e900-425c-a577-5b4c5894379d
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/a8a78c07-e900-425c-a577-5b4c5894379d/KuIk8gU
This commit is contained in:
michaelschal committed 2025-08-11 20:43:52 +00:00
1 parent 4422a561c7
commit 213208d48f
3 files changed
+233 -17

No files matched your search

@@ -0,0 +1,201 @@
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
Deliveries API called with: {
startDate: undefined,
endDate: undefined,
storeId: undefined,
withBL: undefined,
userRole: 'admin'
}
Admin filtering deliveries with groupIds: undefined
Fetching all deliveries
Deliveries returned: 80 items
GET /api/deliveries 304 in 28ms
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
📄 SPA: Serving index.html for /[object%20Object]
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
📄 SPA: Serving index.html for /[object%20Object]
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
📄 SPA: Serving index.html for /[object%20Object]
🔍 getUserWithGroups called for user: admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
Orders API called with: {
startDate: '2025-08-01',
endDate: '2025-08-31',
storeId: '1',
userRole: 'admin'
}
Admin filtering with groupIds: [ 1 ]
Fetching orders by date range: 2025-08-01 to 2025-08-31
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
🔍 getUserWithGroups called for user: admin_local
🔍 Querying user_groups for user: admin_local
Orders returned: 9 items
🔍 Found 0 group assignments for user admin_local
🔍 Raw query result: []
✅ Processed 0 groups for user admin_local
Deliveries API called with: {
startDate: '2025-08-01',
endDate: '2025-08-31',
storeId: '1',
withBL: undefined,
userRole: 'admin'
}
Admin filtering deliveries with groupIds: [ 1 ]
Fetching deliveries by date range: 2025-08-01 to 2025-08-31
GET /api/orders 304 in 23ms
Deliveries returned: 20 items
GET /api/deliveries 304 in 31ms
HEAD /api/health 200 in 0ms
Binary file not shown.

After

Width:  |  Height:  |  Size: 282 KiB

+32 -17
View File
@@ -149,38 +149,53 @@ export default function Calendar() {
try {
console.log('🔄 Starting manual sync of order-delivery status...');
// Solution temporaire : récupérer TOUTES les données et faire la sync côté client
// Solution temporaire : récupérer TOUTES les données sans filtres de dates
console.log('📡 Fetching ALL orders (no date filter)...');
const ordersResponse = await fetch('/api/orders', { credentials: 'include' });
const allOrders = await ordersResponse.json();
const filteredOrders = await ordersResponse.json();
// Récupérer aussi toutes les livraisons pour avoir une vue complète
console.log('📡 Fetching ALL deliveries (no date filter)...');
const deliveriesResponse = await fetch('/api/deliveries', { credentials: 'include' });
const allDeliveries = await deliveriesResponse.json();
// Enrichir les commandes avec leurs livraisons pour avoir les bonnes relations
const enrichedOrders = filteredOrders.map(order => {
const orderDeliveries = allDeliveries.filter(delivery => delivery.orderId === order.id);
return {
...order,
deliveries: orderDeliveries
};
});
console.log('📊 Data loaded for sync:', {
orders: allOrders.length,
deliveries: allDeliveries.length,
filteredOrders: filteredOrders.length,
enrichedOrders: enrichedOrders.length,
allDeliveries: allDeliveries.length,
deliveredDeliveries: allDeliveries.filter(d => d.status === 'delivered').length
});
// Chercher spécifiquement CMD-55
const cmd55 = allOrders.find(o => o.id === 55);
if (cmd55) {
console.log('🎯 CMD-55 Details:', {
id: cmd55.id,
status: cmd55.status,
deliveries: cmd55.deliveries?.length || 0,
deliveryDetails: cmd55.deliveries || []
});
} else {
console.log('❌ CMD-55 not found in current orders');
}
const cmd55 = enrichedOrders.find(o => o.id === 55);
const cmd55Deliveries = allDeliveries.filter(d => d.orderId === 55);
console.log('🎯 CMD-55 Analysis:', {
foundInOrders: !!cmd55,
cmd55Status: cmd55?.status || 'NOT_FOUND',
cmd55Deliveries: cmd55Deliveries.length,
deliveryStatuses: cmd55Deliveries.map(d => ({
id: d.id,
status: d.status,
deliveredDate: d.deliveredDate,
scheduledDate: d.scheduledDate
}))
});
let problematicOrders = 0;
let fixedOrders = 0;
// Parcourir les commandes et identifier celles à corriger
for (const order of allOrders) {
// Parcourir les commandes enrichies et identifier celles à corriger
for (const order of enrichedOrders) {
console.log(`🔍 Analyzing order #CMD-${order.id}:`, {
status: order.status,
deliveries: order.deliveries?.length || 0,