Files
fcs/lib/domain/entities/fcs_shipment.dart

89 lines
2.7 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;
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,
});
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 != null ? _cutoffDate.toDate() : null,
etaDate: _arrivalDate != null ? _arrivalDate.toDate() : null,
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']);
}
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 != this.shipmentNumber ||
fcsShipment.cutoffDate != this.cutoffDate ||
fcsShipment.etaDate != this.etaDate ||
fcsShipment.shipmentTypeId != this.shipmentTypeId ||
fcsShipment.consigneeId != this.consigneeId ||
fcsShipment.loadingPortId != this.loadingPortId ||
fcsShipment.destinationPortId != this.destinationPortId;
}
@override
bool operator ==(Object other) => other is FcsShipment && other.id == id;
@override
int get hashCode => id.hashCode;
}