add paginator
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user