Correção de valor pendente no relatorio de depositos #AL-2259

Merge pull request 'AL-2259' (!84) from #AL-2259 into master
Reviewed-on: http://18.235.188.113:3000/adm/VentaBoletosAdm/pulls/84
Reviewed-by: Valdir Cordeiro <valdir.cordeiro@totvs.com.br>
Reviewed-by: Gleison da Cruz <gleison.cruz@totvs.com.br>
master 1.0.65
fabio 2023-03-01 20:11:56 +00:00
commit eb4da7faf0
4 changed files with 69 additions and 94 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.rjconsultores</groupId>
<artifactId>ventaboletosadm</artifactId>
<version>1.0.64</version>
<version>1.0.65</version>
<packaging>war</packaging>
<properties>

View File

@ -35,33 +35,33 @@ public class RelatorioBoletos extends Relatorio {
Map<String, Object> parametros = this.relatorio.getParametros();
Integer puntoventaId = parametros.get("puntoventaId") != null ? Integer.parseInt(parametros.get("puntoventaId").toString()) : null;
Integer empresaId = parametros.get("empresaId") != null ? Integer.parseInt(parametros.get("empresaId").toString()) : null;
Integer puntoventaId = parametros.get(PUNTOVENTA_ID) != null ? Integer.parseInt(parametros.get(PUNTOVENTA_ID).toString()) : null;
Integer empresaId = parametros.get(EMPRESA_ID) != null ? Integer.parseInt(parametros.get(EMPRESA_ID).toString()) : null;
Boolean filtrarPendentes = parametros.get("filtrarPendentes") != null ? Boolean.parseBoolean(parametros.get("filtrarPendentes").toString()) : false;
String fecInicio = parametros.get("fecInicio") != null ? parametros.get("fecInicio").toString() + " 00:00:00" :null;
String fecFinal = parametros.get("fecFinal") != null ? parametros.get("fecFinal").toString() + " 23:59:59" :null;
String baixaInicial = parametros.get("baixaInicial") != null ? parametros.get("baixaInicial").toString() + " 00:00:00" :null;
String baixaFinal = parametros.get("baixaFinal") != null ? parametros.get("baixaFinal").toString() + " 23:59:59" :null;
String fecInicio = parametros.get(FEC_INICIO) != null ? parametros.get(FEC_INICIO).toString() + " 00:00:00" :null;
String fecFinal = parametros.get(FEC_FINAL) != null ? parametros.get(FEC_FINAL).toString() + " 23:59:59" :null;
String baixaInicial = parametros.get(BAIXA_INICIAL) != null ? parametros.get(BAIXA_INICIAL).toString() + " 00:00:00" :null;
String baixaFinal = parametros.get(BAIXA_FINAL) != null ? parametros.get(BAIXA_FINAL).toString() + " 23:59:59" :null;
String sql = getSQL(puntoventaId, empresaId, filtrarPendentes, fecInicio, fecFinal, baixaInicial, baixaFinal);
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
if(fecInicio != null && fecFinal != null) {
stmt.setTimestamp("fecInicio", DateUtil.getTimestampFromString(fecInicio, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp("fecFinal", DateUtil.getTimestampFromString(fecFinal, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp(FEC_INICIO, DateUtil.getTimestampFromString(fecInicio, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp(FEC_FINAL, DateUtil.getTimestampFromString(fecFinal, DateUtil.ddMMaaHH24mmss));
}
if(baixaInicial != null && baixaFinal != null) {
stmt.setTimestamp("baixaInicial", DateUtil.getTimestampFromString(baixaInicial, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp("baixaFinal", DateUtil.getTimestampFromString(baixaFinal, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp(BAIXA_INICIAL, DateUtil.getTimestampFromString(baixaInicial, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp(BAIXA_FINAL, DateUtil.getTimestampFromString(baixaFinal, DateUtil.ddMMaaHH24mmss));
}
if(puntoventaId != null) {
stmt.setInt("puntoventaId", puntoventaId);
if(puntoventaId != null && puntoventaId != -1) {
stmt.setInt(PUNTOVENTA_ID, puntoventaId);
}
if(empresaId != null) {
stmt.setInt("empresaId", empresaId);
stmt.setInt(EMPRESA_ID, empresaId);
}
ResultSet rs = stmt.executeQuery();
@ -88,49 +88,11 @@ public class RelatorioBoletos extends Relatorio {
}else {
boleto.setVrpendente(boleto.getVrboleto());
}
/*
if (! filtrarPendentes){
}
boolean isPontoVendaEmpresaDiferente = (puntoventaIdAux == null || !puntoventaIdAux.equals(deposito.getPuntoventaId())) ||
(empresaIdAux == null || !empresaIdAux.equals(deposito.getEmpresaId()));
if(fechamentocntcorrenteId == null) {
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
} if(!isPontoVendaEmpresaDiferente && dtMotivo != null && DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) == 0 && !fechamentocntcorrenteId.equals(rs.getLong("fechamentocntcorrenteId"))) {
pendente = deposito.getVrfechamento();
totalFechamento = totalFechamento.add(deposito.getVrfechamento());
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
}
if(isPontoVendaEmpresaDiferente || (dtMotivo == null || DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) != 0)) {
if(isPontoVendaEmpresaDiferente) {
puntoventaIdAux = deposito.getPuntoventaId();
empresaIdAux = deposito.getEmpresaId();
pendente = deposito.getVrfechamento();
dtMotivo = deposito.getDtmotivo();
totalFechamento = totalFechamento.add(deposito.getVrfechamento());
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
}
if(dtMotivo == null || DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) != 0) {
pendente = deposito.getVrfechamento();
totalFechamento = totalFechamento.add(deposito.getVrfechamento());
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
}
dtMotivo = deposito.getDtmotivo();
}
pendente = pendente.subtract(deposito.getVrdeposito());
deposito.setVrpendente(pendente);
*/
lsDadosRelatorio.add(boleto);
}
if (lsDadosRelatorio.size() > 0) {
if (!lsDadosRelatorio.isEmpty()) {
setLsDadosRelatorio(lsDadosRelatorio);
}
@ -190,7 +152,7 @@ public class RelatorioBoletos extends Relatorio {
sql.append(" AND fb.fecbaixa BETWEEN :baixaInicial AND :baixaFinal ");
}
if(puntoventaId != null) {
if(puntoventaId != null && puntoventaId != -1) {
sql.append(" AND fcc.puntoventa_id = :puntoventaId ");
}

View File

@ -2,9 +2,7 @@ package com.rjconsultores.ventaboletos.relatorios.impl;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -16,6 +14,7 @@ import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioDepositoBean;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
@ -37,26 +36,31 @@ public class RelatorioDepositos extends Relatorio {
Map<String, Object> parametros = this.relatorio.getParametros();
Integer puntoventaId = parametros.get("puntoventaId") != null ? Integer.parseInt(parametros.get("puntoventaId").toString()) : null;
Integer empresaId = parametros.get("empresaId") != null ? Integer.parseInt(parametros.get("empresaId").toString()) : null;
Boolean filtrarPendentes = parametros.get("filtrarPendentes") != null ? Boolean.parseBoolean(parametros.get("filtrarPendentes").toString()) : false;
String fecInicio = parametros.get("fecInicio").toString() + " 00:00:00";
String fecFinal = parametros.get("fecFinal").toString() + " 23:59:59";
Integer puntoventaId = parametros.get(PUNTOVENTA_ID) != null ? Integer.parseInt(parametros.get(PUNTOVENTA_ID).toString()) : null;
Integer empresaId = parametros.get(EMPRESA_ID) != null ? Integer.parseInt(parametros.get(EMPRESA_ID).toString()) : null;
boolean filtrarPendentes = parametros.get("filtrarPendentes") != null ? Boolean.parseBoolean(parametros.get("filtrarPendentes").toString()) : false;
String fecInicio = parametros.get(FEC_INICIO).toString() + " 00:00:00";
String fecFinal = parametros.get(FEC_FINAL).toString() + " 23:59:59";
String sql = getSQL(puntoventaId, empresaId, filtrarPendentes);
PreparedStatement stmt = conexao.prepareStatement(sql);
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
ResultSet rs = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
stmt.setTimestamp(FEC_INICIO, DateUtil.getTimestampFromString(fecInicio, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp(FEC_FINAL, DateUtil.getTimestampFromString(fecFinal, DateUtil.ddMMaaHH24mmss));
stmt.setTimestamp(1, new java.sql.Timestamp(sdf.parse(fecInicio).getTime()));
stmt.setTimestamp(2, new java.sql.Timestamp(sdf.parse(fecFinal).getTime()));
if(puntoventaId != null && puntoventaId != -1) {
stmt.setInt(PUNTOVENTA_ID, puntoventaId);
}
rs = stmt.executeQuery();
if(empresaId != null) {
stmt.setInt(EMPRESA_ID, empresaId);
}
ResultSet rs = stmt.executeQuery();
rs.setFetchSize(500);
lsDadosRelatorio = new ArrayList<RelatorioDepositoBean>();
lsDadosRelatorio = new ArrayList<>();
Integer puntoventaIdAux = null;
Integer empresaIdAux = null;
@ -74,9 +78,8 @@ public class RelatorioDepositos extends Relatorio {
deposito.setSaldo(rs.getBigDecimal("saldo").multiply(BigDecimal.valueOf(-1)));
deposito.setVrdeposito(rs.getBigDecimal("vlrBoletoDeposito"));
deposito.setVrfechamento(rs.getBigDecimal("vrfechamento"));
deposito.setEmpresaId(rs.getInt("empresaId"));
deposito.setPuntoventaId(rs.getInt("puntoventaId"));
deposito.setEmpresaId(rs.getInt(EMPRESA_ID));
deposito.setPuntoventaId(rs.getInt(PUNTOVENTA_ID));
if (! filtrarPendentes){
deposito.setNumdeposito(rs.getString("numdeposito"));
@ -86,11 +89,11 @@ public class RelatorioDepositos extends Relatorio {
(empresaIdAux == null || !empresaIdAux.equals(deposito.getEmpresaId()));
if(fechamentocntcorrenteId == null) {
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
} if(!isPontoVendaEmpresaDiferente && dtMotivo != null && DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) == 0 && !fechamentocntcorrenteId.equals(rs.getLong("fechamentocntcorrenteId"))) {
fechamentocntcorrenteId = rs.getLong(FECHAMENTOCNTCORRENTE_ID);
} if(!isPontoVendaEmpresaDiferente && dtMotivo != null && DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) == 0 && !fechamentocntcorrenteId.equals(rs.getLong(FECHAMENTOCNTCORRENTE_ID))) {
pendente = deposito.getVrfechamento();
totalFechamento = totalFechamento.add(deposito.getVrfechamento());
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
fechamentocntcorrenteId = rs.getLong(FECHAMENTOCNTCORRENTE_ID);
}
if(isPontoVendaEmpresaDiferente || (dtMotivo == null || DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) != 0)) {
@ -101,13 +104,13 @@ public class RelatorioDepositos extends Relatorio {
pendente = deposito.getVrfechamento();
dtMotivo = deposito.getDtmotivo();
totalFechamento = totalFechamento.add(deposito.getVrfechamento());
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
fechamentocntcorrenteId = rs.getLong(FECHAMENTOCNTCORRENTE_ID);
}
if(dtMotivo == null || DateUtil.compareOnlyDate(dtMotivo, deposito.getDtmotivo()) != 0) {
pendente = deposito.getVrfechamento();
totalFechamento = totalFechamento.add(deposito.getVrfechamento());
fechamentocntcorrenteId = rs.getLong("fechamentocntcorrenteId");
fechamentocntcorrenteId = rs.getLong(FECHAMENTOCNTCORRENTE_ID);
}
dtMotivo = deposito.getDtmotivo();
}
@ -118,7 +121,7 @@ public class RelatorioDepositos extends Relatorio {
lsDadosRelatorio.add(deposito);
}
if (lsDadosRelatorio.size() > 0) {
if (!lsDadosRelatorio.isEmpty()) {
setLsDadosRelatorio(lsDadosRelatorio);
}
parametros.put("totalFechamento", totalFechamento);
@ -138,6 +141,7 @@ public class RelatorioDepositos extends Relatorio {
@Override
protected void processaParametros() throws Exception {
// TODO document why this method is empty
}
private String getSQL(Integer puntoVentaId, Integer empresaId, boolean filtrarPendentes) {
@ -165,10 +169,10 @@ public class RelatorioDepositos extends Relatorio {
sql.append(" p.numpuntoventa, ");
sql.append(" p.puntoventa_id as puntoventaId, ");
sql.append(" e.empresa_id as empresaId, ");
sql.append(" f.fecfechamento AS dtmotivo, ");
sql.append(" ( SUM(COALESCE(fd.valor_pago,fbol.valordocumento,0)) - f.total ) AS saldo, ");
sql.append(" SUM(COALESCE(fd.valor_pago,fbol.valordocumento,0)) AS vlrBoletoDeposito, ");
sql.append(" f.total AS vrfechamento, ");
sql.append(" f.fecfechamento as dtmotivo, ");
sql.append(" ( SUM(COALESCE(fd.valor_pago,0)) - f.total ) AS saldo, ");
sql.append(" SUM(COALESCE(fd.valor_pago,0)) AS vlrBoletoDeposito, ");
sql.append(" f.total as vrfechamento, ");
if (! filtrarPendentes){
sql.append(" fdp.NUMDEPOSITO as numdeposito, ");
@ -178,8 +182,10 @@ public class RelatorioDepositos extends Relatorio {
sql.append(" FROM fechamento_cntcorrente f ");
sql.append(" INNER JOIN punto_venta p ");
sql.append(" ON p.puntoventa_id = f.puntoventa_id ");
sql.append(" AND p.activo = 1 ");
sql.append(" INNER JOIN empresa e ");
sql.append(" ON e.empresa_id = f.empresa_id ");
sql.append(" AND e.activo = 1 ");
sql.append(" INNER JOIN fechamento_boleto fbol ");
sql.append(" ON f.fechamentocntcorrente_id = fbol.fechamentocntcorrente_id ");
sql.append(" AND fbol.tipo_pagamento = 'D' ");
@ -190,16 +196,15 @@ public class RelatorioDepositos extends Relatorio {
sql.append(" LEFT JOIN FECHAMENTO_DEPOSITO fdp ");
sql.append(" ON fdp.FECHAMENTODEPOSITO_ID = fd.FECHAMENTODEPOSITO_ID ");
sql.append(" AND fdp.activo = 1 ");
sql.append(" WHERE f.fecfechamento BETWEEN ? AND ? ");
sql.append(" WHERE f.fecfechamento BETWEEN :fecInicio AND :fecFinal ");
sql.append(" AND f.activo = 1 ");
sql.append(" AND e.activo = 1 ");
sql.append(" AND p.activo = 1 ");
if(puntoVentaId != null && puntoVentaId != -1) {
sql.append(" and f.puntoventa_id = " + puntoVentaId);
sql.append(" AND f.puntoventa_id = :puntoventaId ");
}
if (empresaId != null && empresaId != -1){
sql.append(" and e.empresa_id = " + empresaId);
if(empresaId != null) {
sql.append(" AND e.empresa_id = :empresaId ");
}
sql.append(" GROUP BY e.nombempresa, ");
sql.append(" p.nombpuntoventa, ");

View File

@ -21,6 +21,14 @@ public abstract class Relatorio {
private static final String DEFAULT_BASE_DIR = "/com/rjconsultores/ventaboletos/relatorios";
private static final String FILTRO_POR_TODOS = "-1";
protected static final String BAIXA_FINAL = "baixaFinal";
protected static final String BAIXA_INICIAL = "baixaInicial";
protected static final String FEC_FINAL = "fecFinal";
protected static final String FEC_INICIO = "fecInicio";
protected static final String EMPRESA_ID = "empresaId";
protected static final String PUNTOVENTA_ID = "puntoventaId";
protected static final String FECHAMENTOCNTCORRENTE_ID = "fechamentocntcorrenteId";
private Connection conexao;
protected Map<String, Object> parametros;
protected RenderRelatorioJasper render;