diff --git a/src/main/java/com/primefactorsolutions/Application.java b/src/main/java/com/primefactorsolutions/Application.java index 298fd56..e66d089 100644 --- a/src/main/java/com/primefactorsolutions/Application.java +++ b/src/main/java/com/primefactorsolutions/Application.java @@ -4,7 +4,6 @@ import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.theme.Theme; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; - /** * The entry point of the Spring Boot application. * diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index f2302bc..447911c 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -3,7 +3,6 @@ package com.primefactorsolutions.service; import com.primefactorsolutions.model.*; import com.primefactorsolutions.repositories.TimeOffRequestRepository; import lombok.AllArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.time.LocalDate; @@ -53,27 +52,22 @@ public class TimeOffRequestService { return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category); } - @Scheduled(cron = "0 0 0 * * ?") - private void updateRequestStatuses() { + public void updateRequestStatuses() { List requests = findAllTimeOffRequests(); LocalDate now = LocalDate.now(); for (TimeOffRequest request : requests) { - if (request.getState() != TimeOffRequestStatus.RECHAZADO) { - LocalDate expirationDate = request.getExpiration(); + if (request.getState() == TimeOffRequestStatus.APROBADO) { LocalDate startDate = request.getStartDate(); LocalDate endDate = request.getEndDate(); - if (now.isAfter(expirationDate)) { - request.setState(TimeOffRequestStatus.VENCIDO); - } else if (now.isAfter(endDate) && now.isBefore(expirationDate)) { + if (now.isAfter(endDate)) { request.setState(TimeOffRequestStatus.TOMADO); } else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) { request.setState(TimeOffRequestStatus.EN_USO); } } } - saveAll(requests); } } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 055bced..50323c7 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -52,6 +52,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private void initializeView() { + requestService.updateRequestStatuses(); setupFilters(); setupGrid(); add(requestGrid, createActionButtons(), createSummaryLayout()); diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 864b9e5..9cedaa3 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -63,6 +63,7 @@ public class RequestRegisterView extends VerticalLayout { } private void initializeView() { + requestService.updateRequestStatuses(); configureFormFields(); configureButtons(); configureBinder(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 73c2cbf..5da8183 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -57,6 +57,7 @@ public class RequestsListView extends Main { } private void initializeView() { + requestService.updateRequestStatuses(); setupFilters(); setupRequestGrid(); add(requestGrid);