|
|
|
@ -72,7 +72,6 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
|
|
|
|
private final Environment env; |
|
|
|
private final ReportService reportService; |
|
|
|
private ListDataProvider<PlanAnual> dataProvider; |
|
|
|
|
|
|
|
H4 titulo = new H4(); |
|
|
|
H5 titulo1 = new H5(); |
|
|
|
@ -89,6 +88,7 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
Button btnEnviarEncuestas; |
|
|
|
HorizontalLayout btnImprimirLayout; |
|
|
|
private Popover reportePopover; |
|
|
|
ComboBox<Integer> yearFilter; |
|
|
|
|
|
|
|
public PlanAnualView(DatabaseService databaseService, Environment env, ReportService reportService) { |
|
|
|
this.databaseService = databaseService; |
|
|
|
@ -109,11 +109,14 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
GridListDataView<PlanAnual> dataView = planAnualGrid.setItems(planAnualItems); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Se crea el filtro para el grid. |
|
|
|
PlanAnualFilter planAnualFilter = new PlanAnualFilter(dataView); |
|
|
|
planAnualFilter.setExcludeRealizado(true); |
|
|
|
|
|
|
|
yearFilter.addValueChangeListener(event -> |
|
|
|
planAnualFilter.setYear(event.getValue()) |
|
|
|
); |
|
|
|
|
|
|
|
HeaderRow headerRow = planAnualGrid.appendHeaderRow(); |
|
|
|
/*headerRow.getCell(planAnualGrid.getColumnByKey("smtColumnKey")) |
|
|
|
.setComponent(createFilterHeader("S.M.T", planAnualFilter::setSmt));*/ |
|
|
|
@ -375,7 +378,7 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
enviarEncConfirm.addConfirmListener(e -> {}); |
|
|
|
btnEnviarEncuestas.addClickListener(e -> enviarEncConfirm.open()); |
|
|
|
|
|
|
|
ComboBox<Integer> yearFilter = new ComboBox<>(); |
|
|
|
yearFilter = new ComboBox<>(); |
|
|
|
int currentYear = Year.now().getValue(); |
|
|
|
List<Integer> years = IntStream.rangeClosed(currentYear - 1, currentYear + 4) |
|
|
|
.boxed().collect(Collectors.toList()); |
|
|
|
@ -384,19 +387,7 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
yearFilter.setClearButtonVisible(true); |
|
|
|
|
|
|
|
List<PlanAnual> todosLosPlanes = databaseService.getPlanAnual(); |
|
|
|
dataProvider = new ListDataProvider<>(todosLosPlanes); |
|
|
|
planAnualGrid.setDataProvider(dataProvider); |
|
|
|
|
|
|
|
dataProvider.addFilter(plan -> { |
|
|
|
if ("REALIZADO".equalsIgnoreCase(plan.getEstado())) { |
|
|
|
return !"NO REALIZADO".equalsIgnoreCase(plan.getSituacion()); |
|
|
|
} |
|
|
|
return true; |
|
|
|
}); |
|
|
|
|
|
|
|
yearFilter.addValueChangeListener(event -> |
|
|
|
aplicarFiltros(event.getValue()) |
|
|
|
); |
|
|
|
|
|
|
|
btnImprimirLayout = new HorizontalLayout(btnColumns, btnImprimirRpt, btnAddEquipo/*, btnEnviarEncuestas*/, yearFilter); |
|
|
|
btnImprimirLayout.setAlignItems(Alignment.BASELINE); |
|
|
|
@ -543,11 +534,14 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
} |
|
|
|
|
|
|
|
private static class PlanAnualFilter { |
|
|
|
|
|
|
|
private final GridListDataView<PlanAnual> dataView; |
|
|
|
|
|
|
|
private String smt; |
|
|
|
private String equipo; |
|
|
|
private String departamento; |
|
|
|
private String mesPlaneado; |
|
|
|
private Integer year; |
|
|
|
private boolean excludeRealizado = true; |
|
|
|
|
|
|
|
public PlanAnualFilter(GridListDataView<PlanAnual> dataView) { |
|
|
|
@ -575,35 +569,51 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
this.dataView.refreshAll(); |
|
|
|
} |
|
|
|
|
|
|
|
public void setYear(Integer year) { |
|
|
|
this.year = year; |
|
|
|
dataView.refreshAll(); |
|
|
|
} |
|
|
|
|
|
|
|
public void setExcludeRealizado(boolean excludeRealizado) { |
|
|
|
this.excludeRealizado = excludeRealizado; |
|
|
|
this.dataView.refreshAll(); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean test(PlanAnual planAnual) { |
|
|
|
if (planAnual == null) { |
|
|
|
return false; // Avoid NullPointerException |
|
|
|
} |
|
|
|
if (planAnual == null) return false; |
|
|
|
|
|
|
|
boolean matchesSmt = matches(planAnual.getSmt(), smt); |
|
|
|
boolean matchesEquipo = matches(planAnual.getNomEquipo(), equipo); |
|
|
|
boolean matchesDepartamento = matches(planAnual.getDepartamento(), departamento); |
|
|
|
boolean matchesMesPlaneado = matches(planAnual.getMesplaneado(), mesPlaneado); |
|
|
|
|
|
|
|
boolean matchesYear = true; |
|
|
|
if (year != null) { |
|
|
|
LocalDate fecha = planAnual.getFechaProgramada(); |
|
|
|
matchesYear = fecha != null && fecha.getYear() == year; |
|
|
|
} |
|
|
|
|
|
|
|
boolean matchesEstado; |
|
|
|
if (excludeRealizado) { |
|
|
|
// Mostrar solo los pendientes |
|
|
|
return matchesSmt && matchesEquipo && matchesDepartamento && matchesMesPlaneado |
|
|
|
&& (planAnual.getEstado() == null || !"REALIZADO".equalsIgnoreCase(planAnual.getEstado())); |
|
|
|
matchesEstado = planAnual.getEstado() == null |
|
|
|
|| !"REALIZADO".equalsIgnoreCase(planAnual.getEstado()); |
|
|
|
} else { |
|
|
|
// Mostrar solo realizados |
|
|
|
return matchesSmt && matchesEquipo && matchesDepartamento && matchesMesPlaneado |
|
|
|
&& "REALIZADO".equalsIgnoreCase(planAnual.getEstado()); |
|
|
|
matchesEstado = |
|
|
|
"REALIZADO".equalsIgnoreCase(planAnual.getEstado()) && |
|
|
|
!"NO REALIZADO".equalsIgnoreCase(planAnual.getSituacion()); |
|
|
|
} |
|
|
|
|
|
|
|
return matchesSmt |
|
|
|
&& matchesEquipo |
|
|
|
&& matchesDepartamento |
|
|
|
&& matchesMesPlaneado |
|
|
|
&& matchesYear |
|
|
|
&& matchesEstado; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean matches(String value, String searchTerm) { |
|
|
|
return searchTerm == null || searchTerm.isEmpty() |
|
|
|
|| value.toLowerCase().contains(searchTerm.toLowerCase()); |
|
|
|
private boolean matches(String value, String serachTerm) { |
|
|
|
return serachTerm == null || serachTerm.isEmpty() |
|
|
|
|| (value != null && value.toLowerCase().contains(serachTerm.toLowerCase())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -995,23 +1005,4 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
dialog.getFooter().add(dialogFooter); |
|
|
|
dialog.open(); |
|
|
|
} |
|
|
|
|
|
|
|
private void aplicarFiltros(Integer selectedYear) { |
|
|
|
|
|
|
|
dataProvider.clearFilters(); |
|
|
|
|
|
|
|
if (selectedYear != null) { |
|
|
|
dataProvider.addFilter(plan -> { |
|
|
|
LocalDate fecha = plan.getFechaProgramada(); |
|
|
|
return fecha != null && fecha.getYear() == selectedYear; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
dataProvider.addFilter(plan -> { |
|
|
|
if ("REALIZADO".equalsIgnoreCase(plan.getEstado())) { |
|
|
|
return !"NO REALIZADO".equalsIgnoreCase(plan.getSituacion()); |
|
|
|
} |
|
|
|
return true; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |