From 69c61e093e5d76415514a06e4eb1f675bd55a366 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Mon, 21 Oct 2024 12:14:26 -0400 Subject: [PATCH] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrativo?= =?UTF-8?q?=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Configuara?= =?UTF-8?q?=20fecha=20manual)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestRegisterView.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index cd73249..4fc4122 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -67,7 +67,10 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItems(employees); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); categoryComboBox.setEnabled(false); - categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); + categoryComboBox.addValueChangeListener(event -> { + clearForm(); + updateAvailableDays(event.getValue()); + }); employeeComboBox.addValueChangeListener(event -> { clearForm(); Employee selectedEmployee = event.getValue(); @@ -116,22 +119,37 @@ public class RequestRegisterView extends VerticalLayout { } private void setDatePickerLimits(Vacation vacation) { - LocalDate startDate = vacation.getVacationDate(); - endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + LocalDate startDate; + if (vacation.getVacationDate() != null) { + startDate = vacation.getVacationDate(); + endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + startDatePicker.setValue(startDate); + endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + + } else { + startDate = LocalDate.now(); + endDate = null; + } startDatePicker.setMin(startDate); startDatePicker.setMax(endDate); endDatePicker.setMin(startDate); endDatePicker.setMax(endDate); - startDatePicker.setValue(startDate); - endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); } private void updateDatePickerMinValues() { LocalDate startDate = startDatePicker.getValue(); + if (vacation.getVacationDate() == null) { + endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + } if (startDate != null) { endDatePicker.setMin(startDate); - endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + endDatePicker.setMax(startDate.plusDays(vacation.getExpiration().intValue() - 1)); + if (vacation.getDuration() == 0.5) { + endDatePicker.setValue(startDate.plusDays(0)); + } else { + endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + } calculateDays(); } } @@ -230,7 +248,6 @@ public class RequestRegisterView extends VerticalLayout { } private void clearForm() { - categoryComboBox.clear(); availableDaysField.clear(); startDatePicker.clear(); endDatePicker.clear();