En-desarrollo #62
@ -20,4 +20,4 @@ public class VacationService {
|
|||||||
public List<Vacation> findVacations() {
|
public List<Vacation> findVacations() {
|
||||||
return vacationRepository.findAll();
|
return vacationRepository.findAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,13 +3,16 @@ package com.primefactorsolutions.views;
|
|||||||
import com.primefactorsolutions.model.*;
|
import com.primefactorsolutions.model.*;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
import com.primefactorsolutions.service.TimeOffRequestService;
|
import com.primefactorsolutions.service.TimeOffRequestService;
|
||||||
|
import com.primefactorsolutions.service.VacationService;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.combobox.ComboBox;
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
import com.vaadin.flow.component.grid.Grid;
|
import com.vaadin.flow.component.grid.Grid;
|
||||||
import com.vaadin.flow.component.html.Div;
|
import com.vaadin.flow.component.html.Div;
|
||||||
import com.vaadin.flow.component.html.H3;
|
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.notification.Notification;
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
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.BeforeEvent;
|
||||||
import com.vaadin.flow.router.HasUrlParameter;
|
import com.vaadin.flow.router.HasUrlParameter;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
@ -33,6 +36,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
|
|
||||||
private final TimeOffRequestService requestService;
|
private final TimeOffRequestService requestService;
|
||||||
private final EmployeeService employeeService;
|
private final EmployeeService employeeService;
|
||||||
|
private final VacationService vacationService;
|
||||||
private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
|
private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
|
||||||
private List<TimeOffRequest> requests = Collections.emptyList();
|
private List<TimeOffRequest> requests = Collections.emptyList();
|
||||||
private ComboBox<TimeOffRequestType> categoryFilter;
|
private ComboBox<TimeOffRequestType> categoryFilter;
|
||||||
@ -40,15 +44,18 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
private UUID employeeId;
|
private UUID employeeId;
|
||||||
private TimeOffRequest request;
|
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.requestService = requestService;
|
||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
|
this.vacationService = vacationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeView() {
|
private void initializeView() {
|
||||||
setupFilters();
|
setupFilters();
|
||||||
setupGrid();
|
setupGrid();
|
||||||
add(requestGrid, createActionButtons());
|
add(requestGrid, createActionButtons(), createSummaryLayout());
|
||||||
refreshRequestGrid(null, null);
|
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() {
|
private HorizontalLayout createActionButtons() {
|
||||||
Button viewButton = new Button("View", event -> {
|
Button viewButton = new Button("View", event -> {
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
|
@ -148,8 +148,8 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
if (category == TimeOffRequestType.HEALTH_PERMIT
|
if (category == TimeOffRequestType.HEALTH_PERMIT
|
||||||
|| category == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT
|
|| category == TimeOffRequestType.VACATION_CURRENT_MANAGEMENT
|
||||||
|| category == TimeOffRequestType.VACATION_PREVIOUS_MANAGEMENT) {
|
|| category == TimeOffRequestType.VACATION_PREVIOUS_MANAGEMENT) {
|
||||||
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED ||
|
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED
|
||||||
(latestRequest.getState() == TimeOffRequestStatus.TAKEN && latestRequest.getDaysBalance() > 0);
|
|| (latestRequest.getState() == TimeOffRequestStatus.TAKEN && latestRequest.getDaysBalance() > 0);
|
||||||
} else {
|
} else {
|
||||||
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED;
|
return latestRequest.getState() == TimeOffRequestStatus.EXPIRED;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,8 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
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 && request.getState() != TimeOffRequestStatus.EXPIRED)
|
.filter(request -> request.getDaysBalance() > 0
|
||||||
|
&& request.getState() != TimeOffRequestStatus.EXPIRED)
|
||||||
.max(Comparator.comparing(TimeOffRequest::getStartDate))
|
.max(Comparator.comparing(TimeOffRequest::getStartDate))
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
if (requestWithBalance != null) {
|
if (requestWithBalance != null) {
|
||||||
@ -214,7 +215,8 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
endDate = null;
|
endDate = null;
|
||||||
|
|
||||||
UUID employeeId = employee.getId();
|
UUID employeeId = employee.getId();
|
||||||
List<TimeOffRequest> previousRequests = requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory());
|
List<TimeOffRequest> previousRequests
|
||||||
|
= requestService.findByEmployeeAndCategory(employeeId, vacation.getCategory());
|
||||||
|
|
||||||
int startYear;
|
int startYear;
|
||||||
if (previousRequests.isEmpty()) {
|
if (previousRequests.isEmpty()) {
|
||||||
@ -236,11 +238,17 @@ public class RequestRegisterView extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vacation.getMonthOfYear() != null && vacation.getDayOfMonth() != null) {
|
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);
|
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||||
} else {
|
} else {
|
||||||
if (vacation.getCategory() == TimeOffRequestType.BIRTHDAY && employee.getBirthday() != null) {
|
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);
|
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||||
} else if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) {
|
} else if (vacation.getCategory() == TimeOffRequestType.HEALTH_PERMIT) {
|
||||||
startDate = LocalDate.now();
|
startDate = LocalDate.now();
|
||||||
|
Loading…
Reference in New Issue
Block a user