Subversion Repositories Integrator Subversion

Rev

Blame | Last modification | View Log | Download | RSS feed

package br.com.ec.domain.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ForeignKey;

import br.com.ec.core.util.VerificadorUtil;

@Entity
@Table(name="sec_venda_formapagament", schema="sc_sec")
public class VendaFormaPagamento implements Serializable {

        private static final long serialVersionUID = 1L;

        private Long sequencial;
       
        private Venda venda;
        private FormaPagamento formaPagamento;
        private BandeiraCartao bandeiraCartao;
        private Cupom cupom;
        private Double valorPagamento;
       
        public VendaFormaPagamento() {}
       
        public VendaFormaPagamento(FormaPagamento formaPagamento) {  
        this.formaPagamento = formaPagamento;  
    }
       
        public VendaFormaPagamento(Venda venda, FormaPagamento formaPagamento) {  
        this.venda = venda;
        this.formaPagamento = formaPagamento;
    }
       
        public VendaFormaPagamento(Venda venda, FormaPagamento formaPagamento, BandeiraCartao bandeiraCartao) {  
        this.venda = venda;
        this.formaPagamento = formaPagamento;
        this.bandeiraCartao = bandeiraCartao;
    }
       
        @Id
        @SequenceGenerator(name = "sq_vendaformapagament")
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name="seq_vendaformapagament", nullable=false)
        public Long getSequencial() {
                return sequencial;
        }
        public void setSequencial(Long sequencial) {
                this.sequencial = sequencial;
        }
       
        @ManyToOne
        @ForeignKey(name="fk_vendaformapag_venda")
        @JoinColumn(name = "seq_venda", nullable=false)
        public Venda getVenda() {
                return venda;
        }
        public void setVenda(Venda venda) {
                this.venda = venda;
        }
       
        @ManyToOne
        @ForeignKey(name="fk_vendaformapag_formapagament")
        @JoinColumn(name = "cod_formapagament", nullable=false)
        public FormaPagamento getFormaPagamento() {
                return formaPagamento;
        }
        public void setFormaPagamento(FormaPagamento formaPagamento) {
                this.formaPagamento = formaPagamento;
        }
       
        @ManyToOne
        @ForeignKey(name="fk_vendaformapag_bandeiracartao")
        @JoinColumn(name = "cod_bandeira_cartao", nullable=false)
        public BandeiraCartao getBandeiraCartao() {
                return bandeiraCartao;
        }
        public void setBandeiraCartao(BandeiraCartao bandeiraCartao) {
                this.bandeiraCartao = bandeiraCartao;
        }
       
        @ManyToOne
        @ForeignKey(name="fk_vendaformapag_cupom")
        @JoinColumn(name = "seq_cupom", nullable=false)
        public Cupom getCupom() {
                return cupom;
        }
        public void setCupom(Cupom cupom) {
                this.cupom = cupom;
        }
       
        @Column(name="val_pagamento", nullable=false)
        public Double getValorPagamento() {
                return valorPagamento;
        }
        public void setValorPagamento(Double valorPagamento) {
                this.valorPagamento = valorPagamento;
        }

        @Transient
        public Long getSequencialDaVenda() {
                return VerificadorUtil.naoEstaNulo(getVenda())? getVenda().getSequencial() : null;
        }

        @Transient
        public Long getCodigoDaFormaPagamento() {
                return VerificadorUtil.naoEstaNulo(getFormaPagamento())? getFormaPagamento().getCodigo() : null;
        }
       
        @Transient
        public Long getCodigoDaBandeiraCartao() {
                return VerificadorUtil.naoEstaNulo(getBandeiraCartao())? getBandeiraCartao().getCodigo() : null;
        }
       
        @Transient
        public String getDescricaoDaBandeiraCartao() {
                return VerificadorUtil.naoEstaNulo(getBandeiraCartao())? getBandeiraCartao().getDescricao() : null;
        }

        @Transient
        public EmpresaAdquirente getEmpresaAdquirenteDaMaquinetaDaVenda() {
                return VerificadorUtil.naoEstaNulo(getVenda().getMaquineta()) ? getVenda().getMaquineta().getEmpresaAdquirente() : null;
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((sequencial == null) ? 0 : sequencial.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;
                VendaFormaPagamento other = (VendaFormaPagamento) obj;
                if (sequencial == null) {
                        if (other.sequencial != null)
                                return false;
                } else if (!sequencial.equals(other.sequencial))
                        return false;
                return true;
        }
       
}