From c45bda21c53589574b6a1dfe7a95debf66ee5c3f Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 8 Sep 2025 14:49:09 +0000 Subject: [PATCH] Improve financial records processing and add production debugging tools Update schema for financial records to allow optional fields and introduce a SQL script for detailed production debugging of financial data and related entities. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/2Jd7tYp --- debug_production.sql | 77 ++++++++++++++++++++++++++++++++++++++++++++ shared/schema.ts | 4 +-- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 debug_production.sql diff --git a/debug_production.sql b/debug_production.sql new file mode 100644 index 0000000..ef69ff9 --- /dev/null +++ b/debug_production.sql @@ -0,0 +1,77 @@ +-- 🔍 DIAGNOSTIC PRODUCTION COMPLET - Module Avoirs +-- Copiez-collez ce script dans votre utilitaire SQL pour diagnostic précis + +BEGIN; + +-- SECTION 1: STRUCTURE DES TABLES +SELECT 'VÉRIFICATION STRUCTURE TABLES' AS section_title; + +-- Table avoirs - structure exacte +SELECT 'STRUCTURE_AVOIRS' AS check_type, column_name, data_type, is_nullable, column_default +FROM information_schema.columns +WHERE table_name = 'avoirs' AND table_schema = 'public' +ORDER BY ordinal_position; + +-- Table suppliers - structure exacte +SELECT 'STRUCTURE_SUPPLIERS' AS check_type, column_name, data_type, is_nullable +FROM information_schema.columns +WHERE table_name = 'suppliers' AND table_schema = 'public' +ORDER BY ordinal_position; + +-- Table groups - structure exacte +SELECT 'STRUCTURE_GROUPS' AS check_type, column_name, data_type, is_nullable +FROM information_schema.columns +WHERE table_name = 'groups' AND table_schema = 'public' +ORDER BY ordinal_position; + +-- Table users - structure exacte +SELECT 'STRUCTURE_USERS' AS check_type, column_name, data_type, is_nullable +FROM information_schema.columns +WHERE table_name = 'users' AND table_schema = 'public' +ORDER BY ordinal_position; + +-- SECTION 2: CONTRAINTES +SELECT 'CONTRAINTES_AVOIRS' AS check_type, conname AS constraint_name, contype AS type, + confrelid::regclass AS referenced_table +FROM pg_constraint +WHERE conrelid = 'avoirs'::regclass; + +-- SECTION 3: DONNÉES EXISTANTES +SELECT 'COMPTES_TABLES' AS check_type, 'suppliers' AS table_name, COUNT(*) AS count FROM suppliers +UNION ALL +SELECT 'COMPTES_TABLES', 'groups', COUNT(*) FROM groups +UNION ALL +SELECT 'COMPTES_TABLES', 'users', COUNT(*) FROM users +UNION ALL +SELECT 'COMPTES_TABLES', 'avoirs', COUNT(*) FROM avoirs; + +-- SECTION 4: EXEMPLES DE DONNÉES (si elles existent) +-- Suppliers +SELECT 'EXEMPLES_SUPPLIERS' AS check_type, id, name FROM suppliers LIMIT 3; + +-- Groups +SELECT 'EXEMPLES_GROUPS' AS check_type, id, name FROM groups LIMIT 3; + +-- Users +SELECT 'EXEMPLES_USERS' AS check_type, id, + COALESCE(username, 'no_username') AS username, + role +FROM users LIMIT 3; + +-- SECTION 5: TEST DE COMPATIBILITÉ +-- Test si on peut insérer avec des champs NULL +SELECT 'TEST_COMPATIBILITÉ' AS check_type, + CASE + WHEN (SELECT is_nullable FROM information_schema.columns + WHERE table_name = 'avoirs' AND column_name = 'invoice_reference') = 'YES' + THEN 'invoice_reference_NULLABLE' + ELSE 'invoice_reference_NOT_NULL' + END AS invoice_ref_status, + CASE + WHEN (SELECT is_nullable FROM information_schema.columns + WHERE table_name = 'avoirs' AND column_name = 'amount') = 'YES' + THEN 'amount_NULLABLE' + ELSE 'amount_NOT_NULL' + END AS amount_status; + +ROLLBACK; -- Ne pas sauvegarder, c'est juste du diagnostic \ No newline at end of file diff --git a/shared/schema.ts b/shared/schema.ts index fd4de86..2dcc23f 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -267,8 +267,8 @@ export const avoirs = pgTable("avoirs", { id: serial("id").primaryKey(), supplierId: integer("supplier_id").notNull(), // Fournisseur groupId: integer("group_id").notNull(), // Magasin/groupe associé - OBLIGATOIRE pour filtrage - invoiceReference: varchar("invoice_reference", { length: 255 }).notNull(), // Référence facture - amount: decimal("amount", { precision: 10, scale: 2 }).notNull(), // Montant + invoiceReference: varchar("invoice_reference", { length: 255 }), // Référence facture (OPTIONNEL) + amount: decimal("amount", { precision: 10, scale: 2 }), // Montant (OPTIONNEL) comment: text("comment"), // Commentaire (optionnel) commercialProcessed: boolean("commercial_processed").default(false), // Avoir fait par commercial status: varchar("status", { length: 50 }).notNull().default("En attente de demande"), // En attente de demande, Demandé, Reçu