Lista de Solicitudes de empleado - Actualizar estado
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m40s

This commit is contained in:
jesus.pelaez 2024-11-13 14:10:09 -04:00
parent 6d60fd00cc
commit ca5fb122fb
5 changed files with 6 additions and 10 deletions

View File

@ -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.
*

View File

@ -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<TimeOffRequest> 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);
}
}

View File

@ -52,6 +52,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
}
private void initializeView() {
requestService.updateRequestStatuses();
setupFilters();
setupGrid();
add(requestGrid, createActionButtons(), createSummaryLayout());

View File

@ -63,6 +63,7 @@ public class RequestRegisterView extends VerticalLayout {
}
private void initializeView() {
requestService.updateRequestStatuses();
configureFormFields();
configureButtons();
configureBinder();

View File

@ -57,6 +57,7 @@ public class RequestsListView extends Main {
}
private void initializeView() {
requestService.updateRequestStatuses();
setupFilters();
setupRequestGrid();
add(requestGrid);