Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m20s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m35s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m41s
Build and Release FLUX (Multi-Platform) / build-macos (push) Failing after 10m33s
202 lines
5.7 KiB
Dart
202 lines
5.7 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'package:flux/core/enums_and_consts/consts.dart';
|
|
import 'package:flux/core/utils/extensions.dart';
|
|
import 'package:flux/features/attachments/models/attachment_model.dart';
|
|
import 'package:flux/features/customers/models/customer_model.dart';
|
|
import 'package:flux/features/operations/models/operation_detail_model.dart';
|
|
|
|
enum OperationStatus {
|
|
success('success', 'OK'),
|
|
waitingForAction('waiting_for_action', 'In attesa di azione'),
|
|
waitingForSupport('waiting_for_support', 'In attesa di supporto'),
|
|
failure('failure', 'KO'),
|
|
draft('draft', 'Bozza');
|
|
|
|
static OperationStatus fromString(String value) {
|
|
final normalizedValue = value.replaceAll('_', '').toLowerCase();
|
|
return OperationStatus.values.firstWhere(
|
|
(e) => e.name.toLowerCase() == normalizedValue,
|
|
);
|
|
}
|
|
|
|
final String supabaseName;
|
|
final String displayName;
|
|
|
|
const OperationStatus(this.supabaseName, this.displayName);
|
|
}
|
|
|
|
class OperationModel extends Equatable {
|
|
final String? id;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
final String note;
|
|
final bool showInDashboard;
|
|
final String companyId;
|
|
final String storeId;
|
|
final String? storeDisplayName;
|
|
final String? staffId;
|
|
final String? staffDisplayName;
|
|
final OperationStatus status;
|
|
final String? customerId;
|
|
final CustomerModel? customer;
|
|
final String reference;
|
|
final bool isBusiness;
|
|
|
|
// ALLEGATI (Aggiunto)
|
|
final List<AttachmentModel> attachments;
|
|
|
|
// DETTAGLI OPERAZIONE (Aggiunto)
|
|
final List<OperationDetailModel> details;
|
|
|
|
const OperationModel({
|
|
this.id,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
this.note = '',
|
|
this.showInDashboard = true,
|
|
required this.companyId,
|
|
this.storeId = '',
|
|
this.storeDisplayName,
|
|
this.staffId,
|
|
this.staffDisplayName,
|
|
this.status = OperationStatus.success,
|
|
this.customerId,
|
|
this.customer,
|
|
this.reference = '',
|
|
this.attachments = const [],
|
|
this.details = const [],
|
|
this.isBusiness = false,
|
|
});
|
|
|
|
OperationModel copyWith({
|
|
String? id,
|
|
DateTime? createdAt,
|
|
DateTime? updatedAt,
|
|
String? note,
|
|
bool? showInDashboard,
|
|
String? companyId,
|
|
String? storeId,
|
|
String? storeDisplayName,
|
|
String? staffId,
|
|
String? staffDisplayName,
|
|
OperationStatus? status,
|
|
String? customerId,
|
|
CustomerModel? customer,
|
|
String? reference,
|
|
List<AttachmentModel>? attachments,
|
|
List<OperationDetailModel>? details,
|
|
bool? isBusiness,
|
|
}) => OperationModel(
|
|
id: id ?? this.id,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
note: note ?? this.note,
|
|
showInDashboard: showInDashboard ?? this.showInDashboard,
|
|
companyId: companyId ?? this.companyId,
|
|
storeId: storeId ?? this.storeId,
|
|
storeDisplayName: storeDisplayName ?? this.storeDisplayName,
|
|
staffId: staffId ?? this.staffId,
|
|
staffDisplayName: staffDisplayName ?? this.staffDisplayName,
|
|
status: status ?? this.status,
|
|
customerId: customerId ?? this.customerId,
|
|
customer: customer ?? this.customer,
|
|
reference: reference ?? this.reference,
|
|
attachments: attachments ?? this.attachments,
|
|
details: details ?? this.details,
|
|
isBusiness: isBusiness ?? this.isBusiness,
|
|
);
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
id,
|
|
createdAt,
|
|
updatedAt,
|
|
note,
|
|
showInDashboard,
|
|
companyId,
|
|
storeId,
|
|
storeDisplayName,
|
|
staffId,
|
|
staffDisplayName,
|
|
status,
|
|
customerId,
|
|
customer,
|
|
reference,
|
|
attachments,
|
|
details,
|
|
isBusiness,
|
|
];
|
|
|
|
factory OperationModel.empty() {
|
|
return OperationModel(
|
|
id: null,
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
showInDashboard: false,
|
|
companyId: '',
|
|
details: const [],
|
|
);
|
|
}
|
|
|
|
factory OperationModel.fromMap(Map<String, dynamic> map) {
|
|
return OperationModel(
|
|
id: map['id'] as String?,
|
|
createdAt: map['created_at'] != null
|
|
? DateTime.parse(map['created_at'] as String).toLocal()
|
|
: null,
|
|
updatedAt: map['updated_at'] != null
|
|
? DateTime.parse(map['updated_at'] as String).toLocal()
|
|
: null,
|
|
note: map['note'] as String? ?? '',
|
|
showInDashboard: map['show_in_dashboard'] as bool? ?? true,
|
|
companyId: map['company_id'] as String,
|
|
|
|
storeId:
|
|
map['store_id'] as String? ??
|
|
'', // Questo è non-nullable nella tua classe
|
|
storeDisplayName: (map[Tables.stores]?['name'] as String?)?.myFormat(),
|
|
staffId: map['staff_id'] as String?,
|
|
staffDisplayName: (map[Tables.staffMembers]?['name'] as String?)
|
|
?.myFormat(),
|
|
status: OperationStatus.fromString(map['status'] ?? 'draft'),
|
|
customerId: map['customer_id'] as String?,
|
|
|
|
customer: map[Tables.customers] != null
|
|
? CustomerModel.fromMap(map[Tables.customers] as Map<String, dynamic>)
|
|
: null,
|
|
|
|
attachments:
|
|
(map[Tables.attachments] as List?)
|
|
?.map((x) => AttachmentModel.fromMap(x))
|
|
.toList() ??
|
|
const [],
|
|
|
|
details:
|
|
(map[Tables.operationDetails] as List?)
|
|
?.map(
|
|
(x) => OperationDetailModel.fromMap(x as Map<String, dynamic>),
|
|
)
|
|
.toList() ??
|
|
const [],
|
|
|
|
reference: map['reference'] as String? ?? '',
|
|
isBusiness: map['is_business'] as bool? ?? false,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
if (id != null) 'id': id,
|
|
'note': note,
|
|
'show_in_dashboard': showInDashboard,
|
|
'company_id': companyId,
|
|
'store_id': storeId,
|
|
if (staffId != null) 'staff_id': staffId,
|
|
'status': status.supabaseName,
|
|
if (customerId != null) 'customer_id': customerId,
|
|
'reference': reference,
|
|
'is_business': isBusiness,
|
|
};
|
|
}
|
|
}
|