Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -10,6 +10,7 @@ const delivery_address_collection = "delivery_addresses";
|
||||
const cargo_types_collection = "cargo_types";
|
||||
const custom_duties_collection = "custom_duties";
|
||||
const discounts_by_weights_collection = "discounts_by_weight";
|
||||
const shipments_collection = "shipments";
|
||||
|
||||
// docs
|
||||
const setting_doc_id = "setting";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/domain/vo/shipment_status.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
|
||||
@@ -17,9 +19,9 @@ class Box {
|
||||
String status;
|
||||
String cargoDesc;
|
||||
String desc;
|
||||
int width;
|
||||
int height;
|
||||
int length;
|
||||
double width;
|
||||
double height;
|
||||
double length;
|
||||
int shipmentWeight;
|
||||
bool isChecked;
|
||||
String cartonType;
|
||||
@@ -38,7 +40,7 @@ class Box {
|
||||
|
||||
List<CargoType> cargoTypes;
|
||||
|
||||
DeliveryAddress shippingAddress;
|
||||
DeliveryAddress deliveryAddress;
|
||||
|
||||
int get amount => rate != null && weight != null ? rate * weight : 0;
|
||||
|
||||
@@ -46,6 +48,9 @@ class Box {
|
||||
shipmentNumber + "-" + receiverNumber + " #" + boxNumber;
|
||||
double get price => rate.toDouble() * weight;
|
||||
|
||||
double get actualWeight =>
|
||||
cargoTypes == null ? 0 : cargoTypes.fold(0, (p, e) => e.weight + p);
|
||||
|
||||
double getShipmentWeight(double volumetricRatio) {
|
||||
if (length == null ||
|
||||
length <= 0 ||
|
||||
@@ -59,6 +64,30 @@ class Box {
|
||||
return (length * width * height) / volumetricRatio;
|
||||
}
|
||||
|
||||
/// calAmount returns total amount
|
||||
double calAmount(Rate rate) {
|
||||
// get shipment weight
|
||||
double volume = (length ?? 0) * (width ?? 0) * (height ?? 0);
|
||||
double sw = volume / rate.volumetricRatio ?? 0;
|
||||
|
||||
// get actual weight
|
||||
double aw = cargoTypes.fold(0.0, (p, c) => p + c.weight);
|
||||
if (aw == 0 || sw == 0) return 0;
|
||||
|
||||
DiscountByWeight discountByWeight =
|
||||
rate.getDiscountByWeight(sw > aw ? sw : aw);
|
||||
|
||||
double total = 0;
|
||||
cargoTypes.forEach((e) {
|
||||
double cargoWeight = aw > sw ? e.weight : e.weight / aw * sw;
|
||||
double r =
|
||||
e.rate - (discountByWeight != null ? discountByWeight.discount : 0);
|
||||
double amount = cargoWeight * r;
|
||||
total += amount;
|
||||
});
|
||||
return total;
|
||||
}
|
||||
|
||||
List<ShipmentStatus> shipmentHistory;
|
||||
|
||||
Box(
|
||||
@@ -91,5 +120,17 @@ class Box {
|
||||
this.shipmentHistory,
|
||||
this.packages,
|
||||
this.cargoTypes,
|
||||
this.shippingAddress});
|
||||
this.deliveryAddress});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
||||
return {
|
||||
"id": id,
|
||||
'cargo_types': _cargoTypes,
|
||||
'length': length,
|
||||
'width': width,
|
||||
'height': height,
|
||||
'delivery_address': deliveryAddress.toMap(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ class CargoType {
|
||||
String id;
|
||||
String name;
|
||||
double rate;
|
||||
double weight;
|
||||
|
||||
int shipmentWeight;
|
||||
double amount;
|
||||
|
||||
factory CargoType.fromMap(Map<String, dynamic> map, String id) {
|
||||
return CargoType(
|
||||
@@ -10,7 +14,6 @@ class CargoType {
|
||||
rate: (map['rate'] ?? 0).toDouble(),
|
||||
);
|
||||
}
|
||||
int weight;
|
||||
CargoType({this.id, this.name, this.rate, this.weight});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
@@ -18,6 +21,7 @@ class CargoType {
|
||||
"id": id,
|
||||
'name': name,
|
||||
'rate': rate,
|
||||
'weight': weight,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,4 +30,9 @@ class CargoType {
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@ class Rate {
|
||||
List<CustomDuty> customDuties;
|
||||
List<DiscountByWeight> discountByWeights;
|
||||
|
||||
DiscountByWeight getDiscountByWeight(double weight) {
|
||||
discountByWeights.sort((d1, d2) => d2.weight.compareTo(d1.weight));
|
||||
return discountByWeights.firstWhere((e) => e.weight < weight,
|
||||
orElse: () => null);
|
||||
}
|
||||
|
||||
CargoType get defaultCargoType => cargoTypes == null
|
||||
? null
|
||||
: cargoTypes.firstWhere((e) => e.name == "General");
|
||||
|
||||
@@ -1,54 +1,77 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
|
||||
import 'cargo_type.dart';
|
||||
|
||||
class Shipment {
|
||||
String id;
|
||||
String shipmentNumber;
|
||||
String shipmentType;
|
||||
DeliveryAddress pickupAddress;
|
||||
DateTime pickupDate;
|
||||
String pickupTimeStart;
|
||||
String pickupTimeEnd;
|
||||
|
||||
String userName;
|
||||
String phoneNumber;
|
||||
String fromTime;
|
||||
String toTime;
|
||||
int numberOfPackage;
|
||||
int weight;
|
||||
int handlingFee;
|
||||
String address;
|
||||
String status;
|
||||
DateTime date;
|
||||
List<CargoType> cargoTypes;
|
||||
String currentStatus;
|
||||
bool isCourier;
|
||||
int radioIndex;
|
||||
List<Box> boxes;
|
||||
|
||||
Shipment(
|
||||
{this.id,
|
||||
this.shipmentNumber,
|
||||
this.shipmentType,
|
||||
this.userName,
|
||||
this.phoneNumber,
|
||||
this.fromTime,
|
||||
this.toTime,
|
||||
this.pickupTimeStart,
|
||||
this.pickupTimeEnd,
|
||||
this.numberOfPackage,
|
||||
this.weight,
|
||||
this.handlingFee,
|
||||
this.address,
|
||||
this.status,
|
||||
this.date,
|
||||
this.cargoTypes,
|
||||
this.currentStatus,
|
||||
this.pickupDate,
|
||||
this.isCourier = false,
|
||||
this.radioIndex = 1});
|
||||
this.radioIndex = 1,
|
||||
this.boxes});
|
||||
|
||||
int get last => DateTime.now().difference(date).inDays;
|
||||
int get last => DateTime.now().difference(pickupDate).inDays;
|
||||
|
||||
factory Shipment.fromMap(Map<String, dynamic> map, String id) {
|
||||
var pd = (map['pickup_date'] as Timestamp);
|
||||
return Shipment(
|
||||
id: id,
|
||||
userName: map['user_name'],
|
||||
shipmentNumber: map['shipment_number'],
|
||||
phoneNumber: map['phone_number'],
|
||||
fromTime: map['from_time'],
|
||||
toTime: map['to_time'],
|
||||
numberOfPackage: map['number_of_package'],
|
||||
weight: map['weight'],
|
||||
address: map['address'],
|
||||
status: map['status']);
|
||||
pickupDate: pd == null ? null : pd.toDate(),
|
||||
pickupTimeStart: map['pickup_time_start'],
|
||||
pickupTimeEnd: map['pickup_time_end'],
|
||||
currentStatus: map['current_status']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
List _boxes = boxes.map((l) => l.toMap()).toList();
|
||||
return {
|
||||
"id": id,
|
||||
'boxes': _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,fromTime:$fromTime,toTime:$toTime,numberOfPackage:$numberOfPackage,weight:$weight,status:$status}';
|
||||
return 'PickUp{id:$id, userName:$userName,phoneNumber:$phoneNumber,numberOfPackage:$numberOfPackage,weight:$weight,currentStatus:$currentStatus}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user