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

82 lines
2.2 KiB
Dart
Raw Normal View History

2020-10-16 10:58:31 +06:30
import 'package:cloud_firestore/cloud_firestore.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-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-18 02:38:46 +06:30
List<Carton> 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,
2020-10-18 02:38:46 +06:30
this.pickupAddress,
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-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-18 02:38:46 +06:30
currentStatus: map['current_status'],
shipmentType: map['shipment_type'],
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-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
}
}