@ -1,8 +1,13 @@
package mx.gob.jumapacelaya.views ;
import com.vaadin.flow.component.UI ;
import com.vaadin.flow.component.button.Button ;
import com.vaadin.flow.component.grid.Grid ;
import com.vaadin.flow.component.html.* ;
import com.vaadin.flow.component.icon.Icon ;
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.VerticalLayout ;
import com.vaadin.flow.component.radiobutton.RadioButtonGroup ;
@ -11,6 +16,9 @@ import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.router.PageTitle ;
import com.vaadin.flow.router.Route ;
import com.vaadin.flow.theme.lumo.LumoUtility ;
import mx.gob.jumapacelaya.Services.GuardarSolicitudService ;
import mx.gob.jumapacelaya.Services.PredioService ;
import mx.gob.jumapacelaya.models.Predio ;
import java.time.LocalDate ;
import java.time.format.DateTimeFormatter ;
@ -21,9 +29,16 @@ import java.util.List;
@Route ( value = "cuestionario" , layout = MainLayout . class )
public class CuestionarioView extends VerticalLayout {
public CuestionarioView ( ) {
private final PredioService predioService ;
private final GuardarSolicitudService guardarSolicitudService ;
private Predio predio ;
public CuestionarioView ( PredioService predioService , GuardarSolicitudService guardarSolicitudService ) {
this . setSizeFull ( ) ;
this . setSpacing ( false ) ;
this . guardarSolicitudService = guardarSolicitudService ;
this . predioService = predioService ;
cabezera ( ) ;
titulo ( ) ;
@ -312,7 +327,7 @@ public class CuestionarioView extends VerticalLayout {
txtTrata . setWidth ( "50px" ) ;
/ / Boton para calcular el puntaje total
Button btnCalcular = new Button ( "Calcular Puntaje" , event - > {
Runnable sumarPuntos = ( ) - > {
int total = 0 ;
/ / Suma los valores seleccionados en cada Radio Button
@ -324,28 +339,94 @@ public class CuestionarioView extends VerticalLayout {
total + = opcionesEscolar . getValue ( ) ! = null ? opcionesEscolar . getValue ( ) : 0 ;
total + = opcionesEdad . getValue ( ) ! = null ? opcionesEdad . getValue ( ) : 0 ;
puntos . setText ( String . valueOf ( total ) ) ;
if ( total > 60 ) {
puntos . setText ( String . valueOf ( total ) ) ;
descuento . setText ( "12%" ) ;
txtAgua . setValue ( 88 . 0 ) ;
txtDrena . setValue ( 88 . 0 ) ;
txtTrata . setValue ( 88 . 0 ) ;
} else {
puntos . setText ( String . valueOf ( total ) ) ;
descuento . setText ( "0%" ) ;
txtAgua . clear ( ) ;
txtDrena . clear ( ) ;
txtTrata . clear ( ) ;
txtAgua . setReadOnly ( true ) ;
txtDrena . setReadOnly ( true ) ;
txtTrata . setReadOnly ( true ) ;
}
} ;
opciones . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
opcionesDepen . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
opcionesEdad . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
opcionesEnf . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
opcionesSalud . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
opcionesEscolar . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
opcionesZona . addValueChangeListener ( event - > sumarPuntos . run ( ) ) ;
/ / Recuperar los datos de la sesión
this . predio = ( Predio ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "predio" ) ;
String tipoSolicitud = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "tipoSolicitud" ) ;
String nombreSolicitante = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "nombreSolicitante" ) ;
String parentesco = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "txtParentesco" ) ;
String tipoIdentificacion = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "cmbTipoIdentificacion" ) ;
String numIdentificacion = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "numIdentificacion" ) ;
String usuarioId = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "usuarioId" ) ;
String firma = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "firma" ) ;
String email = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "email" ) ;
String estado = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "estado" ) ;
String detdesc = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "detdesc" ) ;
String firmaUsuario = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "firmaUsuario" ) ;
String detCalif = ( String ) UI . getCurrent ( ) . getSession ( ) . getAttribute ( "detCalif" ) ;
System . out . println ( "Predio: " + this . predio ) ;
System . out . println ( "Tipo Solicitud: " + tipoSolicitud ) ;
System . out . println ( "Nombre Solicitante: " + nombreSolicitante ) ;
/ / Boton para guardar la solicitud
Button btnGuardar = new Button ( "Guardar" , event - > {
String abreviatura = "" ;
switch ( tipoSolicitud ) {
case "Recargos" :
abreviatura = "REC" ;
break ;
case "Infracciones" :
abreviatura = "INF" ;
break ;
case "Ajuste de Facturas" :
abreviatura = "AJU" ;
break ;
case "Descuento Especial Pago Anual" :
abreviatura = "DAC" ;
break ;
default :
abreviatura = "R" ;
}
guardarSolicitudService . guardarSolicitud (
predio . getPredioid ( ) , / / Long predioId
abreviatura , / / String tipoSolicitud
nombreSolicitante , / / String nombreSolicitante
parentesco , / / String parentesco
tipoIdentificacion , / / String tipoIdentificacion
numIdentificacion , / / String numIdentificacion
usuarioId , / / String usuarioId
firma , / / String firma
email , / / String email
true , / / boolean vigencia ( ejemplo : true )
estado , / / String estado
detdesc , / / String detdesc
firmaUsuario , / / String firmaUsuario
detCalif
) ;
notificacion ( "Solicitud guardada exitosamente." ) ;
} ) ;
VerticalLayout botonLayout = new VerticalLayout ( btnCalcular ) ;
VerticalLayout botonLayout = new VerticalLayout ( btnGuardar ) ;
botonLayout . setAlignItems ( Alignment . END ) ;
VerticalLayout totalesLayout = new VerticalLayout ( puntos , descuento , txtAgua , txtDrena , txtTrata ) ;
@ -370,4 +451,38 @@ public class CuestionarioView extends VerticalLayout {
this . add ( formLayout ) ;
}
private void notificacion ( String message ) {
Notification notification = new Notification ( ) ;
notification . setPosition ( Notification . Position . TOP_CENTER ) ;
notification . addThemeVariants ( NotificationVariant . LUMO_SUCCESS ) ;
notification . setDuration ( 3000 ) ;
Icon warningIcon = new Icon ( VaadinIcon . CHECK_CIRCLE_O ) ;
warningIcon . setSize ( "48px" ) ;
warningIcon . getStyle ( ) . set ( "margin-bottom" , "10px" ) ;
Paragraph messajeTexto = new Paragraph ( message ) ;
messajeTexto . getStyle ( ) . set ( "margin" , "0" ) . set ( "text-align" , "center" ) ;
HorizontalLayout buttonsLayout = new HorizontalLayout ( warningIcon , messajeTexto ) ;
buttonsLayout . setAlignItems ( Alignment . CENTER ) ;
buttonsLayout . setSpacing ( false ) ;
buttonsLayout . setPadding ( false ) ;
buttonsLayout . setWidthFull ( ) ;
HorizontalLayout wrapper = new HorizontalLayout ( buttonsLayout ) ;
wrapper . setPadding ( true ) ;
wrapper . setSpacing ( false ) ;
wrapper . getStyle ( ) . set ( "position" , "relative" ) ;
wrapper . getStyle ( ) . set ( "padding" , "10px" ) ;
wrapper . setWidth ( "100%" ) ;
notification . add ( wrapper ) ;
notification . open ( ) ;
}
}