From 5d42e1ad789d669aaef26a83fb7298038b49b913 Mon Sep 17 00:00:00 2001 From: sma Date: Fri, 9 Feb 2024 12:16:18 +0630 Subject: [PATCH 01/10] prepare carton info --- lib/pages/carton/carton_info.dart | 218 +++++++++++++++++------------- 1 file changed, 124 insertions(+), 94 deletions(-) diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 78ae425..4a9d997 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -61,15 +61,19 @@ class _CartonInfoState extends State { bool isSmallBag = false; bool isFromCartons = false; bool isEdiable = false; + bool isCutomDuty=false; final List cargoTypes = []; final List surchareItems = []; + final List cartons = []; @override void initState() { super.initState(); _box = widget.box; _box?.billToValue = "Bill to sender"; - _cartonSubmit = widget.cartonSubmit; + + + //initPackage(widget.package!); //for shipment weight @@ -206,6 +210,9 @@ class _CartonInfoState extends State { final packageBox = DisplayText( labelTextKey: "box.package", ); + final cartonBox = DisplayText( + labelTextKey: "box.shipment.boxes", + ); final cargosBox = Padding( padding: const EdgeInsets.only(top: 10), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -330,43 +337,7 @@ class _CartonInfoState extends State { controller: multiImgController, title: "Receipt File", ); - final displayMixBox = Container( - child: Row( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - child: Row( - //crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - customerNameBox, - ], - ), - ), - _box?.billToValue == billToSender - ? Expanded( - child: Padding( - padding: EdgeInsets.only(left: 0, top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Ionicons.document_text_outline, - color: primaryColor, size: 20), - Text("Bill to", - style: TextStyle( - color: primaryColor, fontSize: 15)) - ], - ))) - : const SizedBox() - ], - ), - ), - Expanded( + final consigneeBox=Container( child: Padding( padding: const EdgeInsets.only(left: 0), child: Row( @@ -397,15 +368,39 @@ class _CartonInfoState extends State { : const SizedBox() ], ), - )) - ], - ), - packageBox, - Row( - children: getPackageList(_box!.packages), - ) - ], - )); + )); + final customerBox= Container( + child: Row( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + customerNameBox, + ], + ), + ), + _box?.billToValue == billToSender + ? Expanded( + child: Padding( + padding: EdgeInsets.only(left: 0, top: 15), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(Ionicons.document_text_outline, + color: primaryColor, size: 20), + Text("Bill to", + style: TextStyle( + color: primaryColor, fontSize: 15)) + ], + ))) + : const SizedBox() + ], + ), + ); + + final billWidget = Expanded( child: Padding( padding: EdgeInsets.only(left: 0, top: 15), @@ -460,58 +455,82 @@ class _CartonInfoState extends State { ), ], ), + // isMixBox + // ? + // displayMixBox:Container(), + + isMixBox? + - // Row( - // mainAxisAlignment: MainAxisAlignment.start, - // children: [ - // Expanded( - // child: Row( - // //crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // customerNameBox, - // ], - // ), - // ), - // _box?.billToValue == billToSender - // ? billWidget - // : const SizedBox() - // ], - // ), - // ), - // Expanded( - // child: Padding( - // padding: const EdgeInsets.only(left: 0), - // child: Row( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // consigneeNameBox, - // ], - // ), - // ), - // _cartonSubmit?.billToValue == billToSender - // ? billWidget - // : const SizedBox() - // ], - // ), - // )) - // ], - // ), - // packageBox, + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + child: Row( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + customerNameBox, + ], + ), + ), + _box?.billToValue == billToSender + ? billWidget + : const SizedBox( height: 300.0,) + ], + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.only(left: 0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + consigneeNameBox, + ], + ), + ), + _cartonSubmit?.billToValue == billToSender + ? billWidget + : const SizedBox() + ], + ), + )) + ], + ) + // , + // Row( // children: getPackageList(_box!.packages), // ), - // ]):Container(), - + // ]) + :Container(), + isMixBox ? + Column(children: [ + packageBox, + Row( + children: getPackageList(_box!.packages), + ), + ],):Column( + children: [ + cartonBox, + Row( + children: getCartonList(_box!.mixCartons), + ), + ], + ), + isCutomDuty + ? + surchargeItemBox: cargosBox, - surchargeItemBox, + Padding( padding: EdgeInsets.only(left: 200.0, right: 8.0), child: ElevatedButton( @@ -603,6 +622,17 @@ class _CartonInfoState extends State { )); }).toList(); } + List getCartonList(List _c) { + return _c.map((c) { + return Container( + padding: EdgeInsets.only(top: 0), + child: Container( + //padding: + //EdgeInsets.only(top: 0.0), + child: Row(children: [new Text(c.cartonNumber ?? '')]), + )); + }).toList(); + } List getCargoList(List _c) { return _c.map((c) { From 4a9c04ef1e0dc31857531f4391ae2da99801e0aa Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 12:16:39 +0630 Subject: [PATCH 02/10] move bill to to cartion size widget --- assets/local/localization_en.json | 4 +- assets/local/localization_mu.json | 3 + lib/pages/carton/carton_editor.dart | 82 +----------------- .../carton/carton_editor_for_package.dart | 15 +++- lib/pages/carton/carton_size_widget.dart | 84 +++++++++++++++++-- 5 files changed, 100 insertions(+), 88 deletions(-) diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index 84802c6..8442fde 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -341,7 +341,9 @@ "box.select.cargo_type":"Select surcharge item", "box.surcharge.item":"Surcharge items", "box.package.count":"Packages ({0})", - + "box.bill_to":"Bill to", + "box.delvery_carton":"Delivery carton", + "box.pick_up_carton":"Pick-up carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index 72df718..c59ed1c 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -340,6 +340,9 @@ "box.select.cargo_type":"Select surcharge item", "box.surcharge.item":"Surcharge items", "box.package.count":"Packages ({0})", + "box.bill_to":"Bill to", + "box.delvery_carton":"Delivery carton", + "box.pick_up_carton":"Pick-up carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 29840ae..2368710 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -6,7 +6,6 @@ import 'package:fcs/pages/user_search/user_search.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/fcs_id_icon.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; -import 'package:fcs/pages/widgets/local_radio.dart'; import 'package:fcs/pages/widgets/local_radio_buttons.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_title.dart'; @@ -34,7 +33,6 @@ class _CartonEditorState extends State { bool _isLoading = false; bool _isNew = false; - String _billToValue = billToSender; String? _selectedCartonType; User? _consignee; @@ -157,9 +155,9 @@ class _CartonEditorState extends State { context, CupertinoPageRoute( builder: (context) => CartonEditorForPackage( - sender: _sender!, - consignee: _consignee!, - billToValue: _billToValue))); + sender: _sender!, + consignee: _consignee!, + ))); } // for mix cartion else { @@ -169,10 +167,7 @@ class _CartonEditorState extends State { builder: (context) => const MixCartonEditor())); } }, - child: Icon( - Icons.add_circle, - color: primaryColor, - ), + child: Icon(Icons.add_circle, color: primaryColor), ), )); @@ -268,72 +263,6 @@ class _CartonEditorState extends State { ), ); - final billRadioBox = Container( - child: Row( - children: [ - Flexible( - child: InkWell( - onTap: () { - setState(() { - _billToValue = billToSender; - }); - }, - child: Row(children: [ - LocalRadio( - value: billToSender, - groupValue: _billToValue, - onChanged: (p0) { - setState(() { - _billToValue = billToSender; - }); - }, - ), - Flexible( - child: Padding( - padding: const EdgeInsets.only(left: 10), - child: LocalText(context, 'box.bill_to_sender', - fontSize: 15, - color: _billToValue == billToSender - ? primaryColor - : Colors.black), - ), - ) - ]), - )), - Flexible( - child: InkWell( - onTap: () { - setState(() { - _billToValue = billToConsignee; - }); - }, - child: Row(children: [ - LocalRadio( - value: billToConsignee, - groupValue: _billToValue, - onChanged: (p0) { - setState(() { - _billToValue = billToConsignee; - }); - }, - ), - Flexible( - child: Padding( - padding: const EdgeInsets.only(left: 10), - child: LocalText(context, 'box.bill_to.consignee', - fontSize: 15, - color: _billToValue == billToConsignee - ? primaryColor - : Colors.black), - ), - ) - ]), - ), - ) - ], - ), - ); - return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -358,9 +287,6 @@ class _CartonEditorState extends State { Flexible(child: consigneeBox) ], ), - const SizedBox(height: 5), - billRadioBox, - const SizedBox(height: 5), ], ) : Container(), diff --git a/lib/pages/carton/carton_editor_for_package.dart b/lib/pages/carton/carton_editor_for_package.dart index 60ca750..7f6be13 100644 --- a/lib/pages/carton/carton_editor_for_package.dart +++ b/lib/pages/carton/carton_editor_for_package.dart @@ -26,9 +26,12 @@ import 'package_selection_widget.dart'; class CartonEditorForPackage extends StatefulWidget { final User sender; final User consignee; - final String billToValue; + const CartonEditorForPackage( - {Key? key, required this.sender, required this.consignee, required this.billToValue}) + {Key? key, + required this.sender, + required this.consignee, + }) : super(key: key); @override @@ -54,6 +57,8 @@ class _CartonEditorForPackageState extends State { double _height = 0; String _selectedDeliveryType = delivery_caton; + String _billToValue = billToSender; + FcsShipment? _shipment; String _cartonSizeType = standardCarton; CartonSize? _standardSize; @@ -131,6 +136,7 @@ class _CartonEditorForPackageState extends State { return Expanded( child: CartonSizeWidget( deliveryType: _selectedDeliveryType, + billType: _billToValue, sender: widget.sender, consignee: widget.consignee, shipment: _shipment, @@ -142,10 +148,11 @@ class _CartonEditorForPackageState extends State { onPrevious: () { Navigator.pop(context); }, - onContinue: (deliveryType, shipment, cartonSizeType, + onContinue: (deliveryType,billType ,shipment, cartonSizeType, {standardSize, length, width, height}) { setState(() { _selectedDeliveryType = deliveryType; + _billToValue = billType; _shipment = shipment; _cartonSizeType = cartonSizeType; _standardSize = standardSize; @@ -205,7 +212,7 @@ class _CartonEditorForPackageState extends State { child: CartonSubmit( sender: widget.sender, consingee: widget.consignee, - billToValue: widget.billToValue, + billToValue: _billToValue, cartonSizeType: _cartonSizeType, standardSize: _standardSize, length: _length, diff --git a/lib/pages/carton/carton_size_widget.dart b/lib/pages/carton/carton_size_widget.dart index 50da3fe..8aa89ef 100644 --- a/lib/pages/carton/carton_size_widget.dart +++ b/lib/pages/carton/carton_size_widget.dart @@ -21,7 +21,8 @@ import '../widgets/previous_button.dart'; typedef OnPrevious = Function(); -typedef OnContinue = Function(String deliveryType,FcsShipment shipment, String cartonSizeType, +typedef OnContinue = Function(String deliveryType, String billType, + FcsShipment shipment, String cartonSizeType, {CartonSize? standardSize, double? length, double? width, double? height}); class CartonSizeWidget extends StatefulWidget { @@ -30,6 +31,7 @@ class CartonSizeWidget extends StatefulWidget { final User sender; final User consignee; final String deliveryType; + final String billType; final FcsShipment? shipment; final String cartonSizeType; final CartonSize? standardSize; @@ -49,7 +51,8 @@ class CartonSizeWidget extends StatefulWidget { this.height, required this.sender, required this.consignee, - required this.deliveryType}) + required this.deliveryType, + required this.billType}) : super(key: key); @override @@ -65,6 +68,7 @@ class _CartonSizeWidgetState extends State { List _shipments = []; CartonSize? _selectStandardSize; late String _selectedDeliveryType; + late String _billToValue; TextEditingController _widthController = new TextEditingController(); TextEditingController _heightController = new TextEditingController(); @@ -78,9 +82,10 @@ class _CartonSizeWidgetState extends State { _init() async { _selectedDeliveryType = widget.deliveryType; + _billToValue = widget.billType; _shipment = widget.shipment; _cartionSizeType = widget.cartonSizeType; - + List cartonSizes = context.read().cartonSizes; _selectStandardSize = widget.standardSize ?? cartonSizes.first; @@ -142,6 +147,72 @@ class _CartonSizeWidgetState extends State { }); }); + final billRadioBox = Container( + child: Row( + children: [ + Flexible( + child: InkWell( + onTap: () { + setState(() { + _billToValue = billToSender; + }); + }, + child: Row(children: [ + LocalRadio( + value: billToSender, + groupValue: _billToValue, + onChanged: (p0) { + setState(() { + _billToValue = billToSender; + }); + }, + ), + Flexible( + child: Padding( + padding: const EdgeInsets.only(left: 10), + child: LocalText(context, 'box.bill_to_sender', + fontSize: 15, + color: _billToValue == billToSender + ? primaryColor + : Colors.black), + ), + ) + ]), + )), + Flexible( + child: InkWell( + onTap: () { + setState(() { + _billToValue = billToConsignee; + }); + }, + child: Row(children: [ + LocalRadio( + value: billToConsignee, + groupValue: _billToValue, + onChanged: (p0) { + setState(() { + _billToValue = billToConsignee; + }); + }, + ), + Flexible( + child: Padding( + padding: const EdgeInsets.only(left: 10), + child: LocalText(context, 'box.bill_to.consignee', + fontSize: 15, + color: _billToValue == billToConsignee + ? primaryColor + : Colors.black), + ), + ) + ]), + ), + ) + ], + ), + ); + final continueBtn = ContinueButton(onTap: () { double l = double.tryParse(_lengthController.text) ?? 0; double w = double.tryParse(_widthController.text) ?? 0; @@ -170,7 +241,8 @@ class _CartonSizeWidgetState extends State { } if (widget.onContinue != null) { - widget.onContinue!(_selectedDeliveryType,_shipment!, _cartionSizeType, + widget.onContinue!( + _selectedDeliveryType, _billToValue, _shipment!, _cartionSizeType, standardSize: _selectStandardSize, length: l, width: w, height: h); } }); @@ -366,7 +438,9 @@ class _CartonSizeWidgetState extends State { children: [ const SizedBox(height: 8), userRow, - LocalTitle(textKey: "box.select.delivery", topPadding: 10), + const SizedBox(height: 5), + billRadioBox, + LocalTitle(textKey: "box.select.delivery"), const SizedBox(height: 5), deliveryTypeBox, const SizedBox(height: 5), From 62c0da8a9625be054104f841faaaae8d1e7b85f3 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 12:21:49 +0630 Subject: [PATCH 03/10] update carton info --- lib/pages/carton/carton_info.dart | 238 ++++++++++-------------------- 1 file changed, 82 insertions(+), 156 deletions(-) diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 4a9d997..788d446 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -60,8 +60,8 @@ class _CartonInfoState extends State { bool isFromPackages = false; bool isSmallBag = false; bool isFromCartons = false; - bool isEdiable = false; - bool isCutomDuty=false; + + bool isCutomDuty = false; final List cargoTypes = []; final List surchareItems = []; final List cartons = []; @@ -71,9 +71,6 @@ class _CartonInfoState extends State { super.initState(); _box = widget.box; _box?.billToValue = "Bill to sender"; - - - //initPackage(widget.package!); //for shipment weight @@ -100,8 +97,6 @@ class _CartonInfoState extends State { isSmallBag = _box!.cartonType == carton_small_bag; isFromCartons = _box!.cartonType == carton_from_cartons; - isEdiable = (isFromPackages || isMixBox || isFromCartons) && - _box!.status == carton_packed_status; selectMixBoxType = _box!.mixBoxType; getCartonSize(); } @@ -337,70 +332,7 @@ class _CartonInfoState extends State { controller: multiImgController, title: "Receipt File", ); - final consigneeBox=Container( - child: Padding( - padding: const EdgeInsets.only(left: 0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - consigneeNameBox, - ], - ), - ), - _cartonSubmit?.billToValue == billToSender - ? Expanded( - child: Padding( - padding: EdgeInsets.only(left: 0, top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Ionicons.document_text_outline, - color: primaryColor, size: 20), - Text("Bill to", - style: TextStyle( - color: primaryColor, fontSize: 15)) - ], - ))) - : const SizedBox() - ], - ), - )); - final customerBox= Container( - child: Row( - //crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - customerNameBox, - ], - ), - ), - _box?.billToValue == billToSender - ? Expanded( - child: Padding( - padding: EdgeInsets.only(left: 0, top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Ionicons.document_text_outline, - color: primaryColor, size: 20), - Text("Bill to", - style: TextStyle( - color: primaryColor, fontSize: 15)) - ], - ))) - : const SizedBox() - ], - ), - ); - - + final billWidget = Expanded( child: Padding( padding: EdgeInsets.only(left: 0, top: 15), @@ -418,23 +350,15 @@ class _CartonInfoState extends State { inAsyncCall: _isLoading, child: Scaffold( appBar: LocalAppBar( - labelKey: "box.info.title", - backgroundColor: Colors.white, - labelColor: primaryColor, - arrowColor: primaryColor, - actions: isEdiable - ? [ - IconButton( - icon: Icon(Icons.edit, color: primaryColor), - onPressed: _gotoEditor, - ), - IconButton( - icon: Icon(Icons.delete, color: primaryColor), - onPressed: _delete, - ), - ] - : [], - ), + labelKey: "box.info.title", + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor, + actions: [ + IconButton( + icon: Icon(Icons.edit, color: primaryColor), + onPressed: _gotoEditor), + ]), body: Container( padding: const EdgeInsets.all(10.0), child: ListView(children: [ @@ -458,79 +382,81 @@ class _CartonInfoState extends State { // isMixBox // ? // displayMixBox:Container(), - - isMixBox? - - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - child: Row( - //crossAxisAlignment: CrossAxisAlignment.start, + isMixBox + ? Row( + mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + child: Row( + //crossAxisAlignment: CrossAxisAlignment.start, children: [ - customerNameBox, + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + customerNameBox, + ], + ), + ), + _box?.billToValue == billToSender + ? billWidget + : const SizedBox( + height: 300.0, + ) ], ), ), - _box?.billToValue == billToSender - ? billWidget - : const SizedBox( height: 300.0,) - ], - ), - ), - Expanded( - child: Padding( - padding: const EdgeInsets.only(left: 0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ Expanded( - child: Column( + child: Padding( + padding: const EdgeInsets.only(left: 0), + child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - consigneeNameBox, + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + consigneeNameBox, + ], + ), + ), + _cartonSubmit?.billToValue == billToSender + ? billWidget + : const SizedBox() ], ), + )) + ], + ) + // , + + // Row( + // children: getPackageList(_box!.packages), + // ), + // ]) + : Container(), + isMixBox + ? Column( + children: [ + packageBox, + Row( + children: getPackageList(_box!.packages), + ), + ], + ) + : Column( + children: [ + cartonBox, + Row( + children: getCartonList(_box!.mixCartons), ), - _cartonSubmit?.billToValue == billToSender - ? billWidget - : const SizedBox() ], ), - )) - ], - ) - // , - - // Row( - // children: getPackageList(_box!.packages), - // ), - // ]) - :Container(), - isMixBox ? - Column(children: [ - packageBox, - Row( - children: getPackageList(_box!.packages), - ), - ],):Column( - children: [ - cartonBox, - Row( - children: getCartonList(_box!.mixCartons), - ), - ], - ), - isCutomDuty - ? - surchargeItemBox: - cargosBox, - + isCutomDuty ? surchargeItemBox : cargosBox, + Padding( padding: EdgeInsets.only(left: 200.0, right: 8.0), child: ElevatedButton( @@ -571,20 +497,19 @@ class _CartonInfoState extends State { } _gotoEditor() async { - _box!.mixCartons = _box!.mixCartons; bool? updated = await Navigator.push( context, CupertinoPageRoute(builder: (context) => CartonEditor(carton: _box)), ); if (updated ?? false) { - var cartonModel = Provider.of(context, listen: false); - var c = await cartonModel.getCarton(widget.box.id ?? ""); - setState(() { - _box = c; - _loadPackages(); - _loadMixCartons(); - _updateBoxData(); - }); + // var cartonModel = Provider.of(context, listen: false); + // var c = await cartonModel.getCarton(widget.box.id ?? ""); + // setState(() { + // _box = c; + // _loadPackages(); + // _loadMixCartons(); + // _updateBoxData(); + // }); } } @@ -622,7 +547,8 @@ class _CartonInfoState extends State { )); }).toList(); } - List getCartonList(List _c) { + + List getCartonList(List _c) { return _c.map((c) { return Container( padding: EdgeInsets.only(top: 0), From e485e5792e91e1572b6d3e90600eba8783a6c86d Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 13:35:32 +0630 Subject: [PATCH 04/10] update carton info --- assets/local/localization_en.json | 2 + assets/local/localization_mu.json | 1 + lib/domain/entities/carton.dart | 4 +- lib/pages/carton/carton_editor.dart | 6 +- lib/pages/carton/carton_info.dart | 543 +++++++----------- lib/pages/carton/carton_list.dart | 2 +- lib/pages/carton/carton_list_row.dart | 2 +- .../carton/mix_carton/mix_carton_editor.dart | 5 +- .../carton/mix_carton/mix_carton_form.dart | 199 +++++++ lib/pages/carton/model/carton_model.dart | 17 +- ...n_editor.dart => package_carton_form.dart} | 16 +- lib/pages/invoice/invoice_info.dart | 6 +- lib/pages/package/model/package_model.dart | 15 + 13 files changed, 466 insertions(+), 352 deletions(-) create mode 100644 lib/pages/carton/mix_carton/mix_carton_form.dart rename lib/pages/carton/{package_carton_editor.dart => package_carton_form.dart} (96%) diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index 8442fde..af74e52 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -344,6 +344,8 @@ "box.bill_to":"Bill to", "box.delvery_carton":"Delivery carton", "box.pick_up_carton":"Pick-up carton", + "box.delete.btn":"Delete carton", + "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index c59ed1c..d5cb055 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -343,6 +343,7 @@ "box.bill_to":"Bill to", "box.delvery_carton":"Delivery carton", "box.pick_up_carton":"Pick-up carton", + "box.delete.btn":"Delete carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/domain/entities/carton.dart b/lib/domain/entities/carton.dart index 35d74e0..cb94a19 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -37,7 +37,7 @@ class Carton { String? cartonSizeID; String? cartonSizeName; double cartonWeight; - String? billToValue; + String? billTo; bool isSelected; int rate; @@ -149,7 +149,7 @@ class Carton { this.packages = const [], this.cargoTypes = const [], this.cartonNumber, - this.billToValue, + this.billTo, this.fcsShipmentID, this.fcsShipmentNumber, this.packageIDs = const [], diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 2368710..79799ef 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -16,7 +16,7 @@ import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import '../main/util.dart'; import 'carton_editor_for_package.dart'; import 'carton_info.dart'; -import 'mix_carton/mix_carton_editor.dart'; +import 'mix_carton/mix_carton_form.dart'; import 'carton_row.dart'; class CartonEditor extends StatefulWidget { @@ -164,7 +164,7 @@ class _CartonEditorState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => const MixCartonEditor())); + builder: (context) => const MixCartonForm())); } }, child: Icon(Icons.add_circle, color: primaryColor), @@ -307,7 +307,7 @@ class _CartonEditorState extends State { onTap: () async { Navigator.push( context, - CupertinoPageRoute(builder: (context) => CartonInfo(box: c)), + CupertinoPageRoute(builder: (context) => CartonInfo(carton: c)), ); }, child: CartonRow(box: c)); diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 788d446..2d31edc 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -4,11 +4,8 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/carton/carton_image_upload.dart'; -import 'package:fcs/pages/carton/carton_submit.dart'; -import 'package:fcs/pages/carton_size/model/carton_size_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; -import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -20,196 +17,149 @@ import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; - -import 'carton_editor.dart'; +import '../widgets/local_button.dart'; +import 'mix_carton/mix_carton_editor.dart'; import 'model/carton_model.dart'; -final DateFormat dateFormat = DateFormat("d MMM yyyy"); -final NumberFormat numberFormatter = NumberFormat("#,###"); - class CartonInfo extends StatefulWidget { - final Package? package; - final Carton box; - final String? billToValue; - final CartonSubmit? cartonSubmit; - - CartonInfo( - {required this.box, this.billToValue, this.package, this.cartonSubmit}); + final Carton carton; + CartonInfo({required this.carton}); @override _CartonInfoState createState() => _CartonInfoState(); } class _CartonInfoState extends State { - bool _isLoading = false; - Carton? _box; - - CartonSubmit? _cartonSubmit; - + final DateFormat dateFormat = DateFormat("d MMM yyyy"); + final NumberFormat numberFormatter = NumberFormat("#,###"); MultiImgController multiImgController = MultiImgController(); - TextEditingController _widthController = new TextEditingController(); - TextEditingController _heightController = new TextEditingController(); - TextEditingController _lengthController = new TextEditingController(); - TextEditingController _cartonSizeController = new TextEditingController(); - double volumetricRatio = 0; - double shipmentWeight = 0; - String? selectMixBoxType; - bool isMixBox = false; - bool isFromShipments = false; - bool isFromPackages = false; - bool isSmallBag = false; - bool isFromCartons = false; + bool _isLoading = false; + late Carton _carton; - bool isCutomDuty = false; - final List cargoTypes = []; - final List surchareItems = []; - final List cartons = []; + List _cargoTypes = []; + List _surchareItems = []; + List _mixCartons = []; + List _packages = []; @override void initState() { + _carton = widget.carton; + _init(); super.initState(); - _box = widget.box; - _box?.billToValue = "Bill to sender"; - - //initPackage(widget.package!); - //for shipment weight - volumetricRatio = Provider.of(context, listen: false) - .rate - .volumetricRatio; - _lengthController.addListener(_calShipmentWeight); - _widthController.addListener(_calShipmentWeight); - _heightController.addListener(_calShipmentWeight); - multiImgController.setImageUrls = _box!.photos; - // _updateBoxData(); - _loadPackages(); - _loadMixCartons(); } - _updateBoxData() { - _widthController.text = _box!.width.toString(); - _heightController.text = _box!.height.toString(); - _lengthController.text = _box!.length.toString(); - _cartonSizeController.text = _box!.cartonSizeName ?? ""; - isMixBox = _box!.cartonType == carton_mix_box; - isFromShipments = _box!.cartonType == carton_from_shipments; - isFromPackages = _box!.cartonType == carton_from_packages; - isSmallBag = _box!.cartonType == carton_small_bag; - isFromCartons = _box!.cartonType == carton_from_cartons; - - selectMixBoxType = _box!.mixBoxType; - getCartonSize(); - } - - getCartonSize() { - var cartonSizeModel = Provider.of(context, listen: false); - cartonSizeModel.cartonSizes.forEach((c) { - if (c.length == _box!.length && - c.width == _box!.width && - c.height == _box!.height) { - setState(() { - _cartonSizeController.text = c.name ?? ""; - }); - } - }); - } - - _loadPackages() async { - if (!isFromPackages && !isSmallBag) return; - - // if (_box!.cartonType == carton_from_packages && _box!.userID == null) - // return; - PackageModel packageModel = - Provider.of(context, listen: false); - List packages = - await packageModel.getPackages(_box!.userID ?? "", [ - package_processed_status, - package_packed_status, - package_shipped_status, - package_delivered_status - ]); - packages = packages.where((p) => _box!.packageIDs.contains(p.id)).toList(); - packages.forEach((p) { - p.isChecked = true; - }); - - setState(() { - _box!.packages = packages; - }); - } - - _loadMixCartons() async { - if (_box!.cartonType != carton_mix_box) return; - CartonModel cartonModel = Provider.of(context, listen: false); - List catons = []; - for (var id in _box!.mixCartonIDs) { - Carton c = await cartonModel.getCarton(id); - catons.add(c); + _init() async { + _carton.billTo = billToSender; + _carton.cartonType = carton_from_packages; + multiImgController.setImageUrls = _carton.photos; + _cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList(); + _surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList(); + if (_carton.cartonType == carton_from_packages) { + _packages = await context + .read() + .getPackagesByIds(_carton.packageIDs); } - setState(() { - _box!.mixCartons = catons; - }); - } + if (_carton.cartonType == carton_mix_carton) { + _mixCartons = await context + .read() + .getCartonsByIds(_carton.mixCartonIDs); + } - _calShipmentWeight() { - double l = double.tryParse(_lengthController.text) ?? 0; - double w = double.tryParse(_widthController.text) ?? 0; - double h = double.tryParse(_heightController.text) ?? 0; - setState(() { - shipmentWeight = l * w * h / volumetricRatio; - }); + if (mounted) { + setState(() {}); + } } - @override - void dispose() { - super.dispose(); - } - - final DateFormat dateFormat = DateFormat("d MMM yyyy"); - @override Widget build(BuildContext context) { double totalWeight = - _box!.cargoTypes.fold(0, (sum, value) => sum + value.weight); - double totalPieces = surchareItems.fold(0, (sum, value) => sum + value.qty); + _carton.cargoTypes.fold(0, (sum, value) => sum + value.weight); + double totalSurchargeCount = + _surchareItems.fold(0, (sum, value) => sum + value.qty); final cartonTypeBox = DisplayText( - text: _box!.cartonNumber, + text: _carton.cartonNumber, labelTextKey: "box.number", ); - final cartonQrBox = DisplayText( - iconData: AntDesign.qrcode, - ); + + final cartonQrBox = DisplayText(iconData: AntDesign.qrcode); + final shipmentBox = DisplayText( - text: _box!.fcsShipmentNumber, + text: _carton.fcsShipmentNumber, labelTextKey: "box.fcs_shipment_num", ); + final deliveryBox = DisplayText( text: "Delivery Carton", labelTextKey: "box.delivery_type", ); - final customerNameBox = DisplayText( - text: _box!.userName == null ? "" : _box!.userName, - subText: Text(_box!.fcsID ?? "", style: textStyle), + final senderBox = DisplayText( + text: _carton.userName == null ? "" : _carton.userName, + subText: Text(_carton.fcsID ?? "", style: textStyle), labelTextKey: "box.name", ); final consigneeNameBox = DisplayText( - text: _box!.senderName != null ? _box!.senderName : "", - subText: Text(_box!.senderFCSID ?? "", style: textStyle), + text: _carton.senderName != null ? _carton.senderName : "", + subText: Text(_carton.senderFCSID ?? "", style: textStyle), labelTextKey: "processing.consignee.name", ); - final packageBox = DisplayText( - labelTextKey: "box.package", - ); - final cartonBox = DisplayText( - labelTextKey: "box.shipment.boxes", + final billWidget = Expanded( + child: Padding( + padding: EdgeInsets.only(left: 0, top: 15), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(Ionicons.document_text_outline, + color: primaryColor, size: 20), + Text("Bill to", + style: TextStyle(color: primaryColor, fontSize: 15)) + ], + ))); + + final userRowBox = Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + senderBox, + ], + ), + ), + _carton.billTo == billToSender ? billWidget : const SizedBox() + ], + ), + ), + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + consigneeNameBox, + ], + ), + ), + _carton.billTo == billToConsignee ? billWidget : const SizedBox() + ], + )) + ], ); + final cargosBox = Padding( - padding: const EdgeInsets.only(top: 10), + padding: const EdgeInsets.only(top: 15), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -232,7 +182,7 @@ class _CartonInfoState extends State { children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, - children: _box!.cargoTypes.map((e) { + children: _cargoTypes.map((e) { return Padding( padding: const EdgeInsets.symmetric(vertical: 3), child: Row( @@ -258,7 +208,7 @@ class _CartonInfoState extends State { ]), ); final surchargeItemBox = Padding( - padding: const EdgeInsets.only(top: 10), + padding: const EdgeInsets.only(top: 15), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -269,7 +219,7 @@ class _CartonInfoState extends State { fontWeight: FontWeight.normal), Padding( padding: EdgeInsets.only(right: 100), - child: Text("${removeTrailingZeros(totalPieces)} pcs", + child: Text("${removeTrailingZeros(totalSurchargeCount)} pcs", style: TextStyle(color: Colors.black54, fontSize: 15))) ], ), @@ -281,7 +231,7 @@ class _CartonInfoState extends State { children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, - children: surchareItems.map((e) { + children: _surchareItems.map((e) { return Padding( padding: const EdgeInsets.symmetric(vertical: 3), child: Row( @@ -303,7 +253,7 @@ class _CartonInfoState extends State { const SizedBox(height: 10), Column( crossAxisAlignment: CrossAxisAlignment.start, - children: surchareItems.map((e) { + children: _surchareItems.map((e) { return Padding( padding: const EdgeInsets.symmetric(vertical: 3), child: Row( @@ -333,18 +283,37 @@ class _CartonInfoState extends State { title: "Receipt File", ); - final billWidget = Expanded( - child: Padding( - padding: EdgeInsets.only(left: 0, top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Ionicons.document_text_outline, - color: primaryColor, size: 20), - Text("Bill to", - style: TextStyle(color: primaryColor, fontSize: 15)) - ], - ))); + final uploadImageBtn = Padding( + padding: EdgeInsets.only(left: 200.0, right: 8.0), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xff272262), + elevation: 3, + shape: + RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)), + minimumSize: Size(10, 35), + ), + onPressed: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => CartonImageUpload(box: _carton)), + ); + }, + child: const Text('Upload Images'), + ), + ); + + final deleteBtn = Padding( + padding: const EdgeInsets.symmetric(horizontal: 30), + child: LocalButton( + color: dangerColor, + textKey: "box.delete.btn", + callBack: () { + _delete(); + }, + ), + ); return LocalProgress( inAsyncCall: _isLoading, @@ -371,146 +340,92 @@ class _CartonInfoState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Flexible( - child: shipmentBox, - ), - Flexible( - child: deliveryBox, - ), + Flexible(child: shipmentBox), + Flexible(child: deliveryBox), ], ), - // isMixBox - // ? - // displayMixBox:Container(), - - isMixBox - ? Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - child: Row( - //crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - customerNameBox, - ], - ), - ), - _box?.billToValue == billToSender - ? billWidget - : const SizedBox( - height: 300.0, - ) - ], + userRowBox, + _packages.isEmpty + ? const SizedBox() + : Padding( + padding: const EdgeInsets.only(top: 15), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + LocalText(context, "box.package", + color: Colors.black54, fontSize: 15), + const SizedBox(height: 5), + Column( + children: getPackageList(_packages), ), - ), - Expanded( - child: Padding( - padding: const EdgeInsets.only(left: 0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - consigneeNameBox, - ], - ), - ), - _cartonSubmit?.billToValue == billToSender - ? billWidget - : const SizedBox() - ], - ), - )) - ], - ) - // , - - // Row( - // children: getPackageList(_box!.packages), - // ), - // ]) - : Container(), - isMixBox - ? Column( - children: [ - packageBox, - Row( - children: getPackageList(_box!.packages), - ), - ], - ) - : Column( - children: [ - cartonBox, - Row( - children: getCartonList(_box!.mixCartons), - ), - ], + ], + ), ), - isCutomDuty ? surchargeItemBox : cargosBox, - - Padding( - padding: EdgeInsets.only(left: 200.0, right: 8.0), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Color(0xff272262), - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5.0)), - minimumSize: Size(10, 35), //////// HERE - ), - onPressed: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => - CartonImageUpload(box: _box)), - ); - }, - child: const Text('Upload Images'), - ), - ), + _mixCartons.isEmpty + ? const SizedBox() + : Padding( + padding: const EdgeInsets.only(top: 15), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + LocalText(context, "box.shipment.boxes", + color: Colors.black54, fontSize: 15), + const SizedBox(height: 5), + Column(children: getCartonList(_mixCartons)), + ], + ), + ), + _cargoTypes.isEmpty ? const SizedBox() : cargosBox, + _surchareItems.isEmpty ? const SizedBox() : surchargeItemBox, + uploadImageBtn, img, - Center( - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Color(0xffff0606), - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5.0)), - minimumSize: Size(300, 45), //////// HERE - ), - onPressed: () {}, - child: const Text('Delete Carton', - style: TextStyle(fontSize: 20)), - ), - ), + deleteBtn ])))); } + List getPackageList(List list) { + return list.map((p) { + return Container( + padding: EdgeInsets.only(top: 0), + child: Container( + child: Row(children: [new Text(p.trackingID ?? "")]), + )); + }).toList(); + } + + List getCartonList(List list) { + return list.map((c) { + return Container( + padding: EdgeInsets.only(top: 0), + child: Container( + child: Row(children: [new Text(c.cartonNumber ?? '')]), + )); + }).toList(); + } + _gotoEditor() async { - bool? updated = await Navigator.push( - context, - CupertinoPageRoute(builder: (context) => CartonEditor(carton: _box)), - ); - if (updated ?? false) { - // var cartonModel = Provider.of(context, listen: false); - // var c = await cartonModel.getCarton(widget.box.id ?? ""); - // setState(() { - // _box = c; - // _loadPackages(); - // _loadMixCartons(); - // _updateBoxData(); - // }); + if (_carton.cartonType == carton_mix_carton) { + bool? updated = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => MixCartonEditor(carton: _carton)), + ); } + // bool? updated = await Navigator.push( + // context, + // CupertinoPageRoute( + // builder: (context) => MixCartonEditor(carton: _carton)), + // ); + // if (updated ?? false) { + // // var cartonModel = Provider.of(context, listen: false); + // // var c = await cartonModel.getCarton(widget.box.id ?? ""); + // // setState(() { + // // _box = c; + // // _loadPackages(); + // // _loadMixCartons(); + // // _updateBoxData(); + // // }); + // } } _delete() { @@ -524,9 +439,9 @@ class _CartonInfoState extends State { _isLoading = true; }); try { - var cartonModel = Provider.of(context, listen: false); - await cartonModel.deleteCarton(widget.box); - Navigator.pop(context, true); + // var cartonModel = Provider.of(context, listen: false); + // await cartonModel.deleteCarton(widget.carton); + // Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); } finally { @@ -535,40 +450,4 @@ class _CartonInfoState extends State { }); } } - - List getPackageList(List _p) { - return _p.map((p) { - return Container( - padding: EdgeInsets.only(top: 0), - child: Container( - //padding: - //EdgeInsets.only(top: 0.0), - child: Row(children: [new Text(p.trackingID ?? '')]), - )); - }).toList(); - } - - List getCartonList(List _c) { - return _c.map((c) { - return Container( - padding: EdgeInsets.only(top: 0), - child: Container( - //padding: - //EdgeInsets.only(top: 0.0), - child: Row(children: [new Text(c.cartonNumber ?? '')]), - )); - }).toList(); - } - - List getCargoList(List _c) { - return _c.map((c) { - return Container( - padding: EdgeInsets.only(top: 0), - child: Container( - //padding: - //EdgeInsets.only(top: 0.0), - child: Row(children: [new Text(c.name ?? '')]), - )); - }).toList(); - } } diff --git a/lib/pages/carton/carton_list.dart b/lib/pages/carton/carton_list.dart index 0802189..067133e 100644 --- a/lib/pages/carton/carton_list.dart +++ b/lib/pages/carton/carton_list.dart @@ -104,7 +104,7 @@ class _CartonListState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => CartonInfo(box: c)), + builder: (context) => CartonInfo(carton: c)), ); }); }), diff --git a/lib/pages/carton/carton_list_row.dart b/lib/pages/carton/carton_list_row.dart index fe0627e..be93d29 100644 --- a/lib/pages/carton/carton_list_row.dart +++ b/lib/pages/carton/carton_list_row.dart @@ -19,7 +19,7 @@ class CartonListRow extends StatelessWidget { onTap: () { Navigator.push( context, - CupertinoPageRoute(builder: (context) => CartonInfo(box: box)), + CupertinoPageRoute(builder: (context) => CartonInfo(carton: box)), ); }, child: Container( diff --git a/lib/pages/carton/mix_carton/mix_carton_editor.dart b/lib/pages/carton/mix_carton/mix_carton_editor.dart index 463ceaa..ed31519 100644 --- a/lib/pages/carton/mix_carton/mix_carton_editor.dart +++ b/lib/pages/carton/mix_carton/mix_carton_editor.dart @@ -21,9 +21,8 @@ import 'mix_carton_submit.dart'; import 'type_widget.dart'; class MixCartonEditor extends StatefulWidget { - const MixCartonEditor({ - Key? key, - }) : super(key: key); + final Carton carton; + const MixCartonEditor({Key? key, required this.carton}) : super(key: key); @override State createState() => _MixCartonEditorState(); diff --git a/lib/pages/carton/mix_carton/mix_carton_form.dart b/lib/pages/carton/mix_carton/mix_carton_form.dart new file mode 100644 index 0000000..3145652 --- /dev/null +++ b/lib/pages/carton/mix_carton/mix_carton_form.dart @@ -0,0 +1,199 @@ +// ignore_for_file: deprecated_member_use + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:provider/provider.dart'; + +import '../../../domain/constants.dart'; +import '../../../domain/entities/carton.dart'; +import '../../../domain/entities/carton_size.dart'; +import '../../../domain/entities/fcs_shipment.dart'; +import '../../../domain/vo/local_step.dart'; +import '../../../helpers/theme.dart'; +import '../../main/util.dart'; +import '../../widgets/local_text.dart'; +import '../../widgets/progress.dart'; +import '../../widgets/step_widget.dart'; +import '../model/carton_selection_model.dart'; +import 'carton_selection_widget.dart'; +import 'mix_carton_submit.dart'; +import 'type_widget.dart'; + +class MixCartonForm extends StatefulWidget { + const MixCartonForm({Key? key}) : super(key: key); + + @override + State createState() => _MixCartonFormState(); +} + +class _MixCartonFormState extends State { + var dateFormatter = DateFormat('dd MMM yyyy'); + final NumberFormat numberFormatter = NumberFormat("#,###"); + List steps = [ + LocalStep(lable: 'Type', stepType: StepType.TYPE), + LocalStep(lable: 'Cartons', stepType: StepType.CARTONS), + LocalStep(lable: 'Submit', stepType: StepType.SUBMIT) + ]; + List _cartons = []; + + int currentStep = 0; + double _length = 0; + double _width = 0; + double _height = 0; + + FcsShipment? _shipment; + String _cartonSizeType = standardCarton; + CartonSize? _standardSize; + bool _isLoading = false; + + @override + void initState() { + context.read().clearSelection(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return WillPopScope( + onWillPop: () { + if (currentStep == 0) { + Navigator.of(context).pop(); + } + if (currentStep > 0) { + setState(() { + currentStep -= 1; + }); + } + + return Future.value(false); + }, + child: LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + elevation: 0, + centerTitle: true, + leading: IconButton( + icon: const Icon(CupertinoIcons.back, + color: primaryColor, size: 25), + onPressed: () { + if (currentStep == 0) { + Navigator.of(context).pop(); + } + if (currentStep > 0) { + setState(() { + currentStep -= 1; + }); + } + }, + ), + backgroundColor: Colors.white, + title: LocalText(context, 'boxes.new', + color: primaryColor, fontSize: 20), + ), + body: Column( + children: [ + StepperWidget( + labels: steps.map((e) => e.lable).toList(), + currentStep: currentStep, + eachStepWidth: MediaQuery.of(context).size.width / 3, + onChange: (index) { + if (index > currentStep) { + return; + } + setState(() { + currentStep = index; + }); + }, + ), + getContent(currentStep) + ], + ))), + ); + } + + Widget getContent(int index) { + var step = steps[index]; + if (step.stepType == StepType.TYPE) { + return Expanded( + child: TypeWidget( + shipment: _shipment, + cartonSizeType: _cartonSizeType, + standardSize: _standardSize, + length: _length, + width: _width, + height: _height, + onPrevious: () { + Navigator.pop(context); + }, + onContinue: (shipment, cartonSizeType, + {standardSize, length, width, height}) { + setState(() { + _shipment = shipment; + _cartonSizeType = cartonSizeType; + _standardSize = standardSize; + _length = length ?? 0; + _width = width ?? 0; + _height = height ?? 0; + currentStep += 1; + }); + }, + )); + } else if (step.stepType == StepType.CARTONS) { + return Expanded( + child: CartonSelectionWidget( + shipment: _shipment!, + cartons: _cartons, + onContinue: (cartons) { + setState(() { + _cartons = List.from(cartons); + currentStep += 1; + }); + }, + onPrevious: (cartons) { + setState(() { + _cartons = List.from(cartons); + currentStep -= 1; + }); + }, + ), + ); + } else { + return Expanded( + child: MixCartonSubmit( + cartonSizeType: _cartonSizeType, + standardSize: _standardSize, + length: _length, + width: _width, + height: _height, + shipment: _shipment!, + cartons: _cartons, + onCreate: () { + _create(); + }, + onPrevious: () { + setState(() { + currentStep -= 1; + }); + }, + ), + ); + } + } + + _create() async { + setState(() { + _isLoading = true; + }); + try { + Navigator.pop(context, true); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } +} diff --git a/lib/pages/carton/model/carton_model.dart b/lib/pages/carton/model/carton_model.dart index abb86e2..736b48e 100644 --- a/lib/pages/carton/model/carton_model.dart +++ b/lib/pages/carton/model/carton_model.dart @@ -205,7 +205,7 @@ class CartonModel extends BaseModel { return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList(); } - Future getCarton(String id) async { + Future getCarton(String id) async { String path = "/$cartons_collection"; var snap = await FirebaseFirestore.instance.collection(path).doc(id).get(); return Carton.fromMap(snap.data() as Map, snap.id); @@ -226,4 +226,19 @@ class CartonModel extends BaseModel { Future> searchCarton(String term) async { return Services.instance.cartonService.searchCarton(term); } + + Future> getCartonsByIds(List cartonIds) async { + List cartons = []; + try { + for (var e in cartonIds) { + Carton? c = await getCarton(e); + if (c != null) { + cartons.add(c); + } + } + } catch (e) { + log.warning("Error!! $e"); + } + return cartons; + } } diff --git a/lib/pages/carton/package_carton_editor.dart b/lib/pages/carton/package_carton_form.dart similarity index 96% rename from lib/pages/carton/package_carton_editor.dart rename to lib/pages/carton/package_carton_form.dart index d70d6e1..a89a528 100644 --- a/lib/pages/carton/package_carton_editor.dart +++ b/lib/pages/carton/package_carton_form.dart @@ -25,17 +25,17 @@ import 'cargo_type_addtion.dart'; import 'carton_cargo_table.dart'; import 'model/carton_model.dart'; -class PackageCartonEditor extends StatefulWidget { +class PackageCartonForm extends StatefulWidget { final Carton? carton; final bool? isNew; final User? consignee; - PackageCartonEditor({this.carton, this.isNew, this.consignee}); + PackageCartonForm({this.carton, this.isNew, this.consignee}); @override - _PackageCartonEditorState createState() => _PackageCartonEditorState(); + _PackageCartonFormState createState() => _PackageCartonFormState(); } -class _PackageCartonEditorState extends State { +class _PackageCartonFormState extends State { TextEditingController _lengthCtl = new TextEditingController(); TextEditingController _widthCtl = new TextEditingController(); TextEditingController _heightCtl = new TextEditingController(); @@ -295,7 +295,7 @@ class _PackageCartonEditorState extends State { var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id); _c.weight = cargo.weight; _c.qty = cargo.qty; - }); + }); } _creatCarton() async { @@ -349,8 +349,10 @@ class _PackageCartonEditorState extends State { Navigator.pop(context, _c); } else { await cartonModel.updateCarton(carton); - Carton _c = await cartonModel.getCarton(_carton!.id!); - Navigator.pop(context, _c); + Carton? _c = await cartonModel.getCarton(_carton!.id!); + if (_c != null) { + Navigator.pop(context, _c); + } } } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/invoice/invoice_info.dart b/lib/pages/invoice/invoice_info.dart index 59a1427..ccf365f 100644 --- a/lib/pages/invoice/invoice_info.dart +++ b/lib/pages/invoice/invoice_info.dart @@ -49,8 +49,10 @@ class _InvoiceInfoState extends State { List cartons = []; for (var c in _invoice?.cartons ?? []) { var _carton = await cartonModel.getCarton(c.id); - _carton.isChecked = true; - cartons.add(_carton); + if (_carton != null) { + _carton.isChecked = true; + cartons.add(_carton); + } } setState(() { _invoice!.cartons = cartons; diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index 6b21260..809bb6a 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -359,4 +359,19 @@ class PackageModel extends BaseModel { Future packageReturn(Package package) { return Services.instance.packageService.packageReturn(package.id!); } + + Future> getPackagesByIds(List packageIds) async { + List packages = []; + try { + for (var e in packageIds) { + Package? p = await getPackage(e); + if (p != null) { + packages.add(p); + } + } + } catch (e) { + log.warning("Error!! $e"); + } + return packages; + } } From 2d912a20aa3fd1bd09e05ec759740c917a823610 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 13:49:18 +0630 Subject: [PATCH 05/10] update carton info --- lib/pages/carton/cargo_table.dart | 118 ------ lib/pages/carton/cargo_type_addtion.dart | 132 ------- lib/pages/carton/carton_cargo_table.dart | 260 ------------- lib/pages/carton/carton_editor.dart | 6 +- lib/pages/carton/carton_filter.dart | 2 +- ...d.dart => carton_image_upload_editor.dart} | 6 +- lib/pages/carton/carton_info.dart | 44 +-- lib/pages/carton/carton_list.dart | 2 +- lib/pages/carton/carton_package_editor.dart | 263 +++++++++++++ ..._package.dart => carton_package_form.dart} | 8 +- lib/pages/carton/package_carton_form.dart | 365 ------------------ .../carton/{ => widget}/carton_list_row.dart | 2 +- lib/pages/carton/{ => widget}/carton_row.dart | 0 .../{ => widget}/user_search_result.dart | 4 +- .../cargo_type_editor.dart | 0 lib/pages/shipment/shipment_box_editor.dart | 2 +- 16 files changed, 300 insertions(+), 914 deletions(-) delete mode 100644 lib/pages/carton/cargo_table.dart delete mode 100644 lib/pages/carton/cargo_type_addtion.dart delete mode 100644 lib/pages/carton/carton_cargo_table.dart rename lib/pages/carton/{carton_image_upload.dart => carton_image_upload_editor.dart} (94%) create mode 100644 lib/pages/carton/carton_package_editor.dart rename lib/pages/carton/{carton_editor_for_package.dart => carton_package_form.dart} (96%) delete mode 100644 lib/pages/carton/package_carton_form.dart rename lib/pages/carton/{ => widget}/carton_list_row.dart (99%) rename lib/pages/carton/{ => widget}/carton_row.dart (100%) rename lib/pages/carton/{ => widget}/user_search_result.dart (97%) rename lib/pages/{carton => shipment}/cargo_type_editor.dart (100%) diff --git a/lib/pages/carton/cargo_table.dart b/lib/pages/carton/cargo_table.dart deleted file mode 100644 index ea21a8f..0000000 --- a/lib/pages/carton/cargo_table.dart +++ /dev/null @@ -1,118 +0,0 @@ -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:flutter/material.dart'; - -class CargoTable extends StatefulWidget { - final List? cargoTypes; - - const CargoTable({ - Key? key, - this.cargoTypes, - }) : super(key: key); - - @override - _CargoTableState createState() => _CargoTableState(); -} - -class _CargoTableState extends State { - @override - Widget build(BuildContext context) { - return SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: DataTable( - headingRowHeight: 40, - columnSpacing: 50, - showCheckboxColumn: false, - decoration: BoxDecoration(border: Border.all(color: Colors.white)), - border: TableBorder(horizontalInside: BorderSide(color: Colors.white)), - columns: [ - DataColumn( - label: LocalText( - context, - "cargo.type", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.qty", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.weight", - color: Colors.grey, - ), - ), - ], - rows: getCargoRows(context), - ), - ); - } - - List getCargoRows(BuildContext context) { - if (widget.cargoTypes == null) { - return []; - } - double total = 0; - var rows = widget.cargoTypes!.map((c) { - total += c.weight; - return DataRow( - onSelectChanged: (bool? selected) async {}, - cells: [ - DataCell(new Text( - c.name ?? "", - style: textStyle, - )), - DataCell(c.qty == 0 - ? Center( - child: Text( - "-", - style: textStyle, - ), - ) - : Center( - child: Text( - c.qty.toString(), - style: textStyle, - ), - )), - DataCell( - Text(c.weight.toStringAsFixed(2), style: textStyle), - ), - ], - ); - }).toList(); - - var totalRow = DataRow( - onSelectChanged: (bool? selected) {}, - cells: [ - DataCell(Align( - alignment: Alignment.centerRight, - child: LocalText( - context, - "shipment.cargo.total", - color: Colors.black87, - fontWeight: FontWeight.bold, - ), - )), - DataCell(Text("")), - DataCell( - Padding( - padding: const EdgeInsets.only(right: 48.0), - child: Align( - alignment: Alignment.centerRight, - child: Text(total.toStringAsFixed(2)+" lb", - style: TextStyle(fontWeight: FontWeight.bold))), - ), - ), - ], - ); - rows.add(totalRow); - return rows; - } -} diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart deleted file mode 100644 index eb11f1e..0000000 --- a/lib/pages/carton/cargo_type_addtion.dart +++ /dev/null @@ -1,132 +0,0 @@ -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; -import 'package:fcs/pages/widgets/local_app_bar.dart'; -import 'package:fcs/pages/widgets/local_title.dart'; -import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class CargoTypeAddition extends StatefulWidget { - @override - _CargoTypeAdditionState createState() => _CargoTypeAdditionState(); -} - -class _CargoTypeAdditionState extends State { - bool _isLoading = false; - - List cargos = []; - List specialCargos = []; - - @override - void initState() { - super.initState(); - var shipmentRateModel = - Provider.of(context, listen: false); - - cargos = shipmentRateModel.rate.cargoTypes.map((e) => e.clone()).toList(); - specialCargos = List.from(shipmentRateModel.rate.customDuties); - specialCargos = - shipmentRateModel.rate.customDuties.map((e) => e.clone()).toList(); - - cargos.forEach((p) { - p.isChecked = false; - p.isCutomDuty = false; - p.weight = 0; - p.qty = 0; - }); - specialCargos.forEach((p) { - p.isChecked = false; - p.isCutomDuty = true; - p.weight = 0; - p.qty = 1; - }); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - List getCargoRowList(List _c) { - return _c.map((c) { - return Container( - child: Container( - padding: - EdgeInsets.only(left: 10.0, right: 5.0, top: 3.0, bottom: 3.0), - child: InkWell( - onTap: () { - setState(() { - c.isChecked = !c.isChecked; - }); - }, - child: Row( - children: [ - Checkbox( - value: c.isChecked, - activeColor: primaryColor, - onChanged: (bool? check) { - setState(() { - c.isChecked = check ?? false; - }); - }), - new Text(c.name ?? '', style: textStyle), - ], - ), - ), - ), - ); - }).toList(); - } - - final saveBtn = fcsButton( - context, - getLocalString(context, 'box.cargo.select.btn'), - callack: () { - List _cargos = - this.cargos.where((c) => c.isChecked).toList(); - List _scargos = - this.specialCargos.where((c) => c.isChecked).toList(); - _cargos.addAll(_scargos); - Navigator.pop(context, _cargos); - }, - ); - - return LocalProgress( - inAsyncCall: _isLoading, - child: Scaffold( - appBar: LocalAppBar( - labelKey: 'cargo.form.title', - backgroundColor: Colors.white, - labelColor: primaryColor, - arrowColor: primaryColor), - body: Container( - padding: EdgeInsets.all(8), - child: ListView( - shrinkWrap: true, - children: [ - LocalTitle( - textKey: "box.select.cargo.title", - ), - Column( - children: getCargoRowList(cargos), - ), - LocalTitle( - textKey: "box.select.cargo.title", - ), - Column( - children: getCargoRowList(specialCargos), - ), - SizedBox(height: 30), - saveBtn, - SizedBox(height: 20), - ], - ), - ), - ), - ); - } -} diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart deleted file mode 100644 index db8fe82..0000000 --- a/lib/pages/carton/carton_cargo_table.dart +++ /dev/null @@ -1,260 +0,0 @@ -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/widgets/dialog_input.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:flutter/material.dart'; - -typedef OnRemove(CargoType cargoType); -typedef OnUpdate(CargoType cargoType); - -class CargoTable extends StatefulWidget { - final List? cargoTypes; - final bool? isNew; - final OnRemove? onRemove; - final OnUpdate? onUpdate; - - const CargoTable( - {Key? key, this.cargoTypes, this.isNew, this.onRemove, this.onUpdate}) - : super(key: key); - - @override - _CargoTableState createState() => _CargoTableState(); -} - -class _CargoTableState extends State { - double totalWeight = 0; - List? cargoTypes; - - @override - void initState() { - cargoTypes = widget.cargoTypes; - if (!widget.isNew!) { - totalWeight = - cargoTypes!.fold(0, (previous, current) => previous + current.weight); - } - - super.initState(); - } - - @override - Widget build(BuildContext context) { - return SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: DataTable( - showCheckboxColumn: false, - headingRowHeight: 40, - // columnSpacing: 40, - decoration: BoxDecoration(border: Border.all(color: Colors.white)), - border: TableBorder(horizontalInside: BorderSide(color: Colors.white)), - columns: [ - DataColumn( - label: LocalText( - context, - "cargo.type", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.qty", - color: Colors.grey, - ), - ), - DataColumn( - label: LocalText( - context, - "cargo.weight", - color: Colors.grey, - ), - ), - ], - rows: getCargoRows(context), - ), - ); - } - - List getCargoRows(BuildContext context) { - if (cargoTypes == null) { - return []; - } - var rows = cargoTypes!.map((c) { - return DataRow( - onSelectChanged: (bool? selected) async {}, - cells: [ - DataCell( - new Text( - c.name ?? '', - style: textStyle, - ), - ), - DataCell( - c.isCutomDuty - ? GestureDetector( - onTap: () async { - String? _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "cargo.qty", value: c.qty.toString())); - - if (_t == null) return; - setState(() { - c.qty = int.tryParse(_t) ?? 0; - }); - if (widget.onUpdate != null) widget.onUpdate!(c); - }, - child: Center( - child: Container( - width: 40, - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - border: Border.all(color: primaryColor), - borderRadius: BorderRadius.all(Radius.circular(5.0)), - ), - child: new Text( - c.qty.toString(), - style: textStyle, - textAlign: TextAlign.center, - ), - ), - ), - ) - : Center( - child: new Text( - "-", - style: textStyle, - ), - ), - ), - DataCell( - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - GestureDetector( - onTap: () async { - if (this.totalWeight <= 0) { - showMsgDialog( - context, "Error", "Please insert total weight"); - return; - } - - String? _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "cargo.weight", - value: c.weight.toStringAsFixed(2))); - - if (_t == null) return; - setState(() { - c.weight = double.tryParse(_t) ?? 0; - }); - if (c.weight != 0) { - _cal(); - } - if (widget.onUpdate != null) widget.onUpdate!(c); - }, - child: Container( - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - border: Border.all(color: primaryColor), - borderRadius: BorderRadius.all(Radius.circular(5.0)), - ), - child: Text(c.weight.toStringAsFixed(2), style: textStyle), - ), - ), - widget.onRemove == null - ? SizedBox( - width: 50, - ) - : IconButton( - icon: Icon( - Icons.remove_circle, - color: primaryColor, - ), - onPressed: () { - if (widget.onRemove != null) widget.onRemove!(c); - }) - ], - ), - ), - ], - ); - }).toList(); - - var totalRow = DataRow( - onSelectChanged: (bool? selected) {}, - cells: [ - DataCell(Align( - alignment: Alignment.centerRight, - child: LocalText( - context, - "shipment.cargo.total", - color: Colors.black87, - fontWeight: FontWeight.bold, - ), - )), - DataCell(Text("")), - DataCell( - Padding( - padding: const EdgeInsets.only(right: 48.0), - child: Align( - alignment: Alignment.centerRight, - child: InkWell( - onTap: () async { - String? _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "shipment.cargo.total", - value: totalWeight.toStringAsFixed(2)), - ); - - if (_t == null) return; - setState(() { - totalWeight = double.tryParse(_t) ?? 0; - }); - _cal(); - }, - child: Container( - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - border: Border.all(color: primaryColor), - borderRadius: BorderRadius.all(Radius.circular(5.0)), - ), - child: Text(totalWeight.toStringAsFixed(2), - style: TextStyle(fontWeight: FontWeight.bold)), - ), - )), - ), - ), - ], - ); - rows.add(totalRow); - return rows; - } - - _cal() { - var cargoType = autoCalWeight(cargoTypes!, totalWeight); - if (cargoType == null) return; - - setState(() { - cargoTypes!.remove(cargoType); - cargoTypes!.add(cargoType); - }); - - if (widget.onUpdate != null) { - widget.onUpdate!(cargoType); - } - } -} - -CargoType? autoCalWeight(List cargoTypes, double total) { - List noWeight = cargoTypes.where((c) => c.weight == 0).toList(); - if (noWeight.length != 1) return null; - - double _existing = - cargoTypes.fold(0, (previous, current) => previous + current.weight); - - noWeight[0].weight = total - _existing; - return noWeight[0]; -} diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 79799ef..8a34610 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -14,10 +14,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import '../main/util.dart'; -import 'carton_editor_for_package.dart'; +import 'carton_package_form.dart'; import 'carton_info.dart'; import 'mix_carton/mix_carton_form.dart'; -import 'carton_row.dart'; +import 'widget/carton_row.dart'; class CartonEditor extends StatefulWidget { final Carton? carton; @@ -154,7 +154,7 @@ class _CartonEditorState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => CartonEditorForPackage( + builder: (context) => CartonPackageForm( sender: _sender!, consignee: _consignee!, ))); diff --git a/lib/pages/carton/carton_filter.dart b/lib/pages/carton/carton_filter.dart index 27b687d..9fc0054 100644 --- a/lib/pages/carton/carton_filter.dart +++ b/lib/pages/carton/carton_filter.dart @@ -8,7 +8,7 @@ import '../../helpers/theme.dart'; import '../../localization/app_translations.dart'; import '../main/util.dart'; import '../widgets/local_text.dart'; -import 'user_search_result.dart'; +import 'widget/user_search_result.dart'; import 'model/carton_model.dart'; import 'model/consignee_selection_model.dart'; diff --git a/lib/pages/carton/carton_image_upload.dart b/lib/pages/carton/carton_image_upload_editor.dart similarity index 94% rename from lib/pages/carton/carton_image_upload.dart rename to lib/pages/carton/carton_image_upload_editor.dart index d2bf2f9..37b60c2 100644 --- a/lib/pages/carton/carton_image_upload.dart +++ b/lib/pages/carton/carton_image_upload_editor.dart @@ -9,14 +9,14 @@ import '../widgets/multi_img_file.dart'; typedef void FindCallBack(); -class CartonImageUpload extends StatefulWidget { +class CartonImageUploadEditor extends StatefulWidget { final Carton? box; - const CartonImageUpload({this.box}); + const CartonImageUploadEditor({this.box}); @override _CartonImageUploaState createState() => _CartonImageUploaState(); } -class _CartonImageUploaState extends State { +class _CartonImageUploaState extends State { bool _isLoading = false; Carton? _box; MultiImgController multiImgController = MultiImgController(); diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 2d31edc..8cb50ca 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -3,7 +3,7 @@ import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/carton/carton_image_upload.dart'; +import 'package:fcs/pages/carton/carton_image_upload_editor.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; @@ -18,6 +18,7 @@ import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import '../widgets/local_button.dart'; +import 'carton_package_editor.dart'; import 'mix_carton/mix_carton_editor.dart'; import 'model/carton_model.dart'; @@ -297,7 +298,7 @@ class _CartonInfoState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => CartonImageUpload(box: _carton)), + builder: (context) => CartonImageUploadEditor(box: _carton)), ); }, child: const Text('Upload Images'), @@ -404,28 +405,25 @@ class _CartonInfoState extends State { } _gotoEditor() async { - if (_carton.cartonType == carton_mix_carton) { - bool? updated = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => MixCartonEditor(carton: _carton)), - ); + bool? updated = _carton.cartonType == carton_mix_carton + ? await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => MixCartonEditor(carton: _carton)), + ) + : await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => CartonPackageEditor(carton: _carton)), + ); + + if (updated ?? false) { + Carton? c = + await context.read().getCarton(widget.carton.id ?? ""); + if (c == null) return; + _carton = c; + _init(); } - // bool? updated = await Navigator.push( - // context, - // CupertinoPageRoute( - // builder: (context) => MixCartonEditor(carton: _carton)), - // ); - // if (updated ?? false) { - // // var cartonModel = Provider.of(context, listen: false); - // // var c = await cartonModel.getCarton(widget.box.id ?? ""); - // // setState(() { - // // _box = c; - // // _loadPackages(); - // // _loadMixCartons(); - // // _updateBoxData(); - // // }); - // } } _delete() { diff --git a/lib/pages/carton/carton_list.dart b/lib/pages/carton/carton_list.dart index 067133e..5a3a61d 100644 --- a/lib/pages/carton/carton_list.dart +++ b/lib/pages/carton/carton_list.dart @@ -17,7 +17,7 @@ import '../fcs_shipment/model/fcs_shipment_model.dart'; import 'carton_editor.dart'; import 'carton_filter.dart'; import 'carton_info.dart'; -import 'carton_list_row.dart'; +import 'widget/carton_list_row.dart'; class CartonList extends StatefulWidget { @override diff --git a/lib/pages/carton/carton_package_editor.dart b/lib/pages/carton/carton_package_editor.dart new file mode 100644 index 0000000..e0bf4e3 --- /dev/null +++ b/lib/pages/carton/carton_package_editor.dart @@ -0,0 +1,263 @@ +// ignore_for_file: deprecated_member_use + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:provider/provider.dart'; + +import '../../../domain/constants.dart'; +import '../../../domain/entities/carton_size.dart'; +import '../../../domain/entities/fcs_shipment.dart'; +import '../../../domain/vo/local_step.dart'; +import '../../../helpers/theme.dart'; +import '../../domain/entities/cargo_type.dart'; +import '../../domain/entities/carton.dart'; +import '../../domain/entities/package.dart'; +import '../../domain/entities/user.dart'; +import '../main/util.dart'; +import '../widgets/local_text.dart'; +import '../widgets/progress.dart'; +import '../widgets/step_widget.dart'; +import 'cargo_widget.dart'; +import 'carton_size_widget.dart'; +import 'carton_submit.dart'; +import 'model/package_selection_model.dart'; +import 'package_selection_widget.dart'; + +class CartonPackageEditor extends StatefulWidget { + final Carton carton; + + const CartonPackageEditor({Key? key, required this.carton}) : super(key: key); + + @override + State createState() => _CartonPackageEditorState(); +} + +class _CartonPackageEditorState extends State { + var dateFormatter = DateFormat('dd MMM yyyy'); + final NumberFormat numberFormatter = NumberFormat("#,###"); + List steps = [ + LocalStep(lable: 'Size', stepType: StepType.SIZE), + LocalStep(lable: 'Packages', stepType: StepType.PACKAGES), + LocalStep(lable: 'Cargos', stepType: StepType.CARGOS), + LocalStep(lable: 'Submit', stepType: StepType.SUBMIT) + ]; + List _packages = []; + List _cargoTypes = []; + List _surchareItems = []; + + int currentStep = 0; + double _length = 0; + double _width = 0; + double _height = 0; + + String _selectedDeliveryType = delivery_caton; + String _billToValue = billToSender; + + FcsShipment? _shipment; + String _cartonSizeType = standardCarton; + CartonSize? _standardSize; + bool _isLoading = false; + + User? _consignee; + User? _sender; + + @override + void initState() { + _sender = User( + name: "ptd-phyo44 kaelone", + fcsID: "FCS-8X6V", + phoneNumber: "+959444444444", + id: "48u_4s-HiQeW-HwSqeRd9TSMWh3mLZfSk5rpaUEh_zw"); + + _consignee = User( + id: "HsIwG88K-0_HSazgEy5QR27kcjkOvfv7_Sr1JP18Q1A", + name: "One One", + phoneNumber: "+959111111111", + fcsID: "FCS-EFRF"); + + context.read().clearSelection(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return WillPopScope( + onWillPop: () { + if (currentStep == 0) { + Navigator.of(context).pop(); + } + if (currentStep > 0) { + setState(() { + currentStep -= 1; + }); + } + + return Future.value(false); + }, + child: LocalProgress( + inAsyncCall: _isLoading, + child: Scaffold( + appBar: AppBar( + elevation: 0, + centerTitle: true, + leading: IconButton( + icon: const Icon(CupertinoIcons.back, + color: primaryColor, size: 25), + onPressed: () { + if (currentStep == 0) { + Navigator.of(context).pop(); + } + if (currentStep > 0) { + setState(() { + currentStep -= 1; + }); + } + }, + ), + backgroundColor: Colors.white, + title: LocalText(context, 'boxes.new', + color: primaryColor, fontSize: 20), + ), + body: Column( + children: [ + StepperWidget( + labels: steps.map((e) => e.lable).toList(), + currentStep: currentStep, + eachStepWidth: MediaQuery.of(context).size.width / 4, + onChange: (index) { + if (index > currentStep) { + return; + } + setState(() { + currentStep = index; + }); + }, + ), + getContent(currentStep) + ], + ))), + ); + } + + Widget getContent(int index) { + var step = steps[index]; + if (step.stepType == StepType.SIZE) { + return Expanded( + child: CartonSizeWidget( + deliveryType: _selectedDeliveryType, + billType: _billToValue, + sender: _sender!, + consignee: _consignee!, + shipment: _shipment, + cartonSizeType: _cartonSizeType, + standardSize: _standardSize, + length: _length, + width: _width, + height: _height, + onPrevious: () { + Navigator.pop(context); + }, + onContinue: (deliveryType, billType, shipment, cartonSizeType, + {standardSize, length, width, height}) { + setState(() { + _selectedDeliveryType = deliveryType; + _billToValue = billType; + _shipment = shipment; + _cartonSizeType = cartonSizeType; + _standardSize = standardSize; + _length = length ?? 0; + _width = width ?? 0; + _height = height ?? 0; + currentStep += 1; + }); + }, + )); + } else if (step.stepType == StepType.PACKAGES) { + return Expanded( + child: PackageSelectionWidget( + sender: _sender!, + consignee: _consignee!, + shipment: _shipment!, + packages: _packages, + onContinue: (packages) { + setState(() { + _packages = List.from(packages); + currentStep += 1; + }); + }, + onPrevious: (packages) { + setState(() { + _packages = List.from(packages); + currentStep -= 1; + }); + }, + ), + ); + } else if (step.stepType == StepType.CARGOS) { + return Expanded( + child: CargoWidget( + sender: _sender!, + consignee: _consignee!, + cargoTypes: _cargoTypes, + surchargeItems: _surchareItems, + onContinue: (cargoTypes, customDuties) { + setState(() { + _cargoTypes = List.from(cargoTypes); + _surchareItems = List.from(customDuties); + currentStep += 1; + }); + }, + onPrevious: (cargoTypes, customDuties) { + setState(() { + _cargoTypes = List.from(cargoTypes); + _surchareItems = List.from(customDuties); + currentStep -= 1; + }); + }, + ), + ); + } else { + return Expanded( + child: CartonSubmit( + sender: _sender!, + consingee: _consignee!, + billToValue: _billToValue, + cartonSizeType: _cartonSizeType, + standardSize: _standardSize, + length: _length, + width: _width, + height: _height, + deliveryType: _selectedDeliveryType, + shipment: _shipment!, + packages: _packages, + cargoTypes: _cargoTypes, + surchareItems: _surchareItems, + onCreate: () { + _create(); + }, + onPrevious: () { + setState(() { + currentStep -= 1; + }); + }, + ), + ); + } + } + + _create() async { + setState(() { + _isLoading = true; + }); + try { + Navigator.pop(context, true); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } +} diff --git a/lib/pages/carton/carton_editor_for_package.dart b/lib/pages/carton/carton_package_form.dart similarity index 96% rename from lib/pages/carton/carton_editor_for_package.dart rename to lib/pages/carton/carton_package_form.dart index 7f6be13..3f627c8 100644 --- a/lib/pages/carton/carton_editor_for_package.dart +++ b/lib/pages/carton/carton_package_form.dart @@ -23,11 +23,11 @@ import 'carton_submit.dart'; import 'model/package_selection_model.dart'; import 'package_selection_widget.dart'; -class CartonEditorForPackage extends StatefulWidget { +class CartonPackageForm extends StatefulWidget { final User sender; final User consignee; - const CartonEditorForPackage( + const CartonPackageForm( {Key? key, required this.sender, required this.consignee, @@ -35,10 +35,10 @@ class CartonEditorForPackage extends StatefulWidget { : super(key: key); @override - State createState() => _CartonEditorForPackageState(); + State createState() => _CartonPackageFormState(); } -class _CartonEditorForPackageState extends State { +class _CartonPackageFormState extends State { var dateFormatter = DateFormat('dd MMM yyyy'); final NumberFormat numberFormatter = NumberFormat("#,###"); List steps = [ diff --git a/lib/pages/carton/package_carton_form.dart b/lib/pages/carton/package_carton_form.dart deleted file mode 100644 index a89a528..0000000 --- a/lib/pages/carton/package_carton_form.dart +++ /dev/null @@ -1,365 +0,0 @@ -import 'package:fcs/domain/constants.dart'; -import 'package:fcs/domain/entities/carton.dart'; -import 'package:fcs/domain/entities/cargo_type.dart'; -import 'package:fcs/domain/entities/carton_size.dart'; -import 'package:fcs/domain/entities/package.dart'; -import 'package:fcs/domain/entities/user.dart'; -import 'package:fcs/domain/vo/delivery_address.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/carton_size/carton_size_list.dart'; -import 'package:fcs/pages/carton_size/model/carton_size_model.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; -import 'package:fcs/pages/widgets/delivery_address_selection.dart'; -import 'package:fcs/pages/widgets/length_picker.dart'; -import 'package:fcs/pages/widgets/local_button.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/material.dart'; -import 'package:flutter_vector_icons/flutter_vector_icons.dart'; -import 'package:provider/provider.dart'; - -import 'cargo_type_addtion.dart'; -import 'carton_cargo_table.dart'; -import 'model/carton_model.dart'; - -class PackageCartonForm extends StatefulWidget { - final Carton? carton; - final bool? isNew; - final User? consignee; - PackageCartonForm({this.carton, this.isNew, this.consignee}); - - @override - _PackageCartonFormState createState() => _PackageCartonFormState(); -} - -class _PackageCartonFormState extends State { - TextEditingController _lengthCtl = new TextEditingController(); - TextEditingController _widthCtl = new TextEditingController(); - TextEditingController _heightCtl = new TextEditingController(); - - Carton? _carton; - bool _isLoading = false; - DeliveryAddress? _deliveryAddress = new DeliveryAddress(); - List _cargoTypes = []; - CartonSize? selectedCatonSize; - bool isFromPackages = false; - bool isFromCartons = false; - - @override - void initState() { - super.initState(); - _load(); - } - - _load() { - _carton = widget.carton; - isFromPackages = _carton!.cartonType == carton_from_packages; - isFromCartons = _carton!.cartonType == carton_from_cartons; - - if (widget.isNew!) { - _lengthCtl.text = "0"; - _widthCtl.text = "0"; - _heightCtl.text = "0"; - } else { - _cargoTypes = widget.carton!.cargoTypes.map((e) => e.clone()).toList(); - _lengthCtl.text = _carton!.length.toString(); - _widthCtl.text = _carton!.width.toString(); - _heightCtl.text = _carton!.height.toString(); - _deliveryAddress = _carton!.deliveryAddress; - _getCartonSize(); - } - } - - _getCartonSize() { - var cartonSizeModel = Provider.of(context, listen: false); - cartonSizeModel.cartonSizes.forEach((c) { - if (c.length == _carton!.length && - c.width == _carton!.width && - c.height == _carton!.height) { - selectedCatonSize = CartonSize( - id: c.id, - name: c.name, - length: c.length, - width: c.width, - height: c.height); - } - }); - } - - @override - Widget build(BuildContext context) { - final lengthBox = LengthPicker( - controller: _lengthCtl, - lableKey: "box.length", - isReadOnly: false, - ); - final widthBox = LengthPicker( - controller: _widthCtl, - lableKey: "box.width", - isReadOnly: false, - ); - final heightBox = LengthPicker( - controller: _heightCtl, - lableKey: "box.height", - isReadOnly: false, - ); - 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 createBtn = LocalButton( - textKey: widget.isNew! ? "box.new_carton_btn" : "box.cargo.save.btn", - callBack: _creatCarton, - ); - - final cargoTableTitleBox = LocalTitle( - textKey: "box.cargo.type", - trailing: IconButton( - icon: Icon( - Icons.add_circle, - color: primaryColor, - ), - onPressed: () async { - List? cargos = await Navigator.push>( - context, - CupertinoPageRoute(builder: (context) => CargoTypeAddition())); - if (cargos == null) return; - setState(() { - _cargoTypes.addAll( - cargos.where((e) => !_cargoTypes.contains(e)).toList()); - }); - }), - ); - - final cargoTableBox = CargoTable( - isNew: widget.isNew, - cargoTypes: _cargoTypes, - onRemove: (c) => _removeCargo(c), - onUpdate: (c) => _updateCargo(c), - ); - - return LocalProgress( - inAsyncCall: _isLoading, - child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon( - CupertinoIcons.back, - color: primaryColor, - ), - onPressed: () => Navigator.of(context).pop()), - shadowColor: Colors.transparent, - backgroundColor: Colors.white, - title: LocalText( - context, - widget.isNew! ? "boxes.create.title" : "box.edit.title", - fontSize: 20, - color: primaryColor, - ), - ), - body: Padding( - padding: const EdgeInsets.all(8.0), - child: ListView( - children: [ - cargoTableTitleBox, - cargoTableBox, - LocalTitle(textKey: "box.dimension"), - cartonSizeDropdown(), - dimBox, - LocalTitle(textKey: "box.delivery_address"), - DefaultDeliveryAddress( - deliveryAddress: _deliveryAddress, - labelKey: "box.delivery_address", - onTap: () async { - DeliveryAddress? d = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => DeliveryAddressSelection( - deliveryAddress: _deliveryAddress, - user: User( - id: _carton!.userID, - name: _carton!.userName), - )), - ); - if (d == null) return; - setState(() { - _deliveryAddress = d; - }); - }), - SizedBox( - height: 20, - ), - createBtn - ], - ), - ), - ), - ); - } - - Widget cartonSizeDropdown() { - List _cartonSizes = - Provider.of(context).getCartonSizes; - - return Padding( - padding: const EdgeInsets.only(top: 10), - child: Row( - children: [ - Padding( - padding: const EdgeInsets.only(left: 0, right: 10), - child: Icon(AntDesign.CodeSandbox, color: primaryColor), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(right: 18.0), - child: LocalText( - context, - "box.carton_size", - color: Colors.black54, - fontSize: 16, - ), - ), - DropdownButton( - isDense: true, - value: selectedCatonSize, - style: TextStyle(color: Colors.black, fontSize: 14), - underline: Container( - height: 1, - color: Colors.grey, - ), - onChanged: (CartonSize? newValue) { - setState(() { - if (newValue!.name == MANAGE_CARTONSIZE) { - selectedCatonSize = null; - _manageCartonSize(); - return; - } - selectedCatonSize = newValue; - _widthCtl.text = selectedCatonSize!.width.toString(); - _heightCtl.text = selectedCatonSize!.height.toString(); - _lengthCtl.text = selectedCatonSize!.length.toString(); - }); - }, - isExpanded: true, - items: _cartonSizes - .map>((CartonSize value) { - return DropdownMenuItem( - value: value, - child: Text(value.name ?? "", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: value.name == MANAGE_CARTONSIZE - ? secondaryColor - : primaryColor)), - ); - }).toList(), - ), - ], - ), - ), - ], - ), - ); - } - - _manageCartonSize() { - Navigator.push( - context, - CupertinoPageRoute(builder: (context) => CartonSizeList()), - ); - } - - _removeCargo(CargoType cargo) { - setState(() { - _cargoTypes.remove(cargo); - }); - } - - _updateCargo(CargoType cargo) { - setState(() { - var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id); - _c.weight = cargo.weight; - _c.qty = cargo.qty; - }); - } - - _creatCarton() async { - if (_cargoTypes.length == 0) { - showMsgDialog(context, "Error", "Expect at least one cargo type"); - return; - } - double l = double.parse(_lengthCtl.text); - double w = double.parse(_widthCtl.text); - double h = double.parse(_heightCtl.text); - if ((l <= 0 || w <= 0 || h <= 0)) { - showMsgDialog(context, "Error", "Invalid dimension"); - return; - } - if (_deliveryAddress == null) { - showMsgDialog(context, "Error", "Invalid delivery address"); - return; - } - - Carton carton = Carton(); - carton.id = _carton!.id; - carton.cartonType = _carton!.cartonType; - carton.fcsShipmentID = _carton!.fcsShipmentID; - carton.cargoTypes = _cargoTypes; - if (isFromPackages) { - carton.userID = _carton!.userID; - carton.packages = _carton!.packages.where((e) => e.isChecked).toList(); - } - - if (isFromCartons) { - carton.userID = _carton!.userID; - carton.fcsID = _carton!.fcsID; - carton.userName = _carton!.userName; - carton.senderID = _carton!.senderID; - carton.senderFCSID = _carton!.senderFCSID; - carton.senderName = _carton!.senderName; - } - - carton.length = l; - carton.width = w; - carton.height = h; - carton.deliveryAddress = _deliveryAddress; - setState(() { - _isLoading = true; - }); - try { - CartonModel cartonModel = - Provider.of(context, listen: false); - if (widget.isNew!) { - Carton _c = await cartonModel.createCarton(carton); - Navigator.pop(context, _c); - } else { - await cartonModel.updateCarton(carton); - Carton? _c = await cartonModel.getCarton(_carton!.id!); - if (_c != null) { - Navigator.pop(context, _c); - } - } - } catch (e) { - showMsgDialog(context, "Error", e.toString()); - } finally { - setState(() { - _isLoading = false; - }); - } - } -} diff --git a/lib/pages/carton/carton_list_row.dart b/lib/pages/carton/widget/carton_list_row.dart similarity index 99% rename from lib/pages/carton/carton_list_row.dart rename to lib/pages/carton/widget/carton_list_row.dart index be93d29..c69dfca 100644 --- a/lib/pages/carton/carton_list_row.dart +++ b/lib/pages/carton/widget/carton_list_row.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; -import 'carton_info.dart'; +import '../carton_info.dart'; class CartonListRow extends StatelessWidget { final Carton box; diff --git a/lib/pages/carton/carton_row.dart b/lib/pages/carton/widget/carton_row.dart similarity index 100% rename from lib/pages/carton/carton_row.dart rename to lib/pages/carton/widget/carton_row.dart diff --git a/lib/pages/carton/user_search_result.dart b/lib/pages/carton/widget/user_search_result.dart similarity index 97% rename from lib/pages/carton/user_search_result.dart rename to lib/pages/carton/widget/user_search_result.dart index 1155b6e..330a089 100644 --- a/lib/pages/carton/user_search_result.dart +++ b/lib/pages/carton/widget/user_search_result.dart @@ -1,8 +1,8 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/material.dart'; -import '../../../helpers/theme.dart'; -import '../../domain/entities/user.dart'; +import '../../../../helpers/theme.dart'; +import '../../../domain/entities/user.dart'; typedef OnAction = Future Function(); diff --git a/lib/pages/carton/cargo_type_editor.dart b/lib/pages/shipment/cargo_type_editor.dart similarity index 100% rename from lib/pages/carton/cargo_type_editor.dart rename to lib/pages/shipment/cargo_type_editor.dart diff --git a/lib/pages/shipment/shipment_box_editor.dart b/lib/pages/shipment/shipment_box_editor.dart index b89c46c..76e27a7 100644 --- a/lib/pages/shipment/shipment_box_editor.dart +++ b/lib/pages/shipment/shipment_box_editor.dart @@ -2,7 +2,7 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/carton/cargo_type_editor.dart'; +import 'package:fcs/pages/shipment/cargo_type_editor.dart'; import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; From 02f1954127fc87d16ab62e0546870b864fd70866 Mon Sep 17 00:00:00 2001 From: sma Date: Fri, 9 Feb 2024 17:09:05 +0630 Subject: [PATCH 06/10] prepare carton info --- lib/domain/entities/carton.dart | 8 +- .../carton/carton_image_upload_editor.dart | 73 +++++++++---------- lib/pages/carton/carton_info.dart | 40 ++++++---- 3 files changed, 67 insertions(+), 54 deletions(-) diff --git a/lib/domain/entities/carton.dart b/lib/domain/entities/carton.dart index cb94a19..c6fded6 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -36,8 +36,10 @@ class Carton { String? mixCartonNumber; String? cartonSizeID; String? cartonSizeName; + String? cartonSizeType; + String? cartonStandardSize; double cartonWeight; - String? billTo; + String? billTo; bool isSelected; int rate; @@ -49,6 +51,7 @@ class Carton { String? remark; DateTime? arrivedDate; String? cartonNumber; + String? deliveryCarton; List packageIDs; List packages; @@ -159,6 +162,9 @@ class Carton { this.deliveryAddress, this.cartonSizeID, this.cartonSizeName, + this.cartonSizeType, + this.cartonStandardSize, + this.deliveryCarton, this.mixBoxType, this.mixCartons = const [], this.mixCartonIDs = const [], diff --git a/lib/pages/carton/carton_image_upload_editor.dart b/lib/pages/carton/carton_image_upload_editor.dart index 37b60c2..9e5a645 100644 --- a/lib/pages/carton/carton_image_upload_editor.dart +++ b/lib/pages/carton/carton_image_upload_editor.dart @@ -39,47 +39,40 @@ class _CartonImageUploaState extends State { labelColor: primaryColor, arrowColor: primaryColor, actions: [] - // isEdiable - // ? [ - // IconButton( - // icon: Icon(Icons.edit, color: primaryColor), - // onPressed: _gotoEditor, - // ), - // IconButton( - // icon: Icon(Icons.delete, color: primaryColor), - // onPressed: _delete, - // ), - // ] - // : [], + ), - body: ListView( - children: [ - Center( - child: Text("${_box?.cartonNumber}", - style: TextStyle( - color: primaryColor, - fontSize: 25, - ))), - MultiImageFile( - enabled: true, - controller: multiImgController, - title: "Receipt File", - ), - Center( - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Color(0xff272262), - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5.0)), - minimumSize: Size(300, 45), //////// HERE - ), - onPressed: () {}, - child: - const Text('Save', style: TextStyle(fontSize: 20)), + body: + Padding(padding:EdgeInsets.only(left: 12.0, right: 12), + child: ListView( + children: [ + Center( + child: Text("${_box?.cartonNumber}", + style: TextStyle( + color: primaryColor, + fontSize: 25, + ))), + + MultiImageFile( + enabled: true, + controller: multiImgController, + title: "Receipt File", ), - ), - ], - ))); + Center( + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xff272262), + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5.0)), + minimumSize: Size(300, 45), //////// HERE + ), + onPressed: () {}, + child: + const Text('Save', style: TextStyle(fontSize: 20)), + ), + ), + ], + ), + ))); } } diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 8cb50ca..c87eb82 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -34,14 +34,14 @@ class _CartonInfoState extends State { final DateFormat dateFormat = DateFormat("d MMM yyyy"); final NumberFormat numberFormatter = NumberFormat("#,###"); MultiImgController multiImgController = MultiImgController(); - bool _isLoading = false; late Carton _carton; - List _cargoTypes = []; List _surchareItems = []; List _mixCartons = []; List _packages = []; + double totalWeight=0.0; + double totalSurchargeCount=0.0; @override void initState() { @@ -52,6 +52,7 @@ class _CartonInfoState extends State { _init() async { _carton.billTo = billToSender; + _carton.cartonSizeType=standardCarton; _carton.cartonType = carton_from_packages; multiImgController.setImageUrls = _carton.photos; _cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList(); @@ -71,14 +72,16 @@ class _CartonInfoState extends State { if (mounted) { setState(() {}); } + _carton.cartonType="Carton for packages"; + totalWeight = + _carton.cargoTypes.fold(0, (sum, value) => sum + value.weight); + totalSurchargeCount = + _surchareItems.fold(0, (sum, value) => sum + value.qty); } @override Widget build(BuildContext context) { - double totalWeight = - _carton.cargoTypes.fold(0, (sum, value) => sum + value.weight); - double totalSurchargeCount = - _surchareItems.fold(0, (sum, value) => sum + value.qty); + final cartonTypeBox = DisplayText( text: _carton.cartonNumber, @@ -86,6 +89,11 @@ class _CartonInfoState extends State { ); final cartonQrBox = DisplayText(iconData: AntDesign.qrcode); + final cartonSubTypeBox = DisplayText( + text: _carton.cartonType==carton_from_packages ? "Carton for packages":"Mix carton", + subText:Text( "${_carton.cartonStandardSize}"), + labelTextKey: "box.carton.type", + ); final shipmentBox = DisplayText( text: _carton.fcsShipmentNumber, @@ -93,19 +101,19 @@ class _CartonInfoState extends State { ); final deliveryBox = DisplayText( - text: "Delivery Carton", + text: _carton.deliveryCarton, labelTextKey: "box.delivery_type", ); final senderBox = DisplayText( - text: _carton.userName == null ? "" : _carton.userName, - subText: Text(_carton.fcsID ?? "", style: textStyle), + text: _carton.senderName== null ? "" : _carton.senderName, + subText: Text(_carton.senderFCSID?? "", style: textStyle), labelTextKey: "box.name", ); final consigneeNameBox = DisplayText( - text: _carton.senderName != null ? _carton.senderName : "", - subText: Text(_carton.senderFCSID ?? "", style: textStyle), + text: _carton.userName != null ? _carton.userName : "", + subText: Text(_carton.fcsID?? "", style: textStyle), labelTextKey: "processing.consignee.name", ); @@ -338,14 +346,20 @@ class _CartonInfoState extends State { child: cartonQrBox, ), ]), + Row(children: [Flexible(child: cartonSubTypeBox),],), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible(child: shipmentBox), - Flexible(child: deliveryBox), + _mixCartons.isEmpty + ? + Flexible(child: deliveryBox):const SizedBox(), ], ), - userRowBox, + _mixCartons.isEmpty + ? + userRowBox: + const SizedBox(), _packages.isEmpty ? const SizedBox() : Padding( From a246097d05acb0d7e146bc0d46a8d5ab19494260 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 17:10:19 +0630 Subject: [PATCH 07/10] add carton editor to update --- assets/local/localization_en.json | 3 +- assets/local/localization_mu.json | 2 + lib/pages/carton/carton_package_editor.dart | 39 +++++++++++----- lib/pages/carton/carton_size_widget.dart | 44 +++++++++++-------- lib/pages/carton/carton_submit.dart | 7 ++- .../carton/mix_carton/mix_carton_editor.dart | 26 +++++++++-- .../carton/mix_carton/mix_carton_submit.dart | 7 ++- lib/pages/carton/mix_carton/type_widget.dart | 17 ++++--- .../model/fcs_shipment_model.dart | 3 +- 9 files changed, 103 insertions(+), 45 deletions(-) diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index af74e52..08838f9 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -345,7 +345,8 @@ "box.delvery_carton":"Delivery carton", "box.pick_up_carton":"Pick-up carton", "box.delete.btn":"Delete carton", - + "box.update_title":"Edit carton", + "box.update.btn":"Update carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index d5cb055..9feba78 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -344,6 +344,8 @@ "box.delvery_carton":"Delivery carton", "box.pick_up_carton":"Pick-up carton", "box.delete.btn":"Delete carton", + "box.update_title":"Edit carton", + "box.update.btn":"Update carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/pages/carton/carton_package_editor.dart b/lib/pages/carton/carton_package_editor.dart index e0bf4e3..a13be1a 100644 --- a/lib/pages/carton/carton_package_editor.dart +++ b/lib/pages/carton/carton_package_editor.dart @@ -14,6 +14,7 @@ import '../../domain/entities/cargo_type.dart'; import '../../domain/entities/carton.dart'; import '../../domain/entities/package.dart'; import '../../domain/entities/user.dart'; +import '../fcs_shipment/model/fcs_shipment_model.dart'; import '../main/util.dart'; import '../widgets/local_text.dart'; import '../widgets/progress.dart'; @@ -64,20 +65,37 @@ class _CartonPackageEditorState extends State { @override void initState() { + _init(); + super.initState(); + } + + _init() async { _sender = User( - name: "ptd-phyo44 kaelone", - fcsID: "FCS-8X6V", - phoneNumber: "+959444444444", - id: "48u_4s-HiQeW-HwSqeRd9TSMWh3mLZfSk5rpaUEh_zw"); + name: widget.carton.senderName, + fcsID: widget.carton.senderFCSID, + id: widget.carton.senderID); _consignee = User( - id: "HsIwG88K-0_HSazgEy5QR27kcjkOvfv7_Sr1JP18Q1A", - name: "One One", - phoneNumber: "+959111111111", - fcsID: "FCS-EFRF"); + id: widget.carton.userID, + name: widget.carton.userName, + fcsID: widget.carton.fcsID); + + _billToValue = widget.carton.billTo ?? billToSender; + _selectedDeliveryType = delivery_caton; + _cartonSizeType = customCarton; + _length = widget.carton.length; + _width = widget.carton.width; + _height = widget.carton.height; + + var s = await context + .read() + .getFcsShipment(widget.carton.fcsShipmentID ?? ""); + _shipment = s; context.read().clearSelection(); - super.initState(); + if (mounted) { + setState(() {}); + } } @override @@ -116,7 +134,7 @@ class _CartonPackageEditorState extends State { }, ), backgroundColor: Colors.white, - title: LocalText(context, 'boxes.new', + title: LocalText(context, 'box.update_title', color: primaryColor, fontSize: 20), ), body: Column( @@ -220,6 +238,7 @@ class _CartonPackageEditorState extends State { } else { return Expanded( child: CartonSubmit( + isNew: false, sender: _sender!, consingee: _consignee!, billToValue: _billToValue, diff --git a/lib/pages/carton/carton_size_widget.dart b/lib/pages/carton/carton_size_widget.dart index 8aa89ef..54982f1 100644 --- a/lib/pages/carton/carton_size_widget.dart +++ b/lib/pages/carton/carton_size_widget.dart @@ -63,7 +63,7 @@ class _CartonSizeWidgetState extends State { List _deliveryTypes = [delivery_caton, pickup_carton]; FcsShipment? _shipment; - String _cartionSizeType = standardCarton; + String _cartonSizeType = standardCarton; List _shipments = []; CartonSize? _selectStandardSize; @@ -83,34 +83,40 @@ class _CartonSizeWidgetState extends State { _init() async { _selectedDeliveryType = widget.deliveryType; _billToValue = widget.billType; - _shipment = widget.shipment; - _cartionSizeType = widget.cartonSizeType; + _cartonSizeType = widget.cartonSizeType; List cartonSizes = context.read().cartonSizes; _selectStandardSize = widget.standardSize ?? cartonSizes.first; _lengthController.text = - widget.length == null ? "0" : widget.length.toString(); + widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0); _widthController.text = - widget.width == null ? "0" : widget.width.toString(); + widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0); _heightController.text = - widget.height == null ? "0" : widget.height.toString(); + widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0); var fcsShipments = await context.read().getActiveFcsShipments(); _shipments = fcsShipments; + _shipment = widget.shipment; if (mounted) { setState(() {}); } } + @override + void didUpdateWidget(covariant CartonSizeWidget oldWidget) { + _init(); + super.didUpdateWidget(oldWidget); + } + @override Widget build(BuildContext context) { List cartonSizes = context.watch().cartonSizes; - bool isStandardSize = _cartionSizeType == standardCarton; - bool isCustomSize = _cartionSizeType == customCarton; - bool isNoneDefinedSize = _cartionSizeType == packageCartion; + bool isStandardSize = _cartonSizeType == standardCarton; + bool isCustomSize = _cartonSizeType == customCarton; + bool isNoneDefinedSize = _cartonSizeType == packageCartion; final senderBox = DisplayText( text: widget.sender.name, @@ -242,7 +248,7 @@ class _CartonSizeWidgetState extends State { if (widget.onContinue != null) { widget.onContinue!( - _selectedDeliveryType, _billToValue, _shipment!, _cartionSizeType, + _selectedDeliveryType, _billToValue, _shipment!, _cartonSizeType, standardSize: _selectStandardSize, length: l, width: w, height: h); } }); @@ -321,16 +327,16 @@ class _CartonSizeWidgetState extends State { InkWell( onTap: () { setState(() { - _cartionSizeType = standardCarton; + _cartonSizeType = standardCarton; }); }, child: Row(children: [ LocalRadio( value: standardCarton, - groupValue: _cartionSizeType, + groupValue: _cartonSizeType, onChanged: (p0) { setState(() { - _cartionSizeType = standardCarton; + _cartonSizeType = standardCarton; }); }, ), @@ -350,16 +356,16 @@ class _CartonSizeWidgetState extends State { InkWell( onTap: () { setState(() { - _cartionSizeType = customCarton; + _cartonSizeType = customCarton; }); }, child: Row(children: [ LocalRadio( value: customCarton, - groupValue: _cartionSizeType, + groupValue: _cartonSizeType, onChanged: (p0) { setState(() { - _cartionSizeType = customCarton; + _cartonSizeType = customCarton; }); }, ), @@ -379,16 +385,16 @@ class _CartonSizeWidgetState extends State { InkWell( onTap: () { setState(() { - _cartionSizeType = packageCartion; + _cartonSizeType = packageCartion; }); }, child: Row(children: [ LocalRadio( value: packageCartion, - groupValue: _cartionSizeType, + groupValue: _cartonSizeType, onChanged: (p0) { setState(() { - _cartionSizeType = packageCartion; + _cartonSizeType = packageCartion; }); }, ), diff --git a/lib/pages/carton/carton_submit.dart b/lib/pages/carton/carton_submit.dart index cbad83f..681896d 100644 --- a/lib/pages/carton/carton_submit.dart +++ b/lib/pages/carton/carton_submit.dart @@ -35,6 +35,7 @@ class CartonSubmit extends StatelessWidget { final List surchareItems; final OnCreateCarton? onCreate; final OnPrevious? onPrevious; + final bool isNew; const CartonSubmit( {Key? key, required this.sender, @@ -51,7 +52,8 @@ class CartonSubmit extends StatelessWidget { this.width = 0, this.height = 0, this.cargoTypes = const [], - this.surchareItems = const []}) + this.surchareItems = const [], + this.isNew = true}) : super(key: key); @override @@ -310,7 +312,8 @@ class CartonSubmit extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Flexible( - child: LocalText(context, 'box.crete.carton', + child: LocalText( + context, isNew ? 'box.crete.carton' : "box.update.btn", color: Colors.white, fontSize: 15), ), const SizedBox(width: 5), diff --git a/lib/pages/carton/mix_carton/mix_carton_editor.dart b/lib/pages/carton/mix_carton/mix_carton_editor.dart index ed31519..da251d3 100644 --- a/lib/pages/carton/mix_carton/mix_carton_editor.dart +++ b/lib/pages/carton/mix_carton/mix_carton_editor.dart @@ -1,5 +1,6 @@ // ignore_for_file: deprecated_member_use +import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -50,10 +51,26 @@ class _MixCartonEditorState extends State { @override void initState() { - context.read().clearSelection(); + _init(); super.initState(); } + _init() async { + var s = await context + .read() + .getFcsShipment(widget.carton.fcsShipmentID ?? ""); + _shipment = s; + _cartonSizeType = customCarton; + _length = widget.carton.length; + _width = widget.carton.width; + _height = widget.carton.height; + + context.read().clearSelection(); + if (mounted) { + setState(() {}); + } + } + @override Widget build(BuildContext context) { return WillPopScope( @@ -90,7 +107,7 @@ class _MixCartonEditorState extends State { }, ), backgroundColor: Colors.white, - title: LocalText(context, 'boxes.new', + title: LocalText(context, 'box.update_title', color: primaryColor, fontSize: 20), ), body: Column( @@ -163,6 +180,7 @@ class _MixCartonEditorState extends State { } else { return Expanded( child: MixCartonSubmit( + isNew: false, cartonSizeType: _cartonSizeType, standardSize: _standardSize, length: _length, @@ -171,7 +189,7 @@ class _MixCartonEditorState extends State { shipment: _shipment!, cartons: _cartons, onCreate: () { - _create(); + _update(); }, onPrevious: () { setState(() { @@ -183,7 +201,7 @@ class _MixCartonEditorState extends State { } } - _create() async { + _update() async { setState(() { _isLoading = true; }); diff --git a/lib/pages/carton/mix_carton/mix_carton_submit.dart b/lib/pages/carton/mix_carton/mix_carton_submit.dart index 894471b..456ca16 100644 --- a/lib/pages/carton/mix_carton/mix_carton_submit.dart +++ b/lib/pages/carton/mix_carton/mix_carton_submit.dart @@ -18,6 +18,7 @@ typedef OnCreateMixCarton = Function(); typedef OnPrevious = Function(); class MixCartonSubmit extends StatefulWidget { + final bool isNew; final FcsShipment shipment; final List cartons; final String cartonSizeType; @@ -37,7 +38,8 @@ class MixCartonSubmit extends StatefulWidget { required this.cartonSizeType, this.length = 0, this.width = 0, - this.height = 0}) + this.height = 0, + this.isNew = true}) : super(key: key); @override @@ -253,7 +255,8 @@ class _MixCartonSubmitState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Flexible( - child: LocalText(context, 'box.crete.carton', + child: LocalText(context, + widget.isNew ? 'box.crete.carton' : 'box.update.btn', color: Colors.white, fontSize: 15), ), const SizedBox(width: 5), diff --git a/lib/pages/carton/mix_carton/type_widget.dart b/lib/pages/carton/mix_carton/type_widget.dart index ccc2c32..3eccba4 100644 --- a/lib/pages/carton/mix_carton/type_widget.dart +++ b/lib/pages/carton/mix_carton/type_widget.dart @@ -65,28 +65,33 @@ class _TypeWidgetState extends State { } _init() async { - _shipment = widget.shipment; - _cartionSizeType = widget.cartonSizeType; - List cartonSizes = context.read().cartonSizes; _selectStandardSize = widget.standardSize ?? cartonSizes.first; + _cartionSizeType = widget.cartonSizeType; _lengthController.text = - widget.length == null ? "0" : widget.length.toString(); + widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0); _widthController.text = - widget.width == null ? "0" : widget.width.toString(); + widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0); _heightController.text = - widget.height == null ? "0" : widget.height.toString(); + widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0); var fcsShipments = await context.read().getActiveFcsShipments(); _shipments = fcsShipments; + _shipment = widget.shipment; if (mounted) { setState(() {}); } } + @override + void didUpdateWidget(covariant TypeWidget oldWidget) { + _init(); + super.didUpdateWidget(oldWidget); + } + @override Widget build(BuildContext context) { List cartonSizes = context.watch().cartonSizes; diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index 5c5f764..c921bd3 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -83,7 +83,7 @@ class FcsShipmentModel extends BaseModel { try { var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") - .where("status", isEqualTo: fcs_shipment_confirmed_status) + // .where("status", isEqualTo: fcs_shipment_confirmed_status) .get(const GetOptions(source: Source.server)); fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = @@ -97,6 +97,7 @@ class FcsShipmentModel extends BaseModel { } Future getFcsShipment(String id) async { + if (id == "") return null; try { var snap = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") From 95b07c22bb3233d623f48ff1b134fcd0dce09ad8 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 17:40:51 +0630 Subject: [PATCH 08/10] update cartion editor --- lib/domain/entities/carton.dart | 15 +++--- lib/pages/carton/carton_info.dart | 53 +++++++++++-------- lib/pages/carton/carton_package_editor.dart | 13 +++-- .../carton/model/carton_selection_model.dart | 1 + .../carton/model/package_selection_model.dart | 4 ++ .../carton/package_selection_widget.dart | 2 + 6 files changed, 55 insertions(+), 33 deletions(-) diff --git a/lib/domain/entities/carton.dart b/lib/domain/entities/carton.dart index c6fded6..803be65 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -36,10 +36,11 @@ class Carton { String? mixCartonNumber; String? cartonSizeID; String? cartonSizeName; + String? deliveryType; String? cartonSizeType; - String? cartonStandardSize; + double cartonWeight; - String? billTo; + String? billTo; bool isSelected; int rate; @@ -51,7 +52,6 @@ class Carton { String? remark; DateTime? arrivedDate; String? cartonNumber; - String? deliveryCarton; List packageIDs; List packages; @@ -163,12 +163,11 @@ class Carton { this.cartonSizeID, this.cartonSizeName, this.cartonSizeType, - this.cartonStandardSize, - this.deliveryCarton, + this.deliveryType, this.mixBoxType, this.mixCartons = const [], this.mixCartonIDs = const [], - this.cartonWeight =0, + this.cartonWeight = 0, this.photoUrls = const [], this.isSelected = false}); @@ -209,7 +208,7 @@ class Carton { List>.from(map['mix_cartons'] ?? []); var _mixCartons = mixCartonsMaps.map((e) => Carton.fromMap(e, e["id"])).toList(); - List _photoUrls = + List _photoUrls = map['photo_urls'] == null ? [] : List.from(map['photo_urls']); return Carton( @@ -243,7 +242,7 @@ class Carton { senderName: map['sender_name'], mixCartonIDs: List.from(map['mix_carton_ids'] ?? []), cartonWeight: (map['carton_weight'] ?? 0).toDouble(), - photoUrls: _photoUrls, + photoUrls: _photoUrls, ); } diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index c87eb82..3eb6393 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -17,6 +17,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; +import '../../domain/entities/carton_size.dart'; import '../widgets/local_button.dart'; import 'carton_package_editor.dart'; import 'mix_carton/mix_carton_editor.dart'; @@ -40,8 +41,9 @@ class _CartonInfoState extends State { List _surchareItems = []; List _mixCartons = []; List _packages = []; - double totalWeight=0.0; - double totalSurchargeCount=0.0; + double totalWeight = 0.0; + double totalSurchargeCount = 0.0; + CartonSize? standardSize; @override void initState() { @@ -51,13 +53,14 @@ class _CartonInfoState extends State { } _init() async { - _carton.billTo = billToSender; - _carton.cartonSizeType=standardCarton; + _carton.billTo = billToConsignee; + _carton.cartonSizeType = customCarton; _carton.cartonType = carton_from_packages; multiImgController.setImageUrls = _carton.photos; _cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList(); _surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList(); if (_carton.cartonType == carton_from_packages) { + _carton.deliveryType = delivery_caton; _packages = await context .read() .getPackagesByIds(_carton.packageIDs); @@ -72,16 +75,20 @@ class _CartonInfoState extends State { if (mounted) { setState(() {}); } - _carton.cartonType="Carton for packages"; - totalWeight = + _carton.cartonType = "Carton for packages"; + totalWeight = _carton.cargoTypes.fold(0, (sum, value) => sum + value.weight); - totalSurchargeCount = + totalSurchargeCount = _surchareItems.fold(0, (sum, value) => sum + value.qty); } @override Widget build(BuildContext context) { - + String? boxDimension = _carton.cartonSizeType == standardCarton + ? "${standardSize?.name} - ${standardSize?.length.toInt()}”x${standardSize?.width.toInt()}”x${standardSize?.height.toInt()}”" + : _carton.cartonSizeType == customCarton + ? "${_carton.length.toInt()}”x${_carton.width.toInt()}”x${_carton.height.toInt()}”" + : null; final cartonTypeBox = DisplayText( text: _carton.cartonNumber, @@ -90,8 +97,10 @@ class _CartonInfoState extends State { final cartonQrBox = DisplayText(iconData: AntDesign.qrcode); final cartonSubTypeBox = DisplayText( - text: _carton.cartonType==carton_from_packages ? "Carton for packages":"Mix carton", - subText:Text( "${_carton.cartonStandardSize}"), + text: _carton.cartonType == carton_from_packages + ? "Carton for packages" + : "Mix carton", + subText: boxDimension == null ? null : Text("$boxDimension"), labelTextKey: "box.carton.type", ); @@ -101,19 +110,19 @@ class _CartonInfoState extends State { ); final deliveryBox = DisplayText( - text: _carton.deliveryCarton, + text: _carton.deliveryType, labelTextKey: "box.delivery_type", ); final senderBox = DisplayText( - text: _carton.senderName== null ? "" : _carton.senderName, - subText: Text(_carton.senderFCSID?? "", style: textStyle), + text: _carton.senderName == null ? "" : _carton.senderName, + subText: Text(_carton.senderFCSID ?? "", style: textStyle), labelTextKey: "box.name", ); final consigneeNameBox = DisplayText( text: _carton.userName != null ? _carton.userName : "", - subText: Text(_carton.fcsID?? "", style: textStyle), + subText: Text(_carton.fcsID ?? "", style: textStyle), labelTextKey: "processing.consignee.name", ); @@ -183,7 +192,6 @@ class _CartonInfoState extends State { style: TextStyle(color: Colors.black54, fontSize: 15))) ], ), - //), Container( child: Padding( padding: const EdgeInsets.only(right: 100), @@ -346,20 +354,21 @@ class _CartonInfoState extends State { child: cartonQrBox, ), ]), - Row(children: [Flexible(child: cartonSubTypeBox),],), + Row( + children: [ + Flexible(child: cartonSubTypeBox), + ], + ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible(child: shipmentBox), _mixCartons.isEmpty - ? - Flexible(child: deliveryBox):const SizedBox(), + ? Flexible(child: deliveryBox) + : const SizedBox(), ], ), - _mixCartons.isEmpty - ? - userRowBox: - const SizedBox(), + _mixCartons.isEmpty ? userRowBox : const SizedBox(), _packages.isEmpty ? const SizedBox() : Padding( diff --git a/lib/pages/carton/carton_package_editor.dart b/lib/pages/carton/carton_package_editor.dart index a13be1a..595d07a 100644 --- a/lib/pages/carton/carton_package_editor.dart +++ b/lib/pages/carton/carton_package_editor.dart @@ -16,6 +16,7 @@ import '../../domain/entities/package.dart'; import '../../domain/entities/user.dart'; import '../fcs_shipment/model/fcs_shipment_model.dart'; import '../main/util.dart'; +import '../package/model/package_model.dart'; import '../widgets/local_text.dart'; import '../widgets/progress.dart'; import '../widgets/step_widget.dart'; @@ -70,6 +71,7 @@ class _CartonPackageEditorState extends State { } _init() async { + context.read().clearSelection(); _sender = User( name: widget.carton.senderName, fcsID: widget.carton.senderFCSID, @@ -81,18 +83,23 @@ class _CartonPackageEditorState extends State { fcsID: widget.carton.fcsID); _billToValue = widget.carton.billTo ?? billToSender; - _selectedDeliveryType = delivery_caton; - _cartonSizeType = customCarton; + _selectedDeliveryType = widget.carton.deliveryType ?? delivery_caton; + _cartonSizeType = widget.carton.cartonSizeType ?? customCarton; _length = widget.carton.length; _width = widget.carton.width; _height = widget.carton.height; + _cargoTypes = widget.carton.cargoTypes.where((e) => !e.isCutomDuty).toList(); + _surchareItems = widget.carton.cargoTypes.where((e) => e.isCutomDuty).toList(); var s = await context .read() .getFcsShipment(widget.carton.fcsShipmentID ?? ""); _shipment = s; - context.read().clearSelection(); + _packages = await context + .read() + .getPackagesByIds(widget.carton.packageIDs); + if (mounted) { setState(() {}); } diff --git a/lib/pages/carton/model/carton_selection_model.dart b/lib/pages/carton/model/carton_selection_model.dart index 84e84be..b4b47f3 100644 --- a/lib/pages/carton/model/carton_selection_model.dart +++ b/lib/pages/carton/model/carton_selection_model.dart @@ -144,4 +144,5 @@ class CartonSelectionModel extends BaseModel { cartons.clear(); query = ""; } + } diff --git a/lib/pages/carton/model/package_selection_model.dart b/lib/pages/carton/model/package_selection_model.dart index 3f7e0d0..c25e9be 100644 --- a/lib/pages/carton/model/package_selection_model.dart +++ b/lib/pages/carton/model/package_selection_model.dart @@ -102,6 +102,10 @@ class PackageSelectionModel extends BaseModel { } } + addSelectedPackage(List list){ + selectedPackageList = list; + } + Future _refresh( {required String shipmentId, required String senderId, diff --git a/lib/pages/carton/package_selection_widget.dart b/lib/pages/carton/package_selection_widget.dart index 9926920..2d46594 100644 --- a/lib/pages/carton/package_selection_widget.dart +++ b/lib/pages/carton/package_selection_widget.dart @@ -60,6 +60,8 @@ class _PackageSelectionWidgetState extends State { consigneeId: widget.consignee.id!, senderId: widget.sender.id!); + searchModel.addSelectedPackage(widget.packages); + _controller.text = searchModel.query; _query = searchModel.query; if (mounted) { From ba792e87ad2a39a06205f51b2f41a256b52da66f Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 17:44:13 +0630 Subject: [PATCH 09/10] update upload image form --- .../carton/carton_image_upload_editor.dart | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/lib/pages/carton/carton_image_upload_editor.dart b/lib/pages/carton/carton_image_upload_editor.dart index 9e5a645..a7aeaa0 100644 --- a/lib/pages/carton/carton_image_upload_editor.dart +++ b/lib/pages/carton/carton_image_upload_editor.dart @@ -5,6 +5,7 @@ import 'package:fcs/pages/widgets/multi_img_controller.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/material.dart'; +import '../widgets/local_button.dart'; import '../widgets/multi_img_file.dart'; typedef void FindCallBack(); @@ -30,6 +31,14 @@ class _CartonImageUploaState extends State { @override Widget build(BuildContext context) { + final createBtn = Padding( + padding: const EdgeInsets.symmetric(horizontal: 30), + child: LocalButton( + textKey: "btn.save", + callBack: () {}, + ), + ); + return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -38,41 +47,25 @@ class _CartonImageUploaState extends State { backgroundColor: Colors.white, labelColor: primaryColor, arrowColor: primaryColor, - actions: [] - - ), - body: - Padding(padding:EdgeInsets.only(left: 12.0, right: 12), - child: ListView( - children: [ - Center( - child: Text("${_box?.cartonNumber}", - style: TextStyle( - color: primaryColor, - fontSize: 25, - ))), - - MultiImageFile( - enabled: true, - controller: multiImgController, - title: "Receipt File", - ), - Center( - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Color(0xff272262), - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5.0)), - minimumSize: Size(300, 45), //////// HERE - ), - onPressed: () {}, - child: - const Text('Save', style: TextStyle(fontSize: 20)), - ), - ), - ], + actions: []), + body: Padding( + padding: EdgeInsets.only(left: 12.0, right: 12), + child: ListView( + children: [ + Center( + child: Text("${_box?.cartonNumber}", + style: TextStyle( + color: primaryColor, + fontSize: 25, + ))), + MultiImageFile( + enabled: true, + controller: multiImgController, + title: "Receipt File", ), - ))); + createBtn, + ], + ), + ))); } } From 02cf4b7dffdddd8a6907d3e7678c9bda30af6f20 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 17:47:35 +0630 Subject: [PATCH 10/10] update upload image form --- lib/pages/carton/carton_image_upload_editor.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pages/carton/carton_image_upload_editor.dart b/lib/pages/carton/carton_image_upload_editor.dart index a7aeaa0..1abef1f 100644 --- a/lib/pages/carton/carton_image_upload_editor.dart +++ b/lib/pages/carton/carton_image_upload_editor.dart @@ -31,7 +31,7 @@ class _CartonImageUploaState extends State { @override Widget build(BuildContext context) { - final createBtn = Padding( + final saveBtn = Padding( padding: const EdgeInsets.symmetric(horizontal: 30), child: LocalButton( textKey: "btn.save", @@ -63,7 +63,7 @@ class _CartonImageUploaState extends State { controller: multiImgController, title: "Receipt File", ), - createBtn, + saveBtn, ], ), )));