From cb34868b9c89d341f552848f83fdaccc03be8c1f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 7 Nov 2024 15:42:42 -0400 Subject: [PATCH] Descarte funcionalidad generar automaticamente solicitud vacacion --- .../views/EmployeeView.java | 81 ------------------- .../views/RequestEmployeeView.java | 2 +- 2 files changed, 1 insertion(+), 82 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index a164d0c..f0c9599 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -343,10 +343,6 @@ public class EmployeeView extends BeanValidationForm implements HasUrl employee.setStatus(status.getValue()); employee.setAge(age.getValue()); - if (employee.getDateOfEntry() != null) { - processTimeOffRequests(employee); - } - employeeService.createOrUpdate(employee); Notification.show(NOTIFICATION_SAVE_SUCCESS); getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); @@ -355,83 +351,6 @@ public class EmployeeView extends BeanValidationForm implements HasUrl } } - private void processTimeOffRequests(final Employee employee) { - boolean isCurrentYearEntry = employee.getDateOfEntry().getYear() == LocalDate.now().getYear(); - - deleteExistingTimeOffRequests(employee); - - if (isCurrentYearEntry) { - saveCurrentYearRequest(employee); - } else if (LocalDate.now().getYear() > employee.getDateOfEntry().getYear()) { - savePreviousAndCurrentYearRequests(employee); - } - } - - private void deleteExistingTimeOffRequests(final Employee employee) { - deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR); - deleteTimeOffRequestByCategory(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL); - } - - private void deleteTimeOffRequestByCategory(final Employee employee, final TimeOffRequestType category) { - var requests = requestService.findByEmployeeAndCategory(employee.getId(), category); - if (!requests.isEmpty()) { - requestService.deleteTimeOffRequest(requests.getFirst().getId()); - } - } - - private void saveCurrentYearRequest(final Employee employee) { - LocalDate baseDate = LocalDate.of( - LocalDate.now().getYear(), - employee.getDateOfEntry().getMonth(), - employee.getDateOfEntry().getDayOfMonth() - ); - TimeOffRequest currentRequest = createTimeOffRequest( - employee, - TimeOffRequestType.VACACION_GESTION_ACTUAL, - baseDate, - 729 - ); - requestService.saveTimeOffRequest(currentRequest); - } - - private void savePreviousAndCurrentYearRequests(final Employee employee) { - LocalDate previousBaseDate = LocalDate.of( - LocalDate.now().getYear() - 1, - employee.getDateOfEntry().getMonth(), - employee.getDateOfEntry().getDayOfMonth() - ); - TimeOffRequest previousRequest = createTimeOffRequest( - employee, - TimeOffRequestType.VACACION_GESTION_ANTERIOR, - previousBaseDate, - 729 - ); - - LocalDate currentBaseDate = previousBaseDate.plusYears(1); - TimeOffRequest currentRequest = createTimeOffRequest( - employee, - TimeOffRequestType.VACACION_GESTION_ACTUAL, - currentBaseDate, - 1094 - ); - - requestService.saveTimeOffRequest(previousRequest); - requestService.saveTimeOffRequest(currentRequest); - } - - private TimeOffRequest createTimeOffRequest(final Employee employee, - final TimeOffRequestType category, - final LocalDate baseDate, - final int expirationDays) { - TimeOffRequest request = new TimeOffRequest(); - request.setEmployee(employee); - request.setCategory(category); - request.setState(TimeOffRequestStatus.APROBADO); - request.setExpiration(baseDate.plusDays(expirationDays)); - setVacationDuration(employee, request, baseDate); - return request; - } - private void enableEditMode() { setFieldsEditable(); saveButton.setVisible(true); diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 3fe80a7..d72bf12 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -122,7 +122,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; return new VerticalLayout( - new Span("Total días libres: " + totalHoliday), + new Span("Total feriados: " + totalHoliday), new Span("Total vacaciones: " + totalVacations), new Span("Total días personales: " + totalPersonalDays), new Span("Total general: " + totalAvailableDays)