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

@@ -1,6 +1,7 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/domain/entities/shipment.dart';
import 'package:fcs/domain/vo/shipment_status.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
@@ -9,6 +10,7 @@ import 'package.dart';
class Carton {
String id;
String shipmentID;
String shipmentNumber;
String senderFCSID;
String senderName;
@@ -47,9 +49,9 @@ class Carton {
List<String> packageIDs;
List<Package> packages;
List<CargoType> cargoTypes;
List<Carton> cartons;
DeliveryAddress deliveryAddress;
Shipment shipment;
int get amount => rate != null && weight != null ? rate * weight : 0;
@@ -73,6 +75,23 @@ class Carton {
return (length * width * height) / volumetricRatio;
}
/// getCargoTypeForCalWeight returns carton with shipment weight
List<CargoType> getCargoTypeForCalWeight(double volumetricRatio) {
// get shipment weight
double volume = (length ?? 0) * (width ?? 0) * (height ?? 0);
double sw = volume / volumetricRatio ?? 0;
// get actual weight
double aw = cargoTypes.fold(0.0, (p, c) => p + c.weight);
if (aw == 0 || sw == 0) return [];
cargoTypes.forEach((e) {
double calWeight = aw > sw ? e.weight : e.weight / aw * sw;
e.calWeight = calWeight;
});
return cargoTypes;
}
/// calAmount returns total amount
double calAmount(Rate rate) {
// get shipment weight
@@ -101,6 +120,7 @@ class Carton {
Carton(
{this.id,
this.shipmentID,
this.shipmentNumber,
this.senderFCSID,
this.senderName,
@@ -133,7 +153,6 @@ class Carton {
this.cartonNumber,
this.fcsShipmentID,
this.fcsShipmentNumber,
this.cartons,
this.packageIDs,
this.mixCartonID,
this.mixCartonNumber,
@@ -143,7 +162,6 @@ class Carton {
Map<String, dynamic> toMap() {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _packages = packages?.map((c) => c.toJson())?.toList();
List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? [];
return {
"id": id,
'fcs_shipment_id': fcsShipmentID,
@@ -155,8 +173,7 @@ class Carton {
'height': height,
'delivery_address': deliveryAddress.toMap(),
'carton_type': cartonType,
'cartons': _cartons,
'mix_carton_id': mixCartonID
'mix_carton_id': mixCartonID,
};
}
@@ -171,6 +188,7 @@ class Carton {
return Carton(
id: docID,
arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null,
shipmentID: map['shipment_id'],
shipmentNumber: map['shipment_number'],
receiverNumber: map['receiver_number'],
boxNumber: map['box_number'],