Rev 259 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 259 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.persistence.Column; |
||
| 6 | import javax.persistence.Entity; |
||
| 7 | import javax.persistence.GeneratedValue; |
||
| 8 | import javax.persistence.GenerationType; |
||
| 9 | import javax.persistence.Id; |
||
| 10 | import javax.persistence.JoinColumn; |
||
| 11 | import javax.persistence.ManyToOne; |
||
| 12 | import javax.persistence.SequenceGenerator; |
||
| 13 | import javax.persistence.Table; |
||
| 14 | import javax.persistence.Transient; |
||
| 15 | import javax.validation.constraints.Size; |
||
| 16 | |||
| 17 | import org.hibernate.annotations.ForeignKey; |
||
| 18 | |||
| 19 | import br.com.ec.core.util.StringUtil; |
||
| 20 | import br.com.ec.core.util.VerificadorUtil; |
||
| 21 | import br.com.ec.domain.model.tipos.TipoConta; |
||
| 22 | import br.com.ec.domain.model.tipos.TipoFrequencia; |
||
| 23 | |||
| 24 | @Entity |
||
| 25 | @Table(name="sec_conta", schema="sc_sec") |
||
| 26 | public class Conta implements Serializable { |
||
| 27 | |||
| 28 | private static final long serialVersionUID = 1L; |
||
| 29 | |||
| 30 | private Long sequencial; |
||
| 31 | private Categoria categoria; |
||
| 32 | private Venda venda; |
||
| 33 | private Pessoa pessoa; |
||
| 34 | private Loja loja; |
||
| 35 | private ContaFormaPagamento formaDePagamento; |
||
| 36 | private Vigencia vigencia; |
||
| 37 | |||
| 38 | private String tipoFrequencia; |
||
| 39 | private String tipoConta; |
||
| 40 | private String observacao; |
||
| 41 | private Boolean indicadorAtivo; |
||
| 42 | |||
| 43 | private Compra compra; |
||
| 44 | |||
| 45 | public Conta() {} |
||
| 46 | |||
| 439 | espaco | 47 | public Conta(Long sequencial, Categoria categoria, Venda venda, Pessoa pessoa, Loja loja, |
| 48 | ContaFormaPagamento formaDePagamento, Vigencia vigencia, String tipoFrequencia, String tipoConta, |
||
| 49 | String observacao, Boolean indicadorAtivo) { |
||
| 50 | super(); |
||
| 51 | this.sequencial = sequencial; |
||
| 52 | this.categoria = categoria; |
||
| 53 | this.venda = venda; |
||
| 54 | this.pessoa = pessoa; |
||
| 55 | this.loja = loja; |
||
| 56 | this.formaDePagamento = formaDePagamento; |
||
| 57 | this.vigencia = vigencia; |
||
| 58 | this.tipoFrequencia = tipoFrequencia; |
||
| 59 | this.tipoConta = tipoConta; |
||
| 60 | this.observacao = observacao; |
||
| 61 | this.indicadorAtivo = indicadorAtivo; |
||
| 62 | } |
||
| 63 | |||
| 64 | public Conta(Conta conta) { |
||
| 65 | super(); |
||
| 66 | this.sequencial = conta.getSequencial(); |
||
| 67 | this.categoria = conta.getCategoria(); |
||
| 68 | this.venda = conta.getVenda(); |
||
| 69 | this.pessoa = conta.getPessoa(); |
||
| 70 | this.loja = conta.getLoja(); |
||
| 71 | this.formaDePagamento = conta.getFormaDePagamento(); |
||
| 72 | this.vigencia = conta.getVigencia(); |
||
| 73 | this.tipoFrequencia = conta.getTipoFrequencia(); |
||
| 74 | this.tipoConta = conta.getTipoConta(); |
||
| 75 | this.observacao = conta.getObservacao(); |
||
| 76 | this.indicadorAtivo = conta.getIndicadorAtivo(); |
||
| 77 | } |
||
| 78 | |||
| 259 | espaco | 79 | public Conta(String tipoConta) { |
| 80 | this.tipoConta = tipoConta; |
||
| 81 | } |
||
| 82 | |||
| 83 | @Id |
||
| 84 | @SequenceGenerator(name = "sq_conta") |
||
| 85 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 86 | @Column(name="seq_conta", nullable=false) |
||
| 87 | public Long getSequencial() { |
||
| 88 | return sequencial; |
||
| 89 | } |
||
| 90 | public void setSequencial(Long sequencial) { |
||
| 91 | this.sequencial = sequencial; |
||
| 92 | } |
||
| 93 | |||
| 94 | @ManyToOne |
||
| 95 | @ForeignKey(name = "fk_conta_categoria") |
||
| 96 | @JoinColumn(name="seq_categoria", referencedColumnName="seq_categoria", nullable=true) |
||
| 97 | public Categoria getCategoria() { |
||
| 98 | return categoria; |
||
| 99 | } |
||
| 100 | public void setCategoria(Categoria categoria) { |
||
| 101 | this.categoria = categoria; |
||
| 102 | } |
||
| 103 | |||
| 104 | @ManyToOne |
||
| 105 | @ForeignKey(name = "fk_conta_venda") |
||
| 106 | @JoinColumn(name="seq_venda", referencedColumnName="seq_venda", nullable=true) |
||
| 107 | public Venda getVenda() { |
||
| 108 | return venda; |
||
| 109 | } |
||
| 110 | public void setVenda(Venda venda) { |
||
| 111 | this.venda = venda; |
||
| 112 | } |
||
| 113 | |||
| 114 | @ManyToOne |
||
| 115 | @ForeignKey(name="fk_conta_pessoa") |
||
| 116 | @JoinColumn(name="seq_pessoa", referencedColumnName="seq_pessoa", nullable=true) |
||
| 117 | public Pessoa getPessoa() { |
||
| 118 | return pessoa; |
||
| 119 | } |
||
| 120 | public void setPessoa(Pessoa pessoa) { |
||
| 121 | this.pessoa = pessoa; |
||
| 122 | } |
||
| 123 | |||
| 124 | @ManyToOne |
||
| 125 | @ForeignKey(name="fk_conta_loja") |
||
| 126 | @JoinColumn(name="seq_loja", referencedColumnName="seq_loja", nullable=true) |
||
| 127 | public Loja getLoja() { |
||
| 128 | return loja; |
||
| 129 | } |
||
| 130 | public void setLoja(Loja loja) { |
||
| 131 | this.loja = loja; |
||
| 132 | } |
||
| 133 | |||
| 134 | @ManyToOne |
||
| 135 | @ForeignKey(name="fk_conta_contaformapag") |
||
| 136 | @JoinColumn(name="seq_conta_forma_pagamento", referencedColumnName="seq_conta_forma_pagamento", nullable=true) |
||
| 137 | public ContaFormaPagamento getFormaDePagamento() { |
||
| 138 | return formaDePagamento; |
||
| 139 | } |
||
| 140 | public void setFormaDePagamento(ContaFormaPagamento formaDePagamento) { |
||
| 141 | this.formaDePagamento = formaDePagamento; |
||
| 142 | } |
||
| 143 | |||
| 144 | @ManyToOne |
||
| 145 | @ForeignKey(name="fk_conta_vigencia") |
||
| 146 | @JoinColumn(name="seq_vigencia", referencedColumnName="seq_vigencia", nullable=true) |
||
| 147 | public Vigencia getVigencia() { |
||
| 148 | return vigencia; |
||
| 149 | } |
||
| 150 | public void setVigencia(Vigencia vigencia) { |
||
| 151 | this.vigencia = vigencia; |
||
| 152 | } |
||
| 153 | |||
| 154 | @Column(name="tip_frequencia") |
||
| 155 | public String getTipoFrequencia() { |
||
| 156 | return tipoFrequencia; |
||
| 157 | } |
||
| 158 | public void setTipoFrequencia(String tipoFrequencia) { |
||
| 159 | this.tipoFrequencia = tipoFrequencia; |
||
| 160 | } |
||
| 161 | |||
| 162 | @Transient |
||
| 163 | public String getTipoFrequenciaDescricao() { |
||
| 164 | return TipoFrequencia.parse(getTipoFrequencia()).getDescricao(); |
||
| 165 | } |
||
| 166 | |||
| 167 | @Column(name="tip_conta") |
||
| 168 | public String getTipoConta() { |
||
| 169 | return tipoConta; |
||
| 170 | } |
||
| 171 | public void setTipoConta(String tipoConta) { |
||
| 172 | this.tipoConta = tipoConta; |
||
| 173 | } |
||
| 174 | |||
| 175 | @Transient |
||
| 176 | public String getTipoContaDescricao() { |
||
| 177 | return TipoConta.parse(getTipoConta()).getDescricao(); |
||
| 178 | } |
||
| 179 | |||
| 180 | @Column(name="dsc_observacao") |
||
| 181 | @Size(max = 400, message = "Limite de caracteres ultrapassado: Observação") |
||
| 182 | public String getObservacao() { |
||
| 183 | return observacao; |
||
| 184 | } |
||
| 185 | public void setObservacao(String observacao) { |
||
| 186 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 187 | } |
||
| 188 | |||
| 189 | @Column(name="ind_ativo", nullable=false) |
||
| 190 | public Boolean getIndicadorAtivo() { |
||
| 191 | return indicadorAtivo; |
||
| 192 | } |
||
| 193 | public void setIndicadorAtivo(Boolean indicadorAtivo) { |
||
| 194 | this.indicadorAtivo = indicadorAtivo; |
||
| 195 | } |
||
| 196 | |||
| 197 | @Transient |
||
| 198 | public Compra getCompra() { |
||
| 199 | return compra; |
||
| 200 | } |
||
| 201 | public void setCompra(Compra compra) { |
||
| 202 | this.compra = compra; |
||
| 203 | } |
||
| 204 | |||
| 205 | @Override |
||
| 206 | public int hashCode() { |
||
| 207 | final int prime = 31; |
||
| 208 | int result = 1; |
||
| 209 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 210 | return result; |
||
| 211 | } |
||
| 212 | |||
| 213 | @Override |
||
| 214 | public boolean equals(Object obj) { |
||
| 215 | if (this == obj) |
||
| 216 | return true; |
||
| 217 | if (obj == null) |
||
| 218 | return false; |
||
| 219 | if (getClass() != obj.getClass()) |
||
| 220 | return false; |
||
| 221 | Conta other = (Conta) obj; |
||
| 222 | if (sequencial == null) { |
||
| 223 | if (other.sequencial != null) |
||
| 224 | return false; |
||
| 225 | } else if (!sequencial.equals(other.sequencial)) |
||
| 226 | return false; |
||
| 227 | return true; |
||
| 228 | } |
||
| 229 | |||
| 230 | @Transient |
||
| 231 | public Boolean ehContaAPagar() { |
||
| 232 | return VerificadorUtil.naoEstaNulo(getTipoConta())? TipoConta.CONTA_A_PAGAR.getValor().equals(getTipoConta()) : false; |
||
| 233 | } |
||
| 234 | |||
| 235 | @Transient |
||
| 236 | public Boolean ehContaAReceber() { |
||
| 237 | return VerificadorUtil.naoEstaNulo(getTipoConta())? TipoConta.CONTA_A_RECEBER.getValor().equals(getTipoConta()) : false; |
||
| 238 | } |
||
| 239 | |||
| 240 | @Transient |
||
| 241 | public Long getSequencialDaVenda() { |
||
| 242 | return VerificadorUtil.naoEstaNulo(getVenda())? getVenda().getSequencial() : null; |
||
| 243 | } |
||
| 244 | |||
| 245 | @Transient |
||
| 246 | public Boolean formaDePagamentoEhDebito() { |
||
| 247 | return VerificadorUtil.naoEstaNulo(getFormaDePagamento())? getFormaDePagamento().formaDePagamentoEhDebito() : false; |
||
| 248 | } |
||
| 249 | |||
| 250 | @Transient |
||
| 251 | public Boolean formaDePagamentoEhCredito() { |
||
| 252 | return VerificadorUtil.naoEstaNulo(getFormaDePagamento())? getFormaDePagamento().formaDePagamentoEhCredito() : false; |
||
| 253 | } |
||
| 254 | |||
| 255 | } |