|
@ -1,11 +1,14 @@ |
|
|
package mx.gob.jumapacelaya.ui; |
|
|
package mx.gob.jumapacelaya.ui; |
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
import org.vaadin.lineawesome.LineAwesomeIcon; |
|
|
import org.vaadin.lineawesome.LineAwesomeIcon; |
|
|
|
|
|
|
|
|
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.confirmdialog.ConfirmDialog; |
|
|
import com.vaadin.flow.component.dependency.CssImport; |
|
|
import com.vaadin.flow.component.dependency.CssImport; |
|
|
import com.vaadin.flow.component.grid.Grid; |
|
|
import com.vaadin.flow.component.grid.Grid; |
|
|
import com.vaadin.flow.component.grid.GridVariant; |
|
|
import com.vaadin.flow.component.grid.GridVariant; |
|
@ -13,6 +16,8 @@ import com.vaadin.flow.component.gridpro.GridPro; |
|
|
import com.vaadin.flow.component.html.H3; |
|
|
import com.vaadin.flow.component.html.H3; |
|
|
import com.vaadin.flow.component.icon.Icon; |
|
|
import com.vaadin.flow.component.icon.Icon; |
|
|
import com.vaadin.flow.component.icon.VaadinIcon; |
|
|
import com.vaadin.flow.component.icon.VaadinIcon; |
|
|
|
|
|
import com.vaadin.flow.component.notification.Notification; |
|
|
|
|
|
import com.vaadin.flow.component.notification.NotificationVariant; |
|
|
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.component.orderedlayout.VerticalLayout; |
|
|
import com.vaadin.flow.component.textfield.TextField; |
|
|
import com.vaadin.flow.component.textfield.TextField; |
|
@ -24,8 +29,11 @@ import com.vaadin.flow.router.PageTitle; |
|
|
import com.vaadin.flow.router.Route; |
|
|
import com.vaadin.flow.router.Route; |
|
|
|
|
|
|
|
|
import jakarta.annotation.security.PermitAll; |
|
|
import jakarta.annotation.security.PermitAll; |
|
|
|
|
|
import mx.gob.jumapacelaya.models.DepartamentosModel; |
|
|
import mx.gob.jumapacelaya.models.DetalleMantenimientoModel; |
|
|
import mx.gob.jumapacelaya.models.DetalleMantenimientoModel; |
|
|
import mx.gob.jumapacelaya.models.HardwareDetalle; |
|
|
import mx.gob.jumapacelaya.models.HardwareDetalle; |
|
|
|
|
|
import mx.gob.jumapacelaya.models.TiposMantenimiento; |
|
|
|
|
|
import mx.gob.jumapacelaya.models.Usuario; |
|
|
import mx.gob.jumapacelaya.services.DatabaseService; |
|
|
import mx.gob.jumapacelaya.services.DatabaseService; |
|
|
|
|
|
|
|
|
@PageTitle("Detalles del mantenimiento") |
|
|
@PageTitle("Detalles del mantenimiento") |
|
@ -43,16 +51,21 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
private HorizontalLayout fechasLayout; |
|
|
private HorizontalLayout fechasLayout; |
|
|
private TextField txtId; |
|
|
private TextField txtId; |
|
|
private TextField txtEquipo; |
|
|
private TextField txtEquipo; |
|
|
private TextField txtTipo; |
|
|
|
|
|
|
|
|
private ComboBox<TiposMantenimiento> cbTipo; |
|
|
private TextField txtFecha; |
|
|
private TextField txtFecha; |
|
|
private TextField txtFechaRealizacion; |
|
|
private TextField txtFechaRealizacion; |
|
|
private TextField txtUsuario; |
|
|
|
|
|
private TextField txtDepartamento; |
|
|
|
|
|
|
|
|
private ComboBox<Usuario> cbUsuario; |
|
|
|
|
|
private ComboBox<DepartamentosModel> cbDepartamento; |
|
|
private GridPro<HardwareDetalle> gridHardware; |
|
|
private GridPro<HardwareDetalle> gridHardware; |
|
|
private Button btnEditar; |
|
|
private Button btnEditar; |
|
|
private Button btnImprimirRepo; |
|
|
private Button btnImprimirRepo; |
|
|
private Button btnCancelar; |
|
|
private Button btnCancelar; |
|
|
private Button btnGuardar; |
|
|
private Button btnGuardar; |
|
|
|
|
|
private int planAnualIdActual; |
|
|
|
|
|
private int mantenimientoIdActual; |
|
|
|
|
|
private ConfirmDialog confirmDialog; |
|
|
|
|
|
|
|
|
|
|
|
DatabaseService service = new DatabaseService(); |
|
|
|
|
|
|
|
|
public DetallesMantView() { |
|
|
public DetallesMantView() { |
|
|
setPadding(true); |
|
|
setPadding(true); |
|
@ -73,14 +86,24 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
headerLayout.setWidthFull(); |
|
|
headerLayout.setWidthFull(); |
|
|
headerLayout.add(id); |
|
|
headerLayout.add(id); |
|
|
|
|
|
|
|
|
|
|
|
cbTipo = new ComboBox<>("Tipo:"); |
|
|
|
|
|
cbTipo.setItems(service.getTiposDeMantenimientos()); |
|
|
|
|
|
cbTipo.setItemLabelGenerator(TiposMantenimiento::getNombre); |
|
|
|
|
|
|
|
|
|
|
|
cbUsuario = new ComboBox<>("Usuario:"); |
|
|
|
|
|
cbUsuario.setItems(service.getUsuarios()); |
|
|
|
|
|
cbUsuario.setItemLabelGenerator(Usuario::getNombre); |
|
|
|
|
|
|
|
|
|
|
|
cbDepartamento = new ComboBox<>("Area:"); |
|
|
|
|
|
cbDepartamento.setItems(service.getDepartamentos()); |
|
|
|
|
|
cbDepartamento.setItemLabelGenerator(DepartamentosModel::getNombre); |
|
|
|
|
|
|
|
|
layout2 = new HorizontalLayout(); |
|
|
layout2 = new HorizontalLayout(); |
|
|
layout2.setWidthFull(); |
|
|
layout2.setWidthFull(); |
|
|
txtEquipo = new TextField("Equipo:"); |
|
|
txtEquipo = new TextField("Equipo:"); |
|
|
txtTipo = new TextField("Tipo:"); |
|
|
|
|
|
txtEquipo.setReadOnly(true); |
|
|
txtEquipo.setReadOnly(true); |
|
|
txtTipo.setReadOnly(true); |
|
|
|
|
|
layout2.add(txtEquipo,txtTipo); |
|
|
|
|
|
|
|
|
cbTipo.setReadOnly(true); |
|
|
|
|
|
layout2.add(txtEquipo,cbTipo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fechasLayout = new HorizontalLayout(); |
|
|
fechasLayout = new HorizontalLayout(); |
|
@ -93,20 +116,16 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
|
layout3 = new HorizontalLayout(); |
|
|
layout3 = new HorizontalLayout(); |
|
|
layout3.setWidthFull(); |
|
|
layout3.setWidthFull(); |
|
|
txtUsuario = new TextField("Usuario:"); |
|
|
|
|
|
txtDepartamento = new TextField("Area:"); |
|
|
|
|
|
txtUsuario.setReadOnly(true); |
|
|
|
|
|
txtDepartamento.setReadOnly(true); |
|
|
|
|
|
txtUsuario.setWidthFull(); |
|
|
|
|
|
txtDepartamento.setWidthFull(); |
|
|
|
|
|
layout3.add(txtUsuario,txtDepartamento); |
|
|
|
|
|
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
|
|
|
cbUsuario.setWidthFull(); |
|
|
|
|
|
cbDepartamento.setWidthFull(); |
|
|
|
|
|
layout3.add(cbUsuario,cbDepartamento); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gridHardware = new GridPro<>(); |
|
|
gridHardware = new GridPro<>(); |
|
|
gridHardware.addEditColumn(HardwareDetalle::getDescripcion) |
|
|
|
|
|
.text((item, newValue) -> item.setDescripcion(newValue)) |
|
|
|
|
|
.setHeader("Descripción") |
|
|
|
|
|
.setEditorComponent(new TextField()); |
|
|
|
|
|
|
|
|
gridHardware.addColumn(item -> item.getDescripcion()) |
|
|
|
|
|
.setHeader("Descripción"); |
|
|
|
|
|
|
|
|
gridHardware.addEditColumn(HardwareDetalle::getNumSerie) |
|
|
gridHardware.addEditColumn(HardwareDetalle::getNumSerie) |
|
|
.text((item, newValue) -> item.setNumSerie(newValue)) |
|
|
.text((item, newValue) -> item.setNumSerie(newValue)) |
|
@ -139,7 +158,7 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
botonesLayout.add(btnEditar,btnImprimirRepo,btnGuardar,btnCancelar); |
|
|
botonesLayout.add(btnEditar,btnImprimirRepo,btnGuardar,btnCancelar); |
|
|
|
|
|
|
|
|
btnGuardar.setVisible(false); |
|
|
btnGuardar.setVisible(false); |
|
|
btnGuardar.getStyle().set("background-color", "green"); |
|
|
|
|
|
|
|
|
btnGuardar.getStyle().set("background-color", "#008000"); |
|
|
btnGuardar.getStyle().set("color", "white"); |
|
|
btnGuardar.getStyle().set("color", "white"); |
|
|
btnCancelar.setVisible(false); |
|
|
btnCancelar.setVisible(false); |
|
|
btnCancelar.getStyle().set("background-color", "red"); |
|
|
btnCancelar.getStyle().set("background-color", "red"); |
|
@ -147,11 +166,11 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
|
btnEditar.addClickListener(e -> { |
|
|
btnEditar.addClickListener(e -> { |
|
|
txtEquipo.setReadOnly(false); |
|
|
txtEquipo.setReadOnly(false); |
|
|
txtTipo.setReadOnly(false); |
|
|
|
|
|
|
|
|
cbTipo.setReadOnly(false); |
|
|
txtFecha.setReadOnly(false); |
|
|
txtFecha.setReadOnly(false); |
|
|
txtFechaRealizacion.setReadOnly(false); |
|
|
txtFechaRealizacion.setReadOnly(false); |
|
|
txtUsuario.setReadOnly(false); |
|
|
|
|
|
txtDepartamento.setReadOnly(false); |
|
|
|
|
|
|
|
|
cbUsuario.setReadOnly(false); |
|
|
|
|
|
cbDepartamento.setReadOnly(false); |
|
|
btnImprimirRepo.setVisible(false); |
|
|
btnImprimirRepo.setVisible(false); |
|
|
btnEditar.setVisible(false); |
|
|
btnEditar.setVisible(false); |
|
|
btnGuardar.setVisible(true); |
|
|
btnGuardar.setVisible(true); |
|
@ -161,11 +180,39 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
|
btnCancelar.addClickListener(e -> { |
|
|
btnCancelar.addClickListener(e -> { |
|
|
txtEquipo.setReadOnly(true); |
|
|
txtEquipo.setReadOnly(true); |
|
|
txtTipo.setReadOnly(true); |
|
|
|
|
|
|
|
|
cbTipo.setReadOnly(true); |
|
|
|
|
|
txtFecha.setReadOnly(true); |
|
|
|
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
|
|
|
btnImprimirRepo.setVisible(true); |
|
|
|
|
|
btnEditar.setVisible(true); |
|
|
|
|
|
btnGuardar.setVisible(false); |
|
|
|
|
|
btnCancelar.setVisible(false); |
|
|
|
|
|
gridHardware.setEditOnClick(false); |
|
|
|
|
|
gridHardware.getEditor().cancel(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Se dispara el dialogo de confirmacion |
|
|
|
|
|
btnGuardar.addClickListener(e -> confirmDialog.open()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dialogo de confirmación de actualización |
|
|
|
|
|
confirmDialog = new ConfirmDialog(); |
|
|
|
|
|
confirmDialog.setHeader("Actualizar Mantenimiento"); |
|
|
|
|
|
confirmDialog.setText("¿Estás seguro de que deseas actualizar el mantenimiento?"); |
|
|
|
|
|
confirmDialog.setCancelable(true); |
|
|
|
|
|
confirmDialog.setConfirmText("Actualizar"); |
|
|
|
|
|
confirmDialog.setCancelText("Cancelar"); |
|
|
|
|
|
confirmDialog.addConfirmListener(event -> realizarActualizacion()); |
|
|
|
|
|
confirmDialog.addCancelListener( event -> { |
|
|
|
|
|
txtEquipo.setReadOnly(true); |
|
|
|
|
|
cbTipo.setReadOnly(true); |
|
|
txtFecha.setReadOnly(true); |
|
|
txtFecha.setReadOnly(true); |
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
txtUsuario.setReadOnly(true); |
|
|
|
|
|
txtDepartamento.setReadOnly(true); |
|
|
|
|
|
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
btnImprimirRepo.setVisible(true); |
|
|
btnImprimirRepo.setVisible(true); |
|
|
btnEditar.setVisible(true); |
|
|
btnEditar.setVisible(true); |
|
|
btnGuardar.setVisible(false); |
|
|
btnGuardar.setVisible(false); |
|
@ -178,6 +225,63 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
add(mainLayout); |
|
|
add(mainLayout); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void realizarActualizacion() { |
|
|
|
|
|
boolean exito = true; |
|
|
|
|
|
|
|
|
|
|
|
// Obtén los objetos seleccionados |
|
|
|
|
|
TiposMantenimiento tipoSeleccionado = cbTipo.getValue(); |
|
|
|
|
|
Usuario usuarioSeleccionado = cbUsuario.getValue(); |
|
|
|
|
|
DepartamentosModel departamentoSeleccionado = cbDepartamento.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
int tipoId = tipoSeleccionado != null ? Integer.parseInt(tipoSeleccionado.getTipomantId()) : 0; |
|
|
|
|
|
int empleadoId = usuarioSeleccionado != null ? Integer.parseInt(usuarioSeleccionado.getEmpleadoId()) : 0; |
|
|
|
|
|
String departamentoId = departamentoSeleccionado != null ? departamentoSeleccionado.getDepartamentoId() : null; |
|
|
|
|
|
|
|
|
|
|
|
// Fechas (corrige el campo) |
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); |
|
|
|
|
|
LocalDate fechaProg = !txtFechaRealizacion.getValue().isEmpty() ? LocalDate.parse(txtFechaRealizacion.getValue(), formatter) : null; |
|
|
|
|
|
LocalDate fechaRealizado = !txtFecha.getValue().isEmpty() ? LocalDate.parse(txtFecha.getValue(), formatter) : null; |
|
|
|
|
|
|
|
|
|
|
|
// ACTUALIZA PLANANUAL (nombre del equipo y fecha programada) |
|
|
|
|
|
if (!service.actualizarPlanAnual(planAnualIdActual, txtEquipo.getValue(), fechaProg)) { |
|
|
|
|
|
exito = false; |
|
|
|
|
|
} |
|
|
|
|
|
// ACTUALIZA MANTENIMIENTOS (tipo, departamento, usuario, fecha realizado) |
|
|
|
|
|
if (!service.actualizarMantenimiento(mantenimientoIdActual, tipoId, departamentoId, empleadoId, fechaRealizado, txtEquipo.getValue())) { |
|
|
|
|
|
exito = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ACTUALIZA HARDWARE (grid) |
|
|
|
|
|
for (HardwareDetalle detalle : gridHardware.getListDataView().getItems().toList()) { |
|
|
|
|
|
if (!service.actualizarHardwareDetalle(detalle)) { |
|
|
|
|
|
exito = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exito) { |
|
|
|
|
|
Notification.show("Registros actualizados correctamente", 3000, Notification.Position.MIDDLE) |
|
|
|
|
|
.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
|
|
} else { |
|
|
|
|
|
Notification.show("Error al actualizar uno o más registros", 3000, Notification.Position.MIDDLE) |
|
|
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
// Opcional: volver a modo solo lectura |
|
|
|
|
|
txtEquipo.setReadOnly(true); |
|
|
|
|
|
cbTipo.setReadOnly(true); |
|
|
|
|
|
txtFecha.setReadOnly(true); |
|
|
|
|
|
txtFechaRealizacion.setReadOnly(true); |
|
|
|
|
|
cbUsuario.setReadOnly(true); |
|
|
|
|
|
cbDepartamento.setReadOnly(true); |
|
|
|
|
|
btnImprimirRepo.setVisible(true); |
|
|
|
|
|
btnEditar.setVisible(true); |
|
|
|
|
|
btnGuardar.setVisible(false); |
|
|
|
|
|
btnCancelar.setVisible(false); |
|
|
|
|
|
gridHardware.setEditOnClick(false); |
|
|
|
|
|
gridHardware.getEditor().cancel(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void beforeEnter(BeforeEnterEvent event) { |
|
|
public void beforeEnter(BeforeEnterEvent event) { |
|
|
String idParam = event.getLocation().getQueryParameters().getParameters().get("id") != null |
|
|
String idParam = event.getLocation().getQueryParameters().getParameters().get("id") != null |
|
@ -188,13 +292,19 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
try { |
|
|
try { |
|
|
int planId = Integer.parseInt(idParam); |
|
|
int planId = Integer.parseInt(idParam); |
|
|
|
|
|
|
|
|
DatabaseService service = new DatabaseService(); |
|
|
|
|
|
DetalleMantenimientoModel detalle = service.getDetalleMantenimientoPorPlanAnualId(planId); |
|
|
DetalleMantenimientoModel detalle = service.getDetalleMantenimientoPorPlanAnualId(planId); |
|
|
|
|
|
|
|
|
if (detalle != null) { |
|
|
if (detalle != null) { |
|
|
|
|
|
this.planAnualIdActual = detalle.getPlanAnualId(); |
|
|
|
|
|
this.mantenimientoIdActual = detalle.getId(); |
|
|
|
|
|
|
|
|
id.setText("Plan ID: " + idParam); |
|
|
id.setText("Plan ID: " + idParam); |
|
|
txtEquipo.setValue(String.valueOf(detalle.getNombreEquipo())); |
|
|
txtEquipo.setValue(String.valueOf(detalle.getNombreEquipo())); |
|
|
txtTipo.setValue(String.valueOf(detalle.getTipo())); |
|
|
|
|
|
|
|
|
cbTipo.setValue( |
|
|
|
|
|
cbTipo.getListDataView().getItems() |
|
|
|
|
|
.filter(t -> t.getNombre().equals(detalle.getTipo())) |
|
|
|
|
|
.findFirst().orElse(null) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); |
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); |
|
|
String fechaProg = detalle.getFechaprog() != null ? detalle.getFechaprog().format(formatter) : ""; |
|
|
String fechaProg = detalle.getFechaprog() != null ? detalle.getFechaprog().format(formatter) : ""; |
|
@ -202,8 +312,16 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
|
|
|
|
|
|
txtFechaRealizacion.setValue(fechaProg); |
|
|
txtFechaRealizacion.setValue(fechaProg); |
|
|
txtFecha.setValue(fechaReal); |
|
|
txtFecha.setValue(fechaReal); |
|
|
txtUsuario.setValue(String.valueOf(detalle.getUsuario())); |
|
|
|
|
|
txtDepartamento.setValue(String.valueOf(detalle.getDepartamento())); |
|
|
|
|
|
|
|
|
cbUsuario.setValue( |
|
|
|
|
|
cbUsuario.getListDataView().getItems() |
|
|
|
|
|
.filter(u -> u.getNombre().equals(detalle.getUsuario())) |
|
|
|
|
|
.findFirst().orElse(null) |
|
|
|
|
|
); |
|
|
|
|
|
cbDepartamento.setValue( |
|
|
|
|
|
cbDepartamento.getListDataView().getItems() |
|
|
|
|
|
.filter(d -> d.getNombre().equals(detalle.getDepartamento())) |
|
|
|
|
|
.findFirst().orElse(null) |
|
|
|
|
|
); |
|
|
int mantId = detalle.getId(); |
|
|
int mantId = detalle.getId(); |
|
|
List<HardwareDetalle> listaHardware = service.getHardwaredetallePorMantId(mantId); |
|
|
List<HardwareDetalle> listaHardware = service.getHardwaredetallePorMantId(mantId); |
|
|
gridHardware.setItems(listaHardware); |
|
|
gridHardware.setItems(listaHardware); |
|
|