En-desarrollo #65
@ -10,7 +10,35 @@ import jakarta.annotation.security.PermitAll;
|
||||
@Route(value = "", layout = MainLayout.class)
|
||||
@PermitAll
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user