diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesResumido.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesResumido.java new file mode 100644 index 000000000..d81b68480 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioVendasPacotesResumido.java @@ -0,0 +1,232 @@ +package com.rjconsultores.ventaboletos.relatorios.impl; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; + +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.RelatorioAproveitamentoBean; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioVendasPacotesBean; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +public class RelatorioVendasPacotesResumido extends Relatorio { + + private static Logger log = Logger.getLogger(RelatorioVendasPacotesBean.class); + + private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + + private List lsDadosRelatorio; + + private Date fecInicio; + private Date fecFinal; + private Integer empresaId; + + public RelatorioVendasPacotesResumido(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + + this.setCustomDataSource(new DataSource(this) { + @Override + public void initDados() throws Exception { + Map parametros = this.relatorio.getParametros(); + fecInicio = new java.sql.Date(sdf.parse(parametros.get("fecInicio").toString()).getTime()); + fecFinal = new java.sql.Date(sdf.parse(parametros.get("fecFinal").toString()).getTime()); + empresaId = parametros.get("empresaId") != null && parametros.get("empresaId").equals("null") ? Integer.valueOf(parametros.get("empresaId").toString()) : null; + + Connection conexao = this.relatorio.getConexao(); + processarTotalPacote(conexao); + processarTotalBoletos(conexao); + + setLsDadosRelatorio(lsDadosRelatorio); + } + }); + } + + private void processarTotalPacote(Connection conexao) { + ResultSet rset = null; + NamedParameterStatement stmt = null; + + try { + String sql = getSqlPacotes(); + + log.info(sql); + + stmt = new NamedParameterStatement(conexao, sql); + + if(fecInicio != null) { + stmt.setDate("fecInicio", fecInicio); + } + if(fecFinal != null) { + stmt.setDate("fecFinal", fecFinal); + } + if (empresaId != null){ + stmt.setInt("empresaId", empresaId); + } + + rset = stmt.executeQuery(); + + if(lsDadosRelatorio == null) { + lsDadosRelatorio = new ArrayList(); + } + + while (rset.next()) { + RelatorioVendasPacotesBean relatorioVendasPacotesBean = new RelatorioVendasPacotesBean(); + relatorioVendasPacotesBean.setPacoteId(rset.getLong("pacote_id")); + relatorioVendasPacotesBean.setNompacote(rset.getString("nompacote")); + relatorioVendasPacotesBean.setTotalPacotes(rset.getBigDecimal("totalpacote")); + relatorioVendasPacotesBean.setQtdePacotes(rset.getLong("qtdepacote")); + lsDadosRelatorio.add(relatorioVendasPacotesBean); + } + + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if(rset != null) { + rset.close(); + } + if(stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + log.error(e.getMessage(), e); + } + } + + } + + private void processarTotalBoletos(Connection conexao) { + ResultSet rset = null; + NamedParameterStatement stmt = null; + + try { + String sql = getSqlBoletos(); + + log.info(sql); + + stmt = new NamedParameterStatement(conexao, sql); + + if(fecInicio != null) { + stmt.setDate("fecInicio", fecInicio); + } + if(fecFinal != null) { + stmt.setDate("fecFinal", fecFinal); + } + if (empresaId != null){ + stmt.setInt("empresaId", empresaId); + } + + rset = stmt.executeQuery(); + + if(lsDadosRelatorio == null) { + lsDadosRelatorio = new ArrayList(); + } + + while (rset.next()) { + RelatorioVendasPacotesBean relatorioVendasPacotesBean = new RelatorioVendasPacotesBean(); + relatorioVendasPacotesBean.setPacoteId(rset.getLong("pacote_id")); + relatorioVendasPacotesBean.setNompacote(rset.getString("nompacote")); + relatorioVendasPacotesBean.setTotalBoletos(rset.getBigDecimal("totalboletos")); + + if(lsDadosRelatorio.contains(relatorioVendasPacotesBean)) { + RelatorioVendasPacotesBean relatorioVendasPacotesBeanAux = lsDadosRelatorio.get(lsDadosRelatorio.indexOf(relatorioVendasPacotesBean)); + relatorioVendasPacotesBeanAux.setTotalBoletos(relatorioVendasPacotesBean.getTotalBoletos()); + } else { + lsDadosRelatorio.add(relatorioVendasPacotesBean); + } + } + + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if(rset != null) { + rset.close(); + } + if(stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + log.error(e.getMessage(), e); + } + } + + } + + private String getSqlPacotes() { + StringBuilder sQuery = new StringBuilder(); + + sQuery.append("SELECT P.PACOTE_ID, P.NOMPACOTE, COUNT(P.PACOTE_ID) AS QTDEPACOTE, SUM(VP.TOTAL) AS TOTALPACOTE ") + .append("FROM VENDA_PACOTE VP ") + .append("LEFT JOIN PACOTE P ON P.PACOTE_ID = VP.PACOTE_ID ") + .append("WHERE P.ACTIVO = 1 "); + + if(empresaId != null) { + sQuery.append("AND P.EMPRESA_ID = :empresaId "); + } + + if(fecInicio != null) { + sQuery.append("AND VP.DATAPACOTE >= :fecInicio "); + } + + if(fecFinal != null) { + sQuery.append("AND VP.DATAPACOTE <= :fecFinal "); + } + + sQuery.append("GROUP BY P.PACOTE_ID, P.NOMPACOTE "); + + return sQuery.toString(); + } + + private String getSqlBoletos() { + StringBuilder sQuery = new StringBuilder(); + + sQuery.append("SELECT P.PACOTE_ID, P.NOMPACOTE, SUM(TVP.VALOR) AS TOTALBOLETOS ") + .append("FROM VENDA_PACOTE VP ") + .append("LEFT JOIN PACOTE P ON P.PACOTE_ID = VP.PACOTE_ID ") + .append("LEFT JOIN TARIFA_VENDA_PACOTE TVP ON TVP.VENDAPACOTE_ID = VP.VENDAPACOTE_ID ") + .append("LEFT JOIN BOLETO B ON B.BOLETO_ID = TVP.BOLETO_ID ") + .append("WHERE P.ACTIVO = 1 ") + .append("AND B.ACTIVO = 1 ") + .append("AND B.INDSTATUSBOLETO = 'V' "); + + if(empresaId != null) { + sQuery.append("AND P.EMPRESA_ID = :empresaId "); + } + + if(fecInicio != null) { + sQuery.append("AND VP.DATAPACOTE >= :fecInicio "); + } + + if(fecFinal != null) { + sQuery.append("AND VP.DATAPACOTE <= :fecFinal "); + } + + sQuery.append("GROUP BY P.PACOTE_ID, P.NOMPACOTE "); + + return sQuery.toString(); + } + + @Override + protected void processaParametros() throws Exception { + } + + public List getLsDadosRelatorio() { + return lsDadosRelatorio; + } + + public void setLsDadosRelatorio(List lsDadosRelatorio) { + this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); + this.lsDadosRelatorio = lsDadosRelatorio; + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasPacotesResumido.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasPacotesResumido.jasper new file mode 100644 index 000000000..2bf1e34cf Binary files /dev/null and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasPacotesResumido.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasPacotesResumido.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasPacotesResumido.jrxml new file mode 100644 index 000000000..0d87dfc8e --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioVendasPacotesResumido.jrxml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="62" splitType="Stretch"> + <staticText> + <reportElement x="0" y="0" width="301" height="20" uuid="58b5b133-43e0-42f0-a904-5cc3645d3df3"/> + <textElement> + <font size="14" isBold="true"/> + </textElement> + <text><![CDATA[Relatório Vendas de Pacotes - Resumido]]></text> + </staticText> + <textField pattern="dd/MM/yyyy HH:mm"> + <reportElement x="391" y="0" width="164" height="20" uuid="4d1bcd65-c9a6-44b4-8dca-cc3c4c20c9a5"/> + <textElement textAlignment="Right"> + <font isBold="true"/> + </textElement> + <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> + </textField> + <textField> + <reportElement x="0" y="20" width="301" height="20" uuid="a16eb33b-78ca-4fb4-80c2-f5c85a0d09c3"/> + <textElement> + <font isBold="true"/> + </textElement> + <textFieldExpression><![CDATA["Empresa: " + $P{empresa}]]></textFieldExpression> + </textField> + <textField> + <reportElement x="0" y="40" width="301" height="20" uuid="fd05bd35-30d9-4baf-aa56-f8e5d3c3268b"/> + <textElement> + <font isBold="true"/> + </textElement> + <textFieldExpression><![CDATA["Período: " + $P{fecInicio} + " a " + $P{fecFinal}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/RelatorioVendasPacotesBean.java b/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/RelatorioVendasPacotesBean.java new file mode 100644 index 000000000..df2102246 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/RelatorioVendasPacotesBean.java @@ -0,0 +1,78 @@ +package com.rjconsultores.ventaboletos.relatorios.utilitarios; + +import java.math.BigDecimal; + +public class RelatorioVendasPacotesBean { + + private Long pacoteId; + private String nompacote; + private Long qtdePacotes; + private BigDecimal totalBoletos; + private BigDecimal totalPacotes; + + public Long getPacoteId() { + return pacoteId; + } + + public void setPacoteId(Long pacoteId) { + this.pacoteId = pacoteId; + } + + public String getNompacote() { + return nompacote; + } + + public void setNompacote(String nompacote) { + this.nompacote = nompacote; + } + + public BigDecimal getTotalBoletos() { + return totalBoletos; + } + + public void setTotalBoletos(BigDecimal totalBoletos) { + this.totalBoletos = totalBoletos; + } + + public BigDecimal getTotalPacotes() { + return totalPacotes; + } + + public void setTotalPacotes(BigDecimal totalPacotes) { + this.totalPacotes = totalPacotes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((pacoteId == null) ? 0 : pacoteId.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; + RelatorioVendasPacotesBean other = (RelatorioVendasPacotesBean) obj; + if (pacoteId == null) { + if (other.pacoteId != null) + return false; + } else if (!pacoteId.equals(other.pacoteId)) + return false; + return true; + } + + public Long getQtdePacotes() { + return qtdePacotes; + } + + public void setQtdePacotes(Long qtdePacotes) { + this.qtdePacotes = qtdePacotes; + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioVendasPacotesResumidoController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioVendasPacotesResumidoController.java new file mode 100644 index 000000000..06770f58a --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioVendasPacotesResumidoController.java @@ -0,0 +1,96 @@ +package com.rjconsultores.ventaboletos.web.gui.controladores.relatorios; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +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.Comboitem; +import org.zkoss.zul.Datebox; + +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioVendasPacotesResumido; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.service.EmpresaService; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar; +import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; + +@Controller("relatorioVendasPacotesResumidoController") +@Scope("prototype") +public class RelatorioVendasPacotesResumidoController extends MyGenericForwardComposer { + + private static final long serialVersionUID = 1L; + + @Autowired + private DataSource dataSourceRead; + + @Autowired + private EmpresaService empresaService; + + private List lsEmpresa; + private Datebox dataInicial; + private Datebox dataFinal; + private MyComboboxEstandar cmbEmpresa; + + public List getLsEmpresa() { + return lsEmpresa; + } + + public void setLsEmpresa(List lsEmpresa) { + this.lsEmpresa = lsEmpresa; + } + + @Override + public void doAfterCompose(Component comp) throws Exception { + lsEmpresa = empresaService.obtenerTodos(); + super.doAfterCompose(comp); + } + + private void executarPesquisa() { + } + + public void onClick$btnLimpar(Event ev) { + } + + public void onClick$btnPesquisa(Event ev) { + executarPesquisa(); + } + + public void onClick$btnExecutarRelatorio(Event ev) throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + Date dataDe = dataInicial.getValue(); + Date dataAte = dataFinal.getValue(); + + Map parametros = new HashMap(); + parametros.put("fecInicio", sdf.format(dataDe)); + parametros.put("fecFinal", sdf.format(dataAte)); + + Comboitem cbiEmpresa = cmbEmpresa.getSelectedItem(); + String empresaId = null; + parametros.put("empresa", ""); + if (cbiEmpresa != null) { + Empresa empresa = (Empresa) cbiEmpresa.getValue(); + empresaId = empresa.getEmpresaId().toString(); + parametros.put("empresa", empresa.getNombempresa()); + } + parametros.put("empresaId", empresaId); + + Relatorio relatorio = new RelatorioVendasPacotesResumido(parametros, dataSourceRead.getConnection()); + + Map args = new HashMap(); + args.put("relatorio", relatorio); + + openWindow("/component/reportView.zul", + Labels.getLabel("relatorioVendasPacotesResumidoController.window.title"), args, MODAL); + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioVendasPacotesResumido.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioVendasPacotesResumido.java new file mode 100644 index 000000000..4c242bf91 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioVendasPacotesResumido.java @@ -0,0 +1,32 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.web.utilerias.menu.item.relatorios; + +import org.zkoss.util.resource.Labels; + +import com.rjconsultores.ventaboletos.web.utilerias.PantallaUtileria; +import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema; + +/** + * @author Wilian Domingues + * + */ +public class ItemMenuRelatorioVendasPacotesResumido extends DefaultItemMenuSistema { + + public ItemMenuRelatorioVendasPacotesResumido() { + super("indexController.mniRelatorioVendasPacotesResumido.label"); + } + + @Override + public String getClaveMenu() { + return "COM.RJCONSULTORES.ADMINISTRACION.GUI.RELATORIOS.MENU.RELATORIOVENDASPACOTESRESUMIDO"; + } + + @Override + public void ejecutar() { + PantallaUtileria.openWindow("/gui/relatorios/filtroRelatorioVendasPacotesResumido.zul", + Labels.getLabel("relatorioVendasPacotesResumidoController.window.title"), getArgs() ,desktop); + } + +} diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index 6c0d9a6fe..a85468136 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -241,6 +241,7 @@ indexController.mniFechamentoParamptovta.label = Fechamento Conta Corrente Agên indexController.mniRelatorioCorridas.label = Reporte de Corridas indexController.mniRelatorioDemandas.label = Reporte de Demandas indexController.mniPrecoApanhe.label = Preço Apanhe +indexController.mniRelatorioVendasPacotesResumido.label = Ventas de Paquetes Resumido indexController.mniSubMenuClientePacote.label=Pacote indexController.mniAlterarEnderecoApanhe.label=Alterar Endereço Apanhe @@ -5263,4 +5264,10 @@ editarAlterarEnderecoApanheController.lhCep.label = Cep editarAlterarEnderecoApanheController.lhEndereco.label = Logradouro editarAlterarEnderecoApanheController.lhReferencia.label = Referencia editarAlterarEnderecoApanheController.lhNumoperacion.label = Num Operacion -editarAlterarEnderecoApanheController.lhDataPacote.label = Fecha Pacote \ No newline at end of file +editarAlterarEnderecoApanheController.lhDataPacote.label = Fecha Pacote + +# Relatorio Vendas Pacotes Resumido +relatorioVendasPacotesResumidoController.window.title = Relatório Vendas de Pacotes Resumido +relatorioVendasPacotesResumidoController.lbDataIni.value = Fecha Inicio +relatorioVendasPacotesResumidoController.lbDataFin.value = Fecha Final +relatorioVendasPacotesResumidoController.lblEmpresa.value = Empresa \ No newline at end of file diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index 7f803afaa..addbdd690 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -246,6 +246,7 @@ indexController.mniRelatorioCorridas.label = Relatório de Serviços indexController.mniRelatorioCorridas.label = Relatório de Serviços indexController.mniRelatorioDemandas.label = Relatório de Demandas indexController.mniPrecoApanhe.label = Preço Apanhe +indexController.mniRelatorioVendasPacotesResumido.label = Vendas de Pacotes Resumido indexController.mnSubMenuImpressaoFiscal.label=Impressão Fiscal indexController.mniTotnaofiscalEmpresa.label=Totalizadoes Não-fiscais @@ -5390,4 +5391,10 @@ editarAlterarEnderecoApanheController.lhCep.label = Cep editarAlterarEnderecoApanheController.lhEndereco.label = Logradouro editarAlterarEnderecoApanheController.lhReferencia.label = Referência editarAlterarEnderecoApanheController.lhNumoperacion.label = Localizador -editarAlterarEnderecoApanheController.lhDataPacote.label = Data Pacote \ No newline at end of file +editarAlterarEnderecoApanheController.lhDataPacote.label = Data Pacote + +# Relatorio Vendas Pacotes Resumido +relatorioVendasPacotesResumidoController.window.title = Relatório Vendas de Pacotes Resumido +relatorioVendasPacotesResumidoController.lbDataIni.value = Data Inicial +relatorioVendasPacotesResumidoController.lbDataFin.value = Data Final +relatorioVendasPacotesResumidoController.lblEmpresa.value = Empresa \ No newline at end of file diff --git a/web/gui/relatorios/filtroRelatorioVendasPacotesResumido.zul b/web/gui/relatorios/filtroRelatorioVendasPacotesResumido.zul new file mode 100644 index 000000000..20a4ddf54 --- /dev/null +++ b/web/gui/relatorios/filtroRelatorioVendasPacotesResumido.zul @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + +