From 1c18cd566ff3718370f49ad5df9fad24adec3e0f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 20 Oct 2024 18:24:40 -0400 Subject: [PATCH] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrativo?= =?UTF-8?q?=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Excluir=20l?= =?UTF-8?q?as=20categorias=20que=20cuenten=20con=20un=20registro)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestRegisterView.java | 15 ++++++++++++++- src/main/resources/data.sql | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index ba57022..6b5e4ac 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -19,6 +19,7 @@ import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; import java.time.LocalDate; +import java.util.Arrays; import java.util.List; @SpringComponent @@ -65,11 +66,12 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItems(employees); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); categoryComboBox.setEnabled(false); - categoryComboBox.setItems(TimeOffRequestType.values()); categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); employeeComboBox.addValueChangeListener(event -> { + Employee selectedEmployee = event.getValue(); if (event.getValue() != null) { categoryComboBox.setEnabled(true); + filterCategories(selectedEmployee); } }); startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues()); @@ -79,6 +81,17 @@ public class RequestRegisterView extends VerticalLayout { balanceDaysField.setReadOnly(true); } + private void filterCategories(Employee employee) { + List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); + List requestedCategories = employeeRequests.stream() + .map(TimeOffRequest::getCategory) + .toList(); + List availableCategories = Arrays.stream(TimeOffRequestType.values()) + .filter(category -> !requestedCategories.contains(category)) + .toList(); + categoryComboBox.setItems(availableCategories); + } + private void updateAvailableDays(TimeOffRequestType selectedCategory) { if (selectedCategory != null) { Vacation vacation = vacationService.findVacationByCategory(selectedCategory); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 39efdb3..cd96f24 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -25,7 +25,7 @@ INSERT INTO vacation (id, version, category, vacation_date, duration, expiration INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'CHRISTMAS', '2024-12-25', 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', '2024-01-21', 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', '2024-01-21', 3, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('923e4567-e89b-12d3-a456-426614174008', 1, 'CORPUS_CHRISTI', '2024-05-30', 1, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('a23e4567-e89b-12d3-a456-426614174009', 1, 'ANDEAN_NEW_YEAR', '2024-06-21', 1, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('b23e4567-e89b-12d3-a456-42661417400a', 1, 'DEPARTMENTAL_ANNIVERSARY', '2024-09-14', 1, 30, 'MOVABLE');