En-desarrollo #71

Merged
alex merged 10 commits from En-desarrollo into main 2024-11-15 00:24:15 +00:00
5 changed files with 6 additions and 10 deletions
Showing only changes of commit ca5fb122fb - Show all commits

View File

@ -4,7 +4,6 @@ import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme; import com.vaadin.flow.theme.Theme;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
/** /**
* The entry point of the Spring Boot application. * 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.model.*;
import com.primefactorsolutions.repositories.TimeOffRequestRepository; import com.primefactorsolutions.repositories.TimeOffRequestRepository;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
@ -53,27 +52,22 @@ public class TimeOffRequestService {
return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category); return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category);
} }
@Scheduled(cron = "0 0 0 * * ?") public void updateRequestStatuses() {
private void updateRequestStatuses() {
List<TimeOffRequest> requests = findAllTimeOffRequests(); List<TimeOffRequest> requests = findAllTimeOffRequests();
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
for (TimeOffRequest request : requests) { for (TimeOffRequest request : requests) {
if (request.getState() != TimeOffRequestStatus.RECHAZADO) { if (request.getState() == TimeOffRequestStatus.APROBADO) {
LocalDate expirationDate = request.getExpiration();
LocalDate startDate = request.getStartDate(); LocalDate startDate = request.getStartDate();
LocalDate endDate = request.getEndDate(); LocalDate endDate = request.getEndDate();
if (now.isAfter(expirationDate)) { if (now.isAfter(endDate)) {
request.setState(TimeOffRequestStatus.VENCIDO);
} else if (now.isAfter(endDate) && now.isBefore(expirationDate)) {
request.setState(TimeOffRequestStatus.TOMADO); request.setState(TimeOffRequestStatus.TOMADO);
} else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) { } else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) {
request.setState(TimeOffRequestStatus.EN_USO); request.setState(TimeOffRequestStatus.EN_USO);
} }
} }
} }
saveAll(requests); saveAll(requests);
} }
} }

View File

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

View File

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

View File

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