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 {
eventsSnapshot = await _firestore
.collection('events')
.where('workforce', arrayContains: userId)
.where('workforce',
arrayContains: _firestore.collection('users').doc(userId))
.get();
}

View File

@ -35,6 +35,7 @@ class EventDetails extends StatelessWidget {
final currentIndex = sortedEvents.indexWhere((e) => e.id == event.id);
final localUserProvider = Provider.of<LocalUserProvider>(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<num>(
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<num>(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,