From 807555a2dddeef89be103bedc6f146ccfcffc61e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 23 Oct 2024 15:09:36 -0400 Subject: [PATCH] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrativo?= =?UTF-8?q?=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Configurar?= =?UTF-8?q?=20habilitacion=20categoria=20si=20previa=20solicitud=20expira)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primefactorsolutions/views/RequestEmployeeView.java | 9 +++++++++ .../primefactorsolutions/views/RequestRegisterView.java | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 95c9592..f45f3fc 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -20,6 +20,7 @@ import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import java.time.LocalDate; import java.time.Year; import java.util.Collections; import java.util.List; @@ -154,6 +155,14 @@ public class RequestEmployeeView extends Div implements HasUrlParameter List filteredRequests = allFiltersAreNull(category, state) ? requestService.findRequestsByEmployeeId(employeeId) : fetchFilteredTimeOffRequests(category, state); + for (TimeOffRequest request : filteredRequests) { + if (request.getExpiration().isBefore(LocalDate.now())) { + request.setState(TimeOffRequestStatus.EXPIRED); + } + } + for (TimeOffRequest request : filteredRequests) { + requestService.saveTimeOffRequest(request); + } requestGrid.setItems(filteredRequests); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 1d64de7..c1ce30b 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -123,7 +123,8 @@ public class RequestRegisterView extends VerticalLayout { .map(TimeOffRequest::getCategory) .toList(); List availableCategories = Arrays.stream(TimeOffRequestType.values()) - .filter(category -> !requestedCategories.contains(category)) + .filter(category -> !requestedCategories.contains(category) || + employeeRequests.stream().anyMatch(req -> req.getCategory() == category && req.getState() == TimeOffRequestStatus.EXPIRED)) .filter(category -> { if (employee.getGender() == Employee.Gender.MALE) { return category != TimeOffRequestType.MATERNITY @@ -152,7 +153,7 @@ public class RequestRegisterView extends VerticalLayout { vacation = vacationService.findVacationByCategory(selectedCategory); List requests = requestService.findByEmployeeAndCategory(employeeComboBox.getValue().getId(), selectedCategory); if (vacation != null) { - if (!requests.isEmpty()) { + if (!requests.isEmpty() && requests.getFirst().getState() != TimeOffRequestStatus.EXPIRED) { availableDaysField.setValue(requests.getFirst().getDaysBalance()); } else if (vacation.getCategory() == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT) { LocalDate dateOfEntry = employeeComboBox.getValue().getDateOfEntry(); @@ -165,7 +166,7 @@ public class RequestRegisterView extends VerticalLayout { } else if (yearsOfService > 1) { availableDaysField.setValue((double)15); } else { - availableDaysField.setValue((double)0); // O asignar un valor predeterminado + availableDaysField.setValue((double)0); } } else { availableDaysField.setValue(vacation.getDuration());