From 92fac8de1d4599d2ee9fce588eebbdae8bff7f37 Mon Sep 17 00:00:00 2001 From: mramirezg Date: Mon, 9 Dec 2024 14:26:45 -0600 Subject: [PATCH] Se cambio el proceso de guardado directo de un insert a un procedimiento almacenado y tambien se cambio el cuestionario de preguntas para que en vez de que sume los puntos al dar clic a un boton se vayan sumando conforme se van seleccionando las opciones --- .../Services/GuardarSolicitudService.java | 49 ++++++- .../mx/gob/jumapacelaya/models/Predio.java | 4 +- .../jumapacelaya/views/CuestionarioView.java | 137 ++++++++++++++++-- .../views/tiposSolicitud/DescEspView.java | 88 ++++++----- .../views/tiposSolicitud/RecargosView.java | 17 ++- 5 files changed, 237 insertions(+), 58 deletions(-) diff --git a/src/main/java/mx/gob/jumapacelaya/Services/GuardarSolicitudService.java b/src/main/java/mx/gob/jumapacelaya/Services/GuardarSolicitudService.java index 5fb50c6..7fa5136 100644 --- a/src/main/java/mx/gob/jumapacelaya/Services/GuardarSolicitudService.java +++ b/src/main/java/mx/gob/jumapacelaya/Services/GuardarSolicitudService.java @@ -4,6 +4,9 @@ import mx.gob.jumapacelaya.models.Usuario; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; import java.time.LocalDate; @Service @@ -15,14 +18,50 @@ public class GuardarSolicitudService { this.jdbcTemplate = jdbcTemplate; } - public void guardarSolicitud(int predioId, String tipoSolicitud, String solicitante, String parentesco, - String tipoIdentificacion, String numIdentificacion, String usuarioId) { + public void guardarSolicitud( + Long predioId, + String tipoSolicitud, + String nombreSolicitante, + String parentesco, + String tipoIdentificacion, + String numIdentificacion, + String usuarioId, + String firma, + String email, + boolean vigencia, + String estado, + String detdesc, + String firmaUsuario, + String detCalif + ) { - String query = "INSERT INTO soldigitales (PREDIOID, TIPO, FECHORA, FECHA, SOLICITANTE, PARENTESCO, TIPOIDEN, NUMIDEN, USUARIOID) " + - "VALUES (?, ?, SYSDATE, ?, ?, ?, SUBSTR(?, 0, 4), ?, ?)"; + String procedureCall = "{call pk_soldigitales.sp_inssoldig(?, ?, sysdate, sysdate, ?, ?, ?, ?, ?, ?, to_date(?, 'dd/mm/yyyy hh24:mi:ss'), ?, ?, ?)}"; - jdbcTemplate.update(query, predioId, tipoSolicitud, LocalDate.now(), solicitante, parentesco, tipoIdentificacion, numIdentificacion, usuarioId); + jdbcTemplate.execute((Connection connection) -> { + try (CallableStatement callableStatement = connection.prepareCall(procedureCall)) { + // Asignar los parámetros de manera correcta + callableStatement.setLong(1, predioId); // ID del predio + callableStatement.setString(2, tipoSolicitud); // Tipo de solicitud + callableStatement.setString(3, nombreSolicitante); // Solicitante + callableStatement.setString(4, parentesco); // Parentesco + callableStatement.setString(5, tipoIdentificacion); // Tipo de identificación + callableStatement.setString(6, numIdentificacion); // Número de identificación + callableStatement.setString(7, firma); // Firma digital + callableStatement.setString(8, usuarioId); // Usuario ID + callableStatement.setString(9, email); // Correo electrónico + callableStatement.setString(10, "31/12/" + LocalDate.now().getYear() + " 23:59:59"); // Fecha de vigencia + callableStatement.setString(11, estado); // Estado + callableStatement.setString(12, detdesc); // Detalles de descuento + callableStatement.setString(13, detCalif); // Detalles de cálculos // Detalles de cálculos + callableStatement.execute(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + return null; + }); } } diff --git a/src/main/java/mx/gob/jumapacelaya/models/Predio.java b/src/main/java/mx/gob/jumapacelaya/models/Predio.java index 00d965c..a9f6b74 100644 --- a/src/main/java/mx/gob/jumapacelaya/models/Predio.java +++ b/src/main/java/mx/gob/jumapacelaya/models/Predio.java @@ -1,7 +1,5 @@ package mx.gob.jumapacelaya.models; -import java.math.BigInteger; - public class Predio { private int predioid; private int clienteid; @@ -51,7 +49,7 @@ public class Predio { this.actividad = actividad; } - public int getPredioid() { + public long getPredioid() { return predioid; } diff --git a/src/main/java/mx/gob/jumapacelaya/views/CuestionarioView.java b/src/main/java/mx/gob/jumapacelaya/views/CuestionarioView.java index 3c52660..89538f2 100644 --- a/src/main/java/mx/gob/jumapacelaya/views/CuestionarioView.java +++ b/src/main/java/mx/gob/jumapacelaya/views/CuestionarioView.java @@ -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(); + } } diff --git a/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/DescEspView.java b/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/DescEspView.java index 0c5da03..45b799c 100644 --- a/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/DescEspView.java +++ b/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/DescEspView.java @@ -2,8 +2,12 @@ package mx.gob.jumapacelaya.views.tiposSolicitud; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.button.ButtonVariant; 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.router.BeforeEnterEvent; @@ -27,6 +31,7 @@ public class DescEspView extends VerticalLayout implements BeforeEnterObserver { private final GuardarSolicitudService guardarSolicitudService; private Predio predio; Span nombreCliente = new Span(); + private SignaturePad userPadDesc; public DescEspView(PredioService predioService, GuardarSolicitudService guardarSolicitudService) { @@ -54,39 +59,11 @@ public class DescEspView extends VerticalLayout implements BeforeEnterObserver { } // Guardar la solicitud cuando el usuario firme - Button btnGuardarSolicitud = new Button("Guardar Solicitud"); + Button btnGuardarSolicitud = new Button("Realizar Cuestionario"); btnGuardarSolicitud.addClickListener(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 = "DCA"; - break; - default: - abreviatura = "R"; - } - - guardarSolicitudService.guardarSolicitud( - predio.getPredioid(), - abreviatura, // Abreviatura para Descuento Especial Pago Anual - nombreSolicitante, - parentesco, - tipoIdentificacion, - numIdentificacion, - usuarioId - ); - - Notification.show("Solicitud guardada con éxito.", 3000, Notification.Position.MIDDLE); + //notificacion("Solicitud guardada con exito!!"); + UI.getCurrent().navigate("cuestionario"); }); this.add(btnGuardarSolicitud); @@ -170,25 +147,60 @@ public class DescEspView extends VerticalLayout implements BeforeEnterObserver { private void sign() { - VerticalLayout signLayout = new VerticalLayout(); - SignaturePad userPad = new SignaturePad(); - userPad.setBackgroundColor("#FFFFFF"); - userPad.setHeight("200px"); - userPad.setPenColor("#000000"); - userPad.getElement().getStyle().set("border", "1px solid black"); + VerticalLayout signLayout = new VerticalLayout(); + userPadDesc = new SignaturePad(); + userPadDesc.setBackgroundColor("#FFFFFF"); + userPadDesc.setHeight("200px"); + userPadDesc.setPenColor("#000000"); + userPadDesc.getElement().getStyle().set("border", "1px solid black"); Span predioCliente = new Span("Predio: " + predio.getPredioid()); Span contratoCliente = new Span("Contrato: " + predio.getContrato()); - signLayout.add(userPad, nombreCliente, predioCliente, contratoCliente); + signLayout.add(userPadDesc, nombreCliente, predioCliente, contratoCliente); signLayout.setSpacing(false); signLayout.setAlignItems(Alignment.CENTER); + signLayout.setSizeFull(); this.setSpacing(false); this.add(signLayout); } + 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(); + } + + @Override public void beforeEnter(BeforeEnterEvent event) { String solicitante = event.getLocation().getQueryParameters().getParameters().get("solicitante") != null diff --git a/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/RecargosView.java b/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/RecargosView.java index 8fb73e2..1687a3f 100644 --- a/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/RecargosView.java +++ b/src/main/java/mx/gob/jumapacelaya/views/tiposSolicitud/RecargosView.java @@ -154,7 +154,22 @@ public class RecargosView extends VerticalLayout implements BeforeEnterObserver if (predio != null && !solicitante.isEmpty()) { try { guardarSolicitudService.guardarSolicitud( - predio.getPredioid(), "Recargos", solicitante, "", "", "", usuarioId); + predio.getPredioid(), // predioId + "Recargos", // tipoSolicitud + solicitante, // nombreSolicitante + "", // parentesco + "", // tipoIdentificacion + "", // numIdentificacion + usuarioId, // usuarioId + "", // firma (empty or from session) + "", // email (empty or from session) + true, // vigencia (true or false) + "", // estado (empty or some value) + "", // detdesc (description) + "", // firmaUsuario (empty or from session) + "" + ); + Notification.show("Solicitud guardada exitosamente", 3000, Notification.Position.MIDDLE); UI.getCurrent().navigate("solidesc"); } catch (Exception e) {