diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index acc52b3..3a40a60 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -344,15 +344,22 @@ "rate":"Rates", "rate.title":"Rates", "rate.edit.title":"Edit rates", - "rate.cal.title":"Estimate Shipping Cost", + "rate.cal.title":"Calculate Shipping Cost", "rate.min_weight":"Min weight for free delivery within yangon", "rate.delivery_fee":"Delivery fees", + "rate.total_estimated_amount":"Total estimated amount", "rate.volumetric_ratio":"Volumetric ratio", "rate.custom.form.title":"CUSTOM", "rate.cutom.product_type":"Product type", "rate.custom.fee":"Fee", "rate.discount.weight":"Weight", "rate.discount.rate":"Discount rate", + "rate.custom_duty.title":"Custom Duties", + "rate.custom_duty":"Custom Duty", + "rate.cargo.type":"Cargo Types", + "rate.discount_by_weight":"Discounts by weight", + "rate.discount_by_weight.edit.delete.confirm":"Delete this discount by weight?", + "rate.custom.edit.delete.confirm":"Delete this custom duty?", "Rate End ================================================================":"", "Cargo Start ================================================================":"", @@ -361,13 +368,14 @@ "cargo.weight":"Weight", "cargo.rate":"Rate", "cargo.amount":"Amount", + "cargo.edit.delete.confirm":"Delete this cargo type?", "Cargo End ================================================================":"", "Invoices Start ================================================================":"", "invoices.btn": "Invoices", - "invoices.title": "INVOICES", + "invoices.title": "Invoices", "invoices.add":"New invoice", - "invoice.form.title":"INVOICE", + "invoice.form.title":"Invoice", "invoice.payment":"Payment receipt", "invoice.add_box":"Add carton", "invoice.add_package":"Add package", @@ -403,6 +411,8 @@ "invoice.pdf": "Invoice PDF", "invoice.total_custom_fee":"Total custom fee", "invoice.shipment_weight":"Shipment weight", + "invoice.popupmenu.pending":"Pending", + "invoice.popupmenu.paid":"Paid", "Invoices End ================================================================":"", "Discount Start ================================================================":"", @@ -414,6 +424,7 @@ "discount.name":"Customer name", "discount.amount":"Amount", "discount.status":"Status", + "discount.edit.delete.confirm":"Delete this discount?", "Discount End ================================================================":"", "delivery_addresses Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index e019251..0b5192c 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -346,13 +346,20 @@ "rate.edit.title":"စျေးနှုန်းများပြုပြင်ရန်", "rate.cal.title":"စျေးနှုန်းများတွက်ချက်ရန်", "rate.min_weight":"Min Weight for Free delivery within Yangon", - "rate.delivery_fee":"Delivery fees", + "rate.delivery_fee":"ပို့ဆောင်ခ", + "rate.total_estimated_amount":"စုစုပေါင်းခန့်မှန်းပမာဏ", "rate.volumetric_ratio":"Volumetric Ratio", "rate.custom.form.title":"အကောက်ခွန်", "rate.cutom.product_type":"ကုန်ပစ္စည်းအမျိုးအစား", "rate.custom.fee":"အခကြေးငွေ", "rate.discount.weight":"အလေးချိန်", "rate.discount.rate":"လျှော့စျေးနှုန်း", + "rate.custom_duty.title":"အကောက်ခွန်များ", + "rate.custom_duty":"အကောက်ခွန်", + "rate.cargo.type":"ကုန်ပစ္စည်းအမျိုးအစား", + "rate.discount_by_weight":"အထူးလျှော့စျေး", + "rate.discount_by_weight.edit.delete.confirm":"Delete this discount by weight?", + "rate.custom.edit.delete.confirm":"Delete this custom duty?", "Rate End ================================================================":"", "Cargo Start ================================================================":"", @@ -403,6 +410,8 @@ "invoice.pdf": "Invoice PDF", "invoice.total_custom_fee":"အခွန်စုစုပေါင်း", "invoice.shipment_weight":"Shipment weight", + "invoice.popupmenu.pending":"Pending", + "invoice.popupmenu.paid":"Paid", "Invoices End ================================================================":"", "Discount Start ================================================================":"", @@ -414,6 +423,7 @@ "discount.name":"ဝယ်ယူသူအမည်", "discount.amount":"ပမာဏ", "discount.status":"အခြေအနေ", + "discount.edit.delete.confirm":"Delete this discount?", "Discount End ================================================================":"", "delivery_addresses Start ================================================================":"", diff --git a/lib/data/services/rate_imp.dart b/lib/data/services/rate_imp.dart index 4f5c769..6bea2ee 100644 --- a/lib/data/services/rate_imp.dart +++ b/lib/data/services/rate_imp.dart @@ -69,7 +69,6 @@ class RateServiceImp implements RateService { @override Future updateRate(Rate rate) { - // TODO: implement updateRate - throw UnimplementedError(); + return rateDataProvider.updateRates(rate); } } diff --git a/lib/pages/box/cargo_type_editor.dart b/lib/pages/box/cargo_type_editor.dart index 53e166f..c656647 100644 --- a/lib/pages/box/cargo_type_editor.dart +++ b/lib/pages/box/cargo_type_editor.dart @@ -99,11 +99,12 @@ class _CargoTypeEditorState extends State { )), body: Container( padding: EdgeInsets.all(18), - child: ListView( + child: Column( children: [ cargoTypeBox, rateBox, SizedBox(height: 40), + Spacer(), saveBtn, SizedBox(height: 20), ], diff --git a/lib/pages/discount/discount_editor.dart b/lib/pages/discount/discount_editor.dart index 65a0967..e8d0a15 100644 --- a/lib/pages/discount/discount_editor.dart +++ b/lib/pages/discount/discount_editor.dart @@ -1,7 +1,11 @@ import 'package:fcs/domain/entities/discount.dart'; +import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; +import 'package:fcs/pages/discount/model/discount_model.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; +import 'package:fcs/pages/user_search/user_serach.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; @@ -9,6 +13,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; class DiscountEditor extends StatefulWidget { final Discount discount; @@ -24,9 +29,10 @@ class _DiscountEditorState extends State { TextEditingController _codeController = new TextEditingController(); TextEditingController _amountController = new TextEditingController(); TextEditingController _statusController = new TextEditingController(); - TextEditingController _customerController = new TextEditingController(); - bool isNew = false; + bool _isNew = false; + String customerName = ''; + String customerId = ''; @override void initState() { @@ -36,10 +42,10 @@ class _DiscountEditorState extends State { _codeController.text = _discount.code; _amountController.text = _discount.amount.toString(); _statusController.text = _discount.status; - _customerController.text = 'Ko Nyi'; + customerName = widget.discount.customerName; + customerId = widget.discount.customerId; } else { - isNew = true; - _customerController.text = ''; + _isNew = true; } } @@ -49,20 +55,37 @@ class _DiscountEditorState extends State { labelTextKey: 'discount.code', iconData: FontAwesomeIcons.algolia, controller: _codeController); - final nameBox = InputText( - labelTextKey: 'discount.name', - iconData: Feather.user, - controller: _customerController); + final amountBox = InputText( labelTextKey: 'discount.amount', iconData: FontAwesomeIcons.moneyBill, controller: _amountController); + final statusBox = DisplayText( text: _statusController.text, - labelTextKey: getLocalString(context, "discount.status"), + labelTextKey: "discount.status", iconData: Icons.av_timer, ); + final customerBox = Row( + children: [ + Expanded( + child: DisplayText( + text: customerName != null ? customerName : "", + labelTextKey: "discount.name", + iconData: Feather.user, + )), + IconButton( + icon: Icon(Icons.search, color: primaryColor), + onPressed: () => searchUser(context, callbackUserSelect: (u) { + setState(() { + customerId = u.id; + customerName = u.name; + }); + })), + ], + ); + return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -77,18 +100,25 @@ class _DiscountEditorState extends State { onPressed: () => Navigator.of(context).pop(), ), backgroundColor: primaryColor, - actions: [], + actions: [ + IconButton( + icon: Icon(Icons.delete), + onPressed: _delete, + ) + ], ), body: Padding( - padding: const EdgeInsets.only(left: 20.0), + padding: const EdgeInsets.all(8.0), child: Column( children: [ Expanded( child: ListView( children: [ codeBox, - nameBox, amountBox, + SizedBox(height: 7), + customerBox, + SizedBox(height: 7), widget.discount == null ? Container() : Container( @@ -98,35 +128,8 @@ class _DiscountEditorState extends State { ], ), ), - widget.discount == null - ? Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Add Discount'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))) - : Align( - alignment: Alignment.bottomCenter, - child: Center( - child: Container( - width: 250, - child: FlatButton( - child: Text('Save box'), - color: primaryColor, - textColor: Colors.white, - onPressed: () { - Navigator.pop(context); - }, - ), - ))), + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), SizedBox( height: 30, ) @@ -135,4 +138,54 @@ class _DiscountEditorState extends State { )), ); } + + _save() async { + setState(() { + _isLoading = true; + }); + try { + DiscountModel discountModel = + Provider.of(context, listen: false); + Discount _discount = Discount( + code: _codeController.text, + customerName: customerName, + customerId: customerId, + amount: double.parse(_amountController.text)); + if (_isNew) { + await discountModel.addDiscount(_discount); + } else { + _discount.id = widget.discount.id; + await discountModel.updateDiscount(_discount); + } + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + _delete() { + showConfirmDialog( + context, "discount.edit.delete.confirm", _deleteCargoType); + } + + _deleteCargoType() async { + setState(() { + _isLoading = true; + }); + try { + var discountModel = Provider.of(context, listen: false); + await discountModel.deleteDiscount(widget.discount); + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } } diff --git a/lib/pages/discount/discount_list.dart b/lib/pages/discount/discount_list.dart index 3a4bd3c..c21d749 100644 --- a/lib/pages/discount/discount_list.dart +++ b/lib/pages/discount/discount_list.dart @@ -2,6 +2,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/discount/model/discount_model.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -19,6 +20,16 @@ class DiscountList extends StatefulWidget { class _DiscountListState extends State { bool _isLoading = false; + bool _selected = false; + + @override + void initState() { + super.initState(); + if (widget.selected != null) { + _selected = widget.selected; + } + } + @override Widget build(BuildContext context) { var discountModel = Provider.of(context); @@ -52,7 +63,7 @@ class _DiscountListState extends State { var discount = discountModel.discounts[index]; return InkWell( onTap: () { - widget.selected + _selected ? Navigator.pop(context, discount) : Navigator.push( context, @@ -128,7 +139,11 @@ class _DiscountListState extends State { ); }, icon: Icon(Icons.add), - label: Text(AppTranslations.of(context).text("discount.new")), + label: LocalText( + context, + 'discount.new', + color: Colors.white, + ), backgroundColor: primaryColor, ), ), diff --git a/lib/pages/invoice/invoce_list.dart b/lib/pages/invoice/invoce_list.dart index 620bd22..2495b27 100644 --- a/lib/pages/invoice/invoce_list.dart +++ b/lib/pages/invoice/invoce_list.dart @@ -8,6 +8,8 @@ import 'package:fcs/pages/package_search/package_serach.dart'; import 'package:fcs/pages/shipment/shipment_list.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/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/progress.dart'; import 'package:flutter/cupertino.dart'; @@ -40,6 +42,17 @@ class _InvoiceListState extends State { var owner = true; var invoiceModel = Provider.of(context); + final popupMenu = LocalPopupMenuButton( + popmenus: [ + LocalPopupMenu( + id: 1, textKey: "invoice.popupmenu.pending", selected: true), + LocalPopupMenu(id: 2, textKey: "invoice.popupmenu.paid") + ], + popupMenuCallback: (p) => this.setState(() { + // _showDelivered = p.id == 2; + }), + ); + return LocalProgress( inAsyncCall: _isLoading, child: DefaultTabController( @@ -58,6 +71,7 @@ class _InvoiceListState extends State { IconButton( icon: Icon(Icons.search, color: Colors.white), onPressed: () {}), + popupMenu ], ), floatingActionButton: owner diff --git a/lib/pages/invoice/payment_pdf_screen.dart b/lib/pages/invoice/payment_pdf_screen.dart index ce8f1e6..a341664 100644 --- a/lib/pages/invoice/payment_pdf_screen.dart +++ b/lib/pages/invoice/payment_pdf_screen.dart @@ -25,10 +25,9 @@ class _PaymentPDFScreenState extends State @override Widget build(BuildContext context) { - print(' widget.path => ${widget.path}'); - print(' pages => ${pages}'); return Scaffold( appBar: AppBar( + centerTitle: true, backgroundColor: primaryColor, title: LocalText(context, 'invoice.pdf', color: Colors.white, fontSize: 20), diff --git a/lib/pages/rates/cargo_editor.dart b/lib/pages/rates/cargo_editor.dart index a9b93ed..62733d2 100644 --- a/lib/pages/rates/cargo_editor.dart +++ b/lib/pages/rates/cargo_editor.dart @@ -6,6 +6,9 @@ import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import 'model/shipment_rate_model.dart'; class CargoEditor extends StatefulWidget { final CargoType cargo; @@ -21,6 +24,8 @@ class _CargoEditorState extends State { bool _isLoading = false; CargoType _cargo; + bool _isNew = false; + @override void initState() { super.initState(); @@ -28,6 +33,8 @@ class _CargoEditorState extends State { _cargo = widget.cargo; _descController.text = _cargo.name; _rateController.text = _cargo.rate.toString(); + } else { + _isNew = true; } } @@ -57,6 +64,12 @@ class _CargoEditorState extends State { ), backgroundColor: primaryColor, title: Text(AppTranslations.of(context).text("cargo.form.title")), + actions: [ + IconButton( + icon: Icon(Icons.delete), + onPressed: _delete, + ) + ], ), body: Container( padding: EdgeInsets.all(18), @@ -71,9 +84,8 @@ class _CargoEditorState extends State { ], ), ), - widget.cargo == null - ? fcsButton(context, "Create", callack: () {}) - : fcsButton(context, "Save", callack: () {}), + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), SizedBox(height: 10) ], ), @@ -81,4 +93,52 @@ class _CargoEditorState extends State { ), ); } + + _save() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + CargoType _cargo = CargoType( + name: _descController.text, rate: double.parse(_rateController.text)); + if (_isNew) { + await shipmentRateModel.addCargoType(_cargo); + } else { + _cargo.id = widget.cargo.id; + await shipmentRateModel.updateCargoType(_cargo); + } + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + _delete() { + showConfirmDialog( + context, "cargo_type.edit.delete.confirm", _deleteCargoType); + } + + _deleteCargoType() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + await shipmentRateModel.deleteCargoType(widget.cargo.id); + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } } diff --git a/lib/pages/rates/cargo_type_list.dart b/lib/pages/rates/cargo_type_list.dart new file mode 100644 index 0000000..9ae1e2f --- /dev/null +++ b/lib/pages/rates/cargo_type_list.dart @@ -0,0 +1,124 @@ +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/vo/delivery_address.dart'; +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/box/cargo_type_editor.dart'; +import 'package:fcs/pages/delivery_address/delivery_address_editor.dart'; +import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/rates/custom_editor.dart'; +import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/progress.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import 'cargo_editor.dart'; +import 'custom_row.dart'; +import 'model/shipment_rate_model.dart'; + +class CargoTypeList extends StatefulWidget { + const CargoTypeList({Key key}) : super(key: key); + @override + _CargoTypeListState createState() => _CargoTypeListState(); +} + +class _CargoTypeListState extends State { + bool _isLoading = false; + + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + var shipmentRateModel = Provider.of(context); + + return LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + centerTitle: true, + leading: new IconButton( + icon: new Icon(CupertinoIcons.back), + onPressed: () => Navigator.pop(context), + ), + backgroundColor: primaryColor, + title: LocalText( + context, + "cargo.form.title", + fontSize: 20, + color: Colors.white, + ), + ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () { + Navigator.of(context).push( + CupertinoPageRoute(builder: (context) => CargoEditor())); + }, + icon: Icon(Icons.add, color: Colors.white), + backgroundColor: primaryColor, + label: + LocalText(context, 'cargo.form.title', color: Colors.white)), + body: Padding( + padding: const EdgeInsets.all(8.0), + child: ListView.separated( + separatorBuilder: (c, i) => Divider( + color: primaryColor, + ), + itemCount: shipmentRateModel.rate.cargoTypes.length, + itemBuilder: (context, index) { + CargoType cargo = shipmentRateModel.rate.cargoTypes[index]; + return InkWell( + onTap: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => CargoEditor( + cargo: cargo, + ))); + }, + child: Container( + child: _row(cargo.name, "\$ " + cargo.rate.toString(), + 'per pound'), + ), + ); + }), + )), + ); + } + + _row(String desc, String price, String unit) { + return Container( + padding: EdgeInsets.only(left: 25, top: 5, bottom: 5), + child: Row( + children: [ + Text('$desc ', style: TextStyle(fontSize: 15)), + Spacer(), + Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 3.0), + child: Text( + '$price', + style: TextStyle(color: primaryColor, fontSize: 14), + ), + ), + Text( + '$unit', + style: TextStyle(color: Colors.grey, fontSize: 14), + ), + ], + ), + SizedBox( + width: 50, + ), + ], + )); + } +} diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index a8cd494..29e6288 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -7,6 +7,9 @@ import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; + +import 'model/shipment_rate_model.dart'; class CustomEditor extends StatefulWidget { final CustomDuty custom; @@ -22,6 +25,7 @@ class _CustomEditorState extends State { bool _isLoading = false; CustomDuty _custom = new CustomDuty(); + bool _isNew = false; @override void initState() { @@ -30,6 +34,8 @@ class _CustomEditorState extends State { _custom = widget.custom; _productController.text = _custom.productType; _feeController.text = _custom.fee.toString(); + } else { + _isNew = true; } } @@ -62,6 +68,12 @@ class _CustomEditorState extends State { backgroundColor: primaryColor, title: Text(AppTranslations.of(context).text("rate.custom.form.title")), + actions: [ + IconButton( + icon: Icon(Icons.delete), + onPressed: _delete, + ) + ], ), body: Container( padding: EdgeInsets.all(18), @@ -76,9 +88,8 @@ class _CustomEditorState extends State { ], ), ), - widget.custom == null - ? fcsButton(context, "Create", callack: () {}) - : fcsButton(context, "Save", callack: () {}), + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), SizedBox(height: 10) ], ), @@ -86,4 +97,53 @@ class _CustomEditorState extends State { ), ); } + + _save() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + CustomDuty _customduty = CustomDuty( + productType: _productController.text, + fee: double.parse(_feeController.text)); + if (_isNew) { + await shipmentRateModel.addCustomDuty(_customduty); + } else { + _customduty.id = widget.custom.id; + await shipmentRateModel.updateCustomDuty(_customduty); + } + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + _delete() { + showConfirmDialog( + context, "cargo.edit.delete.confirm", _deleteCustomDuty); + } + + _deleteCustomDuty() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + await shipmentRateModel.deleteCustomDuty(widget.custom.id); + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } } diff --git a/lib/pages/rates/custom_list.dart b/lib/pages/rates/custom_list.dart index b2f399c..7ffa414 100644 --- a/lib/pages/rates/custom_list.dart +++ b/lib/pages/rates/custom_list.dart @@ -49,11 +49,20 @@ class _CustomListState extends State { backgroundColor: primaryColor, title: LocalText( context, - "Customs", + "rate.custom_duty.title", fontSize: 20, color: Colors.white, ), ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () { + Navigator.of(context).push( + CupertinoPageRoute(builder: (context) => CustomEditor())); + }, + icon: Icon(Icons.add, color: Colors.white), + backgroundColor: primaryColor, + label: + LocalText(context, 'rate.custom_duty', color: Colors.white)), body: Padding( padding: const EdgeInsets.all(8.0), child: ListView.separated( @@ -62,26 +71,46 @@ class _CustomListState extends State { ), itemCount: shipmentRateModel.rate.customDuties.length, itemBuilder: (context, index) { - return _row( - context, shipmentRateModel.rate.customDuties[index]); + CustomDuty custom = + shipmentRateModel.rate.customDuties[index]; + return InkWell( + onTap: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => CustomEditor(custom: custom))); + }, + child: Container( + child: _row( + custom.productType, "\$ " + custom.fee.toString()), + ), + ); }), )), ); } - _row(BuildContext context, CustomDuty custom) { - return InkWell( - onTap: () => Navigator.pop(context, custom), - child: Row( - children: [ - Expanded( - child: CustomRow( - key: ValueKey(custom.id), - custom: custom, + _row(String desc, String price) { + return Container( + padding: EdgeInsets.only(left: 25, top: 5, bottom: 5), + child: Row( + children: [ + Text('$desc ', style: TextStyle(fontSize: 15)), + Spacer(), + Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 3.0), + child: Text( + '$price', + style: TextStyle(color: primaryColor, fontSize: 14), + ), + ), + ], ), - ), - ], - ), - ); + SizedBox( + width: 50, + ), + ], + )); } } diff --git a/lib/pages/rates/discount_by weight_list.dart b/lib/pages/rates/discount_by weight_list.dart new file mode 100644 index 0000000..84ee955 --- /dev/null +++ b/lib/pages/rates/discount_by weight_list.dart @@ -0,0 +1,119 @@ +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; +import 'package:fcs/domain/vo/delivery_address.dart'; +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/delivery_address/delivery_address_editor.dart'; +import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/rates/custom_editor.dart'; +import 'package:fcs/pages/rates/discount_by_weight_editor.dart'; +import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; +import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/progress.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import 'custom_row.dart'; +import 'model/shipment_rate_model.dart'; + +class DiscountByWeightList extends StatefulWidget { + const DiscountByWeightList({Key key}) : super(key: key); + @override + _DiscountByWeightListState createState() => _DiscountByWeightListState(); +} + +class _DiscountByWeightListState extends State { + bool _isLoading = false; + + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + var shipmentRateModel = Provider.of(context); + + return LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + centerTitle: true, + leading: new IconButton( + icon: new Icon(CupertinoIcons.back), + onPressed: () => Navigator.pop(context), + ), + backgroundColor: primaryColor, + title: LocalText( + context, + "rate.discount_by_weight", + fontSize: 20, + color: Colors.white, + ), + ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => DiscountByWeightEditor())); + }, + icon: Icon(Icons.add, color: Colors.white), + backgroundColor: primaryColor, + label: LocalText(context, 'discount.new', color: Colors.white)), + body: Padding( + padding: const EdgeInsets.all(8.0), + child: ListView.separated( + separatorBuilder: (c, i) => Divider( + color: primaryColor, + ), + itemCount: shipmentRateModel.rate.discountByWeights.length, + itemBuilder: (context, index) { + DiscountByWeight discountByWeight = + shipmentRateModel.rate.discountByWeights[index]; + return InkWell( + onTap: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => DiscountByWeightEditor( + discountByWeight: discountByWeight))); + }, + child: Container( + child: _row("${discountByWeight.weight.toString()} lb", + "\$ " + discountByWeight.discount.toString()), + ), + ); + }), + )), + ); + } + + _row(String desc, String price) { + return Container( + padding: EdgeInsets.only(left: 25, top: 5, bottom: 5), + child: Row( + children: [ + Text('$desc ', style: TextStyle(fontSize: 15)), + Spacer(), + Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 3.0), + child: Text( + '$price', + style: TextStyle(color: primaryColor, fontSize: 14), + ), + ), + ], + ), + SizedBox( + width: 50, + ), + ], + )); + } +} diff --git a/lib/pages/rates/discount_by_weight_editor.dart b/lib/pages/rates/discount_by_weight_editor.dart index a6b8fdd..66a48b1 100644 --- a/lib/pages/rates/discount_by_weight_editor.dart +++ b/lib/pages/rates/discount_by_weight_editor.dart @@ -2,11 +2,13 @@ import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; class DiscountByWeightEditor extends StatefulWidget { final DiscountByWeight discountByWeight; @@ -18,18 +20,19 @@ class DiscountByWeightEditor extends StatefulWidget { class _DiscountByWeightEditorState extends State { TextEditingController _weightController = new TextEditingController(); - TextEditingController _rateController = new TextEditingController(); + TextEditingController _discountController = new TextEditingController(); bool _isLoading = false; + bool _isNew = false; DiscountByWeight _discountByWeight = new DiscountByWeight(); @override void initState() { super.initState(); if (widget.discountByWeight != null) { - _discountByWeight = widget.discountByWeight; + _discountByWeight = widget.discountByWeight; _weightController.text = _discountByWeight.weight.toString(); - _rateController.text = _discountByWeight.discount.toString(); + _discountController.text = _discountByWeight.discount.toString(); } } @@ -47,7 +50,7 @@ class _DiscountByWeightEditorState extends State { final discountRateBox = InputText( labelTextKey: 'rate.discount.rate', iconData: Icons.attach_money, - controller: _rateController); + controller: _discountController); return LocalProgress( inAsyncCall: _isLoading, @@ -60,6 +63,12 @@ class _DiscountByWeightEditorState extends State { ), backgroundColor: primaryColor, title: Text(AppTranslations.of(context).text("discount.new")), + actions: [ + IconButton( + icon: Icon(Icons.delete), + onPressed: _delete, + ) + ], ), body: Container( padding: EdgeInsets.all(18), @@ -74,9 +83,8 @@ class _DiscountByWeightEditorState extends State { ], ), ), - widget.discountByWeight == null - ? fcsButton(context, "Create", callack: () {}) - : fcsButton(context, "Save", callack: () {}), + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), SizedBox(height: 10) ], ), @@ -84,4 +92,53 @@ class _DiscountByWeightEditorState extends State { ), ); } + + _save() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + DiscountByWeight _discount = DiscountByWeight( + weight: double.parse(_weightController.text), + discount: double.parse(_discountController.text)); + if (_isNew) { + await shipmentRateModel.addDiscountByWeight(_discount); + } else { + _discount.id = widget.discountByWeight.id; + await shipmentRateModel.updateDiscountByWeight(_discount); + } + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } + + _delete() { + showConfirmDialog(context, "rate.discount_by_weight.edit.delete.confirm", + _deleteDiscountByWeight); + } + + _deleteDiscountByWeight() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + await shipmentRateModel.deleteDiscountByWeight(widget.discountByWeight.id); + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } } diff --git a/lib/pages/rates/model/shipment_rate_model.dart b/lib/pages/rates/model/shipment_rate_model.dart index a8ea478..0b25799 100644 --- a/lib/pages/rates/model/shipment_rate_model.dart +++ b/lib/pages/rates/model/shipment_rate_model.dart @@ -1,6 +1,9 @@ import 'dart:async'; import 'package:fcs/data/services/services.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; +import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/pages/main/model/base_model.dart'; import 'package:logging/logging.dart'; @@ -24,4 +27,53 @@ class ShipmentRateModel extends BaseModel { logout() async { if (listener != null) await listener.cancel(); } + + // Rate + + Future updateRate(Rate rate) { + return Services.instance.rateService.updateRate(rate); + } + + //Cargo Type + + Future addCargoType(CargoType cargoType) { + return Services.instance.rateService.createCargoType(cargoType); + } + + Future updateCargoType(CargoType cargoType) { + return Services.instance.rateService.updateCargoType(cargoType); + } + + Future deleteCargoType(String id) { + return Services.instance.rateService.deleteCargoType(id); + } + + //CustomDuty + + Future addCustomDuty(CustomDuty customDuty) { + return Services.instance.rateService.createCustomDuty(customDuty); + } + + Future updateCustomDuty(CustomDuty customDuty) { + return Services.instance.rateService.updateCustomDuty(customDuty); + } + + Future deleteCustomDuty(String id) { + return Services.instance.rateService.deleteCargoType(id); + } + + //Discount by weight + Future addDiscountByWeight(DiscountByWeight discountByWeight) { + return Services.instance.rateService + .createDiscountByWeight(discountByWeight); + } + + Future updateDiscountByWeight(DiscountByWeight discountByWeight) { + return Services.instance.rateService + .updateDiscountByWeight(discountByWeight); + } + + Future deleteDiscountByWeight(String id) { + return Services.instance.rateService.deleteDiscountByWeight(id); + } } diff --git a/lib/pages/rates/shipment_rates.dart b/lib/pages/rates/shipment_rates.dart index 95aeff5..abffd93 100644 --- a/lib/pages/rates/shipment_rates.dart +++ b/lib/pages/rates/shipment_rates.dart @@ -5,6 +5,8 @@ import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/main/model/main_model.dart'; +import 'package:fcs/pages/rates/cargo_type_list.dart'; +import 'package:fcs/pages/rates/custom_list.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -14,6 +16,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../main/util.dart'; +import 'discount_by weight_list.dart'; import 'shipment_rates_calculate.dart'; import 'shipment_rates_edit.dart'; @@ -74,7 +77,7 @@ class _ShipmentRatesState extends State { child: ListView( // crossAxisAlignment: CrossAxisAlignment.center, children: [ - fcsButton(context, "Calculate shipping cost", callack: () { + fcsButton(context, getLocalString(context, "rate.cal.title"), callack: () { Navigator.of(context).push(CupertinoPageRoute( builder: (context) => ShipmentRatesCal())); }), @@ -82,13 +85,21 @@ class _ShipmentRatesState extends State { color: Colors.grey, ), Container( - padding: EdgeInsets.only(left: 25, top: 10), - child: Text( - "Cargo Types", - style: TextStyle( - color: primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15), + padding: EdgeInsets.only(left: 25, top: 10, right: 25), + child: Row( + children: [ + LocalText(context, "rate.cargo.type", + color: primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15), + Spacer(), + IconButton( + icon: Icon(Icons.edit, color: primaryColor), + onPressed: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => CargoTypeList())); + }) + ], ), ), Column( @@ -98,13 +109,21 @@ class _ShipmentRatesState extends State { color: Colors.grey, ), Container( - padding: EdgeInsets.only(left: 25, top: 10), - child: Text( - "Discounts by weight", - style: TextStyle( - color: primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15), + padding: EdgeInsets.only(left: 25, top: 10, right: 25), + child: Row( + children: [ + LocalText(context, "rate.discount_by_weight", + color: primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15), + Spacer(), + IconButton( + icon: Icon(Icons.edit, color: primaryColor), + onPressed: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => DiscountByWeightList())); + }) + ], ), ), Column( @@ -124,13 +143,21 @@ class _ShipmentRatesState extends State { color: Colors.grey, ), Container( - padding: EdgeInsets.only(left: 25, top: 10), - child: Text( - "Custom Duties", - style: TextStyle( - color: primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15), + padding: EdgeInsets.only(left: 25, top: 10, right: 25), + child: Row( + children: [ + LocalText(context, "rate.custom_duty", + color: primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15), + Spacer(), + IconButton( + icon: Icon(Icons.edit, color: primaryColor), + onPressed: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => CustomList())); + }) + ], ), ), Column( diff --git a/lib/pages/rates/shipment_rates_calculate.dart b/lib/pages/rates/shipment_rates_calculate.dart index f1a1257..e417432 100644 --- a/lib/pages/rates/shipment_rates_calculate.dart +++ b/lib/pages/rates/shipment_rates_calculate.dart @@ -1,9 +1,13 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; +import 'package:fcs/pages/widgets/display_text.dart'; +import 'package:fcs/pages/widgets/length_picker.dart'; import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter_icons/flutter_icons.dart'; import 'package:provider/provider.dart'; import 'package:flutter/material.dart'; @@ -18,10 +22,26 @@ class ShipmentRatesCal extends StatefulWidget { class _ShipmentRatesCalState extends State { bool _isLoading = false; String cargoType; + TextEditingController _widthController = new TextEditingController(); + TextEditingController _heightController = new TextEditingController(); + TextEditingController _lengthController = new TextEditingController(); + double shipmentWeight = 0; + double volumetricRatio = 0; @override void initState() { super.initState(); + + //for shipment weight + volumetricRatio = Provider.of(context, listen: false) + .rate + .volumetricRatio; + // _lengthController.addListener(_calShipmentWeight); + // _widthController.addListener(_calShipmentWeight); + // _heightController.addListener(_calShipmentWeight); + _lengthController.text = '10'; + _widthController.text = '10'; + _heightController.text = '10'; } @override @@ -33,6 +53,44 @@ class _ShipmentRatesCalState extends State { Widget build(BuildContext context) { var shipmentRateModel = Provider.of(context); + final lengthBox = LengthPicker( + controller: _lengthController, + lableKey: "box.length", + ); + final widthBox = LengthPicker( + controller: _widthController, + lableKey: "box.width", + ); + final heightBox = LengthPicker( + controller: _heightController, + lableKey: "box.height", + ); + + final dimBox = Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(right: 8.0), + child: Icon(FontAwesome.arrow_circle_right, color: primaryColor), + ), + SizedBox(child: lengthBox, width: 80), + SizedBox(child: widthBox, width: 80), + SizedBox(child: heightBox, width: 80), + ], + ); + + final shipmentWeightBox = DisplayText( + text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "6", + labelTextKey: "box.shipment_weight", + iconData: MaterialCommunityIcons.weight, + ); + + final actualWeightBox = DisplayText( + text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "", + labelTextKey: "box.actual_weight", + iconData: MaterialCommunityIcons.weight, + ); + return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -56,8 +114,8 @@ class _ShipmentRatesCalState extends State { child: Row( children: [ Expanded( - child: - Text('Cargo Type', style: TextStyle(fontSize: 15))), + child: LocalText(context, 'rate.cargo.type', + color: Colors.grey, fontSize: 15)), Container( width: 150.0, child: DropdownButtonFormField( @@ -79,46 +137,50 @@ class _ShipmentRatesCalState extends State { ], ), ), - _row('Width (inches)', "", "", "10", input: true), - _row('Height (inches)', "", "", "10", input: true), - _row('Length (inches)', "", "", "10", input: true), - _row('Actual Weight (pounds)', "", "", "0", input: true), - Container( - padding: EdgeInsets.only(left: 25, top: 15, bottom: 5), - child: Row( - children: [ - Text('Shipment Weight', style: TextStyle(fontSize: 15)), - Spacer(), - Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Padding( - padding: const EdgeInsets.only(bottom: 3.0), - child: Text( - '6', - style: - TextStyle(color: primaryColor, fontSize: 16), - ), - ), - Text( - 'pounds', - style: TextStyle(color: Colors.grey, fontSize: 16), - ), - ], - ), - ], - )), + // LocalTitle(textKey: "box.dimension"), + dimBox, + shipmentWeightBox, + actualWeightBox, + SizedBox(height: 50), Center( - child: Text( - "Delivery fee:\$ 5", - style: TextStyle(color: primaryColor, fontSize: 16), + child: Container( + alignment: Alignment.center, + width: 150, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + LocalText(context, "rate.delivery_fee", + color: primaryColor, fontSize: 16), + Text( + ':\$ 5', + style: TextStyle( + color: primaryColor, + fontSize: 16, + ), + ) + ], + ), )), SizedBox(height: 20), Center( - child: Text( - "Total estimated amount:\$ 41", - style: TextStyle(color: primaryColor, fontSize: 20), + child: Container( + width: 220, + alignment: Alignment.center, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + LocalText(context, "rate.total_estimated_amount", + color: primaryColor, fontSize: 16), + Text( + ':\$ 41', + style: TextStyle( + color: primaryColor, + fontSize: 16, + ), + ) + ], + ), )) ], ), diff --git a/lib/pages/rates/shipment_rates_edit.dart b/lib/pages/rates/shipment_rates_edit.dart index f9ca5f4..7a6e138 100644 --- a/lib/pages/rates/shipment_rates_edit.dart +++ b/lib/pages/rates/shipment_rates_edit.dart @@ -34,6 +34,8 @@ class _ShipmentRatesEditState extends State { TextEditingController _deliveryFee = new TextEditingController(); TextEditingController _volumetricRatio = new TextEditingController(); + bool _isNew = false; + @override void initState() { super.initState(); @@ -89,208 +91,207 @@ class _ShipmentRatesEditState extends State { feeBox, ratioBox, SizedBox(height: 10), - ExpansionTile( - title: Text( - 'Cargo Types', - style: TextStyle( - color: primaryColor, fontWeight: FontWeight.bold), - ), - children: [ - Container( - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: MyDataTable( - headingRowHeight: 40, - columnSpacing: 50, - columns: [ - MyDataColumn( - label: Text("Cargo Type", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - MyDataColumn( - label: Text("Rate", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - MyDataColumn( - label: Text("Delete", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - ], - rows: getCargoRows( - shipmentRateModel.rate.cargoTypes), - ), - ), - ), - Container( - padding: - EdgeInsets.only(top: 20, bottom: 15, right: 15), - child: Align( - alignment: Alignment.bottomRight, - child: Container( - width: 120, - height: 40, - child: FloatingActionButton.extended( - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - icon: Icon(Icons.add), - onPressed: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => CargoEditor()), - ); - }, - label: Text( - 'Add Cargo', - style: TextStyle(fontSize: 12), - ), - backgroundColor: primaryColor, - ), - ), - ), - ) - ], - ), - ExpansionTile( - title: Text( - 'Custom Duties', - style: TextStyle( - color: primaryColor, fontWeight: FontWeight.bold), - ), - children: [ - Container( - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: MyDataTable( - headingRowHeight: 40, - columnSpacing: 50, - columns: [ - MyDataColumn( - label: Text("Produt Type", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - MyDataColumn( - label: Text("Fee", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - MyDataColumn( - label: Text("Delete", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - ], - rows: getCustomsRows( - shipmentRateModel.rate.customDuties), - ), - ), - ), - Container( - padding: - EdgeInsets.only(top: 20, bottom: 15, right: 15), - child: Align( - alignment: Alignment.bottomRight, - child: Container( - width: 120, - height: 40, - child: FloatingActionButton.extended( - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - icon: Icon(Icons.add), - onPressed: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => CustomEditor()), - ); - }, - label: Text( - 'Add Custom\nDuty', - style: TextStyle(fontSize: 12), - ), - backgroundColor: primaryColor, - ), - ), - ), - ) - ], - ), - ExpansionTile( - title: Text( - 'Discounts by weight', - style: TextStyle( - color: primaryColor, fontWeight: FontWeight.bold), - ), - children: [ - Container( - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: MyDataTable( - headingRowHeight: 40, - columnSpacing: 30, - columns: [ - MyDataColumn( - label: Text("Weight", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - MyDataColumn( - label: Text("Discount Rate", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - MyDataColumn( - label: Text("Delete", - style: TextStyle( - fontSize: 15, - color: Colors.grey[600]))), - ], - rows: getDiscounts( - shipmentRateModel.rate.discountByWeights), - ), - ), - ), - Container( - padding: - EdgeInsets.only(top: 20, bottom: 15, right: 15), - child: Align( - alignment: Alignment.bottomRight, - child: Container( - width: 130, - height: 40, - child: FloatingActionButton.extended( - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - icon: Icon(Icons.add), - onPressed: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => - DiscountByWeightEditor()), - ); - }, - label: Text( - 'Add Discount', - style: TextStyle(fontSize: 12), - ), - backgroundColor: primaryColor, - ), - ), - ), - ) - ], - ), + // ExpansionTile( + // title: Text( + // 'Cargo Types', + // style: TextStyle( + // color: primaryColor, fontWeight: FontWeight.bold), + // ), + // children: [ + // Container( + // child: SingleChildScrollView( + // scrollDirection: Axis.horizontal, + // child: MyDataTable( + // headingRowHeight: 40, + // columnSpacing: 50, + // columns: [ + // MyDataColumn( + // label: Text("Cargo Type", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // MyDataColumn( + // label: Text("Rate", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // MyDataColumn( + // label: Text("Delete", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // ], + // rows: getCargoRows( + // shipmentRateModel.rate.cargoTypes), + // ), + // ), + // ), + // Container( + // padding: + // EdgeInsets.only(top: 20, bottom: 15, right: 15), + // child: Align( + // alignment: Alignment.bottomRight, + // child: Container( + // width: 120, + // height: 40, + // child: FloatingActionButton.extended( + // materialTapTargetSize: + // MaterialTapTargetSize.shrinkWrap, + // icon: Icon(Icons.add), + // onPressed: () { + // Navigator.push( + // context, + // CupertinoPageRoute( + // builder: (context) => CargoEditor()), + // ); + // }, + // label: Text( + // 'Add Cargo', + // style: TextStyle(fontSize: 12), + // ), + // backgroundColor: primaryColor, + // ), + // ), + // ), + // ) + // ], + // ), + // ExpansionTile( + // title: Text( + // 'Custom Duties', + // style: TextStyle( + // color: primaryColor, fontWeight: FontWeight.bold), + // ), + // children: [ + // Container( + // child: SingleChildScrollView( + // scrollDirection: Axis.horizontal, + // child: MyDataTable( + // headingRowHeight: 40, + // columnSpacing: 50, + // columns: [ + // MyDataColumn( + // label: Text("Produt Type", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // MyDataColumn( + // label: Text("Fee", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // MyDataColumn( + // label: Text("Delete", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // ], + // rows: getCustomsRows( + // shipmentRateModel.rate.customDuties), + // ), + // ), + // ), + // Container( + // padding: + // EdgeInsets.only(top: 20, bottom: 15, right: 15), + // child: Align( + // alignment: Alignment.bottomRight, + // child: Container( + // width: 120, + // height: 40, + // child: FloatingActionButton.extended( + // materialTapTargetSize: + // MaterialTapTargetSize.shrinkWrap, + // icon: Icon(Icons.add), + // onPressed: () { + // Navigator.push( + // context, + // CupertinoPageRoute( + // builder: (context) => CustomEditor()), + // ); + // }, + // label: Text( + // 'Add Custom\nDuty', + // style: TextStyle(fontSize: 12), + // ), + // backgroundColor: primaryColor, + // ), + // ), + // ), + // ) + // ], + // ), + // ExpansionTile( + // title: Text( + // 'Discounts by weight', + // style: TextStyle( + // color: primaryColor, fontWeight: FontWeight.bold), + // ), + // children: [ + // Container( + // child: SingleChildScrollView( + // scrollDirection: Axis.horizontal, + // child: MyDataTable( + // headingRowHeight: 40, + // columnSpacing: 30, + // columns: [ + // MyDataColumn( + // label: Text("Weight", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // MyDataColumn( + // label: Text("Discount Rate", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // MyDataColumn( + // label: Text("Delete", + // style: TextStyle( + // fontSize: 15, + // color: Colors.grey[600]))), + // ], + // rows: getDiscounts( + // shipmentRateModel.rate.discountByWeights), + // ), + // ), + // ), + // Container( + // padding: + // EdgeInsets.only(top: 20, bottom: 15, right: 15), + // child: Align( + // alignment: Alignment.bottomRight, + // child: Container( + // width: 130, + // height: 40, + // child: FloatingActionButton.extended( + // materialTapTargetSize: + // MaterialTapTargetSize.shrinkWrap, + // icon: Icon(Icons.add), + // onPressed: () { + // Navigator.push( + // context, + // CupertinoPageRoute( + // builder: (context) => + // DiscountByWeightEditor()), + // ); + // }, + // label: Text( + // 'Add Discount', + // style: TextStyle(fontSize: 12), + // ), + // backgroundColor: primaryColor, + // ), + // ), + // ), + // ) + // ], + // ), ], ), ), - fcsButton(context, "Save", callack: () { - Navigator.pop(context); - }), + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), SizedBox(height: 10) ], ), @@ -299,6 +300,28 @@ class _ShipmentRatesEditState extends State { ); } + _save() async { + setState(() { + _isLoading = true; + }); + try { + var shipmentRateModel = + Provider.of(context, listen: false); + Rate _rate = Rate( + deliveryFee: double.parse(_deliveryFee.text), + freeDeliveryWeight: double.parse(_minWeight.text), + volumetricRatio: double.parse(_volumetricRatio.text)); + await shipmentRateModel.updateRate(_rate); + Navigator.pop(context); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } + List getCargoRows(List cargos) { return cargos.map((r) { return MyDataRow(