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_conta_forma_pagamento", schema="sc_sec")
public class ContaFormaPagamento implements Serializable {

        private static final long serialVersionUID = 1L;

        private Long sequencial;
       
        private FormaPagamento formaPagamento;
        private BandeiraCartao bandeiraCartao;
        private Double valorPagamento;
       
        public ContaFormaPagamento() {}
       
        public ContaFormaPagamento(FormaPagamento formaPagamento, BandeiraCartao bandeiraCartao) {  
        this.formaPagamento = formaPagamento;
        this.bandeiraCartao = bandeiraCartao;
    }
       
        public ContaFormaPagamento(VendaFormaPagamento vendaFormaPagamento) {  
        this.formaPagamento = vendaFormaPagamento.getFormaPagamento();
        this.bandeiraCartao = vendaFormaPagamento.getBandeiraCartao();
        this.valorPagamento = vendaFormaPagamento.getValorPagamento();
    }
       
        @Id
        @SequenceGenerator(name = "sq_contaformapag")
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name="seq_conta_forma_pagamento", nullable=false)
        public Long getSequencial() {
                return sequencial;
        }
        public void setSequencial(Long sequencial) {
                this.sequencial = sequencial;
        }
       
        @ManyToOne
        @ForeignKey(name = "fk_contaformapag_formapagament")
        @JoinColumn(name="cod_formapagament", referencedColumnName="cod_formapagament", insertable=true, updatable=false)
        public FormaPagamento getFormaPagamento() {
                return formaPagamento;
        }
        public void setFormaPagamento(FormaPagamento formaPagamento) {
                this.formaPagamento = formaPagamento;
        }
       
        @ManyToOne
        @ForeignKey(name="fk_contaformapag_banderiacartao")
        @JoinColumn(name = "cod_bandeira_cartao", nullable=false)
        public BandeiraCartao getBandeiraCartao() {
                return bandeiraCartao;
        }
        public void setBandeiraCartao(BandeiraCartao bandeiraCartao) {
                this.bandeiraCartao = bandeiraCartao;
        }
       
        @Column(name="val_pagamento", nullable=false)
        public Double getValorPagamento() {
                return valorPagamento;
        }
        public void setValorPagamento(Double valorPagamento) {
                this.valorPagamento = valorPagamento;
        }
       
        @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;
                ContaFormaPagamento other = (ContaFormaPagamento) obj;
                if (sequencial == null) {
                        if (other.sequencial != null)
                                return false;
                } else if (!sequencial.equals(other.sequencial))
                        return false;
                return true;
        }
       
        @Transient
        public Long getCodigoDaFormaPagamento() {
                return VerificadorUtil.naoEstaNulo(getFormaPagamento())? getFormaPagamento().getCodigo() : null;
        }
       
        @Transient
        public Long getCodigoDaBandeiraCartao() {
                return VerificadorUtil.naoEstaNulo(getBandeiraCartao())? getBandeiraCartao().getCodigo() : null;
        }
       
        @Transient
        public Boolean formaDePagamentoEhDebito() {
                return VerificadorUtil.naoEstaNulo(getFormaPagamento())? getFormaPagamento().formaPagamentoEhDebito() : false;
        }
       
        @Transient
        public Boolean formaDePagamentoEhCredito() {
                return VerificadorUtil.naoEstaNulo(getFormaPagamento())? getFormaPagamento().formaPagamentoEhCredito() : false;
        }
       
}