Rev 683 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 683 | Rev 685 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | import java.util.Date; |
4 | import java.util.Date; |
| 5 | import java.util.Random; |
- | |
| 6 | 5 | ||
| 7 | import javax.persistence.Column; |
6 | import javax.persistence.Column; |
| 8 | import javax.persistence.Entity; |
7 | import javax.persistence.Entity; |
| 9 | import javax.persistence.GeneratedValue; |
8 | import javax.persistence.GeneratedValue; |
| 10 | import javax.persistence.GenerationType; |
9 | import javax.persistence.GenerationType; |
| Line 16... | Line 15... | ||
| 16 | import javax.persistence.Transient; |
15 | import javax.persistence.Transient; |
| 17 | import javax.validation.constraints.NotNull; |
16 | import javax.validation.constraints.NotNull; |
| 18 | import javax.validation.constraints.Size; |
17 | import javax.validation.constraints.Size; |
| 19 | 18 | ||
| 20 | import org.hibernate.annotations.ForeignKey; |
19 | import org.hibernate.annotations.ForeignKey; |
| 21 | import org.hibernate.validator.constraints.NotEmpty; |
- | |
| 22 | 20 | ||
| 23 | import br.com.ec.core.interfaces.Alterar; |
21 | import br.com.ec.core.interfaces.Alterar; |
| 24 | import br.com.ec.core.interfaces.Cadastrar; |
22 | import br.com.ec.core.interfaces.Cadastrar; |
| 25 | import br.com.ec.core.util.DataUtils; |
23 | import br.com.ec.core.util.DataUtils; |
| 26 | import br.com.ec.core.util.StringUtil; |
24 | import br.com.ec.core.util.StringUtil; |
| 27 | import br.com.ec.core.util.VerificadorUtil; |
25 | import br.com.ec.core.util.VerificadorUtil; |
| 28 | import br.com.ec.domain.model.tipos.TipoCupom; |
- | |
| - | 26 | import br.com.ec.domain.model.tipos.TipoCashback; |
|
| 29 | 27 | ||
| 30 | @Entity |
28 | @Entity |
| 31 | @Table(name="sec_cashback", schema="sc_sec") |
29 | @Table(name="sec_cashback", schema="sc_sec") |
| 32 | public class Cashback implements Serializable, Cloneable { |
30 | public class Cashback implements Serializable, Cloneable { |
| 33 | 31 | ||
| Line 87... | Line 85... | ||
| 87 | public Double getValor() { |
85 | public Double getValor() { |
| 88 | return valor; |
86 | return valor; |
| 89 | }
|
87 | }
|
| 90 | public void setValor(Double valor) { |
88 | public void setValor(Double valor) { |
| 91 | this.valor = valor; |
89 | 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 | }
|
90 | }
|
| 104 | 91 | ||
| 105 | @Column(name="dsc_observacao", nullable=false) |
92 | @Column(name="dsc_observacao", nullable=false) |
| 106 | @Size(max = 1000, message = "Limite de caracteres ultrapassado: Observação") |
93 | @Size(max = 1000, message = "Limite de caracteres ultrapassado: Observação") |
| 107 | public String getObservacao() { |
94 | public String getObservacao() { |
| Line 109... | Line 96... | ||
| 109 | }
|
96 | }
|
| 110 | public void setObservacao(String observacao) { |
97 | public void setObservacao(String observacao) { |
| 111 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
98 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
| 112 | }
|
99 | }
|
| 113 | 100 | ||
| 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; |
- | |
| - | 101 | @Column(name="tip_cashback", nullable=false) |
|
| - | 102 | @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo do cashback", groups = {Cadastrar.class, Alterar.class}) |
|
| - | 103 | public String getTipoCashback() { |
|
| - | 104 | return tipoCashback; |
|
| 118 | }
|
105 | }
|
| 119 | public void setTipoCupom(String tipoCupom) { |
- | |
| 120 | this.tipoCupom = tipoCupom; |
- | |
| - | 106 | public void setTipoCashback(String tipoCashback) { |
|
| - | 107 | this.tipoCashback = tipoCashback; |
|
| 121 | }
|
108 | }
|
| 122 | @Transient |
109 | @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; |
- | |
| - | 110 | public String getDescricaoDoTipoCashback() { |
|
| - | 111 | return VerificadorUtil.naoEstaNulo(tipoCashback)? TipoCashback.parse(tipoCashback).getDescricao() : ""; |
|
| 186 | }
|
112 | }
|
| 187 | 113 | ||
| 188 | @Column(name="ind_ativo", nullable=false) |
114 | @Column(name="ind_ativo", nullable=false) |
| - | 115 | @NotNull(message = "Parâmetro obrigatório não preenchido: Ativo do cashback", groups = {Cadastrar.class, Alterar.class}) |
|
| 189 | public Boolean getAtivo() { |
116 | public Boolean getAtivo() { |
| 190 | return ativo; |
117 | return ativo; |
| 191 | }
|
118 | }
|
| 192 | public void setAtivo(Boolean ativo) { |
119 | public void setAtivo(Boolean ativo) { |
| 193 | this.ativo = ativo; |
120 | 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 | }
|
121 | }
|
| 206 | 122 | ||
| 207 | @ManyToOne |
123 | @ManyToOne |
| 208 | @ForeignKey(name="fk_cupom_cliente") |
124 | @ForeignKey(name="fk_cupom_cliente") |
| 209 | @JoinColumn(name = "seq_cliente", nullable=true) |
- | |
| - | 125 | @JoinColumn(name = "seq_cliente", nullable=false) |
|
| - | 126 | @NotNull(message = "Parâmetro obrigatório não preenchido: Cliente do cashback", groups = {Cadastrar.class, Alterar.class}) |
|
| 210 | public Cliente getCliente() { |
127 | public Cliente getCliente() { |
| 211 | return cliente; |
128 | return cliente; |
| 212 | }
|
129 | }
|
| 213 | public void setCliente(Cliente cliente) { |
130 | public void setCliente(Cliente cliente) { |
| 214 | this.cliente = cliente; |
131 | this.cliente = cliente; |
| 215 | }
|
132 | }
|
| 216 | 133 | ||
| 217 | @Transient |
- | |
| 218 | public Lancamento getLancamento() { |
- | |
| 219 | return lancamento; |
- | |
| - | 134 | @ManyToOne |
|
| - | 135 | @ForeignKey(name="fk_cupom_venda") |
|
| - | 136 | @JoinColumn(name = "seq_venda", nullable=true) |
|
| - | 137 | public Venda getVenda() { |
|
| - | 138 | return venda; |
|
| 220 | }
|
139 | }
|
| 221 | public void setLancamento(Lancamento lancamento) { |
- | |
| 222 | this.lancamento = lancamento; |
- | |
| - | 140 | public void setVenda(Venda venda) { |
|
| - | 141 | this.venda = venda; |
|
| 223 | }
|
142 | }
|
| 224 | 143 | ||
| 225 | @Override |
144 | @Override |
| 226 | public int hashCode() { |
145 | public int hashCode() { |
| 227 | final int prime = 31; |
146 | final int prime = 31; |
| Line 254... | Line 173... | ||
| 254 | }
|
173 | }
|
| 255 | 174 | ||
| 256 | @Transient |
175 | @Transient |
| 257 | public String getNomeDoCliente() { |
176 | public String getNomeDoCliente() { |
| 258 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getNome() : ""; |
177 | 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 | }
|
178 | }
|
| 267 | 179 | ||
| 268 | @Transient |
180 | @Transient |
| 269 | public Boolean valido() { |
181 | public Boolean valido() { |
| 270 | if (VerificadorUtil.naoEstaNulo(getDataHoraValidade())) { |
- | |
| 271 | return DataUtils.getDataAtual().before(getDataHoraValidade()); |
- | |
| - | 182 | if (VerificadorUtil.naoEstaNulo(getPrazoInicial()) && VerificadorUtil.naoEstaNulo(getPrazoFinal())) { |
|
| - | 183 | return DataUtils.getDataAtual().before(getPrazoFinal()) && DataUtils.getDataAtual().after(getPrazoInicial()); |
|
| 272 | }
|
184 | }
|
| 273 | return getAtivo(); |
185 | return getAtivo(); |
| 274 | }
|
186 | }
|
| 275 | 187 | ||
| 276 | }
|
188 | }
|