82 lines
2.2 KiB
Dart
82 lines
2.2 KiB
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:fcs/domain/entities/carton.dart';
|
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
|
|
|
class Shipment {
|
|
String id;
|
|
String shipmentNumber;
|
|
String shipmentType;
|
|
DeliveryAddress pickupAddress;
|
|
DateTime pickupDate;
|
|
String pickupTimeStart;
|
|
String pickupTimeEnd;
|
|
|
|
String userName;
|
|
String phoneNumber;
|
|
int numberOfPackage;
|
|
int weight;
|
|
int handlingFee;
|
|
String address;
|
|
String currentStatus;
|
|
bool isCourier;
|
|
int radioIndex;
|
|
List<Carton> boxes;
|
|
|
|
Shipment(
|
|
{this.id,
|
|
this.shipmentNumber,
|
|
this.shipmentType,
|
|
this.userName,
|
|
this.phoneNumber,
|
|
this.pickupTimeStart,
|
|
this.pickupTimeEnd,
|
|
this.numberOfPackage,
|
|
this.weight,
|
|
this.handlingFee,
|
|
this.address,
|
|
this.currentStatus,
|
|
this.pickupDate,
|
|
this.isCourier = false,
|
|
this.radioIndex = 1,
|
|
this.pickupAddress,
|
|
this.boxes});
|
|
|
|
int get last => DateTime.now().difference(pickupDate).inDays;
|
|
|
|
factory Shipment.fromMap(Map<String, dynamic> map, String id) {
|
|
var pd = (map['pickup_date'] as Timestamp);
|
|
var pa = map['pickup_address'];
|
|
var _pa = pa != null ? DeliveryAddress.fromMap(pa, pa["id"]) : null;
|
|
return Shipment(
|
|
id: id,
|
|
userName: map['user_name'],
|
|
shipmentNumber: map['shipment_number'],
|
|
phoneNumber: map['phone_number'],
|
|
pickupDate: pd == null ? null : pd.toDate(),
|
|
pickupTimeStart: map['pickup_time_start'],
|
|
pickupTimeEnd: map['pickup_time_end'],
|
|
currentStatus: map['current_status'],
|
|
shipmentType: map['shipment_type'],
|
|
pickupAddress: _pa);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
List _boxes = boxes.map((l) => l.toMap()).toList();
|
|
|
|
return {
|
|
"id": id,
|
|
'cartons': _boxes,
|
|
'shipment_type': shipmentType,
|
|
'pickup_address': pickupAddress.toMap(),
|
|
"pickup_date": pickupDate?.toUtc()?.toIso8601String(),
|
|
'pickup_time_start': pickupTimeStart,
|
|
'pickup_time_end': pickupTimeEnd,
|
|
};
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'PickUp{id:$id, userName:$userName,phoneNumber:$phoneNumber,numberOfPackage:$numberOfPackage,weight:$weight,currentStatus:$currentStatus}';
|
|
}
|
|
}
|