From 41a1be745e3b4de90728692c7e651d05af9ba1d1 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 1 Mar 2024 17:27:56 +0630 Subject: [PATCH] update shipment type --- .../provider/fcs_shipment_data_provider.dart | 9 ++---- lib/data/services/fcs_shipment_imp.dart | 5 --- lib/data/services/fcs_shipment_service.dart | 1 - lib/domain/constants.dart | 1 + lib/domain/entities/fcs_shipment.dart | 13 ++++---- lib/domain/entities/shipment_type.dart | 10 ++++++ lib/domain/entities/user.dart | 2 +- lib/helpers/api_helper.dart | 2 ++ lib/pages/customer/customer_list.dart | 6 ++-- lib/pages/discount/discount_list_row.dart | 10 +++--- .../fcs_shipment/fcs_shipment_editor.dart | 27 +++++++++------- lib/pages/fcs_shipment/fcs_shipment_info.dart | 32 ++++++++++++++++--- .../model/fcs_shipment_model.dart | 32 +++++++++++++++++++ lib/pages/staff/model/staff_model.dart | 14 ++++---- 14 files changed, 112 insertions(+), 52 deletions(-) create mode 100644 lib/domain/entities/shipment_type.dart diff --git a/lib/data/provider/fcs_shipment_data_provider.dart b/lib/data/provider/fcs_shipment_data_provider.dart index 34a0dc2..90f4210 100644 --- a/lib/data/provider/fcs_shipment_data_provider.dart +++ b/lib/data/provider/fcs_shipment_data_provider.dart @@ -7,17 +7,12 @@ class FcsShipmentDataProvider { final log = Logger('FcsShipmentDataProvider'); Future createFcsShipment(FcsShipment fcsShipment) async { - return await requestAPI("/fcs_shipments", "POST", + return await requestAPI("/shipments", "POST", payload: fcsShipment.toMap(), token: await getToken()); } Future updateFcsShipment(FcsShipment fcsShipment) async { - return await requestAPI("/fcs_shipments", "PUT", - payload: fcsShipment.toMap(), token: await getToken()); - } - - Future deleteFcsShipment(FcsShipment fcsShipment) async { - return await requestAPI("/fcs_shipments", "DELETE", + return await requestAPI("/shipments", "PUT", payload: fcsShipment.toMap(), token: await getToken()); } diff --git a/lib/data/services/fcs_shipment_imp.dart b/lib/data/services/fcs_shipment_imp.dart index 6e5b4bc..e934f13 100644 --- a/lib/data/services/fcs_shipment_imp.dart +++ b/lib/data/services/fcs_shipment_imp.dart @@ -23,11 +23,6 @@ class FcsShipmentServiceImp implements FcsShipmentService { return shipmentDataProvider.updateFcsShipment(fcsShipment); } - @override - Future deleteFcsShipment(FcsShipment fcsShipment) { - return shipmentDataProvider.deleteFcsShipment(fcsShipment); - } - @override Future report(FcsShipment fcsShipment) { return shipmentDataProvider.reportFcsShipment(fcsShipment); diff --git a/lib/data/services/fcs_shipment_service.dart b/lib/data/services/fcs_shipment_service.dart index 4805783..1ac61c8 100644 --- a/lib/data/services/fcs_shipment_service.dart +++ b/lib/data/services/fcs_shipment_service.dart @@ -3,7 +3,6 @@ import 'package:fcs/domain/entities/fcs_shipment.dart'; abstract class FcsShipmentService { Future createFcsShipment(FcsShipment fcsShipment); Future updateFcsShipment(FcsShipment fcsShipment); - Future deleteFcsShipment(FcsShipment fcsShipment); Future report(FcsShipment fcsShipment); Future processFcsShipment(String id); Future cancelFcsShipment(String id); diff --git a/lib/domain/constants.dart b/lib/domain/constants.dart index 52f6bfb..3b7158f 100644 --- a/lib/domain/constants.dart +++ b/lib/domain/constants.dart @@ -7,6 +7,7 @@ const invitations_collection = "invitations"; const privilege_collection = "privileges"; const markets_collection = "markets"; const carton_sizes_collection = "carton_sizes"; +const shipment_type_collection = "shipment_types"; const packages_collection = "packages"; const messages_collection = "messages"; diff --git a/lib/domain/entities/fcs_shipment.dart b/lib/domain/entities/fcs_shipment.dart index b7ca8b9..caeb045 100644 --- a/lib/domain/entities/fcs_shipment.dart +++ b/lib/domain/entities/fcs_shipment.dart @@ -6,6 +6,7 @@ class FcsShipment { String? id; String? shipmentNumber; DateTime? cutoffDate; + String? shipmentTypeId; String? shipType; DateTime? arrivalDate; DateTime? departureDate; @@ -19,6 +20,7 @@ class FcsShipment { this.id, this.shipmentNumber, this.cutoffDate, + this.shipmentTypeId, this.shipType, this.status, this.arrivalDate, @@ -34,17 +36,14 @@ class FcsShipment { map['cutoff_date'] == null ? null : (map['cutoff_date'] as Timestamp); var _arrivalDate = map['arrival_date'] == null ? null : (map['arrival_date'] as Timestamp); - var _departureDate = map['departure_date'] == null - ? null - : (map['departure_date'] as Timestamp); return FcsShipment( id: docID, cutoffDate: _cutoffDate != null ? _cutoffDate.toDate() : null, arrivalDate: _arrivalDate != null ? _arrivalDate.toDate() : null, - departureDate: _departureDate != null ? _departureDate.toDate() : null, shipmentNumber: map['shipment_number'], shipType: map['shipment_type'], + shipmentTypeId: map['shipment_type_id'] ?? "", status: map['status'], consignee: map['consignee'], port: map['port'], @@ -62,8 +61,8 @@ class FcsShipment { 'consignee': consignee, 'port': port, 'destination': destination, - 'status': status, - 'report_name': reportName, + // 'status': status, + // 'report_name': reportName, }; } @@ -75,7 +74,7 @@ class FcsShipment { return fcsShipment.shipmentNumber != this.shipmentNumber || fcsShipment.cutoffDate != this.cutoffDate || fcsShipment.arrivalDate != this.arrivalDate || - fcsShipment.shipType != this.shipType || + fcsShipment.shipmentTypeId != this.shipmentTypeId || fcsShipment.consignee != this.consignee || fcsShipment.port != this.port || fcsShipment.destination != this.destination; diff --git a/lib/domain/entities/shipment_type.dart b/lib/domain/entities/shipment_type.dart new file mode 100644 index 0000000..f40df43 --- /dev/null +++ b/lib/domain/entities/shipment_type.dart @@ -0,0 +1,10 @@ +class ShipmentType { + String id; + String desc; + + ShipmentType({required this.id, required this.desc}); + + factory ShipmentType.fromMap(Map map, String id) { + return ShipmentType(id: id, desc: map['desc'] ?? ""); + } +} diff --git a/lib/domain/entities/user.dart b/lib/domain/entities/user.dart index 8e1a73f..4e4680e 100644 --- a/lib/domain/entities/user.dart +++ b/lib/domain/entities/user.dart @@ -5,7 +5,7 @@ import 'package:intl/intl.dart'; import '../constants.dart'; DateFormat dayFormat = DateFormat("MMM dd yyyy"); -DateFormat timeFormat = DateFormat("HH:mm"); +DateFormat timeFormat = DateFormat("hh:mm a"); final DateFormat dateFormat = DateFormat("d MMM yyyy"); class User { diff --git a/lib/helpers/api_helper.dart b/lib/helpers/api_helper.dart index 4868f75..5cab2ec 100644 --- a/lib/helpers/api_helper.dart +++ b/lib/helpers/api_helper.dart @@ -40,6 +40,8 @@ Future requestAPI(String path, method, headers: headers, ); log.info("baseUrl:${options.baseUrl}, path:$path"); + log.info("payload:$payload"); + try { Dio dio = new Dio(options); Response response = await dio.request( diff --git a/lib/pages/customer/customer_list.dart b/lib/pages/customer/customer_list.dart index eef9255..36b08f9 100644 --- a/lib/pages/customer/customer_list.dart +++ b/lib/pages/customer/customer_list.dart @@ -130,7 +130,7 @@ class _CustomerListState extends State { ), customer.status == user_invited_status ? Padding( - padding: const EdgeInsets.only(right: 10.0), + padding: const EdgeInsets.only(right: 10), child: SizedBox( height: 30, child: TextButton( @@ -182,14 +182,14 @@ class _CustomerListState extends State { decoration: BoxDecoration(shape: BoxShape.circle, color: secondaryColor), child: Text(customer.getFcsUnseenCount, - style: TextStyle(color: Colors.white)), + style: TextStyle(color: Colors.white, fontSize: 12)), ) : Container(); } Widget _status(String status) { return user_requested_status == status || user_disabled_status == status - ? Text(status, style: TextStyle(color: primaryColor, fontSize: 14)) + ? Text(status, style: TextStyle(color: primaryColor, fontSize: 12)) : Container(); } diff --git a/lib/pages/discount/discount_list_row.dart b/lib/pages/discount/discount_list_row.dart index 53268b9..c79a167 100644 --- a/lib/pages/discount/discount_list_row.dart +++ b/lib/pages/discount/discount_list_row.dart @@ -60,11 +60,13 @@ class DiscountListRow extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ - Text(discount.status ?? ''), + Text(discount.status ?? '', + style: TextStyle( + color: primaryColor, + fontSize: 15, + fontWeight: FontWeight.bold)), Padding( - padding: const EdgeInsets.only( - top: 5, - ), + padding: const EdgeInsets.only(top: 5), child: Row( children: [ new Text( diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index 92985e8..6719676 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -3,7 +3,6 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart'; import 'package:fcs/pages/main/model/language_model.dart'; -import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/widgets/input_date.dart'; import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; @@ -15,6 +14,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; +import '../../domain/entities/shipment_type.dart'; import '../main/util.dart'; class FcsShipmentEditor extends StatefulWidget { @@ -39,13 +39,14 @@ class _FcsShipmentEditorState extends State { FcsShipment _shipment = new FcsShipment(); bool _isLoading = false; - String? _currentShipmentType; + ShipmentType? _currentShipmentType; bool _isNew = false; @override void initState() { super.initState(); _isNew = widget.shipment == null; + var model = Provider.of(context, listen: false); if (widget.shipment != null) { _shipment = widget.shipment!; _shipmentNumberController.text = _shipment.shipmentNumber ?? ""; @@ -59,13 +60,13 @@ class _FcsShipmentEditorState extends State { _departureDateControler.text = dateFormatter.format(_shipment.departureDate!); _statusController.text = _shipment.status ?? ""; - _currentShipmentType = _shipment.shipType; _consigneeController.text = _shipment.consignee ?? ""; _portController.text = _shipment.port ?? ""; _destinationController.text = _shipment.destination ?? ""; + + // _currentShipmentType = model.shipmentTypes.where((e) => e.id == _shipment.shipmentTypeId).first; } else { - var mainModel = Provider.of(context, listen: false); - _currentShipmentType = mainModel.setting!.shipmentTypes[0]; + _currentShipmentType = model.shipmentTypes[0]; } } @@ -77,7 +78,8 @@ class _FcsShipmentEditorState extends State { @override Widget build(BuildContext context) { var languageModel = Provider.of(context); - var mainModel = Provider.of(context); + List shipmentTypes = + context.watch().shipmentTypes; final createBtn = Padding( padding: const EdgeInsets.symmetric(horizontal: 30), @@ -171,10 +173,11 @@ class _FcsShipmentEditorState extends State { labelText: AppTranslations.of(context)! .text('FCSshipment.shipment_type'), icon: Icon(Ionicons.ios_airplane, color: primaryColor)), - items: mainModel.setting!.shipmentTypes - .map((e) => DropdownMenuItem(child: Text(e), value: e)) + items: shipmentTypes + .map((e) => + DropdownMenuItem(child: Text(e.desc), value: e)) .toList(), - onChanged: (String? selected) => { + onChanged: (selected) => { setState(() { _currentShipmentType = selected; }) @@ -206,7 +209,7 @@ class _FcsShipmentEditorState extends State { FcsShipment fcsShipment = FcsShipment(); fcsShipment.id = _shipment.id; fcsShipment.shipmentNumber = _shipmentNumberController.text; - fcsShipment.shipType = _currentShipmentType!; + fcsShipment.shipmentTypeId = _currentShipmentType?.id; fcsShipment.consignee = _consigneeController.text; fcsShipment.port = _portController.text; fcsShipment.destination = _destinationController.text; @@ -262,14 +265,14 @@ class _FcsShipmentEditorState extends State { isDataChanged() { if (_isNew) { - var mainModel = Provider.of(context, listen: false); + var shipmentModel = Provider.of(context, listen: false); return _shipmentNumberController.text != "" || _cutoffDateController.text != "" || _arrivalDateController.text != "" || _consigneeController.text != "" || _portController.text != "" || _destinationController.text != "" || - _currentShipmentType != mainModel.setting!.shipmentTypes[0]; + _currentShipmentType != shipmentModel.shipmentTypes[0]; } else { FcsShipment fcsShipment = _getPayload(); return widget.shipment!.isChangedForEdit(fcsShipment); diff --git a/lib/pages/fcs_shipment/fcs_shipment_info.dart b/lib/pages/fcs_shipment/fcs_shipment_info.dart index c622ee8..e51cd00 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_info.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_info.dart @@ -159,7 +159,9 @@ class _FcsShipmentInfoState extends State { color: dangerColor, textKey: "FCSshipment.cancel.btn", callBack: () { - showConfirmDialog(context, "FCSshipment.cancel.confirm", () {}); + showConfirmDialog(context, "FCSshipment.cancel.confirm", () { + _cancelFcsShipment(); + }); }, ), ); @@ -174,10 +176,12 @@ class _FcsShipmentInfoState extends State { labelColor: primaryColor, arrowColor: primaryColor, actions: [ - IconButton( - icon: Icon(Icons.edit, color: primaryColor), - onPressed: _edit, - ), + _fcsShipment?.status == fcs_shipment_pending_status + ? IconButton( + icon: Icon(Icons.edit, color: primaryColor), + onPressed: _edit, + ) + : const SizedBox(), //menuPopWidget(context) ], ), @@ -377,6 +381,24 @@ class _FcsShipmentInfoState extends State { } } + _cancelFcsShipment() async { + setState(() { + _isLoading = true; + }); + try { + FcsShipmentModel fcsShipmentModel = + Provider.of(context, listen: false); + await fcsShipmentModel.cancel(_fcsShipment!.id!); + Navigator.pop(context, true); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + setState(() { + _isLoading = false; + }); + } + } + _showPDF(int id) async { setState(() { _isLoading = true; diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index efdd301..b90cc93 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -7,6 +7,7 @@ import 'package:fcs/domain/entities/fcs_shipment.dart'; import 'package:fcs/pages/main/model/base_model.dart'; import 'package:logging/logging.dart'; +import '../../../domain/entities/shipment_type.dart'; import '../../../pagination/paginator_listener.dart'; class FcsShipmentModel extends BaseModel { @@ -15,6 +16,9 @@ class FcsShipmentModel extends BaseModel { bool isLoading = false; int selectedIndex = 0; + List shipmentTypes = []; + StreamSubscription? _shipmentTypeListener; + onChanged(int index) { selectedIndex = index; loadFcsShipments(selectedIndex); @@ -132,11 +136,35 @@ class FcsShipmentModel extends BaseModel { void initUser(user) { super.initUser(user); + _loadShipmentTypes(); } @override logout() async { fcsShipments?.close(); + _shipmentTypeListener?.cancel(); + shipmentTypes.clear(); + } + + Future _loadShipmentTypes() async { + try { + _shipmentTypeListener = FirebaseFirestore.instance + .collection( + "/$config_collection/$setting_doc_id/$shipment_type_collection") + .snapshots() + .listen((QuerySnapshot snapshot) { + shipmentTypes.clear(); + shipmentTypes = snapshot.docs.map((documentSnapshot) { + var privilege = ShipmentType.fromMap( + documentSnapshot.data() as Map, + documentSnapshot.id); + return privilege; + }).toList(); + notifyListeners(); + }); + } catch (e) { + log.warning("Error!! $e"); + } } Future create(FcsShipment fcsShipment) { @@ -163,6 +191,10 @@ class FcsShipmentModel extends BaseModel { return Services.instance.fcsShipmentService.invoiceFcsShipment(id); } + Future cancel(String id) { + return Services.instance.fcsShipmentService.cancelFcsShipment(id); + } + Future report(FcsShipment fcsShipment) { return Services.instance.fcsShipmentService.report(fcsShipment); } diff --git a/lib/pages/staff/model/staff_model.dart b/lib/pages/staff/model/staff_model.dart index 58fdb6f..3a2e709 100644 --- a/lib/pages/staff/model/staff_model.dart +++ b/lib/pages/staff/model/staff_model.dart @@ -82,13 +82,13 @@ class StaffModel extends BaseModel { {required String userID, required bool enablePin, required int? pin}) async { - // await request("/employee/pin", "PUT", - // payload: { - // "id": userID, - // "enable_pin_login": enablePin, - // "new_pin": pin - // }, - // token: await getToken()); + await request("/employee/pin", "PUT", + payload: { + "id": userID, + "enable_pin_login": enablePin, + "pin": pin + }, + token: await getToken()); } Future findUser(String phoneNumber) {