From c79ac79a91edae07e42a86c0bdf607e675f4c262 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Tue, 12 Aug 2025 10:16:28 +0000 Subject: [PATCH] Enable automatic delivery validation for designated suppliers Add automatic delivery validation logic to the reconciliation process, enabling auto-validation for deliveries from suppliers configured for automatic reconciliation when the delivery status is 'delivered' and a BL number is present. Includes a new method to retrieve supplier details and updates to documentation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/FyjZ5oh --- replit.md | 2 ++ server/routes.ts | 25 +++++++++++++++++++++++++ server/storage.ts | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/replit.md b/replit.md index f997b28..06ca85d 100644 --- a/replit.md +++ b/replit.md @@ -30,6 +30,7 @@ Preferred communication style: Simple, everyday language. ### Core Business Entities - **Management**: Orders, Deliveries, Customer Orders, Suppliers, Publicities, DLC Products (limited shelf life), Tasks. +- **Automatic Reconciliation**: Dual-mode BL/Invoice reconciliation system with automatic validation for designated suppliers. ### Data Flow - **Request Flow**: Client requests via React Query, processed by Express middleware for authentication/security, then by route handlers using Drizzle ORM for database operations. @@ -41,6 +42,7 @@ Preferred communication style: Simple, everyday language. - **Multi-Store Management**: Global store context, role-based access control (admin, manager, employee, directeur), and data isolation. - **Universal Pagination**: Reusable client-side pagination component across all main tabular data pages. - **Reconciliation Module**: For balancing and tracking financial discrepancies. +- **Automatic Reconciliation System**: Dual-mode BL/Invoice reconciliation with automatic validation for suppliers in automatic mode. Auto-validates deliveries when status = "delivered" AND BL number exists. - **Permission System**: Granular, hardcoded permissions (54 permissions across 12 categories, assigned to 4 roles) for improved performance and maintenance. - **User Management**: Comprehensive features including user deletion with ownership transfer, consistent name and email field handling, and robust password hashing. - **Calendar Synchronization**: Proper display of delivery dates and automatic synchronization of order statuses. diff --git a/server/routes.ts b/server/routes.ts index f8df668..0e0d498 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -702,6 +702,31 @@ export async function registerRoutes(app: Express): Promise { console.error(`❌ Auto-sync failed for order #${updatedDelivery.orderId}:`, error); } } + + // AUTO-VALIDATION RAPPROCHEMENT AUTOMATIQUE : Si fournisseur en mode automatique, livraison delivered + BL → auto-valider + if (data.status === 'delivered' || data.blNumber) { + try { + // Récupérer le fournisseur pour vérifier le mode automatique + const supplier = await storage.getSupplier(updatedDelivery.supplierId); + + if (supplier?.automaticReconciliation && + updatedDelivery.status === 'delivered' && + updatedDelivery.blNumber) { + + console.log(`🤖 Auto-reconciliation: Delivery #${id} from automatic supplier ${supplier.name}, auto-validating...`); + + // Auto-valider le rapprochement + await storage.updateDelivery(id, { + reconciled: true, + validatedAt: new Date() + }); + + console.log(`✅ Auto-reconciliation: Delivery #${id} automatically validated for supplier ${supplier.name}`); + } + } catch (error) { + console.error(`❌ Auto-reconciliation failed for delivery #${id}:`, error); + } + } res.json(updatedDelivery); } catch (error) { diff --git a/server/storage.ts b/server/storage.ts index 8ca63fd..f5492cd 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -470,6 +470,11 @@ export class DatabaseStorage implements IStorage { return await db.select().from(suppliers).orderBy(suppliers.name); } + async getSupplier(id: number): Promise { + const [supplier] = await db.select().from(suppliers).where(eq(suppliers.id, id)); + return supplier; + } + async createSupplier(supplier: InsertSupplier): Promise { const [newSupplier] = await db.insert(suppliers).values(supplier).returning(); return newSupplier;