#37 Perfil de Personal Administrativo - Listado General de Vacaciones (Correcciones)

This commit is contained in:
jesus.pelaez 2024-10-27 00:19:56 -04:00
parent 807555a2dd
commit 6a1d3e70c6
3 changed files with 96 additions and 90 deletions

View File

@ -8,10 +8,8 @@ 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;
@ -21,7 +19,6 @@ import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
import java.time.LocalDate;
import java.time.Year;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -37,6 +34,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
private final TimeOffRequestService requestService;
private final EmployeeService employeeService;
private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
private final Grid<Vacation> summaryGrid = new Grid<>();
private List<TimeOffRequest> requests = Collections.emptyList();
private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<TimeOffRequestStatus> stateFilter;
@ -51,7 +49,8 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
private void initializeView() {
setupFilters();
setupGrid();
add(requestGrid, createSummaryLayout(), createActionButtons());
setupSummaryGrid();
add(requestGrid, createActionButtons(), summaryGrid);
refreshRequestGrid(null, null);
}
@ -81,12 +80,9 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
requestGrid.setColumns(
"category",
"state",
"availableDays",
"expiration",
"startDate",
"endDate",
"daysToBeTake",
"daysBalance"
"daysToBeTake"
);
requestGrid.setAllRowsVisible(true);
requestGrid.asSingleSelect().addValueChangeListener(event -> {
@ -97,23 +93,29 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
});
}
private VerticalLayout createSummaryLayout() {
int currentYear = Year.now().getValue();
String yearCategory = "YEAR_" + currentYear;
double totalVacations = requests.stream()
.filter(req -> req.getCategory().name().equals(yearCategory))
.mapToDouble(TimeOffRequest::getAvailableDays)
.sum();
double totalTimeOff = requests.stream()
.filter(req -> !req.getCategory().name().startsWith("YEAR"))
.mapToDouble(TimeOffRequest::getDaysBalance)
.sum();
double totalAvailableDays = totalVacations + totalTimeOff;
return new VerticalLayout(
new Span("TOTAL HOLIDAYS: " + totalVacations),
new Span("TOTAL TIME OFF: " + totalTimeOff),
new Span("TOTAL AVAILABLE DAYS: " + totalAvailableDays)
);
private void setupSummaryGrid() {
summaryGrid.addColumn(this::getCategory).setHeader("Category");
summaryGrid.addColumn(this::getStatus).setHeader("Available");
summaryGrid.addColumn(this::getTotalRequests).setHeader("Expiration");
summaryGrid.addColumn(this::getTotalDays).setHeader("Taken");
summaryGrid.addColumn(this::getTotalDays).setHeader("Balance");
summaryGrid.setAllRowsVisible(true);
}
private Object getTotalDays(final Vacation vacation) {
return null;
}
private Object getTotalRequests(final Vacation vacation) {
return null;
}
private Object getStatus(final Vacation vacation) {
return null;
}
private Object getCategory(final Vacation vacation) {
return vacation.getCategory();
}
private HorizontalLayout createActionButtons() {

View File

@ -22,6 +22,7 @@ import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@SpringComponent
@PermitAll
@ -67,7 +68,10 @@ public class RequestRegisterView extends VerticalLayout {
private void configureFormFields() {
employeeComboBox.setItems(employeeService.findAllEmployees());
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
employeeComboBox.addValueChangeListener(event -> handleEmployeeSelection(employee = event.getValue()));
employeeComboBox.addValueChangeListener(event -> {
employee = event.getValue();
handleEmployeeSelection(employee);
});
categoryComboBox.setEnabled(false);
startDatePicker.setEnabled(false);
endDatePicker.setEnabled(false);
@ -123,8 +127,10 @@ public class RequestRegisterView extends VerticalLayout {
.map(TimeOffRequest::getCategory)
.toList();
List<TimeOffRequestType> availableCategories = Arrays.stream(TimeOffRequestType.values())
.filter(category -> !requestedCategories.contains(category) ||
employeeRequests.stream().anyMatch(req -> req.getCategory() == category && req.getState() == TimeOffRequestStatus.EXPIRED))
.filter(category -> !requestedCategories.contains(category)
|| employeeRequests.stream()
.anyMatch(req -> req.getCategory() == category
&& req.getState() == TimeOffRequestStatus.EXPIRED))
.filter(category -> {
if (employee.getGender() == Employee.Gender.MALE) {
return category != TimeOffRequestType.MATERNITY
@ -151,7 +157,8 @@ public class RequestRegisterView extends VerticalLayout {
private void updateAvailableDays(final TimeOffRequestType selectedCategory) {
vacation = vacationService.findVacationByCategory(selectedCategory);
List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(employeeComboBox.getValue().getId(), selectedCategory);
UUID employeeId = employeeComboBox.getValue().getId();
List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(employeeId, selectedCategory);
if (vacation != null) {
if (!requests.isEmpty() && requests.getFirst().getState() != TimeOffRequestStatus.EXPIRED) {
availableDaysField.setValue(requests.getFirst().getDaysBalance());
@ -160,13 +167,13 @@ public class RequestRegisterView extends VerticalLayout {
LocalDate currentDate = LocalDate.now();
long yearsOfService = ChronoUnit.YEARS.between(dateOfEntry, currentDate);
if (yearsOfService > 10) {
availableDaysField.setValue((double)30);
availableDaysField.setValue((double) 30);
} else if (yearsOfService > 5) {
availableDaysField.setValue((double)20);
availableDaysField.setValue((double) 20);
} else if (yearsOfService > 1) {
availableDaysField.setValue((double)15);
availableDaysField.setValue((double) 15);
} else {
availableDaysField.setValue((double)0);
availableDaysField.setValue((double) 0);
}
} else {
availableDaysField.setValue(vacation.getDuration());
@ -294,7 +301,7 @@ public class RequestRegisterView extends VerticalLayout {
}
}
private void updateBalanceForCategory(TimeOffRequest newRequest) {
private void updateBalanceForCategory(final TimeOffRequest newRequest) {
List<TimeOffRequest> requests = requestService.findByEmployeeAndCategory(
newRequest.getEmployee().getId(), newRequest.getCategory());

View File

@ -29,7 +29,7 @@ public class RequestsListView extends Main {
private final TimeOffRequestService requestService;
private final EmployeeService employeeService;
private final TeamService teamService;
private final PagingGrid<Employee> requestGrid = new PagingGrid<>();
private final PagingGrid<TimeOffRequest> requestGrid = new PagingGrid<>();
private List<Employee> employees = Collections.emptyList();
private ComboBox<Employee> employeeFilter;
@ -67,18 +67,19 @@ public class RequestsListView extends Main {
private void setupRequestGrid() {
requestGrid.addColumn(this::getEmployeeFullName).setHeader("Employee");
requestGrid.addColumn(this::getTeamName).setHeader("Team");
requestGrid.addColumn(this::getEmployeeStatus).setHeader("State");
requestGrid.addColumn(this::getEmployeeStatus).setHeader("Employee State");
requestGrid.addColumn(this::getCategory).setHeader("Category");
requestGrid.addColumn(this::getState).setHeader("Request Status");
requestGrid.addColumn(this::getStartDate).setHeader("Start Date");
requestGrid.addColumn(this::getEndDate).setHeader("End Date");
requestGrid.addColumn(this::getDaysBalance).setHeader("Days Balance");
requestGrid.addColumn(this::getDaysBalance).setHeader("Balance");
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
requestGrid.setPageSize(5);
requestGrid.asSingleSelect().addValueChangeListener(event -> {
Employee selectedRequest = event.getValue();
TimeOffRequest selectedRequest = event.getValue();
if (selectedRequest != null) {
selectedEmployeeId = selectedRequest.getId();
selectedEmployeeId = selectedRequest.getEmployee().getId();
}
});
}
@ -106,56 +107,58 @@ public class RequestsListView extends Main {
requestGrid.getDataProvider().refreshAll();
}
private List<Employee> fetchFilteredEmployees(final int start,
final int pageSize,
final Employee employee,
final Team team,
final TimeOffRequestType category,
final Status state) {
List<Employee> filteredEmployees = employeeService.findAllEmployees();
private List<TimeOffRequest> fetchFilteredEmployees(final int start,
final int pageSize,
final Employee employee,
final Team team,
final TimeOffRequestType category,
final Status employeeState) {
List<TimeOffRequest> filteredRequests = requestService.findAllTimeOffRequests();
if (employee != null && !"ALL".equals(employee.getFirstName())) {
filteredEmployees = filteredEmployees.stream()
.filter(emp -> emp.getId().equals(employee.getId()))
filteredRequests = filteredRequests.stream()
.filter(emp -> emp.getEmployee().getId().equals(employee.getId()))
.collect(Collectors.toList());
}
if (team != null && !"ALL".equals(team.getName())) {
filteredEmployees = filteredEmployees.stream()
.filter(emp -> emp.getTeam() != null && emp.getTeam().getId().equals(team.getId()))
filteredRequests = filteredRequests.stream()
.filter(emp -> {
Team empTeam = emp.getEmployee().getTeam();
return empTeam != null && empTeam.getId().equals(team.getId());
})
.collect(Collectors.toList());
}
if (category != null && category != TimeOffRequestType.values()[0]) {
filteredEmployees = filteredEmployees.stream()
.filter(emp -> {
Optional<TimeOffRequest> request = requestService
.findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.TAKEN);
return request.isPresent() && request.get().getCategory() == category;
})
filteredRequests = filteredRequests.stream()
.filter(emp -> emp.getCategory().equals(category))
.collect(Collectors.toList());
}
if (state != null && state != Status.ALL) {
filteredEmployees = filteredEmployees.stream()
.filter(emp -> {
Optional<TimeOffRequest> request = requestService
.findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.TAKEN);
return state == Status.IDLE ? request.isPresent() : request.isEmpty();
})
if (employeeState != null && employeeState != Status.ALL) {
filteredRequests = filteredRequests.stream()
.filter(emp -> employeeState == Status.IDLE
? emp.getState().equals(TimeOffRequestStatus.IN_USE)
: !emp.getState().equals(TimeOffRequestStatus.IN_USE))
.collect(Collectors.toList());
}
int end = Math.min(start + pageSize, filteredEmployees.size());
return filteredEmployees.subList(start, end);
int end = Math.min(start + pageSize, filteredRequests.size());
return filteredRequests.subList(start, end);
}
private String getEmployeeFullName(final Employee employee) {
private String getEmployeeFullName(final TimeOffRequest request) {
Employee employee = request.getEmployee();
return getEmployeeFullNameLabel(employee);
}
private String getEmployeeFullNameLabel(final Employee employee) {
return "ALL".equals(employee.getFirstName()) ? "ALL" : employee.getFirstName() + " " + employee.getLastName();
}
private String getTeamName(final Employee employee) {
Team team = employee.getTeam();
private String getTeamName(final TimeOffRequest request) {
Team team = request.getEmployee().getTeam();
return team != null ? team.getName() : "Unassigned";
}
@ -164,34 +167,28 @@ public class RequestsListView extends Main {
}
private String getEmployeeStatus(final Employee employee) {
Optional<TimeOffRequest> activeRequest = requestService
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.TAKEN);
return activeRequest.isPresent() ? "IDLE" : "ACTIVE";
private String getEmployeeStatus(final TimeOffRequest request) {
return request.getState() == TimeOffRequestStatus.IN_USE ? "IDLE" : "ACTIVE";
}
private String getCategory(final Employee employee) {
Optional<TimeOffRequest> activeRequest = requestService
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.TAKEN);
return activeRequest.map(request -> request.getCategory().toString()).orElse("");
private String getCategory(final TimeOffRequest request) {
return request.getCategory().toString();
}
private String getStartDate(final Employee employee) {
Optional<TimeOffRequest> activeRequest = requestService
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.TAKEN);
return activeRequest.map(request -> request.getStartDate().toString()).orElse("");
private String getState(final TimeOffRequest request) {
return request.getState().toString();
}
private String getEndDate(final Employee employee) {
Optional<TimeOffRequest> activeRequest = requestService
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.TAKEN);
return activeRequest.map(request -> request.getEndDate().toString()).orElse("");
private String getStartDate(final TimeOffRequest request) {
return request.getStartDate().toString();
}
private String getDaysBalance(final Employee employee) {
Optional<TimeOffRequest> activeRequest = requestService
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.TAKEN);
return activeRequest.map(request -> request.getDaysBalance().toString()).orElse("");
private String getEndDate(final TimeOffRequest request) {
return request.getEndDate().toString();
}
private String getDaysBalance(final TimeOffRequest request) {
return request.getDaysBalance().toString();
}
private ComboBox<Employee> createEmployeeFilter() {
@ -199,7 +196,7 @@ public class RequestsListView extends Main {
List<Employee> employees = new ArrayList<>(employeeService.findAllEmployees());
employees.addFirst(createAllEmployeesOption());
employeeFilter.setItems(employees);
employeeFilter.setItemLabelGenerator(this::getEmployeeFullName);
employeeFilter.setItemLabelGenerator(this::getEmployeeFullNameLabel);
employeeFilter.setValue(employees.getFirst());
employeeFilter.addValueChangeListener(event ->
refreshGeneralRequestGrid(
@ -246,7 +243,7 @@ public class RequestsListView extends Main {
}
private ComboBox<Status> createStateFilter() {
stateFilter = new ComboBox<>("State");
stateFilter = new ComboBox<>("Employee State");
stateFilter.setItems(Status.values());
stateFilter.setValue(Status.values()[0]);
stateFilter.addValueChangeListener(event ->