update invoice page
This commit is contained in:
@@ -393,13 +393,13 @@
|
||||
"rate.delivery_fee":"Delivery fees",
|
||||
"rate.total_estimated_amount":"Total estimated amount",
|
||||
"rate.volumetric_ratio":"Volumetric ratio",
|
||||
"rate.custom.form.title":"CUSTOM",
|
||||
"rate.custom.form.title":"Custom",
|
||||
"rate.cutom.product_type":"Product type",
|
||||
"rate.custom.fee":"Fee",
|
||||
"rate.discount.weight":"Weight",
|
||||
"rate.discount.rate":"Discount rate",
|
||||
"rate.custom_duty.title":"Custom Duties",
|
||||
"rate.custom_duty":"Custom Duty",
|
||||
"rate.custom_duty.title":"Custom Fee",
|
||||
"rate.custom_duty":"Custom Fee",
|
||||
"rate.cargo.type":"Cargo Types",
|
||||
"rate.discount_by_weight":"Discounts by weight",
|
||||
"rate.discount_by_weight.edit.delete.confirm":"Delete this discount by weight?",
|
||||
@@ -428,6 +428,8 @@
|
||||
"invoice.customer_name":"Customer name",
|
||||
"invoice.status":"Status",
|
||||
"invoice.amount":"Amount",
|
||||
"invoice.weight":"Weight(lb)",
|
||||
"invoice.rate":"Rate(USD)",
|
||||
"invoice.total":"Total amount",
|
||||
"invoice.balance":"Balance",
|
||||
"invoice.handling_fee":"Handling fee",
|
||||
@@ -435,15 +437,16 @@
|
||||
"invoice.custom_fee_desc":"Custom fee description",
|
||||
"invoice.discount":"Discount code",
|
||||
"invoice.payment_method":"Payment method",
|
||||
"invoice.delivery_fee":"Delivery fee : ",
|
||||
"invoice.delivery_fee":"Delivery fee",
|
||||
"invoice.payment_attachment":"Payment attachment",
|
||||
"invoice.box_info":"Carton information",
|
||||
"invoice.box_info":"Cartons",
|
||||
"invoice.cargo_table":"Cargo table",
|
||||
"invoice.btn_create":"Create invoice",
|
||||
"invoice.btn_save":"Save invoice",
|
||||
"invoice.btn_payment_receipt":"Attachment payment receipt",
|
||||
"invoice.description": "Description",
|
||||
"invoice.box.cargo_type": "Cargo types",
|
||||
"invoice.box.desc": "Description",
|
||||
"invoice.cargo_type":"Cargo types",
|
||||
"invoice.box.number":"Carton number",
|
||||
"invoice.box.length":"L",
|
||||
@@ -459,6 +462,12 @@
|
||||
"invoice.popupmenu.paid":"Paid",
|
||||
"invoice.shipment.title":"Select FCS shipment",
|
||||
"invoice.customer.title":"Select Customer",
|
||||
"invoice.add.custom.fee.menu":"Custom fee",
|
||||
"invoice.add.handling.fee.menu":"Handling fee",
|
||||
"invoice.add.discount.menu":"Discount",
|
||||
"invoice.shipment.handling.fee.title":"Select shipment",
|
||||
"invoice.shipment.number":"Shipment number",
|
||||
"invoice.shipment.discount.title":"Select discount",
|
||||
"Invoices End ================================================================":"",
|
||||
|
||||
"Discount Start ================================================================":"",
|
||||
|
||||
@@ -428,6 +428,8 @@
|
||||
"invoice.customer_name":"ဝယ်ယူသူနာမည်",
|
||||
"invoice.status":"အခြေအနေ",
|
||||
"invoice.amount":"ပမာဏ",
|
||||
"invoice.weight":"Weight(lb)",
|
||||
"invoice.rate":"Rate(USD)",
|
||||
"invoice.total":"စုစုပေါင်းပမာဏ",
|
||||
"invoice.balance":"ပေးချေရန်ကျန်ရှိငွေ",
|
||||
"invoice.handling_fee":"ထိန်းသိမ်းခ",
|
||||
@@ -437,7 +439,7 @@
|
||||
"invoice.payment_method":"ငွေပေးချေစနစ်",
|
||||
"invoice.delivery_fee":"ပို့ဆောင်ခ",
|
||||
"invoice.payment_attachment":"ပေးချေပြီးဖိုင်များ",
|
||||
"invoice.box_info":"Box အချက်အလက်",
|
||||
"invoice.box_info":"Cartons",
|
||||
"invoice.cargo_table":"ကုန်ပစ္စည်းဇယား",
|
||||
"invoice.btn_create":"ငွေတောင်းခံလွှာ ပြုလုပ်ရန်",
|
||||
"invoice.btn_save":"ငွေတောင်းခံလွှာ သိမ်းရန်",
|
||||
@@ -445,6 +447,7 @@
|
||||
"invoice.box.cargo_type": "ကုန်ပစ္စည်းအမျိုးအစားများ",
|
||||
"invoice.description": "ငွေတောင်းခံလွှာအကြောင်းအရာ",
|
||||
"invoice.cargo_type":"Cargo Types",
|
||||
"invoice.box.desc": "Description",
|
||||
"invoice.box.number":"Box နံပါတ်",
|
||||
"invoice.box.length":"L",
|
||||
"invoice.box.width":"W",
|
||||
@@ -459,6 +462,12 @@
|
||||
"invoice.popupmenu.paid":"Paid",
|
||||
"invoice.shipment.title":"Select FCS shipment",
|
||||
"invoice.customer.title":"Select Customer",
|
||||
"invoice.add.custom.fee.menu":"Custom fee",
|
||||
"invoice.add.handling.fee.menu":"Handling fee",
|
||||
"invoice.add.discount.menu":"Discount",
|
||||
"invoice.shipment.number":"Shipment number",
|
||||
"invoice.shipment.handling.fee.title":"Select shipment",
|
||||
"invoice.shipment.discount.title":"Select discount",
|
||||
"Invoices End ================================================================":"",
|
||||
|
||||
"Discount Start ================================================================":"",
|
||||
|
||||
@@ -4,7 +4,6 @@ class CargoType {
|
||||
double rate;
|
||||
double weight;
|
||||
|
||||
int shipmentWeight;
|
||||
double amount;
|
||||
|
||||
double calRate;
|
||||
@@ -16,9 +15,10 @@ class CargoType {
|
||||
name: map['name'],
|
||||
rate: map['rate']?.toDouble() ?? 0,
|
||||
weight: map['weight']?.toDouble() ?? 0,
|
||||
calWeight: map['cal_weight']?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
CargoType({this.id, this.name, this.rate, this.weight});
|
||||
CargoType({this.id, this.name, this.rate, this.weight, this.calWeight});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
@@ -26,6 +26,7 @@ class CargoType {
|
||||
'name': name,
|
||||
'rate': rate,
|
||||
'weight': weight,
|
||||
'cal_weight': calWeight,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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;
|
||||
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(tc.clone());
|
||||
cargoTypes.add(ct.clone());
|
||||
}
|
||||
actualWeight += tc.weight;
|
||||
totalCalWeight += ct.calWeight;
|
||||
});
|
||||
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);
|
||||
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,
|
||||
Invoice({
|
||||
this.id,
|
||||
this.invoiceNumber,
|
||||
this.invoiceDate,
|
||||
this.customerName,
|
||||
this.customerPhoneNumber,
|
||||
this.userName,
|
||||
this.phoneNumber,
|
||||
this.amount,
|
||||
this.discount,
|
||||
this.status,
|
||||
this.paymentAttachment,
|
||||
this.packages,
|
||||
this.receiptPhotos,
|
||||
this.customDuties,
|
||||
this.cartons,
|
||||
this.cargoTypes,
|
||||
this.handlingFee,
|
||||
this.receipts});
|
||||
|
||||
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p);
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
|
||||
class Receipt {
|
||||
String id;
|
||||
int amount;
|
||||
|
||||
@@ -18,6 +18,7 @@ class Shipment {
|
||||
int numberOfPackage;
|
||||
int weight;
|
||||
double handlingFee;
|
||||
double paidHandlingFee;
|
||||
String address;
|
||||
String status;
|
||||
bool isCourier;
|
||||
@@ -31,6 +32,7 @@ class Shipment {
|
||||
String fcsShipmentID;
|
||||
String fcsShipmentNumber;
|
||||
String shipmentLabelUrl;
|
||||
bool isSelected;
|
||||
|
||||
Shipment(
|
||||
{this.id,
|
||||
@@ -44,6 +46,7 @@ class Shipment {
|
||||
this.numberOfPackage,
|
||||
this.weight,
|
||||
this.handlingFee,
|
||||
this.paidHandlingFee,
|
||||
this.address,
|
||||
this.status,
|
||||
this.pickupDate,
|
||||
@@ -89,6 +92,7 @@ class Shipment {
|
||||
pickupUserName: map['pickup_user_name'],
|
||||
pickupUserPhoneNumber: map['pickup_user_phone_number'],
|
||||
handlingFee: map['handling_fee'],
|
||||
paidHandlingFee: map['paid_handling_fee'],
|
||||
fcsShipmentID: map['fcs_shipment_id'],
|
||||
fcsShipmentNumber: map['fcs_shipment_number'],
|
||||
shipmentLabelUrl: map['shipment_label_url'],
|
||||
@@ -116,6 +120,12 @@ class Shipment {
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is Shipment && other.id == id;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PickUp{id:$id, userName:$userName,phoneNumber:$phoneNumber,numberOfPackage:$numberOfPackage,weight:$weight,status:$status}';
|
||||
|
||||
@@ -89,14 +89,16 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
|
||||
_loadPackages();
|
||||
} else {
|
||||
_carton = Carton(cargoTypes: [], packages: [], cartons: []);
|
||||
_carton = Carton(
|
||||
cargoTypes: [],
|
||||
packages: [],
|
||||
);
|
||||
_lengthController.text = "12";
|
||||
_widthController.text = "12";
|
||||
_heightController.text = "12";
|
||||
_isNew = true;
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_loadFcsShipments();
|
||||
_loadMixCartons();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,16 +114,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
});
|
||||
}
|
||||
|
||||
_loadMixCartons() async {
|
||||
if (_fcsShipment == null) return;
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
var mixCartons =
|
||||
await cartonModel.getMixCartonsByFcsShipment(_fcsShipment.id);
|
||||
setState(() {
|
||||
_mixCartons = mixCartons;
|
||||
});
|
||||
}
|
||||
|
||||
_loadPackages() async {
|
||||
if (_user == null) return;
|
||||
PackageModel packageModel =
|
||||
@@ -159,19 +151,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_populateDeliveryAddress();
|
||||
}
|
||||
|
||||
_loadCartons() async {
|
||||
if (_fcsShipment == null) return;
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
List<Carton> cartons =
|
||||
await cartonModel.getCartonsByFcsShipment(_fcsShipment.id);
|
||||
cartons.forEach((c) {
|
||||
c.isChecked = true;
|
||||
});
|
||||
setState(() {
|
||||
_carton.cartons = cartons;
|
||||
});
|
||||
}
|
||||
|
||||
_populateDeliveryAddress() {
|
||||
if (_carton.packages == null) return;
|
||||
var d = _carton.packages
|
||||
@@ -217,12 +196,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
setState(() {
|
||||
_fcsShipment = v;
|
||||
});
|
||||
if (_selectedCartonType == carton_mix_box) {
|
||||
_loadCartons();
|
||||
}
|
||||
if (_selectedCartonType == carton_small_bag) {
|
||||
_loadMixCartons();
|
||||
}
|
||||
},
|
||||
labelKey: "shipment.pack.fcs.shipment",
|
||||
iconData: Ionicons.ios_airplane,
|
||||
@@ -322,9 +295,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
setState(() {
|
||||
_selectedCartonType = v;
|
||||
});
|
||||
if (_selectedCartonType == carton_mix_box) {
|
||||
_loadCartons();
|
||||
}
|
||||
});
|
||||
|
||||
final cargoTableTitleBox = LocalTitle(
|
||||
@@ -507,9 +477,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
carton.deliveryAddress = _deliveryAddress;
|
||||
carton.cartons = _carton.cartons == null
|
||||
? []
|
||||
: _carton.cartons.where((c) => c.isChecked).toList();
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
@@ -179,14 +179,15 @@ class CartonModel extends BaseModel {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
.collection(path)
|
||||
// .where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||
.where("user_id", isEqualTo: userID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.where("is_invoiced", isEqualTo: false)
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
List<Carton> cartons = querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
return cartons;
|
||||
}
|
||||
|
||||
Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async {
|
||||
|
||||
@@ -49,9 +49,9 @@ class DiscountModel extends BaseModel {
|
||||
.orderBy("code", descending: false)
|
||||
.snapshots()
|
||||
.listen((snaps) {
|
||||
discounts.clear();
|
||||
_discounts.clear();
|
||||
snaps.documents.forEach((d) {
|
||||
discounts.add(Discount.fromMap(d.data, d.documentID));
|
||||
_discounts.add(Discount.fromMap(d.data, d.documentID));
|
||||
});
|
||||
notifyListeners();
|
||||
});
|
||||
@@ -73,6 +73,27 @@ class DiscountModel extends BaseModel {
|
||||
return paginator;
|
||||
}
|
||||
|
||||
Future<List<Discount>> getDiscount(String userID) async {
|
||||
String path = "/$discounts_collection";
|
||||
try {
|
||||
var q = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("customer_id", isEqualTo: userID)
|
||||
.where("status", isEqualTo: "available");
|
||||
var snaps = await q.getDocuments(source: Source.server);
|
||||
List<Discount> discounts = snaps.documents.map((snap) {
|
||||
if (snap.exists) {
|
||||
var s = Discount.fromMap(snap.data, snap.documentID);
|
||||
return s;
|
||||
}
|
||||
}).toList();
|
||||
return discounts;
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
if (_used.ended || _selectedIndex == 1) return;
|
||||
isLoading = true;
|
||||
|
||||
@@ -1,350 +0,0 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/discount/discount_list.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
typedef OnDiscountSelected(Discount discount);
|
||||
typedef OnDeliveryFeeSelected(bool selected);
|
||||
final formatter = new NumberFormat("#,###.00");
|
||||
|
||||
class InvoiceCargoTable extends StatelessWidget {
|
||||
final Invoice invoice;
|
||||
final Rate rate;
|
||||
final OnDiscountSelected discountSelected;
|
||||
final OnDeliveryFeeSelected deliveryFeeSelected;
|
||||
|
||||
const InvoiceCargoTable(
|
||||
{Key key,
|
||||
this.invoice,
|
||||
this.discountSelected,
|
||||
this.deliveryFeeSelected,
|
||||
this.rate})
|
||||
: super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: getRows(context));
|
||||
}
|
||||
|
||||
getRows(BuildContext context) {
|
||||
List<CargoType> _cargoTypes = invoice.getCargoTypes(rate);
|
||||
double total = 0;
|
||||
List<Widget> dataRow = _cargoTypes.map((cargo) {
|
||||
var amount = cargo.calWeight * cargo.calRate;
|
||||
total += amount;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(flex: 2, child: Text('${cargo.name}')),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
'${cargo.calWeight.toStringAsFixed(2)} x ${cargo.calRate.toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.center)),
|
||||
Expanded(
|
||||
child: Text('\$ ${amount.toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)))
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
dataRow.insert(
|
||||
0,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(getLocalString(context, 'invoice.box.cargo_type'),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
getLocalString(context, 'cargo.weight') +
|
||||
' x ' +
|
||||
getLocalString(context, 'cargo.rate'),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey))),
|
||||
Expanded(
|
||||
child: Text(getLocalString(context, 'invoice.amount'),
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.total',
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 40),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'\$ ${total.toStringAsFixed(2)}',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.end,
|
||||
))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.discount_value',
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
new IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () async {
|
||||
Discount discount = await Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
DiscountList(selectionMode: true)));
|
||||
if (discountSelected != null) {
|
||||
discountSelected(discount);
|
||||
}
|
||||
}),
|
||||
Expanded(
|
||||
child:
|
||||
Text('\$ ( ${invoice.getDiscount().toStringAsFixed(2)} )',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 0.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.custom_fee',
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 40),
|
||||
Expanded(
|
||||
child: Text('\$ ${invoice.getCustomFee().toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 20.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.handling_fee',
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 50),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'\$ ${invoice.getHandlingFee().toStringAsFixed(2) ?? ""}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.delivery_fee',
|
||||
color: Colors.black,
|
||||
),
|
||||
)),
|
||||
Switch(
|
||||
value: (invoice.deliveryFee ?? 0) > 0,
|
||||
onChanged: (value) {
|
||||
if (deliveryFeeSelected != null) {
|
||||
deliveryFeeSelected(value);
|
||||
}
|
||||
},
|
||||
activeTrackColor: primaryColor.withOpacity(0.8),
|
||||
activeColor: primaryColor,
|
||||
),
|
||||
Expanded(
|
||||
child:
|
||||
Text('\$ ${invoice.getDeliveryFee().toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text('')),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Divider(
|
||||
thickness: 3,
|
||||
)),
|
||||
],
|
||||
)));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Center(
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.net_amount',
|
||||
color: Colors.black,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: primaryColor)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Center(
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.balance',
|
||||
color: Colors.black,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'\$ ${invoice.getTotalBalance(rate).toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: primaryColor)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
return dataRow;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
@@ -20,7 +19,7 @@ class InvoiceCartonTable extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tableTitle = Container(
|
||||
padding: EdgeInsets.only(right: 10.0, top: 20),
|
||||
padding: EdgeInsets.only(right: 10.0, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
@@ -76,10 +75,6 @@ class InvoiceCartonTable extends StatelessWidget {
|
||||
p.value.cartonNumber,
|
||||
style: textStyle,
|
||||
),
|
||||
Text(
|
||||
p.value.shipmentNumber ?? "",
|
||||
style: textStyle,
|
||||
),
|
||||
],
|
||||
)),
|
||||
Flexible(
|
||||
|
||||
88
lib/pages/invoice/invoice_discount_table.dart
Normal file
88
lib/pages/invoice/invoice_discount_table.dart
Normal file
@@ -0,0 +1,88 @@
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/my_data_table.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class InvoiceDiscountTable extends StatelessWidget {
|
||||
final List<Discount> discounts;
|
||||
|
||||
const InvoiceDiscountTable({
|
||||
Key key,
|
||||
this.discounts,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"invoice.shipment.discount.title",
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: table(context),
|
||||
));
|
||||
}
|
||||
|
||||
Widget table(BuildContext context) {
|
||||
return MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"discount.code",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"discount.amount",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: getRows(context),
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getRows(BuildContext context) {
|
||||
if (discounts == null) {
|
||||
return [];
|
||||
}
|
||||
var rows = discounts.map((c) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (value) => Navigator.pop(context, c),
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.code ?? "",
|
||||
style: textStyle,
|
||||
)),
|
||||
MyDataCell(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(c.amount?.toStringAsFixed(2) ?? "0", style: textStyle),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,33 @@
|
||||
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/fcs_shipment.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/payment_method.dart';
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/domain/entities/user.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||
import 'package:fcs/pages/discount/discount_list.dart';
|
||||
import 'package:fcs/pages/discount/model/discount_model.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_cargo_table.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_discount_table.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_shipment_table.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_table.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_carton_table.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/payment_methods/model/payment_method_model.dart';
|
||||
import 'package:fcs/pages/rates/custom_list.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/shipment/model/shipment_model.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/fcs_icons.dart';
|
||||
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
||||
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
||||
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -44,99 +49,84 @@ class InvoiceEditor extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
User user;
|
||||
User _user;
|
||||
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
TextEditingController _invoiceNumberController = new TextEditingController();
|
||||
TextEditingController _dateController = new TextEditingController();
|
||||
TextEditingController _nameController = new TextEditingController();
|
||||
TextEditingController _phoneController = new TextEditingController();
|
||||
TextEditingController _discountController = new TextEditingController();
|
||||
TextEditingController _amountController = new TextEditingController();
|
||||
TextEditingController _statusController = new TextEditingController();
|
||||
TextEditingController _handlingFeeController = new TextEditingController();
|
||||
TextEditingController _customFeeController = new TextEditingController();
|
||||
MultiImgController multiImgController = MultiImgController();
|
||||
TextEditingController _descriptionController = new TextEditingController();
|
||||
TextEditingController _balanceController = new TextEditingController();
|
||||
|
||||
Invoice _invoice;
|
||||
bool _isLoading = false;
|
||||
List<Carton> _cartons = [];
|
||||
bool isSwitched = false;
|
||||
int deliveryfee = 0;
|
||||
double customFee = 10.0;
|
||||
double handlingFee = 10.0; // it will get from shipment
|
||||
double total = 0;
|
||||
Discount _discount;
|
||||
bool _isNew = false;
|
||||
Discount selectedDiscount;
|
||||
int selectedDiscountAmt;
|
||||
PaymentMethod _paymentMethod;
|
||||
double volumetricRatio = 0;
|
||||
|
||||
List<Carton> selectedBoxes = [];
|
||||
List<CustomDuty> customs = [];
|
||||
|
||||
// List<CargoType> _cargoTypes = [
|
||||
// CargoType(name: 'General Cargo', weight: 33, rate: 6),
|
||||
// CargoType(name: 'Medicine', weight: 33, rate: 7),
|
||||
// CargoType(name: 'Dangerous Cargo', weight: 33, rate: 8)
|
||||
// ];
|
||||
bool _isNew;
|
||||
|
||||
List<bool> isSelected = [false];
|
||||
bool _showCartons = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
||||
.rate
|
||||
.volumetricRatio;
|
||||
_isNew = widget.invoice == null;
|
||||
|
||||
if (widget.invoice != null) {
|
||||
_isNew = false;
|
||||
_invoice = widget.invoice;
|
||||
_invoiceNumberController.text = _invoice.invoiceNumber;
|
||||
_dateController.text = dateFormatter.format(_invoice.invoiceDate);
|
||||
_nameController.text = _invoice.customerName;
|
||||
_phoneController.text = _invoice.customerPhoneNumber;
|
||||
// _amountController.text = _invoice.getAmount.toString();
|
||||
_amountController.text = _invoice.amount.toString();
|
||||
_statusController.text = _invoice.status.toString();
|
||||
_handlingFeeController.text = '0';
|
||||
_customFeeController.text = '0';
|
||||
// multiImgController.setImageUrls = _receipts;
|
||||
_descriptionController.text = 'For Electronics goods';
|
||||
_balanceController.text =
|
||||
(_invoice.amount - _invoice.receipts[0].amount).toString();
|
||||
// _boxes = _invoice.packages;
|
||||
} else {
|
||||
_isNew = true;
|
||||
_dateController.text = dateFormatter.format(DateTime.now());
|
||||
_amountController.text = '0';
|
||||
_handlingFeeController.text = '0';
|
||||
_customFeeController.text = '0';
|
||||
_descriptionController.text = '';
|
||||
_balanceController.text = '0';
|
||||
_invoice = Invoice(customDuties: [], cartons: []);
|
||||
_invoice = Invoice(
|
||||
customDuties: [],
|
||||
cartons: [],
|
||||
shipments: [],
|
||||
invoiceDate: DateTime.now());
|
||||
}
|
||||
_user = widget.customer;
|
||||
_loadAll();
|
||||
}
|
||||
|
||||
if (widget.customer != null && widget.invoice == null) {
|
||||
user = widget.customer;
|
||||
_loadAll() async {
|
||||
setState(() {
|
||||
_isNew = true;
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await _loadCartons();
|
||||
await _loadShipments();
|
||||
await _loadDiscount();
|
||||
} catch (e) {} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
_loadCartons();
|
||||
}
|
||||
|
||||
_loadCartons() async {
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
List<Carton> cartons = await cartonModel.getCartonsForInvoice(
|
||||
widget.fcsShipment.id, widget.customer.id);
|
||||
setState(() {
|
||||
_cartons = cartons;
|
||||
cartons.forEach((c) {
|
||||
c.isChecked = true;
|
||||
});
|
||||
setState(() {
|
||||
_invoice.cartons = cartons;
|
||||
});
|
||||
}
|
||||
|
||||
_loadShipments() async {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
List<Shipment> shipments = await shipmentModel.getShipmentWithHandlingFee(
|
||||
widget.fcsShipment.id, widget.customer.id);
|
||||
shipments.forEach((s) {
|
||||
s.isSelected = true;
|
||||
});
|
||||
setState(() {
|
||||
_invoice.shipments = shipments;
|
||||
});
|
||||
}
|
||||
|
||||
List<Discount> discounts = [];
|
||||
_loadDiscount() async {
|
||||
DiscountModel discountModel =
|
||||
Provider.of<DiscountModel>(context, listen: false);
|
||||
discounts = await discountModel.getDiscount(widget.customer.id);
|
||||
if (discounts != null && discounts.length > 0) {
|
||||
setState(() {
|
||||
_invoice.discount = discounts.first;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -147,38 +137,22 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var mainModel = Provider.of<MainModel>(context);
|
||||
var discountModel = Provider.of<DiscountModel>(context);
|
||||
var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
|
||||
var rateModel = Provider.of<ShipmentRateModel>(context);
|
||||
var rate = rateModel.rate;
|
||||
|
||||
final nameBox = DisplayText(
|
||||
iconData: Feather.user,
|
||||
labelTextKey: 'invoice.customer_name',
|
||||
text: user != null ? user.name : 'Ko Nyi');
|
||||
|
||||
final statusBox = DisplayText(
|
||||
text: _statusController.text,
|
||||
text: _invoice?.status ?? "",
|
||||
iconData: Icons.av_timer,
|
||||
labelTextKey: 'invoice.status');
|
||||
|
||||
final fcsIDBox = DisplayText(
|
||||
text: user != null ? user.fcsID : "FCS-KRUTUG",
|
||||
labelTextKey: "box.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
);
|
||||
final cartonTable = InvoiceCartonTable(
|
||||
cartons: _cartons,
|
||||
cartons: _invoice.cartons,
|
||||
rate: rate,
|
||||
onSelect: (c, checked) {
|
||||
setState(() {
|
||||
c.isChecked = checked;
|
||||
});
|
||||
if (checked) {
|
||||
_invoice.cartons.add(c);
|
||||
} else {
|
||||
_invoice.cartons.remove(c);
|
||||
}
|
||||
},
|
||||
);
|
||||
final customTableHeaderBox = LocalTitle(
|
||||
@@ -196,19 +170,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
onAdd: (c) => _addCustom(c),
|
||||
onRemove: (c) => _removeCustom(c),
|
||||
);
|
||||
var paymentTypesBox = LocalDropdown<PaymentMethod>(
|
||||
final paymentTypesBox = LocalDropdown<PaymentMethod>(
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_paymentMethod = v;
|
||||
_invoice.paymentMethod = v;
|
||||
});
|
||||
},
|
||||
labelKey: "invoice.payment_method",
|
||||
iconData: FontAwesome.money,
|
||||
display: (u) => u.name,
|
||||
selectedValue: _paymentMethod,
|
||||
selectedValue: _invoice.paymentMethod,
|
||||
values: paymentMethodModel.paymentMethods,
|
||||
);
|
||||
final cargoTypeTableBox = InvoiceCargoTable(
|
||||
final invoiceTableBox = InvoiceTable(
|
||||
invoice: _invoice,
|
||||
rate: rate,
|
||||
deliveryFeeSelected: (selected) {
|
||||
@@ -225,6 +199,97 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
_invoice.discount = discount;
|
||||
});
|
||||
},
|
||||
onRemove: (i) {
|
||||
if (i.invoiceDataType == InvoiceDataType.CustomFeeDataType) {
|
||||
_removeCustom(i.data);
|
||||
}
|
||||
if (i.invoiceDataType == InvoiceDataType.DiscountDataType) {
|
||||
setState(() {
|
||||
_invoice.discount = null;
|
||||
});
|
||||
}
|
||||
if (i.invoiceDataType == InvoiceDataType.DeliveryFeeType) {
|
||||
setState(() {
|
||||
_invoice.deliveryFee = 0;
|
||||
});
|
||||
}
|
||||
if (i.invoiceDataType == InvoiceDataType.HandlingFeeType) {
|
||||
setState(() {
|
||||
_removeShipment(i.data);
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
final toggleButtonsBox = ToggleButtons(
|
||||
color: Colors.black45,
|
||||
selectedColor: Colors.black45,
|
||||
disabledColor: Colors.grey,
|
||||
selectedBorderColor: primaryColor,
|
||||
borderColor: Colors.transparent,
|
||||
fillColor: Colors.transparent,
|
||||
highlightColor: Colors.black45,
|
||||
children: <Widget>[
|
||||
Icon(cartonIconData),
|
||||
],
|
||||
onPressed: (int index) {
|
||||
setState(() {
|
||||
_showCartons = !_showCartons;
|
||||
});
|
||||
},
|
||||
isSelected: [_showCartons],
|
||||
);
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
buttonIcon: Icons.add_circle,
|
||||
selectable: false,
|
||||
buttonColor: Colors.black45,
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "invoice.add.custom.fee.menu",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "invoice.add.handling.fee.menu",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
id: 3,
|
||||
textKey: "invoice.add.discount.menu",
|
||||
),
|
||||
LocalPopupMenu(
|
||||
id: 4,
|
||||
textKey: "invoice.delivery_fee",
|
||||
)
|
||||
],
|
||||
popupMenuCallback: (p) async {
|
||||
if (p.id == 1) {
|
||||
CustomDuty customDuty = await Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CustomList(selected: true)));
|
||||
_addCustom(customDuty);
|
||||
} else if (p.id == 2) {
|
||||
Shipment shipment = await Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
InvoiceShipmentTable(shipments: _invoice.shipments)));
|
||||
_addShipment(shipment);
|
||||
} else if (p.id == 3) {
|
||||
Discount discount =
|
||||
await Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => InvoiceDiscountTable(
|
||||
discounts: discounts,
|
||||
)));
|
||||
if (discount != null) {
|
||||
setState(() {
|
||||
_invoice.discount = discount;
|
||||
});
|
||||
}
|
||||
} else if (p.id == 4) {
|
||||
setState(() {
|
||||
_invoice.deliveryFee = rate.deliveryFee;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
@@ -245,31 +310,55 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
LocalTitle(textKey: "invoice.customer_info"),
|
||||
DisplayText(
|
||||
labelTextKey: 'invoice.date',
|
||||
iconData: Icons.date_range,
|
||||
text: _dateController.text),
|
||||
widget.invoice == null
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(dateFormatter.format(_invoice.invoiceDate)),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(_user?.name ?? ""),
|
||||
Text(
|
||||
_user?.fcsID ?? "",
|
||||
style: TextStyle(fontSize: 12),
|
||||
)
|
||||
],
|
||||
),
|
||||
Spacer(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
toggleButtonsBox,
|
||||
popupMenu,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
_isNew
|
||||
? Container()
|
||||
: DisplayText(
|
||||
labelTextKey: 'invoice.number',
|
||||
iconData: FontAwesomeIcons.fileInvoice,
|
||||
text: _invoiceNumberController.text),
|
||||
fcsIDBox,
|
||||
nameBox,
|
||||
text: _invoice?.invoiceNumber ?? ""),
|
||||
_isNew ? Container() : statusBox,
|
||||
SizedBox(height: 20),
|
||||
customTableHeaderBox,
|
||||
customTableBox,
|
||||
SizedBox(height: 20),
|
||||
cartonTable,
|
||||
LocalTitle(textKey: "invoice.cargo_type"),
|
||||
cargoTypeTableBox,
|
||||
// Column(children: getCargoTableByBox(context)),
|
||||
SizedBox(height: 20),
|
||||
_showCartons ? cartonTable : Container(),
|
||||
_showCartons
|
||||
? Divider(
|
||||
color: primaryColor,
|
||||
thickness: 2,
|
||||
)
|
||||
: Container(),
|
||||
invoiceTableBox,
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
paymentTypesBox,
|
||||
SizedBox(height: 20),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
_isNew
|
||||
? Container()
|
||||
: LocalTitle(
|
||||
@@ -277,7 +366,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.add_circle, color: primaryColor),
|
||||
onPressed: () async {})),
|
||||
widget.invoice == null
|
||||
_isNew
|
||||
? fcsButton(
|
||||
context, getLocalString(context, 'invoice.btn_create'))
|
||||
: mainModel.isCustomer()
|
||||
@@ -300,15 +389,6 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
getTotalBalance(total) {
|
||||
double balance = 0;
|
||||
double custom = customFee != 0 ? customFee.toDouble() : 0;
|
||||
double discount = _discount != null ? _discount.amount.toDouble() : 0;
|
||||
double deliveryFee = deliveryfee != 0 ? deliveryfee.toDouble() : 0;
|
||||
balance = (total + custom + deliveryFee) - discount;
|
||||
return balance;
|
||||
}
|
||||
|
||||
_addCustom(CustomDuty customDuty) {
|
||||
if (customDuty == null) return;
|
||||
setState(() {
|
||||
@@ -317,6 +397,24 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
});
|
||||
}
|
||||
|
||||
_addShipment(Shipment shipment) {
|
||||
if (shipment == null) return;
|
||||
shipment.isSelected = true;
|
||||
setState(() {
|
||||
_invoice.shipments.remove(shipment);
|
||||
_invoice.shipments.add(shipment);
|
||||
});
|
||||
}
|
||||
|
||||
_removeShipment(Shipment shipment) {
|
||||
if (shipment == null) return;
|
||||
shipment.isSelected = false;
|
||||
setState(() {
|
||||
_invoice.shipments.remove(shipment);
|
||||
_invoice.shipments.add(shipment);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCustom(CustomDuty customDuty) {
|
||||
setState(() {
|
||||
_invoice.customDuties.remove(customDuty);
|
||||
|
||||
@@ -99,16 +99,14 @@ class _InvoiceInfoPageState extends State<InvoiceInfoPage> {
|
||||
_invoice = widget.invoice;
|
||||
_invoiceNumberController.text = _invoice.invoiceNumber;
|
||||
_dateController.text = dateFormatter.format(_invoice.invoiceDate);
|
||||
_nameController.text = _invoice.customerName;
|
||||
_phoneController.text = _invoice.customerPhoneNumber;
|
||||
_nameController.text = _invoice.userName;
|
||||
_phoneController.text = _invoice.phoneNumber;
|
||||
// _amountController.text = _invoice.getAmount.toString();
|
||||
_amountController.text = _invoice.amount.toString();
|
||||
_statusController.text = _invoice.status.toString();
|
||||
_customFeeController.text = '0';
|
||||
// multiImgController.setImageUrls = _receipts;
|
||||
_descriptionController.text = 'For Electronics goods';
|
||||
_balanceController.text =
|
||||
(_invoice.amount - _invoice.receipts[0].amount).toString();
|
||||
// _boxes = _invoice.packages;
|
||||
} else {
|
||||
_dateController.text = dateFormatter.format(DateTime.now());
|
||||
|
||||
105
lib/pages/invoice/invoice_shipment_table.dart
Normal file
105
lib/pages/invoice/invoice_shipment_table.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/my_data_table.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef OnAdd(Shipment shipment);
|
||||
typedef OnRemove(Shipment shipment);
|
||||
|
||||
class InvoiceShipmentTable extends StatelessWidget {
|
||||
final List<Shipment> shipments;
|
||||
final OnAdd onAdd;
|
||||
final OnRemove onRemove;
|
||||
|
||||
const InvoiceShipmentTable(
|
||||
{Key key, this.shipments, this.onAdd, this.onRemove})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"invoice.shipment.handling.fee.title",
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: table(context),
|
||||
));
|
||||
}
|
||||
|
||||
Widget table(BuildContext context) {
|
||||
return MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"invoice.shipment.number",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"invoice.add.handling.fee.menu",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: getRows(context),
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getRows(BuildContext context) {
|
||||
if (shipments == null) {
|
||||
return [];
|
||||
}
|
||||
var rows = shipments.map((c) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (value) => Navigator.pop(context, c),
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.shipmentNumber ?? "",
|
||||
style: textStyle,
|
||||
)),
|
||||
MyDataCell(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(c.handlingFee?.toStringAsFixed(2) ?? "0",
|
||||
style: textStyle),
|
||||
onRemove == null
|
||||
? SizedBox(
|
||||
width: 50,
|
||||
)
|
||||
: IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
if (onRemove != null) onRemove(c);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
377
lib/pages/invoice/invoice_table.dart
Normal file
377
lib/pages/invoice/invoice_table.dart
Normal file
@@ -0,0 +1,377 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/discount/discount_list.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
typedef OnDiscountSelected(Discount discount);
|
||||
typedef OnDeliveryFeeSelected(bool selected);
|
||||
typedef OnRemove(InvoiceTableRow row);
|
||||
final formatter = new NumberFormat("#,###.00");
|
||||
|
||||
enum InvoiceDataType {
|
||||
CargoDataType,
|
||||
DiscountDataType,
|
||||
CustomFeeDataType,
|
||||
HandlingFeeType,
|
||||
DeliveryFeeType,
|
||||
}
|
||||
|
||||
class InvoiceTableRow {
|
||||
final dynamic data;
|
||||
final String id;
|
||||
final InvoiceDataType invoiceDataType;
|
||||
final String desc;
|
||||
final String rate;
|
||||
final String amount;
|
||||
|
||||
InvoiceTableRow(
|
||||
{this.id,
|
||||
this.data,
|
||||
this.invoiceDataType,
|
||||
this.desc,
|
||||
this.rate,
|
||||
this.amount});
|
||||
}
|
||||
|
||||
class InvoiceTable extends StatelessWidget {
|
||||
final Invoice invoice;
|
||||
final Rate rate;
|
||||
final OnDiscountSelected discountSelected;
|
||||
final OnDeliveryFeeSelected deliveryFeeSelected;
|
||||
final OnRemove onRemove;
|
||||
|
||||
const InvoiceTable(
|
||||
{Key key,
|
||||
this.invoice,
|
||||
this.discountSelected,
|
||||
this.deliveryFeeSelected,
|
||||
this.onRemove,
|
||||
this.rate})
|
||||
: super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: getRows(context));
|
||||
}
|
||||
|
||||
List<InvoiceTableRow> getTableRows() {
|
||||
List<InvoiceTableRow> tableRows = [];
|
||||
// add cargo types
|
||||
List<CargoType> _cargoTypes = invoice.getCargoTypes(rate);
|
||||
_cargoTypes.forEach((c) {
|
||||
tableRows.add(InvoiceTableRow(
|
||||
invoiceDataType: InvoiceDataType.CargoDataType,
|
||||
desc: c.name,
|
||||
rate:
|
||||
"${c.calWeight.toStringAsFixed(2)} x ${c.calRate.toStringAsFixed(2)}",
|
||||
amount: "${c.amount.toStringAsFixed(2)}"));
|
||||
});
|
||||
invoice.shipments.where((ss) => (ss.isSelected ?? false)).forEach((s) {
|
||||
tableRows.add(InvoiceTableRow(
|
||||
data: s,
|
||||
invoiceDataType: InvoiceDataType.HandlingFeeType,
|
||||
desc: "Handling fee\n${s.shipmentNumber}",
|
||||
rate: "",
|
||||
amount: "${s.handlingFee.toStringAsFixed(2)}"));
|
||||
});
|
||||
// add custom fee
|
||||
invoice.customDuties.forEach((c) {
|
||||
tableRows.add(InvoiceTableRow(
|
||||
data: c,
|
||||
invoiceDataType: InvoiceDataType.CustomFeeDataType,
|
||||
desc: "${c.productType} custom fee",
|
||||
rate: "",
|
||||
amount: "${c.fee.toStringAsFixed(2)}"));
|
||||
});
|
||||
// add delivery fee
|
||||
tableRows.add(InvoiceTableRow(
|
||||
data: invoice.deliveryFee == null || invoice.deliveryFee == 0
|
||||
? null
|
||||
: invoice.deliveryFee,
|
||||
invoiceDataType: InvoiceDataType.DeliveryFeeType,
|
||||
desc: "Delivery fee",
|
||||
rate: "",
|
||||
amount: "${invoice?.deliveryFee?.toStringAsFixed(2) ?? '0'}"));
|
||||
|
||||
// add discounts
|
||||
if (invoice.discount != null) {
|
||||
tableRows.add(InvoiceTableRow(
|
||||
data: invoice.discount,
|
||||
invoiceDataType: InvoiceDataType.DiscountDataType,
|
||||
desc: "Discount\n${invoice?.discount?.code ?? ""}",
|
||||
rate: "",
|
||||
amount: "(${invoice?.discount?.amount?.toStringAsFixed(2) ?? ''})"));
|
||||
}
|
||||
|
||||
return tableRows;
|
||||
}
|
||||
|
||||
getRows(BuildContext context) {
|
||||
List<InvoiceTableRow> tableRows = getTableRows();
|
||||
|
||||
List<Widget> dataRow = tableRows.map((r) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(child: Text('${r.desc}')),
|
||||
SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
r.data == null || onRemove == null
|
||||
? Container()
|
||||
: InkWell(
|
||||
onTap: () => onRemove(r),
|
||||
child: Icon(
|
||||
Icons.remove_circle,
|
||||
color: Colors.black45,
|
||||
),
|
||||
)
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text(
|
||||
'${r.rate}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(fontSize: 12),
|
||||
)),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text('\$ ${r.amount}',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
)))
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
dataRow.insert(
|
||||
0,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(getLocalString(context, 'invoice.box.desc'),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
getLocalString(context, 'invoice.weight') +
|
||||
' x ' +
|
||||
getLocalString(context, 'invoice.rate'),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey))),
|
||||
Expanded(
|
||||
child: Text(getLocalString(context, 'invoice.amount'),
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey)))
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
'invoice.total',
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
Text(
|
||||
'\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.end,
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 20.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 1,
|
||||
// child: Container(
|
||||
// alignment: Alignment.centerRight,
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.handling_fee',
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(width: 50),
|
||||
// Expanded(
|
||||
// child: Text(
|
||||
// '\$ ${invoice.getHandlingFee().toStringAsFixed(2) ?? ""}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// )))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 1,
|
||||
// child: Container(
|
||||
// alignment: Alignment.centerRight,
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.delivery_fee',
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// )),
|
||||
// Switch(
|
||||
// value: (invoice.deliveryFee ?? 0) > 0,
|
||||
// onChanged: (value) {
|
||||
// if (deliveryFeeSelected != null) {
|
||||
// deliveryFeeSelected(value);
|
||||
// }
|
||||
// },
|
||||
// activeTrackColor: primaryColor.withOpacity(0.8),
|
||||
// activeColor: primaryColor,
|
||||
// ),
|
||||
// Expanded(
|
||||
// child:
|
||||
// Text('\$ ${invoice.getDeliveryFee().toStringAsFixed(2)}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// )))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(child: Text('')),
|
||||
// Expanded(
|
||||
// flex: 2,
|
||||
// child: Divider(
|
||||
// thickness: 3,
|
||||
// )),
|
||||
// ],
|
||||
// )));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 2,
|
||||
// child: Center(
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.net_amount',
|
||||
// color: Colors.black,
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Expanded(
|
||||
// child: Text(
|
||||
// '\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: primaryColor)))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 2,
|
||||
// child: Center(
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.balance',
|
||||
// color: Colors.black,
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Expanded(
|
||||
// child: Text(
|
||||
// '\$ ${invoice.getTotalBalance(rate).toStringAsFixed(2)}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: primaryColor)))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
return dataRow;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/entities/receipt.dart';
|
||||
import 'package:fcs/domain/vo/message.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
|
||||
class InvoiceModel extends BaseModel {
|
||||
final log = Logger('InvoiceModel');
|
||||
@@ -20,35 +17,11 @@ class InvoiceModel extends BaseModel {
|
||||
Invoice(
|
||||
invoiceNumber: 'A092(A)-33',
|
||||
invoiceDate: DateTime(2020, 4, 6, 12, 15),
|
||||
customerName: 'Ko Myo Min',
|
||||
customerPhoneNumber: '+959 555555555',
|
||||
userName: 'Ko Myo Min',
|
||||
phoneNumber: '+959 555555555',
|
||||
amount: 300,
|
||||
status: 'Pending',
|
||||
receipts: [
|
||||
Receipt(amount: 200, date: '1 Jun 2020'),
|
||||
],
|
||||
packages: [
|
||||
Package(
|
||||
shipmentNumber: "A201",
|
||||
receiverNumber: "1",
|
||||
boxNumber: "1",
|
||||
rate: 9,
|
||||
packageType: "Dangerous",
|
||||
weight: 25,
|
||||
status: "Delivered",
|
||||
arrivedDate: DateTime(2020, 5, 21),
|
||||
receiverAddress: '3 Kambzwza St, Bahan Tsp, Yangon'),
|
||||
Package(
|
||||
shipmentNumber: "A201",
|
||||
receiverNumber: "1",
|
||||
boxNumber: "2",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
weight: 5,
|
||||
status: "Delivered",
|
||||
arrivedDate: DateTime(2020, 5, 21),
|
||||
receiverAddress: '3 Kambzwza St, Bahan Tsp, Yangon'),
|
||||
])
|
||||
)
|
||||
];
|
||||
|
||||
List<Invoice> get invoices =>
|
||||
|
||||
@@ -121,7 +121,7 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
getCustomFeeRows(BuildContext context) {
|
||||
List<Widget> dataRow = [];
|
||||
|
||||
dataRow = _invoice.receipts.asMap().entries.map((receipt) {
|
||||
dataRow = [].asMap().entries.map((receipt) {
|
||||
var r = receipt.value;
|
||||
var k = receipt.key + 1;
|
||||
return Container(
|
||||
|
||||
@@ -148,6 +148,30 @@ class ShipmentModel extends BaseModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<List<Shipment>> getShipmentWithHandlingFee(
|
||||
String fcsShipmentID, String userID) async {
|
||||
String path = "/$shipments_collection";
|
||||
try {
|
||||
var q = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("user_id", isEqualTo: userID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.where("handling_fee", isGreaterThan: 0)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID);
|
||||
var snaps = await q.getDocuments(source: Source.server);
|
||||
List<Shipment> shipments = snaps.documents.map((snap) {
|
||||
if (snap.exists) {
|
||||
var s = Shipment.fromMap(snap.data, snap.documentID);
|
||||
return s;
|
||||
}
|
||||
}).toList();
|
||||
return shipments;
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
|
||||
5
lib/pages/widgets/fcs_icons.dart
Normal file
5
lib/pages/widgets/fcs_icons.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
|
||||
const cartonIconData = MaterialCommunityIcons.package;
|
||||
const customFeeIconData = MaterialCommunityIcons.security;
|
||||
const shipmentIconData = SimpleLineIcons.direction;
|
||||
@@ -12,6 +12,7 @@ class LocalPopupMenuButton extends StatefulWidget {
|
||||
final bool multiSelect;
|
||||
final bool selectable;
|
||||
final IconData buttonIcon;
|
||||
final Color buttonColor;
|
||||
|
||||
const LocalPopupMenuButton(
|
||||
{Key key,
|
||||
@@ -19,7 +20,8 @@ class LocalPopupMenuButton extends StatefulWidget {
|
||||
this.popmenus,
|
||||
this.buttonIcon,
|
||||
this.selectable = true,
|
||||
this.multiSelect = false})
|
||||
this.multiSelect = false,
|
||||
this.buttonColor = primaryColor})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -76,7 +78,7 @@ class _LocalPopupMenuButtonState extends State<LocalPopupMenuButton> {
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
widget.buttonIcon ?? Icons.filter_list,
|
||||
color: primaryColor,
|
||||
color: widget.buttonColor ?? primaryColor,
|
||||
),
|
||||
hightlight
|
||||
? Positioned(
|
||||
|
||||
Reference in New Issue
Block a user