fix rates

This commit is contained in:
2021-01-04 17:19:01 +06:30
parent 3fdcb851ed
commit ee586e8f41
10 changed files with 103 additions and 63 deletions

View File

@@ -62,7 +62,7 @@ class Carton {
double get actualWeight =>
cargoTypes == null ? 0 : cargoTypes.fold(0, (p, e) => e.weight + p);
double getShipmentWeight(double volumetricRatio) {
int getShipmentWeight(double volumetricRatio) {
if (length == null ||
length <= 0 ||
width == null ||
@@ -71,8 +71,8 @@ class Carton {
height <= 0 ||
volumetricRatio == null ||
volumetricRatio <= 0) return 0;
return (length * width * height) / volumetricRatio;
return ((length * width * height) / volumetricRatio).round();
}
/// getCargoTypeForCalWeight returns carton with shipment weight
@@ -95,25 +95,26 @@ class Carton {
/// 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;
int sw = getShipmentWeight(rate.volumetricRatio);
// 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 wd = sw - aw;
wd = wd - rate.diffDiscountWeight;
double wdAmount = wd > 0 ? wd * rate.diffWeightRate : 0;
DiscountByWeight discountByWeight = rate.getDiscountByWeight(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;
double amount = e.weight * r;
total += amount;
});
return total;
return total + wdAmount;
}
List<ShipmentStatus> shipmentHistory;