You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemm-flutter-app/lib/api/leave_balance_api_client.dart

119 lines
5.7 KiB
Dart

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/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';
class LeaveBalanceApiClient {
static final LeaveBalanceApiClient _instance = LeaveBalanceApiClient._internal();
LeaveBalanceApiClient._internal();
factory LeaveBalanceApiClient() => _instance;
Future<List<GetAbsenceTransactionList>> getAbsenceTransactions(int pSelectedResopID) async {
String url = "${ApiConsts.erpRest}GET_ABSENCE_TRANSACTIONS";
Map<String, dynamic> postParams = {"P_PAGE_LIMIT": 50, "P_PAGE_NUM": 1, "P_MENU_TYPE": "E", "P_SELECTED_RESP_ID": pSelectedResopID};
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return responseData.getAbsenceTransactionList ?? [];
}, url, postParams);
}
Future<List<GetAbsenceAttendanceTypesList>> getAbsenceAttendanceTypes() async {
String url = "${ApiConsts.erpRest}GET_ABSENCE_ATTENDANCE_TYPES";
Map<String, dynamic> postParams = {};
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return responseData.getAbsenceAttendanceTypesList ?? [];
}, url, postParams);
}
Future<CalculateAbsenceDuration> calculateAbsenceDuration(int pAbsenceAttendanceTypeID, String pDateStart, String pDateEnd, int pSelectedResopID) async {
String url = "${ApiConsts.erpRest}CALCULATE_ABSENCE_DURATION";
Map<String, dynamic> postParams = {
"P_ABSENCE_ATTENDANCE_TYPE_ID": pAbsenceAttendanceTypeID,
"P_DATE_END": pDateStart, //"29-Sep-2022",
"P_DATE_START": pDateEnd,
"P_SELECTED_RESP_ID": pSelectedResopID,
"P_MENU_TYPE": "E",
"P_TIME_END": null,
"P_TIME_START": null,
};
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return responseData.calculateAbsenceDuration!;
}, url, postParams);
}
Future<List<GetAbsenceDffStructureList>> getAbsenceDffStructure(String pDescFlexContextCode, String pFunctionName, int pSelectedResopID) async {
String url = "${ApiConsts.erpRest}GET_ABSENCE_DFF_STRUCTURE";
Map<String, dynamic> postParams = {"P_DESC_FLEX_CONTEXT_CODE": pDescFlexContextCode, "P_FUNCTION_NAME": pFunctionName, "P_MENU_TYPE": "E", "P_SELECTED_RESP_ID": pSelectedResopID};
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return responseData.getAbsenceDffStructureList ?? [];
}, url, postParams);
}
Future<GenericResponseModel> validateAbsenceTransaction(
String pDescFlexContextCode, String pFunctionName, int pAbsenceAttendanceTypeID, String pReplacementUserName, String pDateStart, String pDateEnd, int pSelectedResopID, Map<String, String> data,
{String comments = ""}) async {
String url = "${ApiConsts.erpRest}VALIDATE_ABSENCE_TRANSACTION";
Map<String, dynamic> 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_END": pDateStart, //"29-Sep-2022",
"P_DATE_START": pDateEnd,
"P_SELECTED_RESP_ID": pSelectedResopID,
"P_MENU_TYPE": "E",
"P_TIME_END": null,
"P_TIME_START": null,
};
postParams.addAll(data);
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return responseData;
}, url, postParams);
}
Future<GenericResponseModel> submitAbsenceTransaction(
String pDescFlexContextCode, String pFunctionName, int pAbsenceAttendanceTypeID, String pReplacementUserName, String pDateStart, String pDateEnd, int pSelectedResopID, Map<String, String> data,
{String comments = ""}) async {
String url = "${ApiConsts.erpRest}SUBMIT_ABSENCE_TRANSACTION";
Map<String, dynamic> 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_END": pDateStart, //"29-Sep-2022",
"P_DATE_START": pDateEnd,
"P_SELECTED_RESP_ID": pSelectedResopID,
"P_MENU_TYPE": "E",
"P_TIME_END": null,
"P_TIME_START": null,
};
postParams.addAll(data);
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
return responseData;
}, url, postParams);
}
}