diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index edb63b3..e652266 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -55,8 +55,15 @@ public class TimeOffRequestService { public void updateRequestStatuses() { List requests = findAllTimeOffRequests(); LocalDate now = LocalDate.now(); + LocalDate startOfYear = LocalDate.of(now.getYear(), 1, 1); + + requests.removeIf(request -> request.getCategory() == TimeOffRequestType.VACACION_GESTION_ANTERIOR); for (TimeOffRequest request : requests) { + if (request.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL && now.isEqual(startOfYear)) { + request.setCategory(TimeOffRequestType.VACACION_GESTION_ANTERIOR); + } + if (request.getState() == TimeOffRequestStatus.APROBADO || request.getState() == TimeOffRequestStatus.EN_USO) { LocalDate startDate = request.getStartDate(); @@ -64,11 +71,12 @@ public class TimeOffRequestService { if (now.isAfter(endDate)) { 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); } } } + saveAll(requests); } } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 2424f65..cc150c4 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -131,6 +131,13 @@ public class RequestEmployeeView extends Div implements HasUrlParameter List vacations = vacationService.findVacations(); + double healthLicence = 2; + List healthRequests = requestService + .findByEmployeeAndCategory(employeeId, TimeOffRequestType.PERMISOS_DE_SALUD); + if (healthRequests != null && !healthRequests.isEmpty()) { + healthLicence = healthRequests.getLast().getDaysBalance(); + } + double totalFixedAndMovableHolidays = calculateHolidayDays(vacations); double totalPersonalDays = calculatePersonalDays(vacations, isMale); double totalVacationDays = calculateVacationDays(employee); @@ -140,7 +147,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear); double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; - double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays; + double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence; double remainingVacationDays = totalVacationDays - utilizedVacationDays; double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays; @@ -166,6 +173,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !req.getCategory().name().startsWith("VACACION")) + .filter(req -> req.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD) .mapToDouble(Vacation::getDuration) .sum(); } @@ -235,6 +243,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !req.getCategory().name().startsWith("VACACION")) + .filter(req -> req.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD) .filter(req -> getStartDateYear(req) == year) .mapToDouble(TimeOffRequest::getDaysToBeTake) .sum(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 2f34ba3..564ab81 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -166,13 +166,20 @@ public class RequestRegisterView extends VerticalLayout { .max(Comparator.comparing(TimeOffRequest::getStartDate)) .orElse(null); - if (category == TimeOffRequestType.PERMISOS_DE_SALUD + boolean isSpecialCategory = category == TimeOffRequestType.PERMISOS_DE_SALUD || category == TimeOffRequestType.VACACION_GESTION_ACTUAL - || category == TimeOffRequestType.VACACION_GESTION_ANTERIOR) { - return latestRequest.getState() == TimeOffRequestStatus.VENCIDO - || (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0); + || category == TimeOffRequestType.VACACION_GESTION_ANTERIOR; + + if (isSpecialCategory) { + return (latestRequest.getState() == TimeOffRequestStatus.TOMADO + && latestRequest.getDaysBalance() > 0) + || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO + || (latestRequest.getState() == TimeOffRequestStatus.TOMADO + && latestRequest.getDaysBalance() == 0 + && latestRequest.getExpiration().isBefore(LocalDate.now())); } else { - return latestRequest.getState() == TimeOffRequestStatus.VENCIDO + return (latestRequest.getState() == TimeOffRequestStatus.TOMADO + && latestRequest.getExpiration().isBefore(LocalDate.now())) || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO; } } @@ -199,30 +206,40 @@ public class RequestRegisterView extends VerticalLayout { vacation = vacationService.findVacationByCategory(selectedCategory); UUID employeeId = employeeComboBox.getValue().getId(); List requests = requestService.findByEmployeeAndCategory(employeeId, selectedCategory); + if (vacation != null) { TimeOffRequest requestWithBalance = requests.stream() .filter(request -> request.getDaysBalance() > 0 - && request.getState() != TimeOffRequestStatus.VENCIDO) + && request.getState() != TimeOffRequestStatus.VENCIDO + && request.getState() != TimeOffRequestStatus.RECHAZADO) .max(Comparator.comparing(TimeOffRequest::getStartDate)) .orElse(null); + if (requestWithBalance != null) { - if (requestWithBalance.getState() == TimeOffRequestStatus.TOMADO) { + if (requestWithBalance.getState() == TimeOffRequestStatus.TOMADO + && requestWithBalance.getDaysBalance() > 0) { availableDaysField.setValue(requestWithBalance.getDaysBalance()); - } else if (requestWithBalance.getState() == TimeOffRequestStatus.VENCIDO) { + } else { availableDaysField.setValue(vacation.getDuration()); } - } else if (vacation.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) { + } else if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL + || selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) { LocalDate dateOfEntry = employeeComboBox.getValue().getDateOfEntry(); LocalDate currentDate = LocalDate.now(); long yearsOfService = ChronoUnit.YEARS.between(dateOfEntry, currentDate); + + if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) { + yearsOfService -= 1; + } + if (yearsOfService > 10) { - availableDaysField.setValue((double) 30); + availableDaysField.setValue(30.0); } else if (yearsOfService > 5) { - availableDaysField.setValue((double) 20); + availableDaysField.setValue(20.0); } else if (yearsOfService > 1) { - availableDaysField.setValue((double) 15); + availableDaysField.setValue(15.0); } else { - availableDaysField.setValue((double) 0); + availableDaysField.setValue(0.0); } } else { availableDaysField.setValue(vacation.getDuration()); @@ -257,20 +274,6 @@ public class RequestRegisterView extends VerticalLayout { startDate = LocalDate.now(); } - System.out.println(vacation); - System.out.println(vacation); - System.out.println(vacation); - System.out.println(vacation); - System.out.println(vacation); - System.out.println(vacation); - - System.out.println(startDate); - System.out.println(startDate); - System.out.println(startDate); - System.out.println(startDate); - System.out.println(startDate); - System.out.println(startDate); - setPickerValues(vacation, startDate); setPickerLimits(startDate, endDate); } @@ -447,15 +450,10 @@ public class RequestRegisterView extends VerticalLayout { List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); - int maxRequests; - - if (request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { - maxRequests = 4; - } else if (request.getCategory().name().startsWith("VACACION")) { - maxRequests = 2; - } else { - maxRequests = 1; - } + int maxRequests = request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD + && !request.getCategory().name().startsWith("VACACION") + && request.getCategory() != TimeOffRequestType.CUMPLEAÑOS + ? 2 : 1; if (existingRequests.size() >= maxRequests) { existingRequests.stream() diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 41639bf..110ddf7 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -195,6 +195,7 @@ public class RequestsListView extends Main { int currentYear = LocalDate.now().getYear(); return employeeRequests.stream() .filter(Objects::nonNull) + .filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD) .filter(request -> request.getStartDate() != null && ( request.getStartDate().getYear() == currentYear || (request.getCategory().name().startsWith("VACACION") @@ -255,8 +256,16 @@ public class RequestsListView extends Main { .map(TimeOffRequest::getCategory) .collect(Collectors.toSet()); - return vacations.stream() + double healthLicence = 2; + List healthRequests = requestService + .findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.PERMISOS_DE_SALUD); + if (healthRequests != null && !healthRequests.isEmpty()) { + healthLicence = healthRequests.getLast().getDaysBalance(); + } + + double totalAvailable = vacations.stream() .filter(Objects::nonNull) + .filter(vacation -> vacation.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD) .filter(vacation -> shouldIncludeVacation( vacation, excludedCategories, @@ -265,6 +274,8 @@ public class RequestsListView extends Main { )) .mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0) .sum(); + + return totalAvailable + healthLicence; } private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {