Vacaciones #61
@ -24,7 +24,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@SpringComponent
|
@SpringComponent
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@ -132,7 +131,8 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
categoryComboBox.setItems(availableCategories);
|
categoryComboBox.setItems(availableCategories);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCategoryAvailable(List<TimeOffRequest> employeeRequests, TimeOffRequestType category) {
|
private boolean isCategoryAvailable(final List<TimeOffRequest> employeeRequests,
|
||||||
|
final TimeOffRequestType category) {
|
||||||
List<TimeOffRequest> requestsByCategory = employeeRequests.stream()
|
List<TimeOffRequest> requestsByCategory = employeeRequests.stream()
|
||||||
.filter(request -> request.getCategory() == category)
|
.filter(request -> request.getCategory() == category)
|
||||||
.toList();
|
.toList();
|
||||||
@ -148,7 +148,7 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED;
|
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCategoryAllowedByGender(TimeOffRequestType category, Employee.Gender gender) {
|
private boolean isCategoryAllowedByGender(final TimeOffRequestType category, final Employee.Gender gender) {
|
||||||
if (gender == Employee.Gender.MALE) {
|
if (gender == Employee.Gender.MALE) {
|
||||||
return category != TimeOffRequestType.MATERNITY
|
return category != TimeOffRequestType.MATERNITY
|
||||||
&& category != TimeOffRequestType.MOTHERS_DAY
|
&& category != TimeOffRequestType.MOTHERS_DAY
|
||||||
@ -196,29 +196,43 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
|
|
||||||
private void setDatePickerLimits(final Vacation vacation) {
|
private void setDatePickerLimits(final Vacation vacation) {
|
||||||
LocalDate startDate;
|
LocalDate startDate;
|
||||||
|
endDate = null;
|
||||||
|
|
||||||
if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) {
|
if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) {
|
||||||
startDate = LocalDate.of(LocalDate.now().getYear(), vacation.getMonthOfYear(), vacation.getDayOfMonth());
|
startDate = LocalDate.of(
|
||||||
|
LocalDate.now().getYear(),
|
||||||
|
vacation.getMonthOfYear().intValue(),
|
||||||
|
vacation.getDayOfMonth().intValue()
|
||||||
|
);
|
||||||
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||||
startDatePicker.setValue(startDate);
|
|
||||||
endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1));
|
|
||||||
} else {
|
} else {
|
||||||
if (vacation.getCategory() == TimeOffRequestType.BIRTHDAY) {
|
if (vacation.getCategory() == TimeOffRequestType.BIRTHDAY && employee.getBirthday() != null) {
|
||||||
startDate = employee.getBirthday();
|
startDate = employee.getBirthday();
|
||||||
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||||
startDatePicker.setValue(startDate);
|
} else if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) {
|
||||||
endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1));
|
startDate = LocalDate.now();
|
||||||
|
endDate = LocalDate.of(LocalDate.now().getYear(), 12, 31);
|
||||||
} else {
|
} else {
|
||||||
startDate = LocalDate.now();
|
startDate = LocalDate.now();
|
||||||
endDate = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
startDatePicker.setValue(startDate);
|
||||||
|
|
||||||
|
if ((vacation.getDuration() != null && vacation.getDuration() == 0.5)
|
||||||
|
|| vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) {
|
||||||
|
endDatePicker.setValue(startDate);
|
||||||
|
} else {
|
||||||
|
int durationDays = (vacation.getDuration() != null ? vacation.getDuration().intValue() - 1 : 0);
|
||||||
|
endDatePicker.setValue(startDate.plusDays(durationDays));
|
||||||
|
}
|
||||||
|
|
||||||
startDatePicker.setMin(startDate);
|
startDatePicker.setMin(startDate);
|
||||||
startDatePicker.setMax(endDate);
|
startDatePicker.setMax(endDate);
|
||||||
endDatePicker.setMin(startDate);
|
endDatePicker.setMin(startDate);
|
||||||
endDatePicker.setMax(endDate);
|
endDatePicker.setMax(endDate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateDatePickerMinValues() {
|
private void updateDatePickerMinValues() {
|
||||||
LocalDate startDate = startDatePicker.getValue();
|
LocalDate startDate = startDatePicker.getValue();
|
||||||
if (vacation.getDuration() == 0.5) {
|
if (vacation.getDuration() == 0.5) {
|
||||||
@ -236,15 +250,12 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
|
|
||||||
if (startDate != null && endDate != null) {
|
if (startDate != null && endDate != null) {
|
||||||
double daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
double daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||||
if (daysToBeTaken == 1 && vacation.getDuration() == 0.5) {
|
if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT || vacation.getDuration() == 0.5) {
|
||||||
daysToBeTaken = 0.5;
|
|
||||||
}
|
|
||||||
if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT && daysToBeTaken == 1) {
|
|
||||||
daysToBeTakenField.setValue(0.5);
|
daysToBeTakenField.setValue(0.5);
|
||||||
} else {
|
} else {
|
||||||
daysToBeTakenField.setValue(daysToBeTaken);
|
daysToBeTakenField.setValue(daysToBeTaken);
|
||||||
}
|
}
|
||||||
double balanceDays = availableDays - daysToBeTaken;
|
double balanceDays = availableDays - daysToBeTakenField.getValue();
|
||||||
balanceDaysField.setValue(balanceDays);
|
balanceDaysField.setValue(balanceDays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,18 +283,19 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
if (binder.validate().isOk()) {
|
if (binder.validate().isOk()) {
|
||||||
TimeOffRequest request = binder.getBean();
|
TimeOffRequest request = binder.getBean();
|
||||||
request.setStartDate(startDatePicker.getValue());
|
request.setStartDate(startDatePicker.getValue());
|
||||||
if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) {
|
request.setAvailableDays(availableDaysField.getValue());
|
||||||
request.setExpiration(LocalDate.of(LocalDate.now().getYear(), 12, 31));
|
request.setExpiration(endDate);
|
||||||
} else if (request.getExpiration() == null) {
|
request.setState(TimeOffRequestStatus.REQUESTED);
|
||||||
request.setExpiration(startDatePicker.getValue().plusDays(vacation.getExpiration().intValue() - 1));
|
|
||||||
}
|
List<TimeOffRequest> existingRequests =
|
||||||
List<TimeOffRequest> existingRequests = requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
|
requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
|
||||||
|
|
||||||
if (existingRequests.size() >= 2) {
|
if (existingRequests.size() >= 2) {
|
||||||
existingRequests.stream().min(Comparator.comparing(TimeOffRequest::getStartDate)).ifPresent(oldestRequest -> requestService.deleteTimeOffRequest(oldestRequest.getId()));
|
existingRequests.stream()
|
||||||
|
.min(Comparator.comparing(TimeOffRequest::getStartDate))
|
||||||
|
.ifPresent(oldestRequest -> requestService.deleteTimeOffRequest(oldestRequest.getId()));
|
||||||
}
|
}
|
||||||
request.setState(TimeOffRequestStatus.REQUESTED);
|
|
||||||
updateBalanceForCategory(request);
|
updateBalanceForCategory(request);
|
||||||
requestService.saveTimeOffRequest(request);
|
requestService.saveTimeOffRequest(request);
|
||||||
Notification.show("Request saved successfully.");
|
Notification.show("Request saved successfully.");
|
||||||
|
Loading…
Reference in New Issue
Block a user