diff --git a/lib/api/worklist/worklist_api_client.dart b/lib/api/worklist/worklist_api_client.dart index f1f9408..91c0db0 100644 --- a/lib/api/worklist/worklist_api_client.dart +++ b/lib/api/worklist/worklist_api_client.dart @@ -296,7 +296,39 @@ class WorkListApiClient { "RequestType": requestType, "TaskID": taskId, "ItemID": itemId, - "EmployeeNumber": "15153", + "EmployeeNumber": employeeNumber, + }; + postParams.addAll(AppState().postParamsJson); + return await ApiClient().postJsonForObject((json) { + ItgFormsModel responseData = ItgFormsModel.fromJson(json); + return responseData.itgRequest; + }, url, postParams); + } + + Future rejectITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String comments) async { + String url = "${ApiConsts.cocRest}ITGRejectRequest"; + Map postParams = { + "RequestType": requestType, + "TaskID": taskId, + "ItemID": itemId, + "EmployeeNumber": employeeNumber, + "Comments": comments, + }; + postParams.addAll(AppState().postParamsJson); + return await ApiClient().postJsonForObject((json) { + ItgFormsModel responseData = ItgFormsModel.fromJson(json); + return responseData.itgRequest; + }, url, postParams); + } + + Future approveITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String comments) async { + String url = "${ApiConsts.cocRest}ITGApproveRequest"; + Map postParams = { + "RequestType": requestType, + "TaskID": taskId, + "ItemID": itemId, + "EmployeeNumber": employeeNumber, + "Comments": comments, }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { diff --git a/lib/ui/work_list/itg_detail_screen.dart b/lib/ui/work_list/itg_detail_screen.dart index 25eced3..203d6cd 100644 --- a/lib/ui/work_list/itg_detail_screen.dart +++ b/lib/ui/work_list/itg_detail_screen.dart @@ -16,11 +16,13 @@ import 'package:mohem_flutter_app/models/get_notification_buttons_list_model.dar import 'package:mohem_flutter_app/models/itg_forms_models/allowed_actions_model.dart'; import 'package:mohem_flutter_app/models/itg_forms_models/itg_request_model.dart'; import 'package:mohem_flutter_app/models/itg_forms_models/request_detail_model.dart'; +import 'package:mohem_flutter_app/models/notification_get_respond_attributes_list_model.dart'; import 'package:mohem_flutter_app/ui/work_list/itg_fragments/approval_level_fragment.dart'; import 'package:mohem_flutter_app/ui/work_list/itg_fragments/request_detail_fragment.dart'; import 'package:mohem_flutter_app/widgets/app_bar_widget.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart'; import 'package:mohem_flutter_app/widgets/dialogs/accept_reject_input_dialog.dart'; +import 'package:mohem_flutter_app/widgets/dialogs/itg_comments_dialog.dart'; class ItgDetailScreen extends StatefulWidget { ItgDetailScreen({Key? key}) : super(key: key); @@ -56,22 +58,21 @@ class _ItgDetailScreenState extends State { ITGRequest? itgRequest; void getItgData() async { - // try { + try { Utils.showLoading(context); - itgRequest = await WorkListApiClient().getITGFormDetails(requestDetails!.requestType!, requestDetails!.iD!, requestDetails!.itemID!, ""); + itgRequest = await WorkListApiClient().getITGFormDetails(requestDetails!.requestType!, requestDetails!.iD!, requestDetails!.itemID!, AppState().memberInformationList?.eMPLOYEENUMBER ?? ""); allowedActionList = itgRequest?.allowedActions ?? []; if (allowedActionList.isNotEmpty) { isCloseAvailable = allowedActionList.any((element) => element.action == "CLOSE"); isApproveAvailable = itgRequest!.allowedActions!.any((element) => element.action == "Approve"); - // isAnswerAvailable = itgRequest!.allowedActions!.any((element) => element.action == "Answer"); isRejectAvailable = itgRequest!.allowedActions!.any((element) => element.action == "Reject"); } Utils.hideLoading(context); setState(() {}); - // } catch (ex) { - // Utils.hideLoading(context); - // Utils.handleException(ex, context, null); - // } + } catch (ex) { + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } } void getDataFromState() { @@ -341,37 +342,39 @@ class _ItgDetailScreenState extends State { void performAction(String actionMode) { showDialog( context: context, - builder: (cxt) => AcceptRejectInputDialog( - message: LocaleKeys.requestedItems.tr(), - // notificationGetRespond: notificationNoteInput, + builder: (cxt) => ITGCommentsDialog( + message: LocaleKeys.writeComment.tr(), onTap: (note) { - Map payload = { - "P_ACTION_MODE": actionMode, - "P_APPROVER_INDEX": null, - "P_COMMENTS": "", - "P_FORWARD_TO_USER_NAME": "", - // "P_NOTIFICATION_ID": workListData!.nOTIFICATIONID!, - "RespondAttributeList": [ - // if (notificationNoteInput != null) {notificationNoteInput!.attributeName: note} - ], - }; - - performNotificationAction(payload); + performRejectAction(requestDetails!.requestType!, requestDetails!.iD!, requestDetails!.itemID!, AppState().memberInformationList?.eMPLOYEENUMBER ?? "", note); }, ), ); } - void performNotificationAction(Map payload) async { + void performRejectAction(String requestType, int taskId, int itemId, String employeeNumber, String comments) async { + try { + Utils.showLoading(context); + ITGRequest? itgRequest = await WorkListApiClient().rejectITGRequest(requestType, taskId, itemId, employeeNumber, comments); + Utils.hideLoading(context); + Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + Navigator.pop(context, "delegate_reload"); + } catch (ex) { + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + + void performApproveAction(String requestType, int taskId, int itemId, String employeeNumber, String comments) async { try { Utils.showLoading(context); - GenericResponseModel model = await WorkListApiClient().postNotificationActions(payload); + ITGRequest? itgRequest = await WorkListApiClient().approveITGRequest(requestType, taskId, itemId, employeeNumber, comments); Utils.hideLoading(context); Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); - Navigator.pop(context, true); + Navigator.pop(context, "delegate_reload"); } catch (ex) { Utils.hideLoading(context); Utils.handleException(ex, context, null); } } + } diff --git a/lib/ui/work_list/work_list_screen.dart b/lib/ui/work_list/work_list_screen.dart index c3cc9c6..e3231fa 100644 --- a/lib/ui/work_list/work_list_screen.dart +++ b/lib/ui/work_list/work_list_screen.dart @@ -32,17 +32,45 @@ class WorkListScreen extends StatefulWidget { class _WorkListScreenState extends State { List workListItemTypes = [ WorkListItemTypeModelData( - value: 0, name: 'HR', fullName: LocaleKeys.humanResource.tr(), active: false, color: [Color(0xff32D892), Color(0xff1AB170)], icon: "assets/images/miss_swipe.svg", key: 'HRSSA', disable: false), + value: 0, + name: 'HR', + fullName: LocaleKeys.humanResource.tr(), + active: false, + color: [Color(0xff32D892), Color(0xff1AB170)], + icon: "assets/images/miss_swipe.svg", + key: 'HRSSA', + disable: false), WorkListItemTypeModelData( value: 0, name: 'MO', fullName: LocaleKeys.moveOrder.tr(), active: false, color: [Color(0xff58DCFA), Color(0xff3CB9D5)], icon: "assets/images/miss_swipe.svg", key: 'INVMOA', disable: false), WorkListItemTypeModelData( - value: 0, name: 'PR', fullName: LocaleKeys.purchaseRequisition.tr(), active: false, color: [Color(0xff48EACF), Color(0xff3DCAB3)], icon: "assets/images/miss_swipe.svg", key: 'REQAPPRV', disable: false), + value: 0, + name: 'PR', + fullName: LocaleKeys.purchaseRequisition.tr(), + active: false, + color: [Color(0xff48EACF), Color(0xff3DCAB3)], + icon: "assets/images/miss_swipe.svg", + key: 'REQAPPRV', + disable: false), WorkListItemTypeModelData( - value: 0, name: 'PO', fullName: LocaleKeys.purchaseOrder.tr(), active: false, color: [Color(0xff5099E3), Color(0xff3670AA)], icon: "assets/images/miss_swipe.svg", key: 'POAPPRV', disable: false), + value: 0, + name: 'PO', + fullName: LocaleKeys.purchaseOrder.tr(), + active: false, + color: [Color(0xff5099E3), Color(0xff3670AA)], + icon: "assets/images/miss_swipe.svg", + key: 'POAPPRV', + disable: false), WorkListItemTypeModelData( value: 0, name: 'ITG', fullName: LocaleKeys.ITGForms.tr(), active: false, color: [Color(0xffEB8C90), Color(0xffDE6C70)], icon: "assets/images/miss_swipe.svg", key: 'ITG', disable: false), WorkListItemTypeModelData( - value: 0, name: 'IC', fullName: LocaleKeys.itemCreation.tr(), active: false, color: [Color(0xff32D892), Color(0xff1AB170)], icon: "assets/images/miss_swipe.svg", key: 'INVITEM', disable: false), + value: 0, + name: 'IC', + fullName: LocaleKeys.itemCreation.tr(), + active: false, + color: [Color(0xff32D892), Color(0xff1AB170)], + icon: "assets/images/miss_swipe.svg", + key: 'INVITEM', + disable: false), WorkListItemTypeModelData( value: 0, name: 'STAMP', fullName: LocaleKeys.stamp.tr(), active: false, color: [Color(0xff32D892), Color(0xff1AB170)], icon: "assets/images/miss_swipe.svg", key: 'STAMP', disable: false), ]; @@ -232,6 +260,7 @@ class _WorkListScreenState extends State { var shouldReloadData = await Navigator.pushNamed(context, AppRoutes.itgDetail); if (shouldReloadData != null) { if (shouldReloadData.toString() == "delegate_reload") { + providerData.itgFormsModel!.totalCount = providerData.itgFormsModel!.totalCount! - 1; calculateCounter(); getWorkList(); } diff --git a/lib/widgets/dialogs/itg_comments_dialog.dart b/lib/widgets/dialogs/itg_comments_dialog.dart new file mode 100644 index 0000000..b984851 --- /dev/null +++ b/lib/widgets/dialogs/itg_comments_dialog.dart @@ -0,0 +1,102 @@ +import 'package:easy_localization/src/public_ext.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/extensions/int_extensions.dart'; +import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; +import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; +import 'package:mohem_flutter_app/widgets/button/default_button.dart'; +import 'package:mohem_flutter_app/widgets/input_widget.dart'; + +class ITGCommentsDialog extends StatelessWidget { + final String? title; + final String? message; + final String? okTitle; + final Function(String) onTap; + + ITGCommentsDialog({Key? key, this.title, @required this.message, this.okTitle, required this.onTap}) : super(key: key); + + String note = ""; + + @override + Widget build(BuildContext context) { + return Dialog( + backgroundColor: Colors.white, + shape: const RoundedRectangleBorder(), + insetPadding: const EdgeInsets.only(left: 21, right: 21), + child: Padding( + padding: const EdgeInsets.only(left: 20, right: 20, top: 18, bottom: 28), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.only(top: 16.0), + child: Text( + title ?? LocaleKeys.confirm.tr(), + style: const TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: Color(0xff2B353E), height: 35 / 24, letterSpacing: -0.96), + ), + ), + ), + IconButton( + padding: EdgeInsets.zero, + icon: const Icon(Icons.close), + color: const Color(0xff2B353E), + constraints: const BoxConstraints(), + onPressed: () { + Navigator.pop(context); + }, + ) + ], + ), + Text( + message ?? "", + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff808080), letterSpacing: -0.48), + ), + // if (notificationGetRespond != null) ...[ + 14.height, + InputWidget( + "Enter a Note", + LocaleKeys.comments.tr(), + TextEditingController(), + isBackgroundEnable: true, + isInputTypeNum: false, + lines: 3, + onChange: (String note) { + this.note = note; + }, + ), + // ], + 28.height, + Row( + children: [ + DefaultButton( + LocaleKeys.cancel.tr(), + () => Navigator.pop(context), + colors: const [MyColors.lightGreyEAColor, MyColors.lightGreyEAColor], + textColor: MyColors.darkTextColor, + ).expanded, + 10.width, + DefaultButton( + LocaleKeys.ok.tr(), + () { + Navigator.pop(context); + onTap(note); + }, + colors: const [ + Color(0xff28C884), + Color(0xff1BB271), + ], + ).expanded, + ], + ), + ], + ), + ), + ); + } +}