Lista de Solicitudes de empleado - actualizar resumen
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 24s

This commit is contained in:
jesus.pelaez 2024-11-14 04:09:26 -04:00
parent a3e94040ff
commit 1c638ff27b
3 changed files with 61 additions and 16 deletions

View File

@ -140,15 +140,30 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations); double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
double totalPersonalDays = calculatePersonalDays(vacations, isMale); double totalPersonalDays = calculatePersonalDays(vacations, isMale);
double totalVacationDays = calculateVacationDays(employee); List<Double> vacationDays = calculateVacationDays(employee);
double utilizedVacationCurrentDays = vacationDays.get(1);
List<TimeOffRequest> vacationCurrentRequests = requestService
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ACTUAL);
if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) {
utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance();
}
double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays);
double utilizedVacationPreviousDays = vacationDays.get(0);
List<TimeOffRequest> vacationPreviousRequests = requestService
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ANTERIOR);
if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) {
utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance();
}
double totalVacationPreviousDays = vacationDays.getFirst() - (vacationDays.getFirst() - utilizedVacationPreviousDays);
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear); double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
double utilizedVacationDays = calculateVacationUtilizedDays(currentYear);
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear); double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays; double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence; double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence;
double remainingVacationDays = totalVacationDays - utilizedVacationDays; double remainingVacationDays = totalVacationCurrentDays + totalVacationPreviousDays;
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays; double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
@ -178,7 +193,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
.sum(); .sum();
} }
private double calculateVacationDays(final Employee employee) { private List<Double> calculateVacationDays(final Employee employee) {
List<Double> vacationDays = new ArrayList<>();
if (employee.getDateOfEntry() != null) { if (employee.getDateOfEntry() != null) {
LocalDate entryDate = employee.getDateOfEntry(); LocalDate entryDate = employee.getDateOfEntry();
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
@ -214,11 +231,13 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
); );
} }
return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) vacationDays.add(calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate));
+ calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); vacationDays.add(calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate));
} else { } else {
return 0.0; vacationDays.add(0.0);
vacationDays.add(0.0);
} }
return vacationDays;
} }
private double calculateHolidayUtilizedDays(final int year) { private double calculateHolidayUtilizedDays(final int year) {
@ -233,7 +252,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
return requests.stream() return requests.stream()
.filter(req -> req.getCategory().name().startsWith("VACACION")) .filter(req -> req.getCategory().name().startsWith("VACACION"))
.filter(req -> getStartDateYear(req) == year || getStartDateYear(req) == year - 1) .filter(req -> getStartDateYear(req) == year || getStartDateYear(req) == year - 1)
.mapToDouble(TimeOffRequest::getDaysToBeTake) .mapToDouble(TimeOffRequest::getDaysBalance)
.sum(); .sum();
} }

View File

@ -135,15 +135,15 @@ public class RequestRegisterView extends VerticalLayout {
List<TimeOffRequestType> availableCategories = allCategories.stream() List<TimeOffRequestType> availableCategories = allCategories.stream()
.filter(category -> isCategoryAvailable(employeeRequests, category)) .filter(category -> isCategoryAvailable(employeeRequests, category))
.filter(category -> isCategoryAllowedByGender(category, employee.getGender())) .filter(category -> isCategoryAllowedByGender(category, employee.getGender()))
.filter(category -> category != TimeOffRequestType.VACACION_GESTION_ANTERIOR .filter(category -> category != TimeOffRequestType.TODOS)
&& category != TimeOffRequestType.TODOS)
.toList(); .toList();
categoryComboBox.setItems(availableCategories); categoryComboBox.setItems(availableCategories);
} }
private void onCategoryChange(final TimeOffRequestType selectedCategory) { private void onCategoryChange(final TimeOffRequestType selectedCategory) {
if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL) { if (selectedCategory == TimeOffRequestType.VACACION_GESTION_ACTUAL
|| selectedCategory == TimeOffRequestType.VACACION_GESTION_ANTERIOR) {
startDatePicker.setEnabled(true); startDatePicker.setEnabled(true);
endDatePicker.setEnabled(true); endDatePicker.setEnabled(true);
} else { } else {

View File

@ -164,8 +164,28 @@ public class RequestsListView extends Main {
private String getGeneralTotal(final Employee employee) { private String getGeneralTotal(final Employee employee) {
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
List<Vacation> vacations = vacationService.findVacations(); List<Vacation> vacations = vacationService.findVacations();
List<Double> vacationDays = calculateVacationDays(employee);
double utilizedVacationCurrentDays = vacationDays.get(1);
List<TimeOffRequest> vacationCurrentRequests = requestService
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ACTUAL);
if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) {
utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance();
}
double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays);
double utilizedVacationPreviousDays = vacationDays.get(0);
List<TimeOffRequest> vacationPreviousRequests = requestService
.findByEmployeeAndCategory(employee.getId(), TimeOffRequestType.VACACION_GESTION_ANTERIOR);
if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) {
utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance();
}
double totalVacationPreviousDays = vacationDays.getFirst() - (vacationDays.getFirst() - utilizedVacationPreviousDays);
double totalUtilized = calculateTotalUtilized(employeeRequests); double totalUtilized = calculateTotalUtilized(employeeRequests);
double totalVacations = calculateVacationDays(employee); double totalVacations = totalVacationCurrentDays + totalVacationPreviousDays;
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee); double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
double generalTotal = totalAvailable + totalVacations - totalUtilized; double generalTotal = totalAvailable + totalVacations - totalUtilized;
@ -196,6 +216,8 @@ public class RequestsListView extends Main {
return employeeRequests.stream() return employeeRequests.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD) .filter(request -> request.getCategory() != TimeOffRequestType.PERMISOS_DE_SALUD)
.filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ACTUAL)
.filter(request -> request.getCategory() != TimeOffRequestType.VACACION_GESTION_ANTERIOR)
.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")
@ -205,7 +227,9 @@ public class RequestsListView extends Main {
.sum(); .sum();
} }
private double calculateVacationDays(final Employee employee) { private List<Double> calculateVacationDays(final Employee employee) {
List<Double> vacationDays = new ArrayList<>();
if (employee.getDateOfEntry() != null) { if (employee.getDateOfEntry() != null) {
LocalDate entryDate = employee.getDateOfEntry(); LocalDate entryDate = employee.getDateOfEntry();
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
@ -241,11 +265,13 @@ public class RequestsListView extends Main {
); );
} }
return calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate) vacationDays.add(calculateVacationDaysSinceEntry(entryDate, previousVacationYearDate));
+ calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate); vacationDays.add(calculateVacationDaysSinceEntry(entryDate, currentVacationYearDate));
} else { } else {
return 0.0; vacationDays.add(0.0);
vacationDays.add(0.0);
} }
return vacationDays;
} }
private double calculateTotalAvailable(final List<Vacation> vacations, final List<TimeOffRequest> employeeRequests, private double calculateTotalAvailable(final List<Vacation> vacations, final List<TimeOffRequest> employeeRequests,