Perfil de Personal Administrativo - Listado Vacaciones de empleado (Calcular automadicamente dias de las vacaciones gestion actual y anterior)
This commit is contained in:
parent
cb34868b9c
commit
5e37cbbcd0
@ -21,6 +21,8 @@ import jakarta.annotation.security.PermitAll;
|
|||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.vaadin.firitin.components.grid.PagingGrid;
|
import org.vaadin.firitin.components.grid.PagingGrid;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Period;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -109,10 +111,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
.filter(this::verificationIsHoliday)
|
.filter(this::verificationIsHoliday)
|
||||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||||
.sum();
|
.sum();
|
||||||
double totalVacations = requests.stream()
|
double totalVacations = calculateVacationDays(employeeService.getEmployee(employeeId));
|
||||||
.filter(req -> req.getCategory().toString().startsWith("VACACION"))
|
|
||||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
|
||||||
.sum();
|
|
||||||
double totalPersonalDays = requests.stream()
|
double totalPersonalDays = requests.stream()
|
||||||
.filter(req -> !verificationIsHoliday(req))
|
.filter(req -> !verificationIsHoliday(req))
|
||||||
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
|
.filter(req -> !req.getCategory().name().startsWith("VACACION"))
|
||||||
@ -129,6 +128,45 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, 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 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 20;
|
||||||
|
}
|
||||||
|
if (yearsOfService > 1) {
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private Boolean verificationIsHoliday(final TimeOffRequest request) {
|
private Boolean verificationIsHoliday(final TimeOffRequest request) {
|
||||||
Vacation vacation = vacationService.findVacationByCategory(request.getCategory());
|
Vacation vacation = vacationService.findVacationByCategory(request.getCategory());
|
||||||
return vacation.getType() != Vacation.Type.OTHER;
|
return vacation.getType() != Vacation.Type.OTHER;
|
||||||
|
@ -164,8 +164,10 @@ public class RequestsListView extends Main {
|
|||||||
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
||||||
List<Vacation> vacations = vacationService.findVacations();
|
List<Vacation> vacations = vacationService.findVacations();
|
||||||
double totalUtilized = calculateTotalUtilized(employeeRequests);
|
double totalUtilized = calculateTotalUtilized(employeeRequests);
|
||||||
|
double totalVacations = calculateVacationDays(employee);
|
||||||
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
||||||
double generalTotal = totalAvailable - totalUtilized;
|
|
||||||
|
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
||||||
return String.valueOf(generalTotal);
|
return String.valueOf(generalTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,16 +197,40 @@ public class RequestsListView extends Main {
|
|||||||
.sum();
|
.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, 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,
|
private double calculateTotalAvailable(final List<Vacation> vacations, final List<TimeOffRequest> employeeRequests,
|
||||||
final Employee employee) {
|
final Employee employee) {
|
||||||
double vacationDays = calculateVacationDaysBasedOnService(employee.getDateOfEntry());
|
|
||||||
Set<TimeOffRequestType> excludedCategories = getExcludedCategories();
|
Set<TimeOffRequestType> excludedCategories = getExcludedCategories();
|
||||||
Set<TimeOffRequestType> genderSpecificExclusions = getGenderSpecificExclusions();
|
Set<TimeOffRequestType> genderSpecificExclusions = getGenderSpecificExclusions();
|
||||||
Set<TimeOffRequestType> employeeRequestCategories = employeeRequests.stream()
|
Set<TimeOffRequestType> employeeRequestCategories = employeeRequests.stream()
|
||||||
.map(TimeOffRequest::getCategory)
|
.map(TimeOffRequest::getCategory)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
double availableVacationDays = vacations.stream()
|
return vacations.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(vacation -> shouldIncludeVacation(
|
.filter(vacation -> shouldIncludeVacation(
|
||||||
vacation,
|
vacation,
|
||||||
@ -214,22 +240,20 @@ 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 vacationDays + availableVacationDays;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calculateVacationDaysBasedOnService(final LocalDate dateOfEntry) {
|
private double calculateVacationDaysSinceEntry(final LocalDate dateOfEntry, final LocalDate date) {
|
||||||
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, LocalDate.now()).getYears() : 0;
|
int yearsOfService = dateOfEntry != null ? Period.between(dateOfEntry, date).getYears() : 0;
|
||||||
if (yearsOfService < 1) {
|
if (yearsOfService > 10) {
|
||||||
return 0;
|
return 30;
|
||||||
}
|
}
|
||||||
if (yearsOfService <= 5) {
|
if (yearsOfService > 5) {
|
||||||
return 15;
|
|
||||||
}
|
|
||||||
if (yearsOfService <= 10) {
|
|
||||||
return 20;
|
return 20;
|
||||||
}
|
}
|
||||||
return 30;
|
if (yearsOfService > 1) {
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldIncludeVacation(final Vacation vacation,
|
private boolean shouldIncludeVacation(final Vacation vacation,
|
||||||
|
Loading…
Reference in New Issue
Block a user