diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index 08233f3..75ca39d 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -286,14 +286,15 @@ "box.popupmenu.delivered":"Delivered Cartons", "box.cargo.total":"Total Weight", "box.delete.confirm":"Delete carton?", + "box.mix.carton":"Go into mix carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", "delivery.title":"Deliveries", "delivery":"Deliveries", - "delivery.info.title":"Deliverie", - "delivery.popupmenu.active":"Active Cartons", - "delivery.popupmenu.delivered":"Delivered Cartons", + "delivery.info.title":"Delivery", + "delivery.popupmenu.active":"Active cartons", + "delivery.popupmenu.delivered":"Delivered cartons", "Delivery End ================================================================":"", "FCS Shipment Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index 0998b59..24a24c6 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -286,6 +286,7 @@ "box.popupmenu.delivered":"ပို့ပြီးသော သေတ္တာများ", "box.cargo.total":"စုစုပေါင်း အလေးချိန်", "box.delete.confirm":"Delete carton?", + "box.mix.carton":"Go into mix carton", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/domain/constants.dart b/lib/domain/constants.dart index c5ac918..1c084cc 100644 --- a/lib/domain/constants.dart +++ b/lib/domain/constants.dart @@ -74,6 +74,7 @@ const shipment_courier_dropoff = "Courier drop off"; const carton_from_packages = "From packages"; const carton_from_shipments = "From shipments"; const carton_mix_box = "Mix carton"; +const carton_small_bag = "Small bag"; //Carton status const carton_packed_status = "packed"; diff --git a/lib/domain/entities/carton.dart b/lib/domain/entities/carton.dart index 5c68ace..a402a42 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -32,6 +32,8 @@ class Carton { String userID; String fcsShipmentID; String fcsShipmentNumber; + String mixCartonID; + String mixCartonNumber; int rate; int weight; @@ -134,12 +136,15 @@ class Carton { this.fcsShipmentNumber, this.cartons, this.packageIDs, + this.mixCartonID, + this.mixCartonNumber, this.isShipmentCarton = false, this.deliveryAddress}); Map toMap() { List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList(); List _packages = packages?.map((c) => c.toJson())?.toList(); + List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? []; return { "id": id, 'fcs_shipment_id': fcsShipmentID, @@ -151,6 +156,8 @@ class Carton { 'height': height, 'delivery_address': deliveryAddress.toMap(), 'carton_type': cartonType, + 'cartons': _cartons, + 'mix_carton_id': mixCartonID }; } @@ -158,7 +165,8 @@ class Carton { var _arrivedDate = (map['arrived_date'] as Timestamp); var da = map['delivery_address']; var _da = da != null ? DeliveryAddress.fromMap(da, da["id"]) : null; - var cargoTypesMaps = List>.from(map['cargo_types']); + var cargoTypesMaps = + List>.from(map['cargo_types'] ?? []); var cargoTypes = cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList(); return Carton( @@ -178,6 +186,8 @@ class Carton { fcsShipmentID: map['fcs_shipment_id'], fcsShipmentNumber: map['fcs_shipment_number'], isShipmentCarton: map['is_shipment_carton'], + mixCartonID: map['mix_carton_id'], + mixCartonNumber: map['mix_carton_number'], status: map['status'], packageIDs: List.from(map['package_ids'] ?? []), deliveryAddress: _da, diff --git a/lib/domain/entities/package.dart b/lib/domain/entities/package.dart index 90f9a2d..7a606d6 100644 --- a/lib/domain/entities/package.dart +++ b/lib/domain/entities/package.dart @@ -123,6 +123,12 @@ class Package { currentStatusDate: DateTime.parse(json['status_date'])); } + @override + bool operator ==(Object other) => other is Package && other.id == id; + + @override + int get hashCode => id.hashCode; + @override String toString() { return 'Package{id: $id, status: $status, market:$market, trackingID: $trackingID,}'; diff --git a/lib/pages/carton/cargo_type_editor.dart b/lib/pages/carton/cargo_type_editor.dart index 876250b..b73f73b 100644 --- a/lib/pages/carton/cargo_type_editor.dart +++ b/lib/pages/carton/cargo_type_editor.dart @@ -100,7 +100,8 @@ class _CargoTypeEditorState extends State { )), body: Container( padding: EdgeInsets.all(18), - child: Column( + child: ListView( + shrinkWrap: true, children: [ cargoTypeBox, rateBox, diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 6e02991..5638b50 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -63,6 +63,8 @@ class _CartonEditorState extends State { double shipmentWeight = 0; FcsShipment _fcsShipment; List _fcsShipments; + Carton _mixCarton; + List _mixCartons; @override void initState() { @@ -85,6 +87,7 @@ class _CartonEditorState extends State { _selectedCartonType = _carton.cartonType; _isNew = false; _user = User(fcsID: _carton.fcsID, name: _carton.userName); + _loadPackages(); } else { _carton = Carton(cargoTypes: [], packages: [], cartons: []); _lengthController.text = "12"; @@ -93,6 +96,7 @@ class _CartonEditorState extends State { _isNew = true; _selectedCartonType = carton_from_packages; _loadFcsShipments(); + _loadMixCartons(); } } @@ -108,25 +112,46 @@ class _CartonEditorState extends State { }); } + _loadMixCartons() async { + if (_fcsShipment == null) return; + CartonModel cartonModel = Provider.of(context, listen: false); + var mixCartons = + await cartonModel.getMixCartonsByFcsShipment(_fcsShipment.id); + setState(() { + _mixCartons = mixCartons; + }); + } + _loadPackages() async { if (_user == null) return; PackageModel packageModel = Provider.of(context, listen: false); - List packages = await packageModel.getPackages(_user.id); - String prevCompare; - packages.forEach((p) { - String compare = (p.deliveryAddress?.fullName ?? "") + - (p.deliveryAddress?.phoneNumber ?? ""); - if (prevCompare != null && compare == prevCompare) { - p.isChecked = true; - } else { - p.isChecked = false; - } - if (prevCompare == null) { - p.isChecked = true; - prevCompare = compare; - } - }); + List packages = await packageModel.getPackages( + _user.id, [package_processed_status, package_packed_status]); + if (_isNew) { + String prevCompare; + packages.forEach((p) { + String compare = (p.deliveryAddress?.fullName ?? "") + + (p.deliveryAddress?.phoneNumber ?? ""); + if (prevCompare != null && compare == prevCompare) { + p.isChecked = true; + } else { + p.isChecked = false; + } + if (prevCompare == null) { + p.isChecked = true; + prevCompare = compare; + } + }); + } else { + packages.forEach((p) { + if (_carton.packages.contains(p)) { + p.isChecked = _carton.packages.firstWhere((cp) => cp == p).isChecked; + } else { + p.isChecked = false; + } + }); + } setState(() { _carton.packages = packages; @@ -176,12 +201,17 @@ class _CartonEditorState extends State { Widget build(BuildContext context) { var boxModel = Provider.of(context); bool isMixBox = _selectedCartonType == carton_mix_box; + bool isSmallBag = _selectedCartonType == carton_small_bag; final shipmentBox = DisplayText( text: _carton.fcsShipmentNumber, labelTextKey: "box.fcs_shipment_num", iconData: Ionicons.ios_airplane, ); - + final mixCartonNumberBox = DisplayText( + text: _carton.mixCartonNumber, + labelTextKey: "box.mix.carton", + iconData: MaterialCommunityIcons.package, + ); var fcsShipmentsBox = LocalDropdown( callback: (v) { setState(() { @@ -190,6 +220,9 @@ class _CartonEditorState extends State { if (_selectedCartonType == carton_mix_box) { _loadCartons(); } + if (_selectedCartonType == carton_small_bag) { + _loadMixCartons(); + } }, labelKey: "shipment.pack.fcs.shipment", iconData: Ionicons.ios_airplane, @@ -198,6 +231,19 @@ class _CartonEditorState extends State { values: _fcsShipments, ); + var mixCartonsBox = LocalDropdown( + callback: (v) { + setState(() { + _mixCarton = v; + }); + }, + labelKey: "box.mix.carton", + iconData: MaterialCommunityIcons.package, + display: (u) => u.cartonNumber, + selectedValue: _mixCarton, + values: _mixCartons, + ); + final fcsIDBox = Row( children: [ Expanded( @@ -338,16 +384,19 @@ class _CartonEditorState extends State { cartonTypeBox, LocalTitle(textKey: "box.shipment_info"), _isNew ? fcsShipmentsBox : shipmentBox, + isSmallBag + ? _isNew ? mixCartonsBox : mixCartonNumberBox + : Container(), ...(isMixBox ? [ - CartonMixTable( - cartons: _carton.cartons, - onSelect: (c, check) { - setState(() { - c.isChecked = check; - }); - }, - ) + // CartonMixTable( + // cartons: _carton.cartons, + // onSelect: (c, check) { + // setState(() { + // c.isChecked = check; + // }); + // }, + // ) ] : [ fcsIDBox, @@ -368,9 +417,11 @@ class _CartonEditorState extends State { ), cargoTableTitleBox, cargoTableBox, - LocalTitle(textKey: "box.dimension"), - dimBox, - shipmentWeightBox, + isSmallBag + ? Container() + : LocalTitle(textKey: "box.dimension"), + isSmallBag ? Container() : dimBox, + isSmallBag ? Container() : shipmentWeightBox, LocalTitle(textKey: "box.delivery_address"), DefaultDeliveryAddress( deliveryAddress: _deliveryAddress, @@ -413,7 +464,9 @@ class _CartonEditorState extends State { } _save() async { - if (_user == null) { + bool isFromShipment = _selectedCartonType == carton_from_shipments; + bool isSmallBag = _selectedCartonType == carton_small_bag; + if (_user == null && (isFromShipment || isSmallBag)) { showMsgDialog(context, "Error", "Please select customer"); return; } @@ -421,35 +474,40 @@ class _CartonEditorState extends State { showMsgDialog(context, "Error", "Please select FCS shipment"); return; } - if ((_carton.cargoTypes?.length ?? 0) == 0) { + 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) { + if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) { showMsgDialog(context, "Error", "Invalid dimension"); return; } - if (_deliveryAddress == null) { + if (_deliveryAddress == null && (isFromShipment || isSmallBag)) { showMsgDialog(context, "Error", "Invalid delivery address"); return; } + if (isSmallBag && _mixCarton == null) { + showMsgDialog(context, "Error", "Invalid mix carton"); + return; + } Carton carton = Carton(); carton.id = _carton.id; carton.cartonType = _selectedCartonType; carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; - carton.userID = _user.id; + 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; - + carton.cartons = _carton.cartons.where((c) => c.isChecked).toList(); setState(() { _isLoading = true; }); diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index d83e93e..2c23bd0 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -55,7 +55,8 @@ class _CartonInfoState extends State { bool isMixBox; bool isFromShipments; - bool isFromPackage; + bool isFromPackages; + bool isSmallBag; bool isEdiable; @override @@ -72,35 +73,39 @@ class _CartonInfoState extends State { _widthController.addListener(_calShipmentWeight); _heightController.addListener(_calShipmentWeight); + _updateBoxData(); + _loadPackages(); + } + + _updateBoxData() { _widthController.text = _box.width.toString(); _heightController.text = _box.height.toString(); _lengthController.text = _box.length.toString(); - _cargoTypes = _box.cargoTypes; _deliveryAddress = _box.deliveryAddress; - isMixBox = _box.cartonType == carton_mix_box; isFromShipments = _box.cartonType == carton_from_shipments; - isFromPackage = _box.cartonType == carton_from_packages; - isEdiable = - (isMixBox || isFromPackage) && _box.status == carton_packed_status; - - if (isFromPackage) { - _loadPackages(); - } + isFromPackages = _box.cartonType == carton_from_packages; + isSmallBag = _box.cartonType == carton_small_bag; + isEdiable = !isMixBox && + (isFromPackages || isSmallBag) && + _box.status == carton_packed_status; } _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); + List packages = await packageModel.getPackages(_box.userID, [ + package_processed_status, + package_packed_status, + package_shipped_status + ]); + packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList(); packages.forEach((p) { - if (_box.packageIDs.contains(p.id)) { - p.isChecked = true; - } else { - p.isChecked = false; - } + p.isChecked = true; }); setState(() { @@ -219,6 +224,11 @@ class _CartonInfoState extends State { final cargoTableBox = CargoTable( cargoTypes: _box.cargoTypes, ); + final mixCartonNumberBox = DisplayText( + text: _box.mixCartonNumber, + labelTextKey: "box.mix.carton", + iconData: MaterialCommunityIcons.package, + ); return LocalProgress( inAsyncCall: _isLoading, @@ -250,65 +260,68 @@ class _CartonInfoState extends State { ] : [], ), - body: Card( - child: Column( - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.all(10.0), - child: ListView(children: [ - Center(child: getCartonNumberStatus(context, _box)), - LocalTitle(textKey: "box.type.title"), - cartonTypeBox, - LocalTitle(textKey: "box.shipment_info"), - shipmentBox, - fcsIDBox, - customerNameBox, - isFromPackage - ? CartonPackageTable( - packages: _box.packages, - ) - : Container(), - isFromPackage - ? Container() - : isFromShipments - ? Column( - children: [ - LocalTitle(textKey: "box.shipment.boxes"), - shipmentBoxTitle, - Divider( - color: Colors.grey[400], - ), - shipmentBoxRow - ], - ) - : _selectedCartonType == "Mix carton" - ? CartonMixTable( - cartons: _box.cartons, - onSelect: (c, check) { - setState(() { - c.isChecked = check; - }); - }, - ) - : Container(), - LocalTitle(textKey: "box.cargo.type"), - cargoTableBox, - LocalTitle(textKey: "box.dimension"), - dimBox, - shipmentWeightBox, - LocalTitle(textKey: "box.delivery_address"), - DefaultDeliveryAddress( + body: Padding( + padding: const EdgeInsets.all(10.0), + child: ListView(children: [ + Center(child: getCartonNumberStatus(context, _box)), + LocalTitle(textKey: "box.type.title"), + cartonTypeBox, + LocalTitle(textKey: "box.shipment_info"), + shipmentBox, + isSmallBag ? mixCartonNumberBox : Container(), + isMixBox ? Container() : fcsIDBox, + isMixBox ? Container() : customerNameBox, + isFromPackages || isSmallBag + ? CartonPackageTable( + packages: _box.packages, + ) + : Container(), + isFromPackages + ? Container() + : isFromShipments + ? Column( + children: [ + LocalTitle(textKey: "box.shipment.boxes"), + shipmentBoxTitle, + Divider( + color: Colors.grey[400], + ), + shipmentBoxRow + ], + ) + : Container(), + // : _selectedCartonType == "Mix carton" + // ? CartonMixTable( + // cartons: _box.cartons, + // onSelect: (c, check) { + // setState(() { + // c.isChecked = check; + // }); + // }, + // ) + // : Container(), + isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"), + isMixBox ? Container() : cargoTableBox, + ...(isFromPackages + ? [ + LocalTitle(textKey: "box.dimension"), + dimBox, + shipmentWeightBox, + ] + : []), + isMixBox + ? Container() + : LocalTitle(textKey: "box.delivery_address"), + isMixBox + ? Container() + : DefaultDeliveryAddress( deliveryAddress: _deliveryAddress, labelKey: "box.delivery_address", ), - SizedBox( - height: 20, - ) - ]), - )), - ], - ), + SizedBox( + height: 20, + ) + ]), ), ), ); @@ -324,6 +337,7 @@ class _CartonInfoState extends State { var c = await cartonModel.getCarton(widget.box.id); setState(() { _box = c; + _updateBoxData(); }); _loadPackages(); } diff --git a/lib/pages/carton/carton_list_row.dart b/lib/pages/carton/carton_list_row.dart index b5b48ee..54c4a7e 100644 --- a/lib/pages/carton/carton_list_row.dart +++ b/lib/pages/carton/carton_list_row.dart @@ -7,32 +7,20 @@ import 'package:flutter_icons/flutter_icons.dart'; import 'package:intl/intl.dart'; import 'carton_info.dart'; -class CartonListRow extends StatefulWidget { +class CartonListRow extends StatelessWidget { final Carton box; - const CartonListRow({Key key, this.box}) : super(key: key); + CartonListRow({Key key, this.box}) : super(key: key); - @override - _CartonListRowState createState() => _CartonListRowState(); -} - -class _CartonListRowState extends State { final double dotSize = 15.0; - Carton _box = new Carton(); final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); - @override - void initState() { - super.initState(); - _box = widget.box; - } - @override Widget build(BuildContext context) { return InkWell( onTap: () { Navigator.push( context, - CupertinoPageRoute(builder: (context) => CartonInfo(box: _box)), + CupertinoPageRoute(builder: (context) => CartonInfo(box: box)), ); }, child: Container( @@ -59,7 +47,7 @@ class _CartonListRowState extends State { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - _box.cartonNumber ?? "", + box.cartonNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -67,7 +55,7 @@ class _CartonListRowState extends State { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - _box.userName ?? "", + box.userName ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -83,14 +71,14 @@ class _CartonListRowState extends State { children: [ Padding( padding: const EdgeInsets.all(0), - child: getStatus(_box.status == null ? "" : _box.status), + child: getStatus(box.status == null ? "" : box.status), ), Padding( padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), child: Row( children: [ new Text( - "${_box.actualWeight?.toString() ?? ''} lb", + "${box.actualWeight?.toString() ?? ''} lb", style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/carton/carton_mix_table.dart b/lib/pages/carton/carton_mix_table.dart index 33187c2..86daa49 100644 --- a/lib/pages/carton/carton_mix_table.dart +++ b/lib/pages/carton/carton_mix_table.dart @@ -31,45 +31,47 @@ class CartonMixTable extends StatelessWidget { ), ); - final rows = cartons.asMap().entries.map((p) { - return Container( - color: p.value.isChecked - ? Colors.grey.withOpacity(0.2) - : Colors.grey[50].withOpacity(0.2), - child: Container( - padding: - EdgeInsets.only(left: 0.0, right: 10.0, top: 3.0, bottom: 3.0), - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: p.key == cartons.length - 1 - ? Colors.white - : Colors.grey[350], - width: 1), - ), - ), - child: Row( - children: [ - Checkbox( - value: p.value.isChecked, - activeColor: primaryColor, - onChanged: (bool check) { - if (onSelect != null) onSelect(p.value, check); - }), - Expanded( - child: new Text( - p.value.cartonNumber ?? "", - style: textStyle, - )), - new Text( - p.value?.actualWeight?.toString() ?? "", - style: textStyle, + final rows = cartons == null + ? [] + : cartons.asMap().entries.map((p) { + return Container( + color: p.value.isChecked + ? Colors.grey.withOpacity(0.2) + : Colors.grey[50].withOpacity(0.2), + child: Container( + padding: EdgeInsets.only( + left: 0.0, right: 10.0, top: 3.0, bottom: 3.0), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide( + color: p.key == cartons.length - 1 + ? Colors.white + : Colors.grey[350], + width: 1), + ), + ), + child: Row( + children: [ + Checkbox( + value: p.value.isChecked, + activeColor: primaryColor, + onChanged: (bool check) { + if (onSelect != null) onSelect(p.value, check); + }), + Expanded( + child: new Text( + p.value.cartonNumber ?? "", + style: textStyle, + )), + new Text( + p.value?.actualWeight?.toString() ?? "", + style: textStyle, + ), + ], + ), ), - ], - ), - ), - ); - }).toList(); + ); + }).toList(); return Column( children: [ diff --git a/lib/pages/carton/model/carton_model.dart b/lib/pages/carton/model/carton_model.dart index 98e17ed..e96213c 100644 --- a/lib/pages/carton/model/carton_model.dart +++ b/lib/pages/carton/model/carton_model.dart @@ -55,11 +55,16 @@ class CartonModel extends BaseModel { }); } - List cartonTypes = [carton_from_packages, carton_mix_box]; + List cartonTypes = [ + carton_from_packages, + carton_mix_box, + carton_small_bag + ]; List cartonTypesInfo = [ carton_from_packages, carton_mix_box, - carton_from_shipments + carton_from_shipments, + carton_small_bag ]; set selectedIndex(int index) { @@ -192,6 +197,19 @@ class CartonModel extends BaseModel { .toList(); } + Future> getMixCartonsByFcsShipment(String fcsShipmentID) async { + String path = "/$cartons_collection"; + var querySnap = await Firestore.instance + .collection(path) + .where("fcs_shipment_id", isEqualTo: fcsShipmentID) + .where("carton_type", isEqualTo: carton_mix_box) + .where("is_deleted", isEqualTo: false) + .getDocuments(); + return querySnap.documents + .map((e) => Carton.fromMap(e.data, e.documentID)) + .toList(); + } + Future getCarton(String id) async { String path = "/$cartons_collection"; var snap = await Firestore.instance.collection(path).document(id).get(); diff --git a/lib/pages/delivery/delivery_info.dart b/lib/pages/delivery/delivery_info.dart index 58be46f..8f131b3 100644 --- a/lib/pages/delivery/delivery_info.dart +++ b/lib/pages/delivery/delivery_info.dart @@ -3,6 +3,7 @@ import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/carton/widgets.dart'; import 'package:fcs/pages/delivery/model/delivery_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; @@ -460,90 +461,80 @@ class _DeliveryInfoState extends State { // ), // ], ), - body: Card( - child: Column( - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.all(10.0), - child: ListView(children: [ - // Center(child: nameWidget(_box.packageNumber)), - SizedBox( - height: 10, - ), - LocalTitle(textKey: "box.type.title"), - cargoType, - LocalTitle(textKey: "box.shipment_info"), - shipmentBox, - fcsIDBox, - customerNameBox, - _selectedCartonType == "From packages" - ? Column( - children: [ - LocalTitle(textKey: "box.packages"), - packageTitle, - Divider( - color: Colors.grey[400], - ), - Column( - children: getPackageRowList(), - ), - ], - ) - : _selectedCartonType == "From shipments" - ? Column( - children: [ - LocalTitle(textKey: "box.shipment.boxes"), - shipmentBoxTitle, - Divider( - color: Colors.grey[400], - ), - shipmentBoxRow - ], - ) - : _selectedCartonType == "Mix carton" - ? Column( - children: [ - LocalTitle(textKey: "box.shipment.boxes"), - mixBoxTitle, - Divider( - color: Colors.grey[400], - ), - Column( - children: getMixBoxRowList(), - ) - ], - ) - : Container(), - LocalTitle(textKey: "box.cargo_type"), - cargoTitle, - Divider( - color: Colors.grey[400], - ), - Column( - children: getCargoRowList(), - ), - LocalTitle(textKey: "box.dimension"), - dimBox, - shipmentWeightBox, - LocalTitle(textKey: "box.delivery_address"), - DefaultDeliveryAddress( - deliveryAddress: _deliveryAddress, - labelKey: "box.delivery_address", - ), - LocalTitle(textKey: "box.status"), - Container( - height: 230, - child: Timeline( - children: _models(), position: TimelinePosition.Left), - ), - SizedBox( - height: 20, + body: Padding( + padding: const EdgeInsets.all(10.0), + child: ListView(children: [ + Center(child: getCartonNumberStatus(context, _box)), + LocalTitle(textKey: "box.type.title"), + cargoType, + LocalTitle(textKey: "box.shipment_info"), + shipmentBox, + fcsIDBox, + customerNameBox, + _selectedCartonType == "From packages" + ? Column( + children: [ + LocalTitle(textKey: "box.packages"), + packageTitle, + Divider( + color: Colors.grey[400], + ), + Column( + children: getPackageRowList(), + ), + ], ) - ]), - )), - ], - ), + : _selectedCartonType == "From shipments" + ? Column( + children: [ + LocalTitle(textKey: "box.shipment.boxes"), + shipmentBoxTitle, + Divider( + color: Colors.grey[400], + ), + shipmentBoxRow + ], + ) + : _selectedCartonType == "Mix carton" + ? Column( + children: [ + LocalTitle(textKey: "box.shipment.boxes"), + mixBoxTitle, + Divider( + color: Colors.grey[400], + ), + Column( + children: getMixBoxRowList(), + ) + ], + ) + : Container(), + LocalTitle(textKey: "box.cargo_type"), + cargoTitle, + Divider( + color: Colors.grey[400], + ), + Column( + children: getCargoRowList(), + ), + LocalTitle(textKey: "box.dimension"), + dimBox, + shipmentWeightBox, + LocalTitle(textKey: "box.delivery_address"), + DefaultDeliveryAddress( + deliveryAddress: _deliveryAddress, + labelKey: "box.delivery_address", + ), + LocalTitle(textKey: "box.status"), + Container( + height: 230, + child: Timeline( + children: _models(), position: TimelinePosition.Left), + ), + SizedBox( + height: 20, + ) + ]), ), ), ); diff --git a/lib/pages/delivery/delivery_list_row.dart b/lib/pages/delivery/delivery_list_row.dart index 096b6e7..16bdcac 100644 --- a/lib/pages/delivery/delivery_list_row.dart +++ b/lib/pages/delivery/delivery_list_row.dart @@ -8,32 +8,20 @@ import 'package:intl/intl.dart'; import 'delivery_info.dart'; -class DeliveryListRow extends StatefulWidget { +class DeliveryListRow extends StatelessWidget { final Carton box; - const DeliveryListRow({Key key,this.box}):super(key:key); + DeliveryListRow({Key key, this.box}) : super(key: key); - @override - _DeliveryListRowState createState() => _DeliveryListRowState(); -} - -class _DeliveryListRowState extends State { final double dotSize = 15.0; - Carton _box = new Carton(); final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); - @override - void initState() { - super.initState(); - _box = widget.box; - } - @override Widget build(BuildContext context) { return InkWell( onTap: () { Navigator.push( context, - CupertinoPageRoute(builder: (context) => DeliveryInfo(box: _box)), + CupertinoPageRoute(builder: (context) => DeliveryInfo(box: box)), ); }, child: Container( @@ -42,7 +30,7 @@ class _DeliveryListRowState extends State { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), + padding: const EdgeInsets.symmetric(vertical: 10.0), child: new Row( children: [ Container( @@ -60,7 +48,7 @@ class _DeliveryListRowState extends State { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - _box.cartonNumber ?? "", + box.cartonNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -68,7 +56,7 @@ class _DeliveryListRowState extends State { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - _box.userName ?? "", + box.userName ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -84,14 +72,14 @@ class _DeliveryListRowState extends State { children: [ Padding( padding: const EdgeInsets.all(0), - child: getStatus(_box.status == null ? "" : _box.status), + child: getStatus(box.status == null ? "" : box.status), ), Padding( padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), child: Row( children: [ new Text( - "${_box.actualWeight?.toString() ?? ''} lb", + "${box.actualWeight?.toString() ?? ''} lb", style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index cda652b..f25fce8 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -112,7 +112,14 @@ class _DeliveryAddressEditorState extends State { shadowColor: Colors.transparent, title: LocalText(context, 'delivery_address', color: primaryColor, fontSize: 18), - actions: [IconButton(icon: Icon(Icons.delete), onPressed: _delete)], + actions: [ + IconButton( + icon: Icon( + Icons.delete, + color: primaryColor, + ), + onPressed: _delete) + ], ), body: Padding( padding: const EdgeInsets.only(left: 10.0, right: 10), diff --git a/lib/pages/discount/discount_list_row.dart b/lib/pages/discount/discount_list_row.dart index 376d46f..1bdd912 100644 --- a/lib/pages/discount/discount_list_row.dart +++ b/lib/pages/discount/discount_list_row.dart @@ -8,25 +8,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:intl/intl.dart'; -class DiscountListRow extends StatefulWidget { +class DiscountListRow extends StatelessWidget { final Discount discount; - const DiscountListRow({Key key, this.discount}) : super(key: key); + DiscountListRow({Key key, this.discount}) : super(key: key); - @override - _DiscountListRowState createState() => _DiscountListRowState(); -} - -class _DiscountListRowState extends State { - final double dotSize = 15.0; - Discount _discount; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); - @override - void initState() { - super.initState(); - _discount = widget.discount; - } - @override Widget build(BuildContext context) { return InkWell( @@ -34,7 +21,7 @@ class _DiscountListRowState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => DiscountEditor(discount: _discount)), + builder: (context) => DiscountEditor(discount: discount)), ); }, child: Container( @@ -61,7 +48,7 @@ class _DiscountListRowState extends State { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - _discount.code ?? "", + discount.code ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -69,7 +56,7 @@ class _DiscountListRowState extends State { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - _discount.customerName ?? "", + discount.customerName ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -85,14 +72,14 @@ class _DiscountListRowState extends State { children: [ Padding( padding: const EdgeInsets.all(0), - child: Text(_discount.status), + child: Text(discount.status), ), Padding( padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), child: Row( children: [ new Text( - "${_discount.amount ?? ''}", + "${discount.amount ?? ''}", style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index e3d20b4..11bffd3 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -113,16 +113,16 @@ class _FcsShipmentEditorState extends State { iconData: Icons.date_range, controller: _cutoffDateController, ), - InputDate( - labelTextKey: "FCSshipment.ETA", - iconData: Icons.date_range, - controller: _arrivalDateController, - ), InputDate( labelTextKey: "FCSshipment.departure_date", iconData: Icons.date_range, controller: _departureDateControler, ), + InputDate( + labelTextKey: "FCSshipment.ETA", + iconData: Icons.date_range, + controller: _arrivalDateController, + ), DropdownButtonFormField( value: _currentShipmentType == "" ? null : _currentShipmentType, decoration: InputDecoration( diff --git a/lib/pages/fcs_shipment/fcs_shipment_info.dart b/lib/pages/fcs_shipment/fcs_shipment_info.dart index 2fd29b8..81c2fa8 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_info.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_info.dart @@ -158,8 +158,8 @@ class _FcsShipmentInfoState extends State { child: ListView(children: [ shipmentNumberBox, cutoffDateDBox, - etaBox, departureDateBox, + etaBox, shipTypeBox, consigneeBox, portBox, diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index 9fee1b4..d57cef3 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -128,7 +128,7 @@ class PackageModel extends BaseModel { if (forCustomer) { q = q.where("user_id", isEqualTo: user.id); } - + q = q.orderBy("tracking_id", descending: false); listener = q.snapshots().listen((QuerySnapshot snapshot) { _packages.clear(); _packages = snapshot.documents.map((documentSnapshot) { @@ -197,13 +197,12 @@ class PackageModel extends BaseModel { return null; } - Future> getPackages(String userID) async { + Future> getPackages(String userID, List status) async { List packages = []; try { var snaps = await Firestore.instance .collection("/$packages_collection") - .where("status", - whereIn: [package_processed_status, package_packed_status]) + .where("status", whereIn: status) .where("user_id", isEqualTo: userID) .where("is_deleted", isEqualTo: false) .where("is_delivered", isEqualTo: false) diff --git a/lib/pages/package/package_info.dart b/lib/pages/package/package_info.dart index af92cb5..83bc1d1 100644 --- a/lib/pages/package/package_info.dart +++ b/lib/pages/package/package_info.dart @@ -62,6 +62,9 @@ class _PackageInfoState extends State { Widget build(BuildContext context) { String id = Provider.of(context).user.id; bool owner = _package.userID == id; + bool canChangeDeliveryAddress = + _package.status == package_received_status || + _package.status == package_processed_status; final trackingIdBox = DisplayText( text: _package.trackingID, @@ -106,7 +109,7 @@ class _PackageInfoState extends State { final deliveryAddressBox = DefaultDeliveryAddress( deliveryAddress: _package.deliveryAddress, labelKey: "package.delivery.address", - onTap: owner + onTap: owner && canChangeDeliveryAddress ? () async { DeliveryAddress d = await Navigator.push( context, diff --git a/lib/pages/rates/model/shipment_rate_model.dart b/lib/pages/rates/model/shipment_rate_model.dart index 0b25799..1bf26d3 100644 --- a/lib/pages/rates/model/shipment_rate_model.dart +++ b/lib/pages/rates/model/shipment_rate_model.dart @@ -59,7 +59,7 @@ class ShipmentRateModel extends BaseModel { } Future deleteCustomDuty(String id) { - return Services.instance.rateService.deleteCargoType(id); + return Services.instance.rateService.deleteCustomDuty(id); } //Discount by weight diff --git a/lib/pages/rates/shipment_rates.dart b/lib/pages/rates/shipment_rates.dart index 460b55a..f5f6a8a 100644 --- a/lib/pages/rates/shipment_rates.dart +++ b/lib/pages/rates/shipment_rates.dart @@ -3,12 +3,10 @@ import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/rates/cargo_type_list.dart'; import 'package:fcs/pages/rates/custom_list.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; diff --git a/lib/pages/rates/shipment_rates_edit.dart b/lib/pages/rates/shipment_rates_edit.dart index 18a6ccc..286be1c 100644 --- a/lib/pages/rates/shipment_rates_edit.dart +++ b/lib/pages/rates/shipment_rates_edit.dart @@ -1,25 +1,21 @@ import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/custom_duty.dart'; -import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/my_data_table.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; -import 'package:flutter/material.dart'; - import '../main/util.dart'; import 'cargo_editor.dart'; import 'custom_editor.dart'; -import 'discount_by_weight_editor.dart'; class ShipmentRatesEdit extends StatefulWidget { ShipmentRatesEdit(); @@ -34,14 +30,16 @@ class _ShipmentRatesEditState extends State { TextEditingController _deliveryFee = new TextEditingController(); TextEditingController _volumetricRatio = new TextEditingController(); - bool _isNew = false; - @override void initState() { super.initState(); - _minWeight.text = "10"; - _deliveryFee.text = "5"; - _volumetricRatio.text = "166.36"; + var shipmentRateModel = + Provider.of(context, listen: false); + Rate rate = shipmentRateModel.rate; + + _minWeight.text = rate.freeDeliveryWeight?.toString() ?? ""; + _deliveryFee.text = rate.deliveryFee?.toString() ?? ""; + _volumetricRatio.text = rate.volumetricRatio?.toString() ?? ""; } @override @@ -91,202 +89,6 @@ class _ShipmentRatesEditState extends State { feeBox, ratioBox, SizedBox(height: 10), - // ExpansionTile( - // title: Text( - // 'Cargo Types', - // style: TextStyle( - // color: primaryColor, fontWeight: FontWeight.bold), - // ), - // children: [ - // Container( - // child: SingleChildScrollView( - // scrollDirection: Axis.horizontal, - // child: MyDataTable( - // headingRowHeight: 40, - // columnSpacing: 50, - // columns: [ - // MyDataColumn( - // label: Text("Cargo Type", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // MyDataColumn( - // label: Text("Rate", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // MyDataColumn( - // label: Text("Delete", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // ], - // rows: getCargoRows( - // shipmentRateModel.rate.cargoTypes), - // ), - // ), - // ), - // Container( - // padding: - // EdgeInsets.only(top: 20, bottom: 15, right: 15), - // child: Align( - // alignment: Alignment.bottomRight, - // child: Container( - // width: 120, - // height: 40, - // child: FloatingActionButton.extended( - // materialTapTargetSize: - // MaterialTapTargetSize.shrinkWrap, - // icon: Icon(Icons.add), - // onPressed: () { - // Navigator.push( - // context, - // CupertinoPageRoute( - // builder: (context) => CargoEditor()), - // ); - // }, - // label: Text( - // 'Add Cargo', - // style: TextStyle(fontSize: 12), - // ), - // backgroundColor: primaryColor, - // ), - // ), - // ), - // ) - // ], - // ), - // ExpansionTile( - // title: Text( - // 'Custom Duties', - // style: TextStyle( - // color: primaryColor, fontWeight: FontWeight.bold), - // ), - // children: [ - // Container( - // child: SingleChildScrollView( - // scrollDirection: Axis.horizontal, - // child: MyDataTable( - // headingRowHeight: 40, - // columnSpacing: 50, - // columns: [ - // MyDataColumn( - // label: Text("Produt Type", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // MyDataColumn( - // label: Text("Fee", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // MyDataColumn( - // label: Text("Delete", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // ], - // rows: getCustomsRows( - // shipmentRateModel.rate.customDuties), - // ), - // ), - // ), - // Container( - // padding: - // EdgeInsets.only(top: 20, bottom: 15, right: 15), - // child: Align( - // alignment: Alignment.bottomRight, - // child: Container( - // width: 120, - // height: 40, - // child: FloatingActionButton.extended( - // materialTapTargetSize: - // MaterialTapTargetSize.shrinkWrap, - // icon: Icon(Icons.add), - // onPressed: () { - // Navigator.push( - // context, - // CupertinoPageRoute( - // builder: (context) => CustomEditor()), - // ); - // }, - // label: Text( - // 'Add Custom\nDuty', - // style: TextStyle(fontSize: 12), - // ), - // backgroundColor: primaryColor, - // ), - // ), - // ), - // ) - // ], - // ), - // ExpansionTile( - // title: Text( - // 'Discounts by weight', - // style: TextStyle( - // color: primaryColor, fontWeight: FontWeight.bold), - // ), - // children: [ - // Container( - // child: SingleChildScrollView( - // scrollDirection: Axis.horizontal, - // child: MyDataTable( - // headingRowHeight: 40, - // columnSpacing: 30, - // columns: [ - // MyDataColumn( - // label: Text("Weight", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // MyDataColumn( - // label: Text("Discount Rate", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // MyDataColumn( - // label: Text("Delete", - // style: TextStyle( - // fontSize: 15, - // color: Colors.grey[600]))), - // ], - // rows: getDiscounts( - // shipmentRateModel.rate.discountByWeights), - // ), - // ), - // ), - // Container( - // padding: - // EdgeInsets.only(top: 20, bottom: 15, right: 15), - // child: Align( - // alignment: Alignment.bottomRight, - // child: Container( - // width: 130, - // height: 40, - // child: FloatingActionButton.extended( - // materialTapTargetSize: - // MaterialTapTargetSize.shrinkWrap, - // icon: Icon(Icons.add), - // onPressed: () { - // Navigator.push( - // context, - // CupertinoPageRoute( - // builder: (context) => - // DiscountByWeightEditor()), - // ); - // }, - // label: Text( - // 'Add Discount', - // style: TextStyle(fontSize: 12), - // ), - // backgroundColor: primaryColor, - // ), - // ), - // ), - // ) - // ], - // ), ], ), ), @@ -311,7 +113,7 @@ class _ShipmentRatesEditState extends State { deliveryFee: double.parse(_deliveryFee.text), freeDeliveryWeight: double.parse(_minWeight.text), volumetricRatio: double.parse(_volumetricRatio.text)); - Rate r = new Rate(); + Rate r = new Rate(); print('_rate =>$r'); await shipmentRateModel.updateRate(_rate); Navigator.pop(context); diff --git a/lib/pages/widgets/length_picker.dart b/lib/pages/widgets/length_picker.dart index ea11de6..32ae511 100644 --- a/lib/pages/widgets/length_picker.dart +++ b/lib/pages/widgets/length_picker.dart @@ -10,7 +10,8 @@ class LengthPicker extends StatefulWidget { final String lableKey; final bool isReadOnly; - const LengthPicker({Key key, this.controller, this.lableKey, this.isReadOnly}) + const LengthPicker( + {Key key, this.controller, this.lableKey, this.isReadOnly = false}) : super(key: key); @override @@ -42,9 +43,7 @@ class _LengthPickerState extends State { @override Widget build(BuildContext context) { return InkWell( - onTap: () => widget.isReadOnly == null - ? _showDialog(context) - : widget.isReadOnly ? null : _showDialog(context), + onTap: widget.isReadOnly ? null : () => _showDialog(context), child: Padding( padding: EdgeInsets.only(left: 8, right: 8), child: InputText(