@@ -2,12 +2,14 @@ import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/core/widgets/image_viewer_widget.dart';
|
||||
import 'package:flux/core/widgets/pdf_viewer_widget.dart';
|
||||
import 'package:flux/core/widgets/qr_upload_dialog.dart';
|
||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_files_bloc.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_file_model.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
|
||||
class AttachmentsSection extends StatelessWidget {
|
||||
const AttachmentsSection({super.key});
|
||||
@@ -227,10 +229,30 @@ class AttachmentsSection extends StatelessWidget {
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.copy),
|
||||
label: const Text("Copia in Cliente"),
|
||||
onPressed: () => saveAndCopyFilesToCustomer(
|
||||
context,
|
||||
state.selectedFiles,
|
||||
),
|
||||
onPressed: () {
|
||||
final cubit = context.read<OperationsCubit>();
|
||||
if (cubit.state.currentOperation?.customerId ==
|
||||
null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
context
|
||||
.l10n
|
||||
.operationFormAttachmentSectionNoCustomer,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<OperationFilesBloc>().add(
|
||||
LinkFilesToCustomerEvent(
|
||||
customerId: cubit
|
||||
.state
|
||||
.currentOperation!
|
||||
.customerId!,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -278,9 +300,8 @@ class AttachmentsSection extends StatelessWidget {
|
||||
|
||||
// Salviamo forzatamente in bozza
|
||||
await cubit.saveCurrentOperation(
|
||||
isBozza: true,
|
||||
targetStatus: OperationStatus.draft,
|
||||
shouldPop: false,
|
||||
files: operationFilesBloc.state.localFiles,
|
||||
);
|
||||
|
||||
// Recuperiamo il servizio aggiornato con l'ID!
|
||||
@@ -321,39 +342,8 @@ class AttachmentsSection extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// --- LOGICA DI COPIA AL CLIENTE ---
|
||||
void saveAndCopyFilesToCustomer(
|
||||
BuildContext context,
|
||||
List<OperationFileModel> files,
|
||||
) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text("Copia nei documenti Cliente"),
|
||||
content: const Text(
|
||||
"Vuoi copiare i file selezionati nell'anagrafica del cliente? \n\n"
|
||||
"Attenzione: per procedere, la pratica attuale verrà prima salvata in stato BOZZA.",
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text("Annulla"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(ctx);
|
||||
// 1. Diciamo al Cubit di salvare in Bozza e fare la copia
|
||||
context.read<OperationsCubit>().saveAndCopyFileToCustomer(files);
|
||||
},
|
||||
child: const Text("Salva e Copia"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- LOGICA DI VISUALIZZAZIONE OVERLAY ---
|
||||
void _handleDoubleClick(BuildContext context, OperationFileModel file) {
|
||||
void _handleDoubleClick(BuildContext context, AttachmentModel file) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
|
||||
class GeneralInfoSection extends StatelessWidget {
|
||||
@@ -34,7 +32,7 @@ class GeneralInfoSection extends StatelessWidget {
|
||||
|
||||
// Numero di Riferimento / Telefono
|
||||
TextFormField(
|
||||
initialValue: operation.number,
|
||||
initialValue: operation.reference,
|
||||
keyboardType: TextInputType
|
||||
.phone, // Fa aprire il tastierino numerico su mobile
|
||||
decoration: const InputDecoration(
|
||||
@@ -43,49 +41,6 @@ class GeneralInfoSection extends StatelessWidget {
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.phone),
|
||||
),
|
||||
onChanged: (val) {
|
||||
context.read<OperationsCubit>().updateField(number: val);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// I due Switch affiancati (Bozza e A buon fine)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SwitchListTile(
|
||||
title: const Text("Bozza"),
|
||||
subtitle: const Text(
|
||||
"Pratica in lavorazione",
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
value: operation.isBozza,
|
||||
activeThumbColor: Colors.orange,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
onChanged: (val) {
|
||||
context.read<OperationsCubit>().updateField(isBozza: val);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: SwitchListTile(
|
||||
title: const Text("A buon fine"),
|
||||
subtitle: const Text(
|
||||
"Esito positivo",
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
value: operation.resultOk,
|
||||
activeThumbColor: Colors.green,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
onChanged: (val) {
|
||||
context.read<OperationsCubit>().updateField(
|
||||
resultOk: val,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
@@ -101,9 +56,6 @@ class GeneralInfoSection extends StatelessWidget {
|
||||
border: OutlineInputBorder(),
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
onChanged: (val) {
|
||||
context.read<OperationsCubit>().updateField(note: val);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/attachment_section.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/customer_section.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/general_info_section.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/operations_grid.dart';
|
||||
|
||||
class OperationFormScreen extends StatefulWidget {
|
||||
final String? operationId;
|
||||
@@ -34,9 +33,16 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void _performSave(BuildContext context, {required bool isBozza}) {
|
||||
void _performSave(
|
||||
BuildContext context, {
|
||||
required OperationStatus targetStatus,
|
||||
required bool shouldPop,
|
||||
}) {
|
||||
FocusScope.of(context).unfocus();
|
||||
context.read<OperationsCubit>().saveCurrentOperation(isBozza: isBozza);
|
||||
context.read<OperationsCubit>().saveCurrentOperation(
|
||||
targetStatus: targetStatus,
|
||||
shouldPop: shouldPop,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -93,7 +99,11 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_note),
|
||||
tooltip: "Salva come Bozza",
|
||||
onPressed: () => _performSave(context, isBozza: true),
|
||||
onPressed: () => _performSave(
|
||||
context,
|
||||
targetStatus: OperationStatus.draft,
|
||||
shouldPop: false,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
@@ -101,7 +111,11 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
color: Colors.green,
|
||||
),
|
||||
tooltip: "Conferma Pratica",
|
||||
onPressed: () => _performSave(context, isBozza: false),
|
||||
onPressed: () => _performSave(
|
||||
context,
|
||||
targetStatus: OperationStatus.ok,
|
||||
shouldPop: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
@@ -120,9 +134,6 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
GeneralInfoSection(operation: operation),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
OperationsGrid(operation: operation),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
AttachmentsSection(),
|
||||
const SizedBox(height: 32),
|
||||
_buildBottomActionButtons(context, isSaving: isSaving),
|
||||
@@ -152,7 +163,11 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
label: const Text("Salva in Bozza"),
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => _performSave(context, isBozza: true),
|
||||
: () => _performSave(
|
||||
context,
|
||||
targetStatus: OperationStatus.draft,
|
||||
shouldPop: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -173,7 +188,11 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
),
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => _performSave(context, isBozza: false),
|
||||
: () => _performSave(
|
||||
context,
|
||||
targetStatus: OperationStatus.ok,
|
||||
shouldPop: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -296,7 +296,7 @@ class _OperationMobileUploadScreenState
|
||||
// Diciamo al BLoC di caricare tutti i file.
|
||||
// Usiamo il tuo evento esistente per ogni file (il BLoC li metterà in coda)
|
||||
final bloc = context.read<OperationFilesBloc>();
|
||||
bloc.add(UploadMultipleOperationFilesEvent(_stagedFiles));
|
||||
bloc.add(UploadOperationFilesEvent(pickedFiles: _stagedFiles));
|
||||
|
||||
// N.B: Il Navigator.pop() viene chiamato dal BlocListener in alto quando lo stato diventa "success"!
|
||||
}
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/master_data/products/blocs/product_cubit.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/operations/models/energy_operation_model.dart';
|
||||
import 'package:flux/features/operations/models/entertainment_operation_model.dart';
|
||||
import 'package:flux/features/operations/models/fin_operation_model.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/action_card.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/energy_operation_dialog.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/entertainment_operation_card.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/finance_operation_dialog.dart';
|
||||
import 'package:flux/features/operations/ui/operation_form_screen/int_dialogs.dart'; // Assicurati di importare il modello
|
||||
|
||||
class OperationsGrid extends StatelessWidget {
|
||||
final OperationModel operation;
|
||||
|
||||
const OperationsGrid({super.key, required this.operation});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.layers_outlined,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
"Servizi e Accessori",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 16,
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
// --- CONTATORI SEMPLICI ---
|
||||
ActionCard(
|
||||
label: "AL",
|
||||
count: operation.al,
|
||||
icon: Icons.sim_card,
|
||||
color: Colors.blue,
|
||||
onTap: () => updateCountDialog(
|
||||
context,
|
||||
"AL",
|
||||
operation.al,
|
||||
(val) =>
|
||||
context.read<OperationsCubit>().updateField(al: val),
|
||||
),
|
||||
),
|
||||
ActionCard(
|
||||
label: "MNP",
|
||||
count: operation.mnp,
|
||||
icon: Icons.phone_android,
|
||||
color: Colors.indigo,
|
||||
onTap: () => updateCountDialog(
|
||||
context,
|
||||
"MNP",
|
||||
operation.mnp,
|
||||
(val) =>
|
||||
context.read<OperationsCubit>().updateField(mnp: val),
|
||||
),
|
||||
),
|
||||
ActionCard(
|
||||
label: "NIP",
|
||||
count: operation.nip,
|
||||
icon: Icons.compare_arrows,
|
||||
color: Colors.cyan,
|
||||
onTap: () => updateCountDialog(
|
||||
context,
|
||||
"NIP",
|
||||
operation.nip,
|
||||
(val) =>
|
||||
context.read<OperationsCubit>().updateField(nip: val),
|
||||
),
|
||||
),
|
||||
ActionCard(
|
||||
label: "Unica",
|
||||
count: operation.unica,
|
||||
icon: Icons.all_inclusive,
|
||||
color: Colors.purple,
|
||||
onTap: () => updateCountDialog(
|
||||
context,
|
||||
"Unica",
|
||||
operation.unica,
|
||||
(val) => context.read<OperationsCubit>().updateField(
|
||||
unica: val,
|
||||
),
|
||||
),
|
||||
),
|
||||
ActionCard(
|
||||
label: "Telepass",
|
||||
count: operation.telepass,
|
||||
icon: Icons.directions_car,
|
||||
color: Colors.amber.shade700,
|
||||
onTap: () => updateCountDialog(
|
||||
context,
|
||||
"Telepass",
|
||||
operation.telepass,
|
||||
(val) => context.read<OperationsCubit>().updateField(
|
||||
telepass: val,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// --- MODULI COMPLESSI (Le liste) ---
|
||||
ActionCard(
|
||||
label: "Energia",
|
||||
count: operation.energyOperations.length,
|
||||
icon: Icons.bolt,
|
||||
color: Colors.green,
|
||||
onTap: () async {
|
||||
// Apriamo la modale e aspettiamo il risultato
|
||||
final result =
|
||||
await showDialog<List<EnergyOperationModel>>(
|
||||
context: context,
|
||||
builder: (context) => EnergyOperationDialog(
|
||||
currentStoreId: operation.storeId,
|
||||
initialOperations: operation
|
||||
.energyOperations, // Passiamo la lista attuale
|
||||
),
|
||||
);
|
||||
|
||||
// Se l'utente ha premuto "Conferma" e non "Annulla" o tap fuori
|
||||
if (result != null && context.mounted) {
|
||||
context.read<OperationsCubit>().updateEnergyOperations(
|
||||
result,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
ActionCard(
|
||||
label: "Finanziam.",
|
||||
count: operation.finOperations.length,
|
||||
icon: Icons.euro_symbol,
|
||||
color: Colors.teal,
|
||||
onTap: () async {
|
||||
final result = await showDialog<List<FinOperationModel>>(
|
||||
context: context,
|
||||
builder: (context) => FinanceOperationDialog(
|
||||
productCubit: context.read<ProductCubit>(),
|
||||
currentStoreId: operation.storeId,
|
||||
initialOperations: operation
|
||||
.finOperations, // Passiamo la lista attuale
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
context.read<OperationsCubit>().updateFinOperations(
|
||||
result,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
ActionCard(
|
||||
label: "Intratten.",
|
||||
count: operation.entertainmentOperations.length,
|
||||
icon: Icons.movie_filter_outlined,
|
||||
color: Colors.purple,
|
||||
onTap: () async {
|
||||
final result =
|
||||
await showDialog<List<EntertainmentOperationModel>>(
|
||||
context: context,
|
||||
builder: (context) => EntertainmentOperationDialog(
|
||||
initialOperations:
|
||||
operation.entertainmentOperations,
|
||||
currentStoreId: operation.storeId,
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
context
|
||||
.read<OperationsCubit>()
|
||||
.updateEntertainmentOperations(result);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:flux/features/operations/utils/operation_actions.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
// Importa i tuoi modelli e cubit
|
||||
|
||||
@@ -139,15 +138,6 @@ class _OperationsScreenState extends State<OperationsScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (operation.isBozza)
|
||||
const Chip(
|
||||
label: Text(
|
||||
"BOZZA",
|
||||
style: TextStyle(fontSize: 10, color: Colors.white),
|
||||
),
|
||||
backgroundColor: Colors.orange,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Column(
|
||||
@@ -155,21 +145,14 @@ class _OperationsScreenState extends State<OperationsScreen> {
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
"Pratica: ${operation.number} • ${operation.createdAt?.day}/${operation.createdAt?.month}/${operation.createdAt?.year}",
|
||||
"Pratica: ${operation.reference} • ${operation.createdAt?.day}/${operation.createdAt?.month}/${operation.createdAt?.year}",
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// I nostri mini-chip per i servizi attivati
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
Row(
|
||||
children: [
|
||||
if (operation.al > 0 || operation.mnp > 0)
|
||||
_miniBadge("📞 Tel", Colors.blue),
|
||||
if (operation.energyOperations.isNotEmpty)
|
||||
_miniBadge("⚡ Energy", Colors.green),
|
||||
if (operation.finOperations.isNotEmpty)
|
||||
_miniBadge("💰 Fin", Colors.purple),
|
||||
if (operation.entertainmentOperations.isNotEmpty)
|
||||
_miniBadge("📺 Ent", Colors.red),
|
||||
Text(operation.type),
|
||||
const SizedBox(width: 8),
|
||||
_buildOperationStatus(operation.status),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -187,22 +170,31 @@ class _OperationsScreenState extends State<OperationsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _miniBadge(String text, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: color.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Widget _buildOperationStatus(OperationStatus status) {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case OperationStatus.canceled || OperationStatus.ko:
|
||||
color = Colors.grey.shade800;
|
||||
break;
|
||||
case OperationStatus.waitingforaction || OperationStatus.draft:
|
||||
color = Colors.orange;
|
||||
break;
|
||||
case OperationStatus.ok:
|
||||
color = Colors.green;
|
||||
break;
|
||||
case OperationStatus.waitingfordeployment ||
|
||||
OperationStatus.waitingforsupport:
|
||||
color = Colors.blue;
|
||||
break;
|
||||
}
|
||||
return Chip(
|
||||
label: Text("BOZZA", style: TextStyle(fontSize: 10, color: Colors.white)),
|
||||
backgroundColor: color,
|
||||
visualDensity: VisualDensity.compact,
|
||||
);
|
||||
}
|
||||
|
||||
void startNewOperation(BuildContext context) {
|
||||
context.pushNamed('operation-form');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user