ajout permssion de voir les prix

This commit is contained in:
2025-06-01 15:25:54 +02:00
parent 9a9c932262
commit acab16e101
2 changed files with 56 additions and 47 deletions

View File

@ -25,7 +25,8 @@ class EventProvider with ChangeNotifier {
} else { } else {
eventsSnapshot = await _firestore eventsSnapshot = await _firestore
.collection('events') .collection('events')
.where('workforce', arrayContains: userId) .where('workforce',
arrayContains: _firestore.collection('users').doc(userId))
.get(); .get();
} }

View File

@ -35,6 +35,7 @@ class EventDetails extends StatelessWidget {
final currentIndex = sortedEvents.indexWhere((e) => e.id == event.id); final currentIndex = sortedEvents.indexWhere((e) => e.id == event.id);
final localUserProvider = Provider.of<LocalUserProvider>(context); final localUserProvider = Provider.of<LocalUserProvider>(context);
final isAdmin = localUserProvider.hasPermission('view_all_users'); final isAdmin = localUserProvider.hasPermission('view_all_users');
final canViewPrices = localUserProvider.hasPermission('view_event_prices');
return Card( return Card(
margin: const EdgeInsets.all(16), margin: const EdgeInsets.all(16),
@ -139,12 +140,13 @@ class EventDetails extends StatelessWidget {
'Date de fin', 'Date de fin',
dateFormat.format(event.endDateTime), dateFormat.format(event.endDateTime),
), ),
_buildInfoRow( if (canViewPrices)
context, _buildInfoRow(
Icons.euro, context,
'Prix de base', Icons.euro,
currencyFormat.format(event.basePrice), 'Prix de base',
), currencyFormat.format(event.basePrice),
),
if (event.options.isNotEmpty) ...[ if (event.options.isNotEmpty) ...[
const SizedBox(height: 8), const SizedBox(height: 8),
Text('Options sélectionnées', Text('Options sélectionnées',
@ -166,56 +168,62 @@ class EventDetails extends StatelessWidget {
title: Text(opt['name'] ?? '', title: Text(opt['name'] ?? '',
style: TextStyle(fontWeight: FontWeight.bold)), style: TextStyle(fontWeight: FontWeight.bold)),
subtitle: Text(opt['details'] ?? ''), subtitle: Text(opt['details'] ?? ''),
trailing: Text( trailing: canViewPrices
(isNegative ? '- ' : '+ ') + ? Text(
currencyFormat.format(price.abs()), (isNegative ? '- ' : '+ ') +
style: TextStyle( currencyFormat.format(price.abs()),
color: isNegative ? Colors.red : AppColors.noir, style: TextStyle(
fontWeight: FontWeight.bold, color: isNegative
), ? Colors.red
), : AppColors.noir,
fontWeight: FontWeight.bold,
),
)
: null,
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
dense: true, dense: true,
); );
}).toList(), }).toList(),
), ),
const SizedBox(height: 4), if (canViewPrices) ...[
Builder( const SizedBox(height: 4),
builder: (context) { Builder(
final total = event.basePrice + builder: (context) {
event.options.fold<num>( final total = event.basePrice +
0, (sum, opt) => sum + (opt['price'] ?? 0.0)); event.options.fold<num>(0,
return Padding( (sum, opt) => sum + (opt['price'] ?? 0.0));
padding: return Padding(
const EdgeInsets.only(top: 8.0, bottom: 8.0), padding:
child: Row( const EdgeInsets.only(top: 8.0, bottom: 8.0),
children: [ child: Row(
const Icon(Icons.attach_money, children: [
color: AppColors.rouge), const Icon(Icons.attach_money,
const SizedBox(width: 8), color: AppColors.rouge),
Text('Prix total : ', 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) style: Theme.of(context)
.textTheme .textTheme
.titleMedium .titleMedium
?.copyWith( ?.copyWith(
color: AppColors.noir, color: AppColors.rouge,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
)), ),
Text( ),
currencyFormat.format(total), ],
style: Theme.of(context) ),
.textTheme );
.titleMedium },
?.copyWith( ),
color: AppColors.rouge, ],
fontWeight: FontWeight.bold,
),
),
],
),
);
},
),
], ],
_buildInfoRow( _buildInfoRow(
context, context,