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

78 lines
2.0 KiB
Dart
Raw Normal View History

2020-10-16 10:58:31 +06:30
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/domain/entities/box.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
2020-10-15 03:06:13 +06:30
import 'cargo_type.dart';
2020-06-25 16:19:23 +06:30
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-06-24 16:06:40 +06:30
int handlingFee;
2020-05-29 15:54:26 +06:30
String address;
2020-10-16 10:58:31 +06:30
String currentStatus;
2020-06-30 16:27:56 +06:30
bool isCourier;
2020-07-01 08:12:59 +06:30
int radioIndex;
2020-10-16 10:58:31 +06:30
List<Box> boxes;
2020-05-29 15:54:26 +06:30
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-16 10:58:31 +06:30
this.currentStatus,
this.pickupDate,
2020-07-01 08:12:59 +06:30
this.isCourier = false,
2020-10-16 10:58:31 +06:30
this.radioIndex = 1,
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-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-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'],
currentStatus: map['current_status']);
}
Map<String, dynamic> toMap() {
List _boxes = boxes.map((l) => l.toMap()).toList();
return {
"id": id,
'boxes': _boxes,
'shipment_type': shipmentType,
'pickup_address': pickupAddress.toMap(),
"pickup_date": pickupDate?.toUtc()?.toIso8601String(),
'pickup_time_start': pickupTimeStart,
'pickup_time_end': pickupTimeEnd,
};
2020-05-29 15:54:26 +06:30
}
@override
String toString() {
2020-10-16 10:58:31 +06:30
return 'PickUp{id:$id, userName:$userName,phoneNumber:$phoneNumber,numberOfPackage:$numberOfPackage,weight:$weight,currentStatus:$currentStatus}';
2020-05-29 15:54:26 +06:30
}
}