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