From cf15bc7f22f77335cd97e903b372988798bff3d8 Mon Sep 17 00:00:00 2001 From: valdevir Date: Fri, 14 Aug 2020 21:50:31 +0000 Subject: [PATCH] =?UTF-8?q?fixes=20bug#19632=20qua:=20dev:Valdir=20Impleme?= =?UTF-8?q?ntado=20relat=C3=B3rio=20para=20mostrar=20caixa=20por=20=C3=B3r?= =?UTF-8?q?g=C3=A3o=20concedente=20pode=20filtrar=20por=20usu=C3=A1rio=20e?= =?UTF-8?q?=20por=20ag=C3=AAncia.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@102902 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../impl/RelatorioCaixaOrgaoConcedente.java | 211 ++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioCaixaOrgaoConcedente.java diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioCaixaOrgaoConcedente.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioCaixaOrgaoConcedente.java new file mode 100644 index 000000000..85f43b694 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioCaixaOrgaoConcedente.java @@ -0,0 +1,211 @@ +package com.rjconsultores.ventaboletos.relatorios.impl; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.text.SimpleDateFormat; +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.RelatorioCaixaOrgaoConcedenteBean; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; + +public class RelatorioCaixaOrgaoConcedente extends Relatorio { + + private static final int TODOS = -1; + private List lsDadosRelatorio; + private static Logger log = Logger.getLogger(RelatorioCaixaOrgaoConcedente.class); + + public RelatorioCaixaOrgaoConcedente(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + + this.setCustomDataSource(new DataSource(this) { + + @Override + public void initDados() throws Exception { + try { + Connection conexao = this.relatorio.getConexao(); + + Map parametros = this.relatorio.getParametros(); + + String fecInicio = null; + if (parametros.get("fecInicio") != null) { + fecInicio = parametros.get("fecInicio").toString() + " 00:00:00"; + } + String fecFinal = null; + if (parametros.get("fecFinal") != null) { + fecFinal = parametros.get("fecFinal").toString() + " 23:59:59"; + } + + Integer orgaoConcedenteId = Integer.parseInt(parametros.get("orgao_concedente_id").toString()); + Integer puntoVentaId = Integer.parseInt(parametros.get("puntoVentaId").toString()); + Integer usuarioId = Integer.parseInt(parametros.get("usuarioId").toString()); + String empresa = parametros.get("empresa") != null ? parametros.get("empresa").toString() : ""; + + String sql = getSql(fecInicio, fecFinal, orgaoConcedenteId, puntoVentaId, usuarioId, empresa); + + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); + + if (fecInicio != null) { + stmt.setTimestamp("fecInicio", new java.sql.Timestamp(sdf.parse(fecInicio).getTime())); + } + + if (fecFinal != null) { + stmt.setTimestamp("fecFinal", new java.sql.Timestamp(sdf.parse(fecFinal).getTime())); + } + + if (empresa != null && !empresa.equals("")) { + stmt.setInt("empresa_id", Integer.parseInt(empresa)); + } + + if (orgaoConcedenteId != null && Integer.valueOf(orgaoConcedenteId).intValue() != TODOS) { + stmt.setInt("orgao_concedente_id", orgaoConcedenteId); + } + if (puntoVentaId != null && Integer.valueOf(puntoVentaId).intValue() != TODOS) { + stmt.setInt("puntoVentaId", puntoVentaId); + } + if (usuarioId != null && Integer.valueOf(usuarioId).intValue() != TODOS) { + stmt.setInt("usuarioId", usuarioId); + } + ResultSet rset = null; + + rset = stmt.executeQuery(); + + lsDadosRelatorio = new ArrayList(); + + while (rset.next()) { + RelatorioCaixaOrgaoConcedenteBean bean = new RelatorioCaixaOrgaoConcedenteBean(); + bean.setQtde(rset.getInt("qtde")); + bean.setTarifa(rset.getBigDecimal("tarifa")); + bean.setTaxaembarque(rset.getBigDecimal("taxaembarque")); + bean.setPedagio(rset.getBigDecimal("pedagio")); + bean.setOutros(rset.getBigDecimal("outros")); + bean.setSeguro(rset.getBigDecimal("seguro")); + bean.setCategoria(rset.getString("categoria")); + bean.setDescOrgaoConcedente(rset.getString("descOrgao")); + bean.setOrgaoConcedenteId(rset.getInt("orgaoConcedenteId")); + bean.setTipo(rset.getString("tipo")); + lsDadosRelatorio.add(bean); + } + + log.info("TAMANHO == null ? " + lsDadosRelatorio == null); + + if (lsDadosRelatorio.size() > 0) { + log.info("TAMANHO DA LISTA: " + lsDadosRelatorio.size()); + setLsDadosRelatorio(lsDadosRelatorio); + } + + } catch (Exception e) { + log.error("Erro na geração do Relatório de Caixa Orgão Concedente: \n" + e); + e.printStackTrace(); + throw e; + } + } + }); + } + + public void setLsDadosRelatorio(List lsDadosRelatorio) { + log.info("Setando dados do relatorio Operacional Financeiro "); + this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); + this.lsDadosRelatorio = lsDadosRelatorio; + log.info("depois de Setar dados do relatorio Operacional Financeiro "); + } + + @Override + protected void processaParametros() throws Exception { + } + + private String getSql(String fecInicioVenda, String fecFinalVenda, Integer orgaoConcedenteId, Integer puntoVentaId, Integer usuarioId, String empresa) { + + StringBuilder sql = new StringBuilder(); + sql.append(" SELECT COUNT(caja_id) AS qtde, "); + sql.append(" SUM(tarifa) AS tarifa, "); + sql.append(" SUM(taxaembarque) AS taxaembarque, "); + sql.append(" SUM(pedagio) AS pedagio, "); + sql.append(" SUM(outros) AS outros,"); + sql.append(" SUM(seguro) AS seguro,"); + sql.append(" orgaoConcedenteId,"); + sql.append(" descOrgao,"); + sql.append(" categoria,"); + sql.append(" tipo"); + sql.append(" FROM"); + sql.append(" ( SELECT DISTINCT c.TIPOVENTA_ID AS tipoVenda,"); + sql.append(" c.caja_id,"); + sql.append(" OC.ORGAOCONCEDENTE_ID AS orgaoConcedenteId,"); + sql.append(" OC.DESCORGAO AS descOrgao,"); + sql.append(" cat.DESCCATEGORIA AS categoria,"); + sql.append(" COALESCE(c.PRECIOPAGADO, 0) AS tarifa,"); + sql.append(" COALESCE(c.IMPORTETAXAEMBARQUE, 0) AS taxaembarque,"); + sql.append(" COALESCE(c.IMPORTEPEDAGIO, 0) AS pedagio,"); + sql.append(" COALESCE(c.IMPORTEOUTROS, 0) AS outros,"); + sql.append(" COALESCE(c.IMPORTESEGURO, 0) AS seguro,"); + sql.append(" ( ("); + sql.append(" CASE"); + sql.append(" WHEN c.MOTIVOCANCELACION_ID IS NULL"); + sql.append(" AND c.indreimpresion = 0"); + sql.append(" AND (c.indstatusboleto = 'V' or c.indstatusboleto = 'T' )"); + sql.append(" THEN 'VENDA'"); + sql.append(" WHEN c.indreimpresion = 0"); + sql.append(" AND (c.MOTIVOCANCELACION_ID IS NOT NULL"); + //Não devoluções + sql.append(" AND c.MOTIVOCANCELACION_ID NOT IN (32,36,37, 99))"); + sql.append(" THEN 'CANCELADO'"); + sql.append(" WHEN ((c.indreimpresion = 0"); + sql.append(" AND c.MOTIVOCANCELACION_ID IS NOT NULL"); + //Devoluções + sql.append(" AND c.MOTIVOCANCELACION_ID IN (32,36,37))"); + sql.append(" OR c.MOTIVOCANCELACION_ID = 99)"); + sql.append(" THEN 'DEVOLUCAO'"); + sql.append(" END) ) AS tipo"); + sql.append(" FROM caja c"); + sql.append(" INNER JOIN MARCA ma"); + sql.append(" ON c.marca_id = ma.marca_id"); + sql.append(" INNER JOIN EMPRESA emp"); + sql.append(" ON ma.empresa_id = emp.empresa_id"); + sql.append(" INNER JOIN CATEGORIA cat"); + sql.append(" ON c.categoria_id = cat.categoria_id"); + sql.append(" LEFT JOIN TIPO_VENTA tv"); + sql.append(" ON tv.TIPOVENTA_ID = c.TIPOVENTA_ID"); + sql.append(" LEFT JOIN RUTA r"); + sql.append(" ON r.RUTA_ID = c.RUTA_ID"); + sql.append(" AND r.ACTIVO = 1"); + sql.append(" LEFT JOIN ORGAO_CONCEDENTE OC"); + sql.append(" ON r.ORGAOCONCEDENTE_ID = OC.ORGAOCONCEDENTE_ID"); + sql.append(" AND OC.ACTIVO = 1"); + sql.append(" WHERE c.ACTIVO = 1"); + //Não deve considerar Reimpressão do bilhete"); + sql.append(" AND (c.INDREIMPRESION = 0"); + sql.append(" OR (c.INDREIMPRESION = 1 AND c.MOTIVOCANCELACION_ID =99))"); + sql.append(" AND c.feccorte BETWEEN :fecInicio AND :fecFinal"); + if (orgaoConcedenteId != null && orgaoConcedenteId != TODOS) { + sql.append(" AND OC.ORGAOCONCEDENTE_ID = :orgao_concedente_id "); + } + if (puntoVentaId != null && puntoVentaId != TODOS) { + sql.append(" AND c.puntoventa_id = :puntoVentaId "); + } + if (usuarioId != null && usuarioId != TODOS) { + sql.append(" AND c.usuario_id = :usuarioId "); + } + sql.append(" AND c.empresacorrida_id = :empresa_id"); + sql.append(" ) dados"); + sql.append(" GROUP BY "); + sql.append(" orgaoConcedenteId,"); + sql.append(" categoria,"); + sql.append(" descOrgao,"); + sql.append(" tipo "); + sql.append(" ORDER BY "); + sql.append(" orgaoConcedenteId,"); + sql.append(" categoria,"); + sql.append(" descOrgao, "); + sql.append(" tipo "); + + return sql.toString(); + } +} \ No newline at end of file