operation details
This commit is contained in:
1 parent
9cd0b98a16
commit
c41fcd37b3
3 files changed
+154
-1
No files matched your search
@@ -10,6 +10,7 @@ class Tables {
|
||||
static const String notes = 'notes';
|
||||
static const String noteCollaborators = 'note_collaborators';
|
||||
static const String operations = 'operations';
|
||||
static const String operationDetails = 'operation_details';
|
||||
static const String providerLocations = 'provider_locations';
|
||||
static const String providers = 'providers';
|
||||
static const String providersInStores = 'providers_in_stores';
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/enums_and_consts/consts.dart';
|
||||
import 'package:flux/features/master_data/products/models/model_model.dart';
|
||||
import 'package:flux/features/master_data/providers/models/provider_model.dart';
|
||||
|
||||
class OperationDetailModel extends Equatable {
|
||||
final String? id;
|
||||
final DateTime? createdAt;
|
||||
final String operationId;
|
||||
final String? type;
|
||||
final String? providerId;
|
||||
final String? modelId;
|
||||
final String? description;
|
||||
final DateTime? expirationDate;
|
||||
final String companyId;
|
||||
final String? lastCampaignId;
|
||||
final String? subType;
|
||||
|
||||
// Aggiunte comode per relazioni
|
||||
final ProviderModel? provider;
|
||||
final ModelModel? model;
|
||||
|
||||
const OperationDetailModel({
|
||||
this.id,
|
||||
this.createdAt,
|
||||
this.operationId = '',
|
||||
this.type,
|
||||
this.providerId,
|
||||
this.modelId,
|
||||
this.description,
|
||||
this.expirationDate,
|
||||
this.companyId = '',
|
||||
this.lastCampaignId,
|
||||
this.subType,
|
||||
this.provider,
|
||||
this.model,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
createdAt,
|
||||
operationId,
|
||||
type,
|
||||
providerId,
|
||||
modelId,
|
||||
description,
|
||||
expirationDate,
|
||||
companyId,
|
||||
lastCampaignId,
|
||||
subType,
|
||||
provider,
|
||||
model,
|
||||
];
|
||||
|
||||
OperationDetailModel copyWith({
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
String? operationId,
|
||||
String? type,
|
||||
String? providerId,
|
||||
String? modelId,
|
||||
String? description,
|
||||
DateTime? expirationDate,
|
||||
String? companyId,
|
||||
String? lastCampaignId,
|
||||
String? subType,
|
||||
ProviderModel? Function()? provider,
|
||||
ModelModel? Function()? model,
|
||||
}) => OperationDetailModel(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
operationId: operationId ?? this.operationId,
|
||||
type: type ?? this.type,
|
||||
providerId: providerId ?? this.providerId,
|
||||
modelId: modelId ?? this.modelId,
|
||||
description: description ?? this.description,
|
||||
expirationDate: expirationDate ?? this.expirationDate,
|
||||
companyId: companyId ?? this.companyId,
|
||||
lastCampaignId: lastCampaignId ?? this.lastCampaignId,
|
||||
subType: subType ?? this.subType,
|
||||
provider: provider != null ? provider() : this.provider,
|
||||
model: model != null ? model() : this.model,
|
||||
);
|
||||
|
||||
factory OperationDetailModel.empty() {
|
||||
return OperationDetailModel();
|
||||
}
|
||||
|
||||
factory OperationDetailModel.fromMap(Map<String, dynamic> map) {
|
||||
return OperationDetailModel(
|
||||
id: map['id'] as String?,
|
||||
createdAt: map['created_at'] != null
|
||||
? DateTime.parse(map['created_at'])
|
||||
: null,
|
||||
operationId: map['operation_id'] as String? ?? '',
|
||||
type: map['type'] as String?,
|
||||
providerId: map['provider_id'] as String?,
|
||||
modelId: map['model_id'] as String?,
|
||||
description: map['description'] as String?,
|
||||
expirationDate: map['expiration_date'] != null
|
||||
? DateTime.parse(map['expiration_date'])
|
||||
: null,
|
||||
companyId: map['company_id'] as String? ?? '',
|
||||
lastCampaignId: map['last_campaign_id'] as String?,
|
||||
subType: map['sub_type'] as String?,
|
||||
provider: (map[Tables.providers] != null)
|
||||
? ProviderModel.fromMap(map[Tables.providers] as Map<String, dynamic>)
|
||||
: null,
|
||||
model: (map[Tables.models] != null)
|
||||
? ModelModel.fromJson(map[Tables.models] as Map<String, dynamic>)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'operation_id': operationId,
|
||||
'type': type,
|
||||
'provider_id': provider?.id ?? providerId,
|
||||
'model_id': model?.id ?? modelId,
|
||||
'description': description,
|
||||
if (expirationDate != null)
|
||||
'expiration_date': expirationDate!.toIso8601String(),
|
||||
'company_id': companyId,
|
||||
if (lastCampaignId != null) 'last_campaign_id': lastCampaignId,
|
||||
'sub_type': subType,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ 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/master_data/providers/models/provider_model.dart';
|
||||
import 'package:flux/features/operations/models/operation_detail_model.dart';
|
||||
|
||||
enum OperationStatus {
|
||||
success('success', 'OK'),
|
||||
@@ -54,6 +55,9 @@ class OperationModel extends Equatable {
|
||||
// ALLEGATI (Aggiunto)
|
||||
final List<AttachmentModel> attachments;
|
||||
|
||||
// DETTAGLI OPERAZIONE (Aggiunto)
|
||||
final List<OperationDetailModel> details;
|
||||
|
||||
const OperationModel({
|
||||
this.id,
|
||||
this.createdAt,
|
||||
@@ -78,6 +82,7 @@ class OperationModel extends Equatable {
|
||||
this.customer,
|
||||
this.reference = '',
|
||||
this.attachments = const [],
|
||||
this.details = const [],
|
||||
this.isBusiness = false,
|
||||
this.provider,
|
||||
});
|
||||
@@ -108,6 +113,7 @@ class OperationModel extends Equatable {
|
||||
CustomerModel? customer,
|
||||
String? reference,
|
||||
List<AttachmentModel>? attachments,
|
||||
List<OperationDetailModel>? details,
|
||||
bool? isBusiness,
|
||||
}) => OperationModel(
|
||||
id: id ?? this.id,
|
||||
@@ -136,6 +142,7 @@ class OperationModel extends Equatable {
|
||||
customer: customer ?? this.customer,
|
||||
reference: reference ?? this.reference,
|
||||
attachments: attachments ?? this.attachments,
|
||||
details: details ?? this.details,
|
||||
isBusiness: isBusiness ?? this.isBusiness,
|
||||
);
|
||||
|
||||
@@ -165,11 +172,17 @@ class OperationModel extends Equatable {
|
||||
customer,
|
||||
reference,
|
||||
attachments,
|
||||
details,
|
||||
isBusiness,
|
||||
];
|
||||
|
||||
factory OperationModel.empty() {
|
||||
return OperationModel(id: null, createdAt: null, companyId: '');
|
||||
return OperationModel(
|
||||
id: null,
|
||||
createdAt: null,
|
||||
companyId: '',
|
||||
details: const [],
|
||||
);
|
||||
}
|
||||
|
||||
factory OperationModel.fromMap(Map<String, dynamic> map) {
|
||||
@@ -226,6 +239,14 @@ class OperationModel extends Equatable {
|
||||
.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,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user