Vacaciones #58
@ -19,6 +19,7 @@ import jakarta.annotation.security.PermitAll;
|
|||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringComponent
|
@SpringComponent
|
||||||
@ -65,11 +66,12 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
employeeComboBox.setItems(employees);
|
employeeComboBox.setItems(employees);
|
||||||
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
|
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
|
||||||
categoryComboBox.setEnabled(false);
|
categoryComboBox.setEnabled(false);
|
||||||
categoryComboBox.setItems(TimeOffRequestType.values());
|
|
||||||
categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue()));
|
categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue()));
|
||||||
employeeComboBox.addValueChangeListener(event -> {
|
employeeComboBox.addValueChangeListener(event -> {
|
||||||
|
Employee selectedEmployee = event.getValue();
|
||||||
if (event.getValue() != null) {
|
if (event.getValue() != null) {
|
||||||
categoryComboBox.setEnabled(true);
|
categoryComboBox.setEnabled(true);
|
||||||
|
filterCategories(selectedEmployee);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues());
|
startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues());
|
||||||
@ -79,6 +81,17 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
balanceDaysField.setReadOnly(true);
|
balanceDaysField.setReadOnly(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void filterCategories(Employee employee) {
|
||||||
|
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
||||||
|
List<TimeOffRequestType> requestedCategories = employeeRequests.stream()
|
||||||
|
.map(TimeOffRequest::getCategory)
|
||||||
|
.toList();
|
||||||
|
List<TimeOffRequestType> availableCategories = Arrays.stream(TimeOffRequestType.values())
|
||||||
|
.filter(category -> !requestedCategories.contains(category))
|
||||||
|
.toList();
|
||||||
|
categoryComboBox.setItems(availableCategories);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateAvailableDays(TimeOffRequestType selectedCategory) {
|
private void updateAvailableDays(TimeOffRequestType selectedCategory) {
|
||||||
if (selectedCategory != null) {
|
if (selectedCategory != null) {
|
||||||
Vacation vacation = vacationService.findVacationByCategory(selectedCategory);
|
Vacation vacation = vacationService.findVacationByCategory(selectedCategory);
|
||||||
|
@ -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 ('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 ('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 ('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');
|
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');
|
||||||
|
Loading…
Reference in New Issue
Block a user