import 'dart:async'; import 'dart:convert'; import 'package:mohem_flutter_app/api/api_client.dart'; import 'package:mohem_flutter_app/api/api_mapper_class.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/date_uitl.dart'; import 'package:mohem_flutter_app/models/dashboard/get_accrual_balances_list_model.dart'; import 'package:mohem_flutter_app/models/dashboard/get_attendance_tracking_list_model.dart'; import 'package:mohem_flutter_app/models/dashboard/get_open_missing_swipe.dart'; import 'package:mohem_flutter_app/models/dashboard/itg_forms_model.dart'; import 'package:mohem_flutter_app/models/dashboard/list_menu.dart'; import 'package:mohem_flutter_app/models/dashboard/menu_entries.dart'; import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/models/itg/itg_main_response.dart'; import 'package:mohem_flutter_app/models/itg/itg_response_model.dart'; import 'package:mohem_flutter_app/models/worklist/get_open_notifications.dart'; import 'package:platform_device_id_v2/platform_device_id_v2.dart'; import 'package:uuid/uuid.dart'; class DashboardApiClient { static final DashboardApiClient _instance = DashboardApiClient._internal(); DashboardApiClient._internal(); factory DashboardApiClient() => _instance; Future getAttendanceTracking() async { String url = "${ApiConsts.erpRest}GET_Attendance_Tracking"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); GetAttendanceTracking ress = await ApiClassMapper().handleApiEndpoint(endpoint: "GET_Attendance_Tracking", jsonData: res.data); return ress; } Future> getOpenNotifications() async { String url = "${ApiConsts.erpRest}GET_OPEN_NOTIFICATIONS"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); List ress = await ApiClassMapper().handleApiEndpoint(endpoint: "GET_OPEN_NOTIFICATIONS", jsonData: res.data); return ress; } Future getCOCNotifications() async { String url = "${ApiConsts.cocRest}Mohemm_ITG_ReviewerAdmin_Pending_Tasks"; Map postParams = {"Date": DateUtil.getISODateFormat(DateTime.now()), "EmployeeNumber": AppState().memberInformationList?.employeENumber}; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { GenericResponseModel responseData = GenericResponseModel.fromJson(json); return responseData; }, url, postParams); } Future getItgFormsPendingTask() async { String url = "${ApiConsts.cocRest}ITGFormsPendingTasks"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { ItgFormsModel responseData = ItgFormsModel.fromJson(json); return responseData; }, url, postParams); } Future> getAccrualBalances(String effectiveDate, {String? empID}) async { String url = "${ApiConsts.erpRest}GET_ACCRUAL_BALANCES"; Map postParams = {"p_EFFECTIVE_DATE": effectiveDate}; postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["p_SELECTED_EMPLOYEE_NUMBER"] = empID; dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); List ress = await ApiClassMapper().handleApiEndpoint(endpoint: "GET_ACCRUAL_BALANCES", jsonData: res.data); return ress; } Future getOpenMissingSwipes() async { String url = "${ApiConsts.erpRest}GET_OPEN_MISSING_SWIPES"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); GetOpenMissingSwipes? ress = await ApiClassMapper().handleApiEndpoint(endpoint: "GET_OPEN_MISSING_SWIPES", jsonData: res.data); return ress; } //Menus List Future> getListMenu() async { String url = "${ApiConsts.erpRest}GET_MENU"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); List ress = await ApiClassMapper().handleApiEndpoint(endpoint: "GET_MENU", jsonData: res.data); return ress; } //GET_MENU_ENTRIES Future> getGetMenuEntries() async { String url = "${ApiConsts.erpRest}GET_MENU_ENTRIES"; Map postParams = {"p_SELECTED_RESP_ID": -999, "p_MENU_TYPE": "E"}; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); List ress = await ApiClassMapper().handleApiEndpoint(endpoint: "GET_MENU_ENTRIES", jsonData: res.data); return ress; } //Mark Attendance Future markAttendance({String lat = "0", String? long = "0", required int pointType, String nfcValue = "", bool isGpsRequired = false, String QRValue = "", String payrollCode = ""}) async { String url = "${ApiConsts.erpRest}AuthenticateAndSwipeUserSupportNFC"; var uuid = Uuid(); // Generate a v4 (random) id Map postParams = { "UID": await PlatformDeviceId.getDeviceId, //uuid.v4(), //Mobile Id // "UID": uuid.v4(), //Mobile Id "Latitude": lat, "Longitude": long, "QRValue": QRValue, "PointType": pointType, // NFC=2, Wifi = 3, QR= 1, "NFCValue": nfcValue, "WifiValue": pointType == 3 ? "100" : "", "IsGpsRequired": isGpsRequired, "PayrollCodeStr": AppState().postParamsObject?.payrollCodeStr.toString() ?? "" }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { GenericResponseModel responseData = GenericResponseModel.fromJson(json); return responseData; }, url, postParams); } //Mark Fake Location Future markFakeLocation({String lat = "0", String? long = "0", required String sourceName}) async { String url = "${ApiConsts.erpRest}CreateIssueInfo"; var uuid = Uuid(); // Generate a v4 (random) id Map postParams = { "UID": uuid.v4(), //Mobile Id "Latitude": lat, "Longitude": long, "QRValue": '', "NFCValue": sourceName == 'NFC' ? sourceName : '', "WifiValue": sourceName == 'WIFI' ? sourceName : '', "EmployeeID": AppState().memberInformationList!.employeENumber, }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { GenericResponseModel responseData = GenericResponseModel.fromJson(json["Data"]); return responseData; }, url, postParams); } //Check ITG Type Future getITGPageNotification() async { String url = "${ApiConsts.cocRest}Mohemm_ITG_GetPageNotification"; Map postParams = { "EmployeeNumber": AppState().getUserName, "ItgEnableAt": "After Service Submission", //Mobile Id "ItgServiceName": "Login" }; postParams.addAll(AppState().postParamsJson); dynamic response = await ApiClient().postJsonForObject((json) => json, url, postParams, token: AppState().postParamsObject!.tokenID); ApiResponse res = ApiResponse.fromJson(response); MohemmItgResponseItem ress = await ApiClassMapper().handleApiEndpoint(endpoint: "Mohemm_ITG_GetPageNotification", jsonData: res.data); return ress; } //Submit ITG Future submitItgForm({required String comment, required String masterId, required List> itgList, required int serviceId}) async { String url = "${ApiConsts.cocRest}Mohemm_ITG_Survey_Response"; Map postParams = { "EmployeeNumber": AppState().getUserName, "ItgComments": comment, "ItgNotificationMasterId": masterId, "ItgQuestionResponses": itgList, "ItgSurveyId": serviceId }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { ItgMainRes responseData = ItgMainRes.fromJson(json); return responseData; }, url, postParams); } Future getAdvertisementDetail(String masterID) async { String url = "${ApiConsts.cocRest}Mohemm_ITG_GetPageNotificationDetails"; Map postParams = { "EmployeeNumber": AppState().getUserName, "ItgNotificationMasterId": masterID, //Mobile Id }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { ItgMainRes responseData = ItgMainRes.fromJson(json); return responseData; }, url, postParams); } Future setAdvertisementViewed(String masterID, int advertisementId, String? ackValue) async { String url = "${ApiConsts.cocRest}Mohemm_ITG_UpdateAdvertisementAsViewed"; Map postParams = { "ItgNotificationMasterId": masterID, "EmployeeNumber": AppState().memberInformationList!.employeENumber.toString(), "ItgAdvertisementId": advertisementId, "ItgAcknowledgment": ackValue, // "ItgAdvertisement": {"ItgAdvertisementId": advertisementId, "ItgAcknowledgment": ackValue} //Mobile Id }; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { // ItgMainRes responseData = ItgMainRes.fromJson(json); return json; }, url, postParams); } }