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

135 lines
4.1 KiB
Dart
Raw Normal View History

2020-10-16 10:58:31 +06:30
import 'package:cloud_firestore/cloud_firestore.dart';
2024-09-22 16:49:59 +06:30
import 'package:fcs/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 {
2021-09-10 14:27:38 +06:30
String? id;
String? shipmentNumber;
String? shipmentType;
DeliveryAddress? pickupAddress;
DateTime? pickupDate;
String? pickupTimeStart;
String? pickupTimeEnd;
2020-10-16 10:58:31 +06:30
2021-09-10 14:27:38 +06:30
String? userName;
String? userID;
String? phoneNumber;
int numberOfPackage = 0;
int weight = 0;
double handlingFee = 0;
double paidHandlingFee = 0;
String? address;
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
2021-09-10 14:27:38 +06:30
String? pickupUserID;
String? pickupUserName;
String? pickupUserPhoneNumber;
2020-10-19 05:13:49 +06:30
2021-09-10 14:27:38 +06:30
String? fcsShipmentID;
String? fcsShipmentNumber;
String? shipmentLabelUrl;
bool isSelected = false;
2020-10-19 05:13:49 +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-10-22 04:14:53 +06:30
this.userID,
2020-05-29 15:54:26 +06:30
this.userName,
this.phoneNumber,
2020-10-16 10:58:31 +06:30
this.pickupTimeStart,
this.pickupTimeEnd,
2021-09-10 14:27:38 +06:30
this.numberOfPackage = 0,
this.weight = 0,
this.handlingFee = 0,
this.paidHandlingFee = 0,
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,
2021-09-13 09:51:55 +06:30
this.pickupAddress,
2020-10-19 05:13:49 +06:30
this.pickupUserID,
this.pickupUserName,
this.pickupUserPhoneNumber,
this.fcsShipmentID,
this.fcsShipmentNumber,
this.shipmentLabelUrl,
2021-09-10 14:27:38 +06:30
this.boxes = const []});
2020-05-31 15:00:11 +06:30
2021-09-10 14:27:38 +06:30
// int get last => DateTime.now().difference(pickupDate).inDays;
2020-05-29 15:54:26 +06:30
2021-09-10 14:27:38 +06:30
double get totalWeight => boxes.fold(0, (p, e) => p + e.actualWeight);
int get totalCount => boxes.length;
2020-10-19 05:13:49 +06:30
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) {
2024-01-23 16:28:08 +06:30
var pd =
map['pickup_date'] == null ? null : (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-22 04:14:53 +06:30
userID: map['user_id'],
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'],
2020-10-24 06:14:07 +06:30
paidHandlingFee: map['paid_handling_fee'],
2020-10-19 05:13:49 +06:30
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() {
2021-09-10 14:27:38 +06:30
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-22 04:14:53 +06:30
'user_id': userID,
2020-10-18 02:38:46 +06:30
'cartons': _boxes,
2020-10-16 10:58:31 +06:30
'shipment_type': shipmentType,
2021-09-10 14:27:38 +06:30
'pickup_address': pickupAddress?.toMap(),
"pickup_date": pickupDate?.toUtc().toIso8601String(),
2020-10-16 10:58:31 +06:30
'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
}
2020-10-24 06:14:07 +06:30
@override
bool operator ==(Object other) => other is Shipment && other.id == id;
@override
int get hashCode => id.hashCode;
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
}
}