diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index d86aafa..850babd 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -368,7 +368,14 @@ "invoice.btn_save":"Save Invoice", "invoice.btn_payment_receipt":"Attachment Payment Receipt", "invoice.description": "Description", - "invoice.desc": "Types", + "invoice.box.cargo_type": "Cargo Types", + "invoice.cargo_type":"Cargo Types", + "invoice.box.number":"Box number", + "invoice.box.length":"Length", + "invoice.box.width":"Width", + "invoice.boc.height":"Height", + "invoice.discount_value": "Discount", + "invoice.net_amount":"Net Amount", "Invoices End ================================================================":"", "Discount Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index 5b14485..f9c49f6 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -367,8 +367,15 @@ "invoice.btn_create":"ငွေတောင်းခံလွှာ ပြုလုပ်ရန်", "invoice.btn_save":"ငွေတောင်းခံလွှာ သိမ်းရန်", "invoice.btn_payment_receipt":"ငွေလက်ခံဖြတ်ပိုင်း ထည့်ရန်", - "invoice.desc": "အမျိုးအစား", + "invoice.box.cargo_type": "ကုန်ပစ္စည်းအမျိုးအစားများ", "invoice.description": "ငွေတောင်းခံလွှာအကြောင်းအရာ", + "invoice.cargo_type":"Cargo Types", + "invoice.box.number":"Box နံပါတ်", + "invoice.box.length":"အလျား", + "invoice.box.width":"အနံ", + "invoice.box.height":"အမြင့်", + "invoice.discount_value": "လျှော့စျေး", + "invoice.net_amount":"Net Amount", "Invoices End ================================================================":"", "Discount Start ================================================================":"", diff --git a/lib/pages/invoice/invoice_editor.dart b/lib/pages/invoice/invoice_editor.dart index 724a2bc..c8adcf2 100644 --- a/lib/pages/invoice/invoice_editor.dart +++ b/lib/pages/invoice/invoice_editor.dart @@ -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 { User user; - List get paymentMethods { - List 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 { double total = 0; Discount _discount; bool isNew = false; + Discount selectedDiscount; + int selectedDiscountAmt; + PaymentMethod paymentMethod; List selectedBoxes = []; @@ -185,7 +168,19 @@ class _InvoiceEditorState extends State { Widget build(BuildContext context) { var mainModel = Provider.of(context); var discountModel = Provider.of(context); - var languageModel = Provider.of(context); + var paymentMethodModel = Provider.of(context); + + final discountBox = Container( + child: DiscountDropdown( + 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 { labelTextKey: 'invoice.number', iconData: FontAwesomeIcons.fileInvoice, text: _invoiceNumberController.text), - widget.invoice == null ? Row( children: [ @@ -242,22 +236,35 @@ class _InvoiceEditorState extends State { 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 { 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 { ), ), ), - - 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: [ 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: [], + 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 { 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 { getCargoTableByBox(BuildContext context) { var discountModel = Provider.of(context); - + total = 0; List 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 { 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 { 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 { 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 { 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 { ], ), )); + dataRow.insert( dataRow.length, Container( @@ -561,6 +601,7 @@ class _InvoiceEditorState extends State { )), ], ))); + dataRow.insert( dataRow.length, Container( @@ -570,18 +611,23 @@ class _InvoiceEditorState extends State { 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 { 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 { List 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]}'); } }); }); diff --git a/lib/pages/widgets/discount_dropdown.dart b/lib/pages/widgets/discount_dropdown.dart new file mode 100644 index 0000000..63bf769 --- /dev/null +++ b/lib/pages/widgets/discount_dropdown.dart @@ -0,0 +1,69 @@ +import 'package:fcs/domain/entities/discount.dart'; +import 'package:fcs/helpers/theme.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'local_text.dart'; + +class DiscountDropdown extends StatelessWidget { + final Function(T) callback; + final IconData iconData; + final T selectedValue; + final List values; + + const DiscountDropdown( + {Key key, this.callback, this.iconData, this.selectedValue, this.values}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(left: 5.0, right: 0), + child: Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 0, right: 10), + child: Icon(iconData, color: primaryColor), + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(right: 18.0), + child: LocalText( + context, + "invoice.discount", + color: Colors.black54, + fontSize: 16, + ), + ), + DropdownButton( + isDense: true, + value: selectedValue, + style: TextStyle(color: Colors.black, fontSize: 14), + underline: Container( + height: 1, + color: primaryColor, + ), + onChanged: (T newValue) { + callback(newValue); + }, + isExpanded: true, + items: values.map>((T value) { + return DropdownMenuItem( + value: value, + child: Text(value == null ? "" : (value as Discount).code, + overflow: TextOverflow.ellipsis, + style: TextStyle(color: primaryColor)), + ); + }).toList(), + ), + ], + ), + ), + ], + ), + ); + } +}