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

66 lines
2.1 KiB
Dart
Raw Normal View History

2020-10-15 03:06:13 +06:30
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'cargo_type.dart';
2020-05-29 15:54:26 +06:30
class Rate {
2020-10-15 03:06:13 +06:30
double deliveryFee;
double freeDeliveryWeight;
double volumetricRatio;
2021-01-04 17:19:01 +06:30
double diffDiscountWeight;
double diffWeightRate;
2021-09-10 14:27:38 +06:30
List<CargoType> cargoTypes = [];
List<CargoType> customDuties = [];
List<DiscountByWeight> discountByWeights = [];
2020-10-15 03:06:13 +06:30
2020-10-16 10:58:31 +06:30
DiscountByWeight getDiscountByWeight(double weight) {
discountByWeights.sort((d1, d2) => d2.weight.compareTo(d1.weight));
2021-09-13 09:53:27 +06:30
return discountByWeights.firstWhere((e) => e.weight < weight,
orElse: () => DiscountByWeight());
2020-10-16 10:58:31 +06:30
}
2021-09-13 09:53:27 +06:30
CargoType get defaultCargoType =>
cargoTypes.firstWhere((e) => e.name == "General");
2020-10-15 03:06:13 +06:30
2021-01-04 17:19:01 +06:30
Rate(
2021-09-10 14:27:38 +06:30
{this.deliveryFee = 0,
this.freeDeliveryWeight = 0,
this.volumetricRatio = 0,
this.diffDiscountWeight = 0,
this.diffWeightRate = 0});
2020-10-15 03:06:13 +06:30
factory Rate.fromMap(Map<String, dynamic> map) {
2020-05-29 15:54:26 +06:30
return Rate(
2020-10-15 03:06:13 +06:30
deliveryFee: (map['delivery_fee'] ?? 0).toDouble(),
freeDeliveryWeight: (map['free_delivery_weight'] ?? 0).toDouble(),
volumetricRatio: (map['volumetric_ratio'] ?? 0).toDouble(),
2021-01-04 17:19:01 +06:30
diffDiscountWeight: (map['diff_discount_weight'] ?? 0).toDouble(),
diffWeightRate: (map['diff_weight_rate'] ?? 0).toDouble(),
2020-10-15 03:06:13 +06:30
);
}
Map<String, dynamic> toMap() {
return {
"delivery_fee": deliveryFee,
'free_delivery_weight': freeDeliveryWeight,
'volumetric_ratio': volumetricRatio,
2021-01-04 17:19:01 +06:30
'diff_discount_weight': diffDiscountWeight,
'diff_weight_rate': diffWeightRate,
2020-10-15 03:06:13 +06:30
};
2020-05-29 15:54:26 +06:30
}
bool isChangedForEdit(Rate rate) {
return rate.freeDeliveryWeight != this.freeDeliveryWeight ||
rate.deliveryFee != this.deliveryFee ||
2021-01-04 17:19:01 +06:30
rate.volumetricRatio != this.volumetricRatio ||
rate.diffDiscountWeight != this.diffDiscountWeight ||
rate.diffWeightRate != this.diffWeightRate;
}
2020-05-29 15:54:26 +06:30
@override
String toString() {
2021-01-04 17:19:01 +06:30
return 'Rate{deliveryFee:$deliveryFee,freeDeliveryWeight:$freeDeliveryWeight,volumetricRatio:$volumetricRatio,diffDiscountWeight:$diffDiscountWeight,diffWeightRate:$diffWeightRate}';
2020-05-29 15:54:26 +06:30
}
}