diff --git a/lib/data/provider/rate_data_provider.dart b/lib/data/provider/rate_data_provider.dart index c01e863..c8c416e 100644 --- a/lib/data/provider/rate_data_provider.dart +++ b/lib/data/provider/rate_data_provider.dart @@ -36,6 +36,7 @@ class RateDataProvider { .collection(config_collection) .document(rate_doc_id) .collection(cargo_types_collection) + .where("custom_duty", isEqualTo: false) .snapshots(); await for (var snaps in snapshots) { @@ -48,18 +49,19 @@ class RateDataProvider { } } - Stream> _customDutiesStream() async* { - List customDuries = []; + Stream> _customDutiesStream() async* { + List customDuries = []; Stream snapshots = Firestore.instance .collection(config_collection) .document(rate_doc_id) - .collection(custom_duties_collection) + .collection(cargo_types_collection) + .where("custom_duty", isEqualTo: true) .snapshots(); await for (var snaps in snapshots) { customDuries = []; customDuries = snaps.documents.map((snap) { - return CustomDuty.fromMap(snap.data, snap.documentID); + return CargoType.fromMap(snap.data, snap.documentID); }).toList(); yield customDuries; } @@ -84,7 +86,7 @@ class RateDataProvider { StreamSubscription rateListener; StreamSubscription> cargoListener; - StreamSubscription> customListener; + StreamSubscription> customListener; StreamSubscription> discountListener; Stream rate() { Future _start() async { diff --git a/lib/domain/entities/cargo_type.dart b/lib/domain/entities/cargo_type.dart index 76ccfe2..68ec494 100644 --- a/lib/domain/entities/cargo_type.dart +++ b/lib/domain/entities/cargo_type.dart @@ -5,23 +5,13 @@ class CargoType { double weight; bool isChecked; int qty; - bool isCutomDuty = false; + bool isCutomDuty; + double customDutyFee; double get calAmount => (calRate ?? 0) * (calWeight ?? 0); double calRate; double calWeight; - - factory CargoType.fromMap(Map map, String id) { - return CargoType( - id: id, - name: map['name'], - rate: map['rate']?.toDouble() ?? 0, - weight: map['weight']?.toDouble() ?? 0, - calWeight: map['cal_weight']?.toDouble() ?? 0, - calRate: map['cal_rate']?.toDouble() ?? 0, - ); - } CargoType( {this.id, this.name, @@ -31,7 +21,21 @@ class CargoType { this.calRate, this.isChecked = false, this.qty = 0, - this.isCutomDuty = false}); + this.isCutomDuty, + this.customDutyFee}); + + factory CargoType.fromMap(Map map, String id) { + return CargoType( + id: id, + name: map['name'], + rate: map['rate']?.toDouble() ?? 0, + weight: map['weight']?.toDouble() ?? 0, + calWeight: map['cal_weight']?.toDouble() ?? 0, + calRate: map['cal_rate']?.toDouble() ?? 0, + isCutomDuty: map['custom_duty'] ?? false, + customDutyFee: (map['custom_duty_fee'] ?? 0).toDouble(), + qty: (map['qty'] ?? 0).toInt()); + } Map toMap() { return { @@ -41,6 +45,9 @@ class CargoType { 'weight': weight, 'cal_weight': calWeight, 'cal_rate': calRate, + 'custom_duty': isCutomDuty, + 'custom_duty_fee': customDutyFee, + 'qty': qty }; } @@ -62,4 +69,10 @@ class CargoType { bool isChangedForEdit(CargoType cargoType) { return cargoType.name != this.name || cargoType.rate != this.rate; } + + bool isChangedForEditCustomDuty(CargoType cargoType) { + return cargoType.name != this.name || + cargoType.customDutyFee != this.customDutyFee || + cargoType.rate != this.rate; + } } diff --git a/lib/domain/entities/carton_size.dart b/lib/domain/entities/carton_size.dart index 2587bdf..7d9f494 100644 --- a/lib/domain/entities/carton_size.dart +++ b/lib/domain/entities/carton_size.dart @@ -26,6 +26,21 @@ class CartonSize { ); } + @override + bool operator ==(other) { + if (identical(this, other)) { + return true; + } + return other.id == this.id; + } + + @override + int get hashCode { + int result = 17; + result = 37 * result + id.hashCode; + return result; + } + bool isChangedForEdit(CartonSize cartonSize) { return cartonSize.name != this.name || cartonSize.length != this.length || diff --git a/lib/domain/entities/rate.dart b/lib/domain/entities/rate.dart index 3dadb79..f5682e1 100644 --- a/lib/domain/entities/rate.dart +++ b/lib/domain/entities/rate.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/custom_duty.dart'; + import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'cargo_type.dart'; @@ -12,7 +12,7 @@ class Rate { double diffWeightRate; List cargoTypes; - List customDuties; + List customDuties; List discountByWeights; DiscountByWeight getDiscountByWeight(double weight) { diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart index 043c922..1c1e5a4 100644 --- a/lib/pages/carton/cargo_type_addtion.dart +++ b/lib/pages/carton/cargo_type_addtion.dart @@ -123,7 +123,7 @@ class _CargoTypeAdditionState extends State { color: primaryColor, ), onPressed: () async { - CustomDuty customDuty = await Navigator.of(context).push( + CargoType customDuty = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => CustomList(selected: true))); @@ -143,14 +143,20 @@ class _CargoTypeAdditionState extends State { ); } - _addCustom(CustomDuty customDuty) { + _addCustom(CargoType customDuty) { if (customDuty == null) return; - if (cargos.any((c) => c.name == customDuty.productType)) return; + if (cargos.any((c) => c.name == customDuty.name)) return; + + // setState(() { + // cargos.add(CargoType( + // name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0)); + // }); setState(() { - cargos.add(CargoType( - name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0)); + customDuty.qty = 1; + customDuty.isChecked = false; + cargos.add(customDuty); }); } } diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart index ef0f495..e21adad 100644 --- a/lib/pages/carton/carton_cargo_table.dart +++ b/lib/pages/carton/carton_cargo_table.dart @@ -105,7 +105,9 @@ class _CargoTableState extends State { String _t = await showDialog( context: context, builder: (_) => DialogInput( - label: "cargo.qty", value: c.qty.toString())); + label: "cargo.qty", + value: c.qty.toString(), + isQty: true)); if (_t == null) return; setState(() { @@ -238,10 +240,11 @@ class _CargoTableState extends State { child: InkWell( onTap: () async { String _t = await showDialog( - context: context, - builder: (_) => DialogInput( - label: "shipment.cargo.total", - value: totalWeight.toStringAsFixed(2))); + context: context, + builder: (_) => DialogInput( + label: "shipment.cargo.total", + value: totalWeight.toStringAsFixed(2)), + ); if (_t == null) return; setState(() { diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 33e1e40..ceaf9f3 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -54,19 +54,19 @@ class _CartonEditorState extends State { TextEditingController _heightController = new TextEditingController(); TextEditingController _lengthController = new TextEditingController(); List _deliveryAddresses = []; + DeliveryAddress _deliveryAddress = new DeliveryAddress(); + List _cargoTypes = []; Carton _carton; bool _isLoading = false; bool _isNew; - DeliveryAddress _deliveryAddress = new DeliveryAddress(); User _user; String _selectedCartonType; - String _selectedMixType; + String _selectedMixBoxType; double volumetricRatio = 0; double shipmentWeight = 0; FcsShipment _fcsShipment; List _fcsShipments; - Carton _mixCarton; List _cartons = []; List _mixCartons = []; CartonSize selectedCatonSize; @@ -90,11 +90,12 @@ class _CartonEditorState extends State { _heightController.text = _carton.height.toString(); _lengthController.text = _carton.length.toString(); _selectedCartonType = _carton.cartonType; + _cargoTypes = List.from(_carton.cargoTypes); _isNew = false; _user = User(fcsID: _carton.fcsID, name: _carton.userName); _loadPackages(); _getDeliverAddresses(); - getCartonSize(); + _getCartonSize(); } else { _carton = Carton( cargoTypes: [], @@ -105,9 +106,8 @@ class _CartonEditorState extends State { _heightController.text = "0"; _isNew = true; _selectedCartonType = carton_from_packages; - _selectedMixType = mix_delivery; + _selectedMixBoxType = mix_delivery; _loadFcsShipments(); - // _cartons = [Carton(cartonNumber: "A100B-1#3", userName: "Seven 7")]; // _mixCartons = [ // Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"), @@ -192,21 +192,18 @@ class _CartonEditorState extends State { await addressModel.getDeliveryAddresses(_carton.userID); } - 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) { - print(c.name); - // setState(() { - // // selectedCatonSize = CartonSize( - // // id: c.id, - // // name: c.name, - // // length: c.length, - // // width: c.width, - // // height: c.height); - // }); + selectedCatonSize = CartonSize( + id: c.id, + name: c.name, + length: c.length, + width: c.width, + height: c.height); } }); } @@ -274,7 +271,9 @@ class _CartonEditorState extends State { final createBtn = LocalButton( textKey: "box.complete.packaging", - callBack: _save, + callBack: () { + Navigator.pop(context); + }, ); final saveBtn = LocalButton( @@ -300,62 +299,7 @@ class _CartonEditorState extends State { Icons.add_circle, color: primaryColor, ), - onPressed: () async { - bool isFromPackages = _selectedCartonType == carton_from_packages; - if (_user == null && isFromPackages) { - showMsgDialog(context, "Error", "Please select FCS ID"); - return; - } - if (_fcsShipment == null && _isNew) { - showMsgDialog(context, "Error", "Please select FCS shipment"); - return; - } - - double l = double.parse(_lengthController.text, (s) => 0); - double w = double.parse(_widthController.text, (s) => 0); - double h = double.parse(_heightController.text, (s) => 0); - - Carton carton = Carton(); - carton.id = _carton.id; - carton.cartonType = _selectedCartonType; - carton.fcsShipmentID = - _isNew ? _fcsShipment.id : _carton.fcsShipmentID; - carton.userID = _user?.id; - carton.fcsID = _user?.fcsID; - carton.userName = _user?.name; - carton.packages = - _carton.packages.where((e) => e.isChecked).toList(); - - carton.cargoTypes = _carton.cargoTypes; - carton.length = l; - carton.width = w; - carton.height = h; - - carton.deliveryAddress = _carton.deliveryAddress; - setState(() { - _isLoading = true; - }); - try { - Carton _c = await Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => - PackageCartonEditor(carton: carton, isNew: _isNew)), - ); - if (_c == null) return; - var cartonModel = - Provider.of(context, listen: false); - Carton _carton = await cartonModel.getCarton(_c.id); - _cartons.add(_carton); - setState(() {}); - } catch (e) { - showMsgDialog(context, "Error", e.toString()); - } finally { - setState(() { - _isLoading = false; - }); - } - }), + onPressed: _addCarton), ), ); @@ -374,16 +318,16 @@ class _CartonEditorState extends State { fontWeight: FontWeight.bold, )), Row( - children: boxModel.mixTypes.map((e) { + children: boxModel.mixBoxTypes.map((e) { return Row( children: [ Radio( value: e, - groupValue: _selectedMixType, + groupValue: _selectedMixBoxType, activeColor: primaryColor, onChanged: (v) { setState(() { - _selectedMixType = v; + _selectedMixBoxType = v; }); }, ), @@ -404,12 +348,7 @@ class _CartonEditorState extends State { Icons.add_circle, color: primaryColor, ), - onPressed: () { - Navigator.push( - context, - CupertinoPageRoute(builder: (context) => MixCartonEditor()), - ); - }, + onPressed: _addMixCarton, ), ), ); @@ -426,15 +365,15 @@ class _CartonEditorState extends State { CupertinoPageRoute(builder: (context) => CargoTypeAddition())); if (cargos == null) return; setState(() { - _carton.cargoTypes.clear(); - _carton.cargoTypes.addAll(cargos); + _cargoTypes.clear(); + _cargoTypes.addAll(cargos); }); }), ); final cargoTableBox = CargoTable( isNew: _isNew, - cargoTypes: _carton.cargoTypes, + cargoTypes: _cargoTypes, onAdd: (c) => _addCargo(c), onRemove: (c) => _removeCargo(c), ); @@ -487,7 +426,7 @@ class _CartonEditorState extends State { backgroundColor: Colors.white, title: LocalText( context, - "box.info.title", + _isNew ? "box.info.title" : "box.edit.title", fontSize: 20, color: primaryColor, ), @@ -509,10 +448,7 @@ class _CartonEditorState extends State { ? [ mixcartonTitleBox, Column( - children: _getMixCartons( - context, - this._mixCartons, - )), + children: _getMixCartons(context, this._mixCartons)), ] : [ fcsIDBox, @@ -585,19 +521,26 @@ class _CartonEditorState extends State { ); } - _addCarton(Carton carton) { - if (carton == null) return; - this._cartons.add(carton); - setState(() {}); - } - List _getCartons(BuildContext context, List cartons) { - return cartons.map((c) { + return cartons.asMap().entries.map((c) { return InkWell( - onTap: () {}, + onTap: () async { + _loadPackages(); + c.value.packages = _carton.packages; + Carton _c = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + PackageCartonEditor(carton: c.value, isNew: false)), + ); + if (_c == null) return; + cartons.removeWhere((item) => item.id == _c.id); + cartons.insert(c.key, _c); + setState(() {}); + }, child: CartonRow( - key: ValueKey(c.id), - box: c, + key: ValueKey(c.value.id), + box: c.value, ), ); }).toList(); @@ -696,81 +639,126 @@ class _CartonEditorState extends State { _addCargo(CargoType cargo) { if (cargo == null) return; setState(() { - _carton.cargoTypes.remove(cargo); - _carton.cargoTypes.add(cargo); + _cargoTypes.remove(cargo); + _cargoTypes.add(cargo); }); } _removeCargo(CargoType cargo) { setState(() { - _carton.cargoTypes.remove(cargo); + _cargoTypes.remove(cargo); }); } - _save() async { - // bool isFromShipment = _selectedCartonType == carton_from_shipments; - // bool isSmallBag = _selectedCartonType == carton_small_bag; - // if (_user == null && (isFromShipment || isSmallBag)) { - // showMsgDialog(context, "Error", "Please select customer"); - // return; - // } - // if (_fcsShipment == null && _isNew) { - // showMsgDialog(context, "Error", "Please select FCS shipment"); - // return; - // } - // if ((_carton.cargoTypes?.length ?? 0) == 0 && - // (isFromShipment || isSmallBag)) { - // showMsgDialog(context, "Error", "Expect at least one cargo type"); - // return; - // } - // double l = double.parse(_lengthController.text, (s) => 0); - // double w = double.parse(_widthController.text, (s) => 0); - // double h = double.parse(_heightController.text, (s) => 0); - // if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) { - // showMsgDialog(context, "Error", "Invalid dimension"); - // return; - // } - // if (_deliveryAddress == null && (isFromShipment || isSmallBag)) { - // showMsgDialog(context, "Error", "Invalid delivery address"); - // return; - // } - // if (isSmallBag && _mixCarton == null && _isNew) { - // showMsgDialog(context, "Error", "Invalid mix carton"); - // return; - // } + _addCarton() async { + bool isFromPackages = _selectedCartonType == carton_from_packages; + if (_user == null && isFromPackages) { + showMsgDialog(context, "Error", "Please select FCS ID"); + return; + } + if (_fcsShipment == null && _isNew) { + showMsgDialog(context, "Error", "Please select FCS shipment"); + return; + } - // Carton carton = Carton(); - // carton.id = _carton.id; - // carton.cartonType = _selectedCartonType; - // carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; - // carton.userID = _user?.id; - // carton.cargoTypes = _carton.cargoTypes; - // carton.packages = _carton.packages.where((e) => e.isChecked).toList(); - // carton.mixCartonID = _mixCarton?.id; - // carton.length = l; - // carton.width = w; - // carton.height = h; - // carton.deliveryAddress = _deliveryAddress; - // setState(() { - // _isLoading = true; - // }); - // try { - // CartonModel cartonModel = - // Provider.of(context, listen: false); - // if (_isNew) { - // await cartonModel.createCarton(carton); - // } else { - // await cartonModel.updateCarton(carton); - // } - // Navigator.pop(context, true); - // } catch (e) { - // showMsgDialog(context, "Error", e.toString()); - // } finally { - // setState(() { - // _isLoading = false; - // }); - // } - Navigator.pop(context, true); + double l = double.parse(_lengthController.text, (s) => 0); + double w = double.parse(_widthController.text, (s) => 0); + double h = double.parse(_heightController.text, (s) => 0); + + Carton carton = Carton(); + carton.id = _carton.id; + carton.cartonType = _selectedCartonType; + carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; + carton.userID = _user?.id; + carton.fcsID = _user?.fcsID; + carton.userName = _user?.name; + carton.packages = _carton.packages.where((e) => e.isChecked).toList(); + + carton.cargoTypes = _carton.cargoTypes; + carton.length = l; + carton.width = w; + carton.height = h; + + carton.deliveryAddress = _carton.deliveryAddress; + + try { + Carton _c = await Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + PackageCartonEditor(carton: carton, isNew: _isNew)), + ); + if (_c == null) return; + var cartonModel = Provider.of(context, listen: false); + Carton _carton = await cartonModel.getCarton(_c.id); + _cartons.add(_carton); + setState(() {}); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } + } + + _addMixCarton() async { + if (_fcsShipment == null && _isNew) { + showMsgDialog(context, "Error", "Please select FCS shipment"); + return; + } + Carton carton = Carton(); + carton.id = _carton.id; + carton.cartonType = _selectedCartonType; + carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; + carton.mixBoxType = _selectedMixBoxType; + await Navigator.push( + context, + CupertinoPageRoute(builder: (context) => MixCartonEditor(box: carton)), + ); + } + + _save() async { + bool isFromPackages = _selectedCartonType == carton_from_packages; + if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages)) { + showMsgDialog(context, "Error", "Expect at least one cargo type"); + return; + } + double l = double.parse(_lengthController.text, (s) => 0); + double w = double.parse(_widthController.text, (s) => 0); + double h = double.parse(_heightController.text, (s) => 0); + if ((l <= 0 || w <= 0 || h <= 0) && isFromPackages) { + showMsgDialog(context, "Error", "Invalid dimension"); + return; + } + if (_deliveryAddress == null && (isFromPackages)) { + showMsgDialog(context, "Error", "Invalid delivery address"); + return; + } + + Carton carton = Carton(); + carton.id = _carton.id; + carton.cartonType = _selectedCartonType; + carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; + carton.userID = _user?.id; + carton.packages = _carton.packages.where((e) => e.isChecked).toList(); + carton.cargoTypes = _cargoTypes; + carton.length = l; + carton.width = w; + carton.height = h; + carton.deliveryAddress = _deliveryAddress; + + setState(() { + _isLoading = true; + }); + try { + CartonModel cartonModel = + Provider.of(context, listen: false); + await cartonModel.updateCarton(carton); + Navigator.pop(context, true); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } } isDataChanged() { diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index ec8c900..d9b4cb4 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -109,7 +109,6 @@ class _CartonInfoState extends State { if (c.length == _box.length && c.width == _box.width && c.height == _box.height) { - print(c.name); setState(() { _cartonSizeController.text = c.name; }); diff --git a/lib/pages/carton/mix_carton_editor.dart b/lib/pages/carton/mix_carton_editor.dart index 7092d75..f86c530 100644 --- a/lib/pages/carton/mix_carton_editor.dart +++ b/lib/pages/carton/mix_carton_editor.dart @@ -1,12 +1,15 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/carton/model/carton_model.dart'; import 'package:fcs/pages/carton_search/carton_search.dart'; +import 'package:fcs/pages/main/util.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:provider/provider.dart'; import 'carton_row.dart'; class MixCartonEditor extends StatefulWidget { @@ -26,14 +29,7 @@ class _MixCartonEditorState extends State { @override void initState() { super.initState(); - - if (widget.box != null) { - _box = widget.box; - _isNew = false; - } else { - _isNew = true; - _box = Carton(cargoTypes: []); - } + _box = widget.box; } @override @@ -124,5 +120,26 @@ class _MixCartonEditorState extends State { }); } - _creatCarton() {} + _creatCarton() { + if ((this._cartons?.length ?? 0) == 0) { + showMsgDialog(context, "Error", "Expect at least one carton"); + return; + } + Carton carton = Carton(); + carton.id = _box.id; + carton.cartonType = _box.cartonType; + setState(() { + _isLoading = true; + }); + try { + CartonModel cartonModel = + Provider.of(context, listen: false); + } 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 041500d..d0c20e4 100644 --- a/lib/pages/carton/model/carton_model.dart +++ b/lib/pages/carton/model/carton_model.dart @@ -57,7 +57,7 @@ class CartonModel extends BaseModel { } List cartonTypes = [carton_from_packages, carton_mix_box]; - List mixTypes = [mix_delivery, mix_pickup]; + List mixBoxTypes = [mix_delivery, mix_pickup]; List cartonTypesInfo = [ carton_from_packages, carton_mix_box, @@ -212,7 +212,6 @@ class CartonModel extends BaseModel { } Future updateCarton(Carton carton) { - print(carton.id); return Services.instance.cartonService.updateCarton(carton); } diff --git a/lib/pages/carton/package_carton_editor.dart b/lib/pages/carton/package_carton_editor.dart index d7124cb..b563a28 100644 --- a/lib/pages/carton/package_carton_editor.dart +++ b/lib/pages/carton/package_carton_editor.dart @@ -45,6 +45,7 @@ class _PackageCartonEditorState extends State { DeliveryAddress _deliveryAddress = new DeliveryAddress(); List _deliveryAddresses = []; List _cargoTypes = []; + CartonSize selectedCatonSize; @override void initState() { @@ -65,6 +66,7 @@ class _PackageCartonEditorState extends State { _widthCtl.text = _carton.width.toString(); _heightCtl.text = _carton.height.toString(); _deliveryAddress = _carton.deliveryAddress; + _getCartonSize(); } } @@ -75,6 +77,22 @@ class _PackageCartonEditorState extends State { await addressModel.getDeliveryAddresses(_carton.userID); } + _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( @@ -105,7 +123,7 @@ class _PackageCartonEditorState extends State { ], ); final createBtn = LocalButton( - textKey: "box.new_carton_btn", + textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn", callBack: _creatCarton, ); @@ -193,7 +211,6 @@ class _PackageCartonEditorState extends State { ); } - CartonSize selectedCatonSize; Widget cartonSizeDropdown() { List _cartonSizes = Provider.of(context).getCartonSizes; @@ -307,7 +324,6 @@ class _PackageCartonEditorState extends State { carton.userID = _carton.userID; carton.cargoTypes = _cargoTypes; carton.packages = _carton.packages.where((e) => e.isChecked).toList(); - // carton.cartonSizeID = selectedCatonSize?.id; carton.length = l; carton.width = w; carton.height = h; @@ -323,7 +339,8 @@ class _PackageCartonEditorState extends State { Navigator.pop(context, _c); } else { await cartonModel.updateCarton(carton); - Navigator.pop(context, carton); + Carton _c = await cartonModel.getCarton(_carton.id); + Navigator.pop(context, _c); } } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index 9633fb2..018804d 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -1,4 +1,4 @@ -import 'package:fcs/domain/entities/custom_duty.dart'; +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/main/util.dart'; @@ -12,7 +12,7 @@ import 'package:provider/provider.dart'; import 'model/shipment_rate_model.dart'; class CustomEditor extends StatefulWidget { - final CustomDuty custom; + final CargoType custom; CustomEditor({this.custom}); @override @@ -25,7 +25,7 @@ class _CustomEditorState extends State { TextEditingController _shipmentRateController = new TextEditingController(); bool _isLoading = false; - CustomDuty _custom = new CustomDuty(); + CargoType _custom = new CargoType(); bool _isNew = false; @override @@ -33,11 +33,10 @@ class _CustomEditorState extends State { super.initState(); if (widget.custom != null) { _custom = widget.custom; - _productController.text = _custom.productType; - _feeController.text = _custom.fee.toStringAsFixed(2); - _shipmentRateController.text = _custom.shipmentRate == null - ? "" - : _custom.shipmentRate.toStringAsFixed(2); + _productController.text = _custom.name; + _feeController.text = _custom.customDutyFee.toStringAsFixed(2); + _shipmentRateController.text = + _custom.rate == null ? "" : _custom.rate.toStringAsFixed(2); } else { _isNew = true; } @@ -123,11 +122,10 @@ class _CustomEditorState extends State { try { var shipmentRateModel = Provider.of(context, listen: false); - CustomDuty _customduty = CustomDuty( - productType: _productController.text, - fee: double.parse(_feeController.text), - shipmentRate: double.parse(_shipmentRateController.text)); - print('_customduty => $_customduty'); + CargoType _customduty = CargoType( + name: _productController.text, + customDutyFee: double.parse(_feeController.text), + rate: double.parse(_shipmentRateController.text)); if (_isNew) { await shipmentRateModel.addCustomDuty(_customduty); } else { @@ -173,12 +171,11 @@ class _CustomEditorState extends State { _feeController.text != "" || _shipmentRateController.text != ""; } else { - CustomDuty _customduty = CustomDuty( - productType: _productController.text, - fee: double.parse(_feeController.text), - // shipmentRate: double.parse(_shipmentRateController.text) - ); - return widget.custom.isChangedForEdit(_customduty); + CargoType _customduty = CargoType( + name: _productController.text, + customDutyFee: double.parse(_feeController.text), + rate: double.parse(_shipmentRateController.text)); + return widget.custom.isChangedForEditCustomDuty(_customduty); } } } diff --git a/lib/pages/rates/custom_list.dart b/lib/pages/rates/custom_list.dart index dc65fed..bbff27c 100644 --- a/lib/pages/rates/custom_list.dart +++ b/lib/pages/rates/custom_list.dart @@ -1,3 +1,4 @@ +import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; @@ -74,8 +75,7 @@ class _CustomListState extends State { ), itemCount: shipmentRateModel.rate.customDuties.length, itemBuilder: (context, index) { - CustomDuty custom = - shipmentRateModel.rate.customDuties[index]; + CargoType custom = shipmentRateModel.rate.customDuties[index]; return InkWell( onTap: () { _selected @@ -86,11 +86,11 @@ class _CustomListState extends State { }, child: Container( child: _row( - custom.productType, - "\$ " + custom.fee.toStringAsFixed(2), - custom.shipmentRate == null + custom.name, + "Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2), + custom.rate == null ? "" - : "\$ " + custom.shipmentRate.toStringAsFixed(2)), + : "Shipment rate \$ " + custom.rate.toStringAsFixed(2)), ), ); }), @@ -120,7 +120,7 @@ class _CustomListState extends State { : Padding( padding: const EdgeInsets.only(top: 3.0), child: Text( - "\$ " + "$shipmentRate", + "$shipmentRate", style: TextStyle(color: Colors.grey, fontSize: 14), ), ) diff --git a/lib/pages/rates/model/shipment_rate_model.dart b/lib/pages/rates/model/shipment_rate_model.dart index 1bf26d3..4304dc1 100644 --- a/lib/pages/rates/model/shipment_rate_model.dart +++ b/lib/pages/rates/model/shipment_rate_model.dart @@ -50,16 +50,18 @@ class ShipmentRateModel extends BaseModel { //CustomDuty - Future addCustomDuty(CustomDuty customDuty) { - return Services.instance.rateService.createCustomDuty(customDuty); + Future addCustomDuty(CargoType customDuty) { + customDuty.isCutomDuty=true; + return Services.instance.rateService.createCargoType(customDuty); } - Future updateCustomDuty(CustomDuty customDuty) { - return Services.instance.rateService.updateCustomDuty(customDuty); + Future updateCustomDuty(CargoType customDuty) { + customDuty.isCutomDuty=true; + return Services.instance.rateService.updateCargoType(customDuty); } Future deleteCustomDuty(String id) { - return Services.instance.rateService.deleteCustomDuty(id); + return Services.instance.rateService.deleteCargoType(id); } //Discount by weight diff --git a/lib/pages/rates/shipment_rates.dart b/lib/pages/rates/shipment_rates.dart index 0da9be3..ff4d865 100644 --- a/lib/pages/rates/shipment_rates.dart +++ b/lib/pages/rates/shipment_rates.dart @@ -145,14 +145,10 @@ class _ShipmentRatesState extends State { "Volumetric Ratio", "${rate.volumetricRatio.toStringAsFixed(2)}", "in3 per pound"), - _row( - "Weight difference discount", - "${rate.diffDiscountWeight.toStringAsFixed(2)}", - "pounds"), - _row( - "Weight difference rate", - "\$ ${rate.diffWeightRate.toStringAsFixed(2)}", - ""), + _row("Weight difference discount", + "${rate.diffDiscountWeight.toStringAsFixed(2)}", "pounds"), + _row("Weight difference rate", + "\$ ${rate.diffWeightRate.toStringAsFixed(2)}", ""), Divider( color: Colors.grey, ), @@ -195,10 +191,10 @@ class _ShipmentRatesState extends State { }).toList(); } - List getCustonWidget(List customs) { + List getCustonWidget(List customs) { return customs.map((c) { return Container( - child: _row(c.productType, "\$ " + c.fee.toStringAsFixed(2), ''), + child: _row(c.name, "\$ " + c.customDutyFee.toStringAsFixed(2), ''), ); }).toList(); } diff --git a/lib/pages/rates/shipment_rates_edit.dart b/lib/pages/rates/shipment_rates_edit.dart index 7d0cdb0..b85f5aa 100644 --- a/lib/pages/rates/shipment_rates_edit.dart +++ b/lib/pages/rates/shipment_rates_edit.dart @@ -44,7 +44,8 @@ class _ShipmentRatesEditState extends State { _minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? ""; _deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? ""; _volumetricRatio.text = rate.volumetricRatio?.toStringAsFixed(2) ?? ""; - _diffDiscountWeight.text = rate.diffDiscountWeight?.toStringAsFixed(2) ?? ""; + _diffDiscountWeight.text = + rate.diffDiscountWeight?.toStringAsFixed(2) ?? ""; _diffWeightRate.text = rate.diffWeightRate?.toStringAsFixed(2) ?? ""; } @@ -162,120 +163,4 @@ class _ShipmentRatesEditState extends State { ); return rate.isChangedForEdit(_rate); } - - List getCargoRows(List cargos) { - return cargos.map((r) { - return MyDataRow( - onSelectChanged: (selected) { - Navigator.push( - context, - CupertinoPageRoute(builder: (context) => CargoEditor(cargo: r)), - ); - }, - cells: [ - MyDataCell( - new Text( - r.name, - style: textStyle, - ), - ), - MyDataCell( - new Text( - r.rate.toString(), - style: textStyle, - ), - ), - MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)), - ], - ); - }).toList(); - } - - List getCustomsRows(List customs) { - return customs.map((c) { - return MyDataRow( - onSelectChanged: (selected) { - Navigator.push( - context, - CupertinoPageRoute(builder: (context) => CustomEditor(custom: c)), - ); - }, - cells: [ - MyDataCell( - new Text( - c.productType, - style: textStyle, - ), - ), - MyDataCell( - new Text( - c.fee.toString(), - style: textStyle, - ), - ), - MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)), - ], - ); - }).toList(); - } - - List getDiscounts(List discounts) { - return discounts.map((d) { - return MyDataRow( - onSelectChanged: (selected) { - // Navigator.push( - // context, - // CupertinoPageRoute(builder: (context) => CargoEditor(rate: r)), - // ); - }, - cells: [ - MyDataCell( - new Text( - "${d.weight} lb", - style: textStyle, - ), - ), - MyDataCell( - Center( - child: new Text( - d.discount.toString(), - style: textStyle, - ), - ), - ), - MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)), - ], - ); - }).toList(); - } - - _row(String desc, String price, String unit) { - return Container( - padding: EdgeInsets.only(left: 25, top: 5, bottom: 5), - child: Row( - children: [ - Text('$desc ', style: TextStyle(fontSize: 15)), - Spacer(), - Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Padding( - padding: const EdgeInsets.only(bottom: 3.0), - child: Text( - '$price', - style: TextStyle(color: primaryColor, fontSize: 14), - ), - ), - Text( - '$unit', - style: TextStyle(color: Colors.grey, fontSize: 14), - ), - ], - ), - SizedBox( - width: 50, - ), - ], - )); - } } diff --git a/lib/pages/widgets/dialog_input.dart b/lib/pages/widgets/dialog_input.dart index 0edb5b5..3c63f84 100644 --- a/lib/pages/widgets/dialog_input.dart +++ b/lib/pages/widgets/dialog_input.dart @@ -7,7 +7,9 @@ import 'local_text.dart'; class DialogInput extends StatefulWidget { final String value; final String label; - const DialogInput({Key key, this.label, this.value}) : super(key: key); + final bool isQty; + const DialogInput({Key key, this.label, this.value, this.isQty = false}) + : super(key: key); @override _DialogInputState createState() => _DialogInputState(); } @@ -15,6 +17,7 @@ class DialogInput extends StatefulWidget { class _DialogInputState extends State { final _formKey = GlobalKey(); TextEditingController _controller = new TextEditingController(); + final _focusNode = FocusNode(); bool _isLoading = false; @@ -23,6 +26,12 @@ class _DialogInputState extends State { super.initState(); if (widget.value != null) { _controller.text = widget.value; + _focusNode.addListener(() { + if (_focusNode.hasFocus) { + _controller.selection = TextSelection( + baseOffset: 0, extentOffset: _controller.text.length); + } + }); } } @@ -41,6 +50,8 @@ class _DialogInputState extends State { key: _formKey, child: TextField( controller: _controller, + focusNode: widget.isQty ? _focusNode : FocusNode(), + autofocus: true, keyboardType: TextInputType.number, decoration: new InputDecoration( focusedBorder: UnderlineInputBorder(