|
|
@ -1,20 +1,23 @@ |
|
|
|
package mx.gob.jumapacelaya.ui; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.Base64; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import com.vaadin.flow.component.html.Anchor; |
|
|
|
import com.vaadin.flow.server.StreamResource; |
|
|
|
import mx.gob.jumapacelaya.services.ReportService; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.cglib.core.Local; |
|
|
|
import org.springframework.security.core.context.SecurityContextHolder; |
|
|
|
import org.vaadin.lineawesome.LineAwesomeIcon; |
|
|
|
import com.nimbusds.jose.proc.SecurityContext; |
|
|
|
import com.vaadin.flow.component.button.Button; |
|
|
|
import com.vaadin.flow.component.combobox.ComboBox; |
|
|
|
import com.vaadin.flow.component.confirmdialog.ConfirmDialog; |
|
|
|
import com.vaadin.flow.component.dependency.CssImport; |
|
|
|
import com.vaadin.flow.component.dialog.Dialog; |
|
|
|
import com.vaadin.flow.component.grid.Grid; |
|
|
|
import com.vaadin.flow.component.grid.GridVariant; |
|
|
|
import com.vaadin.flow.component.gridpro.GridPro; |
|
|
|
import com.vaadin.flow.component.html.H3; |
|
|
@ -27,8 +30,6 @@ import com.vaadin.flow.component.notification.NotificationVariant; |
|
|
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
import com.vaadin.flow.component.textfield.TextField; |
|
|
|
import com.vaadin.flow.data.binder.Binder; |
|
|
|
import com.vaadin.flow.function.ValueProvider; |
|
|
|
import com.vaadin.flow.router.BeforeEnterEvent; |
|
|
|
import com.vaadin.flow.router.BeforeEnterObserver; |
|
|
|
import com.vaadin.flow.router.PageTitle; |
|
|
@ -44,7 +45,6 @@ import mx.gob.jumapacelaya.models.TiposMantenimiento; |
|
|
|
import mx.gob.jumapacelaya.models.Usuario; |
|
|
|
import mx.gob.jumapacelaya.services.DatabaseService; |
|
|
|
import mx.gob.jumapacelaya.services.SecurityService; |
|
|
|
import oracle.net.aso.f; |
|
|
|
|
|
|
|
@PageTitle("Detalles del mantenimiento") |
|
|
|
@Route(value = "detalles", layout = MainLayout.class) |
|
|
@ -63,7 +63,8 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
private TextField txtEquipo; |
|
|
|
private ComboBox<TiposMantenimiento> cbTipo; |
|
|
|
private TextField txtFecha; |
|
|
|
private TextField txtFechaRealizacion; |
|
|
|
private TextField txtFechaProgramada; |
|
|
|
private TextField txtSituacion; |
|
|
|
private ComboBox<Usuario> cbUsuario; |
|
|
|
private ComboBox<DepartamentosModel> cbDepartamento; |
|
|
|
private GridPro<HardwareDetalle> gridHardware; |
|
|
@ -90,10 +91,12 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
private final SecurityService securityService; |
|
|
|
private final DatabaseService service; |
|
|
|
private final ReportService reportService; |
|
|
|
|
|
|
|
public DetallesMantView(SecurityService securityService, DatabaseService service) { |
|
|
|
public DetallesMantView(SecurityService securityService, DatabaseService service, ReportService reportService) { |
|
|
|
this.service = service; |
|
|
|
this.securityService = securityService; |
|
|
|
this.reportService = reportService; |
|
|
|
setPadding(true); |
|
|
|
|
|
|
|
mainLayout = new VerticalLayout(); |
|
|
@ -135,10 +138,12 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
fechasLayout = new HorizontalLayout(); |
|
|
|
fechasLayout.setWidthFull(); |
|
|
|
txtFecha = new TextField("Fecha realización:"); |
|
|
|
txtFechaRealizacion = new TextField("Fecha programada:"); |
|
|
|
txtFechaProgramada = new TextField("Fecha programada:"); |
|
|
|
txtSituacion = new TextField("Situación:"); |
|
|
|
txtFecha.setReadOnly(true); |
|
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
|
fechasLayout.add(txtFechaRealizacion,txtFecha); |
|
|
|
txtFechaProgramada.setReadOnly(true); |
|
|
|
txtSituacion.setReadOnly(true); |
|
|
|
fechasLayout.add(txtFechaProgramada,txtFecha,txtSituacion); |
|
|
|
|
|
|
|
layout3 = new HorizontalLayout(); |
|
|
|
layout3.setWidthFull(); |
|
|
@ -216,7 +221,6 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
txtEquipo.setReadOnly(false); |
|
|
|
cbTipo.setReadOnly(false); |
|
|
|
txtFecha.setReadOnly(false); |
|
|
|
txtFechaRealizacion.setReadOnly(false); |
|
|
|
cbUsuario.setReadOnly(false); |
|
|
|
cbDepartamento.setReadOnly(false); |
|
|
|
btnImprimirRepo.setVisible(false); |
|
|
@ -246,7 +250,6 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
txtEquipo.setReadOnly(true); |
|
|
|
cbTipo.setReadOnly(true); |
|
|
|
txtFecha.setReadOnly(true); |
|
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
|
btnImprimirRepo.setVisible(true); |
|
|
@ -268,6 +271,34 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
btnImprimirRepo.addClickListener(e -> { |
|
|
|
try { |
|
|
|
// Prepara los parámetros para el reporte |
|
|
|
Map<String, Object> parametros = new HashMap<>(); |
|
|
|
parametros.put("PLAN_ID", planAnualIdActual); |
|
|
|
|
|
|
|
// Genera el PDF |
|
|
|
byte[] pdf = reportService.generarReporte("mantenimientoReport", parametros); |
|
|
|
|
|
|
|
// Se crea el recurso para descarga |
|
|
|
StreamResource resource = new StreamResource("reporte.pdf", () -> new ByteArrayInputStream(pdf)); |
|
|
|
Anchor downloadLink = new Anchor(resource, "Descargar Reporte"); |
|
|
|
downloadLink.getElement().setAttribute("download", true); |
|
|
|
downloadLink.setId("descargar-reporte-link"); |
|
|
|
add(downloadLink); |
|
|
|
|
|
|
|
getUI().ifPresent(ui -> |
|
|
|
ui.getPage().executeJs("document.getElementById('descargar-reporte-link').click();") |
|
|
|
); |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
Notification.show("Error al generar el reporte: " + ex.getMessage(), 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
ex.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Se dispara el dialogo de confirmacion |
|
|
|
btnGuardar.addClickListener(e -> confirmDialog.open()); |
|
|
|
|
|
|
@ -313,7 +344,6 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
txtEquipo.setReadOnly(true); |
|
|
|
cbTipo.setReadOnly(true); |
|
|
|
txtFecha.setReadOnly(true); |
|
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
|
btnImprimirRepo.setVisible(true); |
|
|
@ -355,7 +385,7 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
// Fechas (corrige el campo) |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); |
|
|
|
LocalDate fechaProg = !txtFechaRealizacion.getValue().isEmpty() ? LocalDate.parse(txtFechaRealizacion.getValue(), formatter) : null; |
|
|
|
LocalDate fechaProg = !txtFechaProgramada.getValue().isEmpty() ? LocalDate.parse(txtFechaProgramada.getValue(), formatter) : null; |
|
|
|
LocalDate fechaRealizado = !txtFecha.getValue().isEmpty() ? LocalDate.parse(txtFecha.getValue(), formatter) : null; |
|
|
|
|
|
|
|
|
|
|
@ -377,7 +407,7 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
|
|
|
|
// ACTUALIZA PLANANUAL (nombre del equipo y fecha programada) |
|
|
|
if (!service.actualizarPlanAnual(planAnualIdActual, txtEquipo.getValue(), fechaProg)) { |
|
|
|
if (!service.actualizarPlanAnual(planAnualIdActual, txtEquipo.getValue())) { |
|
|
|
exito = false; |
|
|
|
} |
|
|
|
// ACTUALIZA MANTENIMIENTOS (tipo, departamento, usuario, fecha realizado) |
|
|
@ -419,7 +449,6 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
txtEquipo.setReadOnly(true); |
|
|
|
cbTipo.setReadOnly(true); |
|
|
|
txtFecha.setReadOnly(true); |
|
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
|
btnImprimirRepo.setVisible(true); |
|
|
@ -508,9 +537,11 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); |
|
|
|
String fechaProg = detalle.getFechaprog() != null ? detalle.getFechaprog().format(formatter) : ""; |
|
|
|
String fechaReal = detalle.getFecha() != null ? detalle.getFecha().format(formatter) : ""; |
|
|
|
String situacion = detalle.getSituacion() != null ? detalle.getSituacion() : ""; |
|
|
|
|
|
|
|
txtFechaRealizacion.setValue(fechaProg); |
|
|
|
txtFechaProgramada.setValue(fechaProg); |
|
|
|
txtFecha.setValue(fechaReal); |
|
|
|
txtSituacion.setValue(situacion); |
|
|
|
cbUsuario.setValue( |
|
|
|
cbUsuario.getListDataView().getItems() |
|
|
|
.filter(u -> u.getNombre().equals(detalle.getUsuario())) |
|
|
@ -554,7 +585,7 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
smtSignLayout.replace(smtSignPad, firmaSmtImg); |
|
|
|
} |
|
|
|
|
|
|
|
Image firmaGcia = new Image("images/firmaGcia.png", "Firma de la Gcia. de T.I"); |
|
|
|
Image firmaGcia = new Image("images/FirmaGerenteTI.png", "Firma de la Gcia. de T.I"); |
|
|
|
firmaGcia.setHeight("200px"); |
|
|
|
firmaGcia.setWidthFull(); |
|
|
|
|
|
|
|