fixed bug #0008450 -Foi criado o novo relatório, com as informações solicitadas pelo cliente.
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@67804 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
bc08e6ea48
commit
3d2d96e26b
|
@ -0,0 +1,199 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.rjconsultores.ventaboletos.relatorios.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Constante;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.ArrayDataSource;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||
|
||||
/**
|
||||
* @author Bruno Neves <bruno@rjconsultores.com.br>
|
||||
*
|
||||
*/
|
||||
public class RelatorioKmProgramada extends Relatorio {
|
||||
|
||||
/**
|
||||
* @param parametros
|
||||
* @param conexao
|
||||
*/
|
||||
public RelatorioKmProgramada(Map<String, Object> parametros, Connection conexao) {
|
||||
super(parametros, conexao);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio#processaParametros()
|
||||
*/
|
||||
@Override
|
||||
public void processaParametros() throws Exception {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ConstanteService constanteService;
|
||||
|
||||
public RelatorioKmProgramada(Map<String, Object> parametros, Connection conexao, ConstanteService constanteService) throws Exception {
|
||||
super(parametros, conexao);
|
||||
this.constanteService = constanteService;
|
||||
|
||||
this.setCustomDataSource(new ArrayDataSource(this) {
|
||||
|
||||
public void initDados() throws Exception {
|
||||
Connection conexao = this.relatorio.getConexao();
|
||||
Map<String, Object> parametros = this.relatorio.getParametros();
|
||||
final Integer CARTAO_CREDITO = 2;
|
||||
String sql = getSql(parametros.get("EMPRESA_ID")+"");
|
||||
|
||||
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
stmt.setTimestamp("fecInicio", new Timestamp(DateUtil.inicioFecha(sdf.parse(parametros.get("DATA_INICIAL").toString())).getTime()));
|
||||
stmt.setTimestamp("fecFinal", new Timestamp(DateUtil.inicioFecha(sdf.parse( parametros.get("DATA_FINAL").toString())).getTime()));
|
||||
// stmt.setTimestamp("data_final", new Timestamp(DateUtil.fimFecha((Date) parametros.get("DATA_FINAL")).getTime()));
|
||||
// stmt.setInt("formaPago1", CARTAO_CREDITO);
|
||||
if(parametros.get("EMPRESA_ID" )!= null){
|
||||
stmt.setInt("empresaId", Integer.valueOf(parametros.get("EMPRESA_ID" )== null ?"0":parametros.get("EMPRESA_ID") + ""));
|
||||
}
|
||||
|
||||
|
||||
ResultSet rset = stmt.executeQuery();
|
||||
|
||||
while (rset.next()) {
|
||||
Map<String, Object> dataResult = new HashMap<String, Object>();
|
||||
dataResult.put("Linhas", rset.getString("Linhas"));
|
||||
dataResult.put("DescLinha", rset.getString("DescLinha"));
|
||||
dataResult.put("Empresa", rset.getString("Empresa"));
|
||||
dataResult.put("KMPadrao", rset.getBigDecimal("KMPadrao"));
|
||||
dataResult.put("SRVNormal", rset.getInt("SRVNormal"));
|
||||
dataResult.put("SRVExtra", rset.getInt("SRVExtra"));
|
||||
dataResult.put("SRVTotal", rset.getInt("SRVTotal"));
|
||||
dataResult.put("KMTotal", rset.getBigDecimal("KMTotal"));
|
||||
|
||||
|
||||
this.dados.add(dataResult);
|
||||
}
|
||||
|
||||
this.resultSet = rset;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getSql(String empresaId) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
|
||||
/* Boletos apenas com venda e cancelamento direto com corrida */
|
||||
|
||||
|
||||
|
||||
sql.append(" select");
|
||||
sql.append(" geral.Linhas,");
|
||||
sql.append(" geral.Empresa,");
|
||||
sql.append(" geral.DescLinha,");
|
||||
sql.append(" geral.KMPadrao,");
|
||||
sql.append(" COUNT(");
|
||||
sql.append(" CASE");
|
||||
sql.append(" WHEN geral.TIPOSERVICIO_ID = 1");
|
||||
sql.append(" THEN 1");
|
||||
sql.append(" ELSE null");
|
||||
sql.append(" END) AS SRVNormal,");
|
||||
sql.append(" COUNT(");
|
||||
sql.append(" CASE");
|
||||
sql.append(" WHEN geral.TIPOSERVICIO_ID = 2");
|
||||
sql.append(" THEN 1");
|
||||
sql.append(" ELSE null");
|
||||
sql.append(" END) AS SRVExtra,");
|
||||
sql.append(" NVL(geral.KMPadrao, 0 ) * (NVL( COUNT(");
|
||||
sql.append(" CASE");
|
||||
sql.append(" WHEN geral.TIPOSERVICIO_ID = 1");
|
||||
sql.append(" THEN 1");
|
||||
sql.append(" ELSE null");
|
||||
sql.append(" END), 0 ) + NVL( COUNT(");
|
||||
sql.append(" CASE");
|
||||
sql.append(" WHEN geral.TIPOSERVICIO_ID = 2");
|
||||
sql.append(" THEN 1");
|
||||
sql.append(" ELSE null");
|
||||
sql.append(" END), 0 )) as KMTotal,");
|
||||
|
||||
|
||||
sql.append("(NVL( COUNT(");
|
||||
sql.append(" CASE");
|
||||
sql.append(" WHEN geral.TIPOSERVICIO_ID = 1");
|
||||
sql.append(" THEN 1");
|
||||
sql.append(" ELSE null");
|
||||
sql.append(" END), 0 ) + NVL( COUNT(");
|
||||
sql.append(" CASE");
|
||||
sql.append(" WHEN geral.TIPOSERVICIO_ID = 2");
|
||||
sql.append(" THEN 1");
|
||||
sql.append(" ELSE null");
|
||||
sql.append(" END), 0 )) SRVTotal");
|
||||
|
||||
sql.append(" from (SELECT c.RUTA_ID AS Linhas,");
|
||||
sql.append(" c.EMPRESACORRIDA_ID AS Empresa,");
|
||||
sql.append(" r.DESCRUTA AS DescLinha,");
|
||||
sql.append(" c.TIPOSERVICIO_ID,");
|
||||
sql.append(" (select sum(t.CANTKMREAL) from CORRIDA_TRAMO ct inner join TRAMO t ON ct.TRAMO_ID = t.TRAMO_ID where ct.CORRIDA_ID = c.CORRIDA_ID");
|
||||
sql.append(" AND ct.FECCORRIDA = c.FECCORRIDA ) AS KMPadrao");
|
||||
sql.append(" FROM CORRIDA c");
|
||||
sql.append(" JOIN RUTA r");
|
||||
sql.append(" ON c.RUTA_ID = r.RUTA_ID");
|
||||
sql.append(" WHERE ");
|
||||
sql.append(" c.FECCORRIDA BETWEEN :fecInicio and :fecFinal");
|
||||
if (!empresaId.equals("null")) {
|
||||
sql.append(" and c.EMPRESACORRIDA_ID = :empresaId ");
|
||||
}
|
||||
sql.append(") geral group by geral.Linhas, geral.Empresa, geral.DescLinha, geral.KMPadrao");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// sql.append("SELECT DISTINCT c.RUTA_ID AS Linhas,");
|
||||
// sql.append(" c.EMPRESACORRIDA_ID AS Empresa,");
|
||||
// sql.append(" r.DESCRUTA AS DescLinha,");
|
||||
// sql.append(" SUM(t.CANTKMREAL) AS KMPadrao,");
|
||||
// sql.append(" COUNT(");
|
||||
// sql.append(" CASE");
|
||||
// sql.append(" WHEN c.TIPOSERVICIO_ID = 1");
|
||||
// sql.append(" THEN 1");
|
||||
// sql.append(" ELSE NULL");
|
||||
// sql.append(" END ) AS SRVNormal,");
|
||||
// sql.append(" COUNT(");
|
||||
// sql.append(" CASE");
|
||||
// sql.append(" WHEN c.TIPOSERVICIO_ID = 2");
|
||||
// sql.append(" THEN 1");
|
||||
// sql.append(" ELSE NULL");
|
||||
// sql.append(" END ) AS SRVExtra,");
|
||||
// sql.append(" COUNT (c.CORRIDA_ID) AS SRVTotal");
|
||||
// sql.append(" FROM CORRIDA c");
|
||||
// sql.append(" JOIN CORRIDA_TRAMO ct");
|
||||
// sql.append(" ON ct.CORRIDA_ID = c.CORRIDA_ID");
|
||||
// sql.append(" AND ct.FECCORRIDA = c.FECCORRIDA");
|
||||
// sql.append(" JOIN TRAMO t");
|
||||
// sql.append(" ON ct.TRAMO_ID = t.TRAMO_ID");
|
||||
// sql.append(" JOIN RUTA r ");
|
||||
// sql.append(" on c.RUTA_ID = r.RUTA_ID");
|
||||
// sql.append(" WHERE ");
|
||||
// sql.append(" c.FECCORRIDA BETWEEN :fecInicio and :fecFinal");
|
||||
// if (empresaId != null) {
|
||||
// sql.append(" and c.EMPRESACORRIDA_ID = :empresaId ");
|
||||
// }
|
||||
// sql.append(" GROUP BY c.RUTA_ID,");
|
||||
// sql.append(" c.EMPRESACORRIDA_ID,");
|
||||
// sql.append(" r.DESCRUTA ");
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue