diff --git a/client/src/pages/BLReconciliation.tsx b/client/src/pages/BLReconciliation.tsx index 43fc194..e765774 100644 --- a/client/src/pages/BLReconciliation.tsx +++ b/client/src/pages/BLReconciliation.tsx @@ -132,7 +132,15 @@ export default function BLReconciliation() { // Fonction pour déclencher la vérification const handleVerifyInvoice = (delivery: any) => { - if (!delivery.group?.webhookUrl) { + console.log('🔍 Debug vérification:', { + delivery: delivery, + group: delivery.group, + webhookUrl: delivery.group?.webhookUrl, + nocodbTableName: delivery.group?.nocodbTableName, + supplier: delivery.supplier + }); + + if (!delivery.group?.nocodbTableName && !delivery.group?.webhookUrl) { toast({ title: "Vérification non disponible", description: "Ce magasin n'a pas de configuration NocoDB", @@ -631,7 +639,7 @@ export default function BLReconciliation() { {/* Icône de vérification de facture */} - {delivery.group?.webhookUrl && ( + {(delivery.group?.webhookUrl || delivery.group?.nocodbTableName) && (
{verifyingDeliveries.has(delivery.id) ? ( diff --git a/server/invoiceVerification.ts b/server/invoiceVerification.ts index 99a3ab9..7aadf11 100644 --- a/server/invoiceVerification.ts +++ b/server/invoiceVerification.ts @@ -20,17 +20,30 @@ interface NocodbInvoice { class InvoiceVerificationService { private async getNocodbConfig(): Promise { - const [config] = await db - .select() - .from(nocodbConfig) - .where(eq(nocodbConfig.isActive, true)) - .limit(1); - - if (!config) { - throw new Error('Aucune configuration NocoDB active trouvée'); + try { + const [config] = await db + .select() + .from(nocodbConfig) + .where(eq(nocodbConfig.isActive, true)) + .limit(1); + + if (!config) { + console.log('⚠️ Aucune configuration NocoDB active trouvée dans la table nocodb_config'); + throw new Error('Aucune configuration NocoDB active trouvée'); + } + + console.log('✅ Configuration NocoDB trouvée:', { + id: config.id, + name: config.name, + baseUrl: config.baseUrl, + projectId: config.projectId + }); + + return config; + } catch (error) { + console.error('❌ Erreur lors de la récupération de la configuration NocoDB:', error); + throw error; } - - return config; } private generateCacheKey(groupId: number, invoiceRef: string, supplierName: string): string { diff --git a/server/routes.ts b/server/routes.ts index 004fc76..475de76 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -862,9 +862,24 @@ export async function registerRoutes(app: Express): Promise { const { invoiceReference, blNumber } = req.body; if (!delivery.supplier || !delivery.group) { + console.log('❌ Livraison manque informations:', { + deliveryId, + hasSupplier: !!delivery.supplier, + hasGroup: !!delivery.group, + delivery: delivery + }); return res.status(400).json({ message: "Delivery missing supplier or group information" }); } + console.log('🔍 Tentative de vérification facture:', { + deliveryId, + invoiceReference: invoiceReference || delivery.invoiceReference, + blNumber: blNumber || delivery.blNumber, + supplierName: delivery.supplier.name, + groupId: delivery.groupId, + groupData: delivery.group + }); + const result = await invoiceVerificationService.verifyInvoiceReference( invoiceReference || delivery.invoiceReference || '', blNumber || delivery.blNumber || '', diff --git a/shared/schema.ts b/shared/schema.ts index b0e8e9e..9acf2c4 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -174,18 +174,6 @@ export const invoiceVerificationCache = pgTable("invoice_verification_cache", { updatedAt: timestamp("updated_at").defaultNow(), }); -export const insertNocodbConfigSchema = createInsertSchema(nocodbConfig).omit({ - id: true, - createdAt: true, - updatedAt: true, -}); - -export const insertInvoiceVerificationCacheSchema = createInsertSchema(invoiceVerificationCache).omit({ - id: true, - createdAt: true, - updatedAt: true, -}); - // Customer Orders (Commandes Client) export const customerOrders = pgTable("customer_orders", { id: serial("id").primaryKey(), @@ -465,8 +453,6 @@ export const insertPublicityParticipationSchema = createInsertSchema(publicityPa createdAt: true, }); - - export const insertNocodbConfigSchema = createInsertSchema(nocodbConfig).omit({ id: true, createdAt: true, @@ -479,6 +465,8 @@ export const insertInvoiceVerificationCacheSchema = createInsertSchema(invoiceVe updatedAt: true, }); + + export const insertCustomerOrderSchema = createInsertSchema(customerOrders).omit({ id: true, createdAt: true,