From d418fda3c966ae0ab78451c384bd2504f82bcd1f Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Wed, 13 Aug 2025 08:32:46 +0000 Subject: [PATCH] Improve delivery reconciliation by ensuring group data is fetched correctly Refactor DatabaseStorage to explicitly select group columns and add webhook URLs to test groups in MemStorage. Also includes debug logging in BLReconciliation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c52a701b-4841-4d00-b8cf-5a41c12abdf3 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/c52a701b-4841-4d00-b8cf-5a41c12abdf3/oAFKRkH --- client/src/pages/BLReconciliation.tsx | 12 +++ server/storage.ts | 127 ++++++++++++++++++++++++-- 2 files changed, 132 insertions(+), 7 deletions(-) diff --git a/client/src/pages/BLReconciliation.tsx b/client/src/pages/BLReconciliation.tsx index 1dc304f..4931724 100644 --- a/client/src/pages/BLReconciliation.tsx +++ b/client/src/pages/BLReconciliation.tsx @@ -222,6 +222,18 @@ export default function BLReconciliation() { // Et il faut qu'il y ait un magasin assigné avec un webhook const hasValidGroup = delivery.group && delivery.group.webhookUrl; + // Debug temporaire pour diagnostiquer le problème + if (delivery && delivery.supplier?.name) { + console.log(`🔍 Debug bouton facture pour ${delivery.supplier.name}:`, { + isNotValidated, + hasNoInvoiceReference, + hasValidGroup, + group: delivery.group, + webhookUrl: delivery.group?.webhookUrl, + shouldShow: (isNotValidated || hasNoInvoiceReference) && hasValidGroup + }); + } + return (isNotValidated || hasNoInvoiceReference) && hasValidGroup; }; diff --git a/server/storage.ts b/server/storage.ts index 3177c24..493d515 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -543,7 +543,14 @@ export class DatabaseStorage implements IStorage { const results = await db.query.deliveries.findMany({ with: { supplier: true, - group: true, + group: { + columns: { + id: true, + name: true, + color: true, + webhookUrl: true, + } + }, creator: true, order: true, }, @@ -572,7 +579,14 @@ export class DatabaseStorage implements IStorage { const results = await db.query.deliveries.findMany({ with: { supplier: true, - group: true, + group: { + columns: { + id: true, + name: true, + color: true, + webhookUrl: true, + } + }, creator: true, order: true, }, @@ -591,7 +605,14 @@ export class DatabaseStorage implements IStorage { where: eq(deliveries.id, id), with: { supplier: true, - group: true, + group: { + columns: { + id: true, + name: true, + color: true, + webhookUrl: true, + } + }, creator: true, order: true, }, @@ -2034,8 +2055,8 @@ class MemStorage implements IStorage { // Add test groups const testGroups = [ - { id: 1, name: 'Magasin A', color: '#FF5733', createdAt: new Date(), updatedAt: new Date() }, - { id: 2, name: 'Magasin B', color: '#33FF57', createdAt: new Date(), updatedAt: new Date() }, + { id: 1, name: 'Magasin A', color: '#FF5733', webhookUrl: 'https://webhook.site/test-facture-magasin-a', createdAt: new Date(), updatedAt: new Date() }, + { id: 2, name: 'Magasin B', color: '#33FF57', webhookUrl: 'https://webhook.site/test-facture-magasin-b', createdAt: new Date(), updatedAt: new Date() }, { id: 3, name: 'Magasin C', color: '#3357FF', createdAt: new Date(), updatedAt: new Date() } ]; testGroups.forEach(group => this.groups.set(group.id, group as Group)); @@ -2076,6 +2097,63 @@ class MemStorage implements IStorage { { publicityId: 2, groupId: 3, createdAt: new Date() } ); + // Add test suppliers + const testSuppliers = [ + { id: 1, name: 'Fournisseur Test A', automaticReconciliation: false, createdAt: new Date(), updatedAt: new Date() }, + { id: 2, name: 'Fournisseur Test B', automaticReconciliation: true, createdAt: new Date(), updatedAt: new Date() } + ]; + testSuppliers.forEach(supplier => this.suppliers.set(supplier.id, supplier as Supplier)); + + // Add test deliveries + const testDeliveries = [ + { + id: 1, + supplierId: 1, + groupId: 1, + blNumber: 'BL001', + status: 'delivered', + scheduledDate: '2025-08-10', + deliveredDate: '2025-08-10', + blAmount: '150.50', + reconciled: false, + createdBy: 'admin_dev', + createdAt: new Date(), + updatedAt: new Date() + }, + { + id: 2, + supplierId: 2, + groupId: 2, + blNumber: 'BL002', + status: 'delivered', + scheduledDate: '2025-08-11', + deliveredDate: '2025-08-11', + blAmount: '89.99', + invoiceReference: 'FACT202', + invoiceAmount: '89.99', + reconciled: false, + createdBy: 'admin_dev', + createdAt: new Date(), + updatedAt: new Date() + }, + { + id: 3, + supplierId: 1, + groupId: 3, + blNumber: 'BL003', + status: 'delivered', + scheduledDate: '2025-08-12', + deliveredDate: '2025-08-12', + blAmount: '234.75', + reconciled: true, + validatedAt: new Date(), + createdBy: 'admin_dev', + createdAt: new Date(), + updatedAt: new Date() + } + ]; + testDeliveries.forEach(delivery => this.deliveries.set(delivery.id, delivery as Delivery)); + console.log('✅ MemStorage initialized with admin user (admin/admin)'); console.log('📢 Test publicities and groups added for development'); } @@ -2147,7 +2225,9 @@ class MemStorage implements IStorage { async createGroup(group: InsertGroup): Promise { return {} as Group; } async updateGroup(id: number, group: Partial): Promise { return {} as Group; } async deleteGroup(id: number): Promise {} - async getSuppliers(): Promise { return []; } + async getSuppliers(): Promise { + return Array.from(this.suppliers.values()); + } async createSupplier(supplier: InsertSupplier): Promise { return {} as Supplier; } async updateSupplier(id: number, supplier: Partial): Promise { return {} as Supplier; } async deleteSupplier(id: number): Promise {} @@ -2156,7 +2236,40 @@ class MemStorage implements IStorage { async createOrder(order: InsertOrder): Promise { return {} as Order; } async updateOrder(id: number, order: Partial): Promise { return {} as Order; } async deleteOrder(id: number): Promise {} - async getDeliveries(groupIds?: number[]): Promise { return []; } + async getDeliveries(groupIds?: number[]): Promise { + console.log('🚚 MemStorage getDeliveries called with:', { groupIds }); + + let deliveriesArray = Array.from(this.deliveries.values()); + + // Filter by groups if provided + if (groupIds && groupIds.length > 0) { + deliveriesArray = deliveriesArray.filter(d => groupIds.includes(d.groupId)); + } + + // Add relations (supplier, group, creator) + const deliveriesWithRelations = deliveriesArray.map(delivery => ({ + ...delivery, + supplier: this.suppliers.get(delivery.supplierId!), + group: this.groups.get(delivery.groupId!), + creator: this.users.get(delivery.createdBy!), + order: undefined // No orders in test data for now + })); + + console.log('🚚 MemStorage returning deliveries:', { + total: deliveriesWithRelations.length, + sample: deliveriesWithRelations[0] ? { + id: deliveriesWithRelations[0].id, + blNumber: deliveriesWithRelations[0].blNumber, + supplier: deliveriesWithRelations[0].supplier?.name, + group: { + name: deliveriesWithRelations[0].group?.name, + hasWebhook: !!deliveriesWithRelations[0].group?.webhookUrl + } + } : null + }); + + return deliveriesWithRelations as DeliveryWithRelations[]; + } async getDeliveriesByDateRange(startDate: string, endDate: string, groupIds?: number[]): Promise { return []; } async createDelivery(delivery: InsertDelivery): Promise { return {} as Delivery; } async updateDelivery(id: number, delivery: Partial): Promise { return {} as Delivery; }