add rate service

This commit is contained in:
Sai Naw Wun
2020-10-15 03:06:13 +06:30
parent 7b88658893
commit 47c07a6c88
45 changed files with 870 additions and 496 deletions

View File

@@ -1,7 +1,7 @@
import 'package:fcs/domain/vo/shipment_status.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'cargo.dart';
import 'cargo_type.dart';
import 'package.dart';
class Box {
@@ -36,7 +36,7 @@ class Box {
List<Package> packages;
List<Cargo> cargoTypes;
List<CargoType> cargoTypes;
DeliveryAddress shippingAddress;

View File

@@ -1,17 +0,0 @@
class Cargo {
String type;
int price;
int weight;
Cargo({this.type, this.price, this.weight});
@override
String toString() {
return type;
}
@override
bool operator ==(Object other) => other is Cargo && other.type == type;
@override
int get hashCode => type.hashCode;
}

View File

@@ -0,0 +1,29 @@
class CargoType {
String id;
String name;
double rate;
factory CargoType.fromMap(Map<String, dynamic> map, String id) {
return CargoType(
id: id,
name: map['name'],
rate: (map['rate'] ?? 0).toDouble(),
);
}
int weight;
CargoType({this.id, this.name, this.rate, this.weight});
Map<String, dynamic> toMap() {
return {
"id": id,
'name': name,
'rate': rate,
};
}
@override
bool operator ==(Object other) => other is CargoType && other.id == id;
@override
int get hashCode => id.hashCode;
}

View File

@@ -1,6 +0,0 @@
class Custom{
String id;
String productType;
int fee;
Custom({this.productType,this.fee});
}

View File

@@ -0,0 +1,25 @@
class CustomDuty {
String id;
String productType;
String desc;
double fee;
CustomDuty({this.id, this.productType, this.desc, this.fee});
factory CustomDuty.fromMap(Map<String, dynamic> map, String id) {
return CustomDuty(
id: id,
productType: map['product_type'],
desc: map['desc'],
fee: (map['fee'] ?? 0).toDouble(),
);
}
Map<String, dynamic> toMap() {
return {
"id": id,
'product_type': productType,
'desc': desc,
'fee': fee,
};
}
}

View File

@@ -0,0 +1,23 @@
class DiscountByWeight {
String id;
double weight;
double discount;
DiscountByWeight({this.id, this.weight, this.discount});
factory DiscountByWeight.fromMap(Map<String, dynamic> map, String id) {
return DiscountByWeight(
id: id,
weight: (map['weight'] ?? 0).toDouble(),
discount: (map['discount'] ?? 0).toDouble(),
);
}
Map<String, dynamic> toMap() {
return {
"id": id,
'weight': weight,
'discount': discount,
};
}
}

View File

@@ -1,6 +0,0 @@
class DiscountRate {
int weight;
double discountRate;
DiscountRate({this.weight, this.discountRate});
}

View File

@@ -1,31 +1,45 @@
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'cargo_type.dart';
class Rate {
String id;
String name;
String description;
String fromTime;
String toTime;
int price;
double deliveryFee;
double freeDeliveryWeight;
double volumetricRatio;
Rate(
{this.id,
this.name,
this.description,
this.fromTime,
this.toTime,
this.price,});
List<CargoType> cargoTypes;
List<CustomDuty> customDuties;
List<DiscountByWeight> discountByWeights;
factory Rate.fromMap(Map<String, dynamic> map, String id) {
CargoType get defaultCargoType => cargoTypes == null
? null
: cargoTypes.firstWhere((e) => e.name == "General");
Rate({
this.deliveryFee,
this.freeDeliveryWeight,
this.volumetricRatio,
});
factory Rate.fromMap(Map<String, dynamic> map) {
return Rate(
id: id,
name: map['name'],
description: map['description'],
fromTime: map['from_time'],
toTime: map['to_time'],
price: map['price'],);
deliveryFee: (map['delivery_fee'] ?? 0).toDouble(),
freeDeliveryWeight: (map['free_delivery_weight'] ?? 0).toDouble(),
volumetricRatio: (map['volumetric_ratio'] ?? 0).toDouble(),
);
}
Map<String, dynamic> toMap() {
return {
"delivery_fee": deliveryFee,
'free_delivery_weight': freeDeliveryWeight,
'volumetric_ratio': volumetricRatio,
};
}
@override
String toString() {
return 'Rate{id:$id, name:$name,description:$description,fromTime:$fromTime,toTime:$toTime}';
return 'Rate{deliveryFee:$deliveryFee,freeDeliveryWeight:$freeDeliveryWeight,volumetricRatio:$volumetricRatio}';
}
}

View File

@@ -1,6 +1,3 @@
import 'package:fcs/domain/entities/cargo.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
List<Day> dayLists = [
Day(id: 1, name: 'Sun'),
Day(id: 2, name: 'Mon'),
@@ -26,32 +23,24 @@ class Setting {
final String termsEng;
final String termsMm;
String about;
double volumetricRatio;
List<String> shipmentTypes;
Map<String, int> cargoTypes;
List<Cargo> get cargoTypesList => cargoTypes.entries
.map((e) => Cargo(type: e.key, price: e.value))
.toList();
Cargo get defaultCargoType =>
cargoTypesList.firstWhere((e) => e.type == "General");
Setting(
{this.supportBuildNum,
this.usaAddress,
this.mmAddress,
this.usaContactNumber,
this.mmContactNumber,
this.emailAddress,
this.facebookLink,
this.inviteRequired,
this.appUrl,
this.termsEng,
this.termsMm,
this.about,
this.shipmentTypes,
this.volumetricRatio,
this.cargoTypes});
Setting({
this.supportBuildNum,
this.usaAddress,
this.mmAddress,
this.usaContactNumber,
this.mmContactNumber,
this.emailAddress,
this.facebookLink,
this.inviteRequired,
this.appUrl,
this.termsEng,
this.termsMm,
this.about,
this.shipmentTypes,
});
factory Setting.fromMap(Map<String, dynamic> map) {
return Setting(
@@ -67,11 +56,7 @@ class Setting {
about: map['about'],
termsEng: map['terms_eng'],
termsMm: map['terms_mm'],
volumetricRatio: map['volumetric_ratio'],
shipmentTypes: List.from(map['shipment_types']),
cargoTypes: map['cargo_types'] == null
? []
: Map<String, int>.from(map['cargo_types']),
);
}

View File

@@ -1,4 +1,4 @@
import 'cargo.dart';
import 'cargo_type.dart';
class Shipment {
String id;
@@ -12,7 +12,7 @@ class Shipment {
String address;
String status;
DateTime date;
List<Cargo> cargoTypes;
List<CargoType> cargoTypes;
bool isCourier;
int radioIndex;