-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
750 lines (645 loc) · 29.4 KB
/
Copy pathmain.js
File metadata and controls
750 lines (645 loc) · 29.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
// Système de Gestion Financière - Association Amicale avec Rôles et Permissions
// Données mock pour la démonstration
const ROLES = {
PRESIDENT: 'president',
TRESORIER: 'tresorier',
MEMBRE: 'membre'
};
const STATUT_DEPENSE = {
EN_ATTENTE: 'en_attente',
APPROUVEE_TRESORIER: 'approuvee_tresorier',
APPROUVEE_PRESIDENT: 'approuvee_president',
REJETEE: 'rejettee',
VALIDEE: 'validee'
};
// Utilisateur actuellement connecté (simulation)
let currentUser = {
id: 1,
nom: 'Martin',
prenom: 'Sophie',
role: ROLES.TRESORIER // Changer pour tester différents rôles
};
const mockData = {
membres: [
{ id: 1, nom: 'Martin', prenom: 'Sophie', email: 'sophie.martin@email.com', telephone: '06 12 34 56 78', dateInscription: '2023-09-15', cotisation: 25, derniereCotisation: '2024-09-15', statut: 'actif', role: ROLES.TRESORIER },
{ id: 2, nom: 'Bernard', prenom: 'Lucas', email: 'lucas.bernard@email.com', telephone: '06 23 45 67 89', dateInscription: '2023-10-02', cotisation: 25, derniereCotisation: '2024-10-02', statut: 'actif', role: ROLES.PRESIDENT },
{ id: 3, nom: 'Dubois', prenom: 'Emma', email: 'emma.dubois@email.com', telephone: '06 34 56 78 90', dateInscription: '2023-09-20', cotisation: 25, derniereCotisation: '2024-08-20', statut: 'retard', role: ROLES.MEMBRE },
{ id: 4, nom: 'Thomas', prenom: 'Hugo', email: 'hugo.thomas@email.com', telephone: '06 45 67 89 01', dateInscription: '2023-11-05', cotisation: 25, derniereCotisation: '2024-11-05', statut: 'actif', role: ROLES.MEMBRE },
{ id: 5, nom: 'Robert', prenom: 'Chloé', email: 'chloe.robert@email.com', telephone: '06 56 78 90 12', dateInscription: '2024-01-15', cotisation: 25, derniereCotisation: '2024-10-15', statut: 'actif', role: ROLES.MEMBRE },
{ id: 6, nom: 'Petit', prenom: 'Nathan', email: 'nathan.petit@email.com', telephone: '06 67 89 01 23', dateInscription: '2024-02-03', cotisation: 25, derniereCotisation: '2024-09-03', statut: 'retard', role: ROLES.MEMBRE },
{ id: 7, nom: 'Durand', prenom: 'Léa', email: 'lea.durand@email.com', telephone: '06 78 90 12 34', dateInscription: '2023-12-10', cotisation: 25, derniereCotisation: '2024-11-10', statut: 'actif', role: ROLES.MEMBRE },
{ id: 8, nom: 'Leroy', prenom: 'Julien', email: 'julien.leroy@email.com', telephone: '06 89 01 23 45', dateInscription: '2024-03-22', cotisation: 25, derniereCotisation: '2024-10-22', statut: 'actif', role: ROLES.MEMBRE },
{ id: 9, nom: 'Moreau', prenom: 'Camille', email: 'camille.moreau@email.com', telephone: '06 90 12 34 56', dateInscription: '2023-09-05', cotisation: 25, derniereCotisation: '2024-09-05', statut: 'actif', role: ROLES.MEMBRE },
{ id: 10, nom: 'Simon', prenom: 'Alexis', email: 'alexis.simon@email.com', telephone: '06 01 23 45 67', dateInscription: '2024-04-18', cotisation: 25, derniereCotisation: '2024-10-18', statut: 'actif', role: ROLES.MEMBRE }
],
transactions: [
// Transactions existantes...
{ id: 1, date: '2024-10-15', type: 'entrée', categorie: 'Cotisations', description: 'Cotisations membres Octobre', montant: 425, membreId: null, statut: STATUT_DEPENSE.VALIDEE },
{ id: 2, date: '2024-10-12', type: 'sortie', categorie: 'Événements', description: 'Location salle pour soirée étudiante', montant: 150, membreId: null, statut: STATUT_DEPENSE.VALIDEE },
{ id: 3, date: '2024-10-08', type: 'sortie', categorie: 'Matériel', description: 'Achat matériel informatique', montant: 320, membreId: null, statut: STATUT_DEPENSE.VALIDEE }
],
demandesDepenses: [
{
id: 1,
membreId: 3,
montant: 45,
categorie: 'Transport',
description: 'Transport pour événement caritatif',
dateDemande: '2024-10-20',
justificatif: 'ticket_transport.jpg',
statut: STATUT_DEPENSE.EN_ATTENTE,
approuveParTresorier: null,
approuveParPresident: null,
dateApprobation: null
},
{
id: 2,
membreId: 5,
montant: 120,
categorie: 'Communication',
description: 'Impression affiches événement',
dateDemande: '2024-10-18',
justificatif: 'devis_impression.pdf',
statut: STATUT_DEPENSE.APPROUVEE_TRESORIER,
approuveParTresorier: 1,
approuveParPresident: null,
dateApprobation: null
}
],
notifications: [
{
id: 1,
membreId: 3,
type: 'cotisation_retard',
message: 'Votre cotisation est en retard. Merci de régulariser votre situation.',
date: '2024-10-15',
lue: false
},
{
id: 2,
membreId: 1,
type: 'demande_depense',
message: 'Nouvelle demande de dépense de Emma Dubois (€45) en attente d\'approbation.',
date: '2024-10-20',
lue: false
}
]
};
// Fonctions utilitaires
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('fr-FR');
}
function formatMontant(montant) {
return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(montant);
}
function calculerSoldeActuel() {
return mockData.transactions.reduce((solde, transaction) => {
return transaction.type === 'entrée' ? solde + transaction.montant : solde - transaction.montant;
}, 0);
}
function calculerMontantMois() {
const maintenant = new Date();
const moisActuel = maintenant.getMonth();
const anneeActuelle = maintenant.getFullYear();
return mockData.transactions
.filter(transaction => {
const dateTransaction = new Date(transaction.date);
return dateTransaction.getMonth() === moisActuel && dateTransaction.getFullYear() === anneeActuelle;
})
.reduce((total, transaction) => {
return transaction.type === 'entrée' ? total + transaction.montant : total - transaction.montant;
}, 0);
}
function obtenirStatistiquesMembres() {
const totalMembres = mockData.membres.length;
const membresActifs = mockData.membres.filter(m => m.statut === 'actif').length;
const membresRetard = mockData.membres.filter(m => m.statut === 'retard').length;
return { totalMembres, membresActifs, membresRetard };
}
// Fonctions de vérification des permissions
function hasPermission(action) {
switch (action) {
case 'view_all_transactions':
return currentUser.role === ROLES.TRESORIER || currentUser.role === ROLES.PRESIDENT;
case 'approve_expenses':
return currentUser.role === ROLES.TRESORIER || currentUser.role === ROLES.PRESIDENT;
case 'approve_large_expenses':
return currentUser.role === ROLES.PRESIDENT;
case 'create_expense_request':
return currentUser.role === ROLES.MEMBRE;
case 'view_own_expenses':
return true; // Tous les membres peuvent voir leurs propres dépenses
default:
return false;
}
}
function isLargeExpense(montant) {
return montant > 100; // Seuil pour nécessiter l'approbation du président
}
// Gestion des demandes de dépenses
function creerDemandeDepense(demandeData) {
if (!hasPermission('create_expense_request')) {
throw new Error('Vous n\'avez pas la permission de créer une demande de dépense.');
}
const nouvelleDemande = {
id: mockData.demandesDepenses.length + 1,
membreId: currentUser.id,
montant: demandeData.montant,
categorie: demandeData.categorie,
description: demandeData.description,
dateDemande: new Date().toISOString().split('T')[0],
justificatif: demandeData.justificatif || null,
statut: STATUT_DEPENSE.EN_ATTENTE,
approuveParTresorier: null,
approuveParPresident: null,
dateApprobation: null
};
mockData.demandesDepenses.push(nouvelleDemande);
// Créer une notification pour le trésorier
const tresorier = mockData.membres.find(m => m.role === ROLES.TRESORIER);
if (tresorier) {
mockData.notifications.push({
id: mockData.notifications.length + 1,
membreId: tresorier.id,
type: 'demande_depense',
message: `Nouvelle demande de dépense de ${currentUser.prenom} ${currentUser.nom} (${formatMontant(demandeData.montant)}) en attente d'approbation.`,
date: new Date().toISOString().split('T')[0],
lue: false
});
}
return nouvelleDemande;
}
function approuverDemandeDepense(demandeId, role) {
const demande = mockData.demandesDepenses.find(d => d.id === demandeId);
if (!demande) {
throw new Error('Demande de dépense introuvable.');
}
if (role === ROLES.TRESORIER) {
if (demande.statut !== STATUT_DEPENSE.EN_ATTENTE) {
throw new Error('Cette demande n\'est plus en attente d\'approbation.');
}
demande.statut = STATUT_DEPENSE.APPROUVEE_TRESORIER;
demande.approuveParTresorier = currentUser.id;
// Si c'est une petite dépense, elle est automatiquement validée
if (!isLargeExpense(demande.montant)) {
demande.statut = STATUT_DEPENSE.VALIDEE;
demande.dateApprobation = new Date().toISOString().split('T')[0];
// Créer la transaction correspondante
const nouvelleTransaction = {
id: mockData.transactions.length + 1,
date: demande.dateApprobation,
type: 'sortie',
categorie: demande.categorie,
description: demande.description,
montant: demande.montant,
membreId: demande.membreId,
statut: STATUT_DEPENSE.VALIDEE
};
mockData.transactions.push(nouvelleTransaction);
} else {
// Pour les grandes dépenses, notifier le président
const president = mockData.membres.find(m => m.role === ROLES.PRESIDENT);
if (president) {
mockData.notifications.push({
id: mockData.notifications.length + 1,
membreId: president.id,
type: 'demande_depense_president',
message: `Demande de dépense de ${formatMontant(demande.montant)} nécessite votre approbation présidentielle.`,
date: new Date().toISOString().split('T')[0],
lue: false
});
}
}
} else if (role === ROLES.PRESIDENT) {
if (demande.statut !== STATUT_DEPENSE.APPROUVEE_TRESORIER) {
throw new Error('Cette demande doit d\'abord être approuvée par le trésorier.');
}
if (!isLargeExpense(demande.montant)) {
throw new Error('Seules les dépenses supérieures à 100€ nécessitent l\'approbation du président.');
}
demande.statut = STATUT_DEPENSE.APPROUVEE_PRESIDENT;
demande.approuveParPresident = currentUser.id;
demande.dateApprobation = new Date().toISOString().split('T')[0];
// Créer la transaction correspondante
const nouvelleTransaction = {
id: mockData.transactions.length + 1,
date: demande.dateApprobation,
type: 'sortie',
categorie: demande.categorie,
description: demande.description,
montant: demande.montant,
membreId: demande.membreId,
statut: STATUT_DEPENSE.VALIDEE
};
mockData.transactions.push(nouvelleTransaction);
}
return demande;
}
function rejeterDemandeDepense(demandeId, raison) {
const demande = mockData.demandesDepenses.find(d => d.id === demandeId);
if (!demande) {
throw new Error('Demande de dépense introuvable.');
}
demande.statut = STATUT_DEPENSE.REJETEE;
demande.raisonRejet = raison;
// Notifier le membre du rejet
mockData.notifications.push({
id: mockData.notifications.length + 1,
membreId: demande.membreId,
type: 'demande_rejetee',
message: `Votre demande de dépense de ${formatMontant(demande.montant)} a été rejetée. Raison: ${raison}`,
date: new Date().toISOString().split('T')[0],
lue: false
});
return demande;
}
// Gestion des notifications
function obtenirNotifications() {
return mockData.notifications.filter(n => n.membreId === currentUser.id && !n.lue);
}
function marquerNotificationLue(notificationId) {
const notification = mockData.notifications.find(n => n.id === notificationId);
if (notification) {
notification.lue = true;
}
}
// Fonctions d'animation
function animerElements() {
if (typeof anime !== 'undefined') {
anime({
targets: '.metric-card',
translateY: [50, 0],
opacity: [0, 1],
delay: anime.stagger(100),
duration: 800,
easing: 'easeOutQuart'
});
anime({
targets: '.chart-container',
scale: [0.8, 1],
opacity: [0, 1],
delay: 300,
duration: 1000,
easing: 'easeOutElastic(1, .8)'
});
}
}
// Fonctions de filtrage
function filtrerTransactions(categorie = null, type = null, dateDebut = null, dateFin = null) {
let transactionsFiltrees = [...mockData.transactions];
if (categorie && categorie !== 'tous') {
transactionsFiltrees = transactionsFiltrees.filter(t => t.categorie === categorie);
}
if (type && type !== 'tous') {
transactionsFiltrees = transactionsFiltrees.filter(t => t.type === type);
}
if (dateDebut) {
transactionsFiltrees = transactionsFiltrees.filter(t => new Date(t.date) >= new Date(dateDebut));
}
if (dateFin) {
transactionsFiltrees = transactionsFiltrees.filter(t => new Date(t.date) <= new Date(dateFin));
}
// Filtrer selon les permissions
if (!hasPermission('view_all_transactions')) {
transactionsFiltrees = transactionsFiltrees.filter(t => t.membreId === currentUser.id);
}
return transactionsFiltrees;
}
function filtrerDemandesDepenses(statut = null, membreId = null) {
let demandesFiltrees = [...mockData.demandesDepenses];
if (statut && statut !== 'tous') {
demandesFiltrees = demandesFiltrees.filter(d => d.statut === statut);
}
if (membreId) {
demandesFiltrees = demandesFiltrees.filter(d => d.membreId === membreId);
}
// Filtrer selon les permissions
if (!hasPermission('view_all_transactions')) {
demandesFiltrees = demandesFiltrees.filter(d => d.membreId === currentUser.id);
}
return demandesFiltrees;
}
// Fonctions d'affichage
function afficherTransactions(transactions, elementId) {
const tbody = document.querySelector(`#${elementId} tbody`);
if (!tbody) return;
tbody.innerHTML = '';
transactions.forEach(transaction => {
const tr = document.createElement('tr');
tr.className = 'hover:bg-blue-50 transition-colors';
tr.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${formatDate(transaction.date)}</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full ${transaction.type === 'entrée' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}">
${transaction.type}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${transaction.categorie}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${transaction.description}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium ${transaction.type === 'entrée' ? 'text-green-600' : 'text-red-600'}">
${transaction.type === 'entrée' ? '+' : '-'}${formatMontant(transaction.montant)}
</td>
`;
tbody.appendChild(tr);
});
}
function afficherDemandesDepenses(demandes, elementId) {
const tbody = document.querySelector(`#${elementId} tbody`);
if (!tbody) return;
tbody.innerHTML = '';
demandes.forEach(demande => {
const membre = mockData.membres.find(m => m.id === demande.membreId);
const tr = document.createElement('tr');
tr.className = 'hover:bg-blue-50 transition-colors';
const statutColors = {
[STATUT_DEPENSE.EN_ATTENTE]: 'bg-yellow-100 text-yellow-800',
[STATUT_DEPENSE.APPROUVEE_TRESORIER]: 'bg-blue-100 text-blue-800',
[STATUT_DEPENSE.APPROUVEE_PRESIDENT]: 'bg-purple-100 text-purple-800',
[STATUT_DEPENSE.VALIDEE]: 'bg-green-100 text-green-800',
[STATUT_DEPENSE.REJETEE]: 'bg-red-100 text-red-800'
};
tr.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${formatDate(demande.dateDemande)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${membre ? `${membre.prenom} ${membre.nom}` : 'Inconnu'}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${demande.categorie}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${demande.description}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-red-600">-${formatMontant(demande.montant)}</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full ${statutColors[demande.statut]}">
${demande.statut.replace('_', ' ')}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
${afficherActionsDemande(demande)}
</td>
`;
tbody.appendChild(tr);
});
}
function afficherActionsDemande(demande) {
let actions = '';
if (demande.statut === STATUT_DEPENSE.EN_ATTENTE && hasPermission('approve_expenses') && currentUser.role === ROLES.TRESORIER) {
actions += `<button onclick="approuverDemandeTresorier(${demande.id})" class="text-blue-600 hover:text-blue-800 mr-2">Approuver</button>`;
actions += `<button onclick="rejeterDemande(${demande.id})" class="text-red-600 hover:text-red-800 mr-2">Rejeter</button>`;
}
if (demande.statut === STATUT_DEPENSE.APPROUVEE_TRESORIER && hasPermission('approve_large_expenses') && currentUser.role === ROLES.PRESIDENT) {
actions += `<button onclick="approuverDemandePresident(${demande.id})" class="text-purple-600 hover:text-purple-800 mr-2">Valider</button>`;
actions += `<button onclick="rejeterDemande(${demande.id})" class="text-red-600 hover:text-red-800 mr-2">Rejeter</button>`;
}
if (demande.membreId === currentUser.id) {
actions += `<button onclick="voirDetailsDemande(${demande.id})" class="text-gray-600 hover:text-gray-800">Détails</button>`;
}
return actions || '<span class="text-gray-400">Aucune action</span>';
}
function afficherMembres(membres, elementId) {
const tbody = document.querySelector(`#${elementId} tbody`);
if (!tbody) return;
tbody.innerHTML = '';
membres.forEach(membre => {
const tr = document.createElement('tr');
tr.className = 'hover:bg-blue-50 transition-colors';
tr.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${membre.prenom} ${membre.nom}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${membre.email}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${membre.telephone}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${formatDate(membre.dateInscription)}</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full ${membre.statut === 'actif' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}">
${membre.statut}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${formatDate(membre.derniereCotisation)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 capitalize">${membre.role}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-blue-600">
<button onclick="ouvrirModalMembre(${membre.id})" class="hover:text-blue-800 transition-colors">
Voir détails
</button>
</td>
`;
tbody.appendChild(tr);
});
}
// Fonctions de graphiques
function creerGraphiqueSolde(elementId) {
if (typeof echarts === 'undefined') return;
const chartDom = document.getElementById(elementId);
if (!chartDom) return;
const myChart = echarts.init(chartDom);
// Calculer l'évolution du solde
const transactionsTriees = [...mockData.transactions].sort((a, b) => new Date(a.date) - new Date(b.date));
let solde = 0;
const dates = [];
const soldes = [];
transactionsTriees.forEach(transaction => {
solde += transaction.type === 'entrée' ? transaction.montant : -transaction.montant;
dates.push(formatDate(transaction.date));
soldes.push(solde);
});
const option = {
title: {
text: 'Évolution du solde',
textStyle: { color: '#1e3a8a', fontSize: 18, fontWeight: 'bold' }
},
tooltip: {
trigger: 'axis',
formatter: function(params) {
return `${params[0].name}<br/>Solde: ${formatMontant(params[0].value)}`;
}
},
xAxis: {
type: 'category',
data: dates,
axisLabel: { color: '#6b7280' }
},
yAxis: {
type: 'value',
axisLabel: {
color: '#6b7280',
formatter: function(value) {
return formatMontant(value);
}
}
},
series: [{
data: soldes,
type: 'line',
smooth: true,
itemStyle: { color: '#3b82f6' },
areaStyle: { color: 'rgba(59, 130, 246, 0.1)' }
}]
};
myChart.setOption(option);
}
function creerGraphiqueRepartition(elementId) {
if (typeof echarts === 'undefined') return;
const chartDom = document.getElementById(elementId);
if (!chartDom) return;
const myChart = echarts.init(chartDom);
// Calculer la répartition des dépenses par catégorie
const depensesParCategorie = {};
mockData.transactions
.filter(t => t.type === 'sortie')
.forEach(transaction => {
depensesParCategorie[transaction.categorie] = (depensesParCategorie[transaction.categorie] || 0) + transaction.montant;
});
const data = Object.entries(depensesParCategorie).map(([categorie, montant]) => ({
name: categorie,
value: montant
}));
const option = {
title: {
text: 'Répartition des dépenses',
textStyle: { color: '#1e3a8a', fontSize: 18, fontWeight: 'bold' }
},
tooltip: {
trigger: 'item',
formatter: function(params) {
return `${params.name}<br/>${formatMontant(params.value)} (${params.percent}%)`;
}
},
series: [{
type: 'pie',
radius: '70%',
data: data,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
itemStyle: {
color: function(params) {
const colors = ['#3b82f6', '#1e40af', '#1e3a8a', '#3730a3', '#581c87'];
return colors[params.dataIndex % colors.length];
}
}
}]
};
myChart.setOption(option);
}
// Gestion des modales
function ouvrirModalMembre(membreId) {
const membre = mockData.membres.find(m => m.id === membreId);
if (!membre) return;
const modal = document.getElementById('modalMembre');
if (!modal) return;
// Remplir les informations du membre
document.getElementById('modalMembreNom').textContent = `${membre.prenom} ${membre.nom}`;
document.getElementById('modalMembreEmail').textContent = membre.email;
document.getElementById('modalMembreTelephone').textContent = membre.telephone;
document.getElementById('modalMembreInscription').textContent = formatDate(membre.dateInscription);
document.getElementById('modalMembreCotisation').textContent = formatDate(membre.derniereCotisation);
document.getElementById('modalMembreStatut').textContent = membre.statut;
const statutBadge = document.getElementById('modalMembreStatutBadge');
statutBadge.className = `inline-flex px-2 py-1 text-xs font-semibold rounded-full ${membre.statut === 'actif' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}`;
modal.classList.remove('hidden');
}
function fermerModalMembre() {
const modal = document.getElementById('modalMembre');
if (modal) {
modal.classList.add('hidden');
}
}
// Initialisation au chargement de la page
document.addEventListener('DOMContentLoaded', function() {
// Initialiser les animations
setTimeout(animerElements, 100);
// Initialiser les graphiques si sur la page du tableau de bord
if (document.getElementById('graphiqueSolde')) {
setTimeout(() => {
creerGraphiqueSolde('graphiqueSolde');
creerGraphiqueRepartition('graphiqueRepartition');
}, 500);
}
// Afficher les données initiales selon les permissions
if (document.getElementById('tableauTransactions')) {
const transactions = hasPermission('view_all_transactions') ?
mockData.transactions :
mockData.transactions.filter(t => t.membreId === currentUser.id);
afficherTransactions(transactions.slice(0, 10), 'tableauTransactions');
}
if (document.getElementById('tableauMembres') && hasPermission('view_all_transactions')) {
afficherMembres(mockData.membres, 'tableauMembres');
}
if (document.getElementById('tableauDemandes')) {
const demandes = filtrerDemandesDepenses();
afficherDemandesDepenses(demandes, 'tableauDemandes');
}
// Afficher les notifications
afficherNotifications();
// Gestion des filtres
const filtres = document.querySelectorAll('.filtre-transaction');
filtres.forEach(filtre => {
filtre.addEventListener('change', function() {
const categorie = document.getElementById('filtreCategorie')?.value || 'tous';
const type = document.getElementById('filtreType')?.value || 'tous';
const dateDebut = document.getElementById('filtreDateDebut')?.value || null;
const dateFin = document.getElementById('filtreDateFin')?.value || null;
const transactionsFiltrees = filtrerTransactions(categorie, type, dateDebut, dateFin);
afficherTransactions(transactionsFiltrees, 'tableauTransactions');
});
});
// Gestion de la modale
const modal = document.getElementById('modalMembre');
if (modal) {
modal.addEventListener('click', function(e) {
if (e.target === modal) {
fermerModalMembre();
}
});
}
// Bouton de fermeture de la modale
const boutonFermer = document.getElementById('fermerModalMembre');
if (boutonFermer) {
boutonFermer.addEventListener('click', fermerModalMembre);
}
});
// Fonctions globales pour les boutons
function afficherNotifications() {
const notifications = obtenirNotifications();
const notificationBadge = document.getElementById('notificationBadge');
const notificationList = document.getElementById('notificationList');
if (notificationBadge && notifications.length > 0) {
notificationBadge.textContent = notifications.length;
notificationBadge.classList.remove('hidden');
}
if (notificationList) {
notificationList.innerHTML = '';
notifications.forEach(notification => {
const li = document.createElement('li');
li.className = 'p-2 hover:bg-gray-100 cursor-pointer';
li.onclick = () => marquerNotificationLue(notification.id);
li.innerHTML = `
<div class="text-sm text-gray-900">${notification.message}</div>
<div class="text-xs text-gray-500">${formatDate(notification.date)}</div>
`;
notificationList.appendChild(li);
});
}
}
// Export des fonctions pour utilisation globale
window.gestionFinanciere = {
mockData,
currentUser,
ROLES,
STATUT_DEPENSE,
hasPermission,
isLargeExpense,
calculerSoldeActuel,
calculerMontantMois,
obtenirStatistiquesMembres,
creerDemandeDepense,
approuverDemandeDepense,
rejeterDemandeDepense,
filtrerTransactions,
filtrerDemandesDepenses,
afficherTransactions,
afficherDemandesDepenses,
afficherMembres,
ouvrirModalMembre,
fermerModalMembre,
formatDate,
formatMontant
};