update invoice page
This commit is contained in:
@@ -393,13 +393,13 @@
|
|||||||
"rate.delivery_fee":"Delivery fees",
|
"rate.delivery_fee":"Delivery fees",
|
||||||
"rate.total_estimated_amount":"Total estimated amount",
|
"rate.total_estimated_amount":"Total estimated amount",
|
||||||
"rate.volumetric_ratio":"Volumetric ratio",
|
"rate.volumetric_ratio":"Volumetric ratio",
|
||||||
"rate.custom.form.title":"CUSTOM",
|
"rate.custom.form.title":"Custom",
|
||||||
"rate.cutom.product_type":"Product type",
|
"rate.cutom.product_type":"Product type",
|
||||||
"rate.custom.fee":"Fee",
|
"rate.custom.fee":"Fee",
|
||||||
"rate.discount.weight":"Weight",
|
"rate.discount.weight":"Weight",
|
||||||
"rate.discount.rate":"Discount rate",
|
"rate.discount.rate":"Discount rate",
|
||||||
"rate.custom_duty.title":"Custom Duties",
|
"rate.custom_duty.title":"Custom Fee",
|
||||||
"rate.custom_duty":"Custom Duty",
|
"rate.custom_duty":"Custom Fee",
|
||||||
"rate.cargo.type":"Cargo Types",
|
"rate.cargo.type":"Cargo Types",
|
||||||
"rate.discount_by_weight":"Discounts by weight",
|
"rate.discount_by_weight":"Discounts by weight",
|
||||||
"rate.discount_by_weight.edit.delete.confirm":"Delete this discount by weight?",
|
"rate.discount_by_weight.edit.delete.confirm":"Delete this discount by weight?",
|
||||||
@@ -428,6 +428,8 @@
|
|||||||
"invoice.customer_name":"Customer name",
|
"invoice.customer_name":"Customer name",
|
||||||
"invoice.status":"Status",
|
"invoice.status":"Status",
|
||||||
"invoice.amount":"Amount",
|
"invoice.amount":"Amount",
|
||||||
|
"invoice.weight":"Weight(lb)",
|
||||||
|
"invoice.rate":"Rate(USD)",
|
||||||
"invoice.total":"Total amount",
|
"invoice.total":"Total amount",
|
||||||
"invoice.balance":"Balance",
|
"invoice.balance":"Balance",
|
||||||
"invoice.handling_fee":"Handling fee",
|
"invoice.handling_fee":"Handling fee",
|
||||||
@@ -435,15 +437,16 @@
|
|||||||
"invoice.custom_fee_desc":"Custom fee description",
|
"invoice.custom_fee_desc":"Custom fee description",
|
||||||
"invoice.discount":"Discount code",
|
"invoice.discount":"Discount code",
|
||||||
"invoice.payment_method":"Payment method",
|
"invoice.payment_method":"Payment method",
|
||||||
"invoice.delivery_fee":"Delivery fee : ",
|
"invoice.delivery_fee":"Delivery fee",
|
||||||
"invoice.payment_attachment":"Payment attachment",
|
"invoice.payment_attachment":"Payment attachment",
|
||||||
"invoice.box_info":"Carton information",
|
"invoice.box_info":"Cartons",
|
||||||
"invoice.cargo_table":"Cargo table",
|
"invoice.cargo_table":"Cargo table",
|
||||||
"invoice.btn_create":"Create invoice",
|
"invoice.btn_create":"Create invoice",
|
||||||
"invoice.btn_save":"Save invoice",
|
"invoice.btn_save":"Save invoice",
|
||||||
"invoice.btn_payment_receipt":"Attachment payment receipt",
|
"invoice.btn_payment_receipt":"Attachment payment receipt",
|
||||||
"invoice.description": "Description",
|
"invoice.description": "Description",
|
||||||
"invoice.box.cargo_type": "Cargo types",
|
"invoice.box.cargo_type": "Cargo types",
|
||||||
|
"invoice.box.desc": "Description",
|
||||||
"invoice.cargo_type":"Cargo types",
|
"invoice.cargo_type":"Cargo types",
|
||||||
"invoice.box.number":"Carton number",
|
"invoice.box.number":"Carton number",
|
||||||
"invoice.box.length":"L",
|
"invoice.box.length":"L",
|
||||||
@@ -459,6 +462,12 @@
|
|||||||
"invoice.popupmenu.paid":"Paid",
|
"invoice.popupmenu.paid":"Paid",
|
||||||
"invoice.shipment.title":"Select FCS shipment",
|
"invoice.shipment.title":"Select FCS shipment",
|
||||||
"invoice.customer.title":"Select Customer",
|
"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 ================================================================":"",
|
"Invoices End ================================================================":"",
|
||||||
|
|
||||||
"Discount Start ================================================================":"",
|
"Discount Start ================================================================":"",
|
||||||
|
|||||||
@@ -428,6 +428,8 @@
|
|||||||
"invoice.customer_name":"ဝယ်ယူသူနာမည်",
|
"invoice.customer_name":"ဝယ်ယူသူနာမည်",
|
||||||
"invoice.status":"အခြေအနေ",
|
"invoice.status":"အခြေအနေ",
|
||||||
"invoice.amount":"ပမာဏ",
|
"invoice.amount":"ပမာဏ",
|
||||||
|
"invoice.weight":"Weight(lb)",
|
||||||
|
"invoice.rate":"Rate(USD)",
|
||||||
"invoice.total":"စုစုပေါင်းပမာဏ",
|
"invoice.total":"စုစုပေါင်းပမာဏ",
|
||||||
"invoice.balance":"ပေးချေရန်ကျန်ရှိငွေ",
|
"invoice.balance":"ပေးချေရန်ကျန်ရှိငွေ",
|
||||||
"invoice.handling_fee":"ထိန်းသိမ်းခ",
|
"invoice.handling_fee":"ထိန်းသိမ်းခ",
|
||||||
@@ -437,7 +439,7 @@
|
|||||||
"invoice.payment_method":"ငွေပေးချေစနစ်",
|
"invoice.payment_method":"ငွေပေးချေစနစ်",
|
||||||
"invoice.delivery_fee":"ပို့ဆောင်ခ",
|
"invoice.delivery_fee":"ပို့ဆောင်ခ",
|
||||||
"invoice.payment_attachment":"ပေးချေပြီးဖိုင်များ",
|
"invoice.payment_attachment":"ပေးချေပြီးဖိုင်များ",
|
||||||
"invoice.box_info":"Box အချက်အလက်",
|
"invoice.box_info":"Cartons",
|
||||||
"invoice.cargo_table":"ကုန်ပစ္စည်းဇယား",
|
"invoice.cargo_table":"ကုန်ပစ္စည်းဇယား",
|
||||||
"invoice.btn_create":"ငွေတောင်းခံလွှာ ပြုလုပ်ရန်",
|
"invoice.btn_create":"ငွေတောင်းခံလွှာ ပြုလုပ်ရန်",
|
||||||
"invoice.btn_save":"ငွေတောင်းခံလွှာ သိမ်းရန်",
|
"invoice.btn_save":"ငွေတောင်းခံလွှာ သိမ်းရန်",
|
||||||
@@ -445,6 +447,7 @@
|
|||||||
"invoice.box.cargo_type": "ကုန်ပစ္စည်းအမျိုးအစားများ",
|
"invoice.box.cargo_type": "ကုန်ပစ္စည်းအမျိုးအစားများ",
|
||||||
"invoice.description": "ငွေတောင်းခံလွှာအကြောင်းအရာ",
|
"invoice.description": "ငွေတောင်းခံလွှာအကြောင်းအရာ",
|
||||||
"invoice.cargo_type":"Cargo Types",
|
"invoice.cargo_type":"Cargo Types",
|
||||||
|
"invoice.box.desc": "Description",
|
||||||
"invoice.box.number":"Box နံပါတ်",
|
"invoice.box.number":"Box နံပါတ်",
|
||||||
"invoice.box.length":"L",
|
"invoice.box.length":"L",
|
||||||
"invoice.box.width":"W",
|
"invoice.box.width":"W",
|
||||||
@@ -459,6 +462,12 @@
|
|||||||
"invoice.popupmenu.paid":"Paid",
|
"invoice.popupmenu.paid":"Paid",
|
||||||
"invoice.shipment.title":"Select FCS shipment",
|
"invoice.shipment.title":"Select FCS shipment",
|
||||||
"invoice.customer.title":"Select Customer",
|
"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 ================================================================":"",
|
"Invoices End ================================================================":"",
|
||||||
|
|
||||||
"Discount Start ================================================================":"",
|
"Discount Start ================================================================":"",
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ class CargoType {
|
|||||||
double rate;
|
double rate;
|
||||||
double weight;
|
double weight;
|
||||||
|
|
||||||
int shipmentWeight;
|
|
||||||
double amount;
|
double amount;
|
||||||
|
|
||||||
double calRate;
|
double calRate;
|
||||||
@@ -16,9 +15,10 @@ class CargoType {
|
|||||||
name: map['name'],
|
name: map['name'],
|
||||||
rate: map['rate']?.toDouble() ?? 0,
|
rate: map['rate']?.toDouble() ?? 0,
|
||||||
weight: map['weight']?.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() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
@@ -26,6 +26,7 @@ class CargoType {
|
|||||||
'name': name,
|
'name': name,
|
||||||
'rate': rate,
|
'rate': rate,
|
||||||
'weight': weight,
|
'weight': weight,
|
||||||
|
'cal_weight': calWeight,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
||||||
import 'package:fcs/domain/entities/rate.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/shipment_status.dart';
|
||||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ import 'package.dart';
|
|||||||
|
|
||||||
class Carton {
|
class Carton {
|
||||||
String id;
|
String id;
|
||||||
|
String shipmentID;
|
||||||
String shipmentNumber;
|
String shipmentNumber;
|
||||||
String senderFCSID;
|
String senderFCSID;
|
||||||
String senderName;
|
String senderName;
|
||||||
@@ -47,9 +49,9 @@ class Carton {
|
|||||||
List<String> packageIDs;
|
List<String> packageIDs;
|
||||||
List<Package> packages;
|
List<Package> packages;
|
||||||
List<CargoType> cargoTypes;
|
List<CargoType> cargoTypes;
|
||||||
List<Carton> cartons;
|
|
||||||
|
|
||||||
DeliveryAddress deliveryAddress;
|
DeliveryAddress deliveryAddress;
|
||||||
|
Shipment shipment;
|
||||||
|
|
||||||
int get amount => rate != null && weight != null ? rate * weight : 0;
|
int get amount => rate != null && weight != null ? rate * weight : 0;
|
||||||
|
|
||||||
@@ -73,6 +75,23 @@ class Carton {
|
|||||||
return (length * width * height) / volumetricRatio;
|
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
|
/// calAmount returns total amount
|
||||||
double calAmount(Rate rate) {
|
double calAmount(Rate rate) {
|
||||||
// get shipment weight
|
// get shipment weight
|
||||||
@@ -101,6 +120,7 @@ class Carton {
|
|||||||
|
|
||||||
Carton(
|
Carton(
|
||||||
{this.id,
|
{this.id,
|
||||||
|
this.shipmentID,
|
||||||
this.shipmentNumber,
|
this.shipmentNumber,
|
||||||
this.senderFCSID,
|
this.senderFCSID,
|
||||||
this.senderName,
|
this.senderName,
|
||||||
@@ -133,7 +153,6 @@ class Carton {
|
|||||||
this.cartonNumber,
|
this.cartonNumber,
|
||||||
this.fcsShipmentID,
|
this.fcsShipmentID,
|
||||||
this.fcsShipmentNumber,
|
this.fcsShipmentNumber,
|
||||||
this.cartons,
|
|
||||||
this.packageIDs,
|
this.packageIDs,
|
||||||
this.mixCartonID,
|
this.mixCartonID,
|
||||||
this.mixCartonNumber,
|
this.mixCartonNumber,
|
||||||
@@ -143,7 +162,6 @@ class Carton {
|
|||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
||||||
List _packages = packages?.map((c) => c.toJson())?.toList();
|
List _packages = packages?.map((c) => c.toJson())?.toList();
|
||||||
List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? [];
|
|
||||||
return {
|
return {
|
||||||
"id": id,
|
"id": id,
|
||||||
'fcs_shipment_id': fcsShipmentID,
|
'fcs_shipment_id': fcsShipmentID,
|
||||||
@@ -155,8 +173,7 @@ class Carton {
|
|||||||
'height': height,
|
'height': height,
|
||||||
'delivery_address': deliveryAddress.toMap(),
|
'delivery_address': deliveryAddress.toMap(),
|
||||||
'carton_type': cartonType,
|
'carton_type': cartonType,
|
||||||
'cartons': _cartons,
|
'mix_carton_id': mixCartonID,
|
||||||
'mix_carton_id': mixCartonID
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +188,7 @@ class Carton {
|
|||||||
return Carton(
|
return Carton(
|
||||||
id: docID,
|
id: docID,
|
||||||
arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null,
|
arrivedDate: _arrivedDate != null ? _arrivedDate.toDate() : null,
|
||||||
|
shipmentID: map['shipment_id'],
|
||||||
shipmentNumber: map['shipment_number'],
|
shipmentNumber: map['shipment_number'],
|
||||||
receiverNumber: map['receiver_number'],
|
receiverNumber: map['receiver_number'],
|
||||||
boxNumber: map['box_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/custom_duty.dart';
|
||||||
import 'package:fcs/domain/entities/discount.dart';
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/domain/entities/discount_by_weight.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:fcs/domain/entities/rate.dart';
|
||||||
|
import 'package:fcs/domain/entities/shipment.dart';
|
||||||
import 'package.dart';
|
|
||||||
import 'receipt.dart';
|
|
||||||
|
|
||||||
class Invoice {
|
class Invoice {
|
||||||
String id;
|
String id;
|
||||||
String invoiceNumber;
|
String invoiceNumber;
|
||||||
DateTime invoiceDate;
|
DateTime invoiceDate;
|
||||||
String customerName;
|
String fcsShipmentID;
|
||||||
String customerPhoneNumber;
|
String userID;
|
||||||
double amount;
|
String userName;
|
||||||
|
String phoneNumber;
|
||||||
String status;
|
String status;
|
||||||
String paymentAttachment;
|
|
||||||
double handlingFee;
|
double handlingFee;
|
||||||
double deliveryFee;
|
double deliveryFee;
|
||||||
double paidAmount;
|
double paidAmount;
|
||||||
|
double amount;
|
||||||
|
|
||||||
List<Package> packages;
|
|
||||||
List<Receipt> receipts;
|
|
||||||
List<String> receiptPhotos;
|
|
||||||
List<CustomDuty> customDuties;
|
List<CustomDuty> customDuties;
|
||||||
List<Carton> cartons;
|
List<Carton> cartons;
|
||||||
|
List<CargoType> cargoTypes;
|
||||||
|
List<Shipment> shipments;
|
||||||
Discount discount;
|
Discount discount;
|
||||||
|
PaymentMethod paymentMethod;
|
||||||
|
|
||||||
List<CargoType> getCargoTypes(Rate rate) {
|
List<CargoType> getCargoTypes(Rate rate) {
|
||||||
List<CargoType> cargoTypes = [];
|
List<CargoType> cargoTypes = [];
|
||||||
double actualWeight = 0;
|
double totalCalWeight = 0;
|
||||||
double shipmentWeight = 0;
|
cartons.forEach((carton) {
|
||||||
cartons.forEach((c) {
|
if (carton.isChecked) {
|
||||||
c.cargoTypes.forEach((tc) {
|
var _cartonsTypes =
|
||||||
if (cargoTypes.contains(tc)) {
|
carton.getCargoTypeForCalWeight(rate.volumetricRatio);
|
||||||
CargoType existing = cargoTypes.firstWhere((wc) => wc.id == tc.id);
|
_cartonsTypes.forEach((ct) {
|
||||||
existing.weight += tc.weight;
|
if (cargoTypes.contains(ct)) {
|
||||||
} else {
|
CargoType existing = cargoTypes.firstWhere((wc) => wc.id == ct.id);
|
||||||
cargoTypes.add(tc.clone());
|
existing.calWeight += ct.calWeight;
|
||||||
}
|
} else {
|
||||||
actualWeight += tc.weight;
|
cargoTypes.add(ct.clone());
|
||||||
});
|
}
|
||||||
double volume = (c.length ?? 0) * (c.width ?? 0) * (c.height ?? 0);
|
totalCalWeight += ct.calWeight;
|
||||||
double sw = volume / rate.volumetricRatio ?? 0;
|
});
|
||||||
shipmentWeight += sw;
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DiscountByWeight discountByWeight = rate.getDiscountByWeight(
|
DiscountByWeight discountByWeight =
|
||||||
shipmentWeight > actualWeight ? shipmentWeight : actualWeight);
|
rate.getDiscountByWeight(totalCalWeight);
|
||||||
|
|
||||||
cargoTypes.forEach((e) {
|
cargoTypes.forEach((e) {
|
||||||
print(actualWeight > shipmentWeight);
|
|
||||||
double cargoWeight = actualWeight > shipmentWeight
|
|
||||||
? e.weight
|
|
||||||
: e.weight / actualWeight * shipmentWeight;
|
|
||||||
double r =
|
double r =
|
||||||
e.rate - (discountByWeight != null ? discountByWeight.discount : 0);
|
e.rate - (discountByWeight != null ? discountByWeight.discount : 0);
|
||||||
double amount = cargoWeight * r;
|
double amount = e.calWeight * r;
|
||||||
e.calRate = r;
|
e.calRate = r;
|
||||||
e.calWeight = cargoWeight;
|
|
||||||
e.amount = amount;
|
e.amount = amount;
|
||||||
});
|
});
|
||||||
return cargoTypes;
|
return cargoTypes;
|
||||||
@@ -81,6 +77,12 @@ class Invoice {
|
|||||||
return total;
|
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) {
|
double getTotalBalance(Rate rate) {
|
||||||
return getNetAmount(rate) - (paidAmount ?? 0);
|
return getNetAmount(rate) - (paidAmount ?? 0);
|
||||||
}
|
}
|
||||||
@@ -89,49 +91,57 @@ class Invoice {
|
|||||||
return customDuties == null ? 0 : customDuties.fold(0, (p, d) => p + d.fee);
|
return customDuties == null ? 0 : customDuties.fold(0, (p, d) => p + d.fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getHandlingFee() {
|
|
||||||
return handlingFee == null ? 0 : handlingFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
double getDeliveryFee() {
|
double getDeliveryFee() {
|
||||||
return deliveryFee == null ? 0 : deliveryFee;
|
return deliveryFee == null ? 0 : deliveryFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getDiscount() => discount == null ? 0 : discount.amount;
|
double getDiscount() => discount == null ? 0 : discount.amount;
|
||||||
|
|
||||||
Invoice(
|
Invoice({
|
||||||
{this.id,
|
this.id,
|
||||||
this.invoiceNumber,
|
this.invoiceNumber,
|
||||||
this.invoiceDate,
|
this.invoiceDate,
|
||||||
this.customerName,
|
this.userName,
|
||||||
this.customerPhoneNumber,
|
this.phoneNumber,
|
||||||
this.amount,
|
this.amount,
|
||||||
this.discount,
|
this.discount,
|
||||||
this.status,
|
this.status,
|
||||||
this.paymentAttachment,
|
this.customDuties,
|
||||||
this.packages,
|
this.cartons,
|
||||||
this.receiptPhotos,
|
this.cargoTypes,
|
||||||
this.customDuties,
|
this.handlingFee,
|
||||||
this.cartons,
|
this.fcsShipmentID,
|
||||||
this.handlingFee,
|
this.shipments,
|
||||||
this.receipts});
|
});
|
||||||
|
|
||||||
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p);
|
|
||||||
|
|
||||||
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
|
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
|
||||||
return Invoice(
|
return Invoice(
|
||||||
id: docID,
|
id: docID,
|
||||||
invoiceNumber: map['invoice_number'],
|
invoiceNumber: map['invoice_number'],
|
||||||
invoiceDate: map['invoice_date'],
|
invoiceDate: map['invoice_date'],
|
||||||
customerName: map['customer_name'],
|
userName: map['user_name'],
|
||||||
customerPhoneNumber: map['phone_number'],
|
phoneNumber: map['phone_number'],
|
||||||
amount: map['amount'],
|
amount: map['amount'],
|
||||||
status: map['status'],
|
status: map['status'],
|
||||||
discount: map['discount'],
|
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 {
|
class Receipt {
|
||||||
String id;
|
String id;
|
||||||
int amount;
|
int amount;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class Shipment {
|
|||||||
int numberOfPackage;
|
int numberOfPackage;
|
||||||
int weight;
|
int weight;
|
||||||
double handlingFee;
|
double handlingFee;
|
||||||
|
double paidHandlingFee;
|
||||||
String address;
|
String address;
|
||||||
String status;
|
String status;
|
||||||
bool isCourier;
|
bool isCourier;
|
||||||
@@ -31,6 +32,7 @@ class Shipment {
|
|||||||
String fcsShipmentID;
|
String fcsShipmentID;
|
||||||
String fcsShipmentNumber;
|
String fcsShipmentNumber;
|
||||||
String shipmentLabelUrl;
|
String shipmentLabelUrl;
|
||||||
|
bool isSelected;
|
||||||
|
|
||||||
Shipment(
|
Shipment(
|
||||||
{this.id,
|
{this.id,
|
||||||
@@ -44,6 +46,7 @@ class Shipment {
|
|||||||
this.numberOfPackage,
|
this.numberOfPackage,
|
||||||
this.weight,
|
this.weight,
|
||||||
this.handlingFee,
|
this.handlingFee,
|
||||||
|
this.paidHandlingFee,
|
||||||
this.address,
|
this.address,
|
||||||
this.status,
|
this.status,
|
||||||
this.pickupDate,
|
this.pickupDate,
|
||||||
@@ -89,6 +92,7 @@ class Shipment {
|
|||||||
pickupUserName: map['pickup_user_name'],
|
pickupUserName: map['pickup_user_name'],
|
||||||
pickupUserPhoneNumber: map['pickup_user_phone_number'],
|
pickupUserPhoneNumber: map['pickup_user_phone_number'],
|
||||||
handlingFee: map['handling_fee'],
|
handlingFee: map['handling_fee'],
|
||||||
|
paidHandlingFee: map['paid_handling_fee'],
|
||||||
fcsShipmentID: map['fcs_shipment_id'],
|
fcsShipmentID: map['fcs_shipment_id'],
|
||||||
fcsShipmentNumber: map['fcs_shipment_number'],
|
fcsShipmentNumber: map['fcs_shipment_number'],
|
||||||
shipmentLabelUrl: map['shipment_label_url'],
|
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
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'PickUp{id:$id, userName:$userName,phoneNumber:$phoneNumber,numberOfPackage:$numberOfPackage,weight:$weight,status:$status}';
|
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);
|
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
|
||||||
_loadPackages();
|
_loadPackages();
|
||||||
} else {
|
} else {
|
||||||
_carton = Carton(cargoTypes: [], packages: [], cartons: []);
|
_carton = Carton(
|
||||||
|
cargoTypes: [],
|
||||||
|
packages: [],
|
||||||
|
);
|
||||||
_lengthController.text = "12";
|
_lengthController.text = "12";
|
||||||
_widthController.text = "12";
|
_widthController.text = "12";
|
||||||
_heightController.text = "12";
|
_heightController.text = "12";
|
||||||
_isNew = true;
|
_isNew = true;
|
||||||
_selectedCartonType = carton_from_packages;
|
_selectedCartonType = carton_from_packages;
|
||||||
_loadFcsShipments();
|
_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 {
|
_loadPackages() async {
|
||||||
if (_user == null) return;
|
if (_user == null) return;
|
||||||
PackageModel packageModel =
|
PackageModel packageModel =
|
||||||
@@ -159,19 +151,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
_populateDeliveryAddress();
|
_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() {
|
_populateDeliveryAddress() {
|
||||||
if (_carton.packages == null) return;
|
if (_carton.packages == null) return;
|
||||||
var d = _carton.packages
|
var d = _carton.packages
|
||||||
@@ -217,12 +196,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_fcsShipment = v;
|
_fcsShipment = v;
|
||||||
});
|
});
|
||||||
if (_selectedCartonType == carton_mix_box) {
|
|
||||||
_loadCartons();
|
|
||||||
}
|
|
||||||
if (_selectedCartonType == carton_small_bag) {
|
|
||||||
_loadMixCartons();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
labelKey: "shipment.pack.fcs.shipment",
|
labelKey: "shipment.pack.fcs.shipment",
|
||||||
iconData: Ionicons.ios_airplane,
|
iconData: Ionicons.ios_airplane,
|
||||||
@@ -322,9 +295,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_selectedCartonType = v;
|
_selectedCartonType = v;
|
||||||
});
|
});
|
||||||
if (_selectedCartonType == carton_mix_box) {
|
|
||||||
_loadCartons();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final cargoTableTitleBox = LocalTitle(
|
final cargoTableTitleBox = LocalTitle(
|
||||||
@@ -507,9 +477,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
carton.width = w;
|
carton.width = w;
|
||||||
carton.height = h;
|
carton.height = h;
|
||||||
carton.deliveryAddress = _deliveryAddress;
|
carton.deliveryAddress = _deliveryAddress;
|
||||||
carton.cartons = _carton.cartons == null
|
|
||||||
? []
|
|
||||||
: _carton.cartons.where((c) => c.isChecked).toList();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -179,14 +179,15 @@ class CartonModel extends BaseModel {
|
|||||||
String path = "/$cartons_collection";
|
String path = "/$cartons_collection";
|
||||||
var querySnap = await Firestore.instance
|
var querySnap = await Firestore.instance
|
||||||
.collection(path)
|
.collection(path)
|
||||||
// .where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||||
.where("user_id", isEqualTo: userID)
|
.where("user_id", isEqualTo: userID)
|
||||||
.where("is_deleted", isEqualTo: false)
|
.where("is_deleted", isEqualTo: false)
|
||||||
.where("is_invoiced", isEqualTo: false)
|
.where("is_invoiced", isEqualTo: false)
|
||||||
.getDocuments();
|
.getDocuments();
|
||||||
return querySnap.documents
|
List<Carton> cartons = querySnap.documents
|
||||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||||
.toList();
|
.toList();
|
||||||
|
return cartons;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async {
|
Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async {
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ class DiscountModel extends BaseModel {
|
|||||||
.orderBy("code", descending: false)
|
.orderBy("code", descending: false)
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.listen((snaps) {
|
.listen((snaps) {
|
||||||
discounts.clear();
|
_discounts.clear();
|
||||||
snaps.documents.forEach((d) {
|
snaps.documents.forEach((d) {
|
||||||
discounts.add(Discount.fromMap(d.data, d.documentID));
|
_discounts.add(Discount.fromMap(d.data, d.documentID));
|
||||||
});
|
});
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
});
|
});
|
||||||
@@ -73,6 +73,27 @@ class DiscountModel extends BaseModel {
|
|||||||
return paginator;
|
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 {
|
Future<void> loadMore() async {
|
||||||
if (_used.ended || _selectedIndex == 1) return;
|
if (_used.ended || _selectedIndex == 1) return;
|
||||||
isLoading = true;
|
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/carton.dart';
|
||||||
import 'package:fcs/domain/entities/package.dart';
|
|
||||||
import 'package:fcs/domain/entities/rate.dart';
|
import 'package:fcs/domain/entities/rate.dart';
|
||||||
import 'package:fcs/helpers/theme.dart';
|
import 'package:fcs/helpers/theme.dart';
|
||||||
import 'package:fcs/pages/widgets/local_text.dart';
|
import 'package:fcs/pages/widgets/local_text.dart';
|
||||||
@@ -20,7 +19,7 @@ class InvoiceCartonTable extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final tableTitle = Container(
|
final tableTitle = Container(
|
||||||
padding: EdgeInsets.only(right: 10.0, top: 20),
|
padding: EdgeInsets.only(right: 10.0, top: 5),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@@ -76,10 +75,6 @@ class InvoiceCartonTable extends StatelessWidget {
|
|||||||
p.value.cartonNumber,
|
p.value.cartonNumber,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
),
|
),
|
||||||
Text(
|
|
||||||
p.value.shipmentNumber ?? "",
|
|
||||||
style: textStyle,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
Flexible(
|
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/carton.dart';
|
||||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||||
import 'package:fcs/domain/entities/discount.dart';
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||||
import 'package:fcs/domain/entities/invoice.dart';
|
import 'package:fcs/domain/entities/invoice.dart';
|
||||||
import 'package:fcs/domain/entities/payment_method.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/domain/entities/user.dart';
|
||||||
import 'package:fcs/helpers/theme.dart';
|
import 'package:fcs/helpers/theme.dart';
|
||||||
import 'package:fcs/pages/carton/model/carton_model.dart';
|
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||||
import 'package:fcs/pages/discount/discount_list.dart';
|
import 'package:fcs/pages/discount/discount_list.dart';
|
||||||
import 'package:fcs/pages/discount/model/discount_model.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/invoice/invoice_carton_table.dart';
|
||||||
import 'package:fcs/pages/main/model/main_model.dart';
|
import 'package:fcs/pages/main/model/main_model.dart';
|
||||||
import 'package:fcs/pages/main/util.dart';
|
import 'package:fcs/pages/main/util.dart';
|
||||||
import 'package:fcs/pages/payment_methods/model/payment_method_model.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/custom_list.dart';
|
||||||
import 'package:fcs/pages/rates/model/shipment_rate_model.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/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/fcs_id_icon.dart';
|
||||||
import 'package:fcs/pages/widgets/local_dropdown.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_text.dart';
|
||||||
import 'package:fcs/pages/widgets/local_title.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:fcs/pages/widgets/progress.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -44,99 +49,84 @@ class InvoiceEditor extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _InvoiceEditorState extends State<InvoiceEditor> {
|
class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||||
User user;
|
User _user;
|
||||||
|
|
||||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
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;
|
Invoice _invoice;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
List<Carton> _cartons = [];
|
bool _isNew;
|
||||||
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)
|
|
||||||
// ];
|
|
||||||
|
|
||||||
|
List<bool> isSelected = [false];
|
||||||
|
bool _showCartons = false;
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_isNew = widget.invoice == null;
|
||||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
|
||||||
.rate
|
|
||||||
.volumetricRatio;
|
|
||||||
|
|
||||||
if (widget.invoice != null) {
|
if (widget.invoice != null) {
|
||||||
_isNew = false;
|
|
||||||
_invoice = widget.invoice;
|
_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 {
|
} else {
|
||||||
_isNew = true;
|
_invoice = Invoice(
|
||||||
_dateController.text = dateFormatter.format(DateTime.now());
|
customDuties: [],
|
||||||
_amountController.text = '0';
|
cartons: [],
|
||||||
_handlingFeeController.text = '0';
|
shipments: [],
|
||||||
_customFeeController.text = '0';
|
invoiceDate: DateTime.now());
|
||||||
_descriptionController.text = '';
|
|
||||||
_balanceController.text = '0';
|
|
||||||
_invoice = Invoice(customDuties: [], cartons: []);
|
|
||||||
}
|
}
|
||||||
|
_user = widget.customer;
|
||||||
|
_loadAll();
|
||||||
|
}
|
||||||
|
|
||||||
if (widget.customer != null && widget.invoice == null) {
|
_loadAll() async {
|
||||||
user = widget.customer;
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await _loadCartons();
|
||||||
|
await _loadShipments();
|
||||||
|
await _loadDiscount();
|
||||||
|
} catch (e) {} finally {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isNew = true;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadCartons();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadCartons() async {
|
_loadCartons() async {
|
||||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||||
List<Carton> cartons = await cartonModel.getCartonsForInvoice(
|
List<Carton> cartons = await cartonModel.getCartonsForInvoice(
|
||||||
widget.fcsShipment.id, widget.customer.id);
|
widget.fcsShipment.id, widget.customer.id);
|
||||||
setState(() {
|
cartons.forEach((c) {
|
||||||
_cartons = cartons;
|
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
|
@override
|
||||||
@@ -147,38 +137,22 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var mainModel = Provider.of<MainModel>(context);
|
var mainModel = Provider.of<MainModel>(context);
|
||||||
var discountModel = Provider.of<DiscountModel>(context);
|
|
||||||
var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
|
var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
|
||||||
var rateModel = Provider.of<ShipmentRateModel>(context);
|
var rateModel = Provider.of<ShipmentRateModel>(context);
|
||||||
var rate = rateModel.rate;
|
var rate = rateModel.rate;
|
||||||
|
|
||||||
final nameBox = DisplayText(
|
|
||||||
iconData: Feather.user,
|
|
||||||
labelTextKey: 'invoice.customer_name',
|
|
||||||
text: user != null ? user.name : 'Ko Nyi');
|
|
||||||
|
|
||||||
final statusBox = DisplayText(
|
final statusBox = DisplayText(
|
||||||
text: _statusController.text,
|
text: _invoice?.status ?? "",
|
||||||
iconData: Icons.av_timer,
|
iconData: Icons.av_timer,
|
||||||
labelTextKey: 'invoice.status');
|
labelTextKey: 'invoice.status');
|
||||||
|
|
||||||
final fcsIDBox = DisplayText(
|
|
||||||
text: user != null ? user.fcsID : "FCS-KRUTUG",
|
|
||||||
labelTextKey: "box.fcs.id",
|
|
||||||
icon: FcsIDIcon(),
|
|
||||||
);
|
|
||||||
final cartonTable = InvoiceCartonTable(
|
final cartonTable = InvoiceCartonTable(
|
||||||
cartons: _cartons,
|
cartons: _invoice.cartons,
|
||||||
rate: rate,
|
rate: rate,
|
||||||
onSelect: (c, checked) {
|
onSelect: (c, checked) {
|
||||||
setState(() {
|
setState(() {
|
||||||
c.isChecked = checked;
|
c.isChecked = checked;
|
||||||
});
|
});
|
||||||
if (checked) {
|
|
||||||
_invoice.cartons.add(c);
|
|
||||||
} else {
|
|
||||||
_invoice.cartons.remove(c);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
final customTableHeaderBox = LocalTitle(
|
final customTableHeaderBox = LocalTitle(
|
||||||
@@ -196,19 +170,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
|||||||
onAdd: (c) => _addCustom(c),
|
onAdd: (c) => _addCustom(c),
|
||||||
onRemove: (c) => _removeCustom(c),
|
onRemove: (c) => _removeCustom(c),
|
||||||
);
|
);
|
||||||
var paymentTypesBox = LocalDropdown<PaymentMethod>(
|
final paymentTypesBox = LocalDropdown<PaymentMethod>(
|
||||||
callback: (v) {
|
callback: (v) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_paymentMethod = v;
|
_invoice.paymentMethod = v;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
labelKey: "invoice.payment_method",
|
labelKey: "invoice.payment_method",
|
||||||
iconData: FontAwesome.money,
|
iconData: FontAwesome.money,
|
||||||
display: (u) => u.name,
|
display: (u) => u.name,
|
||||||
selectedValue: _paymentMethod,
|
selectedValue: _invoice.paymentMethod,
|
||||||
values: paymentMethodModel.paymentMethods,
|
values: paymentMethodModel.paymentMethods,
|
||||||
);
|
);
|
||||||
final cargoTypeTableBox = InvoiceCargoTable(
|
final invoiceTableBox = InvoiceTable(
|
||||||
invoice: _invoice,
|
invoice: _invoice,
|
||||||
rate: rate,
|
rate: rate,
|
||||||
deliveryFeeSelected: (selected) {
|
deliveryFeeSelected: (selected) {
|
||||||
@@ -225,6 +199,97 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
|||||||
_invoice.discount = discount;
|
_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(
|
return LocalProgress(
|
||||||
@@ -245,31 +310,55 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
LocalTitle(textKey: "invoice.customer_info"),
|
Row(
|
||||||
DisplayText(
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
labelTextKey: 'invoice.date',
|
children: [
|
||||||
iconData: Icons.date_range,
|
Column(
|
||||||
text: _dateController.text),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
widget.invoice == null
|
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()
|
? Container()
|
||||||
: DisplayText(
|
: DisplayText(
|
||||||
labelTextKey: 'invoice.number',
|
labelTextKey: 'invoice.number',
|
||||||
iconData: FontAwesomeIcons.fileInvoice,
|
iconData: FontAwesomeIcons.fileInvoice,
|
||||||
text: _invoiceNumberController.text),
|
text: _invoice?.invoiceNumber ?? ""),
|
||||||
fcsIDBox,
|
|
||||||
nameBox,
|
|
||||||
_isNew ? Container() : statusBox,
|
_isNew ? Container() : statusBox,
|
||||||
SizedBox(height: 20),
|
_showCartons ? cartonTable : Container(),
|
||||||
customTableHeaderBox,
|
_showCartons
|
||||||
customTableBox,
|
? Divider(
|
||||||
SizedBox(height: 20),
|
color: primaryColor,
|
||||||
cartonTable,
|
thickness: 2,
|
||||||
LocalTitle(textKey: "invoice.cargo_type"),
|
)
|
||||||
cargoTypeTableBox,
|
: Container(),
|
||||||
// Column(children: getCargoTableByBox(context)),
|
invoiceTableBox,
|
||||||
SizedBox(height: 20),
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
paymentTypesBox,
|
paymentTypesBox,
|
||||||
SizedBox(height: 20),
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
_isNew
|
_isNew
|
||||||
? Container()
|
? Container()
|
||||||
: LocalTitle(
|
: LocalTitle(
|
||||||
@@ -277,7 +366,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
|||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: Icon(Icons.add_circle, color: primaryColor),
|
icon: Icon(Icons.add_circle, color: primaryColor),
|
||||||
onPressed: () async {})),
|
onPressed: () async {})),
|
||||||
widget.invoice == null
|
_isNew
|
||||||
? fcsButton(
|
? fcsButton(
|
||||||
context, getLocalString(context, 'invoice.btn_create'))
|
context, getLocalString(context, 'invoice.btn_create'))
|
||||||
: mainModel.isCustomer()
|
: 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) {
|
_addCustom(CustomDuty customDuty) {
|
||||||
if (customDuty == null) return;
|
if (customDuty == null) return;
|
||||||
setState(() {
|
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) {
|
_removeCustom(CustomDuty customDuty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_invoice.customDuties.remove(customDuty);
|
_invoice.customDuties.remove(customDuty);
|
||||||
|
|||||||
@@ -99,16 +99,14 @@ class _InvoiceInfoPageState extends State<InvoiceInfoPage> {
|
|||||||
_invoice = widget.invoice;
|
_invoice = widget.invoice;
|
||||||
_invoiceNumberController.text = _invoice.invoiceNumber;
|
_invoiceNumberController.text = _invoice.invoiceNumber;
|
||||||
_dateController.text = dateFormatter.format(_invoice.invoiceDate);
|
_dateController.text = dateFormatter.format(_invoice.invoiceDate);
|
||||||
_nameController.text = _invoice.customerName;
|
_nameController.text = _invoice.userName;
|
||||||
_phoneController.text = _invoice.customerPhoneNumber;
|
_phoneController.text = _invoice.phoneNumber;
|
||||||
// _amountController.text = _invoice.getAmount.toString();
|
// _amountController.text = _invoice.getAmount.toString();
|
||||||
_amountController.text = _invoice.amount.toString();
|
_amountController.text = _invoice.amount.toString();
|
||||||
_statusController.text = _invoice.status.toString();
|
_statusController.text = _invoice.status.toString();
|
||||||
_customFeeController.text = '0';
|
_customFeeController.text = '0';
|
||||||
// multiImgController.setImageUrls = _receipts;
|
// multiImgController.setImageUrls = _receipts;
|
||||||
_descriptionController.text = 'For Electronics goods';
|
_descriptionController.text = 'For Electronics goods';
|
||||||
_balanceController.text =
|
|
||||||
(_invoice.amount - _invoice.receipts[0].amount).toString();
|
|
||||||
// _boxes = _invoice.packages;
|
// _boxes = _invoice.packages;
|
||||||
} else {
|
} else {
|
||||||
_dateController.text = dateFormatter.format(DateTime.now());
|
_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 'dart:async';
|
||||||
|
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
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/invoice.dart';
|
||||||
import 'package:fcs/domain/entities/package.dart';
|
|
||||||
import 'package:fcs/domain/entities/receipt.dart';
|
import 'package:fcs/domain/entities/receipt.dart';
|
||||||
import 'package:fcs/domain/vo/message.dart';
|
|
||||||
import 'package:fcs/helpers/paginator.dart';
|
import 'package:fcs/helpers/paginator.dart';
|
||||||
import 'package:fcs/pages/main/model/base_model.dart';
|
import 'package:fcs/pages/main/model/base_model.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:fcs/domain/constants.dart';
|
|
||||||
|
|
||||||
class InvoiceModel extends BaseModel {
|
class InvoiceModel extends BaseModel {
|
||||||
final log = Logger('InvoiceModel');
|
final log = Logger('InvoiceModel');
|
||||||
@@ -18,37 +15,13 @@ class InvoiceModel extends BaseModel {
|
|||||||
|
|
||||||
List<Invoice> _invoices = [
|
List<Invoice> _invoices = [
|
||||||
Invoice(
|
Invoice(
|
||||||
invoiceNumber: 'A092(A)-33',
|
invoiceNumber: 'A092(A)-33',
|
||||||
invoiceDate: DateTime(2020, 4, 6, 12, 15),
|
invoiceDate: DateTime(2020, 4, 6, 12, 15),
|
||||||
customerName: 'Ko Myo Min',
|
userName: 'Ko Myo Min',
|
||||||
customerPhoneNumber: '+959 555555555',
|
phoneNumber: '+959 555555555',
|
||||||
amount: 300,
|
amount: 300,
|
||||||
status: 'Pending',
|
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 =>
|
List<Invoice> get invoices =>
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class _PaymentPageState extends State<PaymentPage> {
|
|||||||
getCustomFeeRows(BuildContext context) {
|
getCustomFeeRows(BuildContext context) {
|
||||||
List<Widget> dataRow = [];
|
List<Widget> dataRow = [];
|
||||||
|
|
||||||
dataRow = _invoice.receipts.asMap().entries.map((receipt) {
|
dataRow = [].asMap().entries.map((receipt) {
|
||||||
var r = receipt.value;
|
var r = receipt.value;
|
||||||
var k = receipt.key + 1;
|
var k = receipt.key + 1;
|
||||||
return Container(
|
return Container(
|
||||||
|
|||||||
@@ -148,6 +148,30 @@ class ShipmentModel extends BaseModel {
|
|||||||
return null;
|
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) {
|
void initUser(user) {
|
||||||
super.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 multiSelect;
|
||||||
final bool selectable;
|
final bool selectable;
|
||||||
final IconData buttonIcon;
|
final IconData buttonIcon;
|
||||||
|
final Color buttonColor;
|
||||||
|
|
||||||
const LocalPopupMenuButton(
|
const LocalPopupMenuButton(
|
||||||
{Key key,
|
{Key key,
|
||||||
@@ -19,7 +20,8 @@ class LocalPopupMenuButton extends StatefulWidget {
|
|||||||
this.popmenus,
|
this.popmenus,
|
||||||
this.buttonIcon,
|
this.buttonIcon,
|
||||||
this.selectable = true,
|
this.selectable = true,
|
||||||
this.multiSelect = false})
|
this.multiSelect = false,
|
||||||
|
this.buttonColor = primaryColor})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -76,7 +78,7 @@ class _LocalPopupMenuButtonState extends State<LocalPopupMenuButton> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Icon(
|
Icon(
|
||||||
widget.buttonIcon ?? Icons.filter_list,
|
widget.buttonIcon ?? Icons.filter_list,
|
||||||
color: primaryColor,
|
color: widget.buttonColor ?? primaryColor,
|
||||||
),
|
),
|
||||||
hightlight
|
hightlight
|
||||||
? Positioned(
|
? Positioned(
|
||||||
|
|||||||
Reference in New Issue
Block a user