Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dd8a3ac71 | ||
|
|
70db03066b | ||
|
|
addb06a61a | ||
|
|
5e505d96b3 | ||
|
|
66c7094ada | ||
|
|
bd496ad37f |
No files matched your search
@@ -48,6 +48,7 @@ import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_details_list_cubit.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_form_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:flux/features/operations/ui/financing_form_screen.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen.dart';
|
||||
import 'package:flux/features/operations/ui/operation_list_screen.dart';
|
||||
import 'package:flux/features/settings/blocs/reminder_defaults_cubit.dart';
|
||||
@@ -97,8 +98,13 @@ class AppRouter {
|
||||
final isGoingToSetPassword = state.matchedLocation == '/set-password';
|
||||
|
||||
// 1. LA PASSATOIA VIP (DEVE ESSERE IN CIMA)
|
||||
// Usiamo state.uri.path perché state.matchedLocation a volte fa i capricci coi deep link iniziali
|
||||
final isPublicRoute = state.uri.path.startsWith('/upload');
|
||||
// Usiamo sia state.uri.path che state.matchedLocation per sicurezza con i deep link
|
||||
final path = state.uri.path;
|
||||
final matched = state.matchedLocation;
|
||||
final isPublicRoute = path.startsWith('/upload') ||
|
||||
path.startsWith('/financing') ||
|
||||
matched.startsWith('/upload') ||
|
||||
matched.startsWith('/financing');
|
||||
|
||||
if (isPublicRoute) {
|
||||
// Ritorna null esplicitamente per dire al router "Rimani qui e non fare altri controlli"
|
||||
@@ -154,6 +160,14 @@ class AppRouter {
|
||||
child: const OnboardingScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/financing/:sessionId',
|
||||
name: Routes.financing,
|
||||
builder: (context, state) {
|
||||
final sessionId = state.pathParameters['sessionId'] ?? '';
|
||||
return FinancingFormScreen(sessionId: sessionId);
|
||||
},
|
||||
),
|
||||
|
||||
// --- CORE APP (DENTRO LA SHELL CON NAVIGATION BAR/RAIL) ---
|
||||
ShellRoute(
|
||||
|
||||
@@ -30,4 +30,5 @@ class Routes {
|
||||
static const String targets = 'targets';
|
||||
static const String targetForm = 'target-form';
|
||||
static const String targetDetail = 'target-detail';
|
||||
static const String financing = 'financing';
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
class FinancingTranslations {
|
||||
static const List<FinancingLanguage> supportedLanguages = [
|
||||
FinancingLanguage(code: 'it', name: 'Italiano', flag: '🇮🇹', isRtl: false),
|
||||
FinancingLanguage(code: 'en', name: 'English', flag: '🇬🇧', isRtl: false),
|
||||
FinancingLanguage(code: 'fr', name: 'Français', flag: '🇫🇷', isRtl: false),
|
||||
FinancingLanguage(code: 'es', name: 'Español', flag: '🇪🇸', isRtl: false),
|
||||
FinancingLanguage(code: 'ar', name: 'العربية', flag: '🇸🇦', isRtl: true),
|
||||
FinancingLanguage(code: 'uk', name: 'Українська', flag: '🇺🇦', isRtl: false),
|
||||
FinancingLanguage(code: 'ru', name: 'Русский', flag: '🇷🇺', isRtl: false),
|
||||
FinancingLanguage(code: 'mk', name: 'Македонски', flag: '🇲🇰', isRtl: false),
|
||||
FinancingLanguage(code: 'sq', name: 'Shqip', flag: '🇦🇱', isRtl: false),
|
||||
];
|
||||
|
||||
static const List<String> canonicalMaritalStatuses = [
|
||||
'Celibe / Nubile',
|
||||
'Coniugato/a',
|
||||
'Separato/a',
|
||||
'Divorziato/a',
|
||||
'Vedovo/a',
|
||||
];
|
||||
|
||||
static const List<String> canonicalIncomeRanges = [
|
||||
'Fino a 2.000 €',
|
||||
'Da 2.000 € a 5.000 €',
|
||||
'Oltre 5.000 €',
|
||||
];
|
||||
|
||||
static FinancingStrings getStrings(String langCode) {
|
||||
switch (langCode) {
|
||||
case 'en':
|
||||
return const FinancingStrings(
|
||||
title: 'Financing Details',
|
||||
subtitle: 'Please fill in the information below required for your financing application.',
|
||||
maritalStatusLabel: 'Marital Status',
|
||||
maritalOptions: ['Single', 'Married', 'Separated', 'Divorced', 'Widowed'],
|
||||
occupationLabel: 'Occupation',
|
||||
occupationHint: 'e.g. Employee, Factory Worker, Self-employed...',
|
||||
incomeLabel: 'Net Monthly Income',
|
||||
incomeOptions: ['Up to €2,000', 'From €2,000 to €5,000', 'Over €5,000'],
|
||||
submitButton: 'Submit Information',
|
||||
errorRequired: 'Please complete all fields before submitting.',
|
||||
successTitle: 'Information Submitted!',
|
||||
successSubtitle: 'Thank you! Your information has been safely received by our store. You can close this page.',
|
||||
);
|
||||
case 'fr':
|
||||
return const FinancingStrings(
|
||||
title: 'Informations de Financement',
|
||||
subtitle: 'Veuillez renseigner les informations requises pour votre demande de financement.',
|
||||
maritalStatusLabel: 'État Civil',
|
||||
maritalOptions: ['Célibataire', 'Marié(e)', 'Séparé(e)', 'Divorcé(e)', 'Veuf / Veuve'],
|
||||
occupationLabel: 'Profession',
|
||||
occupationHint: 'Ex. Employé, Ouvrier, Artisan, Indépendant...',
|
||||
incomeLabel: 'Revenu Mensuel Net',
|
||||
incomeOptions: ['Jusqu\'à 2 000 €', 'De 2 000 € à 5 000 €', 'Plus de 5 000 €'],
|
||||
submitButton: 'Envoyer les données',
|
||||
errorRequired: 'Veuillez remplir tous les champs avant de soumettre.',
|
||||
successTitle: 'Données transmises avec succès !',
|
||||
successSubtitle: 'Merci ! Les informations ont été reçues par notre conseiller. Vous pouvez fermer cette page.',
|
||||
);
|
||||
case 'es':
|
||||
return const FinancingStrings(
|
||||
title: 'Datos para Financiación',
|
||||
subtitle: 'Completa los siguientes datos necesarios para la solicitud de financiación.',
|
||||
maritalStatusLabel: 'Estado Civil',
|
||||
maritalOptions: ['Soltero/a', 'Casado/a', 'Separado/a', 'Divorciado/a', 'Viudo/a'],
|
||||
occupationLabel: 'Profesión',
|
||||
occupationHint: 'Ej. Empleado, Obrero, Autónomo, Comerciante...',
|
||||
incomeLabel: 'Ingreso Mensual Neto',
|
||||
incomeOptions: ['Hasta 2.000 €', 'De 2.000 € a 5.000 €', 'Más de 5.000 €'],
|
||||
submitButton: 'Enviar Datos',
|
||||
errorRequired: 'Por favor, completa todos los campos antes de enviar.',
|
||||
successTitle: '¡Datos enviados con éxito!',
|
||||
successSubtitle: '¡Gracias! Nuestro asesor ha recibido tus datos. Ya puedes cerrar esta pantalla.',
|
||||
);
|
||||
case 'ar':
|
||||
return const FinancingStrings(
|
||||
title: 'بيانات التمويل',
|
||||
subtitle: 'يرجى تعبئة البيانات التالية المطلوبة لإتمام معاملة التمويل.',
|
||||
maritalStatusLabel: 'الحالة الاجتماعية',
|
||||
maritalOptions: ['أعزب / عزباء', 'متزوج / متزوجة', 'منفصل / منفصلة', 'مطلق / مطلقة', 'أرمل / أرملة'],
|
||||
occupationLabel: 'المهنة',
|
||||
occupationHint: 'مثال: موظف، عامل، تاجر، عمل حر...',
|
||||
incomeLabel: 'الدخل الشهري الصافي',
|
||||
incomeOptions: ['حتى 2,000 يورو', 'من 2,000 إلى 5,000 يورو', 'أكثر من 5,000 يورو'],
|
||||
submitButton: 'إرسال البيانات',
|
||||
errorRequired: 'يرجى ملء جميع الحقول قبل الإرسال.',
|
||||
successTitle: 'تم إرسال البيانات بنجاح!',
|
||||
successSubtitle: 'شكراً لك! لقد استلم موظفنا البيانات بنجاح. يمكنك إغلاق هذه الصفحة الآن.',
|
||||
);
|
||||
case 'uk':
|
||||
return const FinancingStrings(
|
||||
title: 'Дані для фінансування',
|
||||
subtitle: 'Будь ласка, заповніть наступні дані, необхідні для оформлення фінансування.',
|
||||
maritalStatusLabel: 'Сімейний стан',
|
||||
maritalOptions: ['Неодружений / Незаміжня', 'Одружений / Заміжня', 'Розлучений / Розлучена', 'Проживає окремо', 'Вдівець / Вдова'],
|
||||
occupationLabel: 'Професія / Посада',
|
||||
occupationHint: 'Наприклад: Службовець, Робітник, ФОП...',
|
||||
incomeLabel: 'Чистий щомісячний дохід',
|
||||
incomeOptions: ['До 2 000 €', 'Від 2 000 € до 5 000 €', 'Понад 5 000 €'],
|
||||
submitButton: 'Надіслати дані',
|
||||
errorRequired: 'Будь ласка, заповніть усі поля перед відправленням.',
|
||||
successTitle: 'Дані успішно надіслано!',
|
||||
successSubtitle: 'Дякуємо! Наш фахівець отримав ваші дані. Ви можете закрити цю сторінку.',
|
||||
);
|
||||
case 'ru':
|
||||
return const FinancingStrings(
|
||||
title: 'Данные для финансирования',
|
||||
subtitle: 'Пожалуйста, заполните следующие данные, необходимые для оформления финансирования.',
|
||||
maritalStatusLabel: 'Семейное положение',
|
||||
maritalOptions: ['Холост / Не замужем', 'Женат / Замужем', 'Проживает раздельно', 'Разведен / Разведена', 'Вдовец / Вдова'],
|
||||
occupationLabel: 'Профессия / Должность',
|
||||
occupationHint: 'Например: Служащий, Рабочий, Предприниматель...',
|
||||
incomeLabel: 'Чистый ежемесячный доход',
|
||||
incomeOptions: ['До 2 000 €', 'От 2 000 € до 5 000 €', 'Более 5 000 €'],
|
||||
submitButton: 'Отправить данные',
|
||||
errorRequired: 'Пожалуйста, заполните все поля перед отправкой.',
|
||||
successTitle: 'Данные успешно отправлены!',
|
||||
successSubtitle: 'Спасибо! Наш сотрудник получил ваши данные. Вы можете закрыть эту страницу.',
|
||||
);
|
||||
case 'mk':
|
||||
return const FinancingStrings(
|
||||
title: 'Податоци за финансирање',
|
||||
subtitle: 'Ве молиме пополнете ги следните податоци потребни за апликацијата за финансирање.',
|
||||
maritalStatusLabel: 'Брачна состојба',
|
||||
maritalOptions: ['Неженет / Немажена', 'Оженет / Мажена', 'Разделен / Разделена', 'Разведен / Разведена', 'Вдовец / Вдовица'],
|
||||
occupationLabel: 'Професија',
|
||||
occupationHint: 'Пр. Вработен, Работник, Трговец...',
|
||||
incomeLabel: 'Нето месечен приход',
|
||||
incomeOptions: ['До 2.000 €', 'Од 2.000 € до 5.000 €', 'Над 5.000 €'],
|
||||
submitButton: 'Испрати податоци',
|
||||
errorRequired: 'Ве молиме пополнете ги сите полиња пред испраќање.',
|
||||
successTitle: 'Податоците се успешно испратени!',
|
||||
successSubtitle: 'Ви благодариме! Нашиот оператор ги прими вашите податоци. Можете да го затворите овој прозорец.',
|
||||
);
|
||||
case 'sq':
|
||||
return const FinancingStrings(
|
||||
title: 'Të dhënat për Financim',
|
||||
subtitle: 'Ju lutemi plotësoni të dhënat e mëposhtme të nevojshme për kërkesën për financim.',
|
||||
maritalStatusLabel: 'Gjendja Civile',
|
||||
maritalOptions: ['Beqar / Beqare', 'I/E martuar', 'I/E ndarë', 'I/E divorcuar', 'I/E ve'],
|
||||
occupationLabel: 'Profesioni',
|
||||
occupationHint: 'P.sh. Punonjës, Punëtor, Tregtar, Vetëpunësuar...',
|
||||
incomeLabel: 'Të Ardhurat Mujore Neto',
|
||||
incomeOptions: ['Deri në 2.000 €', 'Nga 2.000 € në 5.000 €', 'Mbi 5.000 €'],
|
||||
submitButton: 'Dërgo të Dhënat',
|
||||
errorRequired: 'Ju lutemi plotësoni të gjitha fushat para dërgimit.',
|
||||
successTitle: 'Të dhënat u dërguan me sukses!',
|
||||
successSubtitle: 'Faleminderit! Operatori ynë i pranoi të dhënat tuaja. Mund ta mbyllni këtë faqe.',
|
||||
);
|
||||
case 'it':
|
||||
default:
|
||||
return const FinancingStrings(
|
||||
title: 'Dati per Finanziamento',
|
||||
subtitle: 'Compila i seguenti dati necessari per la pratica di finanziamento.',
|
||||
maritalStatusLabel: 'Stato Civile',
|
||||
maritalOptions: ['Celibe / Nubile', 'Coniugato/a', 'Separato/a', 'Divorziato/a', 'Vedovo/a'],
|
||||
occupationLabel: 'Professione',
|
||||
occupationHint: 'Es. Impiegato, Operaio, Commerciante, Autonomo...',
|
||||
incomeLabel: 'Reddito Mensile Netto',
|
||||
incomeOptions: ['Fino a 2.000 €', 'Da 2.000 € a 5.000 €', 'Oltre 5.000 €'],
|
||||
submitButton: 'Invia Dati',
|
||||
errorRequired: 'Per favore compila tutti i campi prima di inviare.',
|
||||
successTitle: 'Dati inviati con successo!',
|
||||
successSubtitle: 'Grazie! Le informazioni sono state ricevute dal nostro operatore. Puoi chiudere questa schermata.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static String formatNoteText({
|
||||
required int maritalStatusIndex,
|
||||
required String occupation,
|
||||
required int incomeRangeIndex,
|
||||
required String languageName,
|
||||
}) {
|
||||
final marital = (maritalStatusIndex >= 0 && maritalStatusIndex < canonicalMaritalStatuses.length)
|
||||
? canonicalMaritalStatuses[maritalStatusIndex]
|
||||
: 'Non specificato';
|
||||
|
||||
final income = (incomeRangeIndex >= 0 && incomeRangeIndex < canonicalIncomeRanges.length)
|
||||
? canonicalIncomeRanges[incomeRangeIndex]
|
||||
: 'Non specificato';
|
||||
|
||||
final cleanOccupation = occupation.trim().isNotEmpty ? occupation.trim() : 'Non specificata';
|
||||
|
||||
return '''
|
||||
[DATI FINANZIAMENTO]
|
||||
• Stato civile: $marital
|
||||
• Professione: $cleanOccupation
|
||||
• Reddito mensile: $income
|
||||
(Compilato dal cliente via QR - Lingua: $languageName)''';
|
||||
}
|
||||
}
|
||||
|
||||
class FinancingLanguage {
|
||||
final String code;
|
||||
final String name;
|
||||
final String flag;
|
||||
final bool isRtl;
|
||||
|
||||
const FinancingLanguage({
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.flag,
|
||||
required this.isRtl,
|
||||
});
|
||||
}
|
||||
|
||||
class FinancingStrings {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final String maritalStatusLabel;
|
||||
final List<String> maritalOptions;
|
||||
final String occupationLabel;
|
||||
final String occupationHint;
|
||||
final String incomeLabel;
|
||||
final List<String> incomeOptions;
|
||||
final String submitButton;
|
||||
final String errorRequired;
|
||||
final String successTitle;
|
||||
final String successSubtitle;
|
||||
|
||||
const FinancingStrings({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.maritalStatusLabel,
|
||||
required this.maritalOptions,
|
||||
required this.occupationLabel,
|
||||
required this.occupationHint,
|
||||
required this.incomeLabel,
|
||||
required this.incomeOptions,
|
||||
required this.submitButton,
|
||||
required this.errorRequired,
|
||||
required this.successTitle,
|
||||
required this.successSubtitle,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flux/features/operations/models/financing_translations.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class FinancingFormScreen extends StatefulWidget {
|
||||
final String sessionId;
|
||||
|
||||
const FinancingFormScreen({
|
||||
super.key,
|
||||
required this.sessionId,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FinancingFormScreen> createState() => _FinancingFormScreenState();
|
||||
}
|
||||
|
||||
class _FinancingFormScreenState extends State<FinancingFormScreen> {
|
||||
FinancingLanguage _currentLang = FinancingTranslations.supportedLanguages.first; // Default Italiano
|
||||
final _occupationController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
int? _selectedMaritalIndex;
|
||||
int? _selectedIncomeIndex;
|
||||
|
||||
bool _isSubmitting = false;
|
||||
bool _isSuccess = false;
|
||||
String? _errorMessage;
|
||||
|
||||
RealtimeChannel? _channel;
|
||||
StreamSubscription? _ackSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initRealtimeChannel();
|
||||
}
|
||||
|
||||
void _initRealtimeChannel() {
|
||||
if (widget.sessionId.isEmpty) return;
|
||||
try {
|
||||
_channel = Supabase.instance.client.channel('financing_${widget.sessionId}');
|
||||
_channel?.onBroadcast(
|
||||
event: 'ack',
|
||||
callback: (payload) {
|
||||
if (mounted && _isSubmitting) {
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_isSuccess = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
).subscribe();
|
||||
} catch (e) {
|
||||
debugPrint('Errore init channel financing: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ackSubscription?.cancel();
|
||||
if (_channel != null) {
|
||||
Supabase.instance.client.removeChannel(_channel!);
|
||||
}
|
||||
_occupationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
final strings = FinancingTranslations.getStrings(_currentLang.code);
|
||||
|
||||
if (_selectedMaritalIndex == null ||
|
||||
_selectedIncomeIndex == null ||
|
||||
_occupationController.text.trim().isEmpty) {
|
||||
setState(() {
|
||||
_errorMessage = strings.errorRequired;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_errorMessage = null;
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final formattedText = FinancingTranslations.formatNoteText(
|
||||
maritalStatusIndex: _selectedMaritalIndex!,
|
||||
occupation: _occupationController.text.trim(),
|
||||
incomeRangeIndex: _selectedIncomeIndex!,
|
||||
languageName: _currentLang.name,
|
||||
);
|
||||
|
||||
try {
|
||||
if (_channel == null) {
|
||||
_channel = Supabase.instance.client.channel('financing_${widget.sessionId}');
|
||||
_channel?.subscribe();
|
||||
}
|
||||
|
||||
await _channel?.sendBroadcastMessage(
|
||||
event: 'submit',
|
||||
payload: {
|
||||
'maritalStatusIndex': _selectedMaritalIndex,
|
||||
'occupation': _occupationController.text.trim(),
|
||||
'incomeRangeIndex': _selectedIncomeIndex,
|
||||
'languageCode': _currentLang.code,
|
||||
'languageName': _currentLang.name,
|
||||
'formattedText': formattedText,
|
||||
},
|
||||
);
|
||||
|
||||
// Timeout di sicurezza: se entro 3 secondi non riceviamo ack specifico,
|
||||
// consideriamo comunque la trasmissione completata con successo
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted && _isSubmitting) {
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_isSuccess = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_errorMessage = 'Errore di connessione: $e';
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final strings = FinancingTranslations.getStrings(_currentLang.code);
|
||||
|
||||
return Directionality(
|
||||
textDirection: _currentLang.isRtl ? TextDirection.rtl : TextDirection.ltr,
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF8FAFC),
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.white,
|
||||
centerTitle: true,
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.account_balance_wallet_outlined,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(
|
||||
strings.title,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF1E293B),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: _isSuccess
|
||||
? _buildSuccessView(strings, theme)
|
||||
: _buildFormView(strings, theme),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSuccessView(FinancingStrings strings, ThemeData theme) {
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 90,
|
||||
height: 90,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green.shade50,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.green.shade200, width: 2),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: Colors.green.shade600,
|
||||
size: 56,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
strings.successTitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF0F172A),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
strings.successSubtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.grey.shade700,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 36),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.shade50,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.blue.shade100),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.info_outline, color: Colors.blue.shade700, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
'Sessione completata',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.blue.shade900,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFormView(FinancingStrings strings, ThemeData theme) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 540),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// SELETTORE LINGUA
|
||||
_buildLanguageSelector(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// DESCRIZIONE
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFE2E8F0)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.privacy_tip_outlined,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
strings.subtitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF475569),
|
||||
height: 1.35,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 1. STATO CIVILE
|
||||
_buildSectionHeader(
|
||||
icon: Icons.favorite_border,
|
||||
title: strings.maritalStatusLabel,
|
||||
theme: theme,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildChoiceList(
|
||||
options: strings.maritalOptions,
|
||||
selectedIndex: _selectedMaritalIndex,
|
||||
onSelected: (idx) {
|
||||
setState(() => _selectedMaritalIndex = idx);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 2. PROFESSIONE
|
||||
_buildSectionHeader(
|
||||
icon: Icons.work_outline,
|
||||
title: strings.occupationLabel,
|
||||
theme: theme,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextFormField(
|
||||
controller: _occupationController,
|
||||
textInputAction: TextInputAction.done,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||||
decoration: InputDecoration(
|
||||
hintText: strings.occupationHint,
|
||||
hintStyle: TextStyle(color: Colors.grey.shade400, fontSize: 14),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
borderSide: const BorderSide(color: Color(0xFFCBD5E1)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
borderSide: const BorderSide(color: Color(0xFFCBD5E1)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
borderSide: BorderSide(
|
||||
color: theme.colorScheme.primary,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
onChanged: (_) {
|
||||
if (_errorMessage != null) {
|
||||
setState(() => _errorMessage = null);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 3. REDDITO MENSILE
|
||||
_buildSectionHeader(
|
||||
icon: Icons.euro_symbol_outlined,
|
||||
title: strings.incomeLabel,
|
||||
theme: theme,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildChoiceList(
|
||||
options: strings.incomeOptions,
|
||||
selectedIndex: _selectedIncomeIndex,
|
||||
onSelected: (idx) {
|
||||
setState(() => _selectedIncomeIndex = idx);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// MESSAGGIO DI ERRORE
|
||||
if (_errorMessage != null) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.shade50,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: Colors.red.shade200),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.error_outline, color: Colors.red.shade700, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_errorMessage!,
|
||||
style: TextStyle(
|
||||
color: Colors.red.shade800,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// PULSANTE INVIO
|
||||
SizedBox(
|
||||
height: 54,
|
||||
child: FilledButton.icon(
|
||||
style: FilledButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
elevation: 1,
|
||||
),
|
||||
onPressed: _isSubmitting ? null : _submit,
|
||||
icon: _isSubmitting
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.send_rounded, size: 20),
|
||||
label: Text(
|
||||
_isSubmitting ? '...' : strings.submitButton,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLanguageSelector() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 4.0, bottom: 8.0),
|
||||
child: Text(
|
||||
'Seleziona lingua / Choose language:',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF64748B),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 42,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: FinancingTranslations.supportedLanguages.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final lang = FinancingTranslations.supportedLanguages[index];
|
||||
final isSelected = lang.code == _currentLang.code;
|
||||
|
||||
return ChoiceChip(
|
||||
showCheckmark: false,
|
||||
labelPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
avatar: Text(lang.flag, style: const TextStyle(fontSize: 16)),
|
||||
label: Text(
|
||||
lang.name,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.w500,
|
||||
color: isSelected ? Colors.white : const Color(0xFF1E293B),
|
||||
),
|
||||
),
|
||||
selected: isSelected,
|
||||
selectedColor: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
side: BorderSide(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: const Color(0xFFCBD5E1),
|
||||
),
|
||||
),
|
||||
onSelected: (selected) {
|
||||
if (selected) {
|
||||
setState(() {
|
||||
_currentLang = lang;
|
||||
_errorMessage = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required ThemeData theme,
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 20, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1E293B),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChoiceList({
|
||||
required List<String> options,
|
||||
required int? selectedIndex,
|
||||
required ValueChanged<int> onSelected,
|
||||
}) {
|
||||
return Column(
|
||||
children: List.generate(options.length, (index) {
|
||||
final label = options[index];
|
||||
final isSelected = selectedIndex == index;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: () => onSelected(index),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.08)
|
||||
: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: const Color(0xFFCBD5E1),
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isSelected
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_off,
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: const Color(0xFF94A3B8),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.w500,
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: const Color(0xFF1E293B),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_details_list_cubit.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_form_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:flux/features/operations/ui/widgets/financing_qr_dialog.dart';
|
||||
import 'package:flux/features/operations/ui/widgets/operation_details_section.dart';
|
||||
|
||||
class OperationFormScreen extends StatefulWidget {
|
||||
@@ -629,6 +630,19 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
title: 'Note Interne',
|
||||
icon: Icons.notes,
|
||||
themeColor: Colors.teal,
|
||||
headerTrailing: OutlinedButton.icon(
|
||||
icon: const Icon(Icons.qr_code_2, size: 18),
|
||||
label: const Text('Dati Finanziamento'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.teal,
|
||||
side: const BorderSide(color: Colors.teal),
|
||||
visualDensity: VisualDensity.compact,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
onPressed: _showFinancingQrDialog,
|
||||
),
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _notesController,
|
||||
@@ -649,6 +663,32 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showFinancingQrDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogCtx) => FinancingQrDialog(
|
||||
onDataReceived: (formattedData) {
|
||||
setState(() {
|
||||
final existing = _notesController.text.trim();
|
||||
if (existing.isEmpty) {
|
||||
_notesController.text = formattedData;
|
||||
} else {
|
||||
_notesController.text = '$existing\n\n$formattedData';
|
||||
}
|
||||
});
|
||||
_flushControllersToCubit();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Dati finanziamento inseriti nelle note!'),
|
||||
backgroundColor: Colors.teal,
|
||||
duration: Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cardAllegati(OperationFormState state) {
|
||||
return _buildCard(
|
||||
title: 'Allegati e Documenti',
|
||||
@@ -679,6 +719,7 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
required IconData icon,
|
||||
required Color themeColor,
|
||||
required List<Widget> children,
|
||||
Widget? headerTrailing,
|
||||
}) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 24),
|
||||
@@ -703,13 +744,16 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
child: Icon(icon, color: themeColor),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: themeColor,
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: themeColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
?headerTrailing,
|
||||
],
|
||||
),
|
||||
const Divider(height: 32),
|
||||
|
||||
@@ -0,0 +1,345 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flux/features/operations/models/financing_translations.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class FinancingQrDialog extends StatefulWidget {
|
||||
final ValueChanged<String> onDataReceived;
|
||||
|
||||
const FinancingQrDialog({
|
||||
super.key,
|
||||
required this.onDataReceived,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FinancingQrDialog> createState() => _FinancingQrDialogState();
|
||||
}
|
||||
|
||||
class _FinancingQrDialogState extends State<FinancingQrDialog> {
|
||||
late final String _sessionId;
|
||||
late final String _deepLinkUrl;
|
||||
RealtimeChannel? _channel;
|
||||
|
||||
bool _isReceived = false;
|
||||
Map<String, dynamic>? _receivedPayload;
|
||||
bool _copied = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_sessionId = const Uuid().v4();
|
||||
_deepLinkUrl = 'https://flux.catelli.it/financing/$_sessionId';
|
||||
_setupRealtimeChannel();
|
||||
}
|
||||
|
||||
void _setupRealtimeChannel() {
|
||||
try {
|
||||
_channel = Supabase.instance.client.channel('financing_$_sessionId');
|
||||
_channel?.onBroadcast(
|
||||
event: 'submit',
|
||||
callback: (payload) {
|
||||
if (!mounted) return;
|
||||
|
||||
// Invia risposta di conferma (ACK) allo smartphone del cliente
|
||||
_channel?.sendBroadcastMessage(
|
||||
event: 'ack',
|
||||
payload: {'status': 'ok'},
|
||||
);
|
||||
|
||||
final maritalIndex = payload['maritalStatusIndex'] as int? ?? 0;
|
||||
final occupation = payload['occupation'] as String? ?? '';
|
||||
final incomeIndex = payload['incomeRangeIndex'] as int? ?? 0;
|
||||
final languageName = payload['languageName'] as String? ?? 'Italiano';
|
||||
|
||||
final formattedText = payload['formattedText'] as String? ??
|
||||
FinancingTranslations.formatNoteText(
|
||||
maritalStatusIndex: maritalIndex,
|
||||
occupation: occupation,
|
||||
incomeRangeIndex: incomeIndex,
|
||||
languageName: languageName,
|
||||
);
|
||||
|
||||
widget.onDataReceived(formattedText);
|
||||
|
||||
setState(() {
|
||||
_isReceived = true;
|
||||
_receivedPayload = {
|
||||
'marital': (maritalIndex >= 0 &&
|
||||
maritalIndex <
|
||||
FinancingTranslations.canonicalMaritalStatuses.length)
|
||||
? FinancingTranslations.canonicalMaritalStatuses[maritalIndex]
|
||||
: 'N/D',
|
||||
'occupation': occupation,
|
||||
'income': (incomeIndex >= 0 &&
|
||||
incomeIndex <
|
||||
FinancingTranslations.canonicalIncomeRanges.length)
|
||||
? FinancingTranslations.canonicalIncomeRanges[incomeIndex]
|
||||
: 'N/D',
|
||||
'language': languageName,
|
||||
};
|
||||
});
|
||||
},
|
||||
).subscribe();
|
||||
} catch (e) {
|
||||
debugPrint('Errore setup realtime channel: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_channel != null) {
|
||||
Supabase.instance.client.removeChannel(_channel!);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _copyToClipboard() {
|
||||
Clipboard.setData(ClipboardData(text: _deepLinkUrl));
|
||||
setState(() => _copied = true);
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _copied = false);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
backgroundColor: theme.colorScheme.surface,
|
||||
title: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.teal.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(Icons.qr_code_2, color: Colors.teal, size: 28),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Dati Finanziamento',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
||||
),
|
||||
Text(
|
||||
'Raccolta via smartphone cliente',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
width: 380,
|
||||
child: SingleChildScrollView(
|
||||
child: _isReceived
|
||||
? _buildReceivedContent(theme)
|
||||
: _buildQrContent(theme),
|
||||
),
|
||||
),
|
||||
actionsPadding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
actions: [
|
||||
if (!_isReceived) ...[
|
||||
OutlinedButton.icon(
|
||||
onPressed: _copyToClipboard,
|
||||
icon: Icon(_copied ? Icons.check : Icons.copy, size: 16),
|
||||
label: Text(_copied ? 'Link Copiato!' : 'Copia Link'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Annulla'),
|
||||
),
|
||||
] else ...[
|
||||
FilledButton.icon(
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.teal),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.check, size: 18),
|
||||
label: const Text('Chiudi (Dati inseriti nelle note)'),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQrContent(ThemeData theme) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Fai inquadrare questo codice al cliente con la fotocamera del suo telefono.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.amber.shade50,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.amber.shade200),
|
||||
),
|
||||
child: Text(
|
||||
'🌐 Il cliente potrà scegliere la lingua (IT, EN, FR, ES, AR, UK, RU, MK, SQ)',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.amber.shade900,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.04),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: QrImageView(
|
||||
data: _deepLinkUrl,
|
||||
version: QrVersions.auto,
|
||||
size: 210.0,
|
||||
embeddedImage: const AssetImage('assets/images/logo.png'),
|
||||
embeddedImageStyle: const QrEmbeddedImageStyle(
|
||||
size: Size(40, 40),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.teal),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'In attesa che il cliente compili i dati...',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.grey.shade700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReceivedContent(ThemeData theme) {
|
||||
final marital = _receivedPayload?['marital'] ?? '';
|
||||
final occupation = _receivedPayload?['occupation'] ?? '';
|
||||
final income = _receivedPayload?['income'] ?? '';
|
||||
final lang = _receivedPayload?['language'] ?? '';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.teal.shade50,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: Colors.teal.shade200),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle, color: Colors.teal, size: 28),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Dati ricevuti con successo! 🎉',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: Colors.teal.shade900,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
const Divider(height: 1),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('Stato civile', marital),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow('Professione', occupation),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow('Reddito mensile', income),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow('Lingua cliente', lang),
|
||||
const SizedBox(height: 14),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.notes, size: 18, color: Colors.teal.shade700),
|
||||
const SizedBox(width: 8),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'I dati sono stati automaticamente inseriti nel campo note dell\'operazione.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.black87),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 110,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black54,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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.2.1+79
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flux/features/operations/models/financing_translations.dart';
|
||||
|
||||
void main() {
|
||||
group('FinancingTranslations', () {
|
||||
test('contains all 9 requested languages', () {
|
||||
final supportedCodes = FinancingTranslations.supportedLanguages.map((l) => l.code).toSet();
|
||||
expect(
|
||||
supportedCodes,
|
||||
containsAll([
|
||||
'it',
|
||||
'en',
|
||||
'fr',
|
||||
'es',
|
||||
'ar',
|
||||
'uk',
|
||||
'ru',
|
||||
'mk',
|
||||
'sq',
|
||||
]),
|
||||
);
|
||||
expect(FinancingTranslations.supportedLanguages.length, 9);
|
||||
});
|
||||
|
||||
test('Arabic is marked as RTL', () {
|
||||
final ar = FinancingTranslations.supportedLanguages.firstWhere((l) => l.code == 'ar');
|
||||
expect(ar.isRtl, isTrue);
|
||||
|
||||
final it = FinancingTranslations.supportedLanguages.firstWhere((l) => l.code == 'it');
|
||||
expect(it.isRtl, isFalse);
|
||||
});
|
||||
|
||||
test('formatNoteText outputs canonical Italian labels regardless of language', () {
|
||||
final noteText = FinancingTranslations.formatNoteText(
|
||||
maritalStatusIndex: 0, // Celibe / Nubile
|
||||
occupation: 'Ingegnere Informatico',
|
||||
incomeRangeIndex: 1, // Da 2.000 € a 5.000 €
|
||||
languageName: 'العربية (Arabo)',
|
||||
);
|
||||
|
||||
expect(noteText, contains('[DATI FINANZIAMENTO]'));
|
||||
expect(noteText, contains('Stato civile: Celibe / Nubile'));
|
||||
expect(noteText, contains('Professione: Ingegnere Informatico'));
|
||||
expect(noteText, contains('Reddito mensile: Da 2.000 € a 5.000 €'));
|
||||
expect(noteText, contains('Lingua: العربية (Arabo)'));
|
||||
});
|
||||
|
||||
test('each language has exactly 5 marital status and 3 income range options', () {
|
||||
for (final lang in FinancingTranslations.supportedLanguages) {
|
||||
final strings = FinancingTranslations.getStrings(lang.code);
|
||||
expect(strings.maritalOptions.length, 5, reason: 'Language ${lang.code} should have 5 marital options');
|
||||
expect(strings.incomeOptions.length, 3, reason: 'Language ${lang.code} should have 3 income options');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user