update invoice

This commit is contained in:
PhyoThandar
2020-10-13 18:38:00 +06:30
parent 01d12c0eae
commit e61dc5d0e3
4 changed files with 269 additions and 138 deletions

View File

@@ -10,10 +10,13 @@ import 'package:fcs/pages/discount/model/discount_model.dart';
import 'package:fcs/pages/main/model/language_model.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/user_search/user_serach.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
import 'package:fcs/pages/widgets/discount_dropdown.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/local_dropdown.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/multi_img_controller.dart';
import 'package:fcs/pages/widgets/multi_img_file.dart';
@@ -38,29 +41,6 @@ class InvoiceEditor extends StatefulWidget {
class _InvoiceEditorState extends State<InvoiceEditor> {
User user;
List<PaymentMethod> get paymentMethods {
List<PaymentMethod> methods = [
PaymentMethod(
name: 'AYA Bank',
accountName: 'FCS',
account: '100 23404320548398',
phone: '+959123456789',
),
PaymentMethod(
name: 'KBZ Bank',
accountName: 'FCS',
account: '100 23404320548398',
phone: '+959123456789',
),
PaymentMethod(
name: 'PayPal',
accountName: 'FCS',
link: 'https://www.paypal.com/donate/buttons',
),
];
return methods;
}
var dateFormatter = new DateFormat('dd MMM yyyy');
TextEditingController _invoiceNumberController = new TextEditingController();
TextEditingController _dateController = new TextEditingController();
@@ -84,6 +64,9 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
double total = 0;
Discount _discount;
bool isNew = false;
Discount selectedDiscount;
int selectedDiscountAmt;
PaymentMethod paymentMethod;
List<Box> selectedBoxes = [];
@@ -185,7 +168,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
Widget build(BuildContext context) {
var mainModel = Provider.of<MainModel>(context);
var discountModel = Provider.of<DiscountModel>(context);
var languageModel = Provider.of<LanguageModel>(context);
var paymentMethodModel = Provider.of<PaymentMethodModel>(context);
final discountBox = Container(
child: DiscountDropdown<Discount>(
callback: (v) {
setState(() {
selectedDiscount = v;
});
},
iconData: Entypo.price_ribbon,
selectedValue: selectedDiscount,
values: discountModel.discounts,
));
return LocalProgress(
inAsyncCall: _isLoading,
@@ -218,7 +213,6 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
labelTextKey: 'invoice.number',
iconData: FontAwesomeIcons.fileInvoice,
text: _invoiceNumberController.text),
widget.invoice == null
? Row(
children: <Widget>[
@@ -242,22 +236,35 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
text: _nameController.text,
iconData: Feather.user,
labelTextKey: 'invoice.customer_name'),
InputText(
controller: _handlingFeeController,
iconData: FontAwesomeIcons.moneyBill,
labelTextKey: 'invoice.handling_fee'),
SizedBox(height: 15),
discountBox,
widget.invoice == null
? Container()
: DisplayText(
text: _statusController.text,
iconData: Icons.av_timer,
labelTextKey: 'invoice.status'),
SizedBox(height: 15),
Divider(thickness: 1),
SizedBox(height: 15),
LocalText(context, 'invoice.box_info',
color: primaryColor,
fontWeight: FontWeight.bold,
fontSize: 16.0),
SizedBox(height: 30),
Container(
child: Row(
children: [
Icon(MaterialCommunityIcons.package,
color: primaryColor),
SizedBox(width: 10),
LocalText(
context,
"invoice.box_info",
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.w700,
),
],
),
),
Container(
padding: const EdgeInsets.only(top: 15),
child: SingleChildScrollView(
@@ -272,17 +279,17 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
MyDataColumn(
label: LocalText(
context,
"box.number",
"invoice.box.number",
color: Colors.grey,
),
),
MyDataColumn(
label: Text(
getLocalString(context, "box.length") +
getLocalString(context, "invoice.box.length") +
' x ' +
getLocalString(context, "box.width") +
getLocalString(context, "invoice.box.width") +
' x ' +
getLocalString(context, "box.height"),
getLocalString(context, "invoice.box.height"),
),
),
],
@@ -290,78 +297,75 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
),
),
),
SizedBox(height: 25),
Divider(thickness: 1),
SizedBox(height: 15),
SizedBox(height: 40),
Container(
padding: const EdgeInsets.only(bottom: 10),
child: LocalText(context, 'invoice.description',
color: primaryColor,
fontWeight: FontWeight.bold,
fontSize: 16.0),
child: Row(
children: [
Icon(MaterialCommunityIcons.briefcase_check,
color: primaryColor),
SizedBox(width: 10),
LocalText(
context,
"invoice.cargo_type",
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.w700,
),
],
),
),
Container(
padding: const EdgeInsets.only(top: 15),
padding: const EdgeInsets.only(top: 10),
child: Column(children: getCargoTableByBox(context)),
),
SizedBox(height: 10),
Divider(thickness: 1),
SizedBox(height: 10),
// InputText(
// controller: _handlingFeeController,
// iconData: FontAwesomeIcons.moneyBill,
// labelTextKey: 'invoice.handling_fee'),
LocalText(context, 'invoice.payment_method',
fontSize: 16,
color: primaryColor,
fontWeight: FontWeight.bold),
SizedBox(height: 20),
Container(
padding: EdgeInsets.only(top: 5, left: 18),
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
width: 150.0,
child: DropdownButtonFormField(
hint: Text(getLocalString(
context, 'invoice.payment_method')),
items: paymentMethods
.map((e) => DropdownMenuItem(
child: Text(e.name), value: e.name))
.toList(),
onChanged: (selected) => {},
),
child: LocalText(context, 'invoice.payment_method',
fontSize: 16,
color: Colors.grey,
fontWeight: FontWeight.bold),
),
Container(
width: 150.0,
child: DropdownButtonFormField(
icon: Icon(Icons.edit),
value: paymentMethod,
items: paymentMethodModel.paymentMethods
.map((e) => DropdownMenuItem(
child: Text(e.name), value: e.name))
.toList(),
onChanged: (selected) => {},
),
),
],
),
),
SizedBox(height: 10),
Divider(thickness: 1),
SizedBox(height: 10),
isNew
? Column(
SizedBox(height: 30),
!isNew
? Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocalText(context, 'invoice.payment_attachment',
fontSize: 16,
color: primaryColor,
fontWeight: FontWeight.bold),
Padding(
padding: EdgeInsets.only(left: 20, top: 10),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[],
children: [
Icon(Icons.receipt, color: primaryColor),
SizedBox(width: 10),
LocalText(
context,
"invoice.payment_attachment",
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.w700,
),
],
),
),
Spacer(),
Icon(Icons.add, color: primaryColor),
],
)
: Container()
@@ -379,7 +383,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
getLocalString(context, 'invoice.btn_save'))
],
)),
widget.invoice == null
isNew
? Container()
: fcsButton(context,
getLocalString(context, 'invoice.btn_payment_receipt'))
@@ -392,13 +396,15 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
getCargoTableByBox(BuildContext context) {
var discountModel = Provider.of<DiscountModel>(context);
total = 0;
List<Widget> dataRow = _cargoTypes.map((cargo) {
var amount = cargo.weight * cargo.price;
total += amount;
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),
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
child: Row(
children: [
Expanded(flex: 2, child: Text('${cargo.type}')),
@@ -420,16 +426,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
dataRow.insert(
0,
Container(
padding: const EdgeInsets.all(5.0),
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.desc'),
child: Text(getLocalString(context, 'invoice.box.cargo_type'),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: primaryColor))),
color: Colors.grey))),
Expanded(
flex: 2,
child: Text(
@@ -440,41 +449,58 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: primaryColor))),
color: Colors.grey))),
Expanded(
child: Text(getLocalString(context, 'invoice.amount'),
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: primaryColor)))
color: Colors.grey)))
],
),
));
dataRow.insert(
dataRow.length,
Container(
padding: const EdgeInsets.only(left: 5.0, right: 5.0),
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Container(
child: DropdownButtonFormField(
hint: Text(getLocalString(context, 'invoice.discount'),
style: TextStyle(fontSize: 14)),
items: discountModel.discounts
.map((e) => DropdownMenuItem(
child: Text(e.code, style: TextStyle(fontSize: 13)),
value: e.code))
.toList(),
onChanged: (selected) {
var d = discountModel.discounts
.firstWhere((d) => d.code == selected);
setState(() {
_discount = d;
});
},
child: Center(
child: LocalText(
context,
'invoice.total',
color: Colors.black,
),
),
),
Expanded(
child: Text(
'\$ $total',
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: 10),
child: Row(
children: [
Expanded(
flex: 2,
child: Center(
child: LocalText(
context,
'invoice.discount_value',
color: Colors.black,
),
),
),
@@ -494,12 +520,18 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 10.0, bottom: 0.0),
left: 5.0, right: 5.0, top: 20.0, bottom: 0.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(getLocalString(context, 'invoice.custom_fee'))),
child: Center(
child: LocalText(
context,
'invoice.custom_fee',
color: Colors.black,
),
)),
Expanded(
child: Text('\$ ${customFee}',
textAlign: TextAlign.end,
@@ -516,12 +548,19 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
dataRow.length,
Container(
padding: const EdgeInsets.only(
left: 5.0, right: 5.0, top: 0.0, bottom: 10.0),
left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(getLocalString(context, 'invoice.delivery_fee'))),
flex: 1,
child: Container(
alignment: Alignment.centerRight,
child: LocalText(
context,
'invoice.delivery_fee',
color: Colors.black,
),
)),
Switch(
value: isSwitched,
onChanged: (value) {
@@ -548,6 +587,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
],
),
));
dataRow.insert(
dataRow.length,
Container(
@@ -561,6 +601,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
)),
],
)));
dataRow.insert(
dataRow.length,
Container(
@@ -570,18 +611,23 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
children: [
Expanded(
flex: 2,
child: LocalText(
context,
'invoice.total',
color: Colors.black,
child: Center(
child: LocalText(
context,
'invoice.net_amount',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: Text(
'\$ $total',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
))
child: Text('\$ ${getTotalBalance(total)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: primaryColor)))
],
),
));
@@ -595,10 +641,14 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
children: [
Expanded(
flex: 2,
child: LocalText(
context,
'invoice.balance',
color: Colors.black,
child: Center(
child: LocalText(
context,
'invoice.balance',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
@@ -626,13 +676,11 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
List<MyDataRow> getBoxRow(BuildContext context) {
return _boxes.map((p) {
p.cargoTypes.map((cargo) {
print('cargo => $cargo');
_cargoTypes.asMap().map((index, _cargo) {
if (_cargo.type == cargo.type) {
setState(() {
_cargoTypes[index].weight += cargo.weight;
});
print('${_cargoTypes[index].type} =>${_cargoTypes[index]}');
}
});
});