clean up
This commit is contained in:
125
lib/domain/entities/package.dart
Normal file
125
lib/domain/entities/package.dart
Normal file
@@ -0,0 +1,125 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/vo/shipment_status.dart';
|
||||
|
||||
class Package {
|
||||
String id;
|
||||
String trackingID;
|
||||
String userID;
|
||||
String fcsID;
|
||||
String userName;
|
||||
String phoneNumber;
|
||||
String currentStatus;
|
||||
DateTime currentStatusDate;
|
||||
List<String> photoUrls;
|
||||
List<ShipmentStatus> shipmentHistory;
|
||||
String desc;
|
||||
|
||||
String status;
|
||||
String shipmentNumber;
|
||||
String senderFCSID;
|
||||
String senderName;
|
||||
String receiverFCSID;
|
||||
String receiverName;
|
||||
String receiverAddress;
|
||||
String receiverNumber;
|
||||
String boxNumber;
|
||||
String cargoDesc;
|
||||
String market;
|
||||
|
||||
int rate;
|
||||
int weight;
|
||||
String packageType;
|
||||
String pickUpID;
|
||||
List<String> photos;
|
||||
String remark;
|
||||
DateTime arrivedDate;
|
||||
|
||||
int get amount => rate != null && weight != null ? rate * weight : 0;
|
||||
|
||||
String get packageNumber =>
|
||||
shipmentNumber + "-" + receiverNumber + " #" + boxNumber;
|
||||
double get price => rate.toDouble() * weight;
|
||||
|
||||
Package({
|
||||
this.id,
|
||||
this.trackingID,
|
||||
this.userID,
|
||||
this.userName,
|
||||
this.fcsID,
|
||||
this.phoneNumber,
|
||||
this.shipmentNumber,
|
||||
this.senderFCSID,
|
||||
this.senderName,
|
||||
this.receiverFCSID,
|
||||
this.receiverName,
|
||||
this.receiverNumber,
|
||||
this.receiverAddress,
|
||||
this.boxNumber,
|
||||
this.rate,
|
||||
this.weight,
|
||||
this.packageType,
|
||||
this.pickUpID,
|
||||
this.remark,
|
||||
this.status,
|
||||
this.arrivedDate,
|
||||
this.cargoDesc,
|
||||
this.market,
|
||||
this.shipmentHistory,
|
||||
this.currentStatus,
|
||||
this.currentStatusDate,
|
||||
this.photoUrls,
|
||||
this.desc,
|
||||
});
|
||||
|
||||
factory Package.fromMap(Map<String, dynamic> map, String docID) {
|
||||
var _currentStatusDate = (map['current_status_date'] as Timestamp);
|
||||
|
||||
List<ShipmentStatus> _shipmentStatus = List.from(map['all_status'])
|
||||
.map((e) => ShipmentStatus.fromMap(Map<String, dynamic>.from(e)))
|
||||
.toList();
|
||||
List<String> _photoUrls =
|
||||
map['photo_urls'] == null ? [] : List.from(map['photo_urls']);
|
||||
|
||||
return Package(
|
||||
id: docID,
|
||||
userID: map['user_id'],
|
||||
fcsID: map['fcs_id'],
|
||||
trackingID: map['tracking_id'],
|
||||
market: map['market'],
|
||||
userName: map['user_name'],
|
||||
phoneNumber: map['phone_number'],
|
||||
remark: map['remark'],
|
||||
desc: map['desc'],
|
||||
currentStatus: map['current_status'],
|
||||
currentStatusDate:
|
||||
_currentStatusDate != null ? _currentStatusDate.toDate() : null,
|
||||
photoUrls: _photoUrls,
|
||||
shipmentHistory: _shipmentStatus);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'tracking_id': trackingID,
|
||||
'market': market,
|
||||
'fcs_id': fcsID,
|
||||
"desc": desc,
|
||||
"remark": remark,
|
||||
"photo_urls": photoUrls
|
||||
};
|
||||
|
||||
factory Package.fromJson(Map<String, dynamic> json) {
|
||||
return Package(
|
||||
id: json['id'],
|
||||
trackingID: json['tracking_id'],
|
||||
market: json['market'],
|
||||
userName: json['user_name'],
|
||||
phoneNumber: json['phone_number'],
|
||||
currentStatus: json['current_status'],
|
||||
currentStatusDate: DateTime.parse(json['current_status_date']));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Package{id: $id, currentStatus: $currentStatus, market:$market, trackingID: $trackingID,}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user