fixes bug#19632

qua:
dev:Valdir
Implementado relatório para mostrar caixa por órgão concedente pode filtrar por usuário e por agência.

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@102902 d1611594-4594-4d17-8e1d-87c2c4800839
master
valdevir 2020-08-14 21:50:31 +00:00
parent 8c93a3e298
commit cf15bc7f22
1 changed files with 211 additions and 0 deletions

View File

@ -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<RelatorioCaixaOrgaoConcedenteBean> lsDadosRelatorio;
private static Logger log = Logger.getLogger(RelatorioCaixaOrgaoConcedente.class);
public RelatorioCaixaOrgaoConcedente(Map<String, Object> 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<String, Object> 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<RelatorioCaixaOrgaoConcedenteBean>();
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<RelatorioCaixaOrgaoConcedenteBean> 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();
}
}