From d54b17790d4a7ce561784c54c47a3b7ec99a3bc2 Mon Sep 17 00:00:00 2001 From: "alexandre.lima" Date: Thu, 20 Jul 2017 11:30:25 +0000 Subject: [PATCH] Fixes Bug #0009366 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@71604 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/FormaPagamentoAgenciaDAO.java | 12 +++ .../FormaPagamentoAgenciaDAOImpl.java | 79 +++++++++++++++++ .../ventaboletos/entidad/ParadaSecuencia.java | 8 ++ .../service/FormaPagamentoAgenciaService.java | 12 +++ .../FormaPagamentoAgenciaServiceImpl.java | 85 +++++++++++++++++++ .../service/impl/TramoRutaServiceImpl.java | 2 +- .../impressaofiscal/RelatorioFinanceiro.java | 63 ++++++++++++++ 7 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 src/com/rjconsultores/ventaboletos/dao/FormaPagamentoAgenciaDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/FormaPagamentoAgenciaDAOImpl.java create mode 100644 src/com/rjconsultores/ventaboletos/service/FormaPagamentoAgenciaService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/FormaPagamentoAgenciaServiceImpl.java create mode 100644 src/com/rjconsultores/ventaboletos/vo/impressaofiscal/RelatorioFinanceiro.java diff --git a/src/com/rjconsultores/ventaboletos/dao/FormaPagamentoAgenciaDAO.java b/src/com/rjconsultores/ventaboletos/dao/FormaPagamentoAgenciaDAO.java new file mode 100644 index 000000000..d197f466b --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/FormaPagamentoAgenciaDAO.java @@ -0,0 +1,12 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.dao; + +/** + * + * @author Administrador + */ +public interface FormaPagamentoAgenciaDAO extends GenericDAOInforme { +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FormaPagamentoAgenciaDAOImpl.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FormaPagamentoAgenciaDAOImpl.java new file mode 100644 index 000000000..30121ad3d --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FormaPagamentoAgenciaDAOImpl.java @@ -0,0 +1,79 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Date; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Repository; + +import com.rjconsultores.ventaboletos.dao.FormaPagamentoAgenciaDAO; + +/** + * + * @author Administrador + */ +@Repository("formaPagamentoAgenciaDAO") +public class FormaPagamentoAgenciaDAOImpl implements FormaPagamentoAgenciaDAO { + + private static final Logger log = Logger.getLogger(FormaPagamentoAgenciaDAOImpl.class); + + private String getSql(Date dataInicio, Date dataFinal) { + StringBuilder where = new StringBuilder(); + where.append(" WHERE 1 = 1 "); + + if (dataInicio != null) { + where.append(" AND c.fechorventa >= ? "); + } + + if (dataFinal != null) { + where.append(" AND c.fechorventa <= ? "); + } + + StringBuilder sql = new StringBuilder(); + sql.append(" select to_char(c.fechorventa, 'dd/mm/yyyy') as data, "); + sql.append(" pv.PUNTOVENTA_ID as agencia, "); + sql.append(" fp.DESCPAGO as forma_pagamento, "); + sql.append(" sum(nvl(c.PRECIOPAGADO,0)) as tarifa, "); + sql.append(" sum(nvl(c.IMPORTEPEDAGIO,0)) as pedagio, "); + sql.append(" sum(nvl(c.IMPORTESEGURO,0)) as seguro, "); + sql.append(" sum(nvl(c.IMPORTETAXAEMBARQUE,0)) as taxa, "); + sql.append(" sum((c.PRECIOPAGADO + c.IMPORTEPEDAGIO + c.IMPORTESEGURO + c.IMPORTETAXAEMBARQUE)) as total, "); + sql.append(" count(c.PRECIOPAGADO) as qtde "); + sql.append(" from caja c "); + sql.append(" join caja_formapago cfp on c.caja_id = cfp.caja_id "); + sql.append(" join forma_pago fp on cfp.formapago_id = fp.formapago_id "); + sql.append(" join punto_venta pv on pv.PUNTOVENTA_ID = c.PUNTOVENTA_ID "); + sql.append(where); + sql.append(" group by to_char(c.fechorventa, 'dd/mm/yyyy'), pv.PUNTOVENTA_ID, fp.DESCPAGO "); + sql.append(" order by data, agencia, forma_pagamento"); + + return sql.toString(); + } + + public ResultSet executarSQL(Connection conn, Map parameters) { + Date dataInicio = (Date) parameters.get("dataInicio"); + Date dataFinal = (Date) parameters.get("dataFinal"); + String sql = getSql(dataInicio, dataFinal); + + PreparedStatement stmt = null; + ResultSet rset = null; + + try { + stmt = conn.prepareStatement(sql); + stmt.setDate(1, new java.sql.Date(dataInicio.getTime())); + stmt.setDate(2, new java.sql.Date(dataFinal.getTime())); + rset = stmt.executeQuery(); + } catch (Exception ex) { + log.error(ex); + } + + return rset; + } +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/ParadaSecuencia.java b/src/com/rjconsultores/ventaboletos/entidad/ParadaSecuencia.java index 0e111af69..892fbab94 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/ParadaSecuencia.java +++ b/src/com/rjconsultores/ventaboletos/entidad/ParadaSecuencia.java @@ -20,6 +20,14 @@ public class ParadaSecuencia { private String kmReal = ""; private String kmEntradaSaida = ""; private String tempoReal = ""; + + @Override + public String toString() { + if (parada != null) { + return parada.toString(); + } + return super.toString(); + } public ParadaSecuencia() { } diff --git a/src/com/rjconsultores/ventaboletos/service/FormaPagamentoAgenciaService.java b/src/com/rjconsultores/ventaboletos/service/FormaPagamentoAgenciaService.java new file mode 100644 index 000000000..259898174 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/FormaPagamentoAgenciaService.java @@ -0,0 +1,12 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service; + +/** + * + * @author Administrador + */ +public interface FormaPagamentoAgenciaService extends GenericServiceInforme { +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/FormaPagamentoAgenciaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/FormaPagamentoAgenciaServiceImpl.java new file mode 100644 index 000000000..18d902bf8 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/FormaPagamentoAgenciaServiceImpl.java @@ -0,0 +1,85 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service.impl; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.zkoss.util.media.AMedia; + +import com.rjconsultores.ventaboletos.dao.FormaPagamentoAgenciaDAO; +import com.rjconsultores.ventaboletos.exception.BusinessException; +import com.rjconsultores.ventaboletos.service.FormaPagamentoAgenciaService; + +import net.sf.jasperreports.engine.JRDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRResultSetDataSource; +import net.sf.jasperreports.engine.JasperRunManager; + +/** + * + * @author Administrador + */ +@Service("formaPagamentoAgenciaService") +public class FormaPagamentoAgenciaServiceImpl implements FormaPagamentoAgenciaService { + + @Autowired + private FormaPagamentoAgenciaDAO financeiroDAO; + @Autowired + private DataSource dataSource; + private static final Logger log = Logger.getLogger(FormaPagamentoAgenciaServiceImpl.class); + + public AMedia gerarInforme(InputStream informe, Map parameters) throws BusinessException { + Connection conn = null; + AMedia amedia = null; + + try { + conn = dataSource.getConnection(); + + ResultSet rs = financeiroDAO.executarSQL(conn, parameters); + JRDataSource jrDataSource = new JRResultSetDataSource(rs); + + Date dataInicio = (Date) parameters.get("dataInicio"); + Date dataFinal = (Date) parameters.get("dataFinal"); + Map args = new HashMap(); + args.put("dataInicio", dataInicio); + args.put("dataFinal", dataFinal); + final byte[] buf = JasperRunManager.runReportToPdf(informe, args, jrDataSource); + + final InputStream mediais = new ByteArrayInputStream(buf); + + amedia = new AMedia("financeiro.pdf", "pdf", null, mediais); + } catch (JRException e) { + log.error("Erro al generar reporte", e); + throw new BusinessException("MSG.Error"); + } catch (SQLException e) { + log.error("Error al obtener una conexcion en el datasource", e); + throw new BusinessException("MSG.Error"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + log.error("Error al cerrar la conexion", e); + } + } + } + + return amedia; + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java index c6f79ac9c..8d74466cf 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/TramoRutaServiceImpl.java @@ -466,7 +466,7 @@ public class TramoRutaServiceImpl implements TramoRutaService { for (ParadaSecuencia secuenciaDestino : secuenciasDestino) { //O processo não é realizado na ordem inversa (em que a sequencia da origem é maior que a sequencia de seus destinos), considerando que esse é o processo inversa a ida ou a volta. - if (secuencia.getOrigem().getSecuencia() > secuenciaDestino.getSecuencia()){ + if (secuencia.getOrigem().getSecuencia() >= secuenciaDestino.getSecuencia()){ continue; } diff --git a/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/RelatorioFinanceiro.java b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/RelatorioFinanceiro.java new file mode 100644 index 000000000..5c9c85bc6 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/vo/impressaofiscal/RelatorioFinanceiro.java @@ -0,0 +1,63 @@ +package com.rjconsultores.ventaboletos.vo.impressaofiscal; + +import java.util.Date; + +public class RelatorioFinanceiro { + + private Date data; + private String agencia; + private String formaPagamento; + private Double tarifa; + private Double pedagio; + private Double seguro; + private Double taxas; + private Double total; + public Date getData() { + return data; + } + public void setData(Date data) { + this.data = data; + } + public String getAgencia() { + return agencia; + } + public void setAgencia(String agencia) { + this.agencia = agencia; + } + public String getFormaPagamento() { + return formaPagamento; + } + public void setFormaPagamento(String formaPagamento) { + this.formaPagamento = formaPagamento; + } + public Double getTarifa() { + return tarifa; + } + public void setTarifa(Double tarifa) { + this.tarifa = tarifa; + } + public Double getPedagio() { + return pedagio; + } + public void setPedagio(Double pedagio) { + this.pedagio = pedagio; + } + public Double getSeguro() { + return seguro; + } + public void setSeguro(Double seguro) { + this.seguro = seguro; + } + public Double getTaxas() { + return taxas; + } + public void setTaxas(Double taxas) { + this.taxas = taxas; + } + public Double getTotal() { + return total; + } + public void setTotal(Double total) { + this.total = total; + } +}