reworked operation (#12)

Reviewed-on: #12
Co-authored-by: Mark M2 Macbook <marco@catelli.it>
Co-committed-by: Mark M2 Macbook <marco@catelli.it>
This commit is contained in:
2026-05-04 15:36:42 +02:00
committed by brontomark
parent 9f57207a39
commit 94ad524bae
110 changed files with 5831 additions and 5306 deletions

View File

@@ -1,91 +0,0 @@
import 'package:equatable/equatable.dart';
class CustomerFileModel extends Equatable {
final String? id;
final String customerId; // Riferimento UUID
final String name;
final String storagePath;
final String extension;
final DateTime? createdAt;
final int fileSize;
const CustomerFileModel({
this.id,
required this.customerId,
required this.name,
required this.storagePath,
required this.extension,
this.createdAt,
required this.fileSize,
});
// Trasforma i byte in qualcosa di leggibile (KB, MB, GB)
String get sizeFormatted {
if (fileSize <= 0) return "0 B";
const suffixes = ["B", "KB", "MB", "GB", "TB"];
var i = (fileSize.toString().length - 1) ~/ 3;
if (i >= suffixes.length) i = suffixes.length - 1;
double num = fileSize / (1 << (i * 10));
return "${num.toStringAsFixed(i == 0 ? 0 : 1)} ${suffixes[i]}";
}
bool get isPdf => extension.toLowerCase().replaceAll('.', '') == 'pdf';
CustomerFileModel copyWith({
String? id,
String? customerId,
String? name,
String? storagePath,
String? extension,
DateTime? createdAt,
int? fileSize,
}) {
return CustomerFileModel(
id: id ?? this.id,
customerId: customerId ?? this.customerId,
name: name ?? this.name,
storagePath: storagePath ?? this.storagePath,
extension: extension ?? this.extension,
createdAt: createdAt ?? this.createdAt,
fileSize: fileSize ?? this.fileSize,
);
}
factory CustomerFileModel.fromMap(Map<String, dynamic> map) {
return CustomerFileModel(
id: map['id'] as String,
customerId: map['customer_id'],
name: map['name'],
storagePath: map['storage_path'],
extension: map['extension'] ?? '',
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
: null,
fileSize: map['file_size'] is int
? map['file_size']
: int.tryParse(map['file_size']?.toString() ?? '0') ?? 0,
);
}
Map<String, dynamic> toMap() {
return {
if (id != null) 'id': id,
'customer_id': customerId,
'name': name,
'storage_path': storagePath,
'extension': extension,
'file_size': fileSize,
};
}
@override
List<Object?> get props => [
id,
customerId,
name,
storagePath,
extension,
createdAt,
fileSize,
];
}

View File

@@ -1,74 +1,74 @@
import 'package:equatable/equatable.dart';
import 'package:flux/core/utils/string_extensions.dart';
import 'package:flux/features/customers/models/customer_file_model.dart';
import 'package:flux/core/utils/extensions.dart';
import 'package:flux/features/attachments/models/attachment_model.dart';
class CustomerModel extends Equatable {
final String? id; // Bigint in SQL
final DateTime? createdAt;
final String nome;
final String telefono;
final String name;
final String phoneNumber;
final String email;
final String note;
final DateTime? dataUltimoContatto;
final bool nonDisturbare;
final DateTime? lastContactDate;
final bool doNotDisturb;
final String companyId; // UUID
final bool isActive;
final List<CustomerFileModel> files;
final List<AttachmentModel> attachments;
const CustomerModel({
this.id,
this.createdAt,
required this.nome,
required this.telefono,
required this.name,
required this.phoneNumber,
required this.email,
required this.note,
this.dataUltimoContatto,
this.nonDisturbare = false,
this.lastContactDate,
this.doNotDisturb = false,
required this.companyId,
this.isActive = true,
this.files = const [],
this.attachments = const [],
});
@override
List<Object?> get props => [
id,
createdAt,
nome,
telefono,
name,
phoneNumber,
email,
note,
dataUltimoContatto,
nonDisturbare,
lastContactDate,
doNotDisturb,
companyId,
isActive,
files,
attachments,
];
CustomerModel copyWith({
String? id,
DateTime? createdAt,
String? nome,
String? telefono,
String? name,
String? phoneNumber,
String? email,
String? note,
DateTime? dataUltimoContatto,
bool? nonDisturbare,
DateTime? lastContactDate,
bool? doNotDisturb,
String? companyId,
bool? isActive,
List<CustomerFileModel>? files,
List<AttachmentModel>? attachments,
}) {
return CustomerModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
nome: nome ?? this.nome,
telefono: telefono ?? this.telefono,
name: name ?? this.name,
phoneNumber: phoneNumber ?? this.phoneNumber,
email: email ?? this.email,
note: note ?? this.note,
dataUltimoContatto: dataUltimoContatto ?? this.dataUltimoContatto,
nonDisturbare: nonDisturbare ?? this.nonDisturbare,
lastContactDate: lastContactDate ?? this.lastContactDate,
doNotDisturb: doNotDisturb ?? this.doNotDisturb,
companyId: companyId ?? this.companyId,
isActive: isActive ?? this.isActive,
files: files ?? this.files,
attachments: attachments ?? this.attachments,
);
}
@@ -78,19 +78,19 @@ class CustomerModel extends Equatable {
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
: null,
nome: (map['nome'] as String).myFormat(),
telefono: map['telefono'],
name: (map['name'] as String).myFormat(),
phoneNumber: map['phone_number'],
email: map['email'],
note: map['note'] ?? '',
dataUltimoContatto: map['data_ultimo_contatto'] != null
? DateTime.parse(map['data_ultimo_contatto'])
lastContactDate: map['last_contact_date'] != null
? DateTime.parse(map['last_contact_date'])
: null,
nonDisturbare: map['non_disturbare'] ?? false,
doNotDisturb: map['do_not_disturb'] ?? false,
companyId: map['company_id'] as String,
isActive: map['is_active'] ?? true,
files:
(map['customer_file'] as List?)
?.map((x) => CustomerFileModel.fromMap(x))
attachments:
(map['attachment'] as List?)
?.map((x) => AttachmentModel.fromMap(x))
.toList() ??
const [],
);
@@ -99,13 +99,13 @@ class CustomerModel extends Equatable {
Map<String, dynamic> toJson() {
return {
if (id != null) 'id': id,
'nome': nome.toLowerCase().trim(),
'telefono': telefono,
'name': name.toLowerCase().trim(),
'phone_number': phoneNumber,
'email': email.toLowerCase().trim(),
'note': note,
if (dataUltimoContatto != null)
'data_ultimo_contatto': dataUltimoContatto!.toIso8601String(),
'non_disturbare': nonDisturbare,
if (lastContactDate != null)
'last_contact_date': lastContactDate!.toIso8601String(),
'do_not_disturb': doNotDisturb,
'company_id': companyId,
'is_active': isActive,
};