En-desarrollo #71
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -52,6 +52,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
}
|
||||
|
||||
private void initializeView() {
|
||||
requestService.updateRequestStatuses();
|
||||
setupFilters();
|
||||
setupGrid();
|
||||
add(requestGrid, createActionButtons(), createSummaryLayout());
|
||||
|
@ -63,6 +63,7 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
}
|
||||
|
||||
private void initializeView() {
|
||||
requestService.updateRequestStatuses();
|
||||
configureFormFields();
|
||||
configureButtons();
|
||||
configureBinder();
|
||||
|
@ -57,6 +57,7 @@ public class RequestsListView extends Main {
|
||||
}
|
||||
|
||||
private void initializeView() {
|
||||
requestService.updateRequestStatuses();
|
||||
setupFilters();
|
||||
setupRequestGrid();
|
||||
add(requestGrid);
|
||||
|
Loading…
Reference in New Issue
Block a user