Allow invoice verification using delivery's bill of lading number

Update the invoice verification process to accept either a direct invoice reference or a bill of lading number. This change enables the system to correctly identify and process invoices when only the bill of lading information is available, ensuring that all relevant deliveries are reconciled. The backend service has been enhanced to search for invoices using the bill of lading and supplier name, with improved caching and error handling for missing configurations.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: a3de0820-9397-41b2-b000-7931ee9c29de
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/a3de0820-9397-41b2-b000-7931ee9c29de/AO4neXk
This commit is contained in:
michaelschal committed 2025-08-16 07:00:46 +00:00
1 parent 54bdac580c
commit c6c9369fcb
3 files changed
+379 -34

No files matched your search

+29 -9
View File
@@ -882,7 +882,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
}
}
const { invoiceReference, forceRefresh } = req.body;
const { invoiceReference, blNumber, forceRefresh } = req.body;
if (!delivery.supplier || !delivery.group) {
console.log('❌ Livraison manque informations:', {
@@ -893,24 +893,44 @@ export async function registerRoutes(app: Express): Promise<Server> {
return res.status(400).json({ message: "Delivery missing supplier or group information" });
}
if (!invoiceReference || !invoiceReference.trim()) {
return res.status(400).json({ message: "Référence de facture requise" });
// Accepter soit une référence de facture soit un numéro de BL
if ((!invoiceReference || !invoiceReference.trim()) && (!blNumber || !blNumber.trim())) {
return res.status(400).json({ message: "Référence de facture ou numéro BL requis" });
}
console.log('🔍 Vérification facture:', {
deliveryId,
invoiceReference,
blNumber,
supplier: delivery.supplier?.name,
group: delivery.group?.name,
groupId: delivery.groupId
});
// Appeler le service de vérification
const result = await invoiceVerificationService.verifyInvoice(
invoiceReference,
delivery.groupId,
forceRefresh || false
);
let result;
if (invoiceReference && invoiceReference.trim()) {
// Vérifier par référence de facture
result = await invoiceVerificationService.verifyInvoice(
invoiceReference,
delivery.groupId,
forceRefresh || false
);
} else if (blNumber && blNumber.trim()) {
// Vérifier par numéro BL
result = await invoiceVerificationService.verifyInvoiceByBL(
blNumber,
delivery.supplier.name,
delivery.groupId,
forceRefresh || false
);
} else {
result = {
exists: false,
matchType: 'none',
errorMessage: 'Aucune référence de facture ou numéro BL fourni'
};
}
console.log('✅ Résultat vérification:', result);
res.json(result);