From 41e0443226337b7b4982bf5a255507125c87a168 Mon Sep 17 00:00:00 2001 From: "alexandre.lima" Date: Tue, 27 Jun 2017 19:19:27 +0000 Subject: [PATCH] Fixes Bug #0009258 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@70692 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../impl/RelatorioVendasPacotesBoletos.java | 375 +++++++++--------- 1 file changed, 188 insertions(+), 187 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesBoletos.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesBoletos.java index 9478ae229..a82850044 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesBoletos.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesBoletos.java @@ -22,16 +22,16 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; public class RelatorioVendasPacotesBoletos extends Relatorio { - + private static Logger log = Logger.getLogger(RelatorioVendasPacotesBoletos.class); - + public static final Integer VENDIDOS = 1; public static final Integer CANCELADOS = 0; private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - + private List lsDadosRelatorio; - + private Timestamp fecVendaInicio; private Timestamp fecVendaFinal; private Timestamp fecPacoteInicio; @@ -42,12 +42,11 @@ public class RelatorioVendasPacotesBoletos extends Relatorio { private Integer usuarioId; private Integer tipoTarifaPacoteId; private Integer situacaoBilheteId; - + public RelatorioVendasPacotesBoletos(Map parametros, Connection conexao, final String... nomeSubReporte) throws Exception { super(parametros, conexao); - - this.setCustomDataSource(new DataSource(this) { + this.setCustomDataSource(new DataSource(this) { @Override public void initDados() throws Exception { @@ -62,74 +61,74 @@ public class RelatorioVendasPacotesBoletos extends Relatorio { usuarioId = parametros.get("usuarioId") != null && !parametros.get("usuarioId").equals("null") ? Integer.valueOf(parametros.get("usuarioId").toString()) : null; tipoTarifaPacoteId = parametros.get("tipoTarifaPacoteId") != null && !parametros.get("tipoTarifaPacoteId").equals("null") ? Integer.valueOf(parametros.get("tipoTarifaPacoteId").toString()) : null; situacaoBilheteId = parametros.get("situacaoBilheteId") != null && !parametros.get("situacaoBilheteId").equals("null") ? Integer.valueOf(parametros.get("situacaoBilheteId").toString()) : null; - + Connection conexao = this.relatorio.getConexao(); processarVendasPacote(conexao); - + /* Caso o filtro de data de venda de pacote seja informado, não trazer bilhetes avulsos */ - if(fecPacoteInicio == null && fecPacoteFinal == null) { - if(situacaoBilheteId == null || !CANCELADOS.equals(situacaoBilheteId)) { + if (fecPacoteInicio == null && fecPacoteFinal == null) { + if (situacaoBilheteId == null || !CANCELADOS.equals(situacaoBilheteId)) { processarVendasAvulsas(conexao); } - if(situacaoBilheteId == null || CANCELADOS.equals(situacaoBilheteId)) { + if (situacaoBilheteId == null || CANCELADOS.equals(situacaoBilheteId)) { processarVendasAvulsasCancelados(conexao); } } processarVendasPacoteTotais(); - + setNomeSubReporte(nomeSubReporte); setLsDadosRelatorio(lsDadosRelatorio); } }); } - + private void processarVendasPacote(Connection conexao) { ResultSet rset = null; NamedParameterStatement stmt = null; - + try { stmt = carregarNamedParameterStatementVendasPacotes(conexao); rset = stmt.executeQuery(); - - if(lsDadosRelatorio == null) { + + if (lsDadosRelatorio == null) { lsDadosRelatorio = new ArrayList(); } - + while (rset.next()) { RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset); Integer idx = carregarIndice(relatorioVendasBoletosBean); - - if(idx > -1) { - relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); + + if (idx > -1) { + relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); } - + relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeans(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeans(), false)); - - if(idx > -1) { + + if (idx > -1) { lsDadosRelatorio.set(idx, relatorioVendasBoletosBean); } else { lsDadosRelatorio.add(relatorioVendasBoletosBean); } } - + } catch (Exception e) { log.error(e.getMessage(), e); } finally { try { - if(rset != null) { + if (rset != null) { rset.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } catch (SQLException e) { log.error(e.getMessage(), e); } } - + } - + private List carregarItens(ResultSet rset, RelatorioVendasPacotesBoletosBean relatorioVendasPacotesBoletosBean, List itens, Boolean cancelado) throws SQLException { RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean relatorioVendasPacotesBoletosItemBean = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemBean(); relatorioVendasPacotesBoletosItemBean.setNumruta(rset.getString("numruta")); @@ -147,18 +146,18 @@ public class RelatorioVendasPacotesBoletos extends Relatorio { relatorioVendasPacotesBoletosItemBean.setQtdeImpresso(rset.getInt("qtdeimpresso")); relatorioVendasPacotesBoletosItemBean.setTipoVenda(rset.getString("tipovenda")); relatorioVendasPacotesBoletosItemBean.setAvulsoCancelado(cancelado); - - if(itens == null) { + + if (itens == null) { itens = new ArrayList(); } itens.add(relatorioVendasPacotesBoletosItemBean); - + return itens; } private Integer carregarIndice(RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean) { Integer idx = -1; - if(lsDadosRelatorio.contains(relatorioVendasBoletosBean)) { + if (lsDadosRelatorio.contains(relatorioVendasBoletosBean)) { idx = lsDadosRelatorio.indexOf(relatorioVendasBoletosBean); relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); } @@ -171,154 +170,156 @@ public class RelatorioVendasPacotesBoletos extends Relatorio { relatorioVendasPacotesBoletosBean.setDescorigen(rset.getString("origem")); relatorioVendasPacotesBoletosBean.setCvedestino(rset.getString("cvedestino")); relatorioVendasPacotesBoletosBean.setCveorigen(rset.getString("cveorigem")); - + return relatorioVendasPacotesBoletosBean; } private NamedParameterStatement carregarNamedParameterStatementVendasPacotes(Connection conexao) throws SQLException { String sql = getSqlVendasPacotes(); log.info(sql); - + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); - - if(fecVendaInicio != null) { + + if (fecVendaInicio != null) { stmt.setTimestamp("fecVendaInicio", fecVendaInicio); } - if(fecVendaFinal != null) { + if (fecVendaFinal != null) { stmt.setTimestamp("fecVendaFinal", fecVendaFinal); } - if(fecPacoteInicio != null) { + if (fecPacoteInicio != null) { stmt.setTimestamp("fecPacoteInicio", fecPacoteInicio); } - if(fecPacoteFinal != null) { + if (fecPacoteFinal != null) { stmt.setTimestamp("fecPacoteFinal", fecPacoteFinal); } - if (empresaId != null && empresaId > 0){ + if (empresaId != null && empresaId > 0) { stmt.setInt("empresaId", empresaId); } - if(origenId != null && origenId > 0){ + if (origenId != null && origenId > 0) { stmt.setInt("origenId", origenId); } - if(destinoId != null && destinoId > 0){ + if (destinoId != null && destinoId > 0) { stmt.setInt("destinoId", destinoId); } - if(usuarioId != null) { + if (usuarioId != null) { stmt.setInt("usuarioId", usuarioId); } - if(tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) { + if (tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) { stmt.setInt("tipoTarifaPacoteId", tipoTarifaPacoteId); } - if(situacaoBilheteId != null) { - stmt.setInt("situacaoPacote",SituacaoVendaPacote.CANCELADO.getShortValue()); + if (situacaoBilheteId != null) { + stmt.setInt("situacaoPacote", SituacaoVendaPacote.CANCELADO.getShortValue()); } - + return stmt; } protected String getSqlVendasPacotes() { StringBuilder sQuery = new StringBuilder(); - + sQuery.append("SELECT DES.CVEPARADA AS CVEDESTINO, ORI.CVEPARADA AS CVEORIGEM, ORI.DESCPARADA AS ORIGEM, DES.DESCPARADA AS DESTINO, R.NUMRUTA, R.DESCRUTA, PC.NOMCONVENIO, TTP.DESCTIPOTARIFA, VP.SITUACAO, ") - .append("SUM(CASE WHEN B.MOTIVOCANCELACION_ID = 16 THEN 1 ELSE 0 END) AS QTDEIMPRESSO, ") - .append("COUNT(TVP.TARIFAVENDAPACOTE_ID) AS QTDE, SUM(T.IMPORTETAXAEMBARQUE) AS SIMPORTETAXAEMBARQUE, SUM(T.IMPORTEPEDAGIO) AS SIMPORTEPEDAGIO, ") - .append("SUM(NVL(T.IMPORTEOUTROS,0)) AS SIMPORTEOUTROS, SUM(NVL(T.IMPORTESEGURO,0)) AS SIMPORTESEGURO, SUM(NVL(B.PRECIOBASE,0)) AS SPRECIOBASE, ") - .append(" SUM( ") - .append(" B.PRECIOBASE+NVL(T.IMPORTETAXAEMBARQUE,0)+NVL(T.IMPORTEPEDAGIO,0)+NVL(T.IMPORTESEGURO,0)+NVL(T.IMPORTEOUTROS,0)- ") - .append(" B.PRECIOPAGADO-NVL(B.IMPORTETAXAEMBARQUE,0)-NVL(B.IMPORTEPEDAGIO,0)-NVL(B.IMPORTESEGURO,0)-NVL(B.IMPORTEOUTROS,0) ") - .append(" ) AS DESCONTO, ") - .append("'PACOTE' AS TIPOVENDA ") - .append("FROM VENDA_PACOTE VP ") - .append("INNER JOIN PACOTE P ON P.PACOTE_ID = VP.PACOTE_ID AND P.ACTIVO = 1 ") - .append("LEFT JOIN TARIFA_VENDA_PACOTE TVP ON TVP.VENDAPACOTE_ID = VP.VENDAPACOTE_ID ") - .append("INNER JOIN BOLETO B ON B.BOLETO_ID = TVP.BOLETO_ID ") - .append("LEFT JOIN RUTA R ON R.RUTA_ID = B.RUTA_ID ") - .append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_ID ") - .append("LEFT JOIN PARADA DES ON DES.PARADA_ID = B.DESTINO_ID ") - .append("LEFT JOIN PACOTE_TARIFA PT ON PT.PACOTETARIFA_ID = TVP.PACOTETARIFA_ID ") - .append("LEFT JOIN TIPO_TARIFA_PACOTE TTP ON TTP.TIPOTARIFAPACOTE_ID = PT.TIPOTARIFAPACOTE_ID ") - .append("LEFT JOIN PACOTE_CONVENIO PC ON PC.PACOTECONVENIO_ID = TVP.PACOTECONVENIO_ID AND PC.ACTIVO = 1 ") - .append("LEFT JOIN VIGENCIA_TARIFA VT ON B.FECHORVENTA BETWEEN VT.FECINICIOVIGENCIA AND VT.FECFINVIGENCIA ") - .append("LEFT JOIN TARIFA T ON T.RUTA_ID = B.RUTA_ID ") - .append(" AND T.DESTINO_ID = B.DESTINO_ID ") - .append(" AND T.ORIGEN_ID = B.ORIGEN_ID ") - .append(" AND T.CLASESERVICIO_ID = B.CLASESERVICIO_ID ") - .append(" AND T.ACTIVO = 1 ") - .append(" AND VT.VIGENCIATARIFA_ID = T.VIGENCIATARIFA_ID ") - .append(" AND T.ORGAOCONCEDENTE_ID = R.ORGAOCONCEDENTE_ID ") - .append("WHERE 1=1 "); - - if(fecVendaInicio != null) { + .append("SUM(CASE WHEN B.MOTIVOCANCELACION_ID = 16 THEN 1 ELSE 0 END) AS QTDEIMPRESSO, ") + .append("COUNT(TVP.TARIFAVENDAPACOTE_ID) AS QTDE, SUM(T.IMPORTETAXAEMBARQUE) AS SIMPORTETAXAEMBARQUE, SUM(T.IMPORTEPEDAGIO) AS SIMPORTEPEDAGIO, ") + .append("SUM(NVL(T.IMPORTEOUTROS,0)) AS SIMPORTEOUTROS, SUM(NVL(T.IMPORTESEGURO,0)) AS SIMPORTESEGURO, SUM(NVL(B.PRECIOBASE,0)) AS SPRECIOBASE, ") + .append(" SUM( ") + .append(" B.PRECIOBASE+NVL(T.IMPORTETAXAEMBARQUE,0)+NVL(T.IMPORTEPEDAGIO,0)+NVL(T.IMPORTESEGURO,0)+NVL(T.IMPORTEOUTROS,0)- ") + .append(" B.PRECIOPAGADO-NVL(B.IMPORTETAXAEMBARQUE,0)-NVL(B.IMPORTEPEDAGIO,0)-NVL(B.IMPORTESEGURO,0)-NVL(B.IMPORTEOUTROS,0) ") + .append(" ) AS DESCONTO, ") + .append("'PACOTE' AS TIPOVENDA ") + .append("FROM VENDA_PACOTE VP ") + .append("INNER JOIN PACOTE P ON P.PACOTE_ID = VP.PACOTE_ID AND P.ACTIVO = 1 ") + .append("LEFT JOIN TARIFA_VENDA_PACOTE TVP ON TVP.VENDAPACOTE_ID = VP.VENDAPACOTE_ID ") + .append("INNER JOIN BOLETO B ON B.BOLETO_ID = TVP.BOLETO_ID ") + .append("LEFT JOIN RUTA R ON R.RUTA_ID = B.RUTA_ID ") + .append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_ID ") + .append("LEFT JOIN PARADA DES ON DES.PARADA_ID = B.DESTINO_ID ") + .append("LEFT JOIN PACOTE_TARIFA PT ON PT.PACOTETARIFA_ID = TVP.PACOTETARIFA_ID ") + .append("LEFT JOIN TIPO_TARIFA_PACOTE TTP ON TTP.TIPOTARIFAPACOTE_ID = PT.TIPOTARIFAPACOTE_ID ") + .append("LEFT JOIN PACOTE_CONVENIO PC ON PC.PACOTECONVENIO_ID = TVP.PACOTECONVENIO_ID AND PC.ACTIVO = 1 ") + .append("LEFT JOIN VIGENCIA_TARIFA VT ON B.FECHORVENTA BETWEEN VT.FECINICIOVIGENCIA AND VT.FECFINVIGENCIA ") + .append("LEFT JOIN TARIFA T ON T.RUTA_ID = B.RUTA_ID ") + .append(" AND T.DESTINO_ID = B.DESTINO_ID ") + .append(" AND T.ORIGEN_ID = B.ORIGEN_ID ") + .append(" AND T.CLASESERVICIO_ID = B.CLASESERVICIO_ID ") + .append(" AND T.ACTIVO = 1 ") + .append(" AND VT.VIGENCIATARIFA_ID = T.VIGENCIATARIFA_ID ") + .append(" AND T.ORGAOCONCEDENTE_ID = R.ORGAOCONCEDENTE_ID ") + .append("WHERE 1=1 "); + + if (fecVendaInicio != null) { sQuery.append("AND VP.DATAVENDA >= :fecVendaInicio "); } - - if(fecVendaFinal != null) { + + if (fecVendaFinal != null) { sQuery.append("AND VP.DATAVENDA <= :fecVendaFinal "); } - - if(fecPacoteInicio != null) { + + if (fecPacoteInicio != null) { sQuery.append("AND VP.DATAPACOTE >= :fecPacoteInicio "); } - - if(fecPacoteFinal != null) { + + if (fecPacoteFinal != null) { sQuery.append("AND VP.DATAPACOTE <= :fecPacoteFinal "); } - - if(empresaId != null && empresaId > 0){ + + if (empresaId != null && empresaId > 0) { sQuery.append("AND P.EMPRESA_ID = :empresaId "); } - if(origenId != null && origenId > 0){ + if (origenId != null && origenId > 0) { sQuery.append("AND B.ORIGEN_ID = :origenId "); } - - if(destinoId != null && destinoId > 0){ + + if (destinoId != null && destinoId > 0) { sQuery.append("AND B.DESTINO_ID = :destinoId "); } - if(usuarioId != null) { + if (usuarioId != null) { sQuery.append("AND VP.USUARIO_ID = :usuarioId "); } - if(tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) { + if (tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) { sQuery.append("AND TTP.TIPOTARIFAPACOTE_ID = :tipoTarifaPacoteId "); } - - if(situacaoBilheteId != null) { + + if (situacaoBilheteId != null) { } - - if(situacaoBilheteId != null && !CANCELADOS.equals(situacaoBilheteId)) { + + if (situacaoBilheteId != null && !CANCELADOS.equals(situacaoBilheteId)) { sQuery.append("AND VP.SITUACAO <> :situacaoPacote "); } - - if(situacaoBilheteId != null && CANCELADOS.equals(situacaoBilheteId)) { + + if (situacaoBilheteId != null && CANCELADOS.equals(situacaoBilheteId)) { sQuery.append("AND VP.SITUACAO = :situacaoPacote "); } sQuery.append("GROUP BY DES.CVEPARADA, ORI.CVEPARADA, ORI.DESCPARADA, DES.DESCPARADA, R.NUMRUTA, R.DESCRUTA, PC.NOMCONVENIO, TTP.DESCTIPOTARIFA, VP.SITUACAO, 'PACOTE' ") - .append("ORDER BY DES.CVEPARADA, ORI.CVEPARADA, ORI.DESCPARADA, DES.DESCPARADA, R.NUMRUTA, R.DESCRUTA, PC.NOMCONVENIO, TTP.DESCTIPOTARIFA, VP.SITUACAO, 'PACOTE' "); - + .append("ORDER BY DES.CVEPARADA, ORI.CVEPARADA, ORI.DESCPARADA, DES.DESCPARADA, R.NUMRUTA, R.DESCRUTA, PC.NOMCONVENIO, TTP.DESCTIPOTARIFA, VP.SITUACAO, 'PACOTE' "); + return sQuery.toString(); } - + private void processarVendasPacoteTotais() { List totais = new ArrayList(); for (RelatorioVendasPacotesBoletosBean relatorioVendasPacotesBoletosBean : lsDadosRelatorio) { - for (RelatorioVendasPacotesBoletosItemBean item : relatorioVendasPacotesBoletosBean.getRelatorioVendasPacotesBoletosItemBeans()) { - RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean total = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemTotaisBean(); - total.setTrecho(relatorioVendasPacotesBoletosBean.getCveorigen()+"-"+relatorioVendasPacotesBoletosBean.getCvedestino()); - total.setCategoria(item.getDesctipotarifa()); - total.setQtde(0l); - Integer idx = null; - if(totais.contains(total)) { - idx = totais.indexOf(total); - total = totais.get(idx); - } - total.setQtde(total.getQtde() + item.getQtde()); - - if(idx == null) { - totais.add(total); - } else { - totais.set(idx, total); + if (relatorioVendasPacotesBoletosBean.getRelatorioVendasPacotesBoletosItemBeans() != null) { + for (RelatorioVendasPacotesBoletosItemBean item : relatorioVendasPacotesBoletosBean.getRelatorioVendasPacotesBoletosItemBeans()) { + RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean total = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemTotaisBean(); + total.setTrecho(relatorioVendasPacotesBoletosBean.getCveorigen() + "-" + relatorioVendasPacotesBoletosBean.getCvedestino()); + total.setCategoria(item.getDesctipotarifa()); + total.setQtde(0l); + Integer idx = null; + if (totais.contains(total)) { + idx = totais.indexOf(total); + total = totais.get(idx); + } + total.setQtde(total.getQtde() + item.getQtde()); + + if (idx == null) { + totais.add(total); + } else { + totais.set(idx, total); + } } } } @@ -328,7 +329,7 @@ public class RelatorioVendasPacotesBoletos extends Relatorio { @Override protected void processaParametros() throws Exception { } - + public List getLsDadosRelatorio() { return lsDadosRelatorio; } @@ -337,183 +338,183 @@ public class RelatorioVendasPacotesBoletos extends Relatorio { this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); this.lsDadosRelatorio = lsDadosRelatorio; } - + private void processarVendasAvulsas(Connection conexao) { ResultSet rset = null; NamedParameterStatement stmt = null; - + try { stmt = carregarNamedParameterStatementVendasAvulsas(conexao, false); rset = stmt.executeQuery(); - - if(lsDadosRelatorio == null) { + + if (lsDadosRelatorio == null) { lsDadosRelatorio = new ArrayList(); } - + while (rset.next()) { RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset); Integer idx = carregarIndice(relatorioVendasBoletosBean); - - if(idx > -1) { - relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); + + if (idx > -1) { + relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); } - + relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeans(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeans(), false)); - - if(idx > -1) { + + if (idx > -1) { lsDadosRelatorio.set(idx, relatorioVendasBoletosBean); } else { lsDadosRelatorio.add(relatorioVendasBoletosBean); } } - + } catch (Exception e) { log.error(e.getMessage(), e); } finally { try { - if(rset != null) { + if (rset != null) { rset.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } catch (SQLException e) { log.error(e.getMessage(), e); } } - + } - + private NamedParameterStatement carregarNamedParameterStatementVendasAvulsas(Connection conexao, boolean cancelados) throws SQLException { String sql = getSqlVendasAvulsos(cancelados); log.info(sql); - + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); - - if(fecVendaInicio != null) { + + if (fecVendaInicio != null) { stmt.setTimestamp("fecInicio", fecVendaInicio); } - if(fecVendaFinal != null) { + if (fecVendaFinal != null) { stmt.setTimestamp("fecFinal", fecVendaFinal); } - if(fecPacoteInicio != null) { + if (fecPacoteInicio != null) { stmt.setTimestamp("fecViajeInicio", fecPacoteInicio); } - if(fecPacoteFinal != null) { + if (fecPacoteFinal != null) { stmt.setTimestamp("fecViajeFinal", fecPacoteFinal); } - if (empresaId != null && empresaId > 0){ + if (empresaId != null && empresaId > 0) { stmt.setInt("empresaId", empresaId); } - if(origenId != null) { + if (origenId != null) { stmt.setInt("origenId", origenId); } - if(destinoId != null) { + if (destinoId != null) { stmt.setInt("destinoId", destinoId); } - + return stmt; } - + protected String getSqlVendasAvulsos(boolean cancelado) { StringBuilder sQuery = new StringBuilder(); - + sQuery.append("SELECT DES.CVEPARADA AS CVEDESTINO, ORI.CVEPARADA AS CVEORIGEM, ORI.DESCPARADA AS ORIGEM, DES.DESCPARADA AS DESTINO, ") - .append("CAT.DESCCATEGORIA AS DESCTIPOTARIFA, R.NUMRUTA, R.DESCRUTA, NULL AS SITUACAO, 1 AS QTDEIMPRESSO, NULL AS NOMCONVENIO, 'AVULSO' AS TIPOVENDA, ") - .append("COUNT(B.BOLETO_ID) AS QTDE, SUM(B.IMPORTETAXAEMBARQUE) AS SIMPORTETAXAEMBARQUE, SUM(B.IMPORTEPEDAGIO) AS SIMPORTEPEDAGIO, ") - .append("SUM(B.IMPORTEOUTROS) AS SIMPORTEOUTROS, SUM(B.IMPORTESEGURO) AS SIMPORTESEGURO, SUM(B.PRECIOBASE) AS SPRECIOBASE, SUM(NVL(B.DESCUENTOAMPARADO,0)) AS DESCONTO ") - .append("FROM BOLETO B ") - .append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_ID ") - .append("LEFT JOIN PARADA DES ON DES.PARADA_ID = B.DESTINO_ID ") - .append("LEFT JOIN CATEGORIA CAT ON CAT.CATEGORIA_ID = B.CATEGORIA_ID ") - .append("LEFT JOIN RUTA R ON R.RUTA_ID = B.RUTA_ID ") - .append("WHERE B.ACTIVO = 1 "); - - if(!cancelado) { + .append("CAT.DESCCATEGORIA AS DESCTIPOTARIFA, R.NUMRUTA, R.DESCRUTA, NULL AS SITUACAO, 1 AS QTDEIMPRESSO, NULL AS NOMCONVENIO, 'AVULSO' AS TIPOVENDA, ") + .append("COUNT(B.BOLETO_ID) AS QTDE, SUM(B.IMPORTETAXAEMBARQUE) AS SIMPORTETAXAEMBARQUE, SUM(B.IMPORTEPEDAGIO) AS SIMPORTEPEDAGIO, ") + .append("SUM(B.IMPORTEOUTROS) AS SIMPORTEOUTROS, SUM(B.IMPORTESEGURO) AS SIMPORTESEGURO, SUM(B.PRECIOBASE) AS SPRECIOBASE, SUM(NVL(B.DESCUENTOAMPARADO,0)) AS DESCONTO ") + .append("FROM BOLETO B ") + .append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_ID ") + .append("LEFT JOIN PARADA DES ON DES.PARADA_ID = B.DESTINO_ID ") + .append("LEFT JOIN CATEGORIA CAT ON CAT.CATEGORIA_ID = B.CATEGORIA_ID ") + .append("LEFT JOIN RUTA R ON R.RUTA_ID = B.RUTA_ID ") + .append("WHERE B.ACTIVO = 1 "); + + if (!cancelado) { sQuery.append("AND B.INDSTATUSBOLETO = 'V' ") - .append("AND B.MOTIVOCANCELACION_ID IS NULL "); + .append("AND B.MOTIVOCANCELACION_ID IS NULL "); } else { sQuery.append("AND B.MOTIVOCANCELACION_ID IS NOT NULL "); } - - if (empresaId != null && empresaId > 0){ + + if (empresaId != null && empresaId > 0) { sQuery.append("AND B.EMPRESACORRIDA_ID = :empresaId "); } - if(origenId != null) { + if (origenId != null) { sQuery.append("AND B.ORIGEN_ID = :origenId "); } - - if(destinoId != null) { + + if (destinoId != null) { sQuery.append("AND B.DESTINO_ID = :destinoId "); } - if(fecVendaInicio != null) { + if (fecVendaInicio != null) { sQuery.append("AND B.FECHORVENTA >= :fecInicio "); } - - if(fecVendaFinal != null) { + + if (fecVendaFinal != null) { sQuery.append("AND B.FECHORVENTA <= :fecFinal "); } - - if(fecPacoteInicio != null) { + + if (fecPacoteInicio != null) { sQuery.append("AND B.FECHORVIAJE >= :fecViajeInicio "); } - - if(fecPacoteFinal != null) { + + if (fecPacoteFinal != null) { sQuery.append("AND B.FECHORVIAJE <= :fecViajeFinal "); } - + sQuery.append("GROUP BY DES.CVEPARADA, ORI.CVEPARADA, ORI.DESCPARADA, DES.DESCPARADA, CAT.DESCCATEGORIA, R.NUMRUTA, R.DESCRUTA, NULL, 1, NULL, 'AVULSO' ") - .append("ORDER BY DES.CVEPARADA, ORI.CVEPARADA, ORI.DESCPARADA, DES.DESCPARADA, CAT.DESCCATEGORIA, R.NUMRUTA, R.DESCRUTA, NULL, 1, NULL, 'AVULSO' "); - + .append("ORDER BY DES.CVEPARADA, ORI.CVEPARADA, ORI.DESCPARADA, DES.DESCPARADA, CAT.DESCCATEGORIA, R.NUMRUTA, R.DESCRUTA, NULL, 1, NULL, 'AVULSO' "); + return sQuery.toString(); } - + private void processarVendasAvulsasCancelados(Connection conexao) { ResultSet rset = null; NamedParameterStatement stmt = null; - + try { stmt = carregarNamedParameterStatementVendasAvulsas(conexao, true); rset = stmt.executeQuery(); - - if(lsDadosRelatorio == null) { + + if (lsDadosRelatorio == null) { lsDadosRelatorio = new ArrayList(); } - + while (rset.next()) { RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset); Integer idx = carregarIndice(relatorioVendasBoletosBean); - - if(idx > -1) { - relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); + + if (idx > -1) { + relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); } - + relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeansCancelados(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeansCancelados(), true)); - - if(idx > -1) { + + if (idx > -1) { lsDadosRelatorio.set(idx, relatorioVendasBoletosBean); } else { lsDadosRelatorio.add(relatorioVendasBoletosBean); } } - + } catch (Exception e) { log.error(e.getMessage(), e); } finally { try { - if(rset != null) { + if (rset != null) { rset.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } catch (SQLException e) { log.error(e.getMessage(), e); } } - + } }