Divergência de valores no Relatório Empresa Corrida (fixes bug #6182)

Tempo: 01 horas

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@43238 d1611594-4594-4d17-8e1d-87c2c4800839
master
julio 2015-04-17 13:08:06 +00:00
parent 937ff62423
commit 9cde5d4610
2 changed files with 26 additions and 33 deletions

View File

@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource;
@ -17,10 +19,10 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
public class RelatorioEmpresaCorrida extends Relatorio {
private List<RelatorioEmpresaCorridaBean> lsDadosRelatorio;
public RelatorioEmpresaCorrida(Map<String, Object> parametros, Connection conexao) throws Exception {
public RelatorioEmpresaCorrida(Map<String, Object> parametros, Connection conexao) throws Exception {
super(parametros, conexao);
this.setCustomDataSource(new DataSource(this) {
@Override
public void initDados() throws Exception {
@ -32,24 +34,24 @@ public class RelatorioEmpresaCorrida extends Relatorio {
String fecInicio = parametros.get("fecInicio").toString() + " 00:00:00";
String fecFinal = parametros.get("fecFinal").toString() + " 23:59:59";
String empresa = parametros.get("empresa") != null ? parametros.get("empresa").toString() : "";
String sql = getSql(empresa);
System.out.println(sql);
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
ResultSet rset = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
stmt.setTimestamp("fecInicio", new java.sql.Timestamp(sdf.parse(fecInicio).getTime()));
stmt.setTimestamp("fecFinal", new java.sql.Timestamp(sdf.parse(fecFinal).getTime()));
if (empresa != null && !empresa.equals("")){
if (empresa != null && !empresa.equals("")) {
stmt.setInt("empresa_id", Integer.parseInt(empresa));
}
rset = stmt.executeQuery();
lsDadosRelatorio = new ArrayList<RelatorioEmpresaCorridaBean>();
while (rset.next()) {
RelatorioEmpresaCorridaBean empresaCorridaBean = new RelatorioEmpresaCorridaBean();
empresaCorridaBean.setAbonos(rset.getBigDecimal("abonos"));
@ -60,10 +62,10 @@ public class RelatorioEmpresaCorrida extends Relatorio {
empresaCorridaBean.setKmTotal(rset.getInt("kmTotal"));
empresaCorridaBean.setLinea(rset.getString("linea"));
empresaCorridaBean.setPasajerosTransportados(rset.getInt("passageirosTransp"));
lsDadosRelatorio.add(empresaCorridaBean);
}
if (lsDadosRelatorio.size() > 0) {
setLsDadosRelatorio(lsDadosRelatorio);
@ -71,7 +73,7 @@ public class RelatorioEmpresaCorrida extends Relatorio {
}
});
}
public void setLsDadosRelatorio(List<RelatorioEmpresaCorridaBean> lsDadosRelatorio) {
this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio));
this.lsDadosRelatorio = lsDadosRelatorio;
@ -80,7 +82,7 @@ public class RelatorioEmpresaCorrida extends Relatorio {
@Override
protected void processaParametros() throws Exception {
}
private String getSql(String empresa) {
StringBuffer sql = new StringBuffer();
sql.append("SELECT DISTINCT e.empresa_id, ");
@ -103,12 +105,9 @@ public class RelatorioEmpresaCorrida extends Relatorio {
sql.append(" COALESCE(km2.kmonibusarrendados, 0) kmOnibusArrendados ");
sql.append("FROM boleto b ");
sql.append(" INNER JOIN categoria cat on cat.categoria_id = b.categoria_id ");
sql.append(" INNER JOIN marca m ");
sql.append(" ON m.marca_id = b.marca_id ");
sql.append(" INNER JOIN empresa e ");
sql.append(" ON e.empresa_id = m.empresa_id ");
sql.append(" INNER JOIN ruta r ");
sql.append(" ON r.ruta_id = b.ruta_id ");
sql.append(" INNER JOIN marca m ON m.marca_id = b.marca_id ");
sql.append(" INNER JOIN empresa e ON e.empresa_id = m.empresa_id ");
sql.append(" INNER JOIN ruta r ON r.ruta_id = b.ruta_id ");
sql.append(" LEFT JOIN (SELECT c1.ruta_id ruta_id, ");
sql.append(" c1.EMPRESACORRIDA_ID empresa_id, ");
sql.append(" COALESCE(Sum(t1.cantkmreal), 0) kmtotal, ");
@ -132,18 +131,14 @@ public class RelatorioEmpresaCorrida extends Relatorio {
sql.append(" AND ct.feccorrida = c1.feccorrida ");
sql.append(" INNER JOIN autobus a ");
sql.append(" ON ct.autobus_id = a.autobus_id ");
sql.append(" WHERE c1.feccorrida BETWEEN :fecInicio AND :fecFinal ");
sql.append(" AND c1.empresacorrida_id = :empresa_id ");
sql.append(" AND c1.activo <> 0 AND ct.activo <> 0 ");
sql.append(" WHERE c1.activo <> 0 AND ct.activo <> 0 ");
sql.append(" AND a.activo <> 0 AND t1.activo <> 0 ");
sql.append(" GROUP BY c1.ruta_id, ");
sql.append(" c1.EMPRESACORRIDA_ID) km2 ");
sql.append(StringUtils.isBlank(empresa) ? "" : " AND c1.empresacorrida_id = :empresa_id ");
sql.append(" GROUP BY c1.ruta_id, c1.EMPRESACORRIDA_ID) km2 ");
sql.append(" ON ( km2.ruta_id = r.ruta_id ");
sql.append(" AND km2.empresa_id = e.empresa_id ) ");
sql.append("WHERE b.fechorventa BETWEEN :fecInicio AND :fecFinal ");
if (empresa != null && !empresa.isEmpty()){
sql.append(" AND e.empresa_id = :empresa_id ");
}
sql.append(StringUtils.isBlank(empresa) ? "" : " AND e.empresa_id = :empresa_id ");
sql.append("GROUP BY e.empresa_id, ");
sql.append(" r.ruta_id, ");
sql.append(" r.descruta, ");
@ -151,9 +146,8 @@ public class RelatorioEmpresaCorrida extends Relatorio {
sql.append(" km2.kmtotal, ");
sql.append(" km2.kmonibusproprio, ");
sql.append(" km2.kmonibusarrendados ");
sql.append("ORDER BY nombempresa, ");
sql.append(" linea ");
sql.append("ORDER BY nombempresa, linea ");
return sql.toString();
}
}

View File

@ -7,8 +7,7 @@
<zk xmlns="http://www.zkoss.org/2005/zul">
<window id="winFiltroRelatorioEmpresaCorrida"
apply="${relatorioEmpresaCorridaController}"
contentStyle="overflow:auto" height="264px" width="550px"
border="normal">
contentStyle="overflow:auto" width="550px" border="normal">
<grid fixedLayout="true">
<columns>