Files
fcs/lib/domain/entities/fcs_shipment.dart
2025-02-17 20:13:30 +06:30

94 lines
2.8 KiB
Dart

import 'package:cloud_firestore/cloud_firestore.dart';
class FcsShipment {
String? id;
String? shipmentNumber;
DateTime? cutoffDate;
DateTime? etaDate;
String? shipmentTypeId;
String? shipmentTypeName;
DateTime? departureDate;
String? consigneeId;
String? consigneeName;
String? loadingPortId;
String? loadingPortName;
String? destinationPortId;
String? destinationPortName;
String? status;
String? reportName;
int packageCount;
int cartonCount;
FcsShipment(
{this.id,
this.shipmentNumber,
this.cutoffDate,
this.shipmentTypeId,
this.shipmentTypeName,
this.status,
this.etaDate,
this.departureDate,
this.consigneeId,
this.consigneeName,
this.loadingPortId,
this.loadingPortName,
this.destinationPortId,
this.destinationPortName,
this.reportName,
this.packageCount = 0,
this.cartonCount = 0});
factory FcsShipment.fromMap(Map<String, dynamic> map, String docID) {
var cutoffDate =
map['cutoff_date'] == null ? null : (map['cutoff_date'] as Timestamp);
var arrivalDate =
map['eta_date'] == null ? null : (map['eta_date'] as Timestamp);
return FcsShipment(
id: docID,
cutoffDate: cutoffDate?.toDate(),
etaDate: arrivalDate?.toDate(),
shipmentNumber: map['shipment_number'],
shipmentTypeId: map['shipment_type_id'] ?? "",
shipmentTypeName: map['shipment_type_name'],
status: map['status'],
consigneeId: map['shipment_consignee_id'],
consigneeName: map['shipment_consignee_name'],
loadingPortId: map['loading_port_id'],
loadingPortName: map['loading_port_name'],
destinationPortId: map['destination_port_id'],
destinationPortName: map['destination_port_name'],
packageCount: map['package_count'] ?? 0,
cartonCount: map['carton_count'] ?? 0);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'shipment_number': shipmentNumber,
'cutoff_date': cutoffDate?.toUtc().toIso8601String(),
'eta_date': etaDate?.toUtc().toIso8601String(),
'shipment_type_id': shipmentTypeId,
'shipment_consignee_id': consigneeId,
'loading_port_id': loadingPortId,
'destination_port_id': destinationPortId
};
}
bool isChangedForEdit(FcsShipment fcsShipment) {
return fcsShipment.shipmentNumber != shipmentNumber ||
fcsShipment.cutoffDate != cutoffDate ||
fcsShipment.etaDate != etaDate ||
fcsShipment.shipmentTypeId != shipmentTypeId ||
fcsShipment.consigneeId != consigneeId ||
fcsShipment.loadingPortId != loadingPortId ||
fcsShipment.destinationPortId != destinationPortId;
}
@override
bool operator ==(Object other) => other is FcsShipment && other.id == id;
@override
int get hashCode => id.hashCode;
}