update invoice page
This commit is contained in:
@@ -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(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await _loadCartons();
|
||||
await _loadShipments();
|
||||
await _loadDiscount();
|
||||
} catch (e) {} finally {
|
||||
setState(() {
|
||||
_isNew = true;
|
||||
_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);
|
||||
|
||||
Reference in New Issue
Block a user