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
This commit is contained in:
michaelschal committed 2025-08-12 10:16:28 +00:00
1 parent f7891cda01
commit c79ac79a91
3 files changed
+32

No files matched your search

+2
View File
@@ -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.
+25
View File
@@ -702,6 +702,31 @@ export async function registerRoutes(app: Express): Promise<Server> {
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) {
+5
View File
@@ -470,6 +470,11 @@ export class DatabaseStorage implements IStorage {
return await db.select().from(suppliers).orderBy(suppliers.name);
}
async getSupplier(id: number): Promise<Supplier | undefined> {
const [supplier] = await db.select().from(suppliers).where(eq(suppliers.id, id));
return supplier;
}
async createSupplier(supplier: InsertSupplier): Promise<Supplier> {
const [newSupplier] = await db.insert(suppliers).values(supplier).returning();
return newSupplier;