fix errors

This commit is contained in:
Sai Naw Wun
2020-10-22 04:14:53 +06:30
parent 2021f74872
commit e5540c5491
32 changed files with 1069 additions and 811 deletions

View File

@@ -13,6 +13,7 @@ const custom_duties_collection = "custom_duties";
const discounts_by_weights_collection = "discounts_by_weight";
const shipments_collection = "shipments";
const cartons_collection = "cartons";
const discounts_collection = "discounts";
// docs
const setting_doc_id = "setting";

View File

@@ -9,6 +9,9 @@ class CargoType {
int shipmentWeight;
double amount;
double calRate;
double calWeight;
factory CargoType.fromMap(Map<String, dynamic> map, String id) {
return CargoType(
id: id,

View File

@@ -43,10 +43,9 @@ class Carton {
String remark;
DateTime arrivedDate;
String cartonNumber;
List<String> packageIDs;
List<Package> packages;
List<CargoType> cargoTypes;
List<Carton> cartons;
@@ -193,4 +192,10 @@ class Carton {
deliveryAddress: _da,
cargoTypes: cargoTypes);
}
@override
bool operator ==(Object other) => other is Carton && other.id == id;
@override
int get hashCode => id.hashCode;
}

View File

@@ -22,4 +22,10 @@ class CustomDuty {
'fee': fee,
};
}
@override
bool operator ==(Object other) => other is CustomDuty && other.id == id;
@override
int get hashCode => id.hashCode;
}

View File

@@ -1,3 +1,10 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package.dart';
import 'receipt.dart';
@@ -8,13 +15,89 @@ class Invoice {
String customerName;
String customerPhoneNumber;
double amount;
String discount;
String status;
String paymentAttachment;
double handlingFee;
double deliveryFee;
double paidAmount;
List<Package> packages;
List<Receipt> receipts;
List<String> receiptPhotos;
List<CustomDuty> customDuties;
List<Carton> cartons;
Discount discount;
List<CargoType> getCargoTypes(Rate rate) {
List<CargoType> cargoTypes = [];
double actualWeight = 0;
double shipmentWeight = 0;
cartons.forEach((c) {
c.cargoTypes.forEach((tc) {
if (cargoTypes.contains(tc)) {
CargoType existing = cargoTypes.firstWhere((wc) => wc.id == tc.id);
existing.weight += tc.weight;
} else {
cargoTypes.add(tc);
}
actualWeight += tc.weight;
});
double volume = (c.length ?? 0) * (c.width ?? 0) * (c.height ?? 0);
double sw = volume / rate.volumetricRatio ?? 0;
shipmentWeight += sw;
});
DiscountByWeight discountByWeight = rate.getDiscountByWeight(
shipmentWeight > actualWeight ? shipmentWeight : actualWeight);
cargoTypes.forEach((e) {
print(actualWeight > shipmentWeight);
double cargoWeight = actualWeight > shipmentWeight
? e.weight
: e.weight / actualWeight * shipmentWeight;
double r =
e.rate - (discountByWeight != null ? discountByWeight.discount : 0);
double amount = cargoWeight * r;
e.calRate = r;
e.calWeight = cargoWeight;
e.amount = amount;
});
return cargoTypes;
}
double getTotal(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.amount + p);
return total;
}
double getNetAmount(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.amount + p);
total += getCustomFee();
total += getDeliveryFee();
total += getHandlingFee();
total -= getDiscount();
return total;
}
double getTotalBalance(Rate rate) {
return getNetAmount(rate) - (paidAmount ?? 0);
}
double getCustomFee() {
return customDuties == null ? 0 : customDuties.fold(0, (p, d) => p + d.fee);
}
double getHandlingFee() {
return handlingFee == null ? 0 : handlingFee;
}
double getDeliveryFee() {
return deliveryFee == null ? 0 : deliveryFee;
}
double getDiscount() => discount == null ? 0 : discount.amount;
Invoice(
{this.id,
@@ -28,6 +111,9 @@ class Invoice {
this.paymentAttachment,
this.packages,
this.receiptPhotos,
this.customDuties,
this.cartons,
this.handlingFee,
this.receipts});
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p);

View File

@@ -13,6 +13,7 @@ class Shipment {
String pickupTimeEnd;
String userName;
String userID;
String phoneNumber;
int numberOfPackage;
int weight;
@@ -35,6 +36,7 @@ class Shipment {
{this.id,
this.shipmentNumber,
this.shipmentType,
this.userID,
this.userName,
this.phoneNumber,
this.pickupTimeStart,
@@ -75,6 +77,7 @@ class Shipment {
return Shipment(
id: id,
userName: map['user_name'],
userID: map['user_id'],
shipmentNumber: map['shipment_number'],
phoneNumber: map['phone_number'],
pickupDate: pd == null ? null : pd.toDate(),
@@ -97,6 +100,7 @@ class Shipment {
return {
"id": id,
'user_id': userID,
'cartons': _boxes,
'shipment_type': shipmentType,
'pickup_address': pickupAddress.toMap(),