diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index cc150c4..2fcaaf6 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -140,15 +140,30 @@ public class RequestEmployeeView extends Div implements HasUrlParameter double totalFixedAndMovableHolidays = calculateHolidayDays(vacations); double totalPersonalDays = calculatePersonalDays(vacations, isMale); - double totalVacationDays = calculateVacationDays(employee); + List vacationDays = calculateVacationDays(employee); + + double utilizedVacationCurrentDays = vacationDays.get(1); + List vacationCurrentRequests = requestService + .findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ACTUAL); + if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) { + utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance(); + } + double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays); + + double utilizedVacationPreviousDays = vacationDays.get(0); + List vacationPreviousRequests = requestService + .findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ANTERIOR); + if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) { + utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance(); + } + double totalVacationPreviousDays = vacationDays.getFirst() - (vacationDays.getFirst() - utilizedVacationPreviousDays); double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear); - double utilizedVacationDays = calculateVacationUtilizedDays(currentYear); double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear); double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence; - double remainingVacationDays = totalVacationDays - utilizedVacationDays; + double remainingVacationDays = totalVacationCurrentDays + totalVacationPreviousDays; double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays; @@ -178,7 +193,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .sum(); } - private double calculateVacationDays(final Employee employee) { + private List calculateVacationDays(final Employee employee) { + List vacationDays = new ArrayList<>(); + if (employee.getDateOfEntry() != null) { LocalDate entryDate = employee.getDateOfEntry(); LocalDate today = LocalDate.now(); @@ -214,11 +231,13 @@ public class RequestEmployeeView extends Div implements HasUrlParameter ); } - return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) - + calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); + vacationDays.add(calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate)); + vacationDays.add(calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate)); } else { - return 0.0; + vacationDays.add(0.0); + vacationDays.add(0.0); } + return vacationDays; } private double calculateHolidayUtilizedDays(final int year) { @@ -233,7 +252,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return requests.stream() .filter(req -> req.getCategory().name().startsWith("VACACION")) .filter(req -> getStartDateYear(req) == year || getStartDateYear(req) == year - 1) - .mapToDouble(TimeOffRequest::getDaysToBeTake) + .mapToDouble(TimeOffRequest::getDaysBalance) .sum(); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 564ab81..e5fa896 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -135,15 +135,15 @@ public class RequestRegisterView extends VerticalLayout { List availableCategories = allCategories.stream() .filter(category -> isCategoryAvailable(employeeRequests, category)) .filter(category -> isCategoryAllowedByGender(category, employee.getGender())) - .filter(category -> category != TimeOffRequestType.VACACION_GESTION_ANTERIOR - && category != TimeOffRequestType.TODOS) + .filter(category -> category != TimeOffRequestType.TODOS) .toList(); categoryComboBox.setItems(availableCategories); } private void onCategoryChange(final TimeOffRequestType selectedCategory) { - if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL) { + if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL + || selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) { startDatePicker.setEnabled(true); endDatePicker.setEnabled(true); } else { diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 110ddf7..25d91cd 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -164,8 +164,28 @@ public class RequestsListView extends Main { private String getGeneralTotal(final Employee employee) { List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List vacations = vacationService.findVacations(); + + List vacationDays = calculateVacationDays(employee); + + double utilizedVacationCurrentDays = vacationDays.get(1); + List vacationCurrentRequests = requestService + .findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL); + if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) { + utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance(); + } + double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays); + + double utilizedVacationPreviousDays = vacationDays.get(0); + List vacationPreviousRequests = requestService + .findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR); + if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) { + utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance(); + } + double totalVacationPreviousDays = vacationDays.getFirst() - (vacationDays.getFirst() - utilizedVacationPreviousDays); + + double totalUtilized = calculateTotalUtilized(employeeRequests); - double totalVacations = calculateVacationDays(employee); + double totalVacations = totalVacationCurrentDays + totalVacationPreviousDays; double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee); double generalTotal = totalAvailable + totalVacations - totalUtilized; @@ -196,6 +216,8 @@ public class RequestsListView extends Main { return employeeRequests.stream() .filter(Objects::nonNull) .filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD) + .filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ACTUAL) + .filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ANTERIOR) .filter(request -> request.getStartDate() != null && ( request.getStartDate().getYear() == currentYear || (request.getCategory().name().startsWith("VACACION") @@ -205,7 +227,9 @@ public class RequestsListView extends Main { .sum(); } - private double calculateVacationDays(final Employee employee) { + private List calculateVacationDays(final Employee employee) { + List vacationDays = new ArrayList<>(); + if (employee.getDateOfEntry() != null) { LocalDate entryDate = employee.getDateOfEntry(); LocalDate today = LocalDate.now(); @@ -241,11 +265,13 @@ public class RequestsListView extends Main { ); } - return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) - + calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); + vacationDays.add(calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate)); + vacationDays.add(calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate)); } else { - return 0.0; + vacationDays.add(0.0); + vacationDays.add(0.0); } + return vacationDays; } private double calculateTotalAvailable(final List vacations, final List employeeRequests,