diff --git a/pom.xml b/pom.xml
index 5815e5ac3..34bd90dc2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
br.com.rjconsultores
ModelWeb
- 1.89.0
+ 1.90.0
diff --git a/src/com/rjconsultores/ventaboletos/anotacao/Renderizado.java b/src/com/rjconsultores/ventaboletos/anotacao/Renderizado.java
index 1d8c74109..cd6625385 100644
--- a/src/com/rjconsultores/ventaboletos/anotacao/Renderizado.java
+++ b/src/com/rjconsultores/ventaboletos/anotacao/Renderizado.java
@@ -5,13 +5,37 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-@Target(ElementType.FIELD)
+/**
+ * Anotação para marcar campos que devem ser renderizados e utilizados no Render Padrão {@link RenderPadrao}.
+ *
+ * A anotação permite configurar um conversor personalizado e especificar a posição de ordenação dos campos.
+ */
+@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface Renderizado{
- Class extends Enum>> conversor() default DefaultEnum.class;
-
- String metodoConversor() default "buscarPeloValor";
-
- enum DefaultEnum{
- }
+public @interface Renderizado {
+
+ /**
+ * Define a classe do conversor que será usado para converter o valor do campo.
+ *
+ * @return A classe Enum do conversor que deve obrigatoriamente
+ * implementar o um metodo String buscarPeloValor( String valor).
+ */
+ Class extends Enum>> conversor() default DefaultEnum.class;
+
+ /**
+ * Define o nome do método do conversor que será chamado para converter o valor do campo.
+ *
+ * @return O nome do método do conversor. O padrão é "buscarPeloValor".
+ */
+ String metodoConversor() default "buscarPeloValor";
+
+ /**
+ * Define a posição de ordenação do campo. Campos com valores menores são ordenados primeiro.
+ *
+ * @return A posição numerica de ordenação do campo .
+ */
+ int posicao() default Integer.MAX_VALUE;
+
+ enum DefaultEnum {
+ }
}
\ No newline at end of file
diff --git a/src/com/rjconsultores/ventaboletos/dao/VoucherDAO.java b/src/com/rjconsultores/ventaboletos/dao/VoucherDAO.java
new file mode 100644
index 000000000..60714e5a7
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/dao/VoucherDAO.java
@@ -0,0 +1,12 @@
+package com.rjconsultores.ventaboletos.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import com.rjconsultores.ventaboletos.entidad.Voucher;
+
+public interface VoucherDAO extends GenericDAO {
+
+ public List buscarConsulta(Long voucherId, String numContrato, String nit, String nomeTransportadora, Date dataInicial, Date dataFinal, Integer origemId, Integer destinoId);
+
+}
diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java
index ef40c23d4..bf70a4d48 100644
--- a/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java
+++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/GenericHibernateDAO.java
@@ -7,10 +7,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import com.rjconsultores.ventaboletos.dao.GenericDAO;
-
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
+import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Projections;
@@ -24,6 +23,8 @@ import org.hibernate.loader.criteria.CriteriaLoader;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+import com.rjconsultores.ventaboletos.dao.GenericDAO;
+
/**
*
* @author gleimar
diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/VoucherHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/VoucherHibernateDAO.java
new file mode 100644
index 000000000..d74c0a2e6
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/VoucherHibernateDAO.java
@@ -0,0 +1,165 @@
+package com.rjconsultores.ventaboletos.dao.hibernate;
+
+import java.util.Date;
+import java.util.List;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Restrictions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Repository;
+
+import com.rjconsultores.ventaboletos.dao.VoucherDAO;
+import com.rjconsultores.ventaboletos.entidad.Voucher;
+
+@SuppressWarnings("unchecked")
+@Repository("voucherDAO")
+public class VoucherHibernateDAO extends GenericHibernateDAO implements VoucherDAO {
+
+ @Autowired
+ public VoucherHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
+ setSessionFactory(factory);
+ }
+
+ @Override
+ public List obtenerTodos() {
+ Criteria c = getSession().createCriteria(getPersistentClass());
+ c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
+
+ return c.list();
+ }
+
+ @Override
+ public List buscarConsulta(Long voucherId,
+ String numContrato,
+ String nit,
+ String nomeTransportadora,
+ Date dataInicial,
+ Date dataFinal,
+ Integer origemId,
+ Integer destinoId) {
+
+ StringBuilder hql = new StringBuilder();
+ hql.append("SELECT v, ori.descParada AS descOrigem , des.descParada AS descDestino ");
+ hql.append("FROM Voucher v ");
+
+ setJoins( numContrato,
+ nit,
+ nomeTransportadora,
+ hql);
+
+ hql.append("WHERE v.activo = 1 ");
+
+ setClausulas(voucherId,
+ numContrato,
+ nit,
+ nomeTransportadora,
+ dataInicial,
+ dataFinal,
+ origemId,
+ destinoId,
+ hql);
+
+ hql.append("ORDER BY voucherId ");
+
+ Query query = getSession().createQuery(hql.toString());
+
+ setParametros(voucherId,
+ numContrato,
+ nit,
+ nomeTransportadora,
+ dataInicial,
+ dataFinal,
+ origemId,
+ destinoId,
+ query);
+
+ return query.list();
+ }
+
+ private void setJoins(String numContrato, String nit, String nomeTransportadora, StringBuilder hql) {
+ hql.append("LEFT JOIN Parada ori ON v.origenId = ori.origenId ");
+ hql.append("LEFT JOIN Parada des ON v.origenId = des.origenId ");
+
+ }
+
+ private void setClausulas(Long voucherId, String numContrato, String nit, String nomeTransportadora,
+ Date dataInicial, Date dataFinal, Integer origemId, Integer destinoId, StringBuilder hql) {
+ if(voucherId != null ){
+ hql.append(" AND v.voucherId = :voucherId ");
+ }
+
+ if(numContrato != null ){
+ hql.append(" AND v.voucherId = :voucherId ");
+ }
+
+ if(nit != null ){
+ hql.append(" AND v.voucherId = :voucherId ");
+ }
+
+ if(nomeTransportadora != null ){
+ hql.append(" AND v.voucherId = :voucherId ");
+ }
+
+ if(dataInicial != null ){
+ hql.append(" AND v.dataValidade >= :dataInicial ");
+ }
+
+ if(dataFinal != null ){
+ hql.append(" AND v.dataValidade <= :dataFinal ");
+ }
+
+ if(origemId != null ){
+ hql.append(" AND v.origenId = :origemId ");
+ }
+
+ if(destinoId != null ){
+ hql.append(" AND v.destinoId = :destinoId ");
+ }
+ }
+
+ private void setParametros(Long voucherId,
+ String numContrato,
+ String nit,
+ String nomeTransportadora,
+ Date dataInicial,
+ Date dataFinal,
+ Integer origemId,
+ Integer destinoId,
+ Query query) {
+
+ if(voucherId != null ){
+ query.setLong("voucherId", voucherId);
+ }
+
+ if(numContrato != null ){
+ query.setString("numContrato", numContrato);
+ }
+
+ if(nit != null ){
+ query.setString("nit", nit);
+ }
+
+ if(nomeTransportadora != null ){
+ query.setString("nomeTransportadora", nomeTransportadora);
+ }
+
+ if(dataInicial != null ){
+ query.setDate("dataInicial", dataInicial);
+ }
+
+ if(dataFinal != null ){
+ query.setDate("dataFinal", dataFinal);
+ }
+
+ if(origemId != null ){
+ query.setInteger("origemId", origemId);
+ }
+
+ if(destinoId != null ){
+ query.setInteger("destinoId", destinoId);
+ }
+ }
+}
diff --git a/src/com/rjconsultores/ventaboletos/entidad/ContratoCorporativo.java b/src/com/rjconsultores/ventaboletos/entidad/ContratoCorporativo.java
index 0d8e9a042..aa6139183 100644
--- a/src/com/rjconsultores/ventaboletos/entidad/ContratoCorporativo.java
+++ b/src/com/rjconsultores/ventaboletos/entidad/ContratoCorporativo.java
@@ -165,5 +165,10 @@ public class ContratoCorporativo implements Serializable {
hash = 59 * hash + (this.getContratoId() != null ? this.getContratoId().hashCode() : 0);
return hash;
}
+
+ @Override
+ public String toString() {
+ return this.getContratoId().toString();
+ }
}
\ No newline at end of file
diff --git a/src/com/rjconsultores/ventaboletos/entidad/Transportadora.java b/src/com/rjconsultores/ventaboletos/entidad/Transportadora.java
index b56f83f9d..7faaee1cc 100644
--- a/src/com/rjconsultores/ventaboletos/entidad/Transportadora.java
+++ b/src/com/rjconsultores/ventaboletos/entidad/Transportadora.java
@@ -61,5 +61,13 @@ public class Transportadora implements Serializable{
@Column(name = "FECMODIF")
@Temporal(TemporalType.TIMESTAMP)
private Date fecModif;
-
+
+ @Override
+ public String toString() {
+ return nomeTransportadora;
+ }
+
+ public Transportadora(String nomeTransportadora) {
+ this.nomeTransportadora = nomeTransportadora;
+ }
}
\ No newline at end of file
diff --git a/src/com/rjconsultores/ventaboletos/entidad/Voucher.java b/src/com/rjconsultores/ventaboletos/entidad/Voucher.java
new file mode 100644
index 000000000..5c41f4300
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/entidad/Voucher.java
@@ -0,0 +1,144 @@
+package com.rjconsultores.ventaboletos.entidad;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import com.rjconsultores.ventaboletos.anotacao.Renderizado;
+import com.rjconsultores.ventaboletos.enums.SituacaoVoucher;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@SequenceGenerator(name = "VOUCHER_SEQ", sequenceName = "VOUCHER_SEQ", allocationSize = 1)
+@Table(name = "VOUCHER")
+public class Voucher implements Serializable {
+
+ private static final long serialVersionUID = -3684489881654368314L;
+
+ @Id
+ @Basic(optional = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "VOUCHER_SEQ")
+ @Renderizado( posicao = 1)
+ @Column(name = "VOUCHER_ID")
+ private Long voucherId;
+
+ @OneToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "CONTRATO_ID")
+ @Renderizado( posicao = 2)
+ private ContratoCorporativo contrato;
+
+ @Column(name = "NOME_PASSAGEIRO", length = 150)
+ private String nomePassageiro;
+
+ @Column(name = "NUM_FATURA", length = 30)
+ private String numFatura;
+
+ @Column(name = "VALOR_LICITADO")
+ @Renderizado( posicao = 5 )
+ private BigDecimal valorLicitado;
+
+ @Renderizado( posicao = 6)
+ @Column(name = "VALOR_LEGALIZADO")
+ private BigDecimal valorLegalizado;
+
+ @Renderizado( posicao = 4)
+ @Column(name = "DATA_VALIDADE")
+ private Date dataValidade;
+
+ @Column(name = "DATA_INCLUSAO")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date dataInclusao;
+
+ @Column(name = "ORIGEN_ID")
+ private Integer origenId;
+
+ @Column(name = "DESTINO_ID")
+ private Integer destinoId;
+
+ @Column(name = "CLASESERVICIO_ID")
+ private Long claseServicioId;
+
+ @Column(name = "STATUS")
+ @Renderizado( conversor = SituacaoVoucher.class, posicao = 3)
+ private Integer status;
+
+ @Column(name = "CLIENTECORPORATIVO_ID")
+ private Long clienteCorporativoId;
+
+ @Column(name = "MOTIVOCANCELACION_ID")
+ private Long motivoCancelacionId;
+
+ @Column(name = "GRUPOCONTRATO_ID")
+ private Long grupoContratoId;
+
+ @OneToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "TRANSPORTADORA_ID")
+ private Transportadora transportadora;
+
+ @Column(name = "ACTIVO")
+ private boolean activo;
+
+ @Column(name = "FECMODIF")
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date fecModif;
+
+ @Column(name = "USUARIO_ID")
+ private Integer usuarioId;
+
+ @Transient
+ @Renderizado( posicao = 7 )
+ private transient String descOrigem;
+
+ @Transient
+ @Renderizado( posicao = 8 )
+ private String descDestino;
+
+ public SituacaoVoucher getSituacaoVoucher() {
+ return SituacaoVoucher.buscarPeloValor(status);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final Voucher other = (Voucher) obj;
+ return this.getVoucherId().equals(other.getVoucherId());
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 59 * hash + (this.getVoucherId() != null ? this.getVoucherId().hashCode() : 0);
+ return hash;
+ }
+
+}
diff --git a/src/com/rjconsultores/ventaboletos/enums/SituacaoVoucher.java b/src/com/rjconsultores/ventaboletos/enums/SituacaoVoucher.java
new file mode 100644
index 000000000..063cfdd97
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/enums/SituacaoVoucher.java
@@ -0,0 +1,47 @@
+package com.rjconsultores.ventaboletos.enums;
+
+import org.zkoss.util.resource.Labels;
+
+public enum SituacaoVoucher {
+
+ EMITIDO(0,Labels.getLabel("label.situacaoVoucher.emitido")),
+ LEGALIZADO(1,Labels.getLabel("label.situacaoVoucher.legalizado")),
+ FATURADO(2,Labels.getLabel("label.situacaoVoucher.faturado")),
+ CANCELADO(3,Labels.getLabel("label.situacaoVoucher.cancelado")),
+ ;
+
+ private Integer valor;
+ private String descricao;
+
+ private SituacaoVoucher(Integer valor, String descricao) {
+ this.valor = valor;
+ this.descricao = descricao;
+ }
+
+ public String getDescricao() {
+ return descricao;
+ }
+
+ @Override
+ public String toString() {
+ return getDescricao();
+ }
+
+ public Integer getValor() {
+ return valor;
+ }
+
+ public static SituacaoVoucher buscarPeloValor(Integer valor) {
+
+ for (SituacaoVoucher tipo : SituacaoVoucher.values()) {
+ if (tipo.getValor().equals(valor)) {
+ return tipo;
+ }
+ }
+ return null;
+ }
+
+ public static SituacaoVoucher buscarPeloValor(String valor) {
+ return buscarPeloValor( Integer.valueOf(valor));
+ }
+}
diff --git a/src/com/rjconsultores/ventaboletos/enums/TipoLancamentoCaixa.java b/src/com/rjconsultores/ventaboletos/enums/TipoLancamentoCaixa.java
index ad52b132b..429f505fa 100644
--- a/src/com/rjconsultores/ventaboletos/enums/TipoLancamentoCaixa.java
+++ b/src/com/rjconsultores/ventaboletos/enums/TipoLancamentoCaixa.java
@@ -11,6 +11,7 @@ public enum TipoLancamentoCaixa {
BILHETE_CONFIRMADO(4,Labels.getLabel("label.tipoLancamento.bilheteConfirmado"), false),
BILHETE_ABERTO(5,Labels.getLabel("label.tipoLancamento.bilheteAberto"), false),
EVENTO_EXTRA(6,Labels.getLabel("label.tipoLancamento.eventoExtra"), false),
+ VOUCHER(7,Labels.getLabel("label.tipoLancamento.voucher"), false),
;
private Integer valor;
diff --git a/src/com/rjconsultores/ventaboletos/service/ConvenioTransportadoraService.java b/src/com/rjconsultores/ventaboletos/service/ConvenioTransportadoraService.java
index f6496db1f..b4978c2f1 100644
--- a/src/com/rjconsultores/ventaboletos/service/ConvenioTransportadoraService.java
+++ b/src/com/rjconsultores/ventaboletos/service/ConvenioTransportadoraService.java
@@ -8,7 +8,7 @@ import com.rjconsultores.ventaboletos.exception.BusinessException;
public interface ConvenioTransportadoraService extends GenericService {
- ConvenioTransportadora buscarPelaTransportadoraId(Long transportadoraId);
+ public ConvenioTransportadora buscarPelaTransportadoraId(Long transportadoraId);
public ConvenioTransportadora suscribirActualizar(ConvenioTransportadora convenio) throws BusinessException;
diff --git a/src/com/rjconsultores/ventaboletos/service/VoucherService.java b/src/com/rjconsultores/ventaboletos/service/VoucherService.java
new file mode 100644
index 000000000..83942c652
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/service/VoucherService.java
@@ -0,0 +1,12 @@
+package com.rjconsultores.ventaboletos.service;
+
+import java.util.Date;
+import java.util.List;
+
+import com.rjconsultores.ventaboletos.entidad.Voucher;
+
+public interface VoucherService extends GenericService {
+
+ List buscarConsulta(Long voucherId, String numContrato, String nit, String nomeTransportadora, Date dataInicial, Date dataFinal, Integer origemId, Integer destinoId);
+
+}
diff --git a/src/com/rjconsultores/ventaboletos/service/impl/VoucherServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/VoucherServiceImpl.java
new file mode 100644
index 000000000..e23f380e2
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/service/impl/VoucherServiceImpl.java
@@ -0,0 +1,75 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.rjconsultores.ventaboletos.service.impl;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.rjconsultores.ventaboletos.dao.VoucherDAO;
+import com.rjconsultores.ventaboletos.entidad.Voucher;
+import com.rjconsultores.ventaboletos.service.VoucherService;
+import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
+
+@Service("voucherService")
+public class VoucherServiceImpl implements VoucherService {
+
+ @Autowired
+ private VoucherDAO voucherDAO;
+
+ public List obtenerTodos() {
+ return voucherDAO.obtenerTodos();
+ }
+
+ public Voucher obtenerID(Long id) {
+ return voucherDAO.obtenerID(id);
+ }
+
+ @Transactional
+ public Voucher suscribir(Voucher entidad) {
+ entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
+ entidad.setFecModif(Calendar.getInstance().getTime());
+ entidad.setActivo(Boolean.TRUE);
+
+ return voucherDAO.suscribir(entidad);
+ }
+
+ @Transactional
+ public Voucher actualizacion(Voucher entidad) {
+ return voucherDAO.actualizacion(entidad);
+ }
+
+ @Transactional
+ public void borrar(Voucher entidad) {
+ entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
+ entidad.setFecModif(Calendar.getInstance().getTime());
+ entidad.setActivo(Boolean.FALSE);
+
+ voucherDAO.actualizacion(entidad);
+ }
+
+ @Override
+ public List buscarConsulta(Long voucherId,
+ String numContrato,
+ String nit,
+ String nomeTransportadora,
+ Date dataInicial,
+ Date dataFinal,
+ Integer origemId,
+ Integer destinoId) {
+ return voucherDAO.buscarConsulta(voucherId,
+ numContrato,
+ nit,
+ nomeTransportadora,
+ dataInicial,
+ dataFinal,
+ origemId,
+ destinoId);
+ }
+}