import 'package:cloud_firestore/cloud_firestore.dart'; import '../constants.dart'; class FcsShipment { String? id; String? shipmentNumber; DateTime? cutoffDate; String? shipType; DateTime? arrivalDate; DateTime? departureDate; String? consignee; String? port; String? destination; String? status; String? reportName; FcsShipment({ this.id, this.shipmentNumber, this.cutoffDate, this.shipType, this.status, this.arrivalDate, this.departureDate, this.consignee, this.port, this.destination, this.reportName, }); factory FcsShipment.fromMap(Map map, String docID) { var _cutoffDate = map['cutoff_date'] == null ? null : (map['cutoff_date'] as Timestamp); var _arrivalDate = map['arrival_date'] == null ? null : (map['arrival_date'] as Timestamp); var _departureDate = map['departure_date'] == null ? null : (map['departure_date'] as Timestamp); return FcsShipment( id: docID, cutoffDate: _cutoffDate != null ? _cutoffDate.toDate() : null, arrivalDate: _arrivalDate != null ? _arrivalDate.toDate() : null, departureDate: _departureDate != null ? _departureDate.toDate() : null, shipmentNumber: map['shipment_number'], shipType: map['shipment_type'], status: map['status'], consignee: map['consignee'], port: map['port'], destination: map['destination'], ); } Map toMap() { return { "id": id, 'shipment_number': shipmentNumber, 'cutoff_date': cutoffDate?.toUtc().toIso8601String(), 'shipment_type': shipType, 'arrival_date': arrivalDate?.toUtc().toIso8601String(), 'departure_date': departureDate?.toUtc().toIso8601String(), 'consignee': consignee, 'port': port, 'destination': destination, 'status': status, 'report_name': reportName, }; } bool isConfirmed() { return status == fcs_shipment_confirmed_status; } bool isChangedForEdit(FcsShipment fcsShipment) { return fcsShipment.shipmentNumber != this.shipmentNumber || fcsShipment.cutoffDate != this.cutoffDate || fcsShipment.arrivalDate != this.arrivalDate || fcsShipment.shipType != this.shipType || fcsShipment.consignee != this.consignee || fcsShipment.port != this.port || fcsShipment.destination != this.destination; } }