Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Date; |
||
| 5 | |||
| 6 | import javax.persistence.Column; |
||
| 7 | import javax.persistence.Entity; |
||
| 8 | import javax.persistence.GeneratedValue; |
||
| 9 | import javax.persistence.GenerationType; |
||
| 10 | import javax.persistence.Id; |
||
| 11 | import javax.persistence.JoinColumn; |
||
| 12 | import javax.persistence.ManyToOne; |
||
| 13 | import javax.persistence.Table; |
||
| 14 | import javax.persistence.Transient; |
||
| 15 | import javax.validation.constraints.NotNull; |
||
| 16 | |||
| 17 | import org.hibernate.annotations.ForeignKey; |
||
| 18 | |||
| 19 | import br.com.ec.domain.model.tipos.TipoEstoqueAuditoria; |
||
| 20 | import br.com.ec.domain.model.tipos.TipoEstoqueAuditoriaVerificacao; |
||
| 21 | import br.com.ec.domain.model.tipos.TipoProduto; |
||
| 22 | import br.edu.cesmac.core.generic.identidade.Identidade; |
||
| 23 | import br.edu.cesmac.core.interfaces.Alterar; |
||
| 24 | import br.edu.cesmac.core.interfaces.Cadastrar; |
||
| 25 | import br.edu.cesmac.core.util.DataUtils; |
||
| 26 | import br.edu.cesmac.core.util.StringUtil; |
||
| 27 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 28 | |||
| 29 | @Entity |
||
| 30 | @Table(name="sec_estoque_auditoria", schema="sc_sec") |
||
| 31 | public class EstoqueAuditoria implements Serializable, Identidade { |
||
| 32 | |||
| 33 | private static final long serialVersionUID = 1L; |
||
| 34 | |||
| 35 | private Long sequencial; |
||
| 36 | private Usuario usuario; |
||
| 37 | private Produto produto; |
||
| 38 | private Loja loja; |
||
| 39 | private Cliente cliente; |
||
| 40 | private Integer quantidadeEstoqueAnterior; |
||
| 41 | private Integer quantidadeEstoqueNovo; |
||
| 42 | private String observacao; |
||
| 43 | private String auditoria; |
||
| 44 | private Date dataAtualizacao; |
||
| 45 | private String tipoEstoqueAuditoria; |
||
| 46 | private String tipoVerificacao; |
||
| 47 | private Usuario usuarioVerificacao; |
||
| 48 | |||
| 49 | private Boolean ehDevolucaoMesmoProduto; |
||
| 50 | private Double valorDevolvidoCupom; |
||
| 51 | private Double valorDevolvidoDinheiro; |
||
| 52 | private Double valorDevolvidoEstorno; |
||
| 53 | |||
| 54 | public EstoqueAuditoria() { |
||
| 55 | setEhDevolucaoMesmoProduto(false); |
||
| 56 | setValorDevolvidoCupom(new Double(0.0)); |
||
| 57 | setValorDevolvidoDinheiro(new Double(0.0)); |
||
| 58 | setValorDevolvidoEstorno(new Double(0.0)); |
||
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | @Transient |
||
| 63 | public Object getId() { |
||
| 64 | return this.getSequencial(); |
||
| 65 | } |
||
| 66 | @Override |
||
| 67 | public void setId(Object id) { |
||
| 68 | this.sequencial = (Long) id; |
||
| 69 | } |
||
| 70 | |||
| 71 | @Id |
||
| 72 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 73 | @Column(name="seq_estoque_auditoria", nullable=false) |
||
| 74 | public Long getSequencial() { |
||
| 75 | return sequencial; |
||
| 76 | } |
||
| 77 | public void setSequencial(Long sequencial) { |
||
| 78 | this.sequencial = sequencial; |
||
| 79 | } |
||
| 80 | |||
| 81 | @ManyToOne |
||
| 82 | @ForeignKey(name="fk_estoqueaudit_usuario") |
||
| 83 | @JoinColumn(name = "seq_usuario", nullable=true) |
||
| 84 | public Usuario getUsuario() { |
||
| 85 | return usuario; |
||
| 86 | } |
||
| 87 | public void setUsuario(Usuario usuario) { |
||
| 88 | this.usuario = usuario; |
||
| 89 | } |
||
| 90 | |||
| 91 | @ManyToOne |
||
| 92 | @ForeignKey(name="fk_estoqueaudit_usuarioverificacao") |
||
| 93 | @JoinColumn(name = "seq_usuario_verificacao", nullable=true) |
||
| 94 | public Usuario getUsuarioVerificacao() { |
||
| 95 | return usuarioVerificacao; |
||
| 96 | } |
||
| 97 | public void setUsuarioVerificacao(Usuario usuarioVerificacao) { |
||
| 98 | this.usuarioVerificacao = usuarioVerificacao; |
||
| 99 | } |
||
| 100 | |||
| 101 | @ManyToOne |
||
| 102 | @ForeignKey(name="fk_estoqueaudit_produto") |
||
| 103 | @JoinColumn(name = "seq_produto", nullable=true) |
||
| 104 | public Produto getProduto() { |
||
| 105 | return produto; |
||
| 106 | } |
||
| 107 | public void setProduto(Produto produto) { |
||
| 108 | this.produto = produto; |
||
| 109 | } |
||
| 110 | |||
| 111 | @ManyToOne |
||
| 112 | @ForeignKey(name="fk_estoqueaudit_loja") |
||
| 113 | @JoinColumn(name = "seq_loja", nullable=true) |
||
| 114 | public Loja getLoja() { |
||
| 115 | return loja; |
||
| 116 | } |
||
| 117 | public void setLoja(Loja loja) { |
||
| 118 | this.loja = loja; |
||
| 119 | } |
||
| 120 | |||
| 121 | @ManyToOne |
||
| 122 | @ForeignKey(name="fk_estoqueaudit_cliente") |
||
| 123 | @JoinColumn(name = "seq_cliente", nullable=true) |
||
| 124 | public Cliente getCliente() { |
||
| 125 | return cliente; |
||
| 126 | } |
||
| 127 | public void setCliente(Cliente cliente) { |
||
| 128 | this.cliente = cliente; |
||
| 129 | } |
||
| 130 | |||
| 131 | @Column(name="qtd_estoque_anterior") |
||
| 132 | public Integer getQuantidadeEstoqueAnterior() { |
||
| 133 | return quantidadeEstoqueAnterior; |
||
| 134 | } |
||
| 135 | public void setQuantidadeEstoqueAnterior(Integer quantidadeEstoqueAnterior) { |
||
| 136 | this.quantidadeEstoqueAnterior = quantidadeEstoqueAnterior; |
||
| 137 | } |
||
| 138 | |||
| 139 | @Column(name="qtd_estoque_novo") |
||
| 140 | public Integer getQuantidadeEstoqueNovo() { |
||
| 141 | return quantidadeEstoqueNovo; |
||
| 142 | } |
||
| 143 | public void setQuantidadeEstoqueNovo(Integer quantidadeEstoqueNovo) { |
||
| 144 | this.quantidadeEstoqueNovo = quantidadeEstoqueNovo; |
||
| 145 | } |
||
| 146 | |||
| 147 | @Column(name="dsc_observacao") |
||
| 148 | public String getObservacao() { |
||
| 149 | return observacao; |
||
| 150 | } |
||
| 151 | public void setObservacao(String observacao) { |
||
| 152 | this.observacao = StringUtil.setarUpperCase(observacao); |
||
| 153 | } |
||
| 154 | |||
| 155 | @Column(name="dsc_auditoria") |
||
| 156 | public String getAuditoria() { |
||
| 157 | return auditoria; |
||
| 158 | } |
||
| 159 | public void setAuditoria(String auditoria) { |
||
| 160 | this.auditoria = StringUtil.setarUpperCase(auditoria); |
||
| 161 | } |
||
| 162 | |||
| 163 | @NotNull(message="Obrigatório informar a data do ocorrido", groups={Cadastrar.class, Alterar.class}) |
||
| 164 | @Column(name="dth_atualizacao", nullable=false) |
||
| 165 | public Date getDataAtualizacao() { |
||
| 166 | return dataAtualizacao; |
||
| 167 | } |
||
| 168 | public void setDataAtualizacao(Date dataAtualizacao) { |
||
| 169 | this.dataAtualizacao = dataAtualizacao; |
||
| 170 | } |
||
| 171 | |||
| 172 | @Column(name="tip_estoque_auditoria") |
||
| 173 | public String getTipoEstoqueAuditoria() { |
||
| 174 | return tipoEstoqueAuditoria; |
||
| 175 | } |
||
| 176 | public void setTipoEstoqueAuditoria(String tipoEstoqueAuditoria) { |
||
| 177 | this.tipoEstoqueAuditoria = tipoEstoqueAuditoria; |
||
| 178 | } |
||
| 179 | |||
| 180 | @Column(name="tip_verificacao", nullable=false) |
||
| 181 | public String getTipoVerificacao() { |
||
| 182 | return tipoVerificacao; |
||
| 183 | } |
||
| 184 | public void setTipoVerificacao(String tipoVerificacao) { |
||
| 185 | this.tipoVerificacao = tipoVerificacao; |
||
| 186 | } |
||
| 187 | |||
| 188 | @Transient |
||
| 189 | public Boolean getEhDevolucaoMesmoProduto() { |
||
| 190 | return ehDevolucaoMesmoProduto; |
||
| 191 | } |
||
| 192 | public void setEhDevolucaoMesmoProduto(Boolean ehDevolucaoMesmoProduto) { |
||
| 193 | this.ehDevolucaoMesmoProduto = ehDevolucaoMesmoProduto; |
||
| 194 | } |
||
| 195 | |||
| 196 | @Transient |
||
| 197 | public Double getValorDevolvidoCupom() { |
||
| 198 | return valorDevolvidoCupom; |
||
| 199 | } |
||
| 200 | public void setValorDevolvidoCupom(Double valorDevolvidoCupom) { |
||
| 201 | this.valorDevolvidoCupom = valorDevolvidoCupom; |
||
| 202 | } |
||
| 203 | |||
| 204 | @Transient |
||
| 205 | public Double getValorDevolvidoDinheiro() { |
||
| 206 | return valorDevolvidoDinheiro; |
||
| 207 | } |
||
| 208 | public void setValorDevolvidoDinheiro(Double valorDevolvidoDinheiro) { |
||
| 209 | this.valorDevolvidoDinheiro = valorDevolvidoDinheiro; |
||
| 210 | } |
||
| 211 | |||
| 212 | @Transient |
||
| 213 | public Double getValorDevolvidoEstorno() { |
||
| 214 | return valorDevolvidoEstorno; |
||
| 215 | } |
||
| 216 | public void setValorDevolvidoEstorno(Double valorDevolvidoEstorno) { |
||
| 217 | this.valorDevolvidoEstorno = valorDevolvidoEstorno; |
||
| 218 | } |
||
| 219 | |||
| 220 | @Transient |
||
| 221 | public Boolean aumentouEstoque() { |
||
| 222 | if (VerificadorUtil.naoEstaNulo(getQuantidadeEstoqueAnterior()) && VerificadorUtil.naoEstaNulo(getQuantidadeEstoqueNovo())) { |
||
| 223 | return getQuantidadeEstoqueAnterior() < getQuantidadeEstoqueNovo(); |
||
| 224 | } |
||
| 225 | return null; |
||
| 226 | } |
||
| 227 | |||
| 228 | @Transient |
||
| 229 | public String getTipoEstoqueAuditoriaDescricao() { |
||
| 230 | return VerificadorUtil.naoEstaNulo(getTipoEstoqueAuditoria()) ? TipoEstoqueAuditoria.parse(getTipoEstoqueAuditoria()).getDescricao() : ""; |
||
| 231 | } |
||
| 232 | |||
| 233 | @Transient |
||
| 234 | public Long getSequencialDaLoja() { |
||
| 235 | return VerificadorUtil.naoEstaNulo(getLoja()) ? getLoja().getSequencial() : null; |
||
| 236 | } |
||
| 237 | |||
| 238 | @Transient |
||
| 239 | public Boolean naoVerificado() { |
||
| 240 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoVerificacao()) ? getTipoVerificacao().equals(TipoEstoqueAuditoriaVerificacao.NAO_VERIFICADO.getValor()) : false; |
||
| 241 | } |
||
| 242 | |||
| 243 | @Transient |
||
| 244 | public Boolean verificadoSemPendencia() { |
||
| 245 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoVerificacao()) ? getTipoVerificacao().equals(TipoEstoqueAuditoriaVerificacao.VERIFICADO_SEM_PENDENCIA.getValor()) : false; |
||
| 246 | } |
||
| 247 | |||
| 248 | @Transient |
||
| 249 | public Boolean verificadoComPendencia() { |
||
| 250 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoVerificacao()) ? getTipoVerificacao().equals(TipoEstoqueAuditoriaVerificacao.VERIFICADO_COM_PENDENCIA.getValor()) : false; |
||
| 251 | } |
||
| 252 | |||
| 253 | @Transient |
||
| 254 | public String nomeDoUsuario() { |
||
| 255 | return VerificadorUtil.naoEstaNulo(getUsuario())? getUsuario().getNomeDaPessoa() : null; |
||
| 256 | } |
||
| 257 | |||
| 258 | @Transient |
||
| 259 | public String nomeDoCliente() { |
||
| 260 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getNome() : null; |
||
| 261 | } |
||
| 262 | |||
| 263 | @Transient |
||
| 264 | public String cpfCnpjDoCliente() { |
||
| 265 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getCpfCnpjFormatado() : null; |
||
| 266 | } |
||
| 267 | |||
| 268 | @Transient |
||
| 269 | public Integer getQuantidadeDiasDaAtualizacao() { |
||
| 270 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), getDataAtualizacao()); |
||
| 271 | } |
||
| 272 | |||
| 273 | @Transient |
||
| 274 | public String descricaoCompletaProduto() { |
||
| 275 | StringBuilder descricaoCompleta = new StringBuilder(); |
||
| 276 | if (VerificadorUtil.naoEstaNulo(getProduto())) { |
||
| 277 | descricaoCompleta.append(getProduto().getCodigo()); |
||
| 278 | descricaoCompleta.append(" - "); |
||
| 279 | if (this.getProduto().getTipo().equals(TipoProduto.CAPA.getValor())) { |
||
| 280 | descricaoCompleta.append("CAPA"); |
||
| 281 | } |
||
| 282 | if (!this.getProduto().getTipo().equals(TipoProduto.ACESSORIO.getValor())) { |
||
| 283 | descricaoCompleta.append(" "); |
||
| 284 | descricaoCompleta.append(this.getProduto().getDescricaoDoModelo()); |
||
| 285 | } |
||
| 286 | if (VerificadorUtil.naoEstaNuloOuVazio(this.getProduto().getEstilo())) { |
||
| 287 | descricaoCompleta.append(" "); |
||
| 288 | descricaoCompleta.append(this.getProduto().getDescricaoDoEstilo()); |
||
| 289 | } |
||
| 290 | descricaoCompleta.append(" "); |
||
| 291 | if (this.getProduto().getDescricao().length() > 50) { |
||
| 292 | descricaoCompleta.append(this.getProduto().getDescricao().substring(0, 50)); |
||
| 293 | } else { |
||
| 294 | descricaoCompleta.append(this.getProduto().getDescricao()); |
||
| 295 | } |
||
| 296 | if (VerificadorUtil.naoEstaNuloOuVazio(this.getProduto().getCor())) { |
||
| 297 | descricaoCompleta.append(" ("); |
||
| 298 | descricaoCompleta.append(this.getProduto().getDescricaoDaCor()); |
||
| 299 | descricaoCompleta.append(")"); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | return descricaoCompleta.toString(); |
||
| 303 | } |
||
| 304 | |||
| 305 | @Override |
||
| 306 | public int hashCode() { |
||
| 307 | final int prime = 31; |
||
| 308 | int result = 1; |
||
| 309 | result = prime * result |
||
| 310 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 311 | return result; |
||
| 312 | } |
||
| 313 | |||
| 314 | @Override |
||
| 315 | public boolean equals(Object obj) { |
||
| 316 | if (this == obj) |
||
| 317 | return true; |
||
| 318 | if (obj == null) |
||
| 319 | return false; |
||
| 320 | if (getClass() != obj.getClass()) |
||
| 321 | return false; |
||
| 322 | EstoqueAuditoria other = (EstoqueAuditoria) obj; |
||
| 323 | if (sequencial == null) { |
||
| 324 | if (other.sequencial != null) |
||
| 325 | return false; |
||
| 326 | } else if (!sequencial.equals(other.sequencial)) |
||
| 327 | return false; |
||
| 328 | return true; |
||
| 329 | } |
||
| 330 | |||
| 331 | } |