correcciones
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m38s

This commit is contained in:
jesus.pelaez 2024-11-14 03:17:26 -04:00
parent b1e95cf8a5
commit a3e94040ff
4 changed files with 65 additions and 39 deletions

View File

@ -55,8 +55,15 @@ public class TimeOffRequestService {
public void updateRequestStatuses() { public void updateRequestStatuses() {
List<TimeOffRequest> requests = findAllTimeOffRequests(); List<TimeOffRequest> requests = findAllTimeOffRequests();
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
LocalDate startOfYear = LocalDate.of(now.getYear(), 1, 1);
requests.removeIf(request -> request.getCategory() == TimeOffRequestType.VACACION_GESTION_ANTERIOR);
for (TimeOffRequest request : requests) { for (TimeOffRequest request : requests) {
if (request.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL && now.isEqual(startOfYear)) {
request.setCategory(TimeOffRequestType.VACACION_GESTION_ANTERIOR);
}
if (request.getState() == TimeOffRequestStatus.APROBADO if (request.getState() == TimeOffRequestStatus.APROBADO
|| request.getState() == TimeOffRequestStatus.EN_USO) { || request.getState() == TimeOffRequestStatus.EN_USO) {
LocalDate startDate = request.getStartDate(); LocalDate startDate = request.getStartDate();
@ -64,11 +71,12 @@ public class TimeOffRequestService {
if (now.isAfter(endDate)) { if (now.isAfter(endDate)) {
request.setState(TimeOffRequestStatus.TOMADO); request.setState(TimeOffRequestStatus.TOMADO);
} else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) { } else if (now.isEqual(startDate) || (now.isAfter(startDate) && now.isBefore(endDate))) {
request.setState(TimeOffRequestStatus.EN_USO); request.setState(TimeOffRequestStatus.EN_USO);
} }
} }
} }
saveAll(requests); saveAll(requests);
} }
} }

View File

@ -131,6 +131,13 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
List<Vacation> vacations = vacationService.findVacations(); List<Vacation> vacations = vacationService.findVacations();
double healthLicence = 2;
List<TimeOffRequest> healthRequests = requestService
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.PERMISOS_DE_SALUD);
if (healthRequests != null && !healthRequests.isEmpty()) {
healthLicence = healthRequests.getLast().getDaysBalance();
}
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations); double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
double totalPersonalDays = calculatePersonalDays(vacations, isMale); double totalPersonalDays = calculatePersonalDays(vacations, isMale);
double totalVacationDays = calculateVacationDays(employee); double totalVacationDays = calculateVacationDays(employee);
@ -140,7 +147,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear); double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
double remainingPersonalDays = totalPersonalDays - utilizedPersonalDays; double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence;
double remainingVacationDays = totalVacationDays - utilizedVacationDays; double remainingVacationDays = totalVacationDays - utilizedVacationDays;
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays; double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
@ -166,6 +173,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
.filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !getStandardExclusions().contains(req.getCategory()))
.filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory())))
.filter(req -> !req.getCategory().name().startsWith("VACACION")) .filter(req -> !req.getCategory().name().startsWith("VACACION"))
.filter(req -> req.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
.mapToDouble(Vacation::getDuration) .mapToDouble(Vacation::getDuration)
.sum(); .sum();
} }
@ -235,6 +243,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
.filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !getStandardExclusions().contains(req.getCategory()))
.filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory())))
.filter(req -> !req.getCategory().name().startsWith("VACACION")) .filter(req -> !req.getCategory().name().startsWith("VACACION"))
.filter(req -> req.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
.filter(req -> getStartDateYear(req) == year) .filter(req -> getStartDateYear(req) == year)
.mapToDouble(TimeOffRequest::getDaysToBeTake) .mapToDouble(TimeOffRequest::getDaysToBeTake)
.sum(); .sum();

View File

@ -166,13 +166,20 @@ public class RequestRegisterView extends VerticalLayout {
.max(Comparator.comparing(TimeOffRequest::getStartDate)) .max(Comparator.comparing(TimeOffRequest::getStartDate))
.orElse(null); .orElse(null);
if (category == TimeOffRequestType.PERMISOS_DE_SALUD boolean isSpecialCategory = category == TimeOffRequestType.PERMISOS_DE_SALUD
|| category == TimeOffRequestType.VACACION_GESTION_ACTUAL || category == TimeOffRequestType.VACACION_GESTION_ACTUAL
|| category == TimeOffRequestType.VACACION_GESTION_ANTERIOR) { || category == TimeOffRequestType.VACACION_GESTION_ANTERIOR;
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO && latestRequest.getDaysBalance() > 0); if (isSpecialCategory) {
return (latestRequest.getState() == TimeOffRequestStatus.TOMADO
&& latestRequest.getDaysBalance() > 0)
|| latestRequest.getState() == TimeOffRequestStatus.RECHAZADO
|| (latestRequest.getState() == TimeOffRequestStatus.TOMADO
&& latestRequest.getDaysBalance() == 0
&& latestRequest.getExpiration().isBefore(LocalDate.now()));
} else { } else {
return latestRequest.getState() == TimeOffRequestStatus.VENCIDO return (latestRequest.getState() == TimeOffRequestStatus.TOMADO
&& latestRequest.getExpiration().isBefore(LocalDate.now()))
|| latestRequest.getState() == TimeOffRequestStatus.RECHAZADO; || latestRequest.getState() == TimeOffRequestStatus.RECHAZADO;
} }
} }
@ -199,30 +206,40 @@ public class RequestRegisterView extends VerticalLayout {
vacation = vacationService.findVacationByCategory(selectedCategory); vacation = vacationService.findVacationByCategory(selectedCategory);
UUID employeeId = employeeComboBox.getValue().getId(); UUID employeeId = employeeComboBox.getValue().getId();
List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(employeeId, selectedCategory); List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(employeeId, selectedCategory);
if (vacation != null) { if (vacation != null) {
TimeOffRequest requestWithBalance = requests.stream() TimeOffRequest requestWithBalance = requests.stream()
.filter(request -> request.getDaysBalance() > 0 .filter(request -> request.getDaysBalance() > 0
&& request.getState() != TimeOffRequestStatus.VENCIDO) && request.getState() != TimeOffRequestStatus.VENCIDO
&& request.getState() != TimeOffRequestStatus.RECHAZADO)
.max(Comparator.comparing(TimeOffRequest::getStartDate)) .max(Comparator.comparing(TimeOffRequest::getStartDate))
.orElse(null); .orElse(null);
if (requestWithBalance != null) { if (requestWithBalance != null) {
if (requestWithBalance.getState() == TimeOffRequestStatus.TOMADO) { if (requestWithBalance.getState() == TimeOffRequestStatus.TOMADO
&& requestWithBalance.getDaysBalance() > 0) {
availableDaysField.setValue(requestWithBalance.getDaysBalance()); availableDaysField.setValue(requestWithBalance.getDaysBalance());
} else if (requestWithBalance.getState() == TimeOffRequestStatus.VENCIDO) { } else {
availableDaysField.setValue(vacation.getDuration()); availableDaysField.setValue(vacation.getDuration());
} }
} else if (vacation.getCategory() == TimeOffRequestType.VACACION_GESTION_ACTUAL) { } else if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL
|| selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) {
LocalDate dateOfEntry = employeeComboBox.getValue().getDateOfEntry(); LocalDate dateOfEntry = employeeComboBox.getValue().getDateOfEntry();
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
long yearsOfService = ChronoUnit.YEARS.between(dateOfEntry, currentDate); long yearsOfService = ChronoUnit.YEARS.between(dateOfEntry, currentDate);
if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) {
yearsOfService -= 1;
}
if (yearsOfService > 10) { if (yearsOfService > 10) {
availableDaysField.setValue((double) 30); availableDaysField.setValue(30.0);
} else if (yearsOfService > 5) { } else if (yearsOfService > 5) {
availableDaysField.setValue((double) 20); availableDaysField.setValue(20.0);
} else if (yearsOfService > 1) { } else if (yearsOfService > 1) {
availableDaysField.setValue((double) 15); availableDaysField.setValue(15.0);
} else { } else {
availableDaysField.setValue((double) 0); availableDaysField.setValue(0.0);
} }
} else { } else {
availableDaysField.setValue(vacation.getDuration()); availableDaysField.setValue(vacation.getDuration());
@ -257,20 +274,6 @@ public class RequestRegisterView extends VerticalLayout {
startDate = LocalDate.now(); startDate = LocalDate.now();
} }
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(vacation);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
System.out.println(startDate);
setPickerValues(vacation, startDate); setPickerValues(vacation, startDate);
setPickerLimits(startDate, endDate); setPickerLimits(startDate, endDate);
} }
@ -447,15 +450,10 @@ public class RequestRegisterView extends VerticalLayout {
List<TimeOffRequest> existingRequests = List<TimeOffRequest> existingRequests =
requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory()); requestService.findByEmployeeAndCategory(employee.getId(), request.getCategory());
int maxRequests; int maxRequests = request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD
&& !request.getCategory().name().startsWith("VACACION")
if (request.getCategory() == TimeOffRequestType.PERMISOS_DE_SALUD) { && request.getCategory() != TimeOffRequestType.CUMPLEAÑOS
maxRequests = 4; ? 2 : 1;
} else if (request.getCategory().name().startsWith("VACACION")) {
maxRequests = 2;
} else {
maxRequests = 1;
}
if (existingRequests.size() >= maxRequests) { if (existingRequests.size() >= maxRequests) {
existingRequests.stream() existingRequests.stream()

View File

@ -195,6 +195,7 @@ public class RequestsListView extends Main {
int currentYear = LocalDate.now().getYear(); int currentYear = LocalDate.now().getYear();
return employeeRequests.stream() return employeeRequests.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
.filter(request -> request.getStartDate() != null && ( .filter(request -> request.getStartDate() != null && (
request.getStartDate().getYear() == currentYear request.getStartDate().getYear() == currentYear
|| (request.getCategory().name().startsWith("VACACION") || (request.getCategory().name().startsWith("VACACION")
@ -255,8 +256,16 @@ public class RequestsListView extends Main {
.map(TimeOffRequest::getCategory) .map(TimeOffRequest::getCategory)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return vacations.stream() double healthLicence = 2;
List<TimeOffRequest> healthRequests = requestService
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.PERMISOS_DE_SALUD);
if (healthRequests != null && !healthRequests.isEmpty()) {
healthLicence = healthRequests.getLast().getDaysBalance();
}
double totalAvailable = vacations.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(vacation -> vacation.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
.filter(vacation -> shouldIncludeVacation( .filter(vacation -> shouldIncludeVacation(
vacation, vacation,
excludedCategories, excludedCategories,
@ -265,6 +274,8 @@ public class RequestsListView extends Main {
)) ))
.mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0) .mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0)
.sum(); .sum();
return totalAvailable + healthLicence;
} }
private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) { private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {