add packages

This commit is contained in:
Sai Naw Wun
2020-09-17 06:02:48 +06:30
parent 1ed6f4f00e
commit 33f0c4fd98
34 changed files with 1529 additions and 1205 deletions

View File

@@ -6,6 +6,11 @@ const privilege_collection = "privileges";
const markets_collection = "markets";
const packages_collection = "packages";
const user_requested_status = "requested";
const user_invited_status = "invited";
const pkg_files_path = "/packages";
const ok_doc_id = "ok";
const biz_collection = "bizs";

View File

@@ -10,8 +10,9 @@ class Package {
String phoneNumber;
String currentStatus;
DateTime currentStatusDate;
List<Map<String, dynamic>> allStatus;
List<String> photoUrls;
List<ShipmentStatus> shipmentHistory;
String desc;
String status;
String shipmentNumber;
@@ -39,8 +40,6 @@ class Package {
shipmentNumber + "-" + receiverNumber + " #" + boxNumber;
double get price => rate.toDouble() * weight;
List<ShipmentStatus> shipmentHistory;
Package({
this.id,
this.trackingID,
@@ -66,20 +65,20 @@ class Package {
this.cargoDesc,
this.market,
this.shipmentHistory,
this.allStatus,
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<Map<String, dynamic>> _allStatus = List.from(map['all_status'])
.map((e) => Map<String, dynamic>.from(e))
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 ? [] : map['photo_urls'].cast<List<String>>();
map['photo_urls'] == null ? [] : List.from(map['photo_urls']);
return Package(
id: docID,
@@ -89,13 +88,22 @@ class Package {
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,
allStatus: _allStatus);
shipmentHistory: _shipmentStatus);
}
Map<String, dynamic> toJson() =>
{'id': id, 'tracking_id': trackingID, 'market': market, 'fcs_id': fcsID};
Map<String, dynamic> toJson() => {
'id': id,
'tracking_id': trackingID,
'market': market,
'fcs_id': fcsID,
"desc": desc,
"remark": remark,
"photo_urls": photoUrls
};
}

View File

@@ -94,6 +94,7 @@ class User {
bool hasPackages() {
return hasSysAdmin() ||
hasAdmin() ||
status == userStatusJoined ||
(privileges != null ? privileges.contains('p') : false);
}

View File

@@ -1,6 +1,17 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class ShipmentStatus {
String status;
DateTime date;
bool done;
ShipmentStatus({this.status, this.date, this.done});
factory ShipmentStatus.fromMap(Map<String, dynamic> map) {
var _date = (map['date'] as Timestamp);
return ShipmentStatus(
status: map['status'],
date: _date == null ? null : _date.toDate(),
done: map['done'],
);
}
}