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

68 lines
2.1 KiB
Dart
Raw Normal View History

2020-10-15 03:06:13 +06:30
import 'package:fcs/domain/entities/custom_duty.dart';
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;
2020-10-15 03:06:13 +06:30
List<CargoType> cargoTypes;
List<CustomDuty> customDuties;
List<DiscountByWeight> discountByWeights;
2020-10-16 10:58:31 +06:30
DiscountByWeight getDiscountByWeight(double weight) {
discountByWeights.sort((d1, d2) => d2.weight.compareTo(d1.weight));
return discountByWeights.firstWhere((e) => e.weight < weight,
orElse: () => null);
}
2020-10-15 03:06:13 +06:30
CargoType get defaultCargoType => cargoTypes == null
? null
: cargoTypes.firstWhere((e) => e.name == "General");
2021-01-04 17:19:01 +06:30
Rate(
{this.deliveryFee,
this.freeDeliveryWeight,
this.volumetricRatio,
this.diffDiscountWeight,
this.diffWeightRate});
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
}
}