From 8e1f0fdd7d13da3038b04a8cebd284ec10c0fc4e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 19:54:36 -0400 Subject: [PATCH] Lista de Solicitudes de empleado - actualizar solicitudes permisos de salud --- .../service/TimeOffRequestService.java | 3 ++- .../views/RequestEmployeeView.java | 10 +++++----- .../views/RequestRegisterView.java | 12 ++++++++++-- .../primefactorsolutions/views/RequestsListView.java | 5 +++++ src/main/resources/data.sql | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index 447911c..edb63b3 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -57,7 +57,8 @@ public class TimeOffRequestService { LocalDate now = LocalDate.now(); for (TimeOffRequest request : requests) { - if (request.getState() == TimeOffRequestStatus.APROBADO) { + if (request.getState() == TimeOffRequestStatus.APROBADO + || request.getState() == TimeOffRequestStatus.EN_USO) { LocalDate startDate = request.getStartDate(); LocalDate endDate = request.getEndDate(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index b449f16..c404769 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -217,15 +217,15 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return requests.stream() .filter(this::verificationIsHoliday) .filter(req -> getStartDateYear(req) == year) - .mapToDouble(TimeOffRequest::getAvailableDays) + .mapToDouble(TimeOffRequest::getDaysToBeTake) .sum(); } private double calculateVacationUtilizedDays(final int year) { return requests.stream() - .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) - .filter(req -> getStartDateYear(req) == year) - .mapToDouble(TimeOffRequest::getAvailableDays) + .filter(req -> req.getCategory().name().startsWith("VACACION")) + .filter(req -> getStartDateYear(req) == year || getStartDateYear(req) == year - 1) + .mapToDouble(TimeOffRequest::getDaysToBeTake) .sum(); } @@ -236,7 +236,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !req.getCategory().name().startsWith("VACACION")) .filter(req -> getStartDateYear(req) == year) - .mapToDouble(TimeOffRequest::getAvailableDays) + .mapToDouble(TimeOffRequest::getDaysToBeTake) .sum(); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index cf5c09c..2f34ba3 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -310,7 +310,7 @@ public class RequestRegisterView extends VerticalLayout { } private void setPickerValues(final Vacation vacation, final LocalDate startDate) { - startDatePicker.setValue(startDate) + startDatePicker.setValue(startDate); if ((vacation.getDuration() != null && vacation.getDuration() == 0.5) || vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD @@ -447,7 +447,15 @@ public class RequestRegisterView extends VerticalLayout { List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); - int maxRequests = request.getCategory().name().startsWith("VACACION") ? 2 : 1; + int maxRequests; + + if (request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { + maxRequests = 4; + } else if (request.getCategory().name().startsWith("VACACION")) { + maxRequests = 2; + } else { + maxRequests = 1; + } if (existingRequests.size() >= maxRequests) { existingRequests.stream() diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 5da8183..d9c4c09 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -192,8 +192,13 @@ public class RequestsListView extends Main { } private double calculateTotalUtilized(final List employeeRequests) { + int currentYear = LocalDate.now().getYear(); return employeeRequests.stream() .filter(Objects::nonNull) + .filter(request -> request.getStartDate() != null && ( + request.getStartDate().getYear() == currentYear || + (request.getCategory().name().startsWith("VACACION") && request.getStartDate().getYear() == currentYear - 1) + )) .mapToDouble(request -> request.getDaysToBeTake() != null ? request.getDaysToBeTake() : 0.0) .sum(); } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index aec0cdb..7f3c3f6 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -78,7 +78,7 @@ values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0 insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('9d6f12ba-e444-4e7a-b8a6-caa0982bd8d4', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VIERNES_SANTO', 'APROBADO', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2024-11-01', '2022-11-01', '2022-11-30', 30, 0); +values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2025-11-01', '2023-11-01', '2023-11-30', 30, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'DIA_DEL_TRABAJADOR', 'APROBADO', 1, '2024-05-01', '2024-05-01', '2024-05-01', 1, 0);