From e485e5792e91e1572b6d3e90600eba8783a6c86d Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 9 Feb 2024 13:35:32 +0630 Subject: [PATCH] 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; + } }