diff --git a/attached_assets/{D5EA1398-EDD8-4364-A012-28C574C8D0A3}_1757342535112.png b/attached_assets/{D5EA1398-EDD8-4364-A012-28C574C8D0A3}_1757342535112.png new file mode 100644 index 0000000..7b7a388 Binary files /dev/null and b/attached_assets/{D5EA1398-EDD8-4364-A012-28C574C8D0A3}_1757342535112.png differ 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/deployment_guide.md b/deployment_guide.md new file mode 100644 index 0000000..418d8f3 --- /dev/null +++ b/deployment_guide.md @@ -0,0 +1,85 @@ +# 🔧 GUIDE DE DÉPLOIEMENT URGENT - Serveur de Production + +## 🚹 PROBLÈME IDENTIFIÉ +Votre serveur de production utilise encore l'ancien code avec les erreurs TypeScript, pas le code corrigĂ©. + +## 📋 ÉTAPES DE RÉSOLUTION + +### 1. VÉRIFIEZ LES LOGS DU SERVEUR +```bash +# Option 1: Si vous utilisez PM2 +pm2 logs your_app_name + +# Option 2: Si vous utilisez systemctl +journalctl -u your_service_name -f + +# Option 3: Si vous utilisez Docker +docker logs your_container_name +``` + +### 2. IDENTIFIEZ L'ERREUR EXACTE +Cherchez dans les logs des erreurs comme : +- `No overload matches this call` +- `AuthRequest` +- `requireModulePermission` + +### 3. DÉPLOYEZ LE CODE CORRIGÉ + +**Option A - Git (RecommandĂ©)** +```bash +cd /chemin/vers/votre/application +git pull origin main +# ou +git pull origin master +``` + +**Option B - Copie manuelle** +1. Copiez le fichier `server/routes.ts` depuis ce projet Replit +2. Remplacez-le sur votre serveur de production + +### 4. VÉRIFIEZ LE CODE DÉPLOYÉ +Dans votre fichier `server/routes.ts` en production, vous devez avoir : + +```javascript +// ✅ CORRECT - Nouveau code +app.get('/api/avoirs', isAuthenticated, async (req: any, res) => { + +// ❌ INCORRECT - Ancien code (cause l'erreur) +app.get('/api/avoirs', requireModulePermission('avoir', 'view'), async (req: AuthRequest, res) => { +``` + +### 5. REDÉMARREZ LE SERVEUR +```bash +# Option 1: PM2 +pm2 restart your_app_name + +# Option 2: systemctl +systemctl restart your_service_name + +# Option 3: Docker +docker restart your_container_name + +# Option 4: Service classique +sudo service your_service restart +``` + +### 6. VÉRIFIEZ QUE ÇA MARCHE +1. Rechargez votre page web +2. L'erreur gĂ©nĂ©rale devrait disparaĂźtre +3. Testez l'accĂšs aux autres modules +4. Testez la crĂ©ation d'un avoir + +## 🎯 DIAGNOSTIC RAPIDE + +Si vous n'arrivez pas Ă  identifier le problĂšme : + +1. **Envoyez-moi les logs d'erreur exacts** +2. **Confirmez que le code a Ă©tĂ© dĂ©ployĂ©** +3. **VĂ©rifiez que le serveur a redĂ©marrĂ©** + +## 🚀 APRÈS RÉSOLUTION + +Une fois que l'application fonctionne de nouveau : +1. Testez la crĂ©ation d'un avoir +2. Si ça ne marche pas, le problĂšme sera alors dans la base de donnĂ©es +3. Mais d'abord, rĂ©solvez le problĂšme de dĂ©ploiement ! \ 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 diff --git a/sql/diagnostic_final_production.sql b/sql/diagnostic_final_production.sql new file mode 100644 index 0000000..74afff4 --- /dev/null +++ b/sql/diagnostic_final_production.sql @@ -0,0 +1,66 @@ +-- 🔍 DIAGNOSTIC COMPLET FINAL - Production +-- Trouvons exactement oĂč ça bloque ! + +-- SECTION 1: VĂ©rification des tables et leurs structures +SELECT 'TABLES EXISTANTES' as check_type; +SELECT table_name, + (SELECT COUNT(*) FROM information_schema.columns WHERE table_name = t.table_name) as column_count +FROM information_schema.tables t +WHERE table_schema = 'public' +AND table_name IN ('suppliers', 'groups', 'users', 'avoirs') +ORDER BY table_name; + +-- SECTION 2: Structure dĂ©taillĂ©e de la table avoirs +SELECT 'STRUCTURE TABLE AVOIRS' as check_type; +SELECT column_name, data_type, is_nullable, column_default +FROM information_schema.columns +WHERE table_name = 'avoirs' +ORDER BY ordinal_position; + +-- SECTION 3: Contraintes de la table avoirs +SELECT 'CONTRAINTES AVOIRS' as check_type; +SELECT conname as constraint_name, + confrelid::regclass as referenced_table, + contype as constraint_type +FROM pg_constraint +WHERE conrelid = 'avoirs'::regclass; + +-- SECTION 4: DonnĂ©es dans les tables liĂ©es +SELECT 'DONNÉES TABLES LIÉES' as check_type; +SELECT 'suppliers' as table_name, COUNT(*) as count FROM suppliers +UNION ALL +SELECT 'groups', COUNT(*) FROM groups +UNION ALL +SELECT 'users', COUNT(*) FROM users +UNION ALL +SELECT 'avoirs', COUNT(*) FROM avoirs; + +-- SECTION 5: Si les tables ont des donnĂ©es, montrez quelques exemples +SELECT 'EXEMPLES SUPPLIERS' as check_type; +SELECT id, name, + CASE WHEN LENGTH(name) > 20 THEN LEFT(name, 20) || '...' ELSE name END as display_name +FROM suppliers LIMIT 3; + +SELECT 'EXEMPLES GROUPS' as check_type; +SELECT id, name, + CASE WHEN LENGTH(name) > 20 THEN LEFT(name, 20) || '...' ELSE name END as display_name +FROM groups LIMIT 3; + +SELECT 'EXEMPLES USERS' as check_type; +SELECT id, + COALESCE(username, 'no_username') as username, + CASE WHEN LENGTH(COALESCE(username, 'no_username')) > 15 + THEN LEFT(COALESCE(username, 'no_username'), 15) || '...' + ELSE COALESCE(username, 'no_username') END as display_username +FROM users LIMIT 3; + +-- SECTION 6: Test d'insertion simple +SELECT 'TEST INSERTION' as check_type; +-- Seulement si toutes les tables ont des donnĂ©es +SELECT CASE + WHEN (SELECT COUNT(*) FROM suppliers) > 0 + AND (SELECT COUNT(*) FROM groups) > 0 + AND (SELECT COUNT(*) FROM users) > 0 + THEN 'READY_FOR_INSERT' + ELSE 'MISSING_REFERENCE_DATA' +END as insert_status; \ No newline at end of file diff --git a/sql/fix_foreign_key_issue.sql b/sql/fix_foreign_key_issue.sql new file mode 100644 index 0000000..4a9e4ac --- /dev/null +++ b/sql/fix_foreign_key_issue.sql @@ -0,0 +1,39 @@ +-- 🔧 CORRECTION CONTRAINTE FOREIGN KEY +-- Le problĂšme : l'utilisateur rĂ©fĂ©rencĂ© n'existe pas ! + +-- ÉTAPE 1: Voir les utilisateurs existants +SELECT 'UTILISATEURS EXISTANTS' as check_type; +SELECT id, username, role FROM users ORDER BY id; + +-- ÉTAPE 2: Si aucun utilisateur, crĂ©er un utilisateur admin +INSERT INTO users (id, username, email, role) +VALUES ('admin', 'admin', 'admin@test.com', 'admin') +ON CONFLICT (id) DO NOTHING; + +-- ÉTAPE 3: InsĂ©rer supplier et group de test si nĂ©cessaire +INSERT INTO suppliers (name) VALUES ('Test Supplier') ON CONFLICT DO NOTHING RETURNING id; +INSERT INTO groups (name) VALUES ('Test Group') ON CONFLICT DO NOTHING RETURNING id; + +-- ÉTAPE 4: Test avoir avec utilisateur existant +INSERT INTO avoirs ( + supplier_id, + group_id, + created_by, + invoice_reference, + amount, + comment +) VALUES ( + (SELECT id FROM suppliers WHERE name = 'Test Supplier' LIMIT 1), + (SELECT id FROM groups WHERE name = 'Test Group' LIMIT 1), + (SELECT id FROM users WHERE role = 'admin' LIMIT 1), -- Utilise un ID qui existe ! + 'TEST-FK-FIXED', + 99.99, + 'Test aprĂšs correction foreign key' +) RETURNING id, created_by; + +-- ÉTAPE 5: VĂ©rification +SELECT 'RÉSULTAT INSERTION' as check_type; +SELECT COUNT(*) as total_avoirs FROM avoirs; + +-- ÉTAPE 6: Nettoyage du test +DELETE FROM avoirs WHERE invoice_reference = 'TEST-FK-FIXED'; \ No newline at end of file