Divergência Relatório Empresa ônibus x Empresa Corrida (bug #6270)
Tempo: 03 horas git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@44213 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
8a1f62a08d
commit
aec2f45b02
|
@ -37,7 +37,7 @@ public class RelatorioEmpresaCorrida extends Relatorio {
|
||||||
String fecFinal = parametros.get("fecFinal").toString() + " 23:59:59";
|
String fecFinal = parametros.get("fecFinal").toString() + " 23:59:59";
|
||||||
String empresa = parametros.get("empresa") != null ? parametros.get("empresa").toString() : "";
|
String empresa = parametros.get("empresa") != null ? parametros.get("empresa").toString() : "";
|
||||||
|
|
||||||
log.info("empresa:"+empresa+";fecinicio:"+fecInicio+";fecFinal:"+fecFinal);
|
log.info("empresa:" + empresa + ";fecinicio:" + fecInicio + ";fecFinal:" + fecFinal);
|
||||||
String sql = getSql(empresa);
|
String sql = getSql(empresa);
|
||||||
log.info(sql);
|
log.info(sql);
|
||||||
|
|
||||||
|
@ -50,30 +50,55 @@ public class RelatorioEmpresaCorrida extends Relatorio {
|
||||||
if (empresa != null && !empresa.equals("")) {
|
if (empresa != null && !empresa.equals("")) {
|
||||||
stmt.setInt("empresa_id", Integer.parseInt(empresa));
|
stmt.setInt("empresa_id", Integer.parseInt(empresa));
|
||||||
}
|
}
|
||||||
log.info("Antes de enviar consulta para o banco:"+ System.currentTimeMillis());
|
log.info("Antes de enviar consulta para o banco:" + System.currentTimeMillis());
|
||||||
rset = stmt.executeQuery();
|
rset = stmt.executeQuery();
|
||||||
log.info("Depois de enviar consulta para o banco:"+ System.currentTimeMillis());
|
log.info("Depois de enviar consulta para o banco:" + System.currentTimeMillis());
|
||||||
|
|
||||||
lsDadosRelatorio = new ArrayList<RelatorioEmpresaCorridaBean>();
|
lsDadosRelatorio = new ArrayList<RelatorioEmpresaCorridaBean>();
|
||||||
|
|
||||||
log.info("Preenchendo bean:"+ System.currentTimeMillis());
|
log.info("Preenchendo bean:" + System.currentTimeMillis());
|
||||||
while (rset.next()) {
|
while (rset.next()) {
|
||||||
RelatorioEmpresaCorridaBean empresaCorridaBean = new RelatorioEmpresaCorridaBean();
|
RelatorioEmpresaCorridaBean rec = new RelatorioEmpresaCorridaBean();
|
||||||
empresaCorridaBean.setAbonos(rset.getBigDecimal("abonos"));
|
rec.setRutaId(rset.getInt("ruta_id"));
|
||||||
empresaCorridaBean.setBoletos(rset.getBigDecimal("boletos"));
|
rec.setAbonos(rset.getBigDecimal("abonos"));
|
||||||
empresaCorridaBean.setEmpresa(rset.getString("nombempresa"));
|
rec.setBoletos(rset.getBigDecimal("boletos"));
|
||||||
empresaCorridaBean.setKmOnibusArrendados(rset.getInt("kmOnibusArrendados"));
|
rec.setEmpresa(rset.getString("nombempresa"));
|
||||||
empresaCorridaBean.setKmOnibusProprio(rset.getInt("kmOnibusProprio"));
|
rec.setLinea(rset.getString("linea"));
|
||||||
empresaCorridaBean.setKmTotal(rset.getInt("kmTotal"));
|
rec.setPasajerosTransportados(rset.getInt("passageirosTransp"));
|
||||||
empresaCorridaBean.setLinea(rset.getString("linea"));
|
|
||||||
empresaCorridaBean.setPasajerosTransportados(rset.getInt("passageirosTransp"));
|
|
||||||
|
|
||||||
lsDadosRelatorio.add(empresaCorridaBean);
|
lsDadosRelatorio.add(rec);
|
||||||
|
}
|
||||||
|
log.info("Fim bean:" + System.currentTimeMillis());
|
||||||
|
|
||||||
|
String sqlKm = getSqlKm(empresa);
|
||||||
|
log.info(sqlKm);
|
||||||
|
|
||||||
|
stmt = new NamedParameterStatement(conexao, sqlKm);
|
||||||
|
rset = null;
|
||||||
|
|
||||||
|
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("")) {
|
||||||
|
stmt.setInt("empresa_id", Integer.parseInt(empresa));
|
||||||
|
}
|
||||||
|
|
||||||
|
rset = stmt.executeQuery();
|
||||||
|
while (rset.next()) {
|
||||||
|
|
||||||
|
Integer rutaId = rset.getInt("ruta_id");
|
||||||
|
|
||||||
|
Integer index = buscarRelatorioEmpresaCorrida(lsDadosRelatorio, rutaId);
|
||||||
|
if (index > -1) {
|
||||||
|
RelatorioEmpresaCorridaBean rec = lsDadosRelatorio.get(index);
|
||||||
|
rec.setKmOnibusArrendados(rset.getInt("kmOnibusArrendados"));
|
||||||
|
rec.setKmOnibusProprio(rset.getInt("kmOnibusProprio"));
|
||||||
|
rec.setKmTotal(rset.getInt("kmTotal"));
|
||||||
|
|
||||||
|
lsDadosRelatorio.set(index, rec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("Fim bean:"+ System.currentTimeMillis());
|
|
||||||
|
|
||||||
if (lsDadosRelatorio.size() > 0) {
|
if (lsDadosRelatorio.size() > 0) {
|
||||||
|
|
||||||
setLsDadosRelatorio(lsDadosRelatorio);
|
setLsDadosRelatorio(lsDadosRelatorio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +114,15 @@ public class RelatorioEmpresaCorrida extends Relatorio {
|
||||||
protected void processaParametros() throws Exception {
|
protected void processaParametros() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer buscarRelatorioEmpresaCorrida(List<RelatorioEmpresaCorridaBean> lsDadosRelatorio, Integer rutaId) {
|
||||||
|
for (RelatorioEmpresaCorridaBean rec : lsDadosRelatorio) {
|
||||||
|
if (rec.getRutaId().equals(rutaId)) {
|
||||||
|
return lsDadosRelatorio.indexOf(rec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private String getSql(String empresa) {
|
private String getSql(String empresa) {
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
|
@ -99,29 +133,10 @@ public class RelatorioEmpresaCorrida extends Relatorio {
|
||||||
sql.append(" r.descruta AS linea, ");
|
sql.append(" r.descruta AS linea, ");
|
||||||
sql.append(" COALESCE(SUM(CASE WHEN ((b.motivocancelacion_id IS NULL) AND (cat.grupocategoria_id IS NULL OR cat.grupocategoria_id <> 4)) THEN b.preciopagado ELSE 0 END), 0) boletos, ");
|
sql.append(" COALESCE(SUM(CASE WHEN ((b.motivocancelacion_id IS NULL) AND (cat.grupocategoria_id IS NULL OR cat.grupocategoria_id <> 4)) THEN b.preciopagado ELSE 0 END), 0) boletos, ");
|
||||||
sql.append(" COALESCE(SUM(CASE WHEN b.motivocancelacion_id IS NULL AND cat.grupocategoria_id = 4 THEN b.preciopagado ELSE 0 END), 0) abonos, ");
|
sql.append(" COALESCE(SUM(CASE WHEN b.motivocancelacion_id IS NULL AND cat.grupocategoria_id = 4 THEN b.preciopagado ELSE 0 END), 0) abonos, ");
|
||||||
sql.append(" COALESCE(SUM(CASE WHEN b.motivocancelacion_id IS NULL THEN 1 ELSE 0 END), 0) passageirosTransp, ");
|
sql.append(" COALESCE(SUM(CASE WHEN b.motivocancelacion_id IS NULL THEN 1 ELSE 0 END), 0) passageirosTransp ");
|
||||||
sql.append(" COALESCE(km2.kmtotal, 0) kmtotal, ");
|
|
||||||
sql.append(" COALESCE(km2.kmonibusproprio, 0) kmOnibusProprio, ");
|
|
||||||
sql.append(" COALESCE(km2.kmonibusarrendados, 0) kmOnibusArrendados ");
|
|
||||||
sql.append("FROM ruta r ");
|
sql.append("FROM ruta r ");
|
||||||
sql.append("INNER JOIN ruta_empresa re ON re.ruta_id = r.ruta_id ");
|
sql.append("INNER JOIN ruta_empresa re ON re.ruta_id = r.ruta_id ");
|
||||||
sql.append("INNER JOIN empresa e ON re.empresa_id = e.empresa_id ");
|
sql.append("INNER JOIN empresa e ON re.empresa_id = e.empresa_id ");
|
||||||
sql.append("INNER JOIN ");
|
|
||||||
sql.append(" (SELECT c.ruta_id ruta_id, ");
|
|
||||||
sql.append(" COALESCE(SUM(t.cantkmreal), 0) kmtotal, ");
|
|
||||||
sql.append(" COALESCE(SUM(CASE WHEN a.empresa_id = c.empresacorrida_id THEN t.cantkmreal ELSE 0 END), 0) kmOnibusProprio, ");
|
|
||||||
sql.append(" COALESCE(SUM( CASE WHEN a.empresa_id <> c.empresacorrida_id THEN t.cantkmreal ELSE 0 END), 0) kmOnibusArrendados ");
|
|
||||||
sql.append(" FROM corrida c ");
|
|
||||||
sql.append(" INNER JOIN corrida_tramo ct ON ct.corrida_id = c.corrida_id AND c.feccorrida = ct.feccorrida ");
|
|
||||||
sql.append(" INNER JOIN tramo t ON t.tramo_id = ct.tramo_id ");
|
|
||||||
sql.append(" INNER JOIN parada o ON o.parada_id = ct.origen_id ");
|
|
||||||
sql.append(" INNER JOIN parada d ON d.parada_id = ct.destino_id ");
|
|
||||||
sql.append(" INNER JOIN autobus a ON a.autobus_id = ct.autobus_id ");
|
|
||||||
sql.append(" INNER JOIN empresa e ON e.empresa_id = a.empresa_id ");
|
|
||||||
sql.append(" WHERE c.activo <> 0 AND ct.activo = 1 ");
|
|
||||||
sql.append(StringUtils.isBlank(empresa) ? "" : "AND c.empresacorrida_id = :empresa_id ");
|
|
||||||
sql.append(" AND c.FECCORRIDA BETWEEN :fecInicio AND :fecFinal ");
|
|
||||||
sql.append(" GROUP BY c.ruta_id ) km2 ON re.ruta_id = km2.ruta_id ");
|
|
||||||
sql.append("LEFT JOIN corrida c ON c.ruta_id = re.ruta_id ");
|
sql.append("LEFT JOIN corrida c ON c.ruta_id = re.ruta_id ");
|
||||||
sql.append("LEFT JOIN boleto b ON b.corrida_id = c.corrida_id AND b.feccorrida = c.feccorrida ");
|
sql.append("LEFT JOIN boleto b ON b.corrida_id = c.corrida_id AND b.feccorrida = c.feccorrida ");
|
||||||
sql.append("LEFT OUTER JOIN categoria cat ON cat.categoria_id = b.categoria_id ");
|
sql.append("LEFT OUTER JOIN categoria cat ON cat.categoria_id = b.categoria_id ");
|
||||||
|
@ -134,11 +149,33 @@ public class RelatorioEmpresaCorrida extends Relatorio {
|
||||||
sql.append(" e.empresa_id, ");
|
sql.append(" e.empresa_id, ");
|
||||||
sql.append(" e.nombempresa, ");
|
sql.append(" e.nombempresa, ");
|
||||||
sql.append(" r.ruta_id, ");
|
sql.append(" r.ruta_id, ");
|
||||||
sql.append(" r.descruta, ");
|
sql.append(" r.descruta ");
|
||||||
sql.append(" km2.kmtotal, ");
|
sql.append("ORDER BY r.ruta_id ");
|
||||||
sql.append(" km2.kmonibusproprio, ");
|
|
||||||
sql.append(" km2.kmonibusarrendados ");
|
return sql.toString();
|
||||||
// sql.append("ORDER BY r.descruta");
|
}
|
||||||
|
|
||||||
|
private String getSqlKm(String empresa) {
|
||||||
|
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
sql.append("SELECT ");
|
||||||
|
sql.append("c.ruta_id ruta_id, ");
|
||||||
|
sql.append("COALESCE(SUM(t.cantkmreal), 0) kmtotal, ");
|
||||||
|
sql.append("COALESCE(SUM(CASE WHEN a.empresa_id = c.empresacorrida_id THEN t.cantkmreal ELSE 0 END), 0) kmOnibusProprio, ");
|
||||||
|
sql.append("COALESCE(SUM(CASE WHEN a.empresa_id <> c.empresacorrida_id THEN t.cantkmreal ELSE 0 END), 0) kmOnibusArrendados ");
|
||||||
|
sql.append("FROM corrida c ");
|
||||||
|
sql.append("INNER JOIN corrida_tramo ct ON ct.corrida_id = c.corrida_id AND c.feccorrida = ct.feccorrida ");
|
||||||
|
sql.append("INNER JOIN tramo t ON t.tramo_id = ct.tramo_id ");
|
||||||
|
sql.append("INNER JOIN parada o ON o.parada_id = ct.origen_id ");
|
||||||
|
sql.append("INNER JOIN parada d ON d.parada_id = ct.destino_id ");
|
||||||
|
sql.append("INNER JOIN autobus a ON a.autobus_id = ct.autobus_id ");
|
||||||
|
sql.append("INNER JOIN empresa e ON e.empresa_id = a.empresa_id ");
|
||||||
|
sql.append("WHERE c.activo <> 0 ");
|
||||||
|
sql.append("AND ct.activo = 1 ");
|
||||||
|
sql.append(StringUtils.isBlank(empresa) ? "" : "AND c.empresacorrida_id = :empresa_id ");
|
||||||
|
sql.append("AND c.FECCORRIDA BETWEEN :fecInicio AND :fecFinal ");
|
||||||
|
sql.append("GROUP BY c.ruta_id ");
|
||||||
|
sql.append("ORDER BY c.ruta_id ");
|
||||||
|
|
||||||
return sql.toString();
|
return sql.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,60 +3,112 @@ package com.rjconsultores.ventaboletos.relatorios.utilitarios;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class RelatorioEmpresaCorridaBean {
|
public class RelatorioEmpresaCorridaBean {
|
||||||
protected String empresa;
|
|
||||||
protected String linea;
|
private Integer rutaId;
|
||||||
protected BigDecimal boletos;
|
private String empresa;
|
||||||
protected BigDecimal abonos;
|
private String linea;
|
||||||
protected Integer kmOnibusProprio;
|
private BigDecimal boletos;
|
||||||
protected Integer kmOnibusArrendados;
|
private BigDecimal abonos;
|
||||||
protected Integer kmTotal;
|
private Integer kmOnibusProprio;
|
||||||
protected Integer pasajerosTransportados;
|
private Integer kmOnibusArrendados;
|
||||||
|
private Integer kmTotal;
|
||||||
|
private Integer pasajerosTransportados;
|
||||||
|
|
||||||
|
public Integer getRutaId() {
|
||||||
|
return rutaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRutaId(Integer rutaId) {
|
||||||
|
this.rutaId = rutaId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getEmpresa() {
|
public String getEmpresa() {
|
||||||
return empresa;
|
return empresa;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEmpresa(String empresa) {
|
public void setEmpresa(String empresa) {
|
||||||
this.empresa = empresa;
|
this.empresa = empresa;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLinea() {
|
public String getLinea() {
|
||||||
return linea;
|
return linea;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLinea(String linea) {
|
public void setLinea(String linea) {
|
||||||
this.linea = linea;
|
this.linea = linea;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getBoletos() {
|
public BigDecimal getBoletos() {
|
||||||
return boletos;
|
return boletos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoletos(BigDecimal boletos) {
|
public void setBoletos(BigDecimal boletos) {
|
||||||
this.boletos = boletos;
|
this.boletos = boletos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getAbonos() {
|
public BigDecimal getAbonos() {
|
||||||
return abonos;
|
return abonos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAbonos(BigDecimal abonos) {
|
public void setAbonos(BigDecimal abonos) {
|
||||||
this.abonos = abonos;
|
this.abonos = abonos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getKmOnibusProprio() {
|
public Integer getKmOnibusProprio() {
|
||||||
return kmOnibusProprio;
|
return kmOnibusProprio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKmOnibusProprio(Integer kmOnibusProprio) {
|
public void setKmOnibusProprio(Integer kmOnibusProprio) {
|
||||||
this.kmOnibusProprio = kmOnibusProprio;
|
this.kmOnibusProprio = kmOnibusProprio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getKmOnibusArrendados() {
|
public Integer getKmOnibusArrendados() {
|
||||||
return kmOnibusArrendados;
|
return kmOnibusArrendados;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKmOnibusArrendados(Integer kmOnibusArrendados) {
|
public void setKmOnibusArrendados(Integer kmOnibusArrendados) {
|
||||||
this.kmOnibusArrendados = kmOnibusArrendados;
|
this.kmOnibusArrendados = kmOnibusArrendados;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getKmTotal() {
|
public Integer getKmTotal() {
|
||||||
return kmTotal;
|
return kmTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKmTotal(Integer kmTotal) {
|
public void setKmTotal(Integer kmTotal) {
|
||||||
this.kmTotal = kmTotal;
|
this.kmTotal = kmTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getPasajerosTransportados() {
|
public Integer getPasajerosTransportados() {
|
||||||
return pasajerosTransportados;
|
return pasajerosTransportados;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPasajerosTransportados(Integer pasajerosTransportados) {
|
public void setPasajerosTransportados(Integer pasajerosTransportados) {
|
||||||
this.pasajerosTransportados = pasajerosTransportados;
|
this.pasajerosTransportados = pasajerosTransportados;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((rutaId == null) ? 0 : rutaId.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
RelatorioEmpresaCorridaBean other = (RelatorioEmpresaCorridaBean) obj;
|
||||||
|
if (rutaId == null) {
|
||||||
|
if (other.rutaId != null)
|
||||||
|
return false;
|
||||||
|
} else if (!rutaId.equals(other.rutaId))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue