diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibus.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibus.java index c441a341f..6ac5a4f74 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibus.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibus.java @@ -31,8 +31,10 @@ public class RelatorioEmpresaOnibus 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 autobus = parametros.get("autobus") != null ? parametros.get("autobus").toString() : ""; - String sql = getSql(); + String sql = getSql(empresa, autobus); System.out.println(sql); @@ -40,6 +42,13 @@ public class RelatorioEmpresaOnibus extends Relatorio { NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); 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)); + } + if (autobus != null && !autobus.equals("")){ + stmt.setInt("autobus_id", Integer.parseInt(autobus)); + } + ResultSet rset = null; rset = stmt.executeQuery(); @@ -61,7 +70,6 @@ public class RelatorioEmpresaOnibus extends Relatorio { } if (lsDadosRelatorio.size() > 0) { - setLsDadosRelatorio(lsDadosRelatorio); } } @@ -77,7 +85,7 @@ public class RelatorioEmpresaOnibus extends Relatorio { protected void processaParametros() throws Exception { } - private String getSql() { + private String getSql(String empresa, String autobus) { StringBuffer sql = new StringBuffer(); sql.append(" select c.corrida_Id corridaId, e.nombempresa empresa, c.feccorrida dia, a.numautobus coche, "); @@ -90,9 +98,15 @@ public class RelatorioEmpresaOnibus extends Relatorio { sql.append(" left join tramo t on t.origen_id = c.origen_id and t.destino_id = c.destino_id and t.tramo_id = rc.tramo_id "); sql.append(" inner join autobus a on a.autobus_id = c.autobus_id "); sql.append(" left join empresa e on e.empresa_id = a.empresa_id "); - sql.append(" where extract(month from c.feccorrida) = 6 "); - sql.append(" and c.activo = 1 and rc.activo = 1 and c.feccorrida between :fecInicio and :fecFinal "); - sql.append(" order by e.nombempresa, c.feccorrida "); + sql.append(" where c.activo = 1 "); + if (!empresa.isEmpty()){ + sql.append(" and e.empresa_id = :empresa_id "); + } + if (!autobus.isEmpty()){ + sql.append(" and a.autobus_id = :autobus_id "); + } + sql.append(" and rc.activo = 1 and c.feccorrida between :fecInicio and :fecFinal "); + sql.append(" order by e.nombempresa, a.numautobus, c.feccorrida "); return sql.toString(); } diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibusResumo.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibusResumo.java new file mode 100644 index 000000000..0d380dfe6 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioEmpresaOnibusResumo.java @@ -0,0 +1,124 @@ +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 net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; + +import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioEmpresaOnibusBean; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +public class RelatorioEmpresaOnibusResumo extends Relatorio { + + private List lsDadosRelatorio; + + public RelatorioEmpresaOnibusResumo(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + + this.setCustomDataSource(new DataSource(this) { + @Override + public void initDados() throws Exception { + + Connection conexao = this.relatorio.getConexao(); + + Map parametros = this.relatorio.getParametros(); + + 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 autobus = parametros.get("autobus") != null ? parametros.get("autobus").toString() : ""; + + String sql = getSql(empresa, autobus); + + System.out.println(sql); + + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); + 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)); + } + if (autobus != null && !autobus.equals("")){ + stmt.setInt("autobus_id", Integer.parseInt(autobus)); + } + + ResultSet rset = null; + + rset = stmt.executeQuery(); + + lsDadosRelatorio = new ArrayList(); + + while (rset.next()) { + RelatorioEmpresaOnibusBean empresaOnibusBean = new RelatorioEmpresaOnibusBean(); + //empresaOnibusBean.setCorridaId(rset.getInt("corridaId")); + empresaOnibusBean.setEmpresa(rset.getString("empresa")); + empresaOnibusBean.setCoche(Integer.parseInt(rset.getString("coche"))); + //empresaOnibusBean.setDestino(rset.getString("destino")); + //empresaOnibusBean.setDia(rset.getDate("dia")); + //empresaOnibusBean.setHora(rset.getString("hora")); + empresaOnibusBean.setKmts(rset.getInt("kmts")); + //empresaOnibusBean.setOrigem(rset.getString("origem")); + + lsDadosRelatorio.add(empresaOnibusBean); + } + + if (lsDadosRelatorio.size() > 0) { + setLsDadosRelatorio(lsDadosRelatorio); + } + } + }); + } + + public void setLsDadosRelatorio(List lsDadosRelatorio) { + this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); + this.lsDadosRelatorio = lsDadosRelatorio; + } + + @Override + protected void processaParametros() throws Exception { + } + + private String getSql(String empresa, String autobus) { + StringBuffer sql = new StringBuffer(); + sql.append("SELECT e.nombempresa empresa, "); + sql.append(" a.numautobus coche, "); + sql.append(" Sum(t.cantkmreal) KMTS "); + sql.append("FROM corrida c, "); + sql.append(" ruta_combinacion rc, "); + sql.append(" tramo t, "); + sql.append(" autobus a, "); + sql.append(" empresa e, "); + sql.append(" parada o, "); + sql.append(" parada d "); + sql.append("WHERE c.activo = 1 "); + sql.append(" AND rc.ruta_id = c.ruta_id "); + sql.append(" AND t.origen_id = c.origen_id "); + sql.append(" AND t.destino_id = c.destino_id "); + sql.append(" AND t.tramo_id = rc.tramo_id "); + sql.append(" AND rc.activo = 1 "); + sql.append(" AND c.feccorrida BETWEEN :fecInicio and :fecFinal "); + sql.append(" AND a.autobus_id = c.autobus_id "); + sql.append(" AND e.empresa_id = a.empresa_id "); + sql.append(" AND o.parada_id = c.origen_id "); + sql.append(" AND d.parada_id = c.destino_id "); + if (!empresa.isEmpty()){ + sql.append(" AND e.empresa_id = :empresa_id "); + } + if (!autobus.isEmpty()){ + sql.append(" AND a.autobus_id = :autobus_id "); + } + sql.append("GROUP BY e.nombempresa, "); + sql.append(" a.numautobus "); + sql.append("ORDER BY e.nombempresa, "); + sql.append(" a.numautobus "); + + return sql.toString(); + } +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibusResumo_es.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibusResumo_es.properties new file mode 100644 index 000000000..d00d8ed86 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibusResumo_es.properties @@ -0,0 +1,25 @@ +#geral +msg.noData=No se pudo obtener datos con los parámetros reportados. +msg.a=a + +#Labels header +header.periodo=Período: +header.data.hora=Fecha/Hora\: +header.pagina=Página\: +header.filtro=Filtro\: +header.filtro.servico=Servicio\: +header.filtro.linha=Línea\: +header.filtro.grupo=Grupo de líneas\: + +#Labels detail + +detail.dia=Dia +detail.coche=Coche +detail.origen=Origen +detail.destino=Destino +detail.hora=Hora +detail.kmts=Kmts +detail.corridaId=Corrida + +linhas=Líneas + diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibus_pt_BR2.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibusResumo_pt_BR.properties similarity index 100% rename from src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibus_pt_BR2.properties rename to src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibusResumo_pt_BR.properties diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibus_pt_BR.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibus_pt_BR.properties new file mode 100644 index 000000000..698f8179d --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioEmpresaOnibus_pt_BR.properties @@ -0,0 +1,26 @@ +#geral +msg.noData=Não foi possivel obter dados com os parâmetros informados. +msg.a=à + +#Labels header +header.periodo=Período: +header.data.hora=Data/Hora\: +header.pagina=Página\: +header.filtro=Filtro\: +header.filtro.servico=Serviço\: +header.filtro.linha=Linha\: +header.filtro.grupo=Grupo de Linhas\: + +#Labels detail + +detail.dia=Dia +detail.coche=Carro +detail.origen=Origem +detail.destino=Destino +detail.hora=Hora +detail.kmts=Kmts +detail.corridaId=Corrida + +linhas=Linhas + + diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioEmpresaOnibusResumo.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioEmpresaOnibusResumo.jrxml new file mode 100644 index 000000000..0848b88f2 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioEmpresaOnibusResumo.jrxml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmpresaOnibusController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmpresaOnibusController.java index 49dec40ef..312413fe6 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmpresaOnibusController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioEmpresaOnibusController.java @@ -2,6 +2,7 @@ package com.rjconsultores.ventaboletos.web.gui.controladores.relatorios; import java.text.SimpleDateFormat; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.sql.DataSource; @@ -13,10 +14,17 @@ import org.springframework.stereotype.Controller; import org.zkoss.util.resource.Labels; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; +import org.zkoss.zul.Checkbox; import org.zkoss.zul.Datebox; +import com.rjconsultores.ventaboletos.entidad.Autobus; +import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioEmpresaOnibus; +import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioEmpresaOnibusResumo; import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.service.AutobusService; +import com.rjconsultores.ventaboletos.service.EmpresaService; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar; import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; @Controller("relatorioEmpresaOnibusController") @@ -27,21 +35,49 @@ public class RelatorioEmpresaOnibusController extends MyGenericForwardComposer { @Autowired private DataSource dataSource; + @Autowired + private EmpresaService empresaService; + @Autowired + private AutobusService autobusService; private Datebox datInicial; private Datebox datFinal; + private MyComboboxEstandar cmbEmpresa; + private MyComboboxEstandar cmbAutobus; + private Checkbox chkResumo; + + private List lsEmpresas; + private List lsAutobus; private void executarRelatorio() throws Exception { Map parametros = new HashMap(); + Empresa empresa = cmbEmpresa.getSelectedItem() != null ? (Empresa)cmbEmpresa.getSelectedItem().getValue() : null; + Autobus autobus = cmbAutobus.getSelectedItem() != null ? (Autobus)cmbAutobus.getSelectedItem().getValue() : null; + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); parametros.put("fecInicio", sdf.format(this.datInicial.getValue())); parametros.put("fecFinal", sdf.format(this.datFinal.getValue())); - parametros.put("TITULO", Labels.getLabel("relatorioEmpresaOnibusController.window.title")); - Relatorio relatorio = new RelatorioEmpresaOnibus(parametros, dataSource.getConnection()); - + if (empresa != null){ + parametros.put("empresa", empresa.getEmpresaId()); + } + + if (autobus != null){ + parametros.put("autobus", autobus.getAutobusId()); + } + + Relatorio relatorio; + + if (chkResumo.isChecked()){ + parametros.put("TITULO", Labels.getLabel("relatorioEmpresaOnibusResumoController.window.title")); + relatorio = new RelatorioEmpresaOnibusResumo(parametros, dataSource.getConnection()); + } else { + parametros.put("TITULO", Labels.getLabel("relatorioEmpresaOnibusController.window.title")); + relatorio = new RelatorioEmpresaOnibus(parametros, dataSource.getConnection()); + } + Map args = new HashMap(); args.put("relatorio", relatorio); @@ -56,7 +92,34 @@ public class RelatorioEmpresaOnibusController extends MyGenericForwardComposer { @Override public void doAfterCompose(Component comp) throws Exception { + lsEmpresas = empresaService.obtenerTodos(); + lsAutobus = autobusService.obtenerTodos(); + super.doAfterCompose(comp); } + public MyComboboxEstandar getCmbEmpresa() { + return cmbEmpresa; + } + + public void setCmbEmpresa(MyComboboxEstandar cmbEmpresa) { + this.cmbEmpresa = cmbEmpresa; + } + + public List getLsEmpresas() { + return lsEmpresas; + } + + public void setLsEmpresas(List lsEmpresas) { + this.lsEmpresas = lsEmpresas; + } + + public List getLsAutobus() { + return lsAutobus; + } + + public void setLsAutobus(List lsAutobus) { + this.lsAutobus = lsAutobus; + } + } diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index 854bf75d2..bde9c43eb 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -301,9 +301,12 @@ relatorioEmpresaCorridaController.window.title=Reporte Empresa Corrida relatorioEmpresaCorridaController.lbDataIni.value=Fecha Inicio relatorioEmpresaCorridaController.lbDataFin.value=Fecha Final relatorioEmpresaCorridaController.lbEmpresa.value=Empresa +relatorioEmpresaCorridaController.lbOnibus.value=Onibus +relatorioEmpresaCorridaController.lbResumo.value=Resumen # Relatorio Empresa Onibus relatorioEmpresaOnibusController.window.title=Reporte Empresa Onibus +relatorioEmpresaOnibusResumoController.window.title=Reporte Empresa Onibus - Resumen relatorioEmpresaOnibusController.lbDataIni.value=Fecha Inicio relatorioEmpresaOnibusController.lbDataFin.value=Fecha Final diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index 89075b6ff..46695e74b 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -306,9 +306,12 @@ relatorioEmpresaCorridaController.window.title=Relatório Empresa Corrida relatorioEmpresaCorridaController.lbDataIni.value=Data Inicial relatorioEmpresaCorridaController.lbDataFin.value=Data Final relatorioEmpresaCorridaController.lbEmpresa.value=Empresa +relatorioEmpresaCorridaController.lbOnibus.value=Ônibus +relatorioEmpresaCorridaController.lbResumo.value=Resumo # Relatorio Empresa Onibus relatorioEmpresaOnibusController.window.title=Relatório Empresa Ônibus +relatorioEmpresaOnibusResumoController.window.title=Relatório Empresa Ônibus - Resumo relatorioEmpresaOnibusController.lbDataIni.value=Data Inicial relatorioEmpresaOnibusController.lbDataFin.value=Data Final diff --git a/web/gui/relatorios/filtroRelatorioEmpresaOnibus.zul b/web/gui/relatorios/filtroRelatorioEmpresaOnibus.zul index 20381f6e2..a2380640c 100644 --- a/web/gui/relatorios/filtroRelatorioEmpresaOnibus.zul +++ b/web/gui/relatorios/filtroRelatorioEmpresaOnibus.zul @@ -30,6 +30,25 @@ format="dd/MM/yyyy" lenient="false" constraint="no empty" maxlength="10" /> + + + +