-- ================================================================ -- Finance Workflow - Données de Test -- ================================================================ -- Date: 2026-03-14 -- Objectif: Créer des données de test pour valider l'intégration mobile-backend -- Usage: psql -U unionflow -d unionflow -h localhost -f FINANCE_WORKFLOW_TEST_DATA.sql -- ================================================================ -- 1. ORGANISATION DE TEST -- ================================================================ -- Vérifier si l'organisation existe déjà DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM organisations WHERE id = '00000000-0000-0000-0000-000000000001') THEN INSERT INTO organisations ( id, nom, type_organisation, statut, email, telephone, adresse, pays, date_creation, actif ) VALUES ( '00000000-0000-0000-0000-000000000001', 'Organisation Test Finance', 'ASSOCIATION', 'ACTIVE', 'test@finance.org', '+221771234567', '123 Rue Test, Dakar', 'Sénégal', CURRENT_TIMESTAMP, true ); RAISE NOTICE 'Organisation créée: 00000000-0000-0000-0000-000000000001'; ELSE RAISE NOTICE 'Organisation existe déjà: 00000000-0000-0000-0000-000000000001'; END IF; END $$; -- ================================================================ -- 2. APPROBATIONS DE TRANSACTIONS EN ATTENTE -- ================================================================ -- Approbation 1: Contribution mensuelle (LEVEL1 - 1 approbation requise) INSERT INTO transaction_approvals ( id, transaction_id, transaction_type, amount, currency, requester_id, requester_name, organisation_id, required_level, status, description, created_at, expires_at, date_creation, actif ) VALUES ( '11111111-1111-1111-1111-111111111111', gen_random_uuid(), 'CONTRIBUTION', 50000.00, 'XOF', gen_random_uuid(), 'Mamadou Diallo', '00000000-0000-0000-0000-000000000001', 'LEVEL1', 'PENDING', 'Cotisation mensuelle mars 2026', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + INTERVAL '7 days', CURRENT_TIMESTAMP, true ) ON CONFLICT (id) DO NOTHING; -- Approbation 2: Retrait épargne (LEVEL2 - 2 approbations requises) INSERT INTO transaction_approvals ( id, transaction_id, transaction_type, amount, currency, requester_id, requester_name, organisation_id, required_level, status, description, created_at, expires_at, date_creation, actif ) VALUES ( '22222222-2222-2222-2222-222222222222', gen_random_uuid(), 'WITHDRAWAL', 500000.00, 'XOF', gen_random_uuid(), 'Fatou Sarr', '00000000-0000-0000-0000-000000000001', 'LEVEL2', 'PENDING', 'Retrait épargne pour projet personnel', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + INTERVAL '7 days', CURRENT_TIMESTAMP, true ) ON CONFLICT (id) DO NOTHING; -- Approbation 3: Dépôt solidarité (LEVEL1) INSERT INTO transaction_approvals ( id, transaction_id, transaction_type, amount, currency, requester_id, requester_name, organisation_id, required_level, status, description, created_at, expires_at, date_creation, actif ) VALUES ( '33333333-3333-3333-3333-333333333333', gen_random_uuid(), 'SOLIDARITY', 75000.00, 'XOF', gen_random_uuid(), 'Ibrahima Ndiaye', '00000000-0000-0000-0000-000000000001', 'LEVEL1', 'PENDING', 'Aide solidarité pour funérailles', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + INTERVAL '7 days', CURRENT_TIMESTAMP, true ) ON CONFLICT (id) DO NOTHING; -- Approbation 4: Événement (LEVEL3 - 3 approbations requises) INSERT INTO transaction_approvals ( id, transaction_id, transaction_type, amount, currency, requester_id, requester_name, organisation_id, required_level, status, description, created_at, expires_at, date_creation, actif ) VALUES ( '44444444-4444-4444-4444-444444444444', gen_random_uuid(), 'EVENT', 1500000.00, 'XOF', gen_random_uuid(), 'Aminata Ba', '00000000-0000-0000-0000-000000000001', 'LEVEL3', 'PENDING', 'Organisation gala annuel 2026', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + INTERVAL '7 days', CURRENT_TIMESTAMP, true ) ON CONFLICT (id) DO NOTHING; -- ================================================================ -- 3. APPROBATIONS HISTORIQUES (VALIDÉES/REJETÉES) -- ================================================================ -- Approbation validée (pour historique) INSERT INTO transaction_approvals ( id, transaction_id, transaction_type, amount, currency, requester_id, requester_name, organisation_id, required_level, status, description, created_at, expires_at, completed_at, date_creation, actif ) VALUES ( '55555555-5555-5555-5555-555555555555', gen_random_uuid(), 'CONTRIBUTION', 50000.00, 'XOF', gen_random_uuid(), 'Ousmane Sow', '00000000-0000-0000-0000-000000000001', 'LEVEL1', 'VALIDATED', 'Cotisation mensuelle février 2026', CURRENT_TIMESTAMP - INTERVAL '15 days', CURRENT_TIMESTAMP - INTERVAL '8 days', CURRENT_TIMESTAMP - INTERVAL '14 days', CURRENT_TIMESTAMP - INTERVAL '15 days', true ) ON CONFLICT (id) DO NOTHING; -- Action d'approbation pour la transaction validée INSERT INTO approver_actions ( id, approval_id, approver_id, approver_name, decision, comment, decided_at, date_creation, actif ) VALUES ( gen_random_uuid(), '55555555-5555-5555-5555-555555555555', gen_random_uuid(), 'Cheikh Diop', 'APPROVED', 'Cotisation conforme, approuvé', CURRENT_TIMESTAMP - INTERVAL '14 days', CURRENT_TIMESTAMP - INTERVAL '14 days', true ) ON CONFLICT DO NOTHING; -- Approbation rejetée (pour historique) INSERT INTO transaction_approvals ( id, transaction_id, transaction_type, amount, currency, requester_id, requester_name, organisation_id, required_level, status, description, rejection_reason, created_at, expires_at, completed_at, date_creation, actif ) VALUES ( '66666666-6666-6666-6666-666666666666', gen_random_uuid(), 'WITHDRAWAL', 2000000.00, 'XOF', gen_random_uuid(), 'Awa Diagne', '00000000-0000-0000-0000-000000000001', 'LEVEL2', 'REJECTED', 'Retrait urgent montant élevé', 'Montant trop élevé sans justificatif adéquat. Révision budgétaire nécessaire avant approbation.', CURRENT_TIMESTAMP - INTERVAL '10 days', CURRENT_TIMESTAMP - INTERVAL '3 days', CURRENT_TIMESTAMP - INTERVAL '9 days', CURRENT_TIMESTAMP - INTERVAL '10 days', true ) ON CONFLICT (id) DO NOTHING; -- Action de rejet INSERT INTO approver_actions ( id, approval_id, approver_id, approver_name, decision, comment, decided_at, date_creation, actif ) VALUES ( gen_random_uuid(), '66666666-6666-6666-6666-666666666666', gen_random_uuid(), 'Moussa Kane', 'REJECTED', 'Montant trop élevé sans justificatif adéquat', CURRENT_TIMESTAMP - INTERVAL '9 days', CURRENT_TIMESTAMP - INTERVAL '9 days', true ) ON CONFLICT DO NOTHING; -- ================================================================ -- 4. BUDGETS -- ================================================================ -- Budget mensuel mars 2026 (actif, avec réalisations partielles) INSERT INTO budgets ( id, name, description, organisation_id, period, year, month, start_date, end_date, currency, total_planned, total_realized, status, created_at_budget, date_creation, actif ) VALUES ( '77777777-7777-7777-7777-777777777777', 'Budget Mars 2026', 'Budget mensuel pour le mois de mars 2026', '00000000-0000-0000-0000-000000000001', 'MONTHLY', 2026, 3, '2026-03-01', '2026-03-31', 'XOF', 3500000.00, 2950000.00, 'ACTIVE', CURRENT_TIMESTAMP - INTERVAL '14 days', CURRENT_TIMESTAMP - INTERVAL '14 days', true ) ON CONFLICT (id) DO NOTHING; -- Lignes budgétaires pour Budget Mars 2026 INSERT INTO budget_lines (id, budget_id, category, name, description, amount_planned, amount_realized, notes, date_creation, actif) VALUES (gen_random_uuid(), '77777777-7777-7777-7777-777777777777', 'CONTRIBUTIONS', 'Cotisations mensuelles', 'Cotisations des membres actifs', 2000000.00, 1800000.00, 'Basé sur 40 membres à 50000 XOF', CURRENT_TIMESTAMP, true), (gen_random_uuid(), '77777777-7777-7777-7777-777777777777', 'SAVINGS', 'Épargne collective', 'Épargne pour projets futurs', 1000000.00, 950000.00, NULL, CURRENT_TIMESTAMP, true), (gen_random_uuid(), '77777777-7777-7777-7777-777777777777', 'OPERATIONAL', 'Frais opérationnels', 'Loyer, électricité, fournitures', 500000.00, 200000.00, NULL, CURRENT_TIMESTAMP, true) ON CONFLICT DO NOTHING; -- Budget trimestriel Q2 2026 (actif, sans réalisations encore) INSERT INTO budgets ( id, name, description, organisation_id, period, year, month, start_date, end_date, currency, total_planned, total_realized, status, created_at_budget, date_creation, actif ) VALUES ( '88888888-8888-8888-8888-888888888888', 'Budget Q2 2026', 'Budget deuxième trimestre 2026 (avril-juin)', '00000000-0000-0000-0000-000000000001', 'QUARTERLY', 2026, 4, '2026-04-01', '2026-06-30', 'XOF', 10000000.00, 0.00, 'ACTIVE', CURRENT_TIMESTAMP - INTERVAL '7 days', CURRENT_TIMESTAMP - INTERVAL '7 days', true ) ON CONFLICT (id) DO NOTHING; -- Lignes budgétaires pour Budget Q2 2026 INSERT INTO budget_lines (id, budget_id, category, name, description, amount_planned, amount_realized, notes, date_creation, actif) VALUES (gen_random_uuid(), '88888888-8888-8888-8888-888888888888', 'CONTRIBUTIONS', 'Cotisations trimestrielles', 'Cotisations Q2', 6000000.00, 0.00, '3 mois × 2M', CURRENT_TIMESTAMP, true), (gen_random_uuid(), '88888888-8888-8888-8888-888888888888', 'EVENTS', 'Événements du trimestre', 'AG + formations', 2000000.00, 0.00, NULL, CURRENT_TIMESTAMP, true), (gen_random_uuid(), '88888888-8888-8888-8888-888888888888', 'INVESTMENTS', 'Investissements', 'Matériel informatique', 2000000.00, 0.00, NULL, CURRENT_TIMESTAMP, true) ON CONFLICT DO NOTHING; -- Budget avec dépassement (pour tester indicateurs) INSERT INTO budgets ( id, name, description, organisation_id, period, year, month, start_date, end_date, currency, total_planned, total_realized, status, created_at_budget, date_creation, actif ) VALUES ( '99999999-9999-9999-9999-999999999999', 'Budget Février 2026', 'Budget mensuel février (clôturé)', '00000000-0000-0000-0000-000000000001', 'MONTHLY', 2026, 2, '2026-02-01', '2026-02-28', 'XOF', 3000000.00, 3200000.00, 'CLOSED', CURRENT_TIMESTAMP - INTERVAL '45 days', CURRENT_TIMESTAMP - INTERVAL '45 days', true ) ON CONFLICT (id) DO NOTHING; -- Lignes avec dépassement INSERT INTO budget_lines (id, budget_id, category, name, description, amount_planned, amount_realized, notes, date_creation, actif) VALUES (gen_random_uuid(), '99999999-9999-9999-9999-999999999999', 'CONTRIBUTIONS', 'Cotisations', NULL, 2000000.00, 2100000.00, NULL, CURRENT_TIMESTAMP, true), (gen_random_uuid(), '99999999-9999-9999-9999-999999999999', 'OPERATIONAL', 'Opérationnel', NULL, 500000.00, 650000.00, 'DÉPASSEMENT: +150k', CURRENT_TIMESTAMP, true), (gen_random_uuid(), '99999999-9999-9999-9999-999999999999', 'SOLIDARITY', 'Solidarité', NULL, 500000.00, 450000.00, NULL, CURRENT_TIMESTAMP, true) ON CONFLICT DO NOTHING; -- ================================================================ -- VÉRIFICATION DES DONNÉES -- ================================================================ -- Compter les approbations créées SELECT status, COUNT(*) as count FROM transaction_approvals WHERE organisation_id = '00000000-0000-0000-0000-000000000001' GROUP BY status ORDER BY status; -- Compter les budgets créés SELECT status, COUNT(*) as count FROM budgets WHERE organisation_id = '00000000-0000-0000-0000-000000000001' GROUP BY status ORDER BY status; -- Afficher résumé SELECT '=============================' as separator; SELECT 'DONNÉES DE TEST CRÉÉES' as message; SELECT '=============================' as separator; SELECT 'Approbations en attente: 4' as stat; SELECT 'Approbations historiques: 2' as stat; SELECT 'Budgets actifs: 2' as stat; SELECT 'Budgets clôturés: 1' as stat; SELECT '=============================' as separator;