diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasRequisicao.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasRequisicao.java new file mode 100644 index 000000000..c7a4f6013 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasRequisicao.java @@ -0,0 +1,188 @@ +package com.rjconsultores.ventaboletos.relatorios.impl; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioVendasConexaoBean; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioVendasRequisicaoBean; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; + +public class RelatorioVendasRequisicao extends Relatorio { + + private static Logger log = Logger.getLogger(RelatorioVendasRequisicao.class); + + private List lsDadosRelatorio; + + private Timestamp fecInicio; + private Timestamp fecFinal; + private Integer empresaId; + private Integer puntoventaId; + + public RelatorioVendasRequisicao(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + + this.setCustomDataSource(new DataSource(this) { + + @Override + public void initDados() throws Exception { + Map parametros = this.relatorio.getParametros(); + fecInicio = (Timestamp) parametros.get("dataFiltroInicial"); + fecFinal = (Timestamp) parametros.get("dataFiltroFinal"); + if(parametros.get("EMPRESA_ID")!=null){ + empresaId = Integer.valueOf(parametros.get("EMPRESA_ID").toString()); + } + if(parametros.get("PUNTOVENTA_ID")!=null){ + puntoventaId = Integer.valueOf(parametros.get("PUNTOVENTA_ID").toString()); + } + + Connection conexao = this.relatorio.getConexao(); + processarVendasRequisicao(conexao); + + setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); + } + + }); + } + + private void processarVendasRequisicao(Connection conexao) { + ResultSet rset = null; + NamedParameterStatement stmt = null; + + try { + + stmt = carregarNamedParameterStatement(conexao); + rset = stmt.executeQuery(); + processarResultado(rset); + fecharConexaoBanco(conexao, stmt, rset); + + } catch (Exception e) { + log.error(e.getMessage(), e); + } + + } + + private void fecharConexaoBanco(Connection conexao, NamedParameterStatement stmt, ResultSet rset) { + try { + if(rset != null && !rset.isClosed()) { + rset.close(); + } + if(stmt != null && !stmt.isClosed()) { + stmt.close(); + } + if(conexao != null && !conexao.isClosed()) { + conexao.close(); + } + } catch (SQLException e) { + log.error(e.getMessage(), e); + } + } + + private void processarResultado(ResultSet rset) throws SQLException { + if(lsDadosRelatorio == null) { + lsDadosRelatorio = new ArrayList(); + } + + while (rset.next()) { + RelatorioVendasRequisicaoBean bean = new RelatorioVendasRequisicaoBean(); + bean.setNumdocumento(rset.getString("REQUISICAO")); + bean.setSecretariaId(rset.getInt("SECRETARIA_ID")); + bean.setDescsecretaria(rset.getString("DESCSECRETARIA")); + bean.setPuntoventaId(rset.getInt("PUNTOVENTA_ID")); + bean.setNombpuntoventa(rset.getString("NOMBPUNTOVENTA")); + bean.setNombempresa(rset.getString("NOMBEMPRESA")); + bean.setEmpresaId(rset.getInt("EMPRESA_ID")); + bean.setOrigemId(rset.getString("ORIGEM_ID")); + bean.setOrigem(rset.getString("ORIGEM")); + bean.setDestinoId(rset.getString("DESTINO_ID")); + bean.setDestino(rset.getString("DESTINO")); + bean.setImporte(rset.getBigDecimal("IMPORTE")); + bean.setQtde(rset.getInt("QTDE")); + + lsDadosRelatorio.add(bean); + } + + } + + private NamedParameterStatement carregarNamedParameterStatement(Connection conexao) throws SQLException { + String sql = getSql(); + log.info(sql); + + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); + + if(fecInicio != null) { + stmt.setTimestamp("fecInicio", fecInicio); + } + if(fecFinal != null) { + stmt.setTimestamp("fecFinal", fecFinal); + } + if(empresaId != null) { + stmt.setInt("EMPRESA_ID", empresaId); + } + if(puntoventaId != null && puntoventaId > -1) { + stmt.setInt("PUNTOVENTA_ID", puntoventaId); + } + + return stmt; + } + + protected String getSql() { + + StringBuilder sQuery = new StringBuilder(); + sQuery.append("SELECT CDP.NUMDOCUMENTO AS REQUISICAO, SEC.SECRETARIA_ID AS SECRETARIA_ID, SEC.DESCSECRETARIA, ORI.CVEPARADA AS ORIGEM_ID, ORI.DESCPARADA AS ORIGEM, DES.CVEPARADA AS DESTINO_ID, DES.DESCPARADA AS DESTINO, PV.PUNTOVENTA_ID AS PUNTOVENTA_ID, PV.NOMBPUNTOVENTA, E.NOMBEMPRESA, E.EMPRESA_ID, FP.DESCPAGO AS DESCPAGO, CFP.FORMAPAGO_ID, COUNT(*) AS QTDE, SUM(CFP.IMPORTE) AS IMPORTE ") + .append("FROM CAJA C ") + .append("JOIN PARADA ORI ON ORI.PARADA_ID = C.ORIGEN_ID ") + .append("JOIN PARADA DES ON DES.PARADA_ID = C.DESTINO_ID ") + .append("JOIN CAJA_FORMAPAGO CFP ON CFP.CAJA_ID = C.CAJA_ID ") + .append("LEFT JOIN CAJA_DET_PAGO CDP ON CDP.CAJAFORMAPAGO_ID = CFP.CAJAFORMAPAGO_ID ") + .append("JOIN SECRETARIA SEC ON CDP.OPCIONAL1 = SEC.SECRETARIA_ID ") + .append("JOIN FORMA_PAGO FP ON FP.FORMAPAGO_ID = CFP.FORMAPAGO_ID ") + .append("JOIN MARCA M ON C.MARCA_ID = M.MARCA_ID ") + .append("JOIN EMPRESA E ON E.EMPRESA_ID = M.EMPRESA_ID ") + .append("JOIN PUNTO_VENTA PV ON PV.PUNTOVENTA_ID = C.PUNTOVENTA_ID ") + .append("WHERE FP.FORMAPAGO_ID = 11 "); + + if(fecInicio != null) { + sQuery.append("AND NVL(C.FECHORVENTA_H,C.FECHORVENTA) >= :fecInicio "); + } + if(fecFinal != null) { + sQuery.append("AND NVL(C.FECHORVENTA_H,C.FECHORVENTA) <= :fecFinal "); + } + if(empresaId != null) { + sQuery.append("AND E.EMPRESA_ID = :EMPRESA_ID "); + } + if(puntoventaId != null && puntoventaId > -1) { + sQuery.append("AND C.PUNTOVENTA_ID = :PUNTOVENTA_ID "); + } + + sQuery.append("GROUP BY CDP.NUMDOCUMENTO, SEC.SECRETARIA_ID, SEC.DESCSECRETARIA,PV.NOMBPUNTOVENTA, PV.NOMBPUNTOVENTA, E.NOMBEMPRESA, E.EMPRESA_ID, FP.DESCPAGO, CFP.FORMAPAGO_ID, ORI.DESCPARADA, DES.DESCPARADA, CFP.IMPORTE, ORI.CVEPARADA, DES.CVEPARADA, PV.PUNTOVENTA_ID ") + .append("ORDER BY SEC.DESCSECRETARIA, PV.NOMBPUNTOVENTA, FP.DESCPAGO"); + + return sQuery.toString(); + + } + + @Override + protected void processaParametros() throws Exception { + } + + public List getLsDadosRelatorio() { + return lsDadosRelatorio; + } + + @Override + public String getNome() { + return super.getNome(); + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioVendasRequisicao_es.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioVendasRequisicao_es.properties new file mode 100644 index 000000000..872de7256 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioVendasRequisicao_es.properties @@ -0,0 +1,18 @@ +#geral +msg.noData=Não foi possivel obter dados com os parâmetros informados. + +#Labels cabeçalho +cabecalho.nome=Relatório Vendas Requisição +cabecalho.relatorio=Relatório: +cabecalho.periodo=Período: +cabecalho.periodoA=à +cabecalho.dataHora=Data/Hora: +cabecalho.impressorPor=Impressor por: +cabecalho.pagina=Página +cabecalho.de=de +cabecalho.filtros=Filtros: +cabecalho.usuario=Usuário: +label.nombPuntoVenta=Agência +label.total=Total +label.puntoVenta=Agência: +label.diferenca=Diferença \ No newline at end of file diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioVendasRequisicao_pt_BR.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioVendasRequisicao_pt_BR.properties new file mode 100644 index 000000000..872de7256 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioVendasRequisicao_pt_BR.properties @@ -0,0 +1,18 @@ +#geral +msg.noData=Não foi possivel obter dados com os parâmetros informados. + +#Labels cabeçalho +cabecalho.nome=Relatório Vendas Requisição +cabecalho.relatorio=Relatório: +cabecalho.periodo=Período: +cabecalho.periodoA=à +cabecalho.dataHora=Data/Hora: +cabecalho.impressorPor=Impressor por: +cabecalho.pagina=Página +cabecalho.de=de +cabecalho.filtros=Filtros: +cabecalho.usuario=Usuário: +label.nombPuntoVenta=Agência +label.total=Total +label.puntoVenta=Agência: +label.diferenca=Diferença \ No newline at end of file diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasRequisicao.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasRequisicao.jasper new file mode 100644 index 000000000..a5eafb8ec Binary files /dev/null and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasRequisicao.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasRequisicao.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasRequisicao.jrxml new file mode 100644 index 000000000..a6bfbb281 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasRequisicao.jrxml @@ -0,0 +1,232 @@ + + + + + +