diff --git a/attached_assets/{9A963AF5-8CA1-4143-8A50-BF6B1320ABA2}_1762263946868.png b/attached_assets/{9A963AF5-8CA1-4143-8A50-BF6B1320ABA2}_1762263946868.png new file mode 100644 index 0000000..062d432 Binary files /dev/null and b/attached_assets/{9A963AF5-8CA1-4143-8A50-BF6B1320ABA2}_1762263946868.png differ diff --git a/client/src/pages/BLReconciliation.tsx b/client/src/pages/BLReconciliation.tsx index 34449a1..25a9355 100644 --- a/client/src/pages/BLReconciliation.tsx +++ b/client/src/pages/BLReconciliation.tsx @@ -386,22 +386,42 @@ export default function BLReconciliation() { // CAS SPÉCIAL : Livraisons réconciliées (✅) avec cellules vides // Si reconciled=true ET (cellules vides) ET blNumber existe → auto-remplir deliveriesWithBL.forEach((delivery: any) => { - if (!delivery.reconciled) return; // Ignorer les livraisons non réconciliées - - const hasEmptyCells = !delivery.invoiceReference || !delivery.invoiceAmount || !delivery.dueDate; - const hasBLNumber = delivery.blNumber?.trim(); - const notAlreadyAutoVerified = !autoVerifiedDeliveries.has(delivery.id); - const notCurrentlyVerifying = !verifyingDeliveries.has(delivery.id); - - if (hasEmptyCells && hasBLNumber && notAlreadyAutoVerified && notCurrentlyVerifying) { - // Livraison réconciliée avec cellules vides → vérifier pour auto-remplir (UNE SEULE FOIS) - if (import.meta.env.DEV) { - console.log(`🔄 Livraison réconciliée #${delivery.id} avec cellules vides, auto-vérification (première tentative)...`); + if (delivery.reconciled) { + const hasEmptyCells = !delivery.invoiceReference || !delivery.invoiceAmount || !delivery.dueDate; + const hasBLNumber = delivery.blNumber?.trim(); + const notAlreadyAutoVerified = !autoVerifiedDeliveries.has(delivery.id); + const notCurrentlyVerifying = !verifyingDeliveries.has(delivery.id); + + if (hasEmptyCells && hasBLNumber && notAlreadyAutoVerified && notCurrentlyVerifying) { + // Livraison réconciliée avec cellules vides → vérifier pour auto-remplir (UNE SEULE FOIS) + if (import.meta.env.DEV) { + console.log(`🔄 Livraison réconciliée #${delivery.id} avec cellules vides, auto-vérification (première tentative)...`); + } + // Marquer comme auto-vérifiée AVANT de lancer pour éviter les doublons + setAutoVerifiedDeliveries(prev => new Set(prev).add(delivery.id)); + // Lancer la vérification sans délai + handleVerifyInvoice(delivery, false); } - // Marquer comme auto-vérifiée AVANT de lancer pour éviter les doublons - setAutoVerifiedDeliveries(prev => new Set(prev).add(delivery.id)); - // Lancer la vérification sans délai - handleVerifyInvoice(delivery, false); + return; // Autres livraisons réconciliées = AUCUNE vérification nécessaire + } + + // VÉRIFICATION AUTOMATIQUE pour afficher les coches (UNE SEULE FOIS au chargement) + // Vérifier seulement les livraisons NON réconciliées qui n'ont PAS encore été vérifiées + const hasVerifiableData = delivery.invoiceReference || delivery.blNumber; + const notAlreadyProcessed = !verificationResults[delivery.id] && !verifyingDeliveries.has(delivery.id); + + if (hasVerifiableData && notAlreadyProcessed) { + if (import.meta.env.DEV) { + console.log(`🔍 Vérification initiale pour affichage coche ${delivery.id}:`, { + invoiceRef: delivery.invoiceReference, + blNumber: delivery.blNumber + }); + } + + // Délai pour éviter de surcharger le serveur + setTimeout(() => { + handleVerifyInvoice(delivery, false); + }, Math.random() * 1000); } }); }, [deliveriesWithBL, suppliers, verificationResults, verifyingDeliveries]);