diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/controlador/InfowallControlador.java b/src/main/java/jumapacelaya/gob/mx/infowall/controlador/InfowallControlador.java index db61cae..71794ce 100644 --- a/src/main/java/jumapacelaya/gob/mx/infowall/controlador/InfowallControlador.java +++ b/src/main/java/jumapacelaya/gob/mx/infowall/controlador/InfowallControlador.java @@ -4,11 +4,19 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import jakarta.inject.Inject; +import jumapacelaya.gob.mx.infowall.dto.cobFacVtaDiaDTO; +import jumapacelaya.gob.mx.infowall.dto.compCvDTO; +import jumapacelaya.gob.mx.infowall.dto.otReconexDiaDTO; +import jumapacelaya.gob.mx.infowall.dto.otSuspensionDTO; +import jumapacelaya.gob.mx.infowall.dto.totalCobrosHoyDTO; import jumapacelaya.gob.mx.infowall.dto.totalPagosHoyDTO; +import jumapacelaya.gob.mx.infowall.dto.totalPagosMesDTO; import jumapacelaya.gob.mx.infowall.servicio.InfowallServicio; +@Controller("/infowall") public class InfowallControlador { @Inject @@ -29,4 +37,43 @@ public class InfowallControlador { return servicio.obtenerTotalPagosHoy(entidadIds, puntoIds); } + @Get("/totalcobroshoy/{entidad}/{punto}") + public totalCobrosHoyDTO obtenerTotalCobrosHoy(String entidad, String punto) { + List entidadIds = Arrays.stream(entidad.split(",")) + .map(String::trim) + .map(Integer::parseInt) + .collect(Collectors.toList()); + + List puntoIds = Arrays.stream(punto.split(",")) + .map(String::trim) + .map(Integer::parseInt) + .collect(Collectors.toList()); + + return servicio.obtenerTotalCobrosHoy(entidadIds, puntoIds); + } + + @Get("/totalpagosanualxmes") + public List obtenerTotalPagosAnualPorMes() { + return servicio.obtenerTotalPagosAnualPorMes(); + } + + @Get("/otssuspension") + public List obtenerOtSuspension() { + return servicio.obtenerOtSuspension(); + } + + @Get("/otsreconexdia") + public otReconexDiaDTO obtenerOtsReconexDia() { + return servicio.obtenerOtsReconexDia(); + } + + @Get("/cobfacvtadia/{tipofacvta}") + public List obtenerCobFacVtaDia(String tipofacvta) { + return servicio.obtenerCobFacVtaDia(tipofacvta); + } + + @Get("/compcv") + public compCvDTO obtenerCompCv() { + return servicio.obtenerCompCv(); + } } diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/dto/cobFacVtaDiaDTO.java b/src/main/java/jumapacelaya/gob/mx/infowall/dto/cobFacVtaDiaDTO.java new file mode 100644 index 0000000..11ccf3f --- /dev/null +++ b/src/main/java/jumapacelaya/gob/mx/infowall/dto/cobFacVtaDiaDTO.java @@ -0,0 +1,37 @@ +package jumapacelaya.gob.mx.infowall.dto; + +import java.math.BigDecimal; + +public class cobFacVtaDiaDTO { + private String usoid; + private String uso; + private int cobros; + private BigDecimal total; + + public cobFacVtaDiaDTO(String usoid, String uso, int cobros, BigDecimal total) { + this.usoid = usoid; + this.uso = uso; + this.cobros = cobros; + this.total = total; + } + + public String getUsoid() { return usoid; } + public void setUsoid(String usoid) { + this.usoid = usoid; + } + + public String getUso() { return uso; } + public void setUso(String uso) { + this.uso = uso; + } + + public int getCobros() { return cobros; } + public void setCobros(int cobros) { + this.cobros = cobros; + } + + public BigDecimal getTotal() { return total; } + public void setTotal(BigDecimal total) { + this.total = total; + } +} diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/dto/compCvDTO.java b/src/main/java/jumapacelaya/gob/mx/infowall/dto/compCvDTO.java new file mode 100644 index 0000000..8b707a9 --- /dev/null +++ b/src/main/java/jumapacelaya/gob/mx/infowall/dto/compCvDTO.java @@ -0,0 +1,339 @@ +package jumapacelaya.gob.mx.infowall.dto; + +import java.math.BigDecimal; + +public class compCvDTO { + private BigDecimal saldovencido; + private BigDecimal saldonovencido; + private BigDecimal vencrezago; + private BigDecimal vencactual; + private BigDecimal novencido; + private BigDecimal recvencrezago; + private BigDecimal recvencactual; + private BigDecimal recnovencido; + private BigDecimal saldototal; + private BigDecimal saldogescob; + private BigDecimal vr5, va5, nv5; + private BigDecimal vr6, va6, nv6; + private BigDecimal vr7, va7, nv7; + private BigDecimal vr8, va8, nv8; + private BigDecimal vr11, va11, nv11; + private BigDecimal vr12, va12, nv12; + private BigDecimal vr13, va13, nv13; + private BigDecimal vr14, va14, nv14; + private BigDecimal vr15, va15, nv15; + private BigDecimal vr16, va16, nv16; + private BigDecimal vr17, va17, nv17; + private BigDecimal vr21, va21, nv21; + private BigDecimal vr22, va22, nv22; + private BigDecimal vr112, va112, nv112; + private BigDecimal vr116, va116, nv116; + private BigDecimal vr118, va118, nv118; + private BigDecimal vr122, va122, nv122; + + // Getters y setters + public BigDecimal getSaldovencido() { return saldovencido; } + public void setSaldovencido(BigDecimal saldovencido) { + this.saldovencido = saldovencido; + } + + public BigDecimal getSaldonovencido() { return saldonovencido; } + public void setSaldonovencido(BigDecimal saldonovencido) { + this.saldonovencido = saldonovencido; + } + + public BigDecimal getVencrezago() { return vencrezago; } + public void setVencrezago(BigDecimal vencrezago) { + this.vencrezago = vencrezago; + } + + public BigDecimal getVencactual() { return vencactual; } + public void setVencactual(BigDecimal vencactual) { + this.vencactual = vencactual; + } + + public BigDecimal getNovencido() { return novencido; } + public void setNovencido(BigDecimal novencido) { + this.novencido = novencido; + } + + public BigDecimal getRecvencrezago() { return recvencrezago; } + public void setRecvencrezago(BigDecimal recvencrezago) { + this.recvencrezago = recvencrezago; + } + + public BigDecimal getRecvencactual() { return recvencactual; } + public void setRecvencactual(BigDecimal recvencactual) { + this.recvencactual = recvencactual; + } + + public BigDecimal getRecnovencido() { return recnovencido; } + public void setRecnovencido(BigDecimal recnovencido) { + this.recnovencido = recnovencido; + } + + public BigDecimal getSaldototal() { return saldototal; } + public void setSaldototal(BigDecimal saldototal) { + this.saldototal = saldototal; + } + + public BigDecimal getSaldogescob() { return saldogescob; } + public void setSaldogescob(BigDecimal saldogescob) { + this.saldogescob = saldogescob; + } + + public BigDecimal getVr5() { return vr5; } + public void setVr5(BigDecimal vr5) { + this.vr5 = vr5; + } + + public BigDecimal getVa5() { return va5; } + public void setVa5(BigDecimal va5) { + this.va5 = va5; + } + + public BigDecimal getNv5() { return nv5; } + public void setNv5(BigDecimal nv5) { + this.nv5 = nv5; + } + + public BigDecimal getVr6() { return vr6; } + public void setVr6(BigDecimal vr6) { + this.vr6 = vr6; + } + + public BigDecimal getVa6() { return va6; } + public void setVa6(BigDecimal va6) { + this.va6 = va6; + } + + public BigDecimal getNv6() { return nv6; } + public void setNv6(BigDecimal nv6) { + this.nv6 = nv6; + } + + public BigDecimal getVr7() { return vr7; } + public void setVr7(BigDecimal vr7) { + this.vr7 = vr7; + } + + public BigDecimal getVa7() { return va7; } + public void setVa7(BigDecimal va7) { + this.va7 = va7; + } + + public BigDecimal getNv7() { return nv7; } + public void setNv7(BigDecimal nv7) { + this.nv7 = nv7; + } + + public BigDecimal getVr8() { return vr8; } + public void setVr8(BigDecimal vr8) { + this.vr8 = vr8; + } + + public BigDecimal getVa8() { return va8; } + public void setVa8(BigDecimal va8) { + this.va8 = va8; + } + + public BigDecimal getNv8() { return nv8; } + public void setNv8(BigDecimal nv8) { + this.nv8 = nv8; + } + + public BigDecimal getVr11() { return vr11; } + public void setVr11(BigDecimal vr11) { + this.vr11 = vr11; + } + + public BigDecimal getVa11() { return va11; } + public void setVa11(BigDecimal va11) { + this.va11 = va11; + } + + public BigDecimal getNv11() { return nv11; } + public void setNv11(BigDecimal nv11) { + this.nv11 = nv11; + } + + public BigDecimal getVr12() { return vr12; } + public void setVr12(BigDecimal vr12) { + this.vr12 = vr12; + } + + public BigDecimal getVa12() { return va12; } + public void setVa12(BigDecimal va12) { + this.va12 = va12; + } + + public BigDecimal getNv12() { return nv12; } + public void setNv12(BigDecimal nv12) { + this.nv12 = nv12; + } + + public BigDecimal getVr13() { return vr13; } + public void setVr13(BigDecimal vr13) { + this.vr13 = vr13; + } + + public BigDecimal getVa13() { return va13; } + public void setVa13(BigDecimal va13) { + this.va13 = va13; + } + + public BigDecimal getNv13() { return nv13; } + public void setNv13(BigDecimal nv13) { + this.nv13 = nv13; + } + + public BigDecimal getVr14() { return vr14; } + public void setVr14(BigDecimal vr14) { + this.vr14 = vr14; + } + + public BigDecimal getVa14() { return va14; } + public void setVa14(BigDecimal va14) { + this.va14 = va14; + } + + public BigDecimal getNv14() { return nv14; } + public void setNv14(BigDecimal nv14) { + this.nv14 = nv14; + } + + public BigDecimal getVr15() { return vr15; } + public void setVr15(BigDecimal vr15) { + this.vr15 = vr15; + } + + public BigDecimal getVa15() { return va15; } + public void setVa15(BigDecimal va15) { + this.va15 = va15; + } + + public BigDecimal getNv15() { return nv15; } + public void setNv15(BigDecimal nv15) { + this.nv15 = nv15; + } + + public BigDecimal getVr16() { return vr16; } + public void setVr16(BigDecimal vr16) { + this.vr16 = vr16; + } + + public BigDecimal getVa16() { return va16; } + public void setVa16(BigDecimal va16) { + this.va16 = va16; + } + + public BigDecimal getNv16() { return nv16; } + public void setNv16(BigDecimal nv16) { + this.nv16 = nv16; + } + + public BigDecimal getVr17() { return vr17; } + public void setVr17(BigDecimal vr17) { + this.vr17 = vr17; + } + + public BigDecimal getVa17() { return va17; } + public void setVa17(BigDecimal va17) { + this.va17 = va17; + } + + public BigDecimal getNv17() { return nv17; } + public void setNv17(BigDecimal nv17) { + this.nv17 = nv17; + } + + public BigDecimal getVr21() { return vr21; } + public void setVr21(BigDecimal vr21) { + this.vr21 = vr21; + } + + public BigDecimal getVa21() { return va21; } + public void setVa21(BigDecimal va21) { + this.va21 = va21; + } + + public BigDecimal getNv21() { return nv21; } + public void setNv21(BigDecimal nv21) { + this.nv21 = nv21; + } + + public BigDecimal getVr22() { return vr22; } + public void setVr22(BigDecimal vr22) { + this.vr22 = vr22; + } + + public BigDecimal getVa22() { return va22; } + public void setVa22(BigDecimal va22) { + this.va22 = va22; + } + + public BigDecimal getNv22() { return nv22; } + public void setNv22(BigDecimal nv22) { + this.nv22 = nv22; + } + + public BigDecimal getVr112() { return vr112; } + public void setVr112(BigDecimal vr112) { + this.vr112 = vr112; + } + + public BigDecimal getVa112() { return va112; } + public void setVa112(BigDecimal va112) { + this.va112 = va112; + } + + public BigDecimal getNv112() { return nv112; } + public void setNv112(BigDecimal nv112) { + this.nv112 = nv112; + } + + public BigDecimal getVr116() { return vr116; } + public void setVr116(BigDecimal vr116) { + this.vr116 = vr116; + } + + public BigDecimal getVa116() { return va116; } + public void setVa116(BigDecimal va116) { + this.va116 = va116; + } + + public BigDecimal getNv116() { return nv116; } + public void setNv116(BigDecimal nv116) { + this.nv116 = nv116; + } + + public BigDecimal getVr118() { return vr118; } + public void setVr118(BigDecimal vr118) { + this.vr118 = vr118; + } + + public BigDecimal getVa118() { return va118; } + public void setVa118(BigDecimal va118) { + this.va118 = va118; + } + + public BigDecimal getNv118() { return nv118; } + public void setNv118(BigDecimal nv118) { + this.nv118 = nv118; + } + + public BigDecimal getVr122() { return vr122; } + public void setVr122(BigDecimal vr122) { + this.vr122 = vr122; + } + + public BigDecimal getVa122() { return va122; } + public void setVa122(BigDecimal va122) { + this.va122 = va122; + } + + public BigDecimal getNv122() { return nv122; } + public void setNv122(BigDecimal nv122) { + this.nv122 = nv122; + } +} diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/dto/otReconexDiaDTO.java b/src/main/java/jumapacelaya/gob/mx/infowall/dto/otReconexDiaDTO.java new file mode 100644 index 0000000..4b0ee30 --- /dev/null +++ b/src/main/java/jumapacelaya/gob/mx/infowall/dto/otReconexDiaDTO.java @@ -0,0 +1,14 @@ +package jumapacelaya.gob.mx.infowall.dto; + +public class otReconexDiaDTO { + private int reconexdia; + + public otReconexDiaDTO(int reconexdia) { + this.reconexdia = reconexdia; + } + + public int getReconexdia() { return reconexdia; } + public void setReconexdia(int reconexdia) { + this.reconexdia = reconexdia; + } +} diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/dto/otSuspensionDTO.java b/src/main/java/jumapacelaya/gob/mx/infowall/dto/otSuspensionDTO.java new file mode 100644 index 0000000..ac0ed14 --- /dev/null +++ b/src/main/java/jumapacelaya/gob/mx/infowall/dto/otSuspensionDTO.java @@ -0,0 +1,28 @@ +package jumapacelaya.gob.mx.infowall.dto; + +public class otSuspensionDTO { + private int ots; + private int motivoid; + private String descripcion; + + public otSuspensionDTO(int ots, int motivoid, String descripcion) { + this.ots = ots; + this.motivoid = motivoid; + this.descripcion = descripcion; + } + + public int getOts() { return ots; } + public void setOts(int ots) { + this.ots = ots; + } + + public int getMotivoid() { return motivoid; } + public void setMotivoid(int motivoid) { + this.motivoid = motivoid; + } + + public String getDescripcion() { return descripcion; } + public void setDescripcion(String descripcion) { + this.descripcion = descripcion; + } +} diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/dto/totalCobrosHoyDTO.java b/src/main/java/jumapacelaya/gob/mx/infowall/dto/totalCobrosHoyDTO.java new file mode 100644 index 0000000..3266f24 --- /dev/null +++ b/src/main/java/jumapacelaya/gob/mx/infowall/dto/totalCobrosHoyDTO.java @@ -0,0 +1,23 @@ +package jumapacelaya.gob.mx.infowall.dto; + +import java.math.BigDecimal; + +public class totalCobrosHoyDTO { + private BigDecimal totalcobrado; + private int numerocobros; + + public totalCobrosHoyDTO(BigDecimal totalcobrado, int numerocobros) { + this.totalcobrado = totalcobrado; + this.numerocobros = numerocobros; + } + + public BigDecimal getTotalcobrado() { return totalcobrado; } + public void setTotalcobrado(BigDecimal totalcobrado) { + this.totalcobrado = totalcobrado; + } + + public int getNumerocobros() { return numerocobros; } + public void setNumerocobros(int numerocobros) { + this.numerocobros = numerocobros; + } +} diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/dto/totalPagosMesDTO.java b/src/main/java/jumapacelaya/gob/mx/infowall/dto/totalPagosMesDTO.java new file mode 100644 index 0000000..08728c2 --- /dev/null +++ b/src/main/java/jumapacelaya/gob/mx/infowall/dto/totalPagosMesDTO.java @@ -0,0 +1,39 @@ +package jumapacelaya.gob.mx.infowall.dto; + +import java.math.BigDecimal; + +public class totalPagosMesDTO { + private String mes; + private BigDecimal totalpagado; + private int numeropagos; + + public totalPagosMesDTO(String mes, BigDecimal totalpagado, int numeropagos) { + this.mes = mes; + this.totalpagado = totalpagado; + this.numeropagos = numeropagos; + } + + public String getMes() { + return mes; + } + + public void setMes(String mes) { + this.mes = mes; + } + + public BigDecimal getTotalpagado() { + return totalpagado; + } + + public void setTotalpagado(BigDecimal totalpagado) { + this.totalpagado = totalpagado; + } + + public int getNumeropagos() { + return numeropagos; + } + + public void setNumeropagos(int numeropagos) { + this.numeropagos = numeropagos; + } +} diff --git a/src/main/java/jumapacelaya/gob/mx/infowall/servicio/InfowallServicio.java b/src/main/java/jumapacelaya/gob/mx/infowall/servicio/InfowallServicio.java index 19192dc..fea9cde 100644 --- a/src/main/java/jumapacelaya/gob/mx/infowall/servicio/InfowallServicio.java +++ b/src/main/java/jumapacelaya/gob/mx/infowall/servicio/InfowallServicio.java @@ -4,14 +4,28 @@ import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import javax.sql.DataSource; +import io.micronaut.data.annotation.Query; +import io.micronaut.data.jdbc.annotation.JdbcRepository; +import io.micronaut.data.model.query.builder.sql.Dialect; +import io.micronaut.data.repository.CrudRepository; import io.micronaut.transaction.annotation.Transactional; +import jakarta.inject.Singleton; +import jumapacelaya.gob.mx.infowall.dto.cobFacVtaDiaDTO; +import jumapacelaya.gob.mx.infowall.dto.compCvDTO; +import jumapacelaya.gob.mx.infowall.dto.otReconexDiaDTO; +import jumapacelaya.gob.mx.infowall.dto.otSuspensionDTO; +import jumapacelaya.gob.mx.infowall.dto.totalCobrosHoyDTO; import jumapacelaya.gob.mx.infowall.dto.totalPagosHoyDTO; +import jumapacelaya.gob.mx.infowall.dto.totalPagosMesDTO; +import jumapacelaya.gob.mx.infowall.repositorio.InfowallRepositorio; +@Singleton public class InfowallServicio { private final DataSource dataSource; @@ -58,4 +72,271 @@ public class InfowallServicio { } } + @Transactional + public totalCobrosHoyDTO obtenerTotalCobrosHoy(List entidadIds, List puntoIds) { + String query = "SELECT SUM(total) AS totalcobrado, COUNT(total) AS numerocobros " + + "FROM cobrosenc c " + + "INNER JOIN lotesenc l USING (numloteid) " + + "WHERE fechacob BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE + 1) " + + "AND entidadid IN (%s) AND puntoid IN (%s)"; + + String entidadPlaceholders = entidadIds.stream().map(id -> "?").collect(Collectors.joining(",")); + String puntoPlaceholders = puntoIds.stream().map(id -> "?").collect(Collectors.joining(",")); + + query = String.format(query, entidadPlaceholders, puntoPlaceholders); + + try (Connection connection = dataSource.getConnection(); + PreparedStatement stmt = connection.prepareStatement(query)) { + + int index = 1; + for (Integer id : entidadIds) { + stmt.setInt(index++, id); + } + for (Integer id : puntoIds) { + stmt.setInt(index++, id); + } + + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { + BigDecimal total = rs.getBigDecimal("totalcobrado"); + int count = rs.getInt("numerocobros"); + return new totalCobrosHoyDTO(total != null ? total : BigDecimal.ZERO, count); + } else { + return new totalCobrosHoyDTO(BigDecimal.ZERO, 0); + } + + } catch (Exception e) { + throw new RuntimeException("Error al obtener total de cobros de hoy", e); + } + } + + @Transactional + public List obtenerTotalPagosAnualPorMes() { + String query = "SELECT TO_CHAR(fechapag, 'mm') AS mes, " + + "SUM(total) AS totalpagado, COUNT(total) AS numeropagos " + + "FROM pagosenc p " + + "INNER JOIN lotesenc l USING (numloteid) " + + "WHERE TO_CHAR(fechapag, 'yyyy') = TO_CHAR(SYSDATE, 'yyyy') " + + "AND entidadid = 1 AND puntoid IN (1, 2, 3, 5, 7) " + + "GROUP BY TO_CHAR(fechapag, 'mm') " + + "ORDER BY TO_CHAR(fechapag, 'mm')"; + + List lista = new ArrayList<>(); + + try (Connection connection = dataSource.getConnection(); + PreparedStatement stmt = connection.prepareStatement(query); + ResultSet rs = stmt.executeQuery()) { + + while (rs.next()) { + String mes = rs.getString("mes"); + BigDecimal total = rs.getBigDecimal("totalpagado"); + int count = rs.getInt("numeropagos"); + + lista.add(new totalPagosMesDTO( + mes, + total != null ? total : BigDecimal.ZERO, + count + )); + } + + } catch (Exception e) { + throw new RuntimeException("Error al obtener pagos anuales por mes", e); + } + + return lista; + } + + @Transactional + public List obtenerOtSuspension() { + String query = """ + SELECT COUNT(otid) AS ots, motivoid, descripcion FROM ( + SELECT predioid, otid, motivoid, m.descripcion, fecha, fechaprecierre, dictamenid, latitud, longitud, + RANK() OVER (PARTITION BY predioid ORDER BY otid DESC) AS orden + FROM ordentrabajoenc o + INNER JOIN ot_cortesfisicos f USING (motivoid) + INNER JOIN ot_motivos m USING (motivoid) + INNER JOIN predioslatlon l USING (predioid) + WHERE fechaprecierre IS NOT NULL + ) + WHERE orden = 1 + AND REGEXP_LIKE(dictamenid, 'SRC') + AND otid NOT IN ( + SELECT otipadre FROM ordentrabajoenc + WHERE otipadre IS NOT NULL + AND REGEXP_LIKE(dictamenid, 'SRR') + ) + GROUP BY motivoid, descripcion + ORDER BY motivoid + """; + + List lista = new ArrayList<>(); + + try (Connection connection = dataSource.getConnection(); + PreparedStatement stmt = connection.prepareStatement(query); + ResultSet rs = stmt.executeQuery()) { + + while (rs.next()) { + int ots = rs.getInt("ots"); + int motivoid = rs.getInt("motivoid"); + String descripcion = rs.getString("descripcion"); + + lista.add(new otSuspensionDTO(ots, motivoid, descripcion)); + } + + } catch (Exception e) { + throw new RuntimeException("Error al obtener OTs de suspensión", e); + } + + return lista; + } + + @Transactional + public otReconexDiaDTO obtenerOtsReconexDia() { + String query = """ + SELECT COUNT(otid) AS reconexdia + FROM ordentrabajoenc o + WHERE TRUNC(fechaprecierre) = TRUNC(SYSDATE) + AND motivoid IN ( + SELECT motivoid FROM ot_motivos WHERE origenid = 'REC' + ) + AND REGEXP_LIKE(dictamenid, 'SRR') + """; + + try (Connection connection = dataSource.getConnection(); + PreparedStatement stmt = connection.prepareStatement(query); + ResultSet rs = stmt.executeQuery()) { + + if (rs.next()) { + return new otReconexDiaDTO(rs.getInt("reconexdia")); + } else { + return new otReconexDiaDTO(0); + } + + } catch (Exception e) { + throw new RuntimeException("Error al obtener OTs de reconexión del día", e); + } + } + + @Transactional + public List obtenerCobFacVtaDia(String tipoFacVta) { + String query = """ + WITH reconexiones AS ( + SELECT facvtaencid, tipofacvtaid, nombre, cobroencid, cd.total, predioid, usoid + FROM cobrosdet cd + INNER JOIN cobrosenc ce USING (cobroencid) + INNER JOIN facturavtaenc fe USING (facvtaencid) + INNER JOIN tipofacturaventa USING (tipofacvtaid) + INNER JOIN predios p USING (predioid) + WHERE TRUNC(ce.fechacob) = TRUNC(SYSDATE) + AND REGEXP_LIKE(nombre, ?) + AND activo = 'S' + AND ce.fechaanu IS NULL + ) + SELECT usoid, u.nombre AS uso, COUNT(cobroencid) AS cobros, SUM(total) AS total + FROM reconexiones + INNER JOIN usos u USING (usoid) + GROUP BY usoid, u.nombre + ORDER BY usoid + """; + + List lista = new ArrayList<>(); + + try (Connection connection = dataSource.getConnection(); + PreparedStatement stmt = connection.prepareStatement(query)) { + + stmt.setString(1, tipoFacVta); + + ResultSet rs = stmt.executeQuery(); + while (rs.next()) { + String usoid = rs.getString("usoid"); + String uso = rs.getString("uso"); + int cobros = rs.getInt("cobros"); + BigDecimal total = rs.getBigDecimal("total"); + + lista.add(new cobFacVtaDiaDTO(usoid, uso, cobros, total != null ? total : BigDecimal.ZERO)); + } + + } catch (Exception e) { + throw new RuntimeException("Error al obtener cobros por tipo de factura de venta", e); + } + + return lista; + } + + @Transactional(readOnly = true) + public compCvDTO obtenerCompCv() { + String query = """ + select + sum(saldovencido) saldovencido, sum(saldonovencido) saldonovencido, + sum(vr11+vr12+vr13+vr14+vr15+vr16+vr17+vr112+vr116+vr118+vr21+vr22+vr122) vencrezago, + sum(va11+va12+va13+va14+va15+va16+va17+va112+va116+va118+va21+va22+va122) vencactual, + sum(nv11+nv12+nv13+nv14+nv15+nv16+nv17+nv112+nv116+nv118+nv21+nv22+nv122) novencido, + sum(vr5+vr6+vr7+vr8) recvencrezago, + sum(va5+va6+va7+va8) recvencactual, + sum(nv5+nv6+nv7+nv8) recnovencido, + sum(saldototal) saldototal, sum(saldogescob) saldogescob, + sum(vr11) vr11, sum(va11) va11, sum(nv11) nv11, + sum(vr12) vr12, sum(va12) va12, sum(nv12) nv12, + sum(vr13) vr13, sum(va13) va13, sum(nv13) nv13, + sum(vr14) vr14, sum(va14) va14, sum(nv14) nv14, + sum(vr15) vr15, sum(va15) va15, sum(nv15) nv15, + sum(vr16) vr16, sum(va16) va16, sum(nv16) nv16, + sum(vr17) vr17, sum(va17) va17, sum(nv17) nv17, + sum(vr112) vr112, sum(va112) va112, sum(nv112) nv112, + sum(vr116) vr116, sum(va116) va116, sum(nv116) nv116, + sum(vr118) vr118, sum(va118) va118, sum(nv118) nv118, + sum(vr21) vr21, sum(va21) va21, sum(nv21) nv21, + sum(vr22) vr22, sum(va22) va22, sum(nv22) nv22, + sum(vr122) vr122, sum(va122) va122, sum(nv122) nv122, + sum(vr5) vr5, sum(va5) va5, sum(nv5) nv5, + sum(vr6) vr6, sum(va6) va6, sum(nv6) nv6, + sum(vr7) vr7, sum(va7) va7, sum(nv7) nv7, + sum(vr8) vr8, sum(va8) va8, sum(nv8) nv8 + from cobranza.tblcvlive + """; + + try (Connection connection = dataSource.getConnection(); + PreparedStatement stmt = connection.prepareStatement(query); + ResultSet rs = stmt.executeQuery(query)) { + + if (rs.next()) { + compCvDTO dto = new compCvDTO(); + dto.setSaldovencido(rs.getBigDecimal("saldovencido")); + dto.setSaldonovencido(rs.getBigDecimal("saldonovencido")); + dto.setVencrezago(rs.getBigDecimal("vencrezago")); + dto.setVencactual(rs.getBigDecimal("vencactual")); + dto.setNovencido(rs.getBigDecimal("novencido")); + dto.setRecvencrezago(rs.getBigDecimal("recvencrezago")); + dto.setRecvencactual(rs.getBigDecimal("recvencactual")); + dto.setRecnovencido(rs.getBigDecimal("recnovencido")); + dto.setSaldototal(rs.getBigDecimal("saldototal")); + dto.setSaldogescob(rs.getBigDecimal("saldogescob")); + dto.setVr5(rs.getBigDecimal("vr5")); dto.setVa5(rs.getBigDecimal("va5")); dto.setNv5(rs.getBigDecimal("nv5")); + dto.setVr6(rs.getBigDecimal("vr6")); dto.setVa6(rs.getBigDecimal("va6")); dto.setNv6(rs.getBigDecimal("nv6")); + dto.setVr7(rs.getBigDecimal("vr7")); dto.setVa7(rs.getBigDecimal("va7")); dto.setNv7(rs.getBigDecimal("nv7")); + dto.setVr8(rs.getBigDecimal("vr8")); dto.setVa8(rs.getBigDecimal("va8")); dto.setNv8(rs.getBigDecimal("nv8")); + dto.setVr11(rs.getBigDecimal("vr11")); dto.setVa11(rs.getBigDecimal("va11")); dto.setNv11(rs.getBigDecimal("nv11")); + dto.setVr12(rs.getBigDecimal("vr12")); dto.setVa12(rs.getBigDecimal("va12")); dto.setNv12(rs.getBigDecimal("nv12")); + dto.setVr13(rs.getBigDecimal("vr13")); dto.setVa13(rs.getBigDecimal("va13")); dto.setNv13(rs.getBigDecimal("nv13")); + dto.setVr14(rs.getBigDecimal("vr14")); dto.setVa14(rs.getBigDecimal("va14")); dto.setNv14(rs.getBigDecimal("nv14")); + dto.setVr15(rs.getBigDecimal("vr15")); dto.setVa15(rs.getBigDecimal("va15")); dto.setNv15(rs.getBigDecimal("nv15")); + dto.setVr16(rs.getBigDecimal("vr16")); dto.setVa16(rs.getBigDecimal("va16")); dto.setNv16(rs.getBigDecimal("nv16")); + dto.setVr17(rs.getBigDecimal("vr17")); dto.setVa17(rs.getBigDecimal("va17")); dto.setNv17(rs.getBigDecimal("nv17")); + dto.setVr21(rs.getBigDecimal("vr21")); dto.setVa21(rs.getBigDecimal("va21")); dto.setNv21(rs.getBigDecimal("nv21")); + dto.setVr22(rs.getBigDecimal("vr22")); dto.setVa22(rs.getBigDecimal("va22")); dto.setNv22(rs.getBigDecimal("nv22")); + dto.setVr112(rs.getBigDecimal("vr112")); dto.setVa112(rs.getBigDecimal("va112")); dto.setNv112(rs.getBigDecimal("nv112")); + dto.setVr116(rs.getBigDecimal("vr116")); dto.setVa116(rs.getBigDecimal("va116")); dto.setNv116(rs.getBigDecimal("nv116")); + dto.setVr118(rs.getBigDecimal("vr118")); dto.setVa118(rs.getBigDecimal("va118")); dto.setNv118(rs.getBigDecimal("nv118")); + dto.setVr122(rs.getBigDecimal("vr122")); dto.setVa122(rs.getBigDecimal("va122")); dto.setNv122(rs.getBigDecimal("nv122")); + + return dto; + } else { + throw new RuntimeException("No se obtuvo información de la tabla cobranza.tblcvlive"); + } + + } catch (Exception e) { + throw new RuntimeException("Error al obtener comparativo de cartera vencida", e); + } + } + }