From c669c4eba99bb1d7c050276703af07e718d23ae5 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Tue, 4 Nov 2025 05:30:12 +0000 Subject: [PATCH] Update invoice reconciliation to fix display issues Introduce detailed logging and data type conversions in invoice verification service and client-side reconciliation page to address discrepancies in displayed invoice amounts and due dates. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 41ed310d-8033-46c7-bb26-e56560b56490 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/gTQvEeF --- client/src/pages/BLReconciliation.tsx | 23 ++++++++++++++++++++++- server/invoiceVerification.ts | 10 +++++++++- shared/schema.ts | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/client/src/pages/BLReconciliation.tsx b/client/src/pages/BLReconciliation.tsx index ba325d1..2d1738b 100644 --- a/client/src/pages/BLReconciliation.tsx +++ b/client/src/pages/BLReconciliation.tsx @@ -156,25 +156,46 @@ export default function BLReconciliation() { // Auto-remplissage si facture trouvée (référence facture OU numéro BL) if (result.exists) { + console.log('🔍 DEBUG - Résultat complet de vérification:', { + deliveryId: variables.deliveryId, + exists: result.exists, + matchType: result.matchType, + invoiceReference: result.invoiceReference, + invoiceAmount: result.invoiceAmount, + dueDate: result.dueDate, + hasInvoiceRef: !!result.invoiceReference, + hasAmount: result.invoiceAmount !== undefined && result.invoiceAmount !== null, + hasDueDate: !!result.dueDate + }); + // Auto-remplir les champs dans la livraison via API const updateData: any = {}; // Ajouter la référence de facture SEULEMENT si trouvée via BL (pas déjà renseignée) if (result.invoiceReference && result.matchType === 'bl_number') { updateData.invoiceReference = result.invoiceReference; + console.log('✅ Ajout invoiceReference:', result.invoiceReference); + } else { + console.log('⚠️ Pas d\'ajout invoiceReference:', { hasRef: !!result.invoiceReference, matchType: result.matchType }); } // TOUJOURS mettre à jour le montant si disponible (peu importe le matchType) if (result.invoiceAmount !== undefined && result.invoiceAmount !== null) { updateData.invoiceAmount = result.invoiceAmount; + console.log('✅ Ajout invoiceAmount:', result.invoiceAmount); + } else { + console.log('⚠️ Pas d\'ajout invoiceAmount:', { amount: result.invoiceAmount }); } // TOUJOURS mettre à jour la date d'échéance si disponible (peu importe le matchType) if (result.dueDate) { updateData.dueDate = result.dueDate; + console.log('✅ Ajout dueDate:', result.dueDate); + } else { + console.log('⚠️ Pas d\'ajout dueDate:', { dueDate: result.dueDate }); } - console.log('📝 Données à sauvegarder:', { deliveryId: variables.deliveryId, updateData, matchType: result.matchType }); + console.log('📝 Données finales à sauvegarder:', { deliveryId: variables.deliveryId, updateData, matchType: result.matchType }); // Ne faire l'appel que si on a des données à mettre à jour if (Object.keys(updateData).length > 0) { diff --git a/server/invoiceVerification.ts b/server/invoiceVerification.ts index ff8fdd3..4ae9310 100644 --- a/server/invoiceVerification.ts +++ b/server/invoiceVerification.ts @@ -35,7 +35,9 @@ export class InvoiceVerificationService { console.log('🛡️ [CACHE] PERMANENT - Facture validée avec coche verte, AUCUNE vérification:', { invoiceReference, groupId, - exists: cached.exists + exists: cached.exists, + invoiceAmount: cached.invoiceAmount, + dueDate: cached.dueDate }); return { exists: cached.exists, @@ -43,6 +45,8 @@ export class InvoiceVerificationService { errorMessage: cached.errorMessage, invoiceReference: cached.invoiceReference, supplierName: cached.supplierName, + invoiceAmount: cached.invoiceAmount ? parseFloat(cached.invoiceAmount) : undefined, + dueDate: cached.dueDate ? new Date(cached.dueDate).toISOString() : null, fromCache: true, permanent: true }; @@ -57,6 +61,8 @@ export class InvoiceVerificationService { errorMessage: cached.errorMessage, invoiceReference: cached.invoiceReference, supplierName: cached.supplierName, + invoiceAmount: cached.invoiceAmount ? parseFloat(cached.invoiceAmount) : undefined, + dueDate: cached.dueDate ? new Date(cached.dueDate).toISOString() : null, fromCache: true, permanent: false }; @@ -115,6 +121,8 @@ export class InvoiceVerificationService { groupId, invoiceReference, supplierName: supplierName || null, + invoiceAmount: result.invoiceAmount || null, + dueDate: result.dueDate ? new Date(result.dueDate) : null, exists: result.exists, matchType: result.matchType, errorMessage: result.errorMessage || null, diff --git a/shared/schema.ts b/shared/schema.ts index f5028ef..0fecd2e 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -173,6 +173,8 @@ export const invoiceVerificationCache = pgTable("invoice_verification_cache", { groupId: integer("group_id").notNull(), invoiceReference: varchar("invoice_reference", { length: 255 }).notNull(), supplierName: varchar("supplier_name", { length: 255 }), + invoiceAmount: decimal("invoice_amount", { precision: 10, scale: 2 }), // Montant de la facture + dueDate: timestamp("due_date"), // Date d'échéance exists: boolean("exists").notNull(), matchType: varchar("match_type", { length: 50 }).notNull(), errorMessage: text("error_message"),