alexandre.lima 2017-06-27 19:19:27 +00:00
parent 21537e96f7
commit 41e0443226
1 changed files with 188 additions and 187 deletions

View File

@ -22,16 +22,16 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
public class RelatorioVendasPacotesBoletos extends Relatorio { public class RelatorioVendasPacotesBoletos extends Relatorio {
private static Logger log = Logger.getLogger(RelatorioVendasPacotesBoletos.class); private static Logger log = Logger.getLogger(RelatorioVendasPacotesBoletos.class);
public static final Integer VENDIDOS = 1; public static final Integer VENDIDOS = 1;
public static final Integer CANCELADOS = 0; public static final Integer CANCELADOS = 0;
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
private List<RelatorioVendasPacotesBoletosBean> lsDadosRelatorio; private List<RelatorioVendasPacotesBoletosBean> lsDadosRelatorio;
private Timestamp fecVendaInicio; private Timestamp fecVendaInicio;
private Timestamp fecVendaFinal; private Timestamp fecVendaFinal;
private Timestamp fecPacoteInicio; private Timestamp fecPacoteInicio;
@ -42,12 +42,11 @@ public class RelatorioVendasPacotesBoletos extends Relatorio {
private Integer usuarioId; private Integer usuarioId;
private Integer tipoTarifaPacoteId; private Integer tipoTarifaPacoteId;
private Integer situacaoBilheteId; private Integer situacaoBilheteId;
public RelatorioVendasPacotesBoletos(Map<String, Object> parametros, Connection conexao, final String... nomeSubReporte) throws Exception { public RelatorioVendasPacotesBoletos(Map<String, Object> parametros, Connection conexao, final String... nomeSubReporte) throws Exception {
super(parametros, conexao); super(parametros, conexao);
this.setCustomDataSource(new DataSource(this) {
this.setCustomDataSource(new DataSource(this) {
@Override @Override
public void initDados() throws Exception { 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; 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; 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; situacaoBilheteId = parametros.get("situacaoBilheteId") != null && !parametros.get("situacaoBilheteId").equals("null") ? Integer.valueOf(parametros.get("situacaoBilheteId").toString()) : null;
Connection conexao = this.relatorio.getConexao(); Connection conexao = this.relatorio.getConexao();
processarVendasPacote(conexao); processarVendasPacote(conexao);
/* Caso o filtro de data de venda de pacote seja informado, não trazer bilhetes avulsos */ /* Caso o filtro de data de venda de pacote seja informado, não trazer bilhetes avulsos */
if(fecPacoteInicio == null && fecPacoteFinal == null) { if (fecPacoteInicio == null && fecPacoteFinal == null) {
if(situacaoBilheteId == null || !CANCELADOS.equals(situacaoBilheteId)) { if (situacaoBilheteId == null || !CANCELADOS.equals(situacaoBilheteId)) {
processarVendasAvulsas(conexao); processarVendasAvulsas(conexao);
} }
if(situacaoBilheteId == null || CANCELADOS.equals(situacaoBilheteId)) { if (situacaoBilheteId == null || CANCELADOS.equals(situacaoBilheteId)) {
processarVendasAvulsasCancelados(conexao); processarVendasAvulsasCancelados(conexao);
} }
} }
processarVendasPacoteTotais(); processarVendasPacoteTotais();
setNomeSubReporte(nomeSubReporte); setNomeSubReporte(nomeSubReporte);
setLsDadosRelatorio(lsDadosRelatorio); setLsDadosRelatorio(lsDadosRelatorio);
} }
}); });
} }
private void processarVendasPacote(Connection conexao) { private void processarVendasPacote(Connection conexao) {
ResultSet rset = null; ResultSet rset = null;
NamedParameterStatement stmt = null; NamedParameterStatement stmt = null;
try { try {
stmt = carregarNamedParameterStatementVendasPacotes(conexao); stmt = carregarNamedParameterStatementVendasPacotes(conexao);
rset = stmt.executeQuery(); rset = stmt.executeQuery();
if(lsDadosRelatorio == null) { if (lsDadosRelatorio == null) {
lsDadosRelatorio = new ArrayList<RelatorioVendasPacotesBoletosBean>(); lsDadosRelatorio = new ArrayList<RelatorioVendasPacotesBoletosBean>();
} }
while (rset.next()) { while (rset.next()) {
RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset); RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset);
Integer idx = carregarIndice(relatorioVendasBoletosBean); Integer idx = carregarIndice(relatorioVendasBoletosBean);
if(idx > -1) { if (idx > -1) {
relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); relatorioVendasBoletosBean = lsDadosRelatorio.get(idx);
} }
relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeans(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeans(), false)); relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeans(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeans(), false));
if(idx > -1) { if (idx > -1) {
lsDadosRelatorio.set(idx, relatorioVendasBoletosBean); lsDadosRelatorio.set(idx, relatorioVendasBoletosBean);
} else { } else {
lsDadosRelatorio.add(relatorioVendasBoletosBean); lsDadosRelatorio.add(relatorioVendasBoletosBean);
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} finally { } finally {
try { try {
if(rset != null) { if (rset != null) {
rset.close(); rset.close();
} }
if(stmt != null) { if (stmt != null) {
stmt.close(); stmt.close();
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
} }
} }
private List<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean> carregarItens(ResultSet rset, RelatorioVendasPacotesBoletosBean relatorioVendasPacotesBoletosBean, List<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean> itens, Boolean cancelado) throws SQLException { private List<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean> carregarItens(ResultSet rset, RelatorioVendasPacotesBoletosBean relatorioVendasPacotesBoletosBean, List<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean> itens, Boolean cancelado) throws SQLException {
RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean relatorioVendasPacotesBoletosItemBean = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemBean(); RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean relatorioVendasPacotesBoletosItemBean = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemBean();
relatorioVendasPacotesBoletosItemBean.setNumruta(rset.getString("numruta")); relatorioVendasPacotesBoletosItemBean.setNumruta(rset.getString("numruta"));
@ -147,18 +146,18 @@ public class RelatorioVendasPacotesBoletos extends Relatorio {
relatorioVendasPacotesBoletosItemBean.setQtdeImpresso(rset.getInt("qtdeimpresso")); relatorioVendasPacotesBoletosItemBean.setQtdeImpresso(rset.getInt("qtdeimpresso"));
relatorioVendasPacotesBoletosItemBean.setTipoVenda(rset.getString("tipovenda")); relatorioVendasPacotesBoletosItemBean.setTipoVenda(rset.getString("tipovenda"));
relatorioVendasPacotesBoletosItemBean.setAvulsoCancelado(cancelado); relatorioVendasPacotesBoletosItemBean.setAvulsoCancelado(cancelado);
if(itens == null) { if (itens == null) {
itens = new ArrayList<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean>(); itens = new ArrayList<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemBean>();
} }
itens.add(relatorioVendasPacotesBoletosItemBean); itens.add(relatorioVendasPacotesBoletosItemBean);
return itens; return itens;
} }
private Integer carregarIndice(RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean) { private Integer carregarIndice(RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean) {
Integer idx = -1; Integer idx = -1;
if(lsDadosRelatorio.contains(relatorioVendasBoletosBean)) { if (lsDadosRelatorio.contains(relatorioVendasBoletosBean)) {
idx = lsDadosRelatorio.indexOf(relatorioVendasBoletosBean); idx = lsDadosRelatorio.indexOf(relatorioVendasBoletosBean);
relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); relatorioVendasBoletosBean = lsDadosRelatorio.get(idx);
} }
@ -171,154 +170,156 @@ public class RelatorioVendasPacotesBoletos extends Relatorio {
relatorioVendasPacotesBoletosBean.setDescorigen(rset.getString("origem")); relatorioVendasPacotesBoletosBean.setDescorigen(rset.getString("origem"));
relatorioVendasPacotesBoletosBean.setCvedestino(rset.getString("cvedestino")); relatorioVendasPacotesBoletosBean.setCvedestino(rset.getString("cvedestino"));
relatorioVendasPacotesBoletosBean.setCveorigen(rset.getString("cveorigem")); relatorioVendasPacotesBoletosBean.setCveorigen(rset.getString("cveorigem"));
return relatorioVendasPacotesBoletosBean; return relatorioVendasPacotesBoletosBean;
} }
private NamedParameterStatement carregarNamedParameterStatementVendasPacotes(Connection conexao) throws SQLException { private NamedParameterStatement carregarNamedParameterStatementVendasPacotes(Connection conexao) throws SQLException {
String sql = getSqlVendasPacotes(); String sql = getSqlVendasPacotes();
log.info(sql); log.info(sql);
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
if(fecVendaInicio != null) { if (fecVendaInicio != null) {
stmt.setTimestamp("fecVendaInicio", fecVendaInicio); stmt.setTimestamp("fecVendaInicio", fecVendaInicio);
} }
if(fecVendaFinal != null) { if (fecVendaFinal != null) {
stmt.setTimestamp("fecVendaFinal", fecVendaFinal); stmt.setTimestamp("fecVendaFinal", fecVendaFinal);
} }
if(fecPacoteInicio != null) { if (fecPacoteInicio != null) {
stmt.setTimestamp("fecPacoteInicio", fecPacoteInicio); stmt.setTimestamp("fecPacoteInicio", fecPacoteInicio);
} }
if(fecPacoteFinal != null) { if (fecPacoteFinal != null) {
stmt.setTimestamp("fecPacoteFinal", fecPacoteFinal); stmt.setTimestamp("fecPacoteFinal", fecPacoteFinal);
} }
if (empresaId != null && empresaId > 0){ if (empresaId != null && empresaId > 0) {
stmt.setInt("empresaId", empresaId); stmt.setInt("empresaId", empresaId);
} }
if(origenId != null && origenId > 0){ if (origenId != null && origenId > 0) {
stmt.setInt("origenId", origenId); stmt.setInt("origenId", origenId);
} }
if(destinoId != null && destinoId > 0){ if (destinoId != null && destinoId > 0) {
stmt.setInt("destinoId", destinoId); stmt.setInt("destinoId", destinoId);
} }
if(usuarioId != null) { if (usuarioId != null) {
stmt.setInt("usuarioId", usuarioId); stmt.setInt("usuarioId", usuarioId);
} }
if(tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) { if (tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) {
stmt.setInt("tipoTarifaPacoteId", tipoTarifaPacoteId); stmt.setInt("tipoTarifaPacoteId", tipoTarifaPacoteId);
} }
if(situacaoBilheteId != null) { if (situacaoBilheteId != null) {
stmt.setInt("situacaoPacote",SituacaoVendaPacote.CANCELADO.getShortValue()); stmt.setInt("situacaoPacote", SituacaoVendaPacote.CANCELADO.getShortValue());
} }
return stmt; return stmt;
} }
protected String getSqlVendasPacotes() { protected String getSqlVendasPacotes() {
StringBuilder sQuery = new StringBuilder(); 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, ") 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("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("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(NVL(T.IMPORTEOUTROS,0)) AS SIMPORTEOUTROS, SUM(NVL(T.IMPORTESEGURO,0)) AS SIMPORTESEGURO, SUM(NVL(B.PRECIOBASE,0)) AS SPRECIOBASE, ")
.append(" SUM( ") .append(" SUM( ")
.append(" B.PRECIOBASE+NVL(T.IMPORTETAXAEMBARQUE,0)+NVL(T.IMPORTEPEDAGIO,0)+NVL(T.IMPORTESEGURO,0)+NVL(T.IMPORTEOUTROS,0)- ") .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(" B.PRECIOPAGADO-NVL(B.IMPORTETAXAEMBARQUE,0)-NVL(B.IMPORTEPEDAGIO,0)-NVL(B.IMPORTESEGURO,0)-NVL(B.IMPORTEOUTROS,0) ")
.append(" ) AS DESCONTO, ") .append(" ) AS DESCONTO, ")
.append("'PACOTE' AS TIPOVENDA ") .append("'PACOTE' AS TIPOVENDA ")
.append("FROM VENDA_PACOTE VP ") .append("FROM VENDA_PACOTE VP ")
.append("INNER JOIN PACOTE P ON P.PACOTE_ID = VP.PACOTE_ID AND P.ACTIVO = 1 ") .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("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("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 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 ORI ON ORI.PARADA_ID = B.ORIGEN_ID ")
.append("LEFT JOIN PARADA DES ON DES.PARADA_ID = B.DESTINO_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 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 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 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 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("LEFT JOIN TARIFA T ON T.RUTA_ID = B.RUTA_ID ")
.append(" AND T.DESTINO_ID = B.DESTINO_ID ") .append(" AND T.DESTINO_ID = B.DESTINO_ID ")
.append(" AND T.ORIGEN_ID = B.ORIGEN_ID ") .append(" AND T.ORIGEN_ID = B.ORIGEN_ID ")
.append(" AND T.CLASESERVICIO_ID = B.CLASESERVICIO_ID ") .append(" AND T.CLASESERVICIO_ID = B.CLASESERVICIO_ID ")
.append(" AND T.ACTIVO = 1 ") .append(" AND T.ACTIVO = 1 ")
.append(" AND VT.VIGENCIATARIFA_ID = T.VIGENCIATARIFA_ID ") .append(" AND VT.VIGENCIATARIFA_ID = T.VIGENCIATARIFA_ID ")
.append(" AND T.ORGAOCONCEDENTE_ID = R.ORGAOCONCEDENTE_ID ") .append(" AND T.ORGAOCONCEDENTE_ID = R.ORGAOCONCEDENTE_ID ")
.append("WHERE 1=1 "); .append("WHERE 1=1 ");
if(fecVendaInicio != null) { if (fecVendaInicio != null) {
sQuery.append("AND VP.DATAVENDA >= :fecVendaInicio "); sQuery.append("AND VP.DATAVENDA >= :fecVendaInicio ");
} }
if(fecVendaFinal != null) { if (fecVendaFinal != null) {
sQuery.append("AND VP.DATAVENDA <= :fecVendaFinal "); sQuery.append("AND VP.DATAVENDA <= :fecVendaFinal ");
} }
if(fecPacoteInicio != null) { if (fecPacoteInicio != null) {
sQuery.append("AND VP.DATAPACOTE >= :fecPacoteInicio "); sQuery.append("AND VP.DATAPACOTE >= :fecPacoteInicio ");
} }
if(fecPacoteFinal != null) { if (fecPacoteFinal != null) {
sQuery.append("AND VP.DATAPACOTE <= :fecPacoteFinal "); sQuery.append("AND VP.DATAPACOTE <= :fecPacoteFinal ");
} }
if(empresaId != null && empresaId > 0){ if (empresaId != null && empresaId > 0) {
sQuery.append("AND P.EMPRESA_ID = :empresaId "); sQuery.append("AND P.EMPRESA_ID = :empresaId ");
} }
if(origenId != null && origenId > 0){ if (origenId != null && origenId > 0) {
sQuery.append("AND B.ORIGEN_ID = :origenId "); sQuery.append("AND B.ORIGEN_ID = :origenId ");
} }
if(destinoId != null && destinoId > 0){ if (destinoId != null && destinoId > 0) {
sQuery.append("AND B.DESTINO_ID = :destinoId "); sQuery.append("AND B.DESTINO_ID = :destinoId ");
} }
if(usuarioId != null) { if (usuarioId != null) {
sQuery.append("AND VP.USUARIO_ID = :usuarioId "); sQuery.append("AND VP.USUARIO_ID = :usuarioId ");
} }
if(tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) { if (tipoTarifaPacoteId != null && tipoTarifaPacoteId > 0) {
sQuery.append("AND TTP.TIPOTARIFAPACOTE_ID = :tipoTarifaPacoteId "); 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 "); 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("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' ") 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(); return sQuery.toString();
} }
private void processarVendasPacoteTotais() { private void processarVendasPacoteTotais() {
List<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean> totais = new ArrayList<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean>(); List<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean> totais = new ArrayList<RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean>();
for (RelatorioVendasPacotesBoletosBean relatorioVendasPacotesBoletosBean : lsDadosRelatorio) { for (RelatorioVendasPacotesBoletosBean relatorioVendasPacotesBoletosBean : lsDadosRelatorio) {
for (RelatorioVendasPacotesBoletosItemBean item : relatorioVendasPacotesBoletosBean.getRelatorioVendasPacotesBoletosItemBeans()) { if (relatorioVendasPacotesBoletosBean.getRelatorioVendasPacotesBoletosItemBeans() != null) {
RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean total = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemTotaisBean(); for (RelatorioVendasPacotesBoletosItemBean item : relatorioVendasPacotesBoletosBean.getRelatorioVendasPacotesBoletosItemBeans()) {
total.setTrecho(relatorioVendasPacotesBoletosBean.getCveorigen()+"-"+relatorioVendasPacotesBoletosBean.getCvedestino()); RelatorioVendasPacotesBoletosBean.RelatorioVendasPacotesBoletosItemTotaisBean total = relatorioVendasPacotesBoletosBean.new RelatorioVendasPacotesBoletosItemTotaisBean();
total.setCategoria(item.getDesctipotarifa()); total.setTrecho(relatorioVendasPacotesBoletosBean.getCveorigen() + "-" + relatorioVendasPacotesBoletosBean.getCvedestino());
total.setQtde(0l); total.setCategoria(item.getDesctipotarifa());
Integer idx = null; total.setQtde(0l);
if(totais.contains(total)) { Integer idx = null;
idx = totais.indexOf(total); if (totais.contains(total)) {
total = totais.get(idx); idx = totais.indexOf(total);
} total = totais.get(idx);
total.setQtde(total.getQtde() + item.getQtde()); }
total.setQtde(total.getQtde() + item.getQtde());
if(idx == null) {
totais.add(total); if (idx == null) {
} else { totais.add(total);
totais.set(idx, total); } else {
totais.set(idx, total);
}
} }
} }
} }
@ -328,7 +329,7 @@ public class RelatorioVendasPacotesBoletos extends Relatorio {
@Override @Override
protected void processaParametros() throws Exception { protected void processaParametros() throws Exception {
} }
public List<RelatorioVendasPacotesBoletosBean> getLsDadosRelatorio() { public List<RelatorioVendasPacotesBoletosBean> getLsDadosRelatorio() {
return lsDadosRelatorio; return lsDadosRelatorio;
} }
@ -337,183 +338,183 @@ public class RelatorioVendasPacotesBoletos extends Relatorio {
this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio));
this.lsDadosRelatorio = lsDadosRelatorio; this.lsDadosRelatorio = lsDadosRelatorio;
} }
private void processarVendasAvulsas(Connection conexao) { private void processarVendasAvulsas(Connection conexao) {
ResultSet rset = null; ResultSet rset = null;
NamedParameterStatement stmt = null; NamedParameterStatement stmt = null;
try { try {
stmt = carregarNamedParameterStatementVendasAvulsas(conexao, false); stmt = carregarNamedParameterStatementVendasAvulsas(conexao, false);
rset = stmt.executeQuery(); rset = stmt.executeQuery();
if(lsDadosRelatorio == null) { if (lsDadosRelatorio == null) {
lsDadosRelatorio = new ArrayList<RelatorioVendasPacotesBoletosBean>(); lsDadosRelatorio = new ArrayList<RelatorioVendasPacotesBoletosBean>();
} }
while (rset.next()) { while (rset.next()) {
RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset); RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset);
Integer idx = carregarIndice(relatorioVendasBoletosBean); Integer idx = carregarIndice(relatorioVendasBoletosBean);
if(idx > -1) { if (idx > -1) {
relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); relatorioVendasBoletosBean = lsDadosRelatorio.get(idx);
} }
relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeans(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeans(), false)); relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeans(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeans(), false));
if(idx > -1) { if (idx > -1) {
lsDadosRelatorio.set(idx, relatorioVendasBoletosBean); lsDadosRelatorio.set(idx, relatorioVendasBoletosBean);
} else { } else {
lsDadosRelatorio.add(relatorioVendasBoletosBean); lsDadosRelatorio.add(relatorioVendasBoletosBean);
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} finally { } finally {
try { try {
if(rset != null) { if (rset != null) {
rset.close(); rset.close();
} }
if(stmt != null) { if (stmt != null) {
stmt.close(); stmt.close();
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
} }
} }
private NamedParameterStatement carregarNamedParameterStatementVendasAvulsas(Connection conexao, boolean cancelados) throws SQLException { private NamedParameterStatement carregarNamedParameterStatementVendasAvulsas(Connection conexao, boolean cancelados) throws SQLException {
String sql = getSqlVendasAvulsos(cancelados); String sql = getSqlVendasAvulsos(cancelados);
log.info(sql); log.info(sql);
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
if(fecVendaInicio != null) { if (fecVendaInicio != null) {
stmt.setTimestamp("fecInicio", fecVendaInicio); stmt.setTimestamp("fecInicio", fecVendaInicio);
} }
if(fecVendaFinal != null) { if (fecVendaFinal != null) {
stmt.setTimestamp("fecFinal", fecVendaFinal); stmt.setTimestamp("fecFinal", fecVendaFinal);
} }
if(fecPacoteInicio != null) { if (fecPacoteInicio != null) {
stmt.setTimestamp("fecViajeInicio", fecPacoteInicio); stmt.setTimestamp("fecViajeInicio", fecPacoteInicio);
} }
if(fecPacoteFinal != null) { if (fecPacoteFinal != null) {
stmt.setTimestamp("fecViajeFinal", fecPacoteFinal); stmt.setTimestamp("fecViajeFinal", fecPacoteFinal);
} }
if (empresaId != null && empresaId > 0){ if (empresaId != null && empresaId > 0) {
stmt.setInt("empresaId", empresaId); stmt.setInt("empresaId", empresaId);
} }
if(origenId != null) { if (origenId != null) {
stmt.setInt("origenId", origenId); stmt.setInt("origenId", origenId);
} }
if(destinoId != null) { if (destinoId != null) {
stmt.setInt("destinoId", destinoId); stmt.setInt("destinoId", destinoId);
} }
return stmt; return stmt;
} }
protected String getSqlVendasAvulsos(boolean cancelado) { protected String getSqlVendasAvulsos(boolean cancelado) {
StringBuilder sQuery = new StringBuilder(); StringBuilder sQuery = new StringBuilder();
sQuery.append("SELECT DES.CVEPARADA AS CVEDESTINO, ORI.CVEPARADA AS CVEORIGEM, ORI.DESCPARADA AS ORIGEM, DES.DESCPARADA AS DESTINO, ") 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("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("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("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("FROM BOLETO B ")
.append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_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 PARADA DES ON DES.PARADA_ID = B.DESTINO_ID ")
.append("LEFT JOIN CATEGORIA CAT ON CAT.CATEGORIA_ID = B.CATEGORIA_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("LEFT JOIN RUTA R ON R.RUTA_ID = B.RUTA_ID ")
.append("WHERE B.ACTIVO = 1 "); .append("WHERE B.ACTIVO = 1 ");
if(!cancelado) { if (!cancelado) {
sQuery.append("AND B.INDSTATUSBOLETO = 'V' ") sQuery.append("AND B.INDSTATUSBOLETO = 'V' ")
.append("AND B.MOTIVOCANCELACION_ID IS NULL "); .append("AND B.MOTIVOCANCELACION_ID IS NULL ");
} else { } else {
sQuery.append("AND B.MOTIVOCANCELACION_ID IS NOT NULL "); 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 "); sQuery.append("AND B.EMPRESACORRIDA_ID = :empresaId ");
} }
if(origenId != null) { if (origenId != null) {
sQuery.append("AND B.ORIGEN_ID = :origenId "); sQuery.append("AND B.ORIGEN_ID = :origenId ");
} }
if(destinoId != null) { if (destinoId != null) {
sQuery.append("AND B.DESTINO_ID = :destinoId "); sQuery.append("AND B.DESTINO_ID = :destinoId ");
} }
if(fecVendaInicio != null) { if (fecVendaInicio != null) {
sQuery.append("AND B.FECHORVENTA >= :fecInicio "); sQuery.append("AND B.FECHORVENTA >= :fecInicio ");
} }
if(fecVendaFinal != null) { if (fecVendaFinal != null) {
sQuery.append("AND B.FECHORVENTA <= :fecFinal "); sQuery.append("AND B.FECHORVENTA <= :fecFinal ");
} }
if(fecPacoteInicio != null) { if (fecPacoteInicio != null) {
sQuery.append("AND B.FECHORVIAJE >= :fecViajeInicio "); sQuery.append("AND B.FECHORVIAJE >= :fecViajeInicio ");
} }
if(fecPacoteFinal != null) { if (fecPacoteFinal != null) {
sQuery.append("AND B.FECHORVIAJE <= :fecViajeFinal "); 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' ") 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(); return sQuery.toString();
} }
private void processarVendasAvulsasCancelados(Connection conexao) { private void processarVendasAvulsasCancelados(Connection conexao) {
ResultSet rset = null; ResultSet rset = null;
NamedParameterStatement stmt = null; NamedParameterStatement stmt = null;
try { try {
stmt = carregarNamedParameterStatementVendasAvulsas(conexao, true); stmt = carregarNamedParameterStatementVendasAvulsas(conexao, true);
rset = stmt.executeQuery(); rset = stmt.executeQuery();
if(lsDadosRelatorio == null) { if (lsDadosRelatorio == null) {
lsDadosRelatorio = new ArrayList<RelatorioVendasPacotesBoletosBean>(); lsDadosRelatorio = new ArrayList<RelatorioVendasPacotesBoletosBean>();
} }
while (rset.next()) { while (rset.next()) {
RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset); RelatorioVendasPacotesBoletosBean relatorioVendasBoletosBean = carregarRelatorioVendasBoletosBean(rset);
Integer idx = carregarIndice(relatorioVendasBoletosBean); Integer idx = carregarIndice(relatorioVendasBoletosBean);
if(idx > -1) { if (idx > -1) {
relatorioVendasBoletosBean = lsDadosRelatorio.get(idx); relatorioVendasBoletosBean = lsDadosRelatorio.get(idx);
} }
relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeansCancelados(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeansCancelados(), true)); relatorioVendasBoletosBean.setRelatorioVendasPacotesBoletosItemBeansCancelados(carregarItens(rset, relatorioVendasBoletosBean, relatorioVendasBoletosBean.getRelatorioVendasPacotesBoletosItemBeansCancelados(), true));
if(idx > -1) { if (idx > -1) {
lsDadosRelatorio.set(idx, relatorioVendasBoletosBean); lsDadosRelatorio.set(idx, relatorioVendasBoletosBean);
} else { } else {
lsDadosRelatorio.add(relatorioVendasBoletosBean); lsDadosRelatorio.add(relatorioVendasBoletosBean);
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} finally { } finally {
try { try {
if(rset != null) { if (rset != null) {
rset.close(); rset.close();
} }
if(stmt != null) { if (stmt != null) {
stmt.close(); stmt.close();
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
} }
} }
} }