#37 Perfil de Personal Administrativo - Listado General de Vacaciones (Calcular automadicamente dias de las vacaciones gestion actual y anterior)
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 21s
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 21s
This commit is contained in:
parent
cb34868b9c
commit
f7e7dea7cb
@ -164,8 +164,10 @@ public class RequestsListView extends Main {
|
||||
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
||||
List<Vacation> vacations = vacationService.findVacations();
|
||||
double totalUtilized = calculateTotalUtilized(employeeRequests);
|
||||
double totalVacations = calculateVacationDays(employee);
|
||||
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
||||
double generalTotal = totalAvailable - totalUtilized;
|
||||
|
||||
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
||||
return String.valueOf(generalTotal);
|
||||
}
|
||||
|
||||
@ -195,16 +197,41 @@ public class RequestsListView extends Main {
|
||||
.sum();
|
||||
}
|
||||
|
||||
private double calculateVacationDays(final Employee employee) {
|
||||
if (employee.getDateOfEntry() != null) {
|
||||
LocalDate entryDate = employee.getDateOfEntry();
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
boolean hasAnniversaryPassed = entryDate.getMonthValue() < today.getMonthValue()
|
||||
|| (entryDate.getMonthValue() == today.getMonthValue() && entryDate.getDayOfMonth() <= today.getDayOfMonth());
|
||||
|
||||
LocalDate previousVacationYearDate;
|
||||
LocalDate currentVacationYearDate;
|
||||
|
||||
if (hasAnniversaryPassed) {
|
||||
previousVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth());
|
||||
currentVacationYearDate = LocalDate.of(today.getYear(), entryDate.getMonth(), entryDate.getDayOfMonth());
|
||||
} else {
|
||||
previousVacationYearDate = LocalDate.of(today.getYear() - 2, entryDate.getMonth(), entryDate.getDayOfMonth());
|
||||
currentVacationYearDate = LocalDate.of(today.getYear() - 1, entryDate.getMonth(), entryDate.getDayOfMonth());
|
||||
}
|
||||
|
||||
return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate)
|
||||
+ calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private double calculateTotalAvailable(final List<Vacation> vacations, final List<TimeOffRequest> employeeRequests,
|
||||
final Employee employee) {
|
||||
double vacationDays = calculateVacationDaysBasedOnService(employee.getDateOfEntry());
|
||||
Set<TimeOffRequestType> excludedCategories = getExcludedCategories();
|
||||
Set<TimeOffRequestType> genderSpecificExclusions = getGenderSpecificExclusions();
|
||||
Set<TimeOffRequestType> employeeRequestCategories = employeeRequests.stream()
|
||||
.map(TimeOffRequest::getCategory)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
double availableVacationDays = vacations.stream()
|
||||
return vacations.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(vacation -> shouldIncludeVacation(
|
||||
vacation,
|
||||
@ -214,22 +241,20 @@ public class RequestsListView extends Main {
|
||||
))
|
||||
.mapToDouble(vacation -> vacation.getDuration() != null ? vacation.getDuration() : 0.0)
|
||||
.sum();
|
||||
|
||||
return vacationDays + availableVacationDays;
|
||||
}
|
||||
|
||||
private double calculateVacationDaysBasedOnService(final LocalDate dateOfEntry) {
|
||||
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, LocalDate.now()).getYears() : 0;
|
||||
if (yearsOfService < 1) {
|
||||
return 0;
|
||||
private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {
|
||||
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0;
|
||||
if (yearsOfService > 10) {
|
||||
return 30;
|
||||
}
|
||||
if (yearsOfService <= 5) {
|
||||
return 15;
|
||||
}
|
||||
if (yearsOfService <= 10) {
|
||||
if (yearsOfService > 5) {
|
||||
return 20;
|
||||
}
|
||||
return 30;
|
||||
if (yearsOfService > 1) {
|
||||
return 15;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean shouldIncludeVacation(final Vacation vacation,
|
||||
|
Loading…
Reference in New Issue
Block a user