From 94e74325512c7a24f7ba735d3ea262edf83155ad Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 30 Oct 2024 15:10:05 -0400 Subject: [PATCH 01/20] #37 Perfil de Personal Administrativo - Listado General de Vacaciones (Modificar estado del empleado) --- .../java/com/primefactorsolutions/views/RequestsListView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 43edf84..1694682 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -153,7 +153,7 @@ public class RequestsListView extends Main { private String getEmployeeStatus(final Employee employee) { Optional activeRequest = requestService - .findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.TAKEN); + .findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.IN_USE); return activeRequest.isPresent() ? "IDLE" : "ACTIVE"; } From f7ab9f8421e0c904e2753257a7fa8b1466a63b1e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 31 Oct 2024 01:16:48 -0400 Subject: [PATCH 02/20] #37 Perfil de Personal Administrativo - Listado General de Vacaciones (Modificar calcular total general) --- .../views/RequestEmployeeView.java | 4 +- .../views/RequestsListView.java | 107 ++++++++++++++---- src/main/resources/data.sql | 2 +- 3 files changed, 89 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 26872a7..fc58d29 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -109,9 +109,11 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalPersonalDays = requests.stream() - .filter(req -> !verificationIsHoliday(req)) // Solo los de tipo OTHER + .filter(req -> !verificationIsHoliday(req)) + .filter(req -> !req.getCategory().name().startsWith("VACATION")) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); + double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; return new VerticalLayout( diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 1694682..aa1de7e 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -17,6 +17,8 @@ import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.grid.PagingGrid; +import java.time.LocalDate; +import java.time.Period; import java.util.*; import java.util.stream.Collectors; @@ -160,31 +162,92 @@ public class RequestsListView extends Main { private String getGeneralTotal(final Employee employee) { List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List vacations = vacationService.findVacations(); - double totalUtilized = employeeRequests.stream() - .filter(Objects::nonNull) - .mapToDouble(request -> { - Double daysBalance = request.getAvailableDays(); - return daysBalance != null ? daysBalance : 0.0; - }) - .sum(); - double totalUnused = employeeRequests.stream() - .filter(Objects::nonNull) - .mapToDouble(request -> { - Double daysBalance = request.getDaysBalance(); - return daysBalance != null ? daysBalance : 0.0; - }) - .sum(); - double totalAvailable = vacations.stream() - .filter(Objects::nonNull) - .mapToDouble(request -> { - Double daysBalance = request.getDuration(); - return daysBalance != null ? daysBalance : 0.0; - }) - .sum(); - double generalTotal = (totalAvailable - totalUtilized) + totalUnused; + double totalUtilized = calculateTotalUtilized(employeeRequests); + double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee); + double generalTotal = totalAvailable - totalUtilized; return String.valueOf(generalTotal); } + private Set getExcludedCategories() { + return Set.of( + TimeOffRequestType.MATERNITY, + TimeOffRequestType.PATERNITY, + TimeOffRequestType.MARRIAGE, + TimeOffRequestType.FATHERS_DAY, + TimeOffRequestType.MOTHERS_DAY + ); + } + + private Set getGenderSpecificExclusions() { + return Set.of( + TimeOffRequestType.INTERNATIONAL_WOMENS_DAY, + TimeOffRequestType.NATIONAL_WOMENS_DAY + ); + } + + private double calculateTotalUtilized(final List employeeRequests) { + return employeeRequests.stream() + .filter(Objects::nonNull) + .mapToDouble(request -> request.getDaysToBeTake() != null ? request.getDaysToBeTake() : 0.0) + .sum(); + } + + private double calculateTotalAvailable(final List vacations, final List employeeRequests, + final Employee employee) { + double vacationDays = calculateVacationDaysBasedOnService(employee.getDateOfEntry()); + Set excludedCategories = getExcludedCategories(); + Set genderSpecificExclusions = getGenderSpecificExclusions(); + Set employeeRequestCategories = employeeRequests.stream() + .map(TimeOffRequest::getCategory) + .collect(Collectors.toSet()); + + double availableVacationDays = vacations.stream() + .filter(Objects::nonNull) + .filter(vacation -> shouldIncludeVacation( + vacation, + excludedCategories, + genderSpecificExclusions, + employee, employeeRequestCategories + )) + .mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0) + .sum(); + + return vacationDays + availableVacationDays; + } + + private double calculateVacationDaysBasedOnService(final LocalDate dateOfEntry) { + int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, LocalDate.now()).getYears() : 0; + if (yearsOfService < 1) { + return 0; + } + if (yearsOfService <= 5) { + return 15; + } + if (yearsOfService <= 10) { + return 20; + } + return 30; + } + + private boolean shouldIncludeVacation(final Vacation vacation, + final Set excludedCategories, + final Set genderSpecificExclusions, + final Employee employee, + final Set employeeRequestCategories) { + if (excludedCategories.contains(vacation.getCategory()) + && !employeeRequestCategories.contains(vacation.getCategory())) { + return false; + } + if (!isFemale(employee) && genderSpecificExclusions.contains(vacation.getCategory())) { + return false; + } + return true; + } + + private boolean isFemale(final Employee employee) { + return employee.getGender() == Employee.Gender.FEMALE; + } + private ComboBox createEmployeeFilter() { employeeFilter = new ComboBox<>("Employee"); List employees = new ArrayList<>(employeeService.findAllEmployees()); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 763b158..70f9e42 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -76,7 +76,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', 'GOOD_FRIDAY', 'COMPLETED', 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', 'VACATION_CURRENT_MANAGEMENT', 'APPROVED', 30, '2026-11-01', '2024-11-01', '2024-11-30', 30, 0); +values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACATION_CURRENT_MANAGEMENT', 'IN_USE', 30, '2026-11-01', '2024-11-01', '2024-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', 'LABOR_DAY', 'REQUESTED', 1, '2025-05-01', '2024-05-01', '2024-05-01', 1, 0); From ca630ef5c613f2d1a1b869650cb13ca663e2735f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 31 Oct 2024 01:29:59 -0400 Subject: [PATCH 03/20] =?UTF-8?q?#37=20Perfil=20de=20Personal=20Administra?= =?UTF-8?q?tivo=20-=20Listado=20General=20de=20Vacaciones=20(Tracducir=20a?= =?UTF-8?q?=20espa=C3=B1ol)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestsListView.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index aa1de7e..58f991d 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -70,10 +70,10 @@ public class RequestsListView extends Main { } private void setupRequestGrid() { - requestGrid.addColumn(this::getEmployeeFullName).setHeader("Employee"); - requestGrid.addColumn(this::getTeamName).setHeader("Team"); - requestGrid.addColumn(this::getEmployeeStatus).setHeader("Employee State"); - requestGrid.addColumn(this::getGeneralTotal).setHeader("General Total"); + requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado"); + requestGrid.addColumn(this::getTeamName).setHeader("Equipo"); + requestGrid.addColumn(this::getEmployeeStatus).setHeader("Estado del empleado"); + requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general"); requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); requestGrid.setPageSize(5); @@ -86,14 +86,14 @@ public class RequestsListView extends Main { } private HorizontalLayout createActionButtons() { - Button viewButton = new Button("View", event -> { + Button viewButton = new Button("Ver", event -> { if (selectedEmployeeId != null) { navigateToTimeOffRequestView(selectedEmployeeId); } else { - Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE); + Notification.show("Seleccione una solicitud para verla.", 3000, Notification.Position.MIDDLE); } }); - Button closeButton = new Button("Close", event -> navigateToMainView()); + Button closeButton = new Button("Salir", event -> navigateToMainView()); return new HorizontalLayout(viewButton, closeButton); } @@ -114,24 +114,24 @@ public class RequestsListView extends Main { final Status state) { List filteredEmployees = employeeService.findAllEmployees(); - if (employee != null && !"ALL".equals(employee.getFirstName())) { + if (employee != null && !"TODOS".equals(employee.getFirstName())) { filteredEmployees = filteredEmployees.stream() .filter(emp -> emp.getId().equals(employee.getId())) .collect(Collectors.toList()); } - if (team != null && !"ALL".equals(team.getName())) { + if (team != null && !"TODOS".equals(team.getName())) { filteredEmployees = filteredEmployees.stream() .filter(emp -> emp.getTeam() != null && emp.getTeam().getId().equals(team.getId())) .collect(Collectors.toList()); } - if (state != null && state != Status.ALL) { + if (state != null && state != Status.TODOS) { filteredEmployees = filteredEmployees.stream() .filter(emp -> { Optional request = requestService - .findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.TAKEN); - return state == Status.IDLE ? request.isPresent() : request.isEmpty(); + .findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.IN_USE); + return state == Status.EN_DESCANSO ? request.isPresent() : request.isEmpty(); }) .collect(Collectors.toList()); } @@ -141,22 +141,22 @@ public class RequestsListView extends Main { } private String getEmployeeFullName(final Employee employee) { - return "ALL".equals(employee.getFirstName()) ? "ALL" : employee.getFirstName() + " " + employee.getLastName(); + return "TODOS".equals(employee.getFirstName()) ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); } private String getTeamName(final Employee employee) { Team team = employee.getTeam(); - return team != null ? team.getName() : "Unassigned"; + return team != null ? team.getName() : "Sin asignar"; } private String getTeamLabel(final Team team) { - return "ALL".equals(team.getName()) ? "ALL" : team.getName(); + return "TODOS".equals(team.getName()) ? "TODOS" : team.getName(); } private String getEmployeeStatus(final Employee employee) { Optional activeRequest = requestService .findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.IN_USE); - return activeRequest.isPresent() ? "IDLE" : "ACTIVE"; + return activeRequest.isPresent() ? "EN_DESCANSO" : "ACTIVO"; } private String getGeneralTotal(final Employee employee) { @@ -249,7 +249,7 @@ public class RequestsListView extends Main { } private ComboBox createEmployeeFilter() { - employeeFilter = new ComboBox<>("Employee"); + employeeFilter = new ComboBox<>("Empleado"); List employees = new ArrayList<>(employeeService.findAllEmployees()); employees.addFirst(createAllEmployeesOption()); employeeFilter.setItems(employees); @@ -266,7 +266,7 @@ public class RequestsListView extends Main { } private ComboBox createTeamFilter() { - teamFilter = new ComboBox<>("Team"); + teamFilter = new ComboBox<>("Equipo"); List teams = new ArrayList<>(teamService.findAllTeams()); teams.addFirst(createAllTeamsOption()); teamFilter.setItems(teams); @@ -283,7 +283,7 @@ public class RequestsListView extends Main { } private ComboBox createStateFilter() { - stateFilter = new ComboBox<>("Employee State"); + stateFilter = new ComboBox<>("Estado del empleado"); stateFilter.setItems(Status.values()); stateFilter.setValue(Status.values()[0]); stateFilter.addValueChangeListener(event -> @@ -297,20 +297,20 @@ public class RequestsListView extends Main { } private enum Status { - ALL, - IDLE, - ACTIVE + TODOS, + EN_DESCANSO, + ACTIVO } private Employee createAllEmployeesOption() { Employee allEmployeesOption = new Employee(); - allEmployeesOption.setFirstName("ALL"); + allEmployeesOption.setFirstName("TODOS"); return allEmployeesOption; } private Team createAllTeamsOption() { Team allTeamsOption = new Team(); - allTeamsOption.setName("ALL"); + allTeamsOption.setName("TODOS"); return allTeamsOption; } From a02499d53f45ecc3ff634e601eae60d49f900fff Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 31 Oct 2024 01:34:18 -0400 Subject: [PATCH 04/20] =?UTF-8?q?Estado=20de=20la=20solicitud=20-=20traduc?= =?UTF-8?q?irlo=20al=20espa=C3=B1ol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/TimeOffRequestStatus.java | 22 +++++++++---------- .../views/RequestEmployeeView.java | 2 +- .../views/RequestRegisterView.java | 14 ++++++------ .../views/RequestsListView.java | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java b/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java index e549c4e..ac6f552 100644 --- a/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java +++ b/src/main/java/com/primefactorsolutions/model/TimeOffRequestStatus.java @@ -1,15 +1,15 @@ package com.primefactorsolutions.model; public enum TimeOffRequestStatus { - ALL, - TAKEN, - REQUESTED, - APPROVED, - IN_USE, - UNDER_REVIEW, - PENDING, - REJECTED, - COMPLETED, - CANCELLED, - EXPIRED + TODOS, + TOMADO, + SOLICITADO, + APROBADO, + EN_USO, + EN_REVISION, + PENDIENTE, + RECHAZADO, + COMPLETADO, + CANCELADO, + VENCIDO } diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index fc58d29..ba59a9a 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -170,7 +170,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter : fetchFilteredTimeOffRequests(category, state); for (TimeOffRequest request : filteredRequests) { if (request.getExpiration().isBefore(LocalDate.now())) { - request.setState(TimeOffRequestStatus.EXPIRED); + request.setState(TimeOffRequestStatus.VENCIDO); } } for (TimeOffRequest request : filteredRequests) { diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index a3b1f54..304b84f 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -148,10 +148,10 @@ public class RequestRegisterView extends VerticalLayout { if (category == TimeOffRequestType.HEALTH_PERMIT || category == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT || category == TimeOffRequestType.VACATION_PREVIOUS_MANAGEMENT) { - return latestRequest.getState() == TimeOffRequestStatus.EXPIRED - || (latestRequest.getState() == TimeOffRequestStatus.TAKEN && latestRequest.getDaysBalance() > 0); + return latestRequest.getState() == TimeOffRequestStatus.VENCIDO + || (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0); } else { - return latestRequest.getState() == TimeOffRequestStatus.EXPIRED; + return latestRequest.getState() == TimeOffRequestStatus.VENCIDO; } } @@ -181,13 +181,13 @@ public class RequestRegisterView extends VerticalLayout { if (vacation != null) { TimeOffRequest requestWithBalance = requests.stream() .filter(request -> request.getDaysBalance() > 0 - && request.getState() != TimeOffRequestStatus.EXPIRED) + && request.getState() != TimeOffRequestStatus.VENCIDO) .max(Comparator.comparing(TimeOffRequest::getStartDate)) .orElse(null); if (requestWithBalance != null) { - if (requestWithBalance.getState() == TimeOffRequestStatus.TAKEN) { + if (requestWithBalance.getState() == TimeOffRequestStatus.TOMADO) { availableDaysField.setValue(requestWithBalance.getDaysBalance()); - } else if (requestWithBalance.getState() == TimeOffRequestStatus.EXPIRED) { + } else if (requestWithBalance.getState() == TimeOffRequestStatus.VENCIDO) { availableDaysField.setValue(vacation.getDuration()); } } else if (vacation.getCategory() == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT) { @@ -330,7 +330,7 @@ public class RequestRegisterView extends VerticalLayout { } else { request.setExpiration(endDate); } - request.setState(TimeOffRequestStatus.REQUESTED); + request.setState(TimeOffRequestStatus.SOLICITADO); List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 58f991d..7721c1c 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -130,7 +130,7 @@ public class RequestsListView extends Main { filteredEmployees = filteredEmployees.stream() .filter(emp -> { Optional request = requestService - .findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.IN_USE); + .findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.EN_USO); return state == Status.EN_DESCANSO ? request.isPresent() : request.isEmpty(); }) .collect(Collectors.toList()); @@ -155,7 +155,7 @@ public class RequestsListView extends Main { private String getEmployeeStatus(final Employee employee) { Optional activeRequest = requestService - .findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.IN_USE); + .findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.EN_USO); return activeRequest.isPresent() ? "EN_DESCANSO" : "ACTIVO"; } From c0cc1e86de5b85a22330c57b45a8191d34ad21ae Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 31 Oct 2024 01:42:33 -0400 Subject: [PATCH 05/20] =?UTF-8?q?Categoria=20vacaciones=20-=20traducirlo?= =?UTF-8?q?=20al=20espa=C3=B1ol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/TimeOffRequestType.java | 46 +++++++++---------- .../views/RequestRegisterView.java | 34 +++++++------- .../views/RequestsListView.java | 14 +++--- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java b/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java index 32277b8..0b9d245 100644 --- a/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java +++ b/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java @@ -1,29 +1,29 @@ package com.primefactorsolutions.model; public enum TimeOffRequestType { - ALL, - NEW_YEAR, - MONDAY_CARNIVAL, - TUESDAY_CARNIVAL, - GOOD_FRIDAY, - LABOR_DAY, - INDEPENDENCE_DAY, - CHRISTMAS, - PRURINATIONAL_STATE_DAY, + TODOS, + AÑO_NUEVO, + LUNES_CARNAVAL, + MARTES_CARNAVAL, + VIERNES_SANTO, + DIA_DEL_TRABAJADOR, + DIA_DE_LA_INDEPENDENCIA, + NAVIDAD, + DIA_DEL_ESTADO_PLURINACIONAL, CORPUS_CHRISTI, - ANDEAN_NEW_YEAR, - DEPARTMENTAL_ANNIVERSARY, - ALL_SOULS_DAY, + AÑO_NUEVO_ANDINO, + ANIVERSARIO_DEPARTAMENTAL, + DIA_DE_TODOS_LOS_DIFUNTOS, - BIRTHDAY, - MATERNITY, - PATERNITY, - MARRIAGE, - FATHERS_DAY, - MOTHERS_DAY, - INTERNATIONAL_WOMENS_DAY, - NATIONAL_WOMENS_DAY, - HEALTH_PERMIT, - VACATION_CURRENT_MANAGEMENT, - VACATION_PREVIOUS_MANAGEMENT, + CUMPLEAÑOS, + MATERNIDAD, + PATERNIDAD, + MATRIMONIO, + DIA_DEL_PADRE, + DIA_DE_LA_MADRE, + DIA_DE_LA_MUJER_INTERNACIONAL, + DIA_DE_LA_MUJER_NACIONAL, + PERMISOS_DE_SALUD, + VACACION_GESTION_ACTUAL, + VACACION_GESTION_ANTERIOR, } diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 304b84f..fcb1d66 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -145,9 +145,9 @@ public class RequestRegisterView extends VerticalLayout { .max(Comparator.comparing(TimeOffRequest::getStartDate)) .orElse(null); - if (category == TimeOffRequestType.HEALTH_PERMIT - || category == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT - || category == TimeOffRequestType.VACATION_PREVIOUS_MANAGEMENT) { + if (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); } else { @@ -157,13 +157,13 @@ public class RequestRegisterView extends VerticalLayout { private boolean isCategoryAllowedByGender(final TimeOffRequestType category, final Employee.Gender gender) { if (gender == Employee.Gender.MALE) { - return category != TimeOffRequestType.MATERNITY - && category != TimeOffRequestType.MOTHERS_DAY - && category != TimeOffRequestType.INTERNATIONAL_WOMENS_DAY - && category != TimeOffRequestType.NATIONAL_WOMENS_DAY; + return category != TimeOffRequestType.MATERNIDAD + && category != TimeOffRequestType.DIA_DE_LA_MADRE + && category != TimeOffRequestType.DIA_DE_LA_MUJER_INTERNACIONAL + && category != TimeOffRequestType.DIA_DE_LA_MUJER_NACIONAL; } else { - return category != TimeOffRequestType.FATHERS_DAY - && category != TimeOffRequestType.PATERNITY; + return category != TimeOffRequestType.DIA_DEL_PADRE + && category != TimeOffRequestType.PATERNIDAD; } } @@ -190,7 +190,7 @@ public class RequestRegisterView extends VerticalLayout { } else if (requestWithBalance.getState() == TimeOffRequestStatus.VENCIDO) { availableDaysField.setValue(vacation.getDuration()); } - } else if (vacation.getCategory() == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT) { + } else if (vacation.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) { LocalDate dateOfEntry = employeeComboBox.getValue().getDateOfEntry(); LocalDate currentDate = LocalDate.now(); long yearsOfService = ChronoUnit.YEARS.between(dateOfEntry, currentDate); @@ -244,13 +244,13 @@ public class RequestRegisterView extends VerticalLayout { vacation.getDayOfMonth().intValue()); endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); } else { - if (vacation.getCategory() == TimeOffRequestType.BIRTHDAY && employee.getBirthday() != null) { + if (vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() != null) { startDate = LocalDate.of( startYear, employee.getBirthday().getMonth(), employee.getBirthday().getDayOfMonth()); endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); - } else if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) { + } else if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { startDate = LocalDate.now(); endDate = LocalDate.of(startYear, 12, 31); } else { @@ -260,7 +260,7 @@ public class RequestRegisterView extends VerticalLayout { startDatePicker.setValue(startDate); if ((vacation.getDuration() != null && vacation.getDuration() == 0.5) - || vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) { + || vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { endDatePicker.setValue(startDate); } else { int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0); @@ -291,7 +291,7 @@ public class RequestRegisterView extends VerticalLayout { if (startDate != null && endDate != null) { double daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1; - if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT || vacation.getDuration() == 0.5) { + if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD || vacation.getDuration() == 0.5) { daysToBeTakenField.setValue(0.5); } else { daysToBeTakenField.setValue(daysToBeTaken); @@ -335,7 +335,7 @@ public class RequestRegisterView extends VerticalLayout { List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); - int maxRequests = request.getCategory() == TimeOffRequestType.HEALTH_PERMIT ? 4 : 2; + int maxRequests = request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD ? 4 : 2; if (existingRequests.size() >= maxRequests) { existingRequests.stream() @@ -355,8 +355,8 @@ public class RequestRegisterView extends VerticalLayout { List requests = requestService.findByEmployeeAndCategory( newRequest.getEmployee().getId(), newRequest.getCategory()); - if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT - && vacation.getCategory() == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT) { + if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD + && vacation.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) { for (TimeOffRequest request : requests) { double newBalance = request.getDaysBalance() - newRequest.getDaysToBeTake(); request.setDaysBalance(newBalance); diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 7721c1c..facfb69 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -170,18 +170,18 @@ public class RequestsListView extends Main { private Set getExcludedCategories() { return Set.of( - TimeOffRequestType.MATERNITY, - TimeOffRequestType.PATERNITY, - TimeOffRequestType.MARRIAGE, - TimeOffRequestType.FATHERS_DAY, - TimeOffRequestType.MOTHERS_DAY + TimeOffRequestType.MATERNIDAD, + TimeOffRequestType.PATERNIDAD, + TimeOffRequestType.MATRIMONIO, + TimeOffRequestType.DIA_DEL_PADRE, + TimeOffRequestType.DIA_DE_LA_MADRE ); } private Set getGenderSpecificExclusions() { return Set.of( - TimeOffRequestType.INTERNATIONAL_WOMENS_DAY, - TimeOffRequestType.NATIONAL_WOMENS_DAY + TimeOffRequestType.DIA_DE_LA_MUJER_INTERNACIONAL, + TimeOffRequestType.DIA_DE_LA_MUJER_NACIONAL ); } From 3efa8c73d58540b7b139123706edb1910efab60e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Fri, 1 Nov 2024 13:42:23 -0400 Subject: [PATCH 06/20] =?UTF-8?q?Traducir=20a=20epa=C3=B1ol=20las=20senten?= =?UTF-8?q?cias=20de=20incercion=20de=20datos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/data.sql | 66 ++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 70f9e42..9efe2f8 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -16,33 +16,33 @@ INSERT INTO team (id, version, name) VALUES ('c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3 INSERT INTO team (id, version, name) VALUES ('8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 1, 'GHI'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('123e4567-e89b-12d3-a456-426614174000', 1, 'NEW_YEAR', 1, 1, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('223e4567-e89b-12d3-a456-426614174001', 1, 'MONDAY_CARNIVAL', 2, 12, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('323e4567-e89b-12d3-a456-426614174002', 1, 'TUESDAY_CARNIVAL', 2, 13, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('423e4567-e89b-12d3-a456-426614174003', 1, 'GOOD_FRIDAY', 3, 29, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('523e4567-e89b-12d3-a456-426614174004', 1, 'LABOR_DAY', 5, 1, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('623e4567-e89b-12d3-a456-426614174005', 1, 'INDEPENDENCE_DAY', 8, 6, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'CHRISTMAS', 12, 25, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('123e4567-e89b-12d3-a456-426614174000', 1, 'AÑO_NUEVO', 1, 1, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('223e4567-e89b-12d3-a456-426614174001', 1, 'LUNES_CARNAVAL', 2, 12, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('323e4567-e89b-12d3-a456-426614174002', 1, 'MARTES_CARNAVAL', 2, 13, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('423e4567-e89b-12d3-a456-426614174003', 1, 'VIERNES_SANTO', 3, 29, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('523e4567-e89b-12d3-a456-426614174004', 1, 'DIA_DEL_TRABAJADOR', 5, 1, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('623e4567-e89b-12d3-a456-426614174005', 1, 'DIA_DE_LA_INDEPENDENCIA', 8, 6, 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'NAVIDAD', 12, 25, 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', 1, 21, 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'DIA_DEL_ESTADO_PLURINACIONAL', 1, 21, 1, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('923e4567-e89b-12d3-a456-426614174008', 1, 'CORPUS_CHRISTI', 5, 30, 1, 30, 'MOVABLE'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('a23e4567-e89b-12d3-a456-426614174009', 1, 'ANDEAN_NEW_YEAR', 6, 21, 1, 30, 'MOVABLE'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('b23e4567-e89b-12d3-a456-42661417400a', 1, 'DEPARTMENTAL_ANNIVERSARY', 9, 14, 1, 30, 'MOVABLE'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400b', 1, 'ALL_SOULS_DAY', 11, 2, 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('a23e4567-e89b-12d3-a456-426614174009', 1, 'AÑO_NUEVO_ANDINO', 6, 21, 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('b23e4567-e89b-12d3-a456-42661417400a', 1, 'ANIVERSARIO_DEPARTAMENTAL', 9, 14, 1, 30, 'MOVABLE'); +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, 'BIRTHDAY', 0.5, 365, 'OTHER'); -INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400d', 1, 'MATERNITY', 90, 90, 'OTHER'); -INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400e', 1, 'PATERNITY', 3, 3, 'OTHER'); -INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400f', 1, 'MARRIAGE', 3, 3, 'OTHER'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401a', 1, 'FATHERS_DAY', 3, 19, 0.5, 30, 'OTHER'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401b', 1, 'MOTHERS_DAY', 5, 27, 0.5, 30, 'OTHER'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401c', 1, 'INTERNATIONAL_WOMENS_DAY', 3, 8, 0.5, 30, 'OTHER'); -INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401d', 1, 'NATIONAL_WOMENS_DAY', 10, 11, 0.5, 30, 'OTHER'); -INSERT INTO vacation (id, version, category, duration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401e', 1, 'HEALTH_PERMIT', 2, 'OTHER'); -INSERT INTO vacation (id, version, category, expiration, type) VALUES ('490e5fbe-895b-42f8-b914-95437f7b39c0', 1, 'VACATION_CURRENT_MANAGEMENT', 730, 'OTHER'); -INSERT INTO vacation (id, version, category, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-4266141740ff', 1, 'VACATION_PREVIOUS_MANAGEMENT', 730, 'OTHER'); +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, 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'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401a', 1, 'DIA_DEL_PADRE', 3, 19, 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401b', 1, 'DIA_DE_LA_MADRE', 5, 27, 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401c', 1, 'DIA_DE_LA_MUJER_INTERNACIONAL', 3, 8, 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401d', 1, 'DIA_DE_LA_MUJER_NACIONAL', 10, 11, 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, duration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401e', 1, 'PERMISOS_DE_SALUD', 2, 'OTHER'); +INSERT INTO vacation (id, version, category, expiration, type) VALUES ('490e5fbe-895b-42f8-b914-95437f7b39c0', 1, 'VACACION_GESTION_ACTUAL', 730, 'OTHER'); +INSERT INTO vacation (id, version, category, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-4266141740ff', 1, 'VACACION_GESTION_ANTERIOR', 730, 'OTHER'); insert into employee (id, version, username, first_name, last_name, status, team_id, gender, birthday, date_of_entry) values ('5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 1, 'bob', 'Bob', 'Test', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE', '2024-02-20', '2013-10-22'); @@ -66,25 +66,25 @@ 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', 'PATERNITY', 'TAKEN', 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', 'TOMADO', 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', 'NEW_YEAR', 'EXPIRED', 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', 'VENCIDO', 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', 'MONDAY_CARNIVAL', 'APPROVED', 1, '2025-02-12', '2025-02-12', '2025-02-12', 1, 0); +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', 'TUESDAY_CARNIVAL', 'UNDER_REVIEW', 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', 'EN_REVISION', 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', 'GOOD_FRIDAY', 'COMPLETED', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0); +values ('9d6f12ba-e444-4e7a-b8a6-caa0982bd8d4', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VIERNES_SANTO', 'COMPLETADO', 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', 'VACATION_CURRENT_MANAGEMENT', 'IN_USE', 30, '2026-11-01', '2024-11-01', '2024-11-30', 30, 0); +values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'EN_USO', 30, '2026-11-01', '2024-11-01', '2024-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', 'LABOR_DAY', 'REQUESTED', 1, '2025-05-01', '2024-05-01', '2024-05-01', 1, 0); +values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'DIA_DEL_TRABAJADOR', 'SOLICITADO', 1, '2025-05-01', '2024-05-01', '2024-05-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 ('fb9d9d75-b2ab-4ea4-b8b3-0a8f89e5c123', 1, '2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 'INDEPENDENCE_DAY', 'IN_USE', 1, '2025-08-06', '2024-08-06', '2024-08-06', 1, 0); +values ('fb9d9d75-b2ab-4ea4-b8b3-0a8f89e5c123', 1, '2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 'DIA_DE_LA_INDEPENDENCIA', 'EN_USO', 1, '2025-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', 'ALL_SOULS_DAY', 'PENDING', 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', 'PENDIENTE', 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', 'NEW_YEAR', 'PENDING', 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', 'PENDIENTE', 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', 'MONDAY_CARNIVAL', 'APPROVED', 1, '2025-02-12', '2024-02-12', '2024-02-12', 1, 0); +values ('89bc4b2a-943f-487c-a9f3-bacf78145e67', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'LUNES_CARNAVAL', 'APROBADO', 1, '2025-02-12', '2024-02-12', '2024-02-12', 1, 0); From 71cb2d67c9ddfac4e0e5c25975a7781d6ff9cd05 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sat, 2 Nov 2024 00:51:21 -0400 Subject: [PATCH 07/20] Perfil de Personal Administrativo - Listado solicitudes pendientes de Vacaciones --- .../TimeOffRequestRepository.java | 1 + .../service/TimeOffRequestService.java | 4 + .../views/MainLayout.java | 6 +- .../views/PendingRequestsListView.java | 224 ++++++++++++++++++ 4 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java diff --git a/src/main/java/com/primefactorsolutions/repositories/TimeOffRequestRepository.java b/src/main/java/com/primefactorsolutions/repositories/TimeOffRequestRepository.java index 1485fa0..f58ae50 100644 --- a/src/main/java/com/primefactorsolutions/repositories/TimeOffRequestRepository.java +++ b/src/main/java/com/primefactorsolutions/repositories/TimeOffRequestRepository.java @@ -13,4 +13,5 @@ public interface TimeOffRequestRepository extends JpaRepository findByEmployeeId(UUID idEmployee); Optional findByEmployeeIdAndState(UUID employeeId, TimeOffRequestStatus state); List findByEmployeeIdAndCategory(UUID employeeId, TimeOffRequestType category); + List findByState(TimeOffRequestStatus state); } diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index c5eba83..a097a83 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -31,6 +31,10 @@ public class TimeOffRequestService { return timeOffRequest.orElse(null); } + public List findRequestsByState(TimeOffRequestStatus state) { + return timeOffRequestRepository.findByState(state); + } + public List findRequestsByEmployeeId(final UUID idEmployee) { return timeOffRequestRepository.findByEmployeeId(idEmployee); } diff --git a/src/main/java/com/primefactorsolutions/views/MainLayout.java b/src/main/java/com/primefactorsolutions/views/MainLayout.java index b5602f5..d7e59b6 100644 --- a/src/main/java/com/primefactorsolutions/views/MainLayout.java +++ b/src/main/java/com/primefactorsolutions/views/MainLayout.java @@ -143,9 +143,11 @@ public class MainLayout extends AppLayout { SideNavItem timeOff = new SideNavItem("My Time-off", TimeoffView.class, LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create()); timeOff.addItem(new SideNavItem("Vacations", RequestsListView.class, - LineAwesomeIcon.SUN.create())); + LineAwesomeIcon.UMBRELLA_BEACH_SOLID.create())); timeOff.addItem(new SideNavItem("Add Vacation", RequestRegisterView.class, - LineAwesomeIcon.SUN.create())); + LineAwesomeIcon.CALENDAR_PLUS.create())); + timeOff.addItem(new SideNavItem("Pending Requests", PendingRequestsListView.class, + LineAwesomeIcon.LIST_ALT.create())); SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class, LineAwesomeIcon.HOURGLASS_START_SOLID.create()); timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class, diff --git a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java new file mode 100644 index 0000000..e1311ea --- /dev/null +++ b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java @@ -0,0 +1,224 @@ +package com.primefactorsolutions.views; + +import com.primefactorsolutions.model.*; +import com.primefactorsolutions.service.EmployeeService; +import com.primefactorsolutions.service.TeamService; +import com.primefactorsolutions.service.TimeOffRequestService; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.combobox.ComboBox; +import com.vaadin.flow.component.html.Main; +import com.vaadin.flow.component.notification.Notification; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.router.PageTitle; +import com.vaadin.flow.router.Route; +import com.vaadin.flow.spring.annotation.SpringComponent; +import jakarta.annotation.security.PermitAll; +import org.springframework.context.annotation.Scope; +import org.vaadin.firitin.components.grid.PagingGrid; + +import java.util.*; +import java.util.stream.Collectors; + +@SpringComponent +@Scope("prototype") +@PageTitle("PendingRequests") +@Route(value = "/pending-requests", layout = MainLayout.class) +@PermitAll +public class PendingRequestsListView extends Main { + + private final TimeOffRequestService requestService; + private final EmployeeService employeeService; + private final TeamService teamService; + private final PagingGrid pendingRequestsGrid = new PagingGrid<>(); + + private List employees = Collections.emptyList(); + private ComboBox employeeFilter; + private ComboBox teamFilter; + private ComboBox categoryFilter; + private UUID selectedRequestId; + + + public PendingRequestsListView(final TimeOffRequestService requestService, + final EmployeeService employeeService, + final TeamService teamService) { + this.requestService = requestService; + this.employeeService = employeeService; + this.teamService = teamService; + this.employees = employeeService.findAllEmployees(); + initializeView(); + refreshGeneralPendingRequestsGrid(null, null, null); + } + + private void initializeView() { + setupFilters(); + setupPendingRequestsGrid(); + add(pendingRequestsGrid); + add(createActionButtons()); + } + + private void setupFilters() { + add(createEmployeeFilter()); + add(createTeamFilter()); + add(createCategoryFilter()); + } + + private void setupPendingRequestsGrid() { + pendingRequestsGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado"); + pendingRequestsGrid.addColumn(this::getTeamName).setHeader("Equipo"); + pendingRequestsGrid.addColumn(this::getCategory).setHeader("Categoría"); + + pendingRequestsGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + pendingRequestsGrid.setPageSize(5); + pendingRequestsGrid.asSingleSelect().addValueChangeListener(event -> { + TimeOffRequest selectedRequest = event.getValue(); + if (selectedRequest != null) { + selectedRequestId = selectedRequest.getId(); + } + }); + } + + private HorizontalLayout createActionButtons() { + Button approveButton = createActionButton("Aprobar", TimeOffRequestStatus.APROBADO); + Button rejectButton = createActionButton("Rechazar", TimeOffRequestStatus.RECHAZADO); + Button closeButton = new Button("Salir", event -> navigateToMainView()); + return new HorizontalLayout(approveButton, rejectButton, closeButton); + } + + private Button createActionButton(String caption, TimeOffRequestStatus status) { + return new Button(caption, event -> { + if (selectedRequestId != null) { + TimeOffRequest request = requestService.findTimeOffRequest(selectedRequestId); + request.setState(status); + requestService.saveTimeOffRequest(request); + refreshGeneralPendingRequestsGrid(null, null, null); + } else { + Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); + } + }); + } + + private void refreshGeneralPendingRequestsGrid(final Employee employee, + final Team team, + final TimeOffRequestType category) { + pendingRequestsGrid.setPagingDataProvider((page, pageSize) -> { + int start = (int) (page * pendingRequestsGrid.getPageSize()); + return fetchFilteredPendingRequests(start, pageSize, employee, team, category); + }); + pendingRequestsGrid.getDataProvider().refreshAll(); + } + + private List fetchFilteredPendingRequests(final int start, + final int pageSize, + final Employee employee, + final Team team, + final TimeOffRequestType category) { + List filteredPendingRequests = requestService.findRequestsByState(TimeOffRequestStatus.PENDIENTE); + + if (employee != null && !"TODOS".equals(employee.getFirstName())) { + filteredPendingRequests = filteredPendingRequests.stream() + .filter(emp -> emp.getEmployee().getId().equals(employee.getId())) + .collect(Collectors.toList()); + } + + if (team != null && !"TODOS".equals(team.getName())) { + filteredPendingRequests = filteredPendingRequests.stream() + .filter(emp -> emp.getEmployee().getTeam() != null && emp.getEmployee().getTeam().getId().equals(team.getId())) + .collect(Collectors.toList()); + } + + if (category != null && category != TimeOffRequestType.TODOS) { + filteredPendingRequests = filteredPendingRequests.stream() + .filter(emp -> emp.getCategory().equals(category)) + .collect(Collectors.toList()); + } + + int end = Math.min(start + pageSize, filteredPendingRequests.size()); + return filteredPendingRequests.subList(start, end); + } + + private String getEmployeeFullName(final TimeOffRequest request) { + Employee employee = request.getEmployee(); + return getEmployeeFullNameLabel(employee); + } + + private String getEmployeeFullNameLabel(final Employee employee) { + return "TODOS".equals(employee.getFirstName()) ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); + } + + private String getTeamName(final TimeOffRequest request) { + Team team = request.getEmployee().getTeam(); + return team != null ? team.getName() : "Sin asignar"; + } + + private String getTeamLabel(final Team team) { + return "TODOS".equals(team.getName()) ? "TODOS" : team.getName(); + } + + private String getCategory(TimeOffRequest request){ + return String.valueOf(request.getCategory()); + } + + private ComboBox createEmployeeFilter() { + employeeFilter = new ComboBox<>("Empleado"); + List employees = new ArrayList<>(employeeService.findAllEmployees()); + employees.addFirst(createAllEmployeesOption()); + employeeFilter.setItems(employees); + employeeFilter.setItemLabelGenerator(this::getEmployeeFullNameLabel); + employeeFilter.setValue(employees.getFirst()); + employeeFilter.addValueChangeListener(event -> + refreshGeneralPendingRequestsGrid( + event.getValue(), + teamFilter.getValue(), + categoryFilter.getValue() + ) + ); + return employeeFilter; + } + + private ComboBox createTeamFilter() { + teamFilter = new ComboBox<>("Equipo"); + List teams = new ArrayList<>(teamService.findAllTeams()); + teams.addFirst(createAllTeamsOption()); + teamFilter.setItems(teams); + teamFilter.setItemLabelGenerator(this::getTeamLabel); + teamFilter.setValue(teams.getFirst()); + teamFilter.addValueChangeListener(event -> + refreshGeneralPendingRequestsGrid( + employeeFilter.getValue(), + event.getValue(), + categoryFilter.getValue() + ) + ); + return teamFilter; + } + + private ComboBox createCategoryFilter() { + categoryFilter = new ComboBox<>("Categoría"); + categoryFilter.setItems(TimeOffRequestType.values()); + categoryFilter.setValue(TimeOffRequestType.values()[0]); + categoryFilter.addValueChangeListener(event -> + refreshGeneralPendingRequestsGrid( + employeeFilter.getValue(), + teamFilter.getValue(), + event.getValue() + ) + ); + return categoryFilter; + } + + private Employee createAllEmployeesOption() { + Employee allEmployeesOption = new Employee(); + allEmployeesOption.setFirstName("TODOS"); + return allEmployeesOption; + } + + private Team createAllTeamsOption() { + Team allTeamsOption = new Team(); + allTeamsOption.setName("TODOS"); + return allTeamsOption; + } + + private void navigateToMainView() { + getUI().ifPresent(ui -> ui.navigate(MainView.class)); + } +} \ No newline at end of file From 4421c6fe4589e38c8b8330c0700b1efb9db2f320 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 3 Nov 2024 23:22:09 -0400 Subject: [PATCH 08/20] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administra?= =?UTF-8?q?tivo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(correcc?= =?UTF-8?q?iones)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestEmployeeView.java | 4 +- .../views/RequestRegisterView.java | 299 ++++++++++-------- 2 files changed, 175 insertions(+), 128 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index ba59a9a..275bb6f 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -87,9 +87,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter "state", "startDate", "endDate", - "daysToBeTake", - "daysBalance" - ); + "daysToBeTake"); requestGrid.setAllRowsVisible(true); requestGrid.asSingleSelect().addValueChangeListener(event -> { TimeOffRequest selectedRequest = event.getValue(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index fcb1d66..41f37d1 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -32,13 +32,13 @@ import java.util.UUID; @Route(value = "/requests/new", layout = MainLayout.class) public class RequestRegisterView extends VerticalLayout { - private final ComboBox employeeComboBox = new ComboBox<>("Employee"); - private final ComboBox categoryComboBox = new ComboBox<>("Category"); - private final NumberField availableDaysField = new NumberField("Available Days"); - private final DatePicker startDatePicker = new DatePicker("Start Date"); - private final DatePicker endDatePicker = new DatePicker("End Date"); - private final NumberField daysToBeTakenField = new NumberField("Days To Be Taken"); - private final NumberField balanceDaysField = new NumberField("Balance Days"); + private final ComboBox employeeComboBox = new ComboBox<>("Empleado"); + private final ComboBox categoryComboBox = new ComboBox<>("Categoría"); + private final NumberField availableDaysField = new NumberField("Días disponibles"); + private final DatePicker startDatePicker = new DatePicker("Fecha de inicio"); + private final DatePicker endDatePicker = new DatePicker("Fecha final"); + private final NumberField daysToBeTakenField = new NumberField("Días a tomar"); + private final NumberField balanceDaysField = new NumberField("Días de saldo"); private final TimeOffRequestService requestService; private final EmployeeService employeeService; @@ -59,11 +59,24 @@ public class RequestRegisterView extends VerticalLayout { this.employeeService = employeeService; this.vacationService = vacationService; this.binder = new Binder<>(TimeOffRequest.class); + initializeView(); + } + private void initializeView() { configureFormFields(); configureButtons(); configureBinder(); setupFormLayout(); + configureInitialFieldStates(); + } + + private void configureInitialFieldStates() { + categoryComboBox.setEnabled(false); + startDatePicker.setEnabled(false); + endDatePicker.setEnabled(false); + availableDaysField.setReadOnly(true); + daysToBeTakenField.setReadOnly(true); + balanceDaysField.setReadOnly(true); } private void configureFormFields() { @@ -71,66 +84,74 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); employeeComboBox.addValueChangeListener(event -> { employee = event.getValue(); - handleEmployeeSelection(employee); + System.out.println("Clearing form..." + employee); + + handleEmployeeSelection(event.getValue()); + }); + categoryComboBox.addValueChangeListener(event -> { + onCategoryChange(event.getValue()); + handleCategorySelection(event.getValue()); }); - categoryComboBox.setEnabled(false); - startDatePicker.setEnabled(false); - endDatePicker.setEnabled(false); - categoryComboBox.addValueChangeListener(event -> handleCategorySelection(event.getValue())); startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues()); endDatePicker.addValueChangeListener(event -> calculateDays()); - availableDaysField.setReadOnly(true); - daysToBeTakenField.setReadOnly(true); - balanceDaysField.setReadOnly(true); } private void configureBinder() { binder.forField(employeeComboBox) - .asRequired("Employee is required") .bind(TimeOffRequest::getEmployee, TimeOffRequest::setEmployee); - binder.forField(categoryComboBox) - .asRequired("Category is required") .bind(TimeOffRequest::getCategory, TimeOffRequest::setCategory); - binder.forField(availableDaysField) .bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays); - binder.forField(startDatePicker) - .asRequired("Start date is required") .bind(TimeOffRequest::getStartDate, TimeOffRequest::setStartDate); - binder.forField(endDatePicker) - .asRequired("End date is required") .bind(TimeOffRequest::getEndDate, TimeOffRequest::setEndDate); - binder.forField(daysToBeTakenField) .bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake); - binder.forField(balanceDaysField) .bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance); - binder.setBean(new TimeOffRequest()); } private void handleEmployeeSelection(final Employee selectedEmployee) { - clearForm(); if (selectedEmployee != null) { + categoryComboBox.clear(); + availableDaysField.clear(); + startDatePicker.clear(); + endDatePicker.clear(); + daysToBeTakenField.clear(); + balanceDaysField.clear(); categoryComboBox.setEnabled(true); + startDatePicker.setEnabled(false); + endDatePicker.setEnabled(false); filterCategories(selectedEmployee); } } private void filterCategories(final Employee employee) { + categoryComboBox.clear(); List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List allCategories = Arrays.asList(TimeOffRequestType.values()); 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) .toList(); + categoryComboBox.setItems(availableCategories); } + private void onCategoryChange(final TimeOffRequestType selectedCategory) { + if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL) { + startDatePicker.setEnabled(true); + endDatePicker.setEnabled(true); + } else { + startDatePicker.setEnabled(true); + endDatePicker.setEnabled(false); + } + } + private boolean isCategoryAvailable(final List employeeRequests, final TimeOffRequestType category) { List requestsByCategory = employeeRequests.stream() @@ -170,7 +191,6 @@ public class RequestRegisterView extends VerticalLayout { private void handleCategorySelection(final TimeOffRequestType selectedCategory) { if (selectedCategory != null) { updateAvailableDays(selectedCategory); - startDatePicker.setEnabled(true); } } @@ -215,48 +235,52 @@ public class RequestRegisterView extends VerticalLayout { endDate = null; UUID employeeId = employee.getId(); - List previousRequests - = requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory()); + List previousRequests = requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory()); - int startYear; - if (previousRequests.isEmpty()) { - startYear = LocalDate.now().getYear(); - } else { - int lastRequestYear = previousRequests.stream() - .max(Comparator.comparing(TimeOffRequest::getStartDate)) - .map(request -> request.getStartDate().getYear()) - .orElse(LocalDate.now().getYear()); + int startYear = calculateStartYear(previousRequests); - int proposedYear = lastRequestYear + 1; - int currentYear = LocalDate.now().getYear(); - - if (proposedYear < currentYear) { - startYear = currentYear; - } else { - startYear = proposedYear; - } - } - - if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) { - startDate = LocalDate.of( - startYear, - vacation.getMonthOfYear().intValue(), - vacation.getDayOfMonth().intValue()); + startDate = determineStartDate(vacation, startYear); + if (startDate != null) { endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); } else { - if (vacation.getCategory() == TimeOffRequestType.CUMPLEAÑOS && employee.getBirthday() != null) { - startDate = LocalDate.of( - startYear, - employee.getBirthday().getMonth(), - employee.getBirthday().getDayOfMonth()); - endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); - } else if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { - startDate = LocalDate.now(); - endDate = LocalDate.of(startYear, 12, 31); - } else { - startDate = LocalDate.now(); - } + startDate = LocalDate.now(); } + + setPickerValues(vacation, startDate); + setPickerLimits(startDate, endDate); + } + + private int calculateStartYear(final List previousRequests) { + if (previousRequests.isEmpty()) { + return LocalDate.now().getYear(); + } + + int lastRequestYear = previousRequests.stream() + .max(Comparator.comparing(TimeOffRequest::getStartDate)) + .map(request -> request.getStartDate().getYear()) + .orElse(LocalDate.now().getYear()); + + int currentYear = LocalDate.now().getYear(); + return Math.max(lastRequestYear + 1, 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.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { + return LocalDate.now(); + } + + return LocalDate.now(); + } + + private void setPickerValues(final Vacation vacation, final LocalDate startDate) { startDatePicker.setValue(startDate); if ((vacation.getDuration() != null && vacation.getDuration() == 0.5) @@ -266,22 +290,25 @@ public class RequestRegisterView extends VerticalLayout { int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0); endDatePicker.setValue(startDate.plusDays(durationDays)); } + } + private void setPickerLimits(final LocalDate startDate, final LocalDate endDate) { startDatePicker.setMin(startDate); startDatePicker.setMax(endDate); endDatePicker.setMin(startDate); endDatePicker.setMax(endDate); } - private void updateDatePickerMinValues() { LocalDate startDate = startDatePicker.getValue(); - if (vacation.getDuration() == 0.5) { - endDatePicker.setValue(startDate.plusDays(0)); - } else { - endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + if (availableDaysField.getValue() != null) { + if (availableDaysField.getValue() == 0.5) { + endDatePicker.setValue(startDate.plusDays(0)); + } else { + endDatePicker.setValue(startDate.plusDays(availableDaysField.getValue().intValue() - 1)); + } + calculateDays(); } - calculateDays(); } private void calculateDays() { @@ -289,26 +316,53 @@ public class RequestRegisterView extends VerticalLayout { LocalDate endDate = endDatePicker.getValue(); Double availableDays = availableDaysField.getValue(); - if (startDate != null && endDate != null) { - double daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1; - if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD || vacation.getDuration() == 0.5) { - daysToBeTakenField.setValue(0.5); - } else { - daysToBeTakenField.setValue(daysToBeTaken); - } - double balanceDays = availableDays - daysToBeTakenField.getValue(); + if (areDatesValid(startDate, endDate)) { + double daysToBeTaken = calculateDaysBetween(startDate, endDate); + setDaysToBeTakenField(daysToBeTaken); + + double balanceDays = calculateBalanceDays(availableDays, daysToBeTakenField.getValue()); balanceDaysField.setValue(balanceDays); + + if (balanceDays < 0) { + clearFields(); + } } } + private boolean areDatesValid(final LocalDate startDate, final LocalDate endDate) { + return startDate != null && endDate != null; + } + + private double calculateDaysBetween(final LocalDate startDate, final LocalDate endDate) { + return java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1; + } + + private void setDaysToBeTakenField(final double daysToBeTaken) { + if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { + daysToBeTakenField.setValue(0.5); + } else { + daysToBeTakenField.setValue(daysToBeTaken); + } + } + + private double calculateBalanceDays(final double availableDays, final double daysToBeTaken) { + return availableDays - daysToBeTaken; + } + + private void clearFields() { + daysToBeTakenField.clear(); + balanceDaysField.clear(); + endDatePicker.clear(); + } + private void configureButtons() { - saveButton = new Button("Save", event -> saveRequest()); - closeButton = new Button("Close", event -> closeForm()); + saveButton = new Button("Guardar", event -> saveRequest()); + closeButton = new Button("Salir", event -> closeForm()); } private void setupFormLayout() { add( - new H3("Add Vacation Request"), + new H3("Añadir solicitud de vacaciones"), employeeComboBox, categoryComboBox, availableDaysField, @@ -321,59 +375,54 @@ public class RequestRegisterView extends VerticalLayout { } private void saveRequest() { - if (binder.validate().isOk()) { - TimeOffRequest request = binder.getBean(); - request.setStartDate(startDatePicker.getValue()); - request.setAvailableDays(availableDaysField.getValue()); - if (endDate == null) { - request.setExpiration(endDatePicker.getValue()); - } else { - request.setExpiration(endDate); - } - request.setState(TimeOffRequestStatus.SOLICITADO); + if (!binder.validate().isOk()) { + Notification.show("Rellene correctamente todos los campos obligatorios."); + return; + } - List existingRequests = - requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); + if (!validateForm()) { + Notification.show("Por favor, complete los campos antes de guardar"); + return; + } - int maxRequests = request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD ? 4 : 2; + TimeOffRequest request = prepareRequest(); + handleExistingRequests(request); + requestService.saveTimeOffRequest(request); - if (existingRequests.size() >= maxRequests) { - existingRequests.stream() - .min(Comparator.comparing(TimeOffRequest::getStartDate)) - .ifPresent(oldestRequest -> requestService.deleteTimeOffRequest(oldestRequest.getId())); - } + Notification.show("Solicitud guardada correctamente."); + closeForm(); + } - requestService.saveTimeOffRequest(request); - Notification.show("Request saved successfully."); - closeForm(); - } else { - Notification.show("Please fill all required fields correctly."); + private TimeOffRequest prepareRequest() { + TimeOffRequest request = binder.getBean(); + request.setStartDate(startDatePicker.getValue()); + request.setAvailableDays(availableDaysField.getValue()); + request.setExpiration(endDate != null ? endDate : endDatePicker.getValue()); + request.setState(TimeOffRequestStatus.PENDIENTE); + return request; + } + + private void handleExistingRequests(final TimeOffRequest request) { + List existingRequests = + requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); + + int maxRequests = request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD ? 4 : 2; + + if (existingRequests.size() >= maxRequests) { + existingRequests.stream() + .min(Comparator.comparing(TimeOffRequest::getStartDate)) + .ifPresent(oldestRequest -> requestService.deleteTimeOffRequest(oldestRequest.getId())); } } - private void updateBalanceForCategory(final TimeOffRequest newRequest) { - List requests = requestService.findByEmployeeAndCategory( - newRequest.getEmployee().getId(), newRequest.getCategory()); - - if (vacation.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD - && vacation.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) { - for (TimeOffRequest request : requests) { - double newBalance = request.getDaysBalance() - newRequest.getDaysToBeTake(); - request.setDaysBalance(newBalance); - requestService.saveTimeOffRequest(request); - } - } + private boolean validateForm() { + return employeeComboBox.getValue() != null + && categoryComboBox.getValue() != null + && startDatePicker.getValue() != null + && endDatePicker.getValue() != null; } private void closeForm() { getUI().ifPresent(ui -> ui.navigate(RequestsListView.class)); } - - private void clearForm() { - availableDaysField.clear(); - startDatePicker.clear(); - endDatePicker.clear(); - daysToBeTakenField.clear(); - balanceDaysField.clear(); - } } From cfd5599d327afd1e4cb731482c65dbc78ff51949 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 3 Nov 2024 23:40:13 -0400 Subject: [PATCH 09/20] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administra?= =?UTF-8?q?tivo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(No=20ac?= =?UTF-8?q?eptar=20fechas=20pasadas)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/primefactorsolutions/views/RequestRegisterView.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 41f37d1..8abc086 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -240,6 +240,11 @@ public class RequestRegisterView extends VerticalLayout { int startYear = calculateStartYear(previousRequests); startDate = determineStartDate(vacation, startYear); + + if (startDate.isBefore(LocalDate.now())) { + startDate = determineStartDate(vacation, startYear + 1); + } + if (startDate != null) { endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); } else { From 45bf76c3d83e2e1eb0617bb83ec5c5d5c5ce6c5e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Mon, 4 Nov 2024 00:19:12 -0400 Subject: [PATCH 10/20] Actualizar BD - Actualizar el estado de los registros de solicitudes de vacaciones --- .../service/TimeOffRequestService.java | 4 ++ .../primefactorsolutions/views/MainView.java | 38 ++++++++++++++++++- .../views/RequestEmployeeView.java | 5 --- src/main/resources/data.sql | 12 +++--- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index a097a83..4001143 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -18,6 +18,10 @@ public class TimeOffRequestService { timeOffRequestRepository.save(newTimeOffRequest); } + public void saveAll(List requests) { + timeOffRequestRepository.saveAll(requests); + } + public void deleteTimeOffRequest(final UUID id) { timeOffRequestRepository.deleteById(id); } diff --git a/src/main/java/com/primefactorsolutions/views/MainView.java b/src/main/java/com/primefactorsolutions/views/MainView.java index 8b26aa6..8c44b5a 100644 --- a/src/main/java/com/primefactorsolutions/views/MainView.java +++ b/src/main/java/com/primefactorsolutions/views/MainView.java @@ -1,16 +1,50 @@ 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; 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 { - public MainView() { - add(new Text("welcome")); + + private final TimeOffRequestService requestService; + + public MainView(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 275bb6f..00f2eac 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -166,11 +166,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter List filteredRequests = allFiltersAreNull(category, state) ? requestService.findRequestsByEmployeeId(employeeId) : fetchFilteredTimeOffRequests(category, state); - for (TimeOffRequest request : filteredRequests) { - if (request.getExpiration().isBefore(LocalDate.now())) { - request.setState(TimeOffRequestStatus.VENCIDO); - } - } for (TimeOffRequest request : filteredRequests) { requestService.saveTimeOffRequest(request); } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 9efe2f8..17e4980 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -66,7 +66,7 @@ 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', 'TOMADO', 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', 'VENCIDO', 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); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) @@ -74,17 +74,17 @@ values ('9b6f12ba-e222-4e7a-b8a6-caa0982bd8b2', 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 ('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); 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', 'COMPLETADO', 1, '2024-03-29', '2024-03-29', '2024-03-29', 1, 0); +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', 'EN_USO', 30, '2026-11-01', '2024-11-01', '2024-11-30', 30, 0); +values ('9e6f12ba-e555-4e7a-b8a6-caa0982bd8e5', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACACION_GESTION_ACTUAL', 'APROBADO', 30, '2026-11-01', '2024-11-01', '2024-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', 'SOLICITADO', 1, '2025-05-01', '2024-05-01', '2024-05-01', 1, 0); +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); 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', 'EN_USO', 1, '2025-08-06', '2024-08-06', '2024-08-06', 1, 0); +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); 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); 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, '2025-02-12', '2024-02-12', '2024-02-12', 1, 0); +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); From eb6183df19bd3b1339b855ca448d2e24db5cd490 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Mon, 4 Nov 2024 00:24:34 -0400 Subject: [PATCH 11/20] Correcciones --- .../service/TimeOffRequestService.java | 4 ++-- .../com/primefactorsolutions/views/MainView.java | 2 +- .../views/PendingRequestsListView.java | 13 ++++++++----- .../views/RequestEmployeeView.java | 1 - .../views/RequestRegisterView.java | 6 ++++-- .../views/RequestsListView.java | 3 ++- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index 4001143..65651a8 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -18,7 +18,7 @@ public class TimeOffRequestService { timeOffRequestRepository.save(newTimeOffRequest); } - public void saveAll(List requests) { + public void saveAll(final List requests) { timeOffRequestRepository.saveAll(requests); } @@ -35,7 +35,7 @@ public class TimeOffRequestService { return timeOffRequest.orElse(null); } - public List findRequestsByState(TimeOffRequestStatus state) { + public List findRequestsByState(final TimeOffRequestStatus state) { return timeOffRequestRepository.findByState(state); } diff --git a/src/main/java/com/primefactorsolutions/views/MainView.java b/src/main/java/com/primefactorsolutions/views/MainView.java index 8c44b5a..bc3239d 100644 --- a/src/main/java/com/primefactorsolutions/views/MainView.java +++ b/src/main/java/com/primefactorsolutions/views/MainView.java @@ -19,7 +19,7 @@ public class MainView extends Main { private final TimeOffRequestService requestService; - public MainView(TimeOffRequestService requestService) { + public MainView(final TimeOffRequestService requestService) { this.requestService = requestService; add(new Text("Welcome")); updateRequestStatuses(); diff --git a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java index e1311ea..1ef9f4e 100644 --- a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java @@ -84,7 +84,7 @@ public class PendingRequestsListView extends Main { return new HorizontalLayout(approveButton, rejectButton, closeButton); } - private Button createActionButton(String caption, TimeOffRequestStatus status) { + private Button createActionButton(final String caption, final TimeOffRequestStatus status) { return new Button(caption, event -> { if (selectedRequestId != null) { TimeOffRequest request = requestService.findTimeOffRequest(selectedRequestId); @@ -112,7 +112,8 @@ public class PendingRequestsListView extends Main { final Employee employee, final Team team, final TimeOffRequestType category) { - List filteredPendingRequests = requestService.findRequestsByState(TimeOffRequestStatus.PENDIENTE); + List filteredPendingRequests + = requestService.findRequestsByState(TimeOffRequestStatus.PENDIENTE); if (employee != null && !"TODOS".equals(employee.getFirstName())) { filteredPendingRequests = filteredPendingRequests.stream() @@ -122,7 +123,8 @@ public class PendingRequestsListView extends Main { if (team != null && !"TODOS".equals(team.getName())) { filteredPendingRequests = filteredPendingRequests.stream() - .filter(emp -> emp.getEmployee().getTeam() != null && emp.getEmployee().getTeam().getId().equals(team.getId())) + .filter(emp -> emp.getEmployee().getTeam() != null + && emp.getEmployee().getTeam().getId().equals(team.getId())) .collect(Collectors.toList()); } @@ -142,7 +144,8 @@ public class PendingRequestsListView extends Main { } private String getEmployeeFullNameLabel(final Employee employee) { - return "TODOS".equals(employee.getFirstName()) ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); + return "TODOS".equals(employee.getFirstName()) + ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); } private String getTeamName(final TimeOffRequest request) { @@ -154,7 +157,7 @@ public class PendingRequestsListView extends Main { return "TODOS".equals(team.getName()) ? "TODOS" : team.getName(); } - private String getCategory(TimeOffRequest request){ + private String getCategory(final TimeOffRequest request) { return String.valueOf(request.getCategory()); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 00f2eac..f2e0088 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -21,7 +21,6 @@ import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; -import java.time.LocalDate; import java.util.Collections; import java.util.List; import java.util.UUID; diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 8abc086..b01ed9b 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -136,7 +136,8 @@ 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.VACACION_GESTION_ANTERIOR + && category != TimeOffRequestType.TODOS) .toList(); categoryComboBox.setItems(availableCategories); @@ -235,7 +236,8 @@ public class RequestRegisterView extends VerticalLayout { endDate = null; UUID employeeId = employee.getId(); - List previousRequests = requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory()); + List previousRequests + = requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory()); int startYear = calculateStartYear(previousRequests); diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index facfb69..8b6465c 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -141,7 +141,8 @@ public class RequestsListView extends Main { } private String getEmployeeFullName(final Employee employee) { - return "TODOS".equals(employee.getFirstName()) ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); + return "TODOS".equals(employee.getFirstName()) + ? "TODOS" : employee.getFirstName() + " " + employee.getLastName(); } private String getTeamName(final Employee employee) { From 4615febec32a2145addc29f9dcaa68d9b4820f70 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Mon, 4 Nov 2024 00:48:59 -0400 Subject: [PATCH 12/20] Actualizar BD - Actualizar el estado de los registros de solicitudes de vacaciones --- .../primefactorsolutions/views/MainView.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/MainView.java b/src/main/java/com/primefactorsolutions/views/MainView.java index 9a9fb8f..ebe4a5b 100644 --- a/src/main/java/com/primefactorsolutions/views/MainView.java +++ b/src/main/java/com/primefactorsolutions/views/MainView.java @@ -10,7 +10,35 @@ import jakarta.annotation.security.PermitAll; @Route(value = "", layout = MainLayout.class) @PermitAll public class MainView extends Main { - public MainView() { - add(new Text("Welcome to PFS Intra.")); + + private final TimeOffRequestService requestService; + + public MainView(final TimeOffRequestService requestService) { + this.requestService = requestService; + add(new Text("Welcome")); + updateRequestStatuses(); + } + + private void updateRequestStatuses() { + List 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); } } From 7e415ae8375558fc8557e5ed04a4713399e9b67d Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 5 Nov 2024 10:47:16 -0400 Subject: [PATCH 13/20] cambiar team string a un team class --- .../views/EmployeeView.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index bdf5a82..a8c4f51 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -1,8 +1,10 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; +import com.primefactorsolutions.model.Team; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.ReportService; +import com.primefactorsolutions.service.TeamService; import com.vaadin.componentfactory.pdfviewer.PdfViewer; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; @@ -27,6 +29,7 @@ import com.vaadin.flow.router.*; import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.form.BeanValidationForm; @@ -47,6 +50,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final EmployeeService employeeService; private final ReportService reportService; + private final TeamService teamService; // TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente. private final TextField username = createTextField("Username: ", 30, true); @@ -67,7 +71,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final EmailField personalEmail = createEmailField("E-mail"); private final TextField cod = createTextField("Codigo de Empleado", 30, false); private final TextField position = createTextField("Cargo", 30, false); - private final TextField team = createTextField("Equipo", 30, false); + private final ComboBox team = new ComboBox<>("Equipo"); private final TextField leadManager = createTextField("Lead/Manager", 30, false); private final TextField project = createTextField("Proyecto", 30, false); private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false); @@ -135,10 +139,13 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final H3 datBanc = new H3("Datos Bancados"); private final H3 datGest = new H3("Datos Gestora Pública y Seguro Social"); - public EmployeeView(final EmployeeService employeeService, final ReportService reportService) { + public EmployeeView(final EmployeeService employeeService, + final ReportService reportService, + final TeamService teamService) { super(Employee.class); this.employeeService = employeeService; this.reportService = reportService; + this.teamService = teamService; saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); configureComponents(); @@ -155,6 +162,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl editButton.setVisible(true); reportButton.setVisible(true); birthday.addValueChangeListener(event -> calculateAge()); + createTeamComboBox(); reportButton.addClickListener((ComponentEventListener>) buttonClickEvent -> { var employee = getEntity(); @@ -262,12 +270,11 @@ public class EmployeeView extends BeanValidationForm implements HasUrl return emailField; } - private ComboBox createComboBox(final String label, final T[] items) { - ComboBox comboBox = new ComboBox<>(label); - comboBox.setItems(items); - comboBox.setItemLabelGenerator(Object::toString); - comboBox.setWidthFull(); - return comboBox; + private void createTeamComboBox() { + List teams = teamService.findAllTeams(); + team.setItems(teams); + team.setItemLabelGenerator(Team::getName); + team.setWidthFull(); } private ComboBox createGenderComboBox() { @@ -317,6 +324,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl UUID employeeId = UUID.fromString(s); var employee = employeeService.getEmployee(employeeId); setEntityWithEnabledSave(employee); + team.setValue(employee.getTeam()); if ("edit".equals(action) && !s.isEmpty()) { saveButton.setVisible(true); From 88e80a7dcc5635775197291d7a8a2e1279028291 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 5 Nov 2024 13:33:00 -0400 Subject: [PATCH 14/20] =?UTF-8?q?traducir=20a=20espa=C3=B1ol=20y=20cambiar?= =?UTF-8?q?=20uso=20de=20grid=20a=20paging=20grid=20de=20RequestEmploye?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestEmployeeView.java | 90 ++++++++++--------- .../views/RequestView.java | 24 ++--- .../views/RequestsListView.java | 2 +- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index f2e0088..db19a41 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -6,7 +6,6 @@ import com.primefactorsolutions.service.TimeOffRequestService; import com.primefactorsolutions.service.VacationService; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.combobox.ComboBox; -import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.H3; import com.vaadin.flow.component.html.Span; @@ -20,6 +19,7 @@ import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import org.vaadin.firitin.components.grid.PagingGrid; import java.util.Collections; import java.util.List; @@ -36,7 +36,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter private final TimeOffRequestService requestService; private final EmployeeService employeeService; private final VacationService vacationService; - private final Grid requestGrid = new Grid<>(TimeOffRequest.class); + private final PagingGrid requestGrid = new PagingGrid<>(TimeOffRequest.class); private List requests = Collections.emptyList(); private ComboBox categoryFilter; private ComboBox stateFilter; @@ -65,7 +65,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private ComboBox createCategoryFilter() { - categoryFilter = new ComboBox<>("Category"); + categoryFilter = new ComboBox<>("Categoría"); categoryFilter.setItems(TimeOffRequestType.values()); categoryFilter.setValue(TimeOffRequestType.values()[0]); categoryFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), stateFilter.getValue())); @@ -73,7 +73,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private ComboBox createStateFilter() { - stateFilter = new ComboBox<>("State"); + stateFilter = new ComboBox<>("Estado de la solicitud"); stateFilter.setItems(TimeOffRequestStatus.values()); stateFilter.setValue(TimeOffRequestStatus.values()[0]); stateFilter.addValueChangeListener(event -> refreshRequestGrid(categoryFilter.getValue(), event.getValue())); @@ -87,7 +87,15 @@ public class RequestEmployeeView extends Div implements HasUrlParameter "startDate", "endDate", "daysToBeTake"); - requestGrid.setAllRowsVisible(true); + + requestGrid.getColumnByKey("category").setHeader("Categoría"); + requestGrid.getColumnByKey("state").setHeader("Estado"); + requestGrid.getColumnByKey("startDate").setHeader("Fecha de Inicio"); + requestGrid.getColumnByKey("endDate").setHeader("Fecha de Fin"); + requestGrid.getColumnByKey("daysToBeTake").setHeader("Días a Tomar"); + + requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + requestGrid.setPageSize(5); requestGrid.asSingleSelect().addValueChangeListener(event -> { TimeOffRequest selectedRequest = event.getValue(); if (selectedRequest != null) { @@ -102,22 +110,22 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalVacations = requests.stream() - .filter(req -> req.getCategory().toString().startsWith("VACATION")) + .filter(req -> req.getCategory().toString().startsWith("VACACION")) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalPersonalDays = requests.stream() .filter(req -> !verificationIsHoliday(req)) - .filter(req -> !req.getCategory().name().startsWith("VACATION")) + .filter(req -> !req.getCategory().name().startsWith("VACACION")) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; return new VerticalLayout( - new Span("TOTAL HOLIDAYS: " + totalHoliday), - new Span("TOTAL VACATIONS: " + totalVacations), - new Span("TOTAL PERSONAL DAYS: " + totalPersonalDays), - new Span("TOTAL GENERAL: " + totalAvailableDays) + new Span("Total días libres: " + totalHoliday), + new Span("Total vacaciones: " + totalVacations), + new Span("Total días personales: " + totalPersonalDays), + new Span("Total general: " + totalAvailableDays) ); } @@ -127,24 +135,23 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private HorizontalLayout createActionButtons() { - Button viewButton = new Button("View", event -> { - if (request != null) { - navigateToViewRequest(request); - } else { - Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE); - } - }); - Button editButton = new Button("Edit", event -> { - if (request != null) { - navigateToEditRequest(request); - } else { - Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE); - } - }); - Button closeButton = new Button("Close", event -> navigateToRequestsListView()); + Button viewButton = createButton("Ver", () -> navigateToViewRequest(request)); + Button editButton = createButton("Editar", () -> navigateToEditRequest(request)); + Button closeButton = new Button("Salir", event -> navigateToRequestsListView()); + return new HorizontalLayout(viewButton, editButton, closeButton); } + private Button createButton(String caption, Runnable action) { + return new Button(caption, event -> { + if (request != null) { + action.run(); + } else { + Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); + } + }); + } + private void navigateToRequestsListView() { getUI().ifPresent(ui -> ui.navigate(RequestsListView.class)); } @@ -162,33 +169,30 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private void refreshRequestGrid(final TimeOffRequestType category, final TimeOffRequestStatus state) { - List filteredRequests = allFiltersAreNull(category, state) - ? requestService.findRequestsByEmployeeId(employeeId) - : fetchFilteredTimeOffRequests(category, state); - for (TimeOffRequest request : filteredRequests) { - requestService.saveTimeOffRequest(request); - } - requestGrid.setItems(filteredRequests); + requestGrid.setPagingDataProvider((page, pageSize) -> { + int start = (int) (page * requestGrid.getPageSize()); + return fetchFilteredTimeOffRequests(start, pageSize, category, state); + }); + requestGrid.getDataProvider().refreshAll(); } - private boolean allFiltersAreNull(final TimeOffRequestType category, final TimeOffRequestStatus state) { - return category == null && state == null; - } - - private List fetchFilteredTimeOffRequests(final TimeOffRequestType category, + private List fetchFilteredTimeOffRequests(final int start, + final int pageSize, + final TimeOffRequestType category, final TimeOffRequestStatus state) { requests = requestService.findRequestsByEmployeeId(employeeId); - if (category != null && !"ALL".equals(category.name())) { + if (category != null && !"TODOS".equals(category.name())) { requests = requests.stream() .filter(req -> req.getCategory().equals(category)) .collect(Collectors.toList()); } - if (state != null && !"ALL".equals(state.name())) { + if (state != null && !"TODOS".equals(state.name())) { requests = requests.stream() .filter(req -> req.getState().equals(state)) .collect(Collectors.toList()); } - return requests; + int end = Math.min(start + pageSize, requests.size()); + return requests.subList(start, end); } @Override @@ -202,7 +206,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private void setViewTitle(final String employeeName, final String employeeTeam) { - addComponentAsFirst(new H3("Name: " + employeeName)); - addComponentAtIndex(1, new H3("Team: " + employeeTeam)); + addComponentAsFirst(new H3("Nombre del empleado: " + employeeName)); + addComponentAtIndex(1, new H3("Equipo: " + employeeTeam)); } } diff --git a/src/main/java/com/primefactorsolutions/views/RequestView.java b/src/main/java/com/primefactorsolutions/views/RequestView.java index 1fae708..47b5ae2 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestView.java @@ -27,12 +27,12 @@ import java.util.UUID; @Route(value = "/requests/:requestId?/:action?", layout = MainLayout.class) public class RequestView extends BeanValidationForm implements HasUrlParameter { - private final ComboBox state = new ComboBox<>("State"); - private final DatePicker expiration = new DatePicker("Expiration"); - private final DatePicker startDate = new DatePicker("Start Date"); - private final DatePicker endDate = new DatePicker("End Date"); - private final NumberField availableDays = new NumberField("Available Days"); - private final NumberField daysToBeTake = new NumberField("Days To Be Take"); + private final ComboBox state = new ComboBox<>("Estado de la solicitud"); + private final DatePicker expiration = new DatePicker("Vencimiento"); + private final DatePicker startDate = new DatePicker("Fecha de inicio"); + private final DatePicker endDate = new DatePicker("Fecha de fin"); + private final NumberField availableDays = new NumberField("Días disponibles"); + private final NumberField daysToBeTake = new NumberField("Días a tomar"); private final TimeOffRequestService requestService; private final EmployeeService employeeService; @@ -85,13 +85,13 @@ public class RequestView extends BeanValidationForm implements H } protected Button createSaveButton() { - saveButton = new Button("Save"); + saveButton = new Button("Guardar"); saveButton.addClickListener(event -> saveRequest()); return saveButton; } protected Button createCloseButton() { - Button closeButton = new Button("Close"); + Button closeButton = new Button("Salir"); closeButton.addClickListener(event -> closeForm()); return closeButton; } @@ -110,7 +110,7 @@ public class RequestView extends BeanValidationForm implements H TimeOffRequest request = getEntity(); setRequestFieldValues(request); requestService.saveTimeOffRequest(request); - Notification.show("Request saved successfully."); + Notification.show("Solicitud guardada correctamente."); closeForm(); } } @@ -147,14 +147,14 @@ public class RequestView extends BeanValidationForm implements H } private H3 createEmployeeHeader() { - return new H3("Employee: " + employee.getFirstName() + " " + employee.getLastName()); + return new H3("Empleado: " + employee.getFirstName() + " " + employee.getLastName()); } private H3 createTeamHeader() { - return new H3("Team: " + employee.getTeam().getName()); + return new H3("Equipo: " + employee.getTeam().getName()); } private H3 createCategoryHeader() { - return new H3("Category: " + request.getCategory()); + return new H3("Categoría: " + request.getCategory()); } } diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 8b6465c..2551fee 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -90,7 +90,7 @@ public class RequestsListView extends Main { if (selectedEmployeeId != null) { navigateToTimeOffRequestView(selectedEmployeeId); } else { - Notification.show("Seleccione una solicitud para verla.", 3000, Notification.Position.MIDDLE); + Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); } }); Button closeButton = new Button("Salir", event -> navigateToMainView()); From 9fdf1c08b520a4736ad090c07070983aa5472413 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 5 Nov 2024 14:58:28 -0400 Subject: [PATCH 15/20] Correccion registro solicitud vacaciones actual y anterior --- .../model/TimeOffRequestType.java | 2 ++ .../views/EmployeeView.java | 1 - .../views/RequestEmployeeView.java | 2 +- .../views/RequestRegisterView.java | 18 ++++++++++++++++-- .../views/RequestsListView.java | 2 ++ src/main/resources/data.sql | 8 +++++--- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java b/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java index 0b9d245..82de353 100644 --- a/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java +++ b/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java @@ -19,6 +19,8 @@ public enum TimeOffRequestType { MATERNIDAD, PATERNIDAD, MATRIMONIO, + DUELO_1ER_GRADO, + DUELO_2ER_GRADO, DIA_DEL_PADRE, DIA_DE_LA_MADRE, DIA_DE_LA_MUJER_INTERNACIONAL, diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index a8c4f51..448b5b5 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -29,7 +29,6 @@ import com.vaadin.flow.router.*; import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.form.BeanValidationForm; diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index db19a41..3fe80a7 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -142,7 +142,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter return new HorizontalLayout(viewButton, editButton, closeButton); } - private Button createButton(String caption, Runnable action) { + private Button createButton(final String caption, final Runnable action) { return new Button(caption, event -> { if (request != null) { action.run(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index b01ed9b..ce9af15 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -393,9 +393,14 @@ public class RequestRegisterView extends VerticalLayout { } TimeOffRequest request = prepareRequest(); - handleExistingRequests(request); - requestService.saveTimeOffRequest(request); + if (request.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) { + handleVacationRequest(request); + } else { + handleExistingRequests(request); + } + + requestService.saveTimeOffRequest(request); Notification.show("Solicitud guardada correctamente."); closeForm(); } @@ -422,6 +427,15 @@ public class RequestRegisterView extends VerticalLayout { } } + private void handleVacationRequest(final TimeOffRequest request) { + List existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL); + if (!existingRequests.isEmpty()) { + TimeOffRequest existingRequest = existingRequests.getFirst(); + existingRequest.setCategory(TimeOffRequestType.VACACION_GESTION_ANTERIOR); + requestService.saveTimeOffRequest(existingRequest); + } + } + private boolean validateForm() { return employeeComboBox.getValue() != null && categoryComboBox.getValue() != null diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 2551fee..1f69ed8 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -174,6 +174,8 @@ public class RequestsListView extends Main { TimeOffRequestType.MATERNIDAD, TimeOffRequestType.PATERNIDAD, TimeOffRequestType.MATRIMONIO, + TimeOffRequestType.DUELO_1ER_GRADO, + TimeOffRequestType.DUELO_2ER_GRADO, TimeOffRequestType.DIA_DEL_PADRE, TimeOffRequestType.DIA_DE_LA_MADRE ); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 17e4980..5833a0e 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -36,13 +36,15 @@ INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES 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'); +INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('550e8400-e29b-41d4-a716-446655440000', 1, 'DUELO_1ER_GRADO', 3, 3, 'OTHER'); +INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400a', 1, 'DUELO_2ER_GRADO', 2, 2, 'OTHER'); INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401a', 1, 'DIA_DEL_PADRE', 3, 19, 0.5, 30, 'OTHER'); INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401b', 1, 'DIA_DE_LA_MADRE', 5, 27, 0.5, 30, 'OTHER'); INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401c', 1, 'DIA_DE_LA_MUJER_INTERNACIONAL', 3, 8, 0.5, 30, 'OTHER'); INSERT INTO vacation (id, version, category, month_of_year, day_of_month, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401d', 1, 'DIA_DE_LA_MUJER_NACIONAL', 10, 11, 0.5, 30, 'OTHER'); INSERT INTO vacation (id, version, category, duration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401e', 1, 'PERMISOS_DE_SALUD', 2, 'OTHER'); -INSERT INTO vacation (id, version, category, expiration, type) VALUES ('490e5fbe-895b-42f8-b914-95437f7b39c0', 1, 'VACACION_GESTION_ACTUAL', 730, 'OTHER'); -INSERT INTO vacation (id, version, category, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-4266141740ff', 1, 'VACACION_GESTION_ANTERIOR', 730, 'OTHER'); +INSERT INTO vacation (id, version, category, expiration, type) VALUES ('490e5fbe-895b-42f8-b914-95437f7b39c0', 1, 'VACACION_GESTION_ACTUAL', 360, 'OTHER'); +INSERT INTO vacation (id, version, category, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-4266141740ff', 1, 'VACACION_GESTION_ANTERIOR', 360, 'OTHER'); insert into employee (id, version, username, first_name, last_name, status, team_id, gender, birthday, date_of_entry) values ('5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 1, 'bob', 'Bob', 'Test', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE', '2024-02-20', '2013-10-22'); @@ -76,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, '2026-11-01', '2024-11-01', '2024-11-30', 30, 0); +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); 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); From a0bd00fba4f9f01edb68c6ea89e65f94574faf4f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 6 Nov 2024 14:46:51 -0400 Subject: [PATCH 16/20] =?UTF-8?q?#5,=20#6=20Perfil=20de=20Empleado=20-=20G?= =?UTF-8?q?UARDAR=20y=20EDITAR=20Informaci=C3=B3n=20de=20Empleados=20(Asig?= =?UTF-8?q?nar=20o=20actualizar=20vacaciones)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primefactorsolutions/model/Employee.java | 290 ++++++++++-------- .../views/EmployeeView.java | 116 ++++++- 2 files changed, 262 insertions(+), 144 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index e128132..1d3df41 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -1,147 +1,167 @@ - package com.primefactorsolutions.model; - import com.google.common.collect.Lists; - import jakarta.persistence.*; - import lombok.AllArgsConstructor; - import lombok.Data; - import lombok.EqualsAndHashCode; - import lombok.NoArgsConstructor; - import org.springframework.security.core.GrantedAuthority; - import org.springframework.security.core.userdetails.UserDetails; +package com.primefactorsolutions.model; - import java.time.LocalDate; - import java.util.Collection; +import com.google.common.collect.Lists; +import jakarta.persistence.*; +import jakarta.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; - @Data - @Entity - @AllArgsConstructor - @NoArgsConstructor - @EqualsAndHashCode(callSuper = true) - public class Employee extends BaseEntity implements UserDetails { - private String username; - private String firstName; - private String lastName; - private LocalDate birthday; - private String birthCity; - private String age; +import java.time.LocalDate; +import java.util.Collection; - private String residenceAddress; - private String localAddress; - private String phoneNumber; - private String personalEmail; - private String position; - @ManyToOne - @JoinColumn(name = "team_id", nullable = false) - private Team team; - private String emergencyCName; - private String emergencyCAddress; - private String emergencyCPhone; - private String emergencyCEmail; - private String numberOfChildren; +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class Employee extends BaseEntity implements UserDetails { - private String ci; - private String issuedIn; + private String username; + @NotNull(message = "El nombre no puede estar vacío") + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El nombre solo debe contener letras") + private String firstName; + @NotNull(message = "El apellido no puede estar vacío") + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El apellido solo debe contener letras") + private String lastName; + private LocalDate birthday; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "La ciudad de nacimiento solo debe contener letras") + private String birthCity; + private String age; + @Size(max = 100, message = "La dirección de residencia no debe exceder 100 caracteres") + private String residenceAddress; + @Size(max = 100, message = "La dirección local no debe exceder 100 caracteres") + private String localAddress; + @Pattern(regexp = "^[0-9]+$", message = "El número de teléfono debe contener solo números") + private String phoneNumber; + @Email(message = "El correo personal no tiene un formato válido") + private String personalEmail; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El cargo solo debe contener letras") + private String position; + @ManyToOne + @JoinColumn(name = "team_id", nullable = false) + private Team team; + @Size(max = 100, message = "El nombre de contacto de emergencia no debe exceder 100 caracteres") + private String emergencyCName; + @Size(max = 100, message = "La dirección de contacto de emergencia no debe exceder 100 caracteres") + private String emergencyCAddress; + @Pattern(regexp = "^[0-9]+$", message = "El teléfono de contacto de emergencia debe contener solo números") + private String emergencyCPhone; + @Email(message = "El correo de contacto de emergencia no tiene un formato válido") + private String emergencyCEmail; + @Pattern(regexp = "^[0-9]+$", message = "La cantidad de hijos debe contener solo números") + private String numberOfChildren; + @Pattern(regexp = "^[0-9]+$", message = "El CI debe contener solo números") + private String ci; + private String issuedIn; + @Size(max = 100, message = "El título no debe exceder 100 caracteres") + private String pTitle1; + private String pTitle2; + private String pTitle3; - private String pTitle1; - private String pTitle2; - private String pTitle3; + private String pStudy1; + private String pStudy2; + private String pStudy3; - private String pStudy1; - private String pStudy2; - private String pStudy3; + private String certification1; + private String certification2; + private String certification3; + private String certification4; + @Size(max = 255, message = "El reconocimiento no debe exceder 255 caracteres") + private String recognition; + @Size(max = 500, message = "Los logros no deben exceder 500 caracteres") + private String achievements; - private String certification1; - private String certification2; - private String certification3; - private String certification4; + private String language; + private String languageLevel; + @Pattern(regexp = "^[A-Za-z0-9]+$", message = "El código debe contener solo letras y números") + private String cod; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El lead manager solo debe contener letras") + private String leadManager; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El proyecto solo debe contener letras") + private String project; - private String recognition; - private String achievements; + private LocalDate dateOfEntry; + private LocalDate dateOfExit; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El tipo de contrato solo debe contener letras") + private String contractType; + @Pattern(regexp = "^[0-9]+$", message = "La antigüedad debe contener solo números") + private String seniority; + @Pattern(regexp = "^[0-9]+(\\.[0-9]{1,2})?$", message = "El salario debe ser un número con hasta dos decimales") + private String salary; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "El nombre del banco solo debe contener letras") + private String bankName; + @Pattern(regexp = "^[0-9]+$", message = "El número de cuenta debe contener solo números") + private String accountNumber; - private String language; - private String languageLevel; + private String gpss; + private String sss; + @Pattern(regexp = "^[a-zA-Z ]+$", message = "Los derechohabientes solo deben contener letras") + private String beneficiaries; - private String cod; - private String leadManager; - private String project; + @Column(columnDefinition = "TEXT") + private String profileImage; + @Enumerated(EnumType.STRING) + private Status status; - private LocalDate dateOfEntry; - private LocalDate dateOfExit; - - private String contractType; - private String seniority; - private String salary; - - private String bankName; - private String accountNumber; - - private String gpss; - private String sss; - private String beneficiaries; - - @Column(columnDefinition = "TEXT") - private String profileImage; - @Enumerated(EnumType.STRING) - private Status status; - - @Override - public Collection getAuthorities() { - return Lists.newArrayList(); - } - - @Override - public String getPassword() { - return null; - } - - @Override - public String getUsername() { - return this.username; - } - - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return true; - } - - public enum Status { - ACTIVE, - INACTIVE - } - @Enumerated(EnumType.STRING) - private MaritalStatus maritalStatus; - public enum MaritalStatus { - SINGLE, - MARRIED, - WIDOWED, - DIVORCED - } - @Enumerated(EnumType.STRING) - private Gender gender; - public enum Gender { - MALE, - FEMALE - } - - public Status getStatus() { - - return status; - } - public void setStatus(final Status status) { - this.status = status; - } + @Override + public Collection getAuthorities() { + return Lists.newArrayList(); } + + @Override + public String getPassword() { + return null; + } + + @Override + public String getUsername() { + return this.username; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } + + public enum Status { + ACTIVE, + INACTIVE + } + + @Enumerated(EnumType.STRING) + private MaritalStatus maritalStatus; + + public enum MaritalStatus { + SINGLE, + MARRIED, + WIDOWED, + DIVORCED + } + + @Enumerated(EnumType.STRING) + private Gender gender; + + public enum Gender { + MALE, + FEMALE + } +} diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 448b5b5..43e01f7 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -1,10 +1,10 @@ package com.primefactorsolutions.views; -import com.primefactorsolutions.model.Employee; -import com.primefactorsolutions.model.Team; +import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.ReportService; import com.primefactorsolutions.service.TeamService; +import com.primefactorsolutions.service.TimeOffRequestService; import com.vaadin.componentfactory.pdfviewer.PdfViewer; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; @@ -24,6 +24,9 @@ import com.vaadin.flow.component.textfield.EmailField; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.upload.Upload; import com.vaadin.flow.component.upload.receivers.MemoryBuffer; +import com.vaadin.flow.data.binder.Result; +import com.vaadin.flow.data.binder.ValueContext; +import com.vaadin.flow.data.converter.Converter; import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.router.*; import com.vaadin.flow.server.StreamResource; @@ -36,6 +39,8 @@ import org.vaadin.firitin.form.BeanValidationForm; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.Base64; import java.util.List; import java.util.UUID; @@ -49,8 +54,10 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final EmployeeService employeeService; private final ReportService reportService; + private final TimeOffRequestService requestService; private final TeamService teamService; + // TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente. private final TextField username = createTextField("Username: ", 30, true); private final TextField firstName = createTextField("Nombres: ", 30, true); @@ -140,10 +147,12 @@ public class EmployeeView extends BeanValidationForm implements HasUrl public EmployeeView(final EmployeeService employeeService, final ReportService reportService, - final TeamService teamService) { + final TeamService teamService, + final TimeOffRequestService requestService) { super(Employee.class); this.employeeService = employeeService; this.reportService = reportService; + this.requestService = requestService; this.teamService = teamService; saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); @@ -156,12 +165,18 @@ public class EmployeeView extends BeanValidationForm implements HasUrl phoneNumber.addValueChangeListener(e -> validatePhoneNumber(phoneNumber, e.getValue())); emergencyCPhone.setValueChangeMode(ValueChangeMode.EAGER); emergencyCPhone.addValueChangeListener(e -> validatePhoneNumber(emergencyCPhone, e.getValue())); + + firstName.setValueChangeMode(ValueChangeMode.EAGER); + firstName.addValueChangeListener(e -> validateNameField(firstName, e.getValue())); + lastName.setValueChangeMode(ValueChangeMode.EAGER); + lastName.addValueChangeListener(e -> validateNameField(lastName, e.getValue())); + createTeamComboBox(); + configureUpload(); saveButton.setVisible(true); editButton.setVisible(true); reportButton.setVisible(true); birthday.addValueChangeListener(event -> calculateAge()); - createTeamComboBox(); reportButton.addClickListener((ComponentEventListener>) buttonClickEvent -> { var employee = getEntity(); @@ -174,6 +189,15 @@ public class EmployeeView extends BeanValidationForm implements HasUrl initDialog(); } + private void validateNameField(TextField textField, String value) { + if (!value.matches("^[a-zA-ZáéíóúÁÉÍÓÚñÑ\\s]*$")) { + textField.setInvalid(true); + textField.setErrorMessage("Este campo solo debe contener letras."); + } else { + textField.setInvalid(false); + } + } + private void calculateAge() { if (birthday.getValue() != null) { int currentYear = java.time.LocalDate.now().getYear(); @@ -244,7 +268,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl ComboBox comboBox = new ComboBox<>("Estado"); comboBox.setItems(Employee.Status.values()); comboBox.setItemLabelGenerator(Employee.Status::name); - comboBox.setRequiredIndicatorVisible(true); // Indicador de campo requerido + comboBox.setRequiredIndicatorVisible(true); return comboBox; } @@ -276,6 +300,14 @@ public class EmployeeView extends BeanValidationForm implements HasUrl team.setWidthFull(); } + private ComboBox createComboBox(final String label, final T[] items) { + ComboBox comboBox = new ComboBox<>(label); + comboBox.setItems(items); + comboBox.setItemLabelGenerator(Object::toString); + comboBox.setWidthFull(); + return comboBox; + } + private ComboBox createGenderComboBox() { ComboBox comboBox = new ComboBox<>("Genero"); comboBox.setItems(Employee.Gender.values()); @@ -288,12 +320,33 @@ public class EmployeeView extends BeanValidationForm implements HasUrl return !firstName.isEmpty() && !lastName.isEmpty() && status.getValue() != null; } + private void setVacationDuration(Employee employee, TimeOffRequest request, LocalDate referenceDate) { + double yearsOfService = ChronoUnit.YEARS.between(employee.getDateOfEntry(), referenceDate); + request.setAvailableDays(calculateAvailableDays(yearsOfService)); + } + + private double calculateAvailableDays(double yearsOfService) { + if (yearsOfService > 10) { + return 30.0; + } else if (yearsOfService > 5) { + return 20.0; + } else if (yearsOfService > 1) { + return 15.0; + } else { + return 0.0; + } + } + private void saveEmployee() { if (validateForm()) { Employee employee = getEntity(); 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)); @@ -302,13 +355,60 @@ public class EmployeeView extends BeanValidationForm implements HasUrl } } + private void processTimeOffRequests(Employee employee) { + if (hasTimeOffRequests(employee)) { + updateExistingTimeOffRequests(employee); + } else { + createAndSaveTimeOffRequests(employee); + } + } + + private boolean hasTimeOffRequests(Employee employee) { + return !requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL).isEmpty() || + !requestService.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR).isEmpty(); + } + + private void updateExistingTimeOffRequests(Employee employee) { + updateTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR, -1, 729); + updateTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL, 0, 1094); + } + + private void updateTimeOffRequest(Employee employee, TimeOffRequestType category, int yearOffset, int daysToAdd) { + List requests = requestService.findByEmployeeAndCategory(employee.getId(), category); + if (!requests.isEmpty()) { + TimeOffRequest request = requests.getLast(); + LocalDate newBaseDate = LocalDate.of(LocalDate.now().getYear() + yearOffset, employee.getDateOfEntry().getMonth(), employee.getDateOfEntry().getDayOfMonth()); + request.setExpiration(newBaseDate.plusDays(daysToAdd)); + setVacationDuration(employee, request, newBaseDate); + requestService.saveTimeOffRequest(request); + } + } + + private void createAndSaveTimeOffRequests(Employee employee) { + requestService.saveTimeOffRequest(createTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ANTERIOR, -1, 729)); + requestService.saveTimeOffRequest(createTimeOffRequest(employee, TimeOffRequestType.VACACION_GESTION_ACTUAL, 0, 1094)); + } + + private TimeOffRequest createTimeOffRequest(Employee employee, TimeOffRequestType category, int yearOffset, int daysToAdd) { + LocalDate baseDate = LocalDate.of(LocalDate.now().getYear() + yearOffset, employee.getDateOfEntry().getMonth(), employee.getDateOfEntry().getDayOfMonth()); + LocalDate expirationDate = baseDate.plusDays(daysToAdd); + + TimeOffRequest request = new TimeOffRequest(); + request.setCategory(category); + request.setState(TimeOffRequestStatus.APROBADO); + request.setEmployee(employee); + request.setExpiration(expirationDate); + setVacationDuration(employee, request, baseDate); + + return request; + } + private void enableEditMode() { setFieldsEditable(); saveButton.setVisible(true); editButton.setVisible(false); } - @Override public void setParameter(final BeforeEvent beforeEvent, final String action) { final RouteParameters params = beforeEvent.getRouteParameters(); @@ -323,7 +423,6 @@ public class EmployeeView extends BeanValidationForm implements HasUrl UUID employeeId = UUID.fromString(s); var employee = employeeService.getEmployee(employeeId); setEntityWithEnabledSave(employee); - team.setValue(employee.getTeam()); if ("edit".equals(action) && !s.isEmpty()) { saveButton.setVisible(true); @@ -490,5 +589,4 @@ public class EmployeeView extends BeanValidationForm implements HasUrl saveButton, editButton, reportButton, dialog ); } -} - +} \ No newline at end of file From cb34868b9c89d341f552848f83fdaccc03be8c1f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 7 Nov 2024 15:42:42 -0400 Subject: [PATCH 17/20] 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) From f7e7dea7cb3bb235389b894c997e7bb6db414d14 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 7 Nov 2024 18:29:33 -0400 Subject: [PATCH 18/20] #37 Perfil de Personal Administrativo - Listado General de Vacaciones (Calcular automadicamente dias de las vacaciones gestion actual y anterior) --- .../views/RequestsListView.java | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 1f69ed8..b98c6fd 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -164,8 +164,10 @@ public class RequestsListView extends Main { List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List vacations = vacationService.findVacations(); double totalUtilized = calculateTotalUtilized(employeeRequests); + double totalVacations = calculateVacationDays(employee); double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee); - double generalTotal = totalAvailable - totalUtilized; + + double generalTotal = totalAvailable + totalVacations - totalUtilized; return String.valueOf(generalTotal); } @@ -195,16 +197,41 @@ public class RequestsListView extends Main { .sum(); } + private double calculateVacationDays(final Employee employee) { + if (employee.getDateOfEntry() != null) { + LocalDate entryDate = employee.getDateOfEntry(); + LocalDate today = LocalDate.now(); + + boolean hasAnniversaryPassed = entryDate.getMonthValue() < today.getMonthValue() + || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() <= today.getDayOfMonth()); + + LocalDate previousVacationYearDate; + LocalDate currentVacationYearDate; + + if (hasAnniversaryPassed) { + previousVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + currentVacationYearDate = LocalDate.of(today.getYear(), entryDate.getMonth(), entryDate.getDayOfMonth()); + } else { + previousVacationYearDate = LocalDate.of(today.getYear() - 2, entryDate.getMonth(), entryDate.getDayOfMonth()); + currentVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + } + + return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) + + calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); + } else { + return 0.0; + } + } + private double calculateTotalAvailable(final List vacations, final List employeeRequests, final Employee employee) { - double vacationDays = calculateVacationDaysBasedOnService(employee.getDateOfEntry()); Set excludedCategories = getExcludedCategories(); Set genderSpecificExclusions = getGenderSpecificExclusions(); Set employeeRequestCategories = employeeRequests.stream() .map(TimeOffRequest::getCategory) .collect(Collectors.toSet()); - double availableVacationDays = vacations.stream() + return vacations.stream() .filter(Objects::nonNull) .filter(vacation -> shouldIncludeVacation( vacation, @@ -214,22 +241,20 @@ public class RequestsListView extends Main { )) .mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0) .sum(); - - return vacationDays + availableVacationDays; } - private double calculateVacationDaysBasedOnService(final LocalDate dateOfEntry) { - int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, LocalDate.now()).getYears() : 0; - if (yearsOfService < 1) { - return 0; + private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) { + int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0; + if (yearsOfService > 10) { + return 30; } - if (yearsOfService <= 5) { - return 15; - } - if (yearsOfService <= 10) { + if (yearsOfService > 5) { return 20; } - return 30; + if (yearsOfService > 1) { + return 15; + } + return 0; } private boolean shouldIncludeVacation(final Vacation vacation, From 5e37cbbcd0c33f275b1a7a7dc57e3cea644a830d Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 7 Nov 2024 18:29:33 -0400 Subject: [PATCH 19/20] Perfil de Personal Administrativo - Listado Vacaciones de empleado (Calcular automadicamente dias de las vacaciones gestion actual y anterior) --- .../views/RequestEmployeeView.java | 46 ++++++++++++++-- .../views/RequestsListView.java | 52 ++++++++++++++----- 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index d72bf12..526aa37 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -21,6 +21,8 @@ import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; 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; @@ -109,10 +111,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .filter(this::verificationIsHoliday) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); - double totalVacations = requests.stream() - .filter(req -> req.getCategory().toString().startsWith("VACACION")) - .mapToDouble(TimeOffRequest::getAvailableDays) - .sum(); + double totalVacations = calculateVacationDays(employeeService.getEmployee(employeeId)); double totalPersonalDays = requests.stream() .filter(req -> !verificationIsHoliday(req)) .filter(req -> !req.getCategory().name().startsWith("VACACION")) @@ -129,6 +128,45 @@ public class RequestEmployeeView extends Div implements HasUrlParameter ); } + private double calculateVacationDays(final Employee employee) { + if (employee.getDateOfEntry() != null) { + LocalDate entryDate = employee.getDateOfEntry(); + LocalDate today = LocalDate.now(); + + boolean hasAnniversaryPassed = entryDate.getMonthValue() < today.getMonthValue() + || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() <= today.getDayOfMonth()); + + LocalDate previousVacationYearDate, currentVacationYearDate; + + if (hasAnniversaryPassed) { + previousVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + currentVacationYearDate = LocalDate.of(today.getYear(), entryDate.getMonth(), entryDate.getDayOfMonth()); + } else { + previousVacationYearDate = LocalDate.of(today.getYear() - 2, entryDate.getMonth(), entryDate.getDayOfMonth()); + currentVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + } + + return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) + + calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); + } else { + return 0.0; + } + } + + private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) { + int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0; + if (yearsOfService > 10) { + return 30; + } + if (yearsOfService > 5) { + return 20; + } + if (yearsOfService > 1) { + return 15; + } + return 0; + } + private Boolean verificationIsHoliday(final TimeOffRequest request) { Vacation vacation = vacationService.findVacationByCategory(request.getCategory()); return vacation.getType() != Vacation.Type.OTHER; diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 1f69ed8..c238ca4 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -164,8 +164,10 @@ public class RequestsListView extends Main { List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List vacations = vacationService.findVacations(); double totalUtilized = calculateTotalUtilized(employeeRequests); + double totalVacations = calculateVacationDays(employee); double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee); - double generalTotal = totalAvailable - totalUtilized; + + double generalTotal = totalAvailable + totalVacations - totalUtilized; return String.valueOf(generalTotal); } @@ -195,16 +197,40 @@ public class RequestsListView extends Main { .sum(); } + private double calculateVacationDays(final Employee employee) { + if (employee.getDateOfEntry() != null) { + LocalDate entryDate = employee.getDateOfEntry(); + LocalDate today = LocalDate.now(); + + boolean hasAnniversaryPassed = entryDate.getMonthValue() < today.getMonthValue() + || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() <= today.getDayOfMonth()); + + LocalDate previousVacationYearDate, currentVacationYearDate; + + if (hasAnniversaryPassed) { + previousVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + currentVacationYearDate = LocalDate.of(today.getYear(), entryDate.getMonth(), entryDate.getDayOfMonth()); + } else { + previousVacationYearDate = LocalDate.of(today.getYear() - 2, entryDate.getMonth(), entryDate.getDayOfMonth()); + currentVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + } + + return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) + + calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); + } else { + return 0.0; + } + } + private double calculateTotalAvailable(final List vacations, final List employeeRequests, final Employee employee) { - double vacationDays = calculateVacationDaysBasedOnService(employee.getDateOfEntry()); Set excludedCategories = getExcludedCategories(); Set genderSpecificExclusions = getGenderSpecificExclusions(); Set employeeRequestCategories = employeeRequests.stream() .map(TimeOffRequest::getCategory) .collect(Collectors.toSet()); - double availableVacationDays = vacations.stream() + return vacations.stream() .filter(Objects::nonNull) .filter(vacation -> shouldIncludeVacation( vacation, @@ -214,22 +240,20 @@ public class RequestsListView extends Main { )) .mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0) .sum(); - - return vacationDays + availableVacationDays; } - private double calculateVacationDaysBasedOnService(final LocalDate dateOfEntry) { - int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, LocalDate.now()).getYears() : 0; - if (yearsOfService < 1) { - return 0; + private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) { + int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0; + if (yearsOfService > 10) { + return 30; } - if (yearsOfService <= 5) { - return 15; - } - if (yearsOfService <= 10) { + if (yearsOfService > 5) { return 20; } - return 30; + if (yearsOfService > 1) { + return 15; + } + return 0; } private boolean shouldIncludeVacation(final Vacation vacation, From 39222204390bfd9162d231202dc2d4fbf00491b0 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 7 Nov 2024 18:53:47 -0400 Subject: [PATCH 20/20] Resolver errores de checkstyle --- .../views/RequestEmployeeView.java | 30 +++++++++++++++---- .../views/RequestsListView.java | 30 +++++++++++++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 526aa37..50445d4 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -134,16 +134,34 @@ public class RequestEmployeeView extends Div implements HasUrlParameter LocalDate today = LocalDate.now(); boolean hasAnniversaryPassed = entryDate.getMonthValue() < today.getMonthValue() - || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() <= today.getDayOfMonth()); + || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() + <= today.getDayOfMonth()); - LocalDate previousVacationYearDate, currentVacationYearDate; + LocalDate previousVacationYearDate; + LocalDate currentVacationYearDate; if (hasAnniversaryPassed) { - previousVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); - currentVacationYearDate = LocalDate.of(today.getYear(), entryDate.getMonth(), entryDate.getDayOfMonth()); + previousVacationYearDate = LocalDate.of( + today.getYear() - 1, + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); + currentVacationYearDate = LocalDate.of( + today.getYear(), + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); } else { - previousVacationYearDate = LocalDate.of(today.getYear() - 2, entryDate.getMonth(), entryDate.getDayOfMonth()); - currentVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + previousVacationYearDate = LocalDate.of( + today.getYear() - 2, + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); + currentVacationYearDate = LocalDate.of( + today.getYear() - 1, + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); } return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index c238ca4..73c2cbf 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -203,16 +203,34 @@ public class RequestsListView extends Main { LocalDate today = LocalDate.now(); boolean hasAnniversaryPassed = entryDate.getMonthValue() < today.getMonthValue() - || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() <= today.getDayOfMonth()); + || (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() + <= today.getDayOfMonth()); - LocalDate previousVacationYearDate, currentVacationYearDate; + LocalDate previousVacationYearDate; + LocalDate currentVacationYearDate; if (hasAnniversaryPassed) { - previousVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); - currentVacationYearDate = LocalDate.of(today.getYear(), entryDate.getMonth(), entryDate.getDayOfMonth()); + previousVacationYearDate = LocalDate.of( + today.getYear() - 1, + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); + currentVacationYearDate = LocalDate.of( + today.getYear(), + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); } else { - previousVacationYearDate = LocalDate.of(today.getYear() - 2, entryDate.getMonth(), entryDate.getDayOfMonth()); - currentVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth()); + previousVacationYearDate = LocalDate.of( + today.getYear() - 2, + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); + currentVacationYearDate = LocalDate.of( + today.getYear() - 1, + entryDate.getMonth(), + entryDate.getDayOfMonth() + ); } return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate)