En-desarrollo #65

Merged
alex merged 29 commits from En-desarrollo into main 2024-11-09 12:15:26 +00:00
Showing only changes of commit 4615febec3 - Show all commits

View File

@ -10,7 +10,35 @@ import jakarta.annotation.security.PermitAll;
@Route(value = "", layout = MainLayout.class) @Route(value = "", layout = MainLayout.class)
@PermitAll @PermitAll
public class MainView extends Main { public class MainView extends Main {
public MainView() {
add(new Text("Welcome to PFS Intra.")); private final TimeOffRequestService requestService;
public MainView(final TimeOffRequestService requestService) {
this.requestService = requestService;
add(new Text("Welcome"));
updateRequestStatuses();
}
private void updateRequestStatuses() {
List<TimeOffRequest> requests = requestService.findAllTimeOffRequests();
LocalDate now = LocalDate.now();
for (TimeOffRequest request : requests) {
if (request.getState() == TimeOffRequestStatus.APROBADO) {
LocalDate expirationDate = request.getExpiration();
LocalDate startDate = request.getStartDate();
LocalDate endDate = request.getEndDate();
if (now.isAfter(expirationDate)) {
request.setState(TimeOffRequestStatus.VENCIDO);
} else if (now.isAfter(endDate) && now.isBefore(expirationDate)) {
request.setState(TimeOffRequestStatus.TOMADO);
} else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) {
request.setState(TimeOffRequestStatus.EN_USO);
}
}
}
requestService.saveAll(requests);
} }
} }