2020-05-29 15:54:26 +06:30
|
|
|
import 'dart:async';
|
|
|
|
|
|
2020-10-15 03:06:13 +06:30
|
|
|
import 'package:fcs/data/services/services.dart';
|
2020-10-15 15:49:02 +06:30
|
|
|
import 'package:fcs/domain/entities/cargo_type.dart';
|
|
|
|
|
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/entities/rate.dart';
|
|
|
|
|
import 'package:fcs/pages/main/model/base_model.dart';
|
2020-05-29 15:54:26 +06:30
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
|
|
|
|
|
class ShipmentRateModel extends BaseModel {
|
|
|
|
|
final log = Logger('ShipmentRateModel');
|
|
|
|
|
|
2021-09-10 16:33:52 +06:30
|
|
|
StreamSubscription<Rate>? listener;
|
|
|
|
|
late Rate rate;
|
2020-05-31 15:00:11 +06:30
|
|
|
|
2020-05-29 15:54:26 +06:30
|
|
|
void initUser(user) {
|
|
|
|
|
super.initUser(user);
|
2021-09-10 16:33:52 +06:30
|
|
|
if (listener != null) listener!.cancel();
|
2020-10-15 03:06:13 +06:30
|
|
|
listener = Services.instance.rateService.getRateStream().listen((rate) {
|
|
|
|
|
this.rate = rate;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
});
|
2020-05-29 15:54:26 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
logout() async {
|
2021-09-10 16:33:52 +06:30
|
|
|
if (listener != null) await listener!.cancel();
|
2020-05-29 15:54:26 +06:30
|
|
|
}
|
2020-10-15 15:49:02 +06:30
|
|
|
|
|
|
|
|
// Rate
|
|
|
|
|
|
|
|
|
|
Future<void> updateRate(Rate rate) {
|
|
|
|
|
return Services.instance.rateService.updateRate(rate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Cargo Type
|
|
|
|
|
|
|
|
|
|
Future<void> addCargoType(CargoType cargoType) {
|
|
|
|
|
return Services.instance.rateService.createCargoType(cargoType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> updateCargoType(CargoType cargoType) {
|
|
|
|
|
return Services.instance.rateService.updateCargoType(cargoType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> deleteCargoType(String id) {
|
|
|
|
|
return Services.instance.rateService.deleteCargoType(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//CustomDuty
|
|
|
|
|
|
2021-01-08 17:13:51 +06:30
|
|
|
Future<void> addCustomDuty(CargoType customDuty) {
|
2021-09-10 16:33:52 +06:30
|
|
|
customDuty.isCutomDuty = true;
|
2021-01-08 17:13:51 +06:30
|
|
|
return Services.instance.rateService.createCargoType(customDuty);
|
2020-10-15 15:49:02 +06:30
|
|
|
}
|
|
|
|
|
|
2021-01-08 17:13:51 +06:30
|
|
|
Future<void> updateCustomDuty(CargoType customDuty) {
|
2021-09-10 16:33:52 +06:30
|
|
|
customDuty.isCutomDuty = true;
|
2021-01-08 17:13:51 +06:30
|
|
|
return Services.instance.rateService.updateCargoType(customDuty);
|
2020-10-15 15:49:02 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> deleteCustomDuty(String id) {
|
2021-01-08 17:13:51 +06:30
|
|
|
return Services.instance.rateService.deleteCargoType(id);
|
2020-10-15 15:49:02 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Discount by weight
|
|
|
|
|
Future<void> addDiscountByWeight(DiscountByWeight discountByWeight) {
|
|
|
|
|
return Services.instance.rateService
|
|
|
|
|
.createDiscountByWeight(discountByWeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> updateDiscountByWeight(DiscountByWeight discountByWeight) {
|
|
|
|
|
return Services.instance.rateService
|
|
|
|
|
.updateDiscountByWeight(discountByWeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> deleteDiscountByWeight(String id) {
|
|
|
|
|
return Services.instance.rateService.deleteDiscountByWeight(id);
|
|
|
|
|
}
|
2020-05-29 15:54:26 +06:30
|
|
|
}
|