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"),