update invoice page

This commit is contained in:
Sai Naw Wun
2020-10-24 06:14:07 +06:30
parent d0d664e004
commit feec3c8687
22 changed files with 996 additions and 637 deletions

View File

@@ -3,63 +3,59 @@ 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/payment_method.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package.dart';
import 'receipt.dart';
import 'package:fcs/domain/entities/shipment.dart';
class Invoice {
String id;
String invoiceNumber;
DateTime invoiceDate;
String customerName;
String customerPhoneNumber;
double amount;
String fcsShipmentID;
String userID;
String userName;
String phoneNumber;
String status;
String paymentAttachment;
double handlingFee;
double deliveryFee;
double paidAmount;
double amount;
List<Package> packages;
List<Receipt> receipts;
List<String> receiptPhotos;
List<CustomDuty> customDuties;
List<Carton> cartons;
List<CargoType> cargoTypes;
List<Shipment> shipments;
Discount discount;
PaymentMethod paymentMethod;
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.clone());
}
actualWeight += tc.weight;
});
double volume = (c.length ?? 0) * (c.width ?? 0) * (c.height ?? 0);
double sw = volume / rate.volumetricRatio ?? 0;
shipmentWeight += sw;
double totalCalWeight = 0;
cartons.forEach((carton) {
if (carton.isChecked) {
var _cartonsTypes =
carton.getCargoTypeForCalWeight(rate.volumetricRatio);
_cartonsTypes.forEach((ct) {
if (cargoTypes.contains(ct)) {
CargoType existing = cargoTypes.firstWhere((wc) => wc.id == ct.id);
existing.calWeight += ct.calWeight;
} else {
cargoTypes.add(ct.clone());
}
totalCalWeight += ct.calWeight;
});
}
});
DiscountByWeight discountByWeight = rate.getDiscountByWeight(
shipmentWeight > actualWeight ? shipmentWeight : actualWeight);
DiscountByWeight discountByWeight =
rate.getDiscountByWeight(totalCalWeight);
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;
double amount = e.calWeight * r;
e.calRate = r;
e.calWeight = cargoWeight;
e.amount = amount;
});
return cargoTypes;
@@ -81,6 +77,12 @@ class Invoice {
return total;
}
double getHandlingFee() {
return shipments?.where((sh) => sh.isSelected)?.fold(0, (p, s) {
return p + (s?.handlingFee ?? 0) - (s?.paidHandlingFee ?? 0);
});
}
double getTotalBalance(Rate rate) {
return getNetAmount(rate) - (paidAmount ?? 0);
}
@@ -89,49 +91,57 @@ class Invoice {
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,
this.invoiceNumber,
this.invoiceDate,
this.customerName,
this.customerPhoneNumber,
this.amount,
this.discount,
this.status,
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);
Invoice({
this.id,
this.invoiceNumber,
this.invoiceDate,
this.userName,
this.phoneNumber,
this.amount,
this.discount,
this.status,
this.customDuties,
this.cartons,
this.cargoTypes,
this.handlingFee,
this.fcsShipmentID,
this.shipments,
});
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
return Invoice(
id: docID,
invoiceNumber: map['invoice_number'],
invoiceDate: map['invoice_date'],
customerName: map['customer_name'],
customerPhoneNumber: map['phone_number'],
userName: map['user_name'],
phoneNumber: map['phone_number'],
amount: map['amount'],
status: map['status'],
discount: map['discount'],
paymentAttachment: map['payment_attachment'],
packages: map['packages'],
receiptPhotos: map['receiptPhotos'],
receipts: map['receipts'],
);
}
Map<String, dynamic> toMap() {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _customDuties = customDuties?.map((c) => c.toMap())?.toList();
List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? [];
return {
"id": id,
"invoice_date": invoiceDate,
"user_id": userID,
'fcs_shipment_id': fcsShipmentID,
'cargo_types': _cargoTypes,
'custom_duties': _customDuties,
'cartons': _cartons,
'discount': discount?.toMap(),
'handling_fee': handlingFee,
'delivery_fee': deliveryFee,
};
}
}