From 51a1d22be92ea237047fecd6592f3ea872ecdb91 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 12 Nov 2024 21:54:28 -0400 Subject: [PATCH 01/10] Lista de Solicitudes de empleado - Calcular total disponibilidad de dias --- .../model/TimeOffRequestStatus.java | 7 +- .../service/TimeOffRequestService.java | 26 +++++++ .../primefactorsolutions/views/MainView.java | 32 --------- .../views/RequestEmployeeView.java | 39 +++++++++-- .../views/RequestRegisterView.java | 67 +++++++++++++++---- src/main/resources/data.sql | 2 +- 6 files changed, 117 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java b/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java index ac6f552..6f0a2d0 100644 --- a/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java +++ b/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java @@ -3,13 +3,14 @@ package com.primefactorsolutions.model; public enum TimeOffRequestStatus { TODOS, TOMADO, - SOLICITADO, APROBADO, EN_USO, - EN_REVISION, PENDIENTE, RECHAZADO, + VENCIDO, + + SOLICITADO, + EN_REVISION, COMPLETADO, CANCELADO, - VENCIDO } diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index 65651a8..f2302bc 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -3,8 +3,10 @@ package com.primefactorsolutions.service; import com.primefactorsolutions.model.*; import com.primefactorsolutions.repositories.TimeOffRequestRepository; import lombok.AllArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.time.LocalDate; import java.util.List; import java.util.UUID; import java.util.Optional; @@ -50,4 +52,28 @@ public class TimeOffRequestService { public List findByEmployeeAndCategory(final UUID employeeId, final TimeOffRequestType category) { return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category); } + + @Scheduled(cron = "0 0 0 * * ?") + private void updateRequestStatuses() { + List requests = findAllTimeOffRequests(); + LocalDate now = LocalDate.now(); + + for (TimeOffRequest request : requests) { + if (request.getState() != TimeOffRequestStatus.RECHAZADO) { + 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); + } + } + } + + saveAll(requests); + } } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/MainView.java b/src/main/java/com/primefactorsolutions/views/MainView.java index bc3239d..7dc4aba 100644 --- a/src/main/java/com/primefactorsolutions/views/MainView.java +++ b/src/main/java/com/primefactorsolutions/views/MainView.java @@ -1,7 +1,5 @@ package com.primefactorsolutions.views; -import com.primefactorsolutions.model.TimeOffRequest; -import com.primefactorsolutions.model.TimeOffRequestStatus; import com.primefactorsolutions.service.TimeOffRequestService; import com.vaadin.flow.component.Text; import com.vaadin.flow.component.html.Main; @@ -9,42 +7,12 @@ import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import jakarta.annotation.security.PermitAll; -import java.time.LocalDate; -import java.util.List; - @PageTitle("Home") @Route(value = "", layout = MainLayout.class) @PermitAll public class MainView extends Main { - private final TimeOffRequestService requestService; - public MainView(final TimeOffRequestService requestService) { - this.requestService = requestService; add(new Text("Welcome")); - updateRequestStatuses(); - } - - private void updateRequestStatuses() { - List 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); } } diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 50445d4..ea74641 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -107,24 +107,49 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private VerticalLayout createSummaryLayout() { - double totalHoliday = requests.stream() + List vacations = vacationService.findVacations(); + + double holiday = vacations.stream() + .filter(req -> req.getType() != Vacation.Type.OTHER) + .mapToDouble(Vacation::getDuration) + .sum(); + + double personalDays = vacations.stream() + .filter(req -> req.getType() == Vacation.Type.OTHER) + .filter(req -> !req.getCategory().name().startsWith("VACACION")) + + .mapToDouble(Vacation::getDuration) + .sum(); + + double vacation = calculateVacationDays(employeeService.getEmployee(employeeId)); + + double holidayUtilized = requests.stream() .filter(this::verificationIsHoliday) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); - double totalVacations = calculateVacationDays(employeeService.getEmployee(employeeId)); - double totalPersonalDays = requests.stream() + + double vacationUtilized = requests.stream() + .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) + .mapToDouble(TimeOffRequest::getAvailableDays) + .sum(); + + double personalDaysUtilized = requests.stream() .filter(req -> !verificationIsHoliday(req)) .filter(req -> !req.getCategory().name().startsWith("VACACION")) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); + double totalHoliday = holiday - holidayUtilized; + double totalPersonalDays = personalDays - personalDaysUtilized; + double totalVacations = vacation - vacationUtilized; + double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; return new VerticalLayout( - new Span("Total feriados: " + totalHoliday), - new Span("Total vacaciones: " + totalVacations), - new Span("Total días personales: " + totalPersonalDays), - new Span("Total general: " + totalAvailableDays) + new Span("Total feriados fijos y movibles: " + totalHoliday), + new Span("Total días libres personales: " + totalPersonalDays), + new Span("Total vacaciones pendientes de uso: " + totalVacations), + new Span("Total general de días disponibles: " + totalAvailableDays) ); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index ac733ed..d5d677a 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -84,8 +84,6 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); employeeComboBox.addValueChangeListener(event -> { employee = event.getValue(); - System.out.println("Clearing form..." + employee); - handleEmployeeSelection(event.getValue()); }); categoryComboBox.addValueChangeListener(event -> { @@ -173,7 +171,7 @@ public class RequestRegisterView extends VerticalLayout { return latestRequest.getState() == TimeOffRequestStatus.VENCIDO || (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0); } else { - return latestRequest.getState() == TimeOffRequestStatus.VENCIDO; + return latestRequest.getState() == TimeOffRequestStatus.VENCIDO || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO; } } @@ -248,11 +246,29 @@ public class RequestRegisterView extends VerticalLayout { } if (startDate != null) { - endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + if (vacation.getExpiration() != null) { + endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + } else { + endDate = LocalDate.of(startDate.getYear(), 12, 31); + } } else { 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); } @@ -267,19 +283,23 @@ public class RequestRegisterView extends VerticalLayout { .map(request -> request.getStartDate().getYear()) .orElse(LocalDate.now().getYear()); + if (previousRequests.getLast().getState() != TimeOffRequestStatus.RECHAZADO) { + lastRequestYear = lastRequestYear + 1; + } + int currentYear = LocalDate.now().getYear(); - return Math.max(lastRequestYear + 1, currentYear); + return Math.max(lastRequestYear, currentYear); } private LocalDate determineStartDate(final Vacation vacation, final int startYear) { - if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) { - return LocalDate.of(startYear, vacation.getMonthOfYear().intValue(), vacation.getDayOfMonth().intValue()); - } - if (vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() != null) { return LocalDate.of(startYear, employee.getBirthday().getMonth(), employee.getBirthday().getDayOfMonth()); } + if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) { + return LocalDate.of(startYear, vacation.getMonthOfYear().intValue(), vacation.getDayOfMonth().intValue()); + } + if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { return LocalDate.now(); } @@ -290,8 +310,24 @@ public class RequestRegisterView extends VerticalLayout { private void setPickerValues(final Vacation vacation, final LocalDate startDate) { startDatePicker.setValue(startDate); + 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); + if ((vacation.getDuration() != null && vacation.getDuration() == 0.5) - || vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { + || vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD + || vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS) { + endDatePicker.setValue(startDate); } else { int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0); @@ -330,7 +366,7 @@ public class RequestRegisterView extends VerticalLayout { double balanceDays = calculateBalanceDays(availableDays, daysToBeTakenField.getValue()); balanceDaysField.setValue(balanceDays); - if (balanceDays < 0) { + if (balanceDays < 0.0) { clearFields(); } } @@ -345,7 +381,12 @@ public class RequestRegisterView extends VerticalLayout { } private void setDaysToBeTakenField(final double daysToBeTaken) { - if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { + if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD + || vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS + || vacation.getCategory() == TimeOffRequestType.DIA_DEL_PADRE + || vacation.getCategory() == TimeOffRequestType.DIA_DE_LA_MADRE + || vacation.getCategory() == TimeOffRequestType.DIA_DE_LA_MUJER_INTERNACIONAL + || vacation.getCategory() == TimeOffRequestType.DIA_DE_LA_MUJER_NACIONAL) { daysToBeTakenField.setValue(0.5); } else { daysToBeTakenField.setValue(daysToBeTaken); @@ -418,7 +459,7 @@ public class RequestRegisterView extends VerticalLayout { List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); - int maxRequests = request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD ? 4 : 2; + int maxRequests = request.getCategory().name().startsWith("VACACION") ? 2 : 1; if (existingRequests.size() >= maxRequests) { existingRequests.stream() diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 5833a0e..f93ac0a 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -32,7 +32,7 @@ INSERT INTO vacation (id, version, category, month_of_year, day_of_month, durati INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400b', 1, 'DIA_DE_TODOS_LOS_DIFUNTOS', 11, 2, 1, 30, 'MOVABLE'); -INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400c', 1, 'CUMPLEAÑOS', 0.5, 365, 'OTHER'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400c', 1, 'CUMPLEAÑOS', 12, 31, 0.5, 'OTHER'); INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400d', 1, 'MATERNIDAD', 90, 90, 'OTHER'); INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400e', 1, 'PATERNIDAD', 3, 3, 'OTHER'); INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400f', 1, 'MATRIMONIO', 3, 3, 'OTHER'); -- 2.34.1 From 6d60fd00cce8366dcfd640a823ea697c483134b7 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 12:38:25 -0400 Subject: [PATCH 02/10] Lista de Solicitudes de empleado - Refactorizar --- .../views/RequestEmployeeView.java | 113 ++++++++++++------ .../views/RequestRegisterView.java | 3 +- 2 files changed, 78 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index ea74641..055bced 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -23,9 +23,7 @@ import org.vaadin.firitin.components.grid.PagingGrid; import java.time.LocalDate; import java.time.Period; -import java.util.Collections; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; @SpringComponent @@ -106,51 +104,68 @@ public class RequestEmployeeView extends Div implements HasUrlParameter }); } + private Set getStandardExclusions() { + return Set.of( + TimeOffRequestType.MATERNIDAD, + TimeOffRequestType.PATERNIDAD, + TimeOffRequestType.MATRIMONIO, + TimeOffRequestType.DUELO_1ER_GRADO, + TimeOffRequestType.DUELO_2ER_GRADO, + TimeOffRequestType.DIA_DEL_PADRE, + TimeOffRequestType.DIA_DE_LA_MADRE + ); + } + + private Set getMaleSpecificExclusions() { + return Set.of( + TimeOffRequestType.DIA_DE_LA_MUJER_INTERNACIONAL, + TimeOffRequestType.DIA_DE_LA_MUJER_NACIONAL + ); + } + private VerticalLayout createSummaryLayout() { + Employee employee = employeeService.getEmployee(employeeId); + boolean isMale = employee.getGender() == Employee.Gender.MALE; + List vacations = vacationService.findVacations(); - double holiday = vacations.stream() + double totalFixedAndMovableHolidays = calculateHolidayDays(vacations); + double totalPersonalDays = calculatePersonalDays(vacations, isMale); + double totalVacationDays = calculateVacationDays(employee); + + double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(); + double utilizedVacationDays = calculateVacationUtilizedDays(); + double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale); + + double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; + double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays; + double remainingVacationDays = totalVacationDays - utilizedVacationDays; + + double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays; + + return new VerticalLayout( + new Span("Total feriados fijos y movibles: " + remainingHolidayDays), + new Span("Total días libres personales: " + remainingPersonalDays), + new Span("Total vacaciones pendientes de uso: " + remainingVacationDays), + new Span("Total general de días disponibles: " + totalAvailableDays) + ); + } + + private double calculateHolidayDays(final List vacations) { + return vacations.stream() .filter(req -> req.getType() != Vacation.Type.OTHER) .mapToDouble(Vacation::getDuration) .sum(); + } - double personalDays = vacations.stream() + private double calculatePersonalDays(final List vacations, final boolean isMale) { + return vacations.stream() .filter(req -> req.getType() == Vacation.Type.OTHER) + .filter(req -> !getStandardExclusions().contains(req.getCategory())) + .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !req.getCategory().name().startsWith("VACACION")) - .mapToDouble(Vacation::getDuration) .sum(); - - double vacation = calculateVacationDays(employeeService.getEmployee(employeeId)); - - double holidayUtilized = requests.stream() - .filter(this::verificationIsHoliday) - .mapToDouble(TimeOffRequest::getAvailableDays) - .sum(); - - double vacationUtilized = requests.stream() - .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) - .mapToDouble(TimeOffRequest::getAvailableDays) - .sum(); - - double personalDaysUtilized = requests.stream() - .filter(req -> !verificationIsHoliday(req)) - .filter(req -> !req.getCategory().name().startsWith("VACACION")) - .mapToDouble(TimeOffRequest::getAvailableDays) - .sum(); - - double totalHoliday = holiday - holidayUtilized; - double totalPersonalDays = personalDays - personalDaysUtilized; - double totalVacations = vacation - vacationUtilized; - - double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; - - return new VerticalLayout( - new Span("Total feriados fijos y movibles: " + totalHoliday), - new Span("Total días libres personales: " + totalPersonalDays), - new Span("Total vacaciones pendientes de uso: " + totalVacations), - new Span("Total general de días disponibles: " + totalAvailableDays) - ); } private double calculateVacationDays(final Employee employee) { @@ -196,6 +211,30 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } } + private double calculateHolidayUtilizedDays() { + return requests.stream() + .filter(this::verificationIsHoliday) + .mapToDouble(TimeOffRequest::getAvailableDays) + .sum(); + } + + private double calculateVacationUtilizedDays() { + return requests.stream() + .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) + .mapToDouble(TimeOffRequest::getAvailableDays) + .sum(); + } + + private double calculatePersonalDaysUtilized(final boolean isMale) { + return requests.stream() + .filter(req -> !verificationIsHoliday(req)) + .filter(req -> !getStandardExclusions().contains(req.getCategory())) + .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) + .filter(req -> !req.getCategory().name().startsWith("VACACION")) + .mapToDouble(TimeOffRequest::getAvailableDays) + .sum(); + } + private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) { int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0; if (yearsOfService > 10) { diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index d5d677a..864b9e5 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -171,7 +171,8 @@ public class RequestRegisterView extends VerticalLayout { return latestRequest.getState() == TimeOffRequestStatus.VENCIDO || (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0); } else { - return latestRequest.getState() == TimeOffRequestStatus.VENCIDO || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO; + return latestRequest.getState() == TimeOffRequestStatus.VENCIDO + || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO; } } -- 2.34.1 From ca5fb122fb375eb8dc9e8e3a825a731c2ac07eb4 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 14:10:09 -0400 Subject: [PATCH 03/10] Lista de Solicitudes de empleado - Actualizar estado --- .../java/com/primefactorsolutions/Application.java | 1 - .../service/TimeOffRequestService.java | 12 +++--------- .../views/RequestEmployeeView.java | 1 + .../views/RequestRegisterView.java | 1 + .../primefactorsolutions/views/RequestsListView.java | 1 + 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/Application.java b/src/main/java/com/primefactorsolutions/Application.java index 298fd56..e66d089 100644 --- a/src/main/java/com/primefactorsolutions/Application.java +++ b/src/main/java/com/primefactorsolutions/Application.java @@ -4,7 +4,6 @@ import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.theme.Theme; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; - /** * The entry point of the Spring Boot application. * diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index f2302bc..447911c 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -3,7 +3,6 @@ package com.primefactorsolutions.service; import com.primefactorsolutions.model.*; import com.primefactorsolutions.repositories.TimeOffRequestRepository; import lombok.AllArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.time.LocalDate; @@ -53,27 +52,22 @@ public class TimeOffRequestService { return timeOffRequestRepository.findByEmployeeIdAndCategory(employeeId, category); } - @Scheduled(cron = "0 0 0 * * ?") - private void updateRequestStatuses() { + public void updateRequestStatuses() { List requests = findAllTimeOffRequests(); LocalDate now = LocalDate.now(); for (TimeOffRequest request : requests) { - if (request.getState() != TimeOffRequestStatus.RECHAZADO) { - LocalDate expirationDate = request.getExpiration(); + if (request.getState() == TimeOffRequestStatus.APROBADO) { LocalDate startDate = request.getStartDate(); LocalDate endDate = request.getEndDate(); - if (now.isAfter(expirationDate)) { - request.setState(TimeOffRequestStatus.VENCIDO); - } else if (now.isAfter(endDate) && now.isBefore(expirationDate)) { + if (now.isAfter(endDate)) { request.setState(TimeOffRequestStatus.TOMADO); } 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 055bced..50323c7 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -52,6 +52,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private void initializeView() { + requestService.updateRequestStatuses(); setupFilters(); setupGrid(); add(requestGrid, createActionButtons(), createSummaryLayout()); diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 864b9e5..9cedaa3 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -63,6 +63,7 @@ public class RequestRegisterView extends VerticalLayout { } private void initializeView() { + requestService.updateRequestStatuses(); configureFormFields(); configureButtons(); configureBinder(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 73c2cbf..5da8183 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -57,6 +57,7 @@ public class RequestsListView extends Main { } private void initializeView() { + requestService.updateRequestStatuses(); setupFilters(); setupRequestGrid(); add(requestGrid); -- 2.34.1 From efca245c1db45de90f09643f3beb685b6d365ca3 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 14:47:28 -0400 Subject: [PATCH 04/10] Corregir datos de prueba --- src/main/resources/data.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index f93ac0a..002da7d 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -68,13 +68,13 @@ insert into employee (id, version, username, first_name, last_name, status, team insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9d6f12ba-e341-4e7a-b8a6-cab0982bd8c1', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'PATERNIDAD', 'VENCIDO', 3, '2024-10-03', '2024-10-01', '2024-10-03', 3, 0); +values ('9d6f12ba-e341-4e7a-b8a6-cab0982bd8c1', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'PATERNIDAD', 'APROBADO', 3, '2024-10-03', '2024-10-01', '2024-10-03', 3, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9a6f12ba-e111-4e7a-b8a6-caa0982bd8a1', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'AÑO_NUEVO', 'VENCIDO', 1, '2024-01-01', '2024-01-01', '2024-01-01', 1, 0); +values ('9a6f12ba-e111-4e7a-b8a6-caa0982bd8a1', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'AÑO_NUEVO', 'APROBADO', 1, '2024-01-01', '2024-01-01', '2024-01-01', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('9b6f12ba-e222-4e7a-b8a6-caa0982bd8b2', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'LUNES_CARNAVAL', 'APROBADO', 1, '2025-02-12', '2025-02-12', '2025-02-12', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'MARTES_CARNAVAL', 'EN_REVISION', 1, '2025-02-13', '2025-02-13', '2025-02-13', 1, 0); +values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'MARTES_CARNAVAL', 'PENDIENTE', 1, '2025-02-13', '2025-02-13', '2025-02-13', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('9d6f12ba-e444-4e7a-b8a6-caa0982bd8d4', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VIERNES_SANTO', 'APROBADO', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -- 2.34.1 From 9579b33acc9a3a002707bab839d98e1d9d283dda Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 18:34:42 -0400 Subject: [PATCH 05/10] Lista de Solicitudes de empleado - Actualizar resumen de empleado --- .../views/PendingRequestsListView.java | 2 +- .../views/RequestEmployeeView.java | 79 +++++++++++++++++-- .../views/RequestRegisterView.java | 18 +---- src/main/resources/data.sql | 6 +- 4 files changed, 78 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java index 1ef9f4e..db9b783 100644 --- a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java @@ -113,7 +113,7 @@ public class PendingRequestsListView extends Main { final Team team, final TimeOffRequestType category) { List filteredPendingRequests - = requestService.findRequestsByState(TimeOffRequestStatus.PENDIENTE); + = requestService.findRequestsByState(TimeOffRequestStatus.SOLICITADO); if (employee != null && !"TODOS".equals(employee.getFirstName())) { filteredPendingRequests = filteredPendingRequests.stream() diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 50323c7..b449f16 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -127,6 +127,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter private VerticalLayout createSummaryLayout() { Employee employee = employeeService.getEmployee(employeeId); boolean isMale = employee.getGender() == Employee.Gender.MALE; + int currentYear = LocalDate.now().getYear(); List vacations = vacationService.findVacations(); @@ -134,9 +135,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter double totalPersonalDays = calculatePersonalDays(vacations, isMale); double totalVacationDays = calculateVacationDays(employee); - double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(); - double utilizedVacationDays = calculateVacationUtilizedDays(); - double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale); + double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear); + double utilizedVacationDays = calculateVacationUtilizedDays(currentYear); + double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear); double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays; @@ -148,7 +149,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter new Span("Total feriados fijos y movibles: " + remainingHolidayDays), new Span("Total días libres personales: " + remainingPersonalDays), new Span("Total vacaciones pendientes de uso: " + remainingVacationDays), - new Span("Total general de días disponibles: " + totalAvailableDays) + new Span("TOTAL GENERAL DE DÍAS DISPONIBLES: " + totalAvailableDays) ); } @@ -212,30 +213,40 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } } - private double calculateHolidayUtilizedDays() { + private double calculateHolidayUtilizedDays(final int year) { return requests.stream() .filter(this::verificationIsHoliday) + .filter(req -> getStartDateYear(req) == year) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); } - private double calculateVacationUtilizedDays() { + private double calculateVacationUtilizedDays(final int year) { return requests.stream() .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) + .filter(req -> getStartDateYear(req) == year) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); } - private double calculatePersonalDaysUtilized(final boolean isMale) { + private double calculatePersonalDaysUtilized(final boolean isMale, final int year) { return requests.stream() .filter(req -> !verificationIsHoliday(req)) .filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !req.getCategory().name().startsWith("VACACION")) + .filter(req -> getStartDateYear(req) == year) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); } + private int getStartDateYear(TimeOffRequest request) { + if (request.getStartDate() != null) { + return request.getStartDate().getYear(); + } + return 0; + } + private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) { int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0; if (yearsOfService > 10) { @@ -301,7 +312,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter final int pageSize, final TimeOffRequestType category, final TimeOffRequestStatus state) { + requests = requestService.findRequestsByEmployeeId(employeeId); + generateRequests(); if (category != null && !"TODOS".equals(category.name())) { requests = requests.stream() .filter(req -> req.getCategory().equals(category)) @@ -316,6 +329,58 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return requests.subList(start, end); } + public void generateRequests() { + boolean isMale = isEmployeeMale(); + + for (TimeOffRequestType type : TimeOffRequestType.values()) { + if (shouldIncludeRequest(type) && isValidRequestType(type, isMale)) { + TimeOffRequest request = createRequest(type); + if (isVacationExpired(request)) { + request.setState(TimeOffRequestStatus.VENCIDO); + } else { + request.setState(TimeOffRequestStatus.PENDIENTE); + } + requests.add(request); + } + } + } + + private boolean isEmployeeMale() { + return employeeService.getEmployee(employeeId).getGender() == Employee.Gender.MALE; + } + + private boolean isValidRequestType(TimeOffRequestType type, boolean isMale) { + return !getStandardExclusions().contains(type) + && !(isMale && getMaleSpecificExclusions().contains(type)) + && type != TimeOffRequestType.TODOS; + } + + private TimeOffRequest createRequest(TimeOffRequestType type) { + TimeOffRequest request = new TimeOffRequest(); + request.setCategory(type); + return request; + } + + private boolean isVacationExpired(TimeOffRequest request) { + Vacation vacation = vacationService.findVacationByCategory(request.getCategory()); + + if (vacation != null && vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) { + int vacationMonth = vacation.getMonthOfYear(); + int vacationDay = vacation.getDayOfMonth(); + int currentMonth = LocalDate.now().getMonthValue(); + int currentDay = LocalDate.now().getDayOfMonth(); + + return vacationMonth < currentMonth || (vacationMonth == currentMonth && vacationDay < currentDay); + } + + return false; + } + + private boolean shouldIncludeRequest(TimeOffRequestType type) { + List existingRequest = requestService.findByEmployeeAndCategory(employeeId, type); + return existingRequest.isEmpty(); + } + @Override public void setParameter(final BeforeEvent event, final String parameter) { employeeId = UUID.fromString(parameter); diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 9cedaa3..cf5c09c 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -310,21 +310,7 @@ public class RequestRegisterView extends VerticalLayout { } private void setPickerValues(final Vacation vacation, final LocalDate startDate) { - startDatePicker.setValue(startDate); - - 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); + startDatePicker.setValue(startDate) if ((vacation.getDuration() != null && vacation.getDuration() == 0.5) || vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD @@ -453,7 +439,7 @@ public class RequestRegisterView extends VerticalLayout { request.setStartDate(startDatePicker.getValue()); request.setAvailableDays(availableDaysField.getValue()); request.setExpiration(endDate != null ? endDate : endDatePicker.getValue()); - request.setState(TimeOffRequestStatus.PENDIENTE); + request.setState(TimeOffRequestStatus.SOLICITADO); return request; } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 002da7d..aec0cdb 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -74,7 +74,7 @@ values ('9a6f12ba-e111-4e7a-b8a6-caa0982bd8a1', 1, '5c6f11fe-c341-4be7-a9a6-bba0 insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('9b6f12ba-e222-4e7a-b8a6-caa0982bd8b2', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'LUNES_CARNAVAL', 'APROBADO', 1, '2025-02-12', '2025-02-12', '2025-02-12', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'MARTES_CARNAVAL', 'PENDIENTE', 1, '2025-02-13', '2025-02-13', '2025-02-13', 1, 0); +values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'MARTES_CARNAVAL', 'SOLICITADO', 1, '2025-02-13', '2025-02-13', '2025-02-13', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('9d6f12ba-e444-4e7a-b8a6-caa0982bd8d4', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VIERNES_SANTO', 'APROBADO', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) @@ -85,8 +85,8 @@ values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37 insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('fb9d9d75-b2ab-4ea4-b8b3-0a8f89e5c123', 1, '2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 'DIA_DE_LA_INDEPENDENCIA', 'APROBADO', 1, '2024-08-06', '2024-08-06', '2024-08-06', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('6fdc47a8-127b-41c4-8d12-7fc12098ab12', 1, 'b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 'DIA_DE_TODOS_LOS_DIFUNTOS', 'PENDIENTE', 1, '2025-12-01', '2025-11-02', '2025-11-02', 1, 0); +values ('6fdc47a8-127b-41c4-8d12-7fc12098ab12', 1, 'b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 'DIA_DE_TODOS_LOS_DIFUNTOS', 'SOLICITADO', 1, '2025-12-01', '2025-11-02', '2025-11-02', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b77b91b6a8', 'AÑO_NUEVO', 'PENDIENTE', 1, '2025-01-01', '2025-01-01', '2025-01-01', 1, 0); +values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b77b91b6a8', 'AÑO_NUEVO', 'SOLICITADO', 1, '2025-01-01', '2025-01-01', '2025-01-01', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('89bc4b2a-943f-487c-a9f3-bacf78145e67', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'LUNES_CARNAVAL', 'APROBADO', 1, '2024-02-12', '2024-02-12', '2024-02-12', 1, 0); -- 2.34.1 From 8e1f0fdd7d13da3038b04a8cebd284ec10c0fc4e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 19:54:36 -0400 Subject: [PATCH 06/10] Lista de Solicitudes de empleado - actualizar solicitudes permisos de salud --- .../service/TimeOffRequestService.java | 3 ++- .../views/RequestEmployeeView.java | 10 +++++----- .../views/RequestRegisterView.java | 12 ++++++++++-- .../primefactorsolutions/views/RequestsListView.java | 5 +++++ src/main/resources/data.sql | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index 447911c..edb63b3 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -57,7 +57,8 @@ public class TimeOffRequestService { LocalDate now = LocalDate.now(); for (TimeOffRequest request : requests) { - if (request.getState() == TimeOffRequestStatus.APROBADO) { + if (request.getState() == TimeOffRequestStatus.APROBADO + || request.getState() == TimeOffRequestStatus.EN_USO) { LocalDate startDate = request.getStartDate(); LocalDate endDate = request.getEndDate(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index b449f16..c404769 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -217,15 +217,15 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return requests.stream() .filter(this::verificationIsHoliday) .filter(req -> getStartDateYear(req) == year) - .mapToDouble(TimeOffRequest::getAvailableDays) + .mapToDouble(TimeOffRequest::getDaysToBeTake) .sum(); } private double calculateVacationUtilizedDays(final int year) { return requests.stream() - .filter(req -> req.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) - .filter(req -> getStartDateYear(req) == year) - .mapToDouble(TimeOffRequest::getAvailableDays) + .filter(req -> req.getCategory().name().startsWith("VACACION")) + .filter(req -> getStartDateYear(req) == year || getStartDateYear(req) == year - 1) + .mapToDouble(TimeOffRequest::getDaysToBeTake) .sum(); } @@ -236,7 +236,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !req.getCategory().name().startsWith("VACACION")) .filter(req -> getStartDateYear(req) == year) - .mapToDouble(TimeOffRequest::getAvailableDays) + .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 cf5c09c..2f34ba3 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -310,7 +310,7 @@ public class RequestRegisterView extends VerticalLayout { } private void setPickerValues(final Vacation vacation, final LocalDate startDate) { - startDatePicker.setValue(startDate) + startDatePicker.setValue(startDate); if ((vacation.getDuration() != null && vacation.getDuration() == 0.5) || vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD @@ -447,7 +447,15 @@ public class RequestRegisterView extends VerticalLayout { List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); - int maxRequests = request.getCategory().name().startsWith("VACACION") ? 2 : 1; + int maxRequests; + + if (request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { + maxRequests = 4; + } else if (request.getCategory().name().startsWith("VACACION")) { + maxRequests = 2; + } else { + maxRequests = 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 5da8183..d9c4c09 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -192,8 +192,13 @@ public class RequestsListView extends Main { } private double calculateTotalUtilized(final List employeeRequests) { + int currentYear = LocalDate.now().getYear(); return employeeRequests.stream() .filter(Objects::nonNull) + .filter(request -> request.getStartDate() != null && ( + request.getStartDate().getYear() == currentYear || + (request.getCategory().name().startsWith("VACACION") && request.getStartDate().getYear() == currentYear - 1) + )) .mapToDouble(request -> request.getDaysToBeTake() != null ? request.getDaysToBeTake() : 0.0) .sum(); } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index aec0cdb..7f3c3f6 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -78,7 +78,7 @@ values ('9c6f12ba-e333-4e7a-b8a6-caa0982bd8c3', 1, '5c6f11fe-c341-4be7-a9a6-bba0 insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('9d6f12ba-e444-4e7a-b8a6-caa0982bd8d4', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VIERNES_SANTO', 'APROBADO', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2024-11-01', '2022-11-01', '2022-11-30', 30, 0); +values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2025-11-01', '2023-11-01', '2023-11-30', 30, 0); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'DIA_DEL_TRABAJADOR', 'APROBADO', 1, '2024-05-01', '2024-05-01', '2024-05-01', 1, 0); -- 2.34.1 From b1e95cf8a5ae651e543d63d7614c4f9f73bb4395 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 13 Nov 2024 19:58:33 -0400 Subject: [PATCH 07/10] Resolver errores de checkstyle --- .../views/RequestEmployeeView.java | 10 +++++----- .../primefactorsolutions/views/RequestsListView.java | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index c404769..2424f65 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -240,7 +240,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .sum(); } - private int getStartDateYear(TimeOffRequest request) { + private int getStartDateYear(final TimeOffRequest request) { if (request.getStartDate() != null) { return request.getStartDate().getYear(); } @@ -349,19 +349,19 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return employeeService.getEmployee(employeeId).getGender() == Employee.Gender.MALE; } - private boolean isValidRequestType(TimeOffRequestType type, boolean isMale) { + private boolean isValidRequestType(final TimeOffRequestType type, final boolean isMale) { return !getStandardExclusions().contains(type) && !(isMale && getMaleSpecificExclusions().contains(type)) && type != TimeOffRequestType.TODOS; } - private TimeOffRequest createRequest(TimeOffRequestType type) { + private TimeOffRequest createRequest(final TimeOffRequestType type) { TimeOffRequest request = new TimeOffRequest(); request.setCategory(type); return request; } - private boolean isVacationExpired(TimeOffRequest request) { + private boolean isVacationExpired(final TimeOffRequest request) { Vacation vacation = vacationService.findVacationByCategory(request.getCategory()); if (vacation != null && vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) { @@ -376,7 +376,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return false; } - private boolean shouldIncludeRequest(TimeOffRequestType type) { + private boolean shouldIncludeRequest(final TimeOffRequestType type) { List existingRequest = requestService.findByEmployeeAndCategory(employeeId, type); return existingRequest.isEmpty(); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index d9c4c09..41639bf 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -196,8 +196,9 @@ public class RequestsListView extends Main { return employeeRequests.stream() .filter(Objects::nonNull) .filter(request -> request.getStartDate() != null && ( - request.getStartDate().getYear() == currentYear || - (request.getCategory().name().startsWith("VACACION") && request.getStartDate().getYear() == currentYear - 1) + request.getStartDate().getYear() == currentYear + || (request.getCategory().name().startsWith("VACACION") + && request.getStartDate().getYear() == currentYear - 1) )) .mapToDouble(request -> request.getDaysToBeTake() != null ? request.getDaysToBeTake() : 0.0) .sum(); -- 2.34.1 From a3e94040fffcae6c32f68705756b967f34bc465c Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 14 Nov 2024 03:17:26 -0400 Subject: [PATCH 08/10] correcciones --- .../service/TimeOffRequestService.java | 10 ++- .../views/RequestEmployeeView.java | 11 ++- .../views/RequestRegisterView.java | 70 +++++++++---------- .../views/RequestsListView.java | 13 +++- 4 files changed, 65 insertions(+), 39 deletions(-) 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) { -- 2.34.1 From 1c638ff27be08355a6c58b3cdec605f9a8674bc4 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 14 Nov 2024 04:09:26 -0400 Subject: [PATCH 09/10] Lista de Solicitudes de empleado - actualizar resumen --- .../views/RequestEmployeeView.java | 35 +++++++++++++----- .../views/RequestRegisterView.java | 6 ++-- .../views/RequestsListView.java | 36 ++++++++++++++++--- 3 files changed, 61 insertions(+), 16 deletions(-) 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, -- 2.34.1 From 5ba432079b68e3b9cff75dfe1c60b92408a85495 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 14 Nov 2024 04:15:29 -0400 Subject: [PATCH 10/10] Resolver errores de checkstyle --- .../com/primefactorsolutions/views/RequestEmployeeView.java | 3 ++- .../java/com/primefactorsolutions/views/RequestsListView.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 2fcaaf6..6737dc5 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -156,7 +156,8 @@ public class RequestEmployeeView extends Div implements HasUrlParameter if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) { utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance(); } - double totalVacationPreviousDays = vacationDays.getFirst() - (vacationDays.getFirst() - utilizedVacationPreviousDays); + double totalVacationPreviousDays = vacationDays.getFirst() + - (vacationDays.getFirst() - utilizedVacationPreviousDays); double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear); double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear); diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 25d91cd..4b770e1 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -181,7 +181,8 @@ public class RequestsListView extends Main { if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) { utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance(); } - double totalVacationPreviousDays = vacationDays.getFirst() - (vacationDays.getFirst() - utilizedVacationPreviousDays); + double totalVacationPreviousDays = vacationDays.getFirst() + - (vacationDays.getFirst() - utilizedVacationPreviousDays); double totalUtilized = calculateTotalUtilized(employeeRequests); -- 2.34.1