Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
addb06a61a | ||
|
|
5e505d96b3 | ||
|
|
66c7094ada | ||
|
|
bd496ad37f |
No files matched your search
@@ -53,7 +53,9 @@ class StaffSection extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
final staffMembers = state.storeStaff;
|
||||
final staffMembers = state.storeStaff
|
||||
.where((staff) => staff.isActive || staff.id == selectedStaffId)
|
||||
.toList();
|
||||
|
||||
// FIX: Feedback visivo se la lista è vuota
|
||||
if (staffMembers.isEmpty) {
|
||||
|
||||
@@ -61,7 +61,21 @@ class StaffSelectorModal extends StatelessWidget {
|
||||
if (state.status == StaffStatus.loading) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
final staffList = state.storeStaff;
|
||||
final rawList = state.storeStaff.isNotEmpty
|
||||
? state.storeStaff
|
||||
: state.allStaff;
|
||||
final staffList = rawList.where((s) => s.isActive).toList();
|
||||
|
||||
if (staffList.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24.0),
|
||||
child: Text(
|
||||
'Nessun collaboratore attivo trovato.',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return _buildStaffGrid(context, staffList);
|
||||
},
|
||||
),
|
||||
|
||||
+25
-14
@@ -107,7 +107,17 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
storeId: storeId,
|
||||
);
|
||||
|
||||
final activeStaff = allStaff.where((s) => s.isActive).toList();
|
||||
// 1. Escludiamo i collaboratori con qualifica Manager o Tester, o disattivati
|
||||
final Set<String> excludedStaffIds = {};
|
||||
for (final s in allStaff) {
|
||||
if (s.isExcludedFromRicontattiFocus && s.id != null) {
|
||||
excludedStaffIds.add(s.id!);
|
||||
}
|
||||
}
|
||||
|
||||
final activeEligibleStaff = allStaff
|
||||
.where((s) => !s.isExcludedFromRicontattiFocus)
|
||||
.toList();
|
||||
|
||||
// 2. Recupero conteggi mensili per addetto del negozio
|
||||
final monthlyCountsByStaff =
|
||||
@@ -117,11 +127,6 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
month: now,
|
||||
);
|
||||
|
||||
int grandMonthTotal = 0;
|
||||
for (final mVal in monthlyCountsByStaff.values) {
|
||||
grandMonthTotal += mVal;
|
||||
}
|
||||
|
||||
// 3. Recupero operazioni create oggi nel negozio
|
||||
final paginatedOps = await _operationsRepository.fetchPaginatedOperations(
|
||||
companyId: companyId!,
|
||||
@@ -137,12 +142,11 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
return op.details.any((d) => d.type == OperationType.ricontatto);
|
||||
}).toList();
|
||||
|
||||
// 5. Raggruppamento per addetto
|
||||
// 5. Raggruppamento per addetto ammissibile
|
||||
final List<StaffDailyRicontattiSummary> summaries = [];
|
||||
final Set<String> processedStaffIds = {};
|
||||
int grandTotal = 0;
|
||||
final Set<String> processedStaffIds = Set<String>.from(excludedStaffIds);
|
||||
|
||||
for (final staff in activeStaff) {
|
||||
for (final staff in activeEligibleStaff) {
|
||||
final staffId = staff.id ?? '';
|
||||
processedStaffIds.add(staffId);
|
||||
|
||||
@@ -154,7 +158,6 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
staffCount += countInOp > 0 ? countInOp : 1;
|
||||
}
|
||||
|
||||
grandTotal += staffCount;
|
||||
final staffMonthCount = monthlyCountsByStaff[staffId] ?? 0;
|
||||
|
||||
summaries.add(
|
||||
@@ -182,7 +185,6 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
final countInOp = o.details.where((d) => d.type == OperationType.ricontatto).length;
|
||||
staffCount += countInOp > 0 ? countInOp : 1;
|
||||
}
|
||||
grandTotal += staffCount;
|
||||
final staffMonthCount = monthlyCountsByStaff[opStaffId] ?? 0;
|
||||
|
||||
summaries.add(
|
||||
@@ -197,7 +199,15 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Ordinamento: per numero di ricontatti oggi decrescente, poi per mese decrescente, poi per nome
|
||||
// 7. Calcolo totali coerenti con gli addetti visibili
|
||||
int grandTotal = 0;
|
||||
int grandMonthTotal = 0;
|
||||
for (final s in summaries) {
|
||||
grandTotal += s.count;
|
||||
grandMonthTotal += s.monthCount;
|
||||
}
|
||||
|
||||
// 8. Ordinamento: per numero di ricontatti oggi decrescente, poi per mese decrescente, poi per nome
|
||||
summaries.sort((a, b) {
|
||||
final countCmp = b.count.compareTo(a.count);
|
||||
if (countCmp != 0) return countCmp;
|
||||
@@ -218,7 +228,8 @@ class DashboardDailyRicontattiCubit extends Cubit<DashboardDailyRicontattiState>
|
||||
errorMessage: null,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
} catch (e, stack) {
|
||||
debugPrint('Errore in DashboardDailyRicontattiCubit: $e\n$stack');
|
||||
if (isClosed) return;
|
||||
emit(
|
||||
state.copyWith(
|
||||
|
||||
+3
-5
@@ -6,7 +6,6 @@ import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/features/home/dashboard_daily_ricontatti/blocs/dashboard_daily_ricontatti_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_daily_ricontatti/blocs/dashboard_daily_ricontatti_state.dart';
|
||||
import 'package:flux/features/home/dashboard_daily_ricontatti/models/staff_daily_ricontatti_summary.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/operations/models/operation_type.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -16,12 +15,11 @@ class DashboardDailyRicontattiCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Visibile solo ai manager o admin
|
||||
// Visibile a chi ha qualifica Manager o Titolare (o Admin di sistema)
|
||||
final staff = context.watch<SessionCubit>().state.currentStaffMember;
|
||||
final isManager = staff?.systemRole == SystemRole.manager ||
|
||||
staff?.systemRole == SystemRole.admin;
|
||||
final canView = staff?.canViewRicontattiFocus ?? false;
|
||||
|
||||
if (!isManager) {
|
||||
if (!canView) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,20 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
},
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
// --- HERO TARGET DEL GIORNO (TUTTA LARGHEZZA IN CIMA) ---
|
||||
// --- 1. QUICK ACTIONS: AZIONI RAPIDE (IN CIMA) ---
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24.0, 0, 24.0, 24.0),
|
||||
child: _buildQuickActions(context),
|
||||
),
|
||||
),
|
||||
|
||||
// --- 2. HERO FOCUS RICONTATTI DEL GIORNO (VISIBILE AI MANAGER) ---
|
||||
const SliverToBoxAdapter(
|
||||
child: DashboardDailyRicontattiCard(),
|
||||
),
|
||||
|
||||
// --- 3. HERO TARGET DEL GIORNO ---
|
||||
const SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(24.0, 0, 24.0, 24.0),
|
||||
@@ -160,22 +173,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// --- HERO FOCUS RICONTATTI DEL GIORNO (SOLO MANAGER) ---
|
||||
const SliverToBoxAdapter(
|
||||
child: DashboardDailyRicontattiCard(),
|
||||
),
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 8)),
|
||||
|
||||
// --- QUICK ACTIONS: AZIONI RAPIDE ---
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: _buildQuickActions(context),
|
||||
),
|
||||
),
|
||||
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 32)),
|
||||
|
||||
// --- I WIDGET DELLA DASHBOARD (Responsive Grid) ---
|
||||
// --- 4. I WIDGET DELLA DASHBOARD (Responsive Grid) ---
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
sliver: SliverGrid(
|
||||
|
||||
@@ -24,21 +24,23 @@ class StaffRepository {
|
||||
${Tables.stores}(*)
|
||||
)
|
||||
''')
|
||||
.eq('company_id', companyId);
|
||||
.eq('company_id', companyId)
|
||||
.order('name', ascending: true);
|
||||
|
||||
if (storeId != null) {
|
||||
filterBuilder = filterBuilder.or(
|
||||
'store_id.eq.$storeId,store_id.is.null',
|
||||
);
|
||||
}
|
||||
final response = await filterBuilder;
|
||||
|
||||
var transformBuilder = filterBuilder.order('name', ascending: true);
|
||||
|
||||
final response = await transformBuilder;
|
||||
|
||||
return (response as List)
|
||||
final list = (response as List)
|
||||
.map((s) => StaffMemberModel.fromMap(s))
|
||||
.toList();
|
||||
|
||||
if (storeId != null) {
|
||||
return list
|
||||
.where((s) =>
|
||||
s.assignedStoreIds.isEmpty || s.assignedStoreIds.contains(storeId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
return list;
|
||||
} on Exception catch (e) {
|
||||
debugPrint('Errore nel recupero della lista di staff: $e');
|
||||
throw Exception('Errore nel recupero della lista di staff: $e');
|
||||
|
||||
@@ -77,6 +77,35 @@ class StaffMemberModel extends Equatable {
|
||||
);
|
||||
}
|
||||
|
||||
/// Indica se il collaboratore ha la qualifica di Manager o Titolare (tramite jobTitle)
|
||||
bool get isManagerOrTitolare {
|
||||
final title = (jobTitle ?? '').trim().toLowerCase();
|
||||
return title.contains('manager') || title.contains('titolare');
|
||||
}
|
||||
|
||||
/// Discriminante per vedere o meno il Focus Ricontatti: Manager e Titolare (o Admin di sistema)
|
||||
bool get canViewRicontattiFocus {
|
||||
if (isManagerOrTitolare) return true;
|
||||
if (systemRole == SystemRole.admin) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Discriminante per non comparire tra gli utenti "controllati" (addetti):
|
||||
/// Manager, Titolari, Tester o collaboratori disattivati
|
||||
bool get isExcludedFromControlledStaff {
|
||||
if (!isActive) return true;
|
||||
final title = (jobTitle ?? '').trim().toLowerCase();
|
||||
if (title.contains('manager') ||
|
||||
title.contains('titolare') ||
|
||||
title.contains('tester')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Alias retrocompatibile
|
||||
bool get isExcludedFromRicontattiFocus => isExcludedFromControlledStaff;
|
||||
|
||||
factory StaffMemberModel.empty() {
|
||||
return const StaffMemberModel(
|
||||
companyId: '',
|
||||
|
||||
@@ -142,24 +142,64 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
myRole == SystemRole.admin || myRole == SystemRole.manager;
|
||||
final hasEmail = member.email != null && member.email!.trim().isNotEmpty;
|
||||
|
||||
final bool isActive = member.isActive;
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
color: isActive ? null : context.surface.withValues(alpha: 0.6),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: context.accent.withValues(alpha: 0.1)),
|
||||
side: BorderSide(
|
||||
color: isActive
|
||||
? context.accent.withValues(alpha: 0.1)
|
||||
: Colors.red.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.all(12),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: context.accent.withValues(alpha: 0.1),
|
||||
backgroundColor: isActive
|
||||
? context.accent.withValues(alpha: 0.1)
|
||||
: Colors.grey.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
member.name[0].toUpperCase(),
|
||||
style: TextStyle(color: context.accent),
|
||||
style: TextStyle(
|
||||
color: isActive ? context.accent : Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
member.name,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
title: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
member.name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isActive ? null : context.secondaryText,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (!isActive) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: Colors.red.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: const Text(
|
||||
'DISATTIVATO',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -177,19 +217,18 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
Text(
|
||||
'Qualifica: ${member.jobTitle!}',
|
||||
style: TextStyle(
|
||||
color: context.accent,
|
||||
color: isActive ? context.accent : Colors.grey,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
// MODIFICA UX: Menu a tendina per le azioni (Salva spazio e previene overflow)
|
||||
trailing: canManageStaff && hasEmail
|
||||
trailing: canManageStaff
|
||||
? PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
if (value == 'invite_reset') {
|
||||
onSelected: (value) async {
|
||||
if (value == 'invite_reset' && hasEmail) {
|
||||
if (!member.hasJoined) {
|
||||
context.read<StaffCubit>().inviteStaffMember(
|
||||
member: member,
|
||||
@@ -207,22 +246,97 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
} else {
|
||||
context.read<StaffCubit>().resetPassword(member.email!);
|
||||
}
|
||||
} else if (value == 'toggle_active') {
|
||||
final newActiveState = !member.isActive;
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(
|
||||
newActiveState
|
||||
? "Riattivare ${member.name}?"
|
||||
: "Disattivare ${member.name}?",
|
||||
),
|
||||
content: Text(
|
||||
newActiveState
|
||||
? "L'addetto tornerà attivo e selezionabile per nuove operazioni, ticket e gare."
|
||||
: "L'addetto non comparirà più nella selezione per nuove operazioni o ticket e non comparirà nelle gare e nelle loro ripartizioni. I dati storici rimarranno intatti.",
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: const Text("Annulla"),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor:
|
||||
newActiveState ? Colors.green : Colors.red,
|
||||
),
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: Text(
|
||||
newActiveState ? "Riattiva" : "Disattiva",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm != true || !mounted) return;
|
||||
|
||||
context.read<StaffCubit>().saveStaffMember(
|
||||
member.copyWith(isActive: newActiveState),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
newActiveState
|
||||
? "${member.name} riattivato con successo!"
|
||||
: "${member.name} disattivato con successo.",
|
||||
),
|
||||
backgroundColor:
|
||||
newActiveState ? Colors.green : Colors.orange.shade800,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
if (hasEmail)
|
||||
PopupMenuItem(
|
||||
value: 'invite_reset',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
!member.hasJoined ? Icons.send : Icons.lock_reset,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
!member.hasJoined
|
||||
? "Re-invia Invito"
|
||||
: "Reset Password",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'invite_reset',
|
||||
value: 'toggle_active',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
!member.hasJoined ? Icons.send : Icons.lock_reset,
|
||||
member.isActive
|
||||
? Icons.person_off_outlined
|
||||
: Icons.person_add_alt_outlined,
|
||||
size: 20,
|
||||
color: member.isActive ? Colors.redAccent : Colors.green,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
!member.hasJoined
|
||||
? "Re-invia Invito"
|
||||
: "Reset Password",
|
||||
member.isActive
|
||||
? "Disattiva Addetto"
|
||||
: "Riattiva Addetto",
|
||||
style: TextStyle(
|
||||
color:
|
||||
member.isActive ? Colors.redAccent : Colors.green,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -241,6 +355,7 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
final emailController = TextEditingController(text: member?.email);
|
||||
final phoneController = TextEditingController(text: member?.phoneNumber);
|
||||
final jobTitleController = TextEditingController(text: member?.jobTitle);
|
||||
bool isActive = member?.isActive ?? true;
|
||||
|
||||
SystemRole selectedRole = member?.systemRole ?? SystemRole.user;
|
||||
List<String> tempSelectedStores =
|
||||
@@ -345,7 +460,31 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// SWITCH ATTIVO / DISATTIVATO
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: isActive,
|
||||
title: const Text(
|
||||
"Collaboratore Attivo",
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
subtitle: Text(
|
||||
isActive
|
||||
? "Visibile per nuove operazioni, ticket e gare"
|
||||
: "Disattivato (invisibile per nuove operazioni, ticket e gare)",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: context.secondaryText,
|
||||
),
|
||||
),
|
||||
activeThumbColor: context.accent,
|
||||
onChanged: (val) {
|
||||
setModalState(() => isActive = val);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
const Text(
|
||||
"Assegna ai Negozi",
|
||||
@@ -412,6 +551,7 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
phoneNumber: phoneController.text.trim(),
|
||||
jobTitle: jobTitleController.text.trim(),
|
||||
systemRole: selectedRole,
|
||||
isActive: isActive,
|
||||
companyId: GetIt.I
|
||||
.get<SessionCubit>()
|
||||
.state
|
||||
|
||||
@@ -53,10 +53,10 @@ class TargetFormCubit extends Cubit<TargetFormState> {
|
||||
final storeId = target.storeId ?? defaultStoreId;
|
||||
final storeStaff = await _loadStoreStaff(companyId, storeId);
|
||||
|
||||
// Costruisci o allinea individualTargets per ogni membro dello staff
|
||||
// Costruisci o allinea individualTargets per ogni membro dello staff attivo
|
||||
final List<IndividualTargetModel> individuals = [];
|
||||
for (final staff in storeStaff) {
|
||||
if (staff.id == null) continue;
|
||||
if (staff.id == null || !staff.isActive) continue;
|
||||
final existing = target.individualTargets.firstWhere(
|
||||
(it) => it.staffId == staff.id,
|
||||
orElse:
|
||||
@@ -119,9 +119,8 @@ class TargetFormCubit extends Cubit<TargetFormState> {
|
||||
}
|
||||
|
||||
// 5. Se trovati addetti assegnati al negozio, ritorniamo quelli attivi
|
||||
final activeStoreStaff = staff.where((s) => s.isActive).toList();
|
||||
if (activeStoreStaff.isNotEmpty) {
|
||||
return activeStoreStaff;
|
||||
if (staff.isNotEmpty) {
|
||||
return staff.where((s) => s.isActive).toList();
|
||||
}
|
||||
|
||||
// 6. Fallback: controlliamo se in allStaff di StaffCubit qualcuno ha questo store associato
|
||||
@@ -163,7 +162,7 @@ class TargetFormCubit extends Cubit<TargetFormState> {
|
||||
|
||||
final List<IndividualTargetModel> individuals = [];
|
||||
for (final staff in storeStaff) {
|
||||
if (staff.id == null) continue;
|
||||
if (staff.id == null || !staff.isActive) continue;
|
||||
individuals.add(
|
||||
IndividualTargetModel(
|
||||
companyId: state.target.companyId,
|
||||
|
||||
@@ -138,9 +138,15 @@ class TargetProgressService {
|
||||
);
|
||||
}
|
||||
|
||||
// 4. Costruzione avanzamento per singoli addetti
|
||||
// 4. Costruzione avanzamento per singoli addetti (solo addetti attivi)
|
||||
final staffProgressMap = <String, TargetProgressModel>{};
|
||||
final individualTargetsList = target.individualTargets;
|
||||
final individualTargetsList = target.individualTargets
|
||||
.where((it) => it.staff == null || it.staff!.isActive)
|
||||
.toList();
|
||||
final inactiveStaffIds = target.individualTargets
|
||||
.where((it) => it.staff != null && !it.staff!.isActive)
|
||||
.map((it) => it.staffId)
|
||||
.toSet();
|
||||
|
||||
final bool hasExplicitIndividualTargets = individualTargetsList.any(
|
||||
(it) => it.metrics.totalLevel1 > 0 || it.metrics.totalLevel2 > 0,
|
||||
@@ -200,6 +206,7 @@ class TargetProgressService {
|
||||
|
||||
// Se ci sono addetti con operazioni che non compaiono in individualTargets, creiamo la loro scheda
|
||||
for (final sId in staffCounts.keys) {
|
||||
if (inactiveStaffIds.contains(sId)) continue;
|
||||
if (!staffProgressMap.containsKey(sId)) {
|
||||
final sCounts = staffCounts[sId] ?? {};
|
||||
final sCategories = <String, CategoryProgress>{};
|
||||
|
||||
@@ -703,7 +703,9 @@ class _TargetDetailScreenState extends State<TargetDetailScreen>
|
||||
TargetProgressModel progress,
|
||||
bool isDesktop,
|
||||
) {
|
||||
final staffMembers = target.individualTargets;
|
||||
final staffMembers = target.individualTargets
|
||||
.where((it) => it.staff == null || it.staff!.isActive)
|
||||
.toList();
|
||||
|
||||
if (staffMembers.isEmpty) {
|
||||
return Center(
|
||||
|
||||
@@ -96,6 +96,9 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
final Map<String, List<StaffMemberModel>> grouped = {};
|
||||
|
||||
for (var staff in staffList) {
|
||||
if (!staff.isActive && !state.selectedStaffIds.contains(staff.id)) {
|
||||
continue;
|
||||
}
|
||||
if (!state.isGlobal) {
|
||||
final belongsToCurrentStore = staff.assignedStores.any(
|
||||
(store) => store.id == _currentStoreId,
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: flux
|
||||
description: "Gestione attività negozio di telefonia"
|
||||
publish_to: 'none'
|
||||
version: 2.0.17+73
|
||||
version: 2.1.3+77
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.3
|
||||
|
||||
@@ -122,4 +122,55 @@ void main() {
|
||||
expect(OperationType.fromValue('RICONTATTO'), equals(OperationType.ricontatto));
|
||||
});
|
||||
});
|
||||
|
||||
group('StaffMemberModel jobTitle discriminants', () {
|
||||
test('canViewRicontattiFocus identifies Manager and Titolare by jobTitle', () {
|
||||
final manager = StaffMemberModel.empty().copyWith(jobTitle: 'Manager');
|
||||
final titolare = StaffMemberModel.empty().copyWith(jobTitle: 'Titolare');
|
||||
final storeManager = StaffMemberModel.empty().copyWith(jobTitle: 'Store Manager');
|
||||
final addetto = StaffMemberModel.empty().copyWith(
|
||||
jobTitle: 'Addetto Vendite',
|
||||
systemRole: SystemRole.user,
|
||||
);
|
||||
final admin = StaffMemberModel.empty().copyWith(
|
||||
jobTitle: 'Tecnico',
|
||||
systemRole: SystemRole.admin,
|
||||
);
|
||||
|
||||
expect(manager.canViewRicontattiFocus, isTrue);
|
||||
expect(titolare.canViewRicontattiFocus, isTrue);
|
||||
expect(storeManager.canViewRicontattiFocus, isTrue);
|
||||
expect(addetto.canViewRicontattiFocus, isFalse);
|
||||
expect(admin.canViewRicontattiFocus, isTrue);
|
||||
});
|
||||
|
||||
test('excludes Manager, Titolare, Tester from controlled staff', () {
|
||||
final manager = StaffMemberModel.empty().copyWith(jobTitle: 'Manager');
|
||||
final titolare = StaffMemberModel.empty().copyWith(jobTitle: 'Titolare');
|
||||
final tester = StaffMemberModel.empty().copyWith(jobTitle: 'Tester');
|
||||
final betaTester = StaffMemberModel.empty().copyWith(jobTitle: 'BETA TESTER');
|
||||
final inactive = StaffMemberModel.empty().copyWith(
|
||||
jobTitle: 'Addetto',
|
||||
isActive: false,
|
||||
);
|
||||
|
||||
expect(manager.isExcludedFromControlledStaff, isTrue);
|
||||
expect(titolare.isExcludedFromControlledStaff, isTrue);
|
||||
expect(tester.isExcludedFromControlledStaff, isTrue);
|
||||
expect(betaTester.isExcludedFromControlledStaff, isTrue);
|
||||
expect(inactive.isExcludedFromControlledStaff, isTrue);
|
||||
});
|
||||
|
||||
test('addetto with systemRole manager is still controlled staff', () {
|
||||
// systemRole indica permessi app, jobTitle indica il ruolo operativo in negozio
|
||||
final addettoWithAdminPerms = StaffMemberModel.empty().copyWith(
|
||||
jobTitle: 'Addetto Vendite',
|
||||
systemRole: SystemRole.manager,
|
||||
isActive: true,
|
||||
);
|
||||
expect(addettoWithAdminPerms.isExcludedFromControlledStaff, isFalse);
|
||||
expect(addettoWithAdminPerms.isManagerOrTitolare, isFalse);
|
||||
expect(addettoWithAdminPerms.canViewRicontattiFocus, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user