Refactor service management: streamline service form, enhance state management, and improve loading logic

This commit is contained in:
2026-04-17 19:19:01 +02:00
parent 667bbf6404
commit a06be4bf7a
13 changed files with 715 additions and 261 deletions

View File

@@ -1,4 +1,6 @@
import 'package:equatable/equatable.dart';
import 'package:flux/features/services/models/entertainment_service_model.dart';
import 'package:flux/features/services/models/fin_service_model.dart';
enum EnergyType { luce, gas } // Mappa il tuo public.energy_type

View File

@@ -115,12 +115,14 @@ class ServiceModel extends Equatable {
factory ServiceModel.fromMap(Map<String, dynamic> map) {
return ServiceModel(
id: map['id'],
createdAt: DateTime.parse(map['created_at']),
storeId: map['store_id'],
employeeId: map['employee_id'],
customerId: map['customer_id'],
number: map['number'] ?? '',
id: map['id'].toString(),
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
: DateTime.now(),
storeId: map['store_id'] ?? '',
employeeId: map['employee_id']?.toString(),
customerId: map['customer_id']?.toString(),
number: map['number']?.toString() ?? '',
isBozza: map['bozza'] ?? true,
note: map['note'] ?? '',
resultOk: map['result_ok'] ?? true,
@@ -130,7 +132,7 @@ class ServiceModel extends Equatable {
unica: map['unica'] ?? 0,
telepass: map['telepass'] ?? 0,
// Mappaggio delle liste collegate (se incluse nella query)
// Estrazione sicura liste collegate
energyServices:
(map['energy_service'] as List?)
?.map((x) => EnergyServiceModel.fromMap(x))
@@ -146,9 +148,12 @@ class ServiceModel extends Equatable {
?.map((x) => EntertainmentServiceModel.fromMap(x))
.toList() ??
const [],
// Display name del cliente con fallback
customerDisplayName: map['customer'] != null
? "${map['customer']['name']} ${map['customer']['surname']}"
: "Cliente sconosciuto",
? "${map['customer']['name'] ?? ''} ${map['customer']['surname'] ?? ''}"
.trim()
: "Cliente non assegnato",
);
}