#37 Perfil de Personal Administrativo - Listado General de Vacaciones(Agregar filtro de categoria)

This commit is contained in:
jesus.pelaez 2024-11-27 21:03:39 -04:00
parent 5f3e1c1f1a
commit d53792f380
2 changed files with 41 additions and 3 deletions

View File

@ -53,7 +53,6 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
private Button saveButton; private Button saveButton;
private Button viewDocumentButton; private Button viewDocumentButton;
public DocumentView(final DocumentService documentService, public DocumentView(final DocumentService documentService,
final EmployeeService employeeService, final EmployeeService employeeService,
final AuthenticationContext authContext) { final AuthenticationContext authContext) {

View File

@ -55,6 +55,7 @@ public class RequestsListView extends BaseView {
private ComboBox<Employee> employeeFilter; private ComboBox<Employee> employeeFilter;
private ComboBox<Team> teamFilter; private ComboBox<Team> teamFilter;
private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<Status> stateFilter; private ComboBox<Status> stateFilter;
public RequestsListView(final TimeOffRequestService requestService, public RequestsListView(final TimeOffRequestService requestService,
@ -66,7 +67,7 @@ public class RequestsListView extends BaseView {
this.teamService = teamService; this.teamService = teamService;
this.vacationService = vacationService; this.vacationService = vacationService;
initializeView(); initializeView();
refreshGeneralRequestGrid(null, null, null); refreshGeneralRequestGrid(null, null, null, null);
} }
private void initializeView() { private void initializeView() {
@ -82,6 +83,7 @@ public class RequestsListView extends BaseView {
final HorizontalLayout hl = new HorizontalLayout(); final HorizontalLayout hl = new HorizontalLayout();
hl.add(createEmployeeFilter()); hl.add(createEmployeeFilter());
hl.add(createTeamFilter()); hl.add(createTeamFilter());
hl.add(createCategoryFilter());
hl.add(createStateFilter()); hl.add(createStateFilter());
getCurrentPageLayout().add(hl); getCurrentPageLayout().add(hl);
} }
@ -90,6 +92,7 @@ public class RequestsListView extends BaseView {
requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado"); requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado");
requestGrid.addColumn(this::getTeamName).setHeader("Equipo"); requestGrid.addColumn(this::getTeamName).setHeader("Equipo");
requestGrid.addColumn(this::getEmployeeStatus).setHeader("Estado del empleado"); requestGrid.addColumn(this::getEmployeeStatus).setHeader("Estado del empleado");
requestGrid.addColumn(this::getCategory).setHeader("Categoria");
requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general"); requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general");
requestGrid.addComponentColumn((ValueProvider<Employee, Component>) employee -> { requestGrid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
final MenuBar menuBar = new MenuBar(); final MenuBar menuBar = new MenuBar();
@ -107,10 +110,11 @@ public class RequestsListView extends BaseView {
private void refreshGeneralRequestGrid(final Employee employee, private void refreshGeneralRequestGrid(final Employee employee,
final Team team, final Team team,
final TimeOffRequestType category,
final Status state) { final Status state) {
requestGrid.setPagingDataProvider((page, pageSize) -> { requestGrid.setPagingDataProvider((page, pageSize) -> {
int start = (int) (page * requestGrid.getPageSize()); int start = (int) (page * requestGrid.getPageSize());
return fetchFilteredEmployees(start, pageSize, employee, team, state); return fetchFilteredEmployees(start, pageSize, employee, team, category, state);
}); });
requestGrid.getDataProvider().refreshAll(); requestGrid.getDataProvider().refreshAll();
} }
@ -119,6 +123,7 @@ public class RequestsListView extends BaseView {
final int pageSize, final int pageSize,
final Employee employee, final Employee employee,
final Team team, final Team team,
final TimeOffRequestType category,
final Status state) { final Status state) {
List<Employee> filteredEmployees = employeeService.findAllEmployees(); List<Employee> filteredEmployees = employeeService.findAllEmployees();
@ -134,6 +139,16 @@ public class RequestsListView extends BaseView {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
if (category != null && category != TimeOffRequestType.values()[0]) {
filteredEmployees = filteredEmployees.stream()
.filter(emp -> {
Optional<TimeOffRequest> request = requestService
.findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.EN_USO);
return request.isPresent() && request.get().getCategory() == category;
})
.collect(Collectors.toList());
}
if (state != null && state != Status.TODOS) { if (state != null && state != Status.TODOS) {
filteredEmployees = filteredEmployees.stream() filteredEmployees = filteredEmployees.stream()
.filter(emp -> { .filter(emp -> {
@ -168,6 +183,12 @@ public class RequestsListView extends BaseView {
return activeRequest.isPresent() ? "EN_DESCANSO" : "EN_FUNCIONES"; return activeRequest.isPresent() ? "EN_DESCANSO" : "EN_FUNCIONES";
} }
private String getCategory(final Employee employee) {
Optional<TimeOffRequest> activeRequest = requestService
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.EN_USO);
return activeRequest.map(request -> request.getCategory().toString()).orElse("");
}
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();
@ -363,6 +384,7 @@ public class RequestsListView extends BaseView {
refreshGeneralRequestGrid( refreshGeneralRequestGrid(
event.getValue(), event.getValue(),
teamFilter.getValue(), teamFilter.getValue(),
categoryFilter.getValue(),
stateFilter.getValue() stateFilter.getValue()
) )
); );
@ -380,12 +402,28 @@ public class RequestsListView extends BaseView {
refreshGeneralRequestGrid( refreshGeneralRequestGrid(
employeeFilter.getValue(), employeeFilter.getValue(),
event.getValue(), event.getValue(),
categoryFilter.getValue(),
stateFilter.getValue() stateFilter.getValue()
) )
); );
return teamFilter; return teamFilter;
} }
private ComboBox<TimeOffRequestType> createCategoryFilter() {
categoryFilter = new ComboBox<>("Category");
categoryFilter.setItems(TimeOffRequestType.values());
categoryFilter.setValue(TimeOffRequestType.values()[0]);
categoryFilter.addValueChangeListener(event ->
refreshGeneralRequestGrid(
employeeFilter.getValue(),
teamFilter.getValue(),
event.getValue(),
stateFilter.getValue()
)
);
return categoryFilter;
}
private ComboBox<Status> createStateFilter() { private ComboBox<Status> createStateFilter() {
stateFilter = new ComboBox<>("Estado del empleado"); stateFilter = new ComboBox<>("Estado del empleado");
stateFilter.setItems(Status.values()); stateFilter.setItems(Status.values());
@ -394,6 +432,7 @@ public class RequestsListView extends BaseView {
refreshGeneralRequestGrid( refreshGeneralRequestGrid(
employeeFilter.getValue(), employeeFilter.getValue(),
teamFilter.getValue(), teamFilter.getValue(),
categoryFilter.getValue(),
event.getValue() event.getValue()
) )
); );