2020-10-16 10:58:31 +06:30
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
2020-10-19 05:13:49 +06:30
|
|
|
import 'package:fcs/domain/constants.dart';
|
2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/domain/entities/carton.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
|
|
|
|
|
2020-10-07 14:42:07 +06:30
|
|
|
class Shipment {
|
2020-05-29 15:54:26 +06:30
|
|
|
String id;
|
2020-10-16 10:58:31 +06:30
|
|
|
String shipmentNumber;
|
|
|
|
|
String shipmentType;
|
|
|
|
|
DeliveryAddress pickupAddress;
|
|
|
|
|
DateTime pickupDate;
|
|
|
|
|
String pickupTimeStart;
|
|
|
|
|
String pickupTimeEnd;
|
|
|
|
|
|
2020-05-29 15:54:26 +06:30
|
|
|
String userName;
|
|
|
|
|
String phoneNumber;
|
|
|
|
|
int numberOfPackage;
|
|
|
|
|
int weight;
|
2020-10-19 05:13:49 +06:30
|
|
|
double handlingFee;
|
2020-05-29 15:54:26 +06:30
|
|
|
String address;
|
2020-10-19 05:13:49 +06:30
|
|
|
String status;
|
2020-06-30 16:27:56 +06:30
|
|
|
bool isCourier;
|
2020-07-01 08:12:59 +06:30
|
|
|
int radioIndex;
|
2020-10-18 02:38:46 +06:30
|
|
|
List<Carton> boxes;
|
2020-05-29 15:54:26 +06:30
|
|
|
|
2020-10-19 05:13:49 +06:30
|
|
|
String pickupUserID;
|
|
|
|
|
String pickupUserName;
|
|
|
|
|
String pickupUserPhoneNumber;
|
|
|
|
|
|
|
|
|
|
String fcsShipmentID;
|
|
|
|
|
String fcsShipmentNumber;
|
|
|
|
|
String shipmentLabelUrl;
|
|
|
|
|
|
2020-10-07 14:42:07 +06:30
|
|
|
Shipment(
|
2020-05-29 15:54:26 +06:30
|
|
|
{this.id,
|
2020-10-16 10:58:31 +06:30
|
|
|
this.shipmentNumber,
|
|
|
|
|
this.shipmentType,
|
2020-05-29 15:54:26 +06:30
|
|
|
this.userName,
|
|
|
|
|
this.phoneNumber,
|
2020-10-16 10:58:31 +06:30
|
|
|
this.pickupTimeStart,
|
|
|
|
|
this.pickupTimeEnd,
|
2020-05-29 15:54:26 +06:30
|
|
|
this.numberOfPackage,
|
|
|
|
|
this.weight,
|
2020-06-24 16:06:40 +06:30
|
|
|
this.handlingFee,
|
2020-05-29 15:54:26 +06:30
|
|
|
this.address,
|
2020-10-19 05:13:49 +06:30
|
|
|
this.status,
|
2020-10-16 10:58:31 +06:30
|
|
|
this.pickupDate,
|
2020-07-01 08:12:59 +06:30
|
|
|
this.isCourier = false,
|
2020-10-16 10:58:31 +06:30
|
|
|
this.radioIndex = 1,
|
2020-10-18 02:38:46 +06:30
|
|
|
this.pickupAddress,
|
2020-10-19 05:13:49 +06:30
|
|
|
this.pickupUserID,
|
|
|
|
|
this.pickupUserName,
|
|
|
|
|
this.pickupUserPhoneNumber,
|
|
|
|
|
this.fcsShipmentID,
|
|
|
|
|
this.fcsShipmentNumber,
|
|
|
|
|
this.shipmentLabelUrl,
|
2020-10-16 10:58:31 +06:30
|
|
|
this.boxes});
|
2020-05-31 15:00:11 +06:30
|
|
|
|
2020-10-16 10:58:31 +06:30
|
|
|
int get last => DateTime.now().difference(pickupDate).inDays;
|
2020-05-29 15:54:26 +06:30
|
|
|
|
2020-10-19 05:13:49 +06:30
|
|
|
double get totalWeight => boxes?.fold(0, (p, e) => p + e.actualWeight);
|
|
|
|
|
int get totalCount => boxes?.length;
|
|
|
|
|
|
|
|
|
|
bool get isPending => status == shipment_pending_status;
|
|
|
|
|
bool get isAssigned => status == shipment_assigned_status;
|
|
|
|
|
bool get isPickuped => status == shipment_pickuped_status;
|
|
|
|
|
bool get isPacked => status == shipment_packed_status;
|
|
|
|
|
bool get isConfirmed => status == shipment_confirmed_status;
|
|
|
|
|
bool get isReceived => status == shipment_received_status;
|
|
|
|
|
|
2020-10-07 14:42:07 +06:30
|
|
|
factory Shipment.fromMap(Map<String, dynamic> map, String id) {
|
2020-10-16 10:58:31 +06:30
|
|
|
var pd = (map['pickup_date'] as Timestamp);
|
2020-10-18 02:38:46 +06:30
|
|
|
var pa = map['pickup_address'];
|
|
|
|
|
var _pa = pa != null ? DeliveryAddress.fromMap(pa, pa["id"]) : null;
|
2020-10-07 14:42:07 +06:30
|
|
|
return Shipment(
|
2020-05-29 15:54:26 +06:30
|
|
|
id: id,
|
|
|
|
|
userName: map['user_name'],
|
2020-10-16 10:58:31 +06:30
|
|
|
shipmentNumber: map['shipment_number'],
|
2020-05-29 15:54:26 +06:30
|
|
|
phoneNumber: map['phone_number'],
|
2020-10-16 10:58:31 +06:30
|
|
|
pickupDate: pd == null ? null : pd.toDate(),
|
|
|
|
|
pickupTimeStart: map['pickup_time_start'],
|
|
|
|
|
pickupTimeEnd: map['pickup_time_end'],
|
2020-10-19 05:13:49 +06:30
|
|
|
status: map['status'],
|
2020-10-18 02:38:46 +06:30
|
|
|
shipmentType: map['shipment_type'],
|
2020-10-19 05:13:49 +06:30
|
|
|
pickupUserID: map['pickup_user_id'],
|
|
|
|
|
pickupUserName: map['pickup_user_name'],
|
|
|
|
|
pickupUserPhoneNumber: map['pickup_user_phone_number'],
|
|
|
|
|
handlingFee: map['handling_fee'],
|
|
|
|
|
fcsShipmentID: map['fcs_shipment_id'],
|
|
|
|
|
fcsShipmentNumber: map['fcs_shipment_number'],
|
|
|
|
|
shipmentLabelUrl: map['shipment_label_url'],
|
2020-10-18 02:38:46 +06:30
|
|
|
pickupAddress: _pa);
|
2020-10-16 10:58:31 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
|
List _boxes = boxes.map((l) => l.toMap()).toList();
|
2020-10-18 02:38:46 +06:30
|
|
|
|
2020-10-16 10:58:31 +06:30
|
|
|
return {
|
|
|
|
|
"id": id,
|
2020-10-18 02:38:46 +06:30
|
|
|
'cartons': _boxes,
|
2020-10-16 10:58:31 +06:30
|
|
|
'shipment_type': shipmentType,
|
|
|
|
|
'pickup_address': pickupAddress.toMap(),
|
|
|
|
|
"pickup_date": pickupDate?.toUtc()?.toIso8601String(),
|
|
|
|
|
'pickup_time_start': pickupTimeStart,
|
|
|
|
|
'pickup_time_end': pickupTimeEnd,
|
2020-10-19 05:13:49 +06:30
|
|
|
'pickup_user_id': pickupUserID,
|
|
|
|
|
'pickup_user_name': pickupUserName,
|
|
|
|
|
'pickup_user_phone_number': pickupUserPhoneNumber,
|
|
|
|
|
'handling_fee': handlingFee,
|
|
|
|
|
'fcs_shipment_id': fcsShipmentID,
|
|
|
|
|
'shipment_label_url': shipmentLabelUrl
|
2020-10-16 10:58:31 +06:30
|
|
|
};
|
2020-05-29 15:54:26 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toString() {
|
2020-10-19 05:13:49 +06:30
|
|
|
return 'PickUp{id:$id, userName:$userName,phoneNumber:$phoneNumber,numberOfPackage:$numberOfPackage,weight:$weight,status:$status}';
|
2020-05-29 15:54:26 +06:30
|
|
|
}
|
|
|
|
|
}
|