2026-04-16 11:50:29 +02:00
|
|
|
import 'package:equatable/equatable.dart';
|
2026-04-29 19:25:48 +02:00
|
|
|
import 'package:flux/core/utils/extensions.dart';
|
2026-05-01 10:11:44 +02:00
|
|
|
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_file_model.dart'; // <-- Aggiunto Import
|
2026-04-16 11:50:29 +02:00
|
|
|
|
2026-05-01 10:11:44 +02:00
|
|
|
class OperationModel extends Equatable {
|
2026-04-16 11:50:29 +02:00
|
|
|
final String? id;
|
|
|
|
|
final DateTime? createdAt;
|
|
|
|
|
final String storeId;
|
|
|
|
|
final String? employeeId;
|
|
|
|
|
final String? customerId;
|
|
|
|
|
final String number;
|
|
|
|
|
final bool isBozza;
|
|
|
|
|
final String note;
|
|
|
|
|
final bool resultOk;
|
|
|
|
|
final String? customerDisplayName;
|
2026-04-20 16:52:20 +02:00
|
|
|
final String companyId;
|
2026-04-16 11:50:29 +02:00
|
|
|
|
|
|
|
|
// Telefonia
|
|
|
|
|
final int al;
|
|
|
|
|
final int mnp;
|
|
|
|
|
final int nip;
|
|
|
|
|
final int unica;
|
|
|
|
|
final int telepass;
|
|
|
|
|
|
|
|
|
|
// Moduli (Liste)
|
2026-05-01 10:11:44 +02:00
|
|
|
final List<EnergyOperationModel> energyOperations;
|
|
|
|
|
final List<FinOperationModel> finOperations;
|
|
|
|
|
final List<EntertainmentOperationModel> entertainmentOperations;
|
2026-04-16 11:50:29 +02:00
|
|
|
|
2026-04-20 16:52:20 +02:00
|
|
|
// ALLEGATI (Aggiunto)
|
2026-05-01 10:11:44 +02:00
|
|
|
final List<OperationFileModel> files;
|
2026-04-20 16:52:20 +02:00
|
|
|
|
2026-05-01 10:11:44 +02:00
|
|
|
const OperationModel({
|
2026-04-16 11:50:29 +02:00
|
|
|
this.id,
|
|
|
|
|
this.createdAt,
|
|
|
|
|
required this.storeId,
|
|
|
|
|
this.employeeId,
|
|
|
|
|
this.customerId,
|
|
|
|
|
required this.number,
|
|
|
|
|
this.isBozza = true,
|
|
|
|
|
this.note = '',
|
|
|
|
|
this.resultOk = true,
|
|
|
|
|
this.al = 0,
|
|
|
|
|
this.mnp = 0,
|
|
|
|
|
this.nip = 0,
|
|
|
|
|
this.unica = 0,
|
|
|
|
|
this.telepass = 0,
|
2026-05-01 10:11:44 +02:00
|
|
|
this.energyOperations = const [],
|
|
|
|
|
this.finOperations = const [],
|
|
|
|
|
this.entertainmentOperations = const [],
|
2026-04-20 16:52:20 +02:00
|
|
|
this.files = const [], // <-- Aggiunto default vuoto
|
2026-04-16 11:50:29 +02:00
|
|
|
this.customerDisplayName,
|
2026-04-20 16:52:20 +02:00
|
|
|
required this.companyId,
|
2026-04-16 11:50:29 +02:00
|
|
|
});
|
|
|
|
|
|
2026-05-01 10:11:44 +02:00
|
|
|
OperationModel copyWith({
|
2026-04-16 11:50:29 +02:00
|
|
|
String? id,
|
|
|
|
|
DateTime? createdAt,
|
|
|
|
|
String? storeId,
|
|
|
|
|
String? employeeId,
|
|
|
|
|
String? customerId,
|
|
|
|
|
String? number,
|
|
|
|
|
bool? isBozza,
|
|
|
|
|
String? note,
|
|
|
|
|
bool? resultOk,
|
|
|
|
|
int? al,
|
|
|
|
|
int? mnp,
|
|
|
|
|
int? nip,
|
|
|
|
|
int? unica,
|
|
|
|
|
int? telepass,
|
2026-05-01 10:11:44 +02:00
|
|
|
List<EnergyOperationModel>? energyOperations,
|
|
|
|
|
List<FinOperationModel>? finOperations,
|
|
|
|
|
List<EntertainmentOperationModel>? entertainmentOperations,
|
|
|
|
|
List<OperationFileModel>? files, // <-- Aggiunto
|
2026-04-16 11:50:29 +02:00
|
|
|
String? customerDisplayName,
|
2026-04-20 16:52:20 +02:00
|
|
|
String? companyId,
|
2026-04-16 11:50:29 +02:00
|
|
|
}) {
|
2026-05-01 10:11:44 +02:00
|
|
|
return OperationModel(
|
2026-04-16 11:50:29 +02:00
|
|
|
id: id ?? this.id,
|
|
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
|
storeId: storeId ?? this.storeId,
|
|
|
|
|
employeeId: employeeId ?? this.employeeId,
|
|
|
|
|
customerId: customerId ?? this.customerId,
|
|
|
|
|
number: number ?? this.number,
|
|
|
|
|
isBozza: isBozza ?? this.isBozza,
|
|
|
|
|
note: note ?? this.note,
|
|
|
|
|
resultOk: resultOk ?? this.resultOk,
|
|
|
|
|
al: al ?? this.al,
|
|
|
|
|
mnp: mnp ?? this.mnp,
|
|
|
|
|
nip: nip ?? this.nip,
|
|
|
|
|
unica: unica ?? this.unica,
|
|
|
|
|
telepass: telepass ?? this.telepass,
|
2026-05-01 10:11:44 +02:00
|
|
|
energyOperations: energyOperations ?? this.energyOperations,
|
|
|
|
|
finOperations: finOperations ?? this.finOperations,
|
|
|
|
|
entertainmentOperations:
|
|
|
|
|
entertainmentOperations ?? this.entertainmentOperations,
|
2026-04-20 16:52:20 +02:00
|
|
|
files: files ?? this.files, // <-- Aggiunto
|
2026-04-16 11:50:29 +02:00
|
|
|
customerDisplayName: customerDisplayName ?? this.customerDisplayName,
|
2026-04-20 16:52:20 +02:00
|
|
|
companyId: companyId ?? this.companyId,
|
2026-04-16 11:50:29 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<Object?> get props => [
|
|
|
|
|
id,
|
|
|
|
|
createdAt,
|
|
|
|
|
storeId,
|
|
|
|
|
employeeId,
|
|
|
|
|
customerId,
|
|
|
|
|
number,
|
|
|
|
|
isBozza,
|
|
|
|
|
note,
|
|
|
|
|
resultOk,
|
|
|
|
|
al,
|
|
|
|
|
mnp,
|
|
|
|
|
nip,
|
|
|
|
|
unica,
|
|
|
|
|
telepass,
|
2026-05-01 10:11:44 +02:00
|
|
|
energyOperations,
|
|
|
|
|
finOperations,
|
|
|
|
|
entertainmentOperations,
|
2026-04-20 16:52:20 +02:00
|
|
|
files, // <-- Aggiunto
|
2026-04-16 11:50:29 +02:00
|
|
|
customerDisplayName,
|
2026-04-20 16:52:20 +02:00
|
|
|
companyId,
|
2026-04-16 11:50:29 +02:00
|
|
|
];
|
|
|
|
|
|
2026-05-01 10:11:44 +02:00
|
|
|
factory OperationModel.fromMap(Map<String, dynamic> map) {
|
|
|
|
|
return OperationModel(
|
2026-04-20 16:52:20 +02:00
|
|
|
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() ?? '',
|
2026-04-16 11:50:29 +02:00
|
|
|
isBozza: map['bozza'] ?? true,
|
|
|
|
|
note: map['note'] ?? '',
|
|
|
|
|
resultOk: map['result_ok'] ?? true,
|
|
|
|
|
al: map['al'] ?? 0,
|
|
|
|
|
mnp: map['mnp'] ?? 0,
|
|
|
|
|
nip: map['nip'] ?? 0,
|
|
|
|
|
unica: map['unica'] ?? 0,
|
|
|
|
|
telepass: map['telepass'] ?? 0,
|
|
|
|
|
|
2026-04-20 16:52:20 +02:00
|
|
|
// Estrazione sicura liste collegate
|
2026-05-01 10:11:44 +02:00
|
|
|
energyOperations:
|
|
|
|
|
(map['energy_operation'] as List?)
|
|
|
|
|
?.map((x) => EnergyOperationModel.fromMap(x))
|
2026-04-16 11:50:29 +02:00
|
|
|
.toList() ??
|
|
|
|
|
const [],
|
2026-05-01 10:11:44 +02:00
|
|
|
finOperations:
|
|
|
|
|
(map['fin_operation'] as List?)
|
|
|
|
|
?.map((x) => FinOperationModel.fromMap(x))
|
2026-04-16 11:50:29 +02:00
|
|
|
.toList() ??
|
|
|
|
|
const [],
|
2026-05-01 10:11:44 +02:00
|
|
|
entertainmentOperations:
|
|
|
|
|
(map['entertainment_operation'] as List?)
|
|
|
|
|
?.map((x) => EntertainmentOperationModel.fromMap(x))
|
2026-04-16 11:50:29 +02:00
|
|
|
.toList() ??
|
|
|
|
|
const [],
|
2026-04-20 16:52:20 +02:00
|
|
|
|
|
|
|
|
// I FILE! (Assicurati che la foreign key su Supabase usi esattamente questo nome)
|
|
|
|
|
files:
|
2026-05-01 10:11:44 +02:00
|
|
|
(map['operation_file'] as List?)
|
|
|
|
|
?.map((x) => OperationFileModel.fromMap(x))
|
2026-04-20 16:52:20 +02:00
|
|
|
.toList() ??
|
|
|
|
|
const [],
|
|
|
|
|
|
|
|
|
|
// Display name del cliente con fallback
|
2026-04-16 11:50:29 +02:00
|
|
|
customerDisplayName: map['customer'] != null
|
2026-04-20 16:52:20 +02:00
|
|
|
? "${map['customer']['nome'] ?? ''}".myFormat()
|
|
|
|
|
: "Cliente non assegnato",
|
|
|
|
|
companyId: map['company_id'] as String,
|
2026-04-16 11:50:29 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
|
return {
|
|
|
|
|
if (id != null) 'id': id,
|
|
|
|
|
'store_id': storeId,
|
|
|
|
|
'employee_id': employeeId,
|
|
|
|
|
'customer_id': customerId,
|
|
|
|
|
'number': number,
|
|
|
|
|
'bozza': isBozza,
|
|
|
|
|
'note': note,
|
|
|
|
|
'result_ok': resultOk,
|
|
|
|
|
'al': al,
|
|
|
|
|
'mnp': mnp,
|
|
|
|
|
'nip': nip,
|
|
|
|
|
'unica': unica,
|
|
|
|
|
'telepass': telepass,
|
2026-04-20 16:52:20 +02:00
|
|
|
'company_id': companyId,
|
2026-04-16 11:50:29 +02:00
|
|
|
// Le liste non le mettiamo qui perché vanno in tabelle diverse!
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|