Details | 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 | import java.util.regex.Matcher; |
||
| 5 | import java.util.regex.Pattern; |
||
| 6 | |||
| 7 | import javax.persistence.Column; |
||
| 8 | import javax.persistence.Entity; |
||
| 9 | import javax.persistence.GeneratedValue; |
||
| 10 | import javax.persistence.GenerationType; |
||
| 11 | import javax.persistence.Id; |
||
| 12 | import javax.persistence.JoinColumn; |
||
| 13 | import javax.persistence.OneToOne; |
||
| 14 | import javax.persistence.SequenceGenerator; |
||
| 15 | import javax.persistence.Table; |
||
| 16 | import javax.persistence.Transient; |
||
| 17 | import javax.validation.constraints.NotNull; |
||
| 18 | |||
| 19 | import org.hibernate.annotations.ForeignKey; |
||
| 20 | |||
| 21 | import br.com.ec.core.interfaces.Alterar; |
||
| 22 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 23 | import br.com.ec.core.util.VerificadorUtil; |
||
| 24 | |||
| 25 | @Entity |
||
| 26 | @Table(name="sec_fornecedor", schema="sc_sec") |
||
| 27 | public class Fornecedor implements Serializable { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private Long sequencial; |
||
| 32 | private Pessoa pessoa; |
||
| 33 | private Boolean emiteNotaFiscal; |
||
| 34 | private Boolean sujeitoST; |
||
| 35 | private Double aliquotaIcms; |
||
| 36 | private Boolean ativo; |
||
| 37 | |||
| 38 | public Fornecedor() { |
||
| 39 | setEmiteNotaFiscal(false); |
||
| 40 | setAtivo(true); |
||
| 41 | } |
||
| 42 | |||
| 43 | @Id |
||
| 44 | @SequenceGenerator(name = "sq_fornecedor") |
||
| 45 | @GeneratedValue(strategy=GenerationType.IDENTITY) |
||
| 46 | @Column(name="seq_fornecedor", nullable=false) |
||
| 47 | public Long getSequencial() { |
||
| 48 | return sequencial; |
||
| 49 | } |
||
| 50 | public void setSequencial(Long sequencial) { |
||
| 51 | this.sequencial = sequencial; |
||
| 52 | } |
||
| 53 | |||
| 54 | @OneToOne |
||
| 55 | @ForeignKey(name="fk_fornecedorproduto_pessoa") |
||
| 56 | @JoinColumn(name="seq_pessoa", referencedColumnName="seq_pessoa") |
||
| 57 | @NotNull(message="Obrigatório informar a pessoa", groups={Cadastrar.class, Alterar.class}) |
||
| 58 | public Pessoa getPessoa() { |
||
| 59 | return pessoa; |
||
| 60 | } |
||
| 61 | public void setPessoa(Pessoa pessoa) { |
||
| 62 | this.pessoa = pessoa; |
||
| 63 | } |
||
| 64 | |||
| 65 | @Column(name="ind_emite_notafiscal", nullable=false) |
||
| 66 | @NotNull(message="Obrigatório informar a indicação de emissão de nota fiscal", groups={Cadastrar.class, Alterar.class}) |
||
| 67 | public Boolean getEmiteNotaFiscal() { |
||
| 68 | return emiteNotaFiscal; |
||
| 69 | } |
||
| 70 | public void setEmiteNotaFiscal(Boolean emiteNotaFiscal) { |
||
| 71 | this.emiteNotaFiscal = emiteNotaFiscal; |
||
| 72 | } |
||
| 73 | |||
| 74 | @Column(name="ind_sujeito_st", nullable=false) |
||
| 75 | @NotNull(message="Obrigatório informar a indicação de substituição tributária", groups={Cadastrar.class, Alterar.class}) |
||
| 76 | public Boolean getSujeitoST() { |
||
| 77 | if (VerificadorUtil.estaNulo(sujeitoST)) { |
||
| 78 | return false; |
||
| 79 | } |
||
| 80 | return sujeitoST; |
||
| 81 | } |
||
| 82 | public void setSujeitoST(Boolean sujeitoST) { |
||
| 83 | this.sujeitoST = sujeitoST; |
||
| 84 | } |
||
| 85 | |||
| 86 | @Column(name="val_aliquota_icms") |
||
| 87 | public Double getAliquotaIcms() { |
||
| 88 | return aliquotaIcms; |
||
| 89 | } |
||
| 90 | public void setAliquotaIcms(Double aliquotaIcms) { |
||
| 91 | this.aliquotaIcms = aliquotaIcms; |
||
| 92 | } |
||
| 93 | |||
| 94 | @Column(name="ind_ativo", nullable=false) |
||
| 95 | @NotNull(message="Obrigatório informar a indicação de ativo", groups={Cadastrar.class, Alterar.class}) |
||
| 96 | public Boolean getAtivo() { |
||
| 97 | return ativo; |
||
| 98 | } |
||
| 99 | public void setAtivo(Boolean ativo) { |
||
| 100 | this.ativo = ativo; |
||
| 101 | } |
||
| 102 | |||
| 103 | @Transient |
||
| 104 | public Long getSequencialPessoa() { |
||
| 105 | return VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getSequencial() : null; |
||
| 106 | } |
||
| 107 | |||
| 108 | @Transient |
||
| 109 | public String getNomeDaPessoa() { |
||
| 110 | return VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getNome() : null; |
||
| 111 | } |
||
| 112 | @Transient |
||
| 113 | public String getNomeAbreviadoDaPessoa() { |
||
| 114 | if (VerificadorUtil.naoEstaNulo(getNomeDaPessoa())) { |
||
| 115 | String pattern = "\\S+"; |
||
| 116 | Pattern r = Pattern.compile(pattern); |
||
| 117 | Matcher m = r.matcher(getNomeDaPessoa()); |
||
| 118 | if (m.find( )) { |
||
| 119 | return m.group(0); |
||
| 120 | } |
||
| 121 | return getNomeDaPessoa(); |
||
| 122 | } |
||
| 123 | return ""; |
||
| 124 | } |
||
| 125 | |||
| 126 | @Override |
||
| 127 | public int hashCode() { |
||
| 128 | final int prime = 31; |
||
| 129 | int result = 1; |
||
| 130 | result = prime * result + ((pessoa == null) ? 0 : pessoa.hashCode()); |
||
| 131 | return result; |
||
| 132 | } |
||
| 133 | |||
| 134 | @Override |
||
| 135 | public boolean equals(Object obj) { |
||
| 136 | if (this == obj) |
||
| 137 | return true; |
||
| 138 | if (obj == null) |
||
| 139 | return false; |
||
| 140 | if (getClass() != obj.getClass()) |
||
| 141 | return false; |
||
| 142 | Fornecedor other = (Fornecedor) obj; |
||
| 143 | if (pessoa == null) { |
||
| 144 | if (other.pessoa != null) |
||
| 145 | return false; |
||
| 146 | } else if (!pessoa.equals(other.pessoa)) |
||
| 147 | return false; |
||
| 148 | return true; |
||
| 149 | } |
||
| 150 | |||
| 151 | } |