Rev 685 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 683 | blopes | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Date; |
||
| 5 | import java.util.Random; |
||
| 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.ManyToOne; |
||
| 14 | import javax.persistence.SequenceGenerator; |
||
| 15 | import javax.persistence.Table; |
||
| 16 | import javax.persistence.Transient; |
||
| 17 | import javax.validation.constraints.NotNull; |
||
| 18 | import javax.validation.constraints.Size; |
||
| 19 | |||
| 20 | import org.hibernate.annotations.ForeignKey; |
||
| 21 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 22 | |||
| 23 | import br.com.ec.core.interfaces.Alterar; |
||
| 24 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 25 | import br.com.ec.core.util.DataUtils; |
||
| 26 | import br.com.ec.core.util.StringUtil; |
||
| 27 | import br.com.ec.core.util.VerificadorUtil; |
||
| 28 | import br.com.ec.domain.model.tipos.TipoCupom; |
||
| 29 | |||
| 30 | @Entity |
||
| 31 | @Table(name="sec_cashback", schema="sc_sec") |
||
| 32 | public class Cashback implements Serializable, Cloneable { |
||
| 33 | |||
| 34 | private static final long serialVersionUID = 1L; |
||
| 35 | |||
| 36 | private Long sequencial; |
||
| 37 | private Date dataHoraEmissao; |
||
| 38 | private Date prazoInicial; |
||
| 39 | private Date prazoFinal; |
||
| 40 | private Double valor; |
||
| 41 | private String tipoCashback; // E - ENTRADA, S - SAÍDA |
||
| 42 | private String observacao; |
||
| 43 | private Boolean ativo; |
||
| 44 | |||
| 45 | private Cliente cliente; |
||
| 46 | private Venda venda; |
||
| 47 | |||
| 48 | public Cashback() {} |
||
| 49 | |||
| 50 | @Id |
||
| 51 | @SequenceGenerator(name = "sq_cashback") |
||
| 52 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 53 | @Column(name="seq_cashback", nullable=false) |
||
| 54 | public Long getSequencial() { |
||
| 55 | return sequencial; |
||
| 56 | } |
||
| 57 | public void setSequencial(Long sequencial) { |
||
| 58 | this.sequencial = sequencial; |
||
| 59 | } |
||
| 60 | |||
| 61 | @NotNull(message = "Informe a data de emissão", groups = {Cadastrar.class, Alterar.class}) |
||
| 62 | @Column(name="dth_emissao", nullable=false) |
||
| 63 | public Date getDataHoraEmissao() { |
||
| 64 | return dataHoraEmissao; |
||
| 65 | } |
||
| 66 | public void setDataHoraEmissao(Date dataHoraEmissao) { |
||
| 67 | this.dataHoraEmissao = dataHoraEmissao; |
||
| 68 | } |
||
| 69 | |||
| 70 | @Column(name="dth_prazo_inicial") |
||
| 71 | public Date getPrazoInicial() { |
||
| 72 | return prazoInicial; |
||
| 73 | } |
||
| 74 | public void setPrazoInicial(Date prazoInicial) { |
||
| 75 | this.prazoInicial = prazoInicial; |
||
| 76 | } |
||
| 77 | |||
| 78 | @Column(name="dth_prazo_final") |
||
| 79 | public Date getPrazoFinal() { |
||
| 80 | return prazoFinal; |
||
| 81 | } |
||
| 82 | public void setPrazoFinal(Date prazoFinal) { |
||
| 83 | this.prazoFinal = prazoFinal; |
||
| 84 | } |
||
| 85 | |||
| 86 | @Column(name="val_cashback") |
||
| 87 | public Double getValor() { |
||
| 88 | return valor; |
||
| 89 | } |
||
| 90 | public void setValor(Double valor) { |
||
| 91 | this.valor = valor; |
||
| 92 | } |
||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | @Column(name="dsc_cupom", nullable=false) |
||
| 97 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Descrição") |
||
| 98 | public String getDescricao() { |
||
| 99 | return descricao; |
||
| 100 | } |
||
| 101 | public void setDescricao(String descricao) { |
||
| 102 | this.descricao = StringUtil.setarUpperCaseComTrim(descricao); |
||
| 103 | } |
||
| 104 | |||
| 105 | @Column(name="dsc_observacao", nullable=false) |
||
| 106 | @Size(max = 1000, message = "Limite de caracteres ultrapassado: Observação") |
||
| 107 | public String getObservacao() { |
||
| 108 | return observacao; |
||
| 109 | } |
||
| 110 | public void setObservacao(String observacao) { |
||
| 111 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 112 | } |
||
| 113 | |||
| 114 | @Column(name="tip_cupom", nullable=false) |
||
| 115 | @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo do cupom", groups = {Cadastrar.class, Alterar.class}) |
||
| 116 | public String getTipoCupom() { |
||
| 117 | return tipoCupom; |
||
| 118 | } |
||
| 119 | public void setTipoCupom(String tipoCupom) { |
||
| 120 | this.tipoCupom = tipoCupom; |
||
| 121 | } |
||
| 122 | @Transient |
||
| 123 | public String getDescricaoDoTipoCupom() { |
||
| 124 | return VerificadorUtil.naoEstaNulo(tipoCupom)? TipoCupom.parse(tipoCupom).getDescricao() : ""; |
||
| 125 | } |
||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | @Column(name="val_percentual_cupom") |
||
| 130 | public Double getPercentual() { |
||
| 131 | return percentual; |
||
| 132 | } |
||
| 133 | public void setPercentual(Double percentual) { |
||
| 134 | this.percentual = percentual; |
||
| 135 | } |
||
| 136 | |||
| 137 | @Column(name="qtd_utilizado") |
||
| 138 | public Integer getQuantidadeUtilizada() { |
||
| 139 | return quantidadeUtilizada; |
||
| 140 | } |
||
| 141 | public void setQuantidadeUtilizada(Integer quantidadeUtilizada) { |
||
| 142 | this.quantidadeUtilizada = quantidadeUtilizada; |
||
| 143 | } |
||
| 144 | |||
| 145 | @Column(name="dth_utilizado") |
||
| 146 | public Date getDataHoraUtilizado() { |
||
| 147 | return dataHoraUtilizado; |
||
| 148 | } |
||
| 149 | public void setDataHoraUtilizado(Date dataHoraUtilizado) { |
||
| 150 | this.dataHoraUtilizado = dataHoraUtilizado; |
||
| 151 | } |
||
| 152 | |||
| 153 | @Column(name="dth_validade") |
||
| 154 | public Date getDataHoraValidade() { |
||
| 155 | return dataHoraValidade; |
||
| 156 | } |
||
| 157 | public void setDataHoraValidade(Date dataHoraValidade) { |
||
| 158 | this.dataHoraValidade = dataHoraValidade; |
||
| 159 | } |
||
| 160 | |||
| 161 | @NotNull(message = "Informe a data de emissão", groups = {Cadastrar.class, Alterar.class}) |
||
| 162 | @Column(name="dth_emissao", nullable=false) |
||
| 163 | public Date getDataHoraEmissao() { |
||
| 164 | return dataHoraEmissao; |
||
| 165 | } |
||
| 166 | public void setDataHoraEmissao(Date dataHoraEmissao) { |
||
| 167 | this.dataHoraEmissao = dataHoraEmissao; |
||
| 168 | } |
||
| 169 | |||
| 170 | @NotNull(message = "Informe se a utilização é limitada", groups = {Cadastrar.class, Alterar.class}) |
||
| 171 | @Column(name="ind_limite_utilizacao", nullable=false) |
||
| 172 | public Boolean getLimiteUtilizacao() { |
||
| 173 | return limiteUtilizacao; |
||
| 174 | } |
||
| 175 | public void setLimiteUtilizacao(Boolean limiteUtilizacao) { |
||
| 176 | this.limiteUtilizacao = limiteUtilizacao; |
||
| 177 | } |
||
| 178 | |||
| 179 | @NotNull(message = "Informe se o cupom é público", groups = {Cadastrar.class, Alterar.class}) |
||
| 180 | @Column(name="ind_publico", nullable=false) |
||
| 181 | public Boolean getPublico() { |
||
| 182 | return publico; |
||
| 183 | } |
||
| 184 | public void setPublico(Boolean publico) { |
||
| 185 | this.publico = publico; |
||
| 186 | } |
||
| 187 | |||
| 188 | @Column(name="ind_ativo", nullable=false) |
||
| 189 | public Boolean getAtivo() { |
||
| 190 | return ativo; |
||
| 191 | } |
||
| 192 | public void setAtivo(Boolean ativo) { |
||
| 193 | this.ativo = ativo; |
||
| 194 | } |
||
| 195 | |||
| 196 | @Transient |
||
| 197 | public String getValorCupomFormatado() { |
||
| 198 | if (VerificadorUtil.naoEstaNulo(getValor())) { |
||
| 199 | return "R$ " + StringUtil.formatarValor(getValor()); |
||
| 200 | } |
||
| 201 | if (VerificadorUtil.naoEstaNulo(getPercentual())) { |
||
| 202 | return StringUtil.formatarPercentual(getPercentual()/100); |
||
| 203 | } |
||
| 204 | return null; |
||
| 205 | } |
||
| 206 | |||
| 207 | @ManyToOne |
||
| 208 | @ForeignKey(name="fk_cupom_cliente") |
||
| 209 | @JoinColumn(name = "seq_cliente", nullable=true) |
||
| 210 | public Cliente getCliente() { |
||
| 211 | return cliente; |
||
| 212 | } |
||
| 213 | public void setCliente(Cliente cliente) { |
||
| 214 | this.cliente = cliente; |
||
| 215 | } |
||
| 216 | |||
| 217 | @Transient |
||
| 218 | public Lancamento getLancamento() { |
||
| 219 | return lancamento; |
||
| 220 | } |
||
| 221 | public void setLancamento(Lancamento lancamento) { |
||
| 222 | this.lancamento = lancamento; |
||
| 223 | } |
||
| 224 | |||
| 225 | @Override |
||
| 226 | public int hashCode() { |
||
| 227 | final int prime = 31; |
||
| 228 | int result = 1; |
||
| 229 | result = prime * result |
||
| 230 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 231 | return result; |
||
| 232 | } |
||
| 233 | |||
| 234 | @Override |
||
| 235 | public boolean equals(Object obj) { |
||
| 236 | if (this == obj) |
||
| 237 | return true; |
||
| 238 | if (obj == null) |
||
| 239 | return false; |
||
| 240 | if (getClass() != obj.getClass()) |
||
| 241 | return false; |
||
| 242 | Cashback other = (Cashback) obj; |
||
| 243 | if (sequencial == null) { |
||
| 244 | if (other.sequencial != null) |
||
| 245 | return false; |
||
| 246 | } else if (!sequencial.equals(other.sequencial)) |
||
| 247 | return false; |
||
| 248 | return true; |
||
| 249 | } |
||
| 250 | |||
| 251 | @Override |
||
| 252 | public Cashback clone() throws CloneNotSupportedException { |
||
| 253 | return (Cashback) super.clone(); |
||
| 254 | } |
||
| 255 | |||
| 256 | @Transient |
||
| 257 | public String getNomeDoCliente() { |
||
| 258 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getNome() : ""; |
||
| 259 | } |
||
| 260 | |||
| 261 | @Transient |
||
| 262 | public void gerarCodigo() { |
||
| 263 | Random random = new Random(); |
||
| 264 | Integer codigoGerado = random.nextInt(999999); |
||
| 265 | setCodigo(codigoGerado.toString()); |
||
| 266 | } |
||
| 267 | |||
| 268 | @Transient |
||
| 269 | public Boolean valido() { |
||
| 270 | if (VerificadorUtil.naoEstaNulo(getDataHoraValidade())) { |
||
| 271 | return DataUtils.getDataAtual().before(getDataHoraValidade()); |
||
| 272 | } |
||
| 273 | return getAtivo(); |
||
| 274 | } |
||
| 275 | |||
| 276 | } |