add invoice pdf

This commit is contained in:
Sai Naw Wun
2020-10-26 04:41:24 +06:30
parent feec3c8687
commit 2786acfd08
33 changed files with 787 additions and 1114 deletions

View File

@@ -4,7 +4,7 @@ class CargoType {
double rate;
double weight;
double amount;
double get calAmount => (calRate ?? 0) * (calWeight ?? 0);
double calRate;
double calWeight;
@@ -16,9 +16,16 @@ class CargoType {
rate: map['rate']?.toDouble() ?? 0,
weight: map['weight']?.toDouble() ?? 0,
calWeight: map['cal_weight']?.toDouble() ?? 0,
calRate: map['cal_rate']?.toDouble() ?? 0,
);
}
CargoType({this.id, this.name, this.rate, this.weight, this.calWeight});
CargoType(
{this.id,
this.name,
this.rate,
this.weight,
this.calWeight,
this.calRate});
Map<String, dynamic> toMap() {
return {
@@ -27,6 +34,7 @@ class CargoType {
'rate': rate,
'weight': weight,
'cal_weight': calWeight,
'cal_rate': calRate,
};
}

View File

@@ -171,7 +171,7 @@ class Carton {
'length': length,
'width': width,
'height': height,
'delivery_address': deliveryAddress.toMap(),
'delivery_address': deliveryAddress?.toMap(),
'carton_type': cartonType,
'mix_carton_id': mixCartonID,
};

View File

@@ -1,3 +1,4 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
@@ -13,6 +14,7 @@ class Invoice {
DateTime invoiceDate;
String fcsShipmentID;
String userID;
String fcsID;
String userName;
String phoneNumber;
String status;
@@ -28,20 +30,23 @@ class Invoice {
List<Shipment> shipments;
Discount discount;
PaymentMethod paymentMethod;
String invoiceURL;
List<CargoType> getCargoTypes(Rate rate) {
List<CargoType> cargoTypes = [];
if (cargoTypes != null) return cargoTypes;
List<CargoType> _cargoTypes = [];
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);
if (_cargoTypes.contains(ct)) {
CargoType existing = _cargoTypes.firstWhere((wc) => wc.id == ct.id);
existing.calWeight += ct.calWeight;
} else {
cargoTypes.add(ct.clone());
_cargoTypes.add(ct.clone());
}
totalCalWeight += ct.calWeight;
});
@@ -51,25 +56,23 @@ class Invoice {
DiscountByWeight discountByWeight =
rate.getDiscountByWeight(totalCalWeight);
cargoTypes.forEach((e) {
_cargoTypes.forEach((e) {
double r =
e.rate - (discountByWeight != null ? discountByWeight.discount : 0);
double amount = e.calWeight * r;
e.calRate = r;
e.amount = amount;
});
return cargoTypes;
return _cargoTypes;
}
double getTotal(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.amount + p);
var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
return total;
}
double getNetAmount(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.amount + p);
var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
total += getCustomFee();
total += getDeliveryFee();
total += getHandlingFee();
@@ -78,7 +81,7 @@ class Invoice {
}
double getHandlingFee() {
return shipments?.where((sh) => sh.isSelected)?.fold(0, (p, s) {
return shipments?.where((sh) => sh.isSelected ?? false)?.fold(0, (p, s) {
return p + (s?.handlingFee ?? 0) - (s?.paidHandlingFee ?? 0);
});
}
@@ -97,33 +100,65 @@ class Invoice {
double getDiscount() => discount == null ? 0 : discount.amount;
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,
});
Invoice(
{this.id,
this.invoiceNumber,
this.invoiceDate,
this.fcsID,
this.userName,
this.phoneNumber,
this.amount,
this.discount,
this.status,
this.customDuties,
this.cartons,
this.cargoTypes,
this.handlingFee,
this.deliveryFee,
this.fcsShipmentID,
this.shipments,
this.invoiceURL,
this.paymentMethod});
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
var invd = (map['invoice_date'] as Timestamp);
var cargoTypesMaps =
List<Map<String, dynamic>>.from(map['cargo_types'] ?? []);
var cargoTypes =
cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList();
var customDutiesMap =
List<Map<String, dynamic>>.from(map['custom_duties'] ?? []);
var customDuties =
customDutiesMap.map((e) => CustomDuty.fromMap(e, e["id"])).toList();
var handlingShipmentsMap =
List<Map<String, dynamic>>.from(map['handling_fee_shipments'] ?? []);
var handingShipments =
handlingShipmentsMap.map((e) => Shipment.fromMap(e, e["id"])).toList();
var cartonsMap = List<Map<String, dynamic>>.from(map['cartons'] ?? []);
var cartons = cartonsMap.map((e) => Carton.fromMap(e, e["id"])).toList();
var paymentMethodMap = map['payment_method'];
var paymentMethod = paymentMethodMap != null
? PaymentMethod.fromMap(paymentMethodMap, paymentMethodMap['id'])
: null;
var discountMap = map['discount'];
var discount = Discount.fromMap(discountMap, discountMap['id']);
return Invoice(
id: docID,
invoiceNumber: map['invoice_number'],
invoiceDate: map['invoice_date'],
invoiceDate: invd?.toDate(),
userName: map['user_name'],
fcsID: map['fcs_id'],
phoneNumber: map['phone_number'],
amount: map['amount'],
status: map['status'],
discount: map['discount'],
cartons: cartons,
cargoTypes: cargoTypes,
shipments: handingShipments,
customDuties: customDuties,
deliveryFee: map['delivery_fee'],
invoiceURL: map['invoice_url'],
paymentMethod: paymentMethod,
discount: discount,
);
}
@@ -131,17 +166,24 @@ class Invoice {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _customDuties = customDuties?.map((c) => c.toMap())?.toList();
List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? [];
List _shipments = shipments?.map((s) => s.toMap())?.toList() ?? [];
return {
"id": id,
"invoice_date": invoiceDate,
"invoice_date": invoiceDate?.toUtc()?.toIso8601String(),
"user_id": userID,
"user_name": userName,
"invoice_number": invoiceNumber,
'fcs_shipment_id': fcsShipmentID,
'cargo_types': _cargoTypes,
'custom_duties': _customDuties,
'handling_fee_shipments': _shipments,
'cartons': _cartons,
'discount': discount?.toMap(),
'amount': amount,
'handling_fee': handlingFee,
'delivery_fee': deliveryFee,
'invoice_url': invoiceURL,
'payment_method': paymentMethod?.toMap(),
};
}
}

View File

@@ -100,7 +100,7 @@ class Shipment {
}
Map<String, dynamic> toMap() {
List _boxes = boxes.map((l) => l.toMap()).toList();
List _boxes = boxes?.map((l) => l.toMap())?.toList() ?? [];
return {
"id": id,