From acab16e1015b8473aab1657ea80f64476178cecc Mon Sep 17 00:00:00 2001 From: "PC-PAUL\\paulf" Date: Sun, 1 Jun 2025 15:25:54 +0200 Subject: [PATCH] ajout permssion de voir les prix --- em2rp/lib/providers/event_provider.dart | 3 +- .../calendar_widgets/event_details.dart | 100 ++++++++++-------- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/em2rp/lib/providers/event_provider.dart b/em2rp/lib/providers/event_provider.dart index 4efa230..46884c0 100644 --- a/em2rp/lib/providers/event_provider.dart +++ b/em2rp/lib/providers/event_provider.dart @@ -25,7 +25,8 @@ class EventProvider with ChangeNotifier { } else { eventsSnapshot = await _firestore .collection('events') - .where('workforce', arrayContains: userId) + .where('workforce', + arrayContains: _firestore.collection('users').doc(userId)) .get(); } diff --git a/em2rp/lib/views/widgets/calendar_widgets/event_details.dart b/em2rp/lib/views/widgets/calendar_widgets/event_details.dart index 45d0eff..aa68a41 100644 --- a/em2rp/lib/views/widgets/calendar_widgets/event_details.dart +++ b/em2rp/lib/views/widgets/calendar_widgets/event_details.dart @@ -35,6 +35,7 @@ class EventDetails extends StatelessWidget { final currentIndex = sortedEvents.indexWhere((e) => e.id == event.id); final localUserProvider = Provider.of(context); final isAdmin = localUserProvider.hasPermission('view_all_users'); + final canViewPrices = localUserProvider.hasPermission('view_event_prices'); return Card( margin: const EdgeInsets.all(16), @@ -139,12 +140,13 @@ class EventDetails extends StatelessWidget { 'Date de fin', dateFormat.format(event.endDateTime), ), - _buildInfoRow( - context, - Icons.euro, - 'Prix de base', - currencyFormat.format(event.basePrice), - ), + if (canViewPrices) + _buildInfoRow( + context, + Icons.euro, + 'Prix de base', + currencyFormat.format(event.basePrice), + ), if (event.options.isNotEmpty) ...[ const SizedBox(height: 8), Text('Options sélectionnées', @@ -166,56 +168,62 @@ class EventDetails extends StatelessWidget { title: Text(opt['name'] ?? '', style: TextStyle(fontWeight: FontWeight.bold)), subtitle: Text(opt['details'] ?? ''), - trailing: Text( - (isNegative ? '- ' : '+ ') + - currencyFormat.format(price.abs()), - style: TextStyle( - color: isNegative ? Colors.red : AppColors.noir, - fontWeight: FontWeight.bold, - ), - ), + trailing: canViewPrices + ? Text( + (isNegative ? '- ' : '+ ') + + currencyFormat.format(price.abs()), + style: TextStyle( + color: isNegative + ? Colors.red + : AppColors.noir, + fontWeight: FontWeight.bold, + ), + ) + : null, contentPadding: EdgeInsets.zero, dense: true, ); }).toList(), ), - const SizedBox(height: 4), - Builder( - builder: (context) { - final total = event.basePrice + - event.options.fold( - 0, (sum, opt) => sum + (opt['price'] ?? 0.0)); - return Padding( - padding: - const EdgeInsets.only(top: 8.0, bottom: 8.0), - child: Row( - children: [ - const Icon(Icons.attach_money, - color: AppColors.rouge), - const SizedBox(width: 8), - Text('Prix total : ', + if (canViewPrices) ...[ + const SizedBox(height: 4), + Builder( + builder: (context) { + final total = event.basePrice + + event.options.fold(0, + (sum, opt) => sum + (opt['price'] ?? 0.0)); + return Padding( + padding: + const EdgeInsets.only(top: 8.0, bottom: 8.0), + child: Row( + children: [ + const Icon(Icons.attach_money, + color: AppColors.rouge), + const SizedBox(width: 8), + Text('Prix total : ', + style: Theme.of(context) + .textTheme + .titleMedium + ?.copyWith( + color: AppColors.noir, + fontWeight: FontWeight.bold, + )), + Text( + currencyFormat.format(total), style: Theme.of(context) .textTheme .titleMedium ?.copyWith( - color: AppColors.noir, + color: AppColors.rouge, fontWeight: FontWeight.bold, - )), - Text( - currencyFormat.format(total), - style: Theme.of(context) - .textTheme - .titleMedium - ?.copyWith( - color: AppColors.rouge, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ); - }, - ), + ), + ), + ], + ), + ); + }, + ), + ], ], _buildInfoRow( context,