Files
fcs/lib/domain/entities/box.dart

137 lines
3.2 KiB
Dart
Raw Normal View History

2020-10-16 10:58:31 +06:30
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'package:fcs/domain/entities/rate.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/vo/shipment_status.dart';
2020-10-08 11:38:05 +06:30
import 'package:fcs/domain/vo/delivery_address.dart';
2020-06-04 01:36:49 +06:30
2020-10-15 03:06:13 +06:30
import 'cargo_type.dart';
2020-10-07 02:33:06 +06:30
import 'package.dart';
2020-06-04 01:36:49 +06:30
class Box {
String id;
String shipmentNumber;
String senderFCSID;
String senderName;
String receiverFCSID;
String receiverName;
String receiverAddress;
String receiverNumber;
String boxNumber;
String status;
String cargoDesc;
2020-10-14 16:53:16 +06:30
String desc;
2020-10-16 10:58:31 +06:30
double width;
double height;
double length;
2020-06-29 16:15:25 +06:30
int shipmentWeight;
2020-10-14 16:53:16 +06:30
bool isChecked;
String cartonType;
String fcsID;
String userName;
2020-06-04 01:36:49 +06:30
int rate;
int weight;
String packageType;
String pickUpID;
List<String> photos;
String remark;
DateTime arrivedDate;
List<Package> packages;
2020-10-15 03:06:13 +06:30
List<CargoType> cargoTypes;
2020-06-25 16:19:23 +06:30
2020-10-16 10:58:31 +06:30
DeliveryAddress deliveryAddress;
2020-06-26 16:17:40 +06:30
2020-06-04 01:36:49 +06:30
int get amount => rate != null && weight != null ? rate * weight : 0;
String get packageNumber =>
shipmentNumber + "-" + receiverNumber + " #" + boxNumber;
double get price => rate.toDouble() * weight;
2020-10-16 10:58:31 +06:30
double get actualWeight =>
cargoTypes == null ? 0 : cargoTypes.fold(0, (p, e) => e.weight + p);
2020-10-13 07:50:25 +06:30
double getShipmentWeight(double volumetricRatio) {
if (length == null ||
length <= 0 ||
width == null ||
width <= 0 ||
height == null ||
height <= 0 ||
volumetricRatio == null ||
volumetricRatio <= 0) return 0;
return (length * width * height) / volumetricRatio;
}
2020-10-16 10:58:31 +06:30
/// 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;
}
2020-10-07 02:33:06 +06:30
List<ShipmentStatus> shipmentHistory;
2020-06-04 01:36:49 +06:30
Box(
{this.id,
this.shipmentNumber,
this.senderFCSID,
this.senderName,
this.receiverFCSID,
this.receiverName,
this.receiverNumber,
this.receiverAddress,
this.boxNumber,
2020-10-14 16:53:16 +06:30
this.desc,
2020-06-25 16:19:23 +06:30
this.width,
this.height,
this.length,
2020-06-29 16:15:25 +06:30
this.shipmentWeight,
2020-10-14 16:53:16 +06:30
this.isChecked = false,
this.cartonType,
this.fcsID,
this.userName,
2020-06-04 01:36:49 +06:30
this.rate,
this.weight,
this.packageType,
this.pickUpID,
this.remark,
this.status,
this.arrivedDate,
this.cargoDesc,
2020-10-07 02:33:06 +06:30
this.shipmentHistory,
2020-06-25 16:19:23 +06:30
this.packages,
2020-06-26 16:17:40 +06:30
this.cargoTypes,
2020-10-16 10:58:31 +06:30
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(),
};
}
2020-06-04 01:36:49 +06:30
}