@ -27,6 +27,9 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route ;
import de.f0rce.signaturepad.SignaturePad ;
import jakarta.annotation.security.PermitAll ;
import mx.gob.jumapacelaya.models.DepartamentosModel ;
import mx.gob.jumapacelaya.models.TiposMantenimiento ;
import mx.gob.jumapacelaya.models.Usuario ;
import mx.gob.jumapacelaya.services.DatabaseService ;
import java.time.LocalDate ;
@ -46,9 +49,10 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
private final VerticalLayout etiquetaLayout ;
private final HorizontalLayout firmasLayout ;
private final DatePicker fecha ;
private final ComboBox < String > tipoMantt ;
private final ComboBox < String > area ;
private final ComboBox < String > usuario ;
private final ComboBox < TiposMantenimiento > tipoMantt ;
private final ComboBox < DepartamentosModel > area ;
private final ComboBox < Usuario > usuario ;
private final TextField nombreEquipo ;
private RadioButtonGroup < String > formaGroup ;
private CheckboxGroup < String > actualizaciones ;
private final HorizontalLayout botonesLayout ;
@ -79,34 +83,46 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
/ / Selector de fecha
this . fecha = new DatePicker ( "Fecha" ) ;
fecha . setRequired ( true ) ;
/ / fecha . setPlaceholder ( "Fecha" ) ;
/ / ComboBox Tipo de Mantenimiento
/ / ComboBox Tipo de Mantenimiento
this . tipoMantt = new ComboBox < > ( "Tipo de Mantenimiento" ) ;
tipoMantt . setItems ( databaseService . getTiposDeMantenimientos ( ) ) ;
List < TiposMantenimiento > tiposMantenimiento = databaseService . getTiposDeMantenimientos ( ) ;
tipoMantt . setItems ( tiposMantenimiento ) ;
tipoMantt . addClassName ( "mantenimiento-combo" ) ;
/ / Listener para manejar el cambio en el tipo de mantenimiento
tipoMantt . addValueChangeListener ( event - > {
String tipoSeleccionado = event . getValue ( ) ;
TiposMantenimiento tipoSeleccionado = event . getValue ( ) ;
if ( tipoSeleccionado ! = null ) {
/ / Actualizar nomenclatura dependiendo del tipo de mantenimiento
String nomenclaturaValue = databaseService . getNomenclatura ( tipoSeleccionado ) ;
String nomenclaturaValue = databaseService . getNomenclatura ( tipoSeleccionado . getTipomantId ( ) ) ;
nomenclatura . setValue ( nomenclaturaValue ) ;
/ / Si el tipo es preventivo se establecerá la fecha automáticamente a la fecha del sistema
if ( "1" . equals ( tipoSeleccionado ) ) { / / 1 es para PREVENTIVO
if ( "1" . equals ( tipoSeleccionado . getTipomantId ( ) ) ) { / / 1 es para PREVENTIVO
this . fecha . setValue ( LocalDate . now ( ) ) ;
etiquetaLayout . setVisible ( false ) ;
} else if ( "2" . equals ( tipoSeleccionado ) ) { / / 2 es para CORRECTIVO
/ / Limpiar el layout de correctivo si es necesario
etiquetaLayout . removeAll ( ) ;
} else if ( "2" . equals ( tipoSeleccionado . getTipomantId ( ) ) ) { / / 2 es para CORRECTIVO
this . fecha . clear ( ) ;
etiquetaLayout . setVisible ( true ) ;
correctivoLayout ( ) ;
correctivoLayout ( ) ; / / Asegúrate de que este método se llame
} else {
/ / Para otros tipos de mantenimiento
this . fecha . clear ( ) ;
etiquetaLayout . setVisible ( false ) ;
etiquetaLayout . removeAll ( ) ; / / Limpia el layout para otros tipos
}
} else {
nomenclatura . clear ( ) ;
this . fecha . clear ( ) ;
etiquetaLayout . setVisible ( false ) ;
etiquetaLayout . removeAll ( ) ; / / Limpia el layout
}
} ) ;
fechaLayout . add ( this . fecha ) ;
@ -118,22 +134,33 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
HorizontalLayout departamentoLayout = new HorizontalLayout ( ) ;
/ / ComboBox Area o Departamento
this . area = new ComboBox < > ( "Area o Departamento" ) ;
List < String > areas = databaseService . getDepartamentos ( ) ;
area . setRequired ( true ) ;
List < DepartamentosModel > areas = databaseService . getDepartamentos ( ) ;
area . setItems ( areas ) ;
this . usuario = new ComboBox < > ( "Usuario" ) ;
usuario . setItems ( databaseService . getUsuarios ( ) ) ;
List < Usuario > usuarios = databaseService . getUsuarios ( ) ;
usuario . setItems ( usuarios ) ;
usuario . setItemLabelGenerator ( Usuario : : getNombre ) ;
usuario . setRequired ( true ) ;
usuario . addValueChangeListener ( event - > {
String usuarioSeleccionado = event . getValue ( ) ;
Usuario usuarioSeleccionado = event . getValue ( ) ;
if ( usuarioSeleccionado ! = null ) {
String nombreUsuario = databaseService . getNombreUsuario ( usuarioSeleccionado ) ;
String empleadoId = usuarioSeleccionado . getEmpleadoId ( ) ;
String nombreUsuario = usuarioSeleccionado . getNombre ( ) ;
userSignSpan . setText ( nombreUsuario ) ;
} else {
userSignSpan . setText ( "S.M.T Nombre" ) ;
}
} ) ;
departamentoLayout . add ( area , usuario ) ;
this . nombreEquipo = new TextField ( "Nombre del Equipo" ) ;
nombreEquipo . setRequired ( true ) ;
departamentoLayout . add ( area , usuario , nombreEquipo ) ;
departamentoLayout . setWidthFull ( ) ;
createHardwareSection ( databaseService ) ;
@ -297,8 +324,8 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
Span Titulo = new Span ( "Reparación Realizada al Equipo: " ) ;
/ / Verificar el ID del tipo de mantenimiento
String tipoMantId = tipoMantt . getValue ( ) ;
if ( "2" . equals ( tipoMantId ) ) { / / Solo si el tipo es CORRECTIVO
TiposMantenimiento tiposMantenimiento = tipoMantt . getValue ( ) ;
if ( tiposMantenimiento ! = null & & "2" . equals ( tipos Mantenimiento . getTipomant Id ( ) ) ) { / / Solo si el tipo es CORRECTIVO
TextField txtModelo = new TextField ( ) ;
txtModelo . setPlaceholder ( "Modelo" ) ;
txtModelo . setWidth ( "240px" ) ;
@ -392,9 +419,17 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
btnGuardar . addClickListener ( event - > {
LocalDate fechaSeleccionada = fecha . getValue ( ) ;
String tipoMantId = tipoMantt . getValue ( ) ;
String departamentoId = area . getValue ( ) ;
String empleadoId = usuario . getValue ( ) ;
TiposMantenimiento tiposMantenimiento = tipoMantt . getValue ( ) ;
String tipoMantId = tiposMantenimiento ! = null ? tiposMantenimiento . getTipomantId ( ) : null ;
/ / Cambié aquí para obtener el departamento seleccionado correctamente
DepartamentosModel departamentoSeleccionado = area . getValue ( ) ;
String departamentoId = departamentoSeleccionado ! = null ? departamentoSeleccionado . getDepartamentoId ( ) . toString ( ) : null ;
/ / Obtener el empleado y el equipo
Usuario usuarioSeleccionado = usuario . getValue ( ) ;
String empleadoId = usuarioSeleccionado ! = null ? usuarioSeleccionado . getEmpleadoId ( ) . toString ( ) : null ;
String equipoId = nombreEquipo . getValue ( ) ;
/ / AQUI SE MANEJA LA OPCION SELECCIONADA EN LA FORMA DE MANTENIMIENTO ( REMOTA o MANUAL )
String formaSeleccionada = formaGroup . getValue ( ) ;
@ -407,12 +442,12 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
}
/ / VALIDACION PARA QUE TODOS LOS CAMPOS OBLIGATORIOS SEAN LLENADOS
if ( fechaSeleccionada = = null | | tipoMantId = = null | | departamentoId = = null | | empleadoId = = null | | formaMantt = = null ) {
if ( fechaSeleccionada = = null | | tipoMantId = = null | | departamentoId = = null | | empleadoId = = null | | equipoId = = null | | formaMantt = = null ) {
Notification . show ( "Por favor, completa todos los campos requeridos" , 4000 , Notification . Position . MIDDLE ) ;
return ;
}
int isInserted = databaseService . insertarMantenimiento ( fechaSeleccionada , tipoMantId , departamentoId , empleadoId , formaMantt ) ;
int isInserted = databaseService . insertarMantenimiento ( fechaSeleccionada , tipoMantId , departamentoId , empleadoId , formaMantt , equipoId ) ;
/ / AQUI SE MANEJA LA INSERCION DE LOS DETALLES DE HARDWARE ( TIPO DE HARDWARE , NO . DE SERIE , MODELO , PLACA )
if ( isInserted > 0 ) {
@ -480,6 +515,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
tipoMantt . clear ( ) ;
area . clear ( ) ;
usuario . clear ( ) ;
nombreEquipo . clear ( ) ;
formaGroup . clear ( ) ;
actualizaciones . clear ( ) ;
masActualizacionesGroup . clear ( ) ;
@ -516,12 +552,12 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
}
/ / Cambiamos el valor por el ID
if ( "1" . equals ( tipoParam ) ) { / / 1 es para PREVENTIVO
/ * if ( "1" . equals ( tipoParam ) ) { / / 1 es para PREVENTIVO
tipoMantt . setValue ( "1" ) ; / / Establecemos el ID en el ComboBox
tipoMantt . setReadOnly ( true ) ;
} else if ( "2" . equals ( tipoParam ) ) { / / 2 es para CORRECTIVO
tipoMantt . setValue ( "2" ) ;
tipoMantt . setReadOnly ( true ) ;
}
} * /
}
}