Listado Solicitudes de Empleado - Calcular totales
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 0s
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 0s
This commit is contained in:
parent
476884408a
commit
98ed64dfda
@ -3,13 +3,16 @@ package com.primefactorsolutions.views;
|
||||
import com.primefactorsolutions.model.*;
|
||||
import com.primefactorsolutions.service.EmployeeService;
|
||||
import com.primefactorsolutions.service.TimeOffRequestService;
|
||||
import com.primefactorsolutions.service.VacationService;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.combobox.ComboBox;
|
||||
import com.vaadin.flow.component.grid.Grid;
|
||||
import com.vaadin.flow.component.html.Div;
|
||||
import com.vaadin.flow.component.html.H3;
|
||||
import com.vaadin.flow.component.html.Span;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
import com.vaadin.flow.router.BeforeEvent;
|
||||
import com.vaadin.flow.router.HasUrlParameter;
|
||||
import com.vaadin.flow.router.PageTitle;
|
||||
@ -33,6 +36,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
|
||||
private final TimeOffRequestService requestService;
|
||||
private final EmployeeService employeeService;
|
||||
private final VacationService vacationService;
|
||||
private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
|
||||
private List<TimeOffRequest> requests = Collections.emptyList();
|
||||
private ComboBox<TimeOffRequestType> categoryFilter;
|
||||
@ -40,15 +44,18 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
private UUID employeeId;
|
||||
private TimeOffRequest request;
|
||||
|
||||
public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) {
|
||||
public RequestEmployeeView(final TimeOffRequestService requestService,
|
||||
final EmployeeService employeeService,
|
||||
final VacationService vacationService) {
|
||||
this.requestService = requestService;
|
||||
this.employeeService = employeeService;
|
||||
this.vacationService = vacationService;
|
||||
}
|
||||
|
||||
private void initializeView() {
|
||||
setupFilters();
|
||||
setupGrid();
|
||||
add(requestGrid, createActionButtons());
|
||||
add(requestGrid, createActionButtons(), createSummaryLayout());
|
||||
refreshRequestGrid(null, null);
|
||||
}
|
||||
|
||||
@ -92,6 +99,34 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
});
|
||||
}
|
||||
|
||||
private VerticalLayout createSummaryLayout() {
|
||||
double totalHoliday = requests.stream()
|
||||
.filter(this::verificationIsHoliday)
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
double totalVacations = requests.stream()
|
||||
.filter(req -> req.getCategory().toString().startsWith("VACATION"))
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
double totalPersonalDays = requests.stream()
|
||||
.filter(req -> !verificationIsHoliday(req)) // Solo los de tipo OTHER
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
|
||||
|
||||
return new VerticalLayout(
|
||||
new Span("TOTAL HOLIDAYS: " + totalHoliday),
|
||||
new Span("TOTAL VACATIONS: " + totalVacations),
|
||||
new Span("TOTAL PERSONAL DAYS: " + totalPersonalDays),
|
||||
new Span("TOTAL GENERAL: " + totalAvailableDays)
|
||||
);
|
||||
}
|
||||
|
||||
private Boolean verificationIsHoliday(final TimeOffRequest request) {
|
||||
Vacation vacation = vacationService.findVacationByCategory(request.getCategory());
|
||||
return vacation.getType() != Vacation.Type.OTHER;
|
||||
}
|
||||
|
||||
private HorizontalLayout createActionButtons() {
|
||||
Button viewButton = new Button("View", event -> {
|
||||
if (request != null) {
|
||||
|
@ -148,8 +148,8 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
if (category == TimeOffRequestType.HEALTH_PERMIT
|
||||
|| category == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT
|
||||
|| category == TimeOffRequestType.VACATION_PREVIOUS_MANAGEMENT) {
|
||||
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED ||
|
||||
(latestRequest.getState() == TimeOffRequestStatus.TAKEN && latestRequest.getDaysBalance() > 0);
|
||||
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED
|
||||
|| (latestRequest.getState() == TimeOffRequestStatus.TAKEN && latestRequest.getDaysBalance() > 0);
|
||||
} else {
|
||||
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED;
|
||||
}
|
||||
@ -180,7 +180,8 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(employeeId, selectedCategory);
|
||||
if (vacation != null) {
|
||||
TimeOffRequest requestWithBalance = requests.stream()
|
||||
.filter(request -> request.getDaysBalance() > 0 && request.getState() != TimeOffRequestStatus.EXPIRED)
|
||||
.filter(request -> request.getDaysBalance() > 0
|
||||
&& request.getState() != TimeOffRequestStatus.EXPIRED)
|
||||
.max(Comparator.comparing(TimeOffRequest::getStartDate))
|
||||
.orElse(null);
|
||||
if (requestWithBalance != null) {
|
||||
@ -214,7 +215,8 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
endDate = null;
|
||||
|
||||
UUID employeeId = employee.getId();
|
||||
List<TimeOffRequest> previousRequests = requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory());
|
||||
List<TimeOffRequest> previousRequests
|
||||
= requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory());
|
||||
|
||||
int startYear;
|
||||
if (previousRequests.isEmpty()) {
|
||||
@ -236,11 +238,17 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
}
|
||||
|
||||
if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) {
|
||||
startDate = LocalDate.of(startYear, vacation.getMonthOfYear().intValue(), vacation.getDayOfMonth().intValue());
|
||||
startDate = LocalDate.of(
|
||||
startYear,
|
||||
vacation.getMonthOfYear().intValue(),
|
||||
vacation.getDayOfMonth().intValue());
|
||||
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||
} else {
|
||||
if (vacation.getCategory() == TimeOffRequestType.BIRTHDAY && employee.getBirthday() != null) {
|
||||
startDate = LocalDate.of(startYear, employee.getBirthday().getMonth(), employee.getBirthday().getDayOfMonth());
|
||||
startDate = LocalDate.of(
|
||||
startYear,
|
||||
employee.getBirthday().getMonth(),
|
||||
employee.getBirthday().getDayOfMonth());
|
||||
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||
} else if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) {
|
||||
startDate = LocalDate.now();
|
||||
|
Loading…
Reference in New Issue
Block a user