uff
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:flux/features/tickets/data/ticket_repository.dart';
|
||||
import 'package:flux/features/tracking/data/tracking_repository.dart';
|
||||
import 'package:flux/features/tracking/models/tracking_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'ticket_form_state.dart';
|
||||
|
||||
class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
final TicketRepository _repository = GetIt.I.get<TicketRepository>();
|
||||
final SessionCubit _sessionCubit = GetIt.I.get<SessionCubit>();
|
||||
final StaffMemberModel? _createdBy;
|
||||
|
||||
TicketFormCubit()
|
||||
TicketFormCubit({StaffMemberModel? createdBy})
|
||||
: super(
|
||||
// Inizializziamo con un ticket vuoto di default
|
||||
TicketFormState(ticket: TicketModel.empty()),
|
||||
TicketFormState(
|
||||
ticket: TicketModel.empty().copyWith(
|
||||
createdById: createdBy?.id,
|
||||
createdByName: createdBy?.name,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// 1. INIZIALIZZAZIONE (Se stiamo modificando un ticket esistente)
|
||||
@@ -48,15 +57,14 @@ class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
} else {
|
||||
// SCENARIO 3 (Nuovo Ticket):
|
||||
// È un nuovo ticket! Inseriamo i default base (Azienda, Negozio, Creatore)
|
||||
final currentUser = _sessionCubit.state.currentStaffMember;
|
||||
final currentStore = _sessionCubit.state.currentStore;
|
||||
final companyId = _sessionCubit.state.company?.id ?? '';
|
||||
|
||||
final newTicket = TicketModel.empty().copyWith(
|
||||
companyId: companyId,
|
||||
storeId: currentStore?.id,
|
||||
createdById: currentUser?.id,
|
||||
createdByName: currentUser?.name,
|
||||
createdById: createdBy.id,
|
||||
createdByName: _createdBy.name,
|
||||
// Impostiamo lo stato iniziale
|
||||
ticketStatus: TicketStatus.open,
|
||||
ticketType: TicketType.repair, // Default
|
||||
@@ -219,4 +227,51 @@ class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> takeInCharge({
|
||||
required String staffId,
|
||||
required String staffName,
|
||||
}) async {
|
||||
final currentTicket = state.ticket;
|
||||
|
||||
// Sicurezza: non possiamo prendere in carico un ticket fantasma
|
||||
if (currentTicket.id == null || currentTicket.id!.isEmpty) return;
|
||||
|
||||
// 1. Prepariamo il ticket aggiornato
|
||||
final updatedTicket = currentTicket.copyWith(
|
||||
ticketStatus: TicketStatus
|
||||
.inProgress, // Assumendo che tu abbia un enum per gli stati
|
||||
assignedToId: staffId,
|
||||
assignedToName: staffName,
|
||||
);
|
||||
|
||||
try {
|
||||
// 2. Aggiorniamo il ticket sul Database (usa il tuo metodo esistente del repo)
|
||||
await _repository.updateTicket(updatedTicket);
|
||||
|
||||
// 3. Spara il log automatico nella Timeline!
|
||||
await GetIt.I.get<TrackingRepository>().logQuickEvent(
|
||||
companyId: currentTicket.companyId,
|
||||
message: "Ticket preso in carico. Inizio lavorazione.",
|
||||
type: TrackingType.statusChange,
|
||||
parentId: currentTicket.id!,
|
||||
parentType: TrackingParentType.ticket,
|
||||
staffId: staffId,
|
||||
// Lo mettiamo pubblico (isInternal: false) così il cliente a casa vede che
|
||||
// il suo dispositivo è ufficialmente sotto i ferri!
|
||||
isInternal: false,
|
||||
);
|
||||
|
||||
// 4. Aggiorniamo lo stato locale del Cubit per far scattare la UI
|
||||
emit(state.copyWith(ticket: updatedTicket));
|
||||
} catch (e) {
|
||||
// Gestisci eventuali errori (es. mostrando una snackbar)
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TicketFormStatus.failure,
|
||||
errorMessage: 'Errore durante la presa in carico: $e',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/staff_section.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_status_extension.dart';
|
||||
import 'package:flux/features/tickets/ui/ticket_timeline_section.dart';
|
||||
import 'package:flux/features/tickets/ui/ticket_workspace_screen.dart';
|
||||
import 'package:flux/features/tickets/utils/ticket_pdf_service.dart';
|
||||
import 'package:flux/features/tracking/blocs/tracking_cubit.dart';
|
||||
import 'package:flux/features/tracking/data/tracking_repository.dart';
|
||||
import 'package:flux/features/tracking/models/tracking_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
@@ -300,6 +300,83 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
ticket.id == null ? 'Nuova Scheda Assistenza' : 'Modifica Scheda',
|
||||
),
|
||||
actions: [
|
||||
BlocBuilder<TicketFormCubit, TicketFormState>(
|
||||
builder: (context, state) {
|
||||
final ticket = state.ticket;
|
||||
|
||||
// Se il ticket non è ancora salvato, niente azioni rapide
|
||||
if (ticket.id == null || ticket.id!.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
// CONDIZIONE A: Da iniziare
|
||||
if (ticket.ticketStatus == TicketStatus.open ||
|
||||
ticket.ticketStatus == TicketStatus.inProgress) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor:
|
||||
Colors.amber.shade700, // Colore Action
|
||||
),
|
||||
onPressed: () {
|
||||
final currentUserId = GetIt.I
|
||||
.get<SessionCubit>()
|
||||
.state
|
||||
.currentStaffMember!
|
||||
.id!;
|
||||
final currentUserName = GetIt.I
|
||||
.get<SessionCubit>()
|
||||
.state
|
||||
.currentStaffMember!
|
||||
.name;
|
||||
|
||||
context.read<TicketFormCubit>().takeInCharge(
|
||||
staffId: currentUserId,
|
||||
staffName: currentUserName,
|
||||
);
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
TicketWorkspaceScreen(ticket: ticket),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.play_arrow, color: Colors.white),
|
||||
label: const Text(
|
||||
'Prendi in Carico',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
// CONDIZIONE B: Già in lavorazione
|
||||
else if (ticket.ticketStatus == TicketStatus.inProgress) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
onPressed: () {
|
||||
// Naviga direttamente alla schermata di lavorazione
|
||||
// Navigator.push(context, MaterialPageRoute(builder: (_) => TicketWorkspaceScreen(ticket: ticket)));
|
||||
},
|
||||
icon: const Icon(Icons.handyman),
|
||||
label: const Text('Vai a Lavorazione'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Se è chiuso o in altri stati strani, nascondiamo il bottone
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16.0),
|
||||
child: Chip(
|
||||
@@ -807,10 +884,8 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
children: [
|
||||
BlocProvider(
|
||||
create: (context) => TrackingCubit(
|
||||
repo: GetIt.I.get<TrackingRepository>(),
|
||||
parentId: ticket.id!,
|
||||
parentType: TrackingParentType.ticket,
|
||||
companyId: ticket.companyId,
|
||||
),
|
||||
child: BlocBuilder<TrackingCubit, TrackingState>(
|
||||
builder: (context, state) {
|
||||
@@ -826,7 +901,11 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
context.read<TrackingCubit>().addManualNote(
|
||||
message,
|
||||
isInternal,
|
||||
// staffId: currentStaffId,
|
||||
staffId: GetIt.I
|
||||
.get<SessionCubit>()
|
||||
.state
|
||||
.currentStaffMember
|
||||
?.id,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
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/routes/routes.dart';
|
||||
import 'package:flux/core/widgets/staff_selector_modal.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_list_cubit.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_list_state.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_status_extension.dart';
|
||||
import 'package:flux/features/tickets/ui/ticket_form_screen.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class TicketListScreen extends StatefulWidget {
|
||||
@@ -148,11 +152,17 @@ class _TicketListScreenState extends State<TicketListScreen> {
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
context.pushNamed(Routes.ticketForm, pathParameters: {'id': 'new'});
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Nuovo Ticket'),
|
||||
onPressed: () async {
|
||||
StaffMemberModel? createdBy = await getStaffMember(context);
|
||||
if (createdBy == null || !context.mounted) return;
|
||||
context.pushNamed(
|
||||
Routes.ticketForm,
|
||||
pathParameters: {'id': 'new'},
|
||||
extra: createdBy,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
251
lib/features/tickets/ui/ticket_workspace_screen.dart
Normal file
251
lib/features/tickets/ui/ticket_workspace_screen.dart
Normal file
@@ -0,0 +1,251 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
// Importa il tuo TicketModel, Cubit, ecc.
|
||||
|
||||
class TicketWorkspaceScreen extends StatelessWidget {
|
||||
// Passiamo il ticket attuale per avere i dati (o il Cubit se preferisci)
|
||||
final dynamic ticket; // Sostituisci con TicketModel
|
||||
|
||||
const TicketWorkspaceScreen({super.key, required this.ticket});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Banco di Lavoro'),
|
||||
backgroundColor: theme.colorScheme.inversePrimary,
|
||||
centerTitle: true,
|
||||
),
|
||||
// SafeArea in basso per ospitare i bottoni fissi
|
||||
bottomNavigationBar: SafeArea(child: _buildBottomActions(context)),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildDeviceHeader(theme),
|
||||
const SizedBox(height: 24),
|
||||
_buildDefectRecap(theme),
|
||||
const SizedBox(height: 32),
|
||||
_buildOperationsSection(theme),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- 1. HEADER DISPOSITIVO E PASSWORD ---
|
||||
Widget _buildDeviceHeader(ThemeData theme) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
color: theme.colorScheme.primaryContainer.withValues(alpha: 0.4),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(
|
||||
color: theme.colorScheme.primary.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'DISPOSITIVO IN LAVORAZIONE',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.primary,
|
||||
letterSpacing: 1.2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
ticket.deviceModel ??
|
||||
'Modello Sconosciuto', // Es: "iPhone 13 Pro"
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// IL DATO PIÙ CERCATO DAI TECNICI: LA PASSWORD
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: theme.dividerColor),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
'PIN / SBLOCCO',
|
||||
style: TextStyle(fontSize: 10, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
ticket.unlockPassword?.isNotEmpty == true
|
||||
? ticket.unlockPassword!
|
||||
: 'Nessuno',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- 2. RECAP DIFETTO ---
|
||||
Widget _buildDefectRecap(ThemeData theme) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(Icons.warning_amber_rounded, color: Colors.orange),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Difetto Segnalato',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest.withValues(
|
||||
alpha: 0.3,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: theme.dividerColor),
|
||||
),
|
||||
child: Text(
|
||||
ticket.defectDescription ?? 'Nessuna descrizione inserita.',
|
||||
style: const TextStyle(fontSize: 16, height: 1.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// --- 3. SEZIONE COSTI E RICAMBI (Mockup) ---
|
||||
Widget _buildOperationsSection(ThemeData theme) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Ricambi e Manodopera',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
// TODO: Apri modal per aggiungere una riga di costo
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Aggiungi Voce'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// Qui ci andrà un ListView.builder collegato alla tabella dei costi/operazioni
|
||||
Container(
|
||||
padding: const EdgeInsets.all(32),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: theme.dividerColor,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'Nessun ricambio o costo inserito.\nClicca su "Aggiungi Voce" per iniziare.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// --- 4. BOTTONI AZIONE FINALI (In basso) ---
|
||||
Widget _buildBottomActions(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, -5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Bottone Pausa / Attesa Ricambi
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
foregroundColor: Colors.orange.shade700,
|
||||
side: BorderSide(color: Colors.orange.shade700),
|
||||
),
|
||||
onPressed: () {
|
||||
// TODO: Logica Metti in Pausa
|
||||
},
|
||||
icon: const Icon(Icons.pause),
|
||||
label: const Text(
|
||||
'Metti in Pausa',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Bottone Completa
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: FilledButton.icon(
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: Colors.green.shade600,
|
||||
),
|
||||
onPressed: () {
|
||||
// TODO: Logica Completa Riparazione
|
||||
},
|
||||
icon: const Icon(Icons.check_circle_outline),
|
||||
label: const Text(
|
||||
'COMPLETA RIPARAZIONE',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, letterSpacing: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user