import 'package:mohem_flutter_app/api/api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/calculate_absence_duration_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/cancel_hr_transaction_list_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/get_absence_attendance_types_list_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/get_absence_dff_structure_list_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/get_absence_transaction_list_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/start_absence_approval_proccess_model.dart'; import 'package:mohem_flutter_app/models/leave_balance/sumbit_absence_transaction_list_model.dart'; class LeaveBalanceApiClient { static final LeaveBalanceApiClient _instance = LeaveBalanceApiClient._internal(); LeaveBalanceApiClient._internal(); factory LeaveBalanceApiClient() => _instance; Future> getAbsenceTransactions(int pSelectedResopID, String? empID) async { String url = "${ApiConsts.erpRest}GET_ABSENCE_TRANSACTIONS"; Map postParams = {"P_PAGE_LIMIT": 50, "P_PAGE_NUM": 1, "P_MENU_TYPE": "E", "P_SELECTED_RESP_ID": pSelectedResopID}; postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.getAbsenceTransactionList ?? []; }, url, postParams); } Future> getAbsenceAttendanceTypes({String? empID}) async { String url = "${ApiConsts.erpRest}GET_ABSENCE_ATTENDANCE_TYPES"; Map postParams = {}; postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.getAbsenceAttendanceTypesList ?? []; }, url, postParams); } Future calculateAbsenceDuration(int pAbsenceAttendanceTypeID, String pDateStart, String pDateEnd, int pSelectedResopID, {String? empID}) async { String url = "${ApiConsts.erpRest}CALCULATE_ABSENCE_DURATION"; Map postParams = { "P_ABSENCE_ATTENDANCE_TYPE_ID": pAbsenceAttendanceTypeID, "P_DATE_START": pDateStart, "P_DATE_END": pDateEnd, "P_SELECTED_RESP_ID": pSelectedResopID, "P_MENU_TYPE": "E", "P_TIME_END": null, "P_TIME_START": null }; postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.calculateAbsenceDuration!; }, url, postParams); } Future> getAbsenceDffStructure(String pDescFlexContextCode, String pFunctionName, int pSelectedResopID, {String? empID}) async { String url = "${ApiConsts.erpRest}GET_ABSENCE_DFF_STRUCTURE"; Map postParams = { "P_DESC_FLEX_CONTEXT_CODE": pDescFlexContextCode, "P_FUNCTION_NAME": pFunctionName, "P_MENU_TYPE": "E", "P_SELECTED_RESP_ID": pSelectedResopID, }; postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.getAbsenceDffStructureList ?? []; }, url, postParams); } Future validateAbsenceTransaction( String pDescFlexContextCode, String pFunctionName, int pAbsenceAttendanceTypeID, String pReplacementUserName, String pDateStart, String pDateEnd, int pSelectedResopID, Map data, {String comments = "", String? empID}) async { String url = "${ApiConsts.erpRest}VALIDATE_ABSENCE_TRANSACTION"; Map postParams = { "P_DESC_FLEX_CONTEXT_CODE": pDescFlexContextCode, "P_FUNCTION_NAME": pFunctionName, "P_REPLACEMENT_USER_NAME": pReplacementUserName, "P_ABSENCE_ACTION": "CREATE", "P_ABSENCE_COMMENTS": comments, "P_ABSENCE_ATTENDANCE_ID": pAbsenceAttendanceTypeID, "P_ABSENCE_ATTENDANCE_TYPE_ID": pAbsenceAttendanceTypeID, "P_DATE_START": pDateStart, "P_DATE_END": pDateEnd, //"29-Sep-2022", "P_SELECTED_RESP_ID": pSelectedResopID, "P_MENU_TYPE": "E", "P_TIME_END": null, "P_TIME_START": null }; postParams.addAll(data); postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData; }, url, postParams); } Future submitAbsenceTransaction( String pDescFlexContextCode, String pFunctionName, int pAbsenceAttendanceTypeID, String pReplacementUserName, String pDateStart, String pDateEnd, int pSelectedResopID, Map data, {String comments = "", String? empID}) async { String url = "${ApiConsts.erpRest}SUBMIT_ABSENCE_TRANSACTION"; Map postParams = { "P_DESC_FLEX_CONTEXT_CODE": pDescFlexContextCode, "P_FUNCTION_NAME": pFunctionName, "P_REPLACEMENT_USER_NAME": pReplacementUserName, "P_ABSENCE_ACTION": "CREATE", "P_ABSENCE_COMMENTS": comments, "P_ABSENCE_ATTENDANCE_ID": pAbsenceAttendanceTypeID, "P_ABSENCE_ATTENDANCE_TYPE_ID": pAbsenceAttendanceTypeID, "P_DATE_START": pDateStart, "P_DATE_END": pDateEnd, //"29-Sep-2022", "P_SELECTED_RESP_ID": pSelectedResopID, "P_MENU_TYPE": "E", "P_TIME_END": null, "P_TIME_START": null }; postParams.addAll(data); postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.sumbitAbsenceTransactionList!; }, url, postParams); } Future cancelHrTransaction(int pTransactionID) async { String url = "${ApiConsts.erpRest}CANCEL_HR_TRANSACTION"; Map postParams = {"P_TRANSACTION_ID": pTransactionID}; postParams.addAll(AppState().postParamsJson); return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.cancelHRTransactionLIst!; }, url, postParams); } Future startAbsenceApprovalProcess(int pTransactionID, String comments, int pSelectedResopID, {String? empID}) async { String url = "${ApiConsts.erpRest}START_ABSENCE_APPROVAL_PROCESS"; Map postParams = {"P_TRANSACTION_ID": pTransactionID, "P_SELECTED_RESP_ID": pSelectedResopID, "P_COMMENTS": comments, "P_MENU_TYPE": "E"}; postParams.addAll(AppState().postParamsJson); if (empID != null) postParams["P_SELECTED_EMPLOYEE_NUMBER"] = empID; return await ApiClient().postJsonForObject((json) { GenericResponseModel? responseData = GenericResponseModel.fromJson(json); return responseData.startAbsenceApprovalProccess!; }, url, postParams); } }