Rev 538 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 535 | blopes | 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.SequenceGenerator; |
||
| 14 | import javax.persistence.Table; |
||
| 15 | import javax.persistence.Transient; |
||
| 16 | import javax.validation.constraints.NotNull; |
||
| 17 | import javax.validation.constraints.Size; |
||
| 18 | |||
| 19 | import org.hibernate.annotations.ForeignKey; |
||
| 20 | |||
| 21 | import br.com.ec.core.generic.identidade.Identidade; |
||
| 22 | import br.com.ec.core.interfaces.Alterar; |
||
| 23 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 24 | import br.com.ec.core.util.DataUtils; |
||
| 25 | import br.com.ec.core.util.StringUtil; |
||
| 26 | import br.com.ec.core.util.VerificadorUtil; |
||
| 27 | import br.com.ec.domain.model.tipos.TipoDevolucao; |
||
| 28 | import br.com.ec.domain.model.tipos.TipoEstoqueAuditoria; |
||
| 29 | import br.com.ec.domain.model.tipos.TipoEstoqueAuditoriaVerificacao; |
||
| 30 | import br.com.ec.domain.model.tipos.TipoProduto; |
||
| 31 | |||
| 32 | @Entity |
||
| 33 | @Table(name="sec_estoque_auditoria", schema="sc_sec") |
||
| 34 | public class EstoqueAuditoria implements Serializable, Identidade { |
||
| 35 | |||
| 36 | private static final long serialVersionUID = 1L; |
||
| 37 | |||
| 38 | private Long sequencial; |
||
| 39 | private Usuario usuario; |
||
| 40 | private Produto produto; |
||
| 41 | private Loja loja; |
||
| 42 | // private Cliente cliente; |
||
| 43 | private Integer quantidadeEstoqueAnterior; |
||
| 44 | private Integer quantidadeEstoqueNovo; |
||
| 45 | private String observacao; |
||
| 46 | private String auditoria; |
||
| 47 | private Date dataAtualizacao; |
||
| 48 | private String tipoEstoqueAuditoria; |
||
| 49 | private String tipoVerificacao; |
||
| 50 | private Usuario usuarioVerificacao; |
||
| 51 | |||
| 52 | private Long sequencialVenda; |
||
| 53 | private Long sequencialPedido; |
||
| 54 | private Pedido pedidoParaVincular; |
||
| 55 | private Date dataVenda; |
||
| 56 | private Loja lojaVenda; |
||
| 57 | private String tipoDevolucao; |
||
| 58 | private Double valorDevolvido; |
||
| 59 | private String dadosBancarios; |
||
| 60 | private String numeroNotaFiscal; |
||
| 61 | private String numeroLote; |
||
| 62 | private Boolean ehDevolucaoMesmoProduto; |
||
| 63 | |||
| 64 | public EstoqueAuditoria() { |
||
| 65 | setEhDevolucaoMesmoProduto(false); |
||
| 66 | setValorDevolvido(new Double(0.0)); |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | @Transient |
||
| 71 | public Object getId() { |
||
| 72 | return this.getSequencial(); |
||
| 73 | } |
||
| 74 | @Override |
||
| 75 | public void setId(Object id) { |
||
| 76 | this.sequencial = (Long) id; |
||
| 77 | } |
||
| 78 | |||
| 79 | @Id |
||
| 80 | @SequenceGenerator(name = "sq_estoqueaudit") |
||
| 81 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 82 | @Column(name="seq_estoque_auditoria", nullable=false) |
||
| 83 | public Long getSequencial() { |
||
| 84 | return sequencial; |
||
| 85 | } |
||
| 86 | public void setSequencial(Long sequencial) { |
||
| 87 | this.sequencial = sequencial; |
||
| 88 | } |
||
| 89 | |||
| 90 | @ManyToOne |
||
| 91 | @ForeignKey(name="fk_estoqueaudit_usuario") |
||
| 92 | @JoinColumn(name = "seq_usuario", nullable=true) |
||
| 93 | public Usuario getUsuario() { |
||
| 94 | return usuario; |
||
| 95 | } |
||
| 96 | public void setUsuario(Usuario usuario) { |
||
| 97 | this.usuario = usuario; |
||
| 98 | } |
||
| 99 | |||
| 100 | @ManyToOne |
||
| 101 | @ForeignKey(name="fk_estoqueaudit_usuarioverificacao") |
||
| 102 | @JoinColumn(name = "seq_usuario_verificacao", nullable=true) |
||
| 103 | public Usuario getUsuarioVerificacao() { |
||
| 104 | return usuarioVerificacao; |
||
| 105 | } |
||
| 106 | public void setUsuarioVerificacao(Usuario usuarioVerificacao) { |
||
| 107 | this.usuarioVerificacao = usuarioVerificacao; |
||
| 108 | } |
||
| 109 | |||
| 110 | @ManyToOne |
||
| 111 | @ForeignKey(name="fk_estoqueaudit_produto") |
||
| 112 | @JoinColumn(name = "seq_produto", nullable=true) |
||
| 113 | public Produto getProduto() { |
||
| 114 | return produto; |
||
| 115 | } |
||
| 116 | public void setProduto(Produto produto) { |
||
| 117 | this.produto = produto; |
||
| 118 | } |
||
| 119 | |||
| 120 | @ManyToOne |
||
| 121 | @ForeignKey(name="fk_estoqueaudit_loja") |
||
| 122 | @JoinColumn(name = "seq_loja", nullable=true) |
||
| 123 | public Loja getLoja() { |
||
| 124 | return loja; |
||
| 125 | } |
||
| 126 | public void setLoja(Loja loja) { |
||
| 127 | this.loja = loja; |
||
| 128 | } |
||
| 129 | |||
| 130 | /* |
||
| 131 | @ManyToOne |
||
| 132 | @ForeignKey(name="fk_estoqueaudit_cliente") |
||
| 133 | @JoinColumn(name = "seq_cliente", nullable=true) |
||
| 134 | public Cliente getCliente() { |
||
| 135 | return cliente; |
||
| 136 | } |
||
| 137 | public void setCliente(Cliente cliente) { |
||
| 138 | this.cliente = cliente; |
||
| 139 | } |
||
| 140 | */ |
||
| 141 | |||
| 142 | @Column(name="qtd_estoque_anterior") |
||
| 143 | public Integer getQuantidadeEstoqueAnterior() { |
||
| 144 | return quantidadeEstoqueAnterior; |
||
| 145 | } |
||
| 146 | public void setQuantidadeEstoqueAnterior(Integer quantidadeEstoqueAnterior) { |
||
| 147 | this.quantidadeEstoqueAnterior = quantidadeEstoqueAnterior; |
||
| 148 | } |
||
| 149 | |||
| 150 | @Column(name="qtd_estoque_novo") |
||
| 151 | public Integer getQuantidadeEstoqueNovo() { |
||
| 152 | return quantidadeEstoqueNovo; |
||
| 153 | } |
||
| 154 | public void setQuantidadeEstoqueNovo(Integer quantidadeEstoqueNovo) { |
||
| 155 | this.quantidadeEstoqueNovo = quantidadeEstoqueNovo; |
||
| 156 | } |
||
| 157 | |||
| 158 | @Column(name="dsc_observacao") |
||
| 159 | @Size(max = 400, message = "Limite de caracteres ultrapassado: Observação") |
||
| 160 | public String getObservacao() { |
||
| 161 | return observacao; |
||
| 162 | } |
||
| 163 | public void setObservacao(String observacao) { |
||
| 164 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 165 | } |
||
| 166 | |||
| 167 | @Column(name="dsc_auditoria") |
||
| 168 | @Size(max = 400, message = "Limite de caracteres ultrapassado: Descrição da Auditoria") |
||
| 169 | public String getAuditoria() { |
||
| 170 | return auditoria; |
||
| 171 | } |
||
| 172 | public void setAuditoria(String auditoria) { |
||
| 173 | this.auditoria = StringUtil.setarUpperCaseComTrim(auditoria); |
||
| 174 | } |
||
| 175 | |||
| 176 | @NotNull(message="Obrigatório informar a data do ocorrido", groups={Cadastrar.class, Alterar.class}) |
||
| 177 | @Column(name="dth_atualizacao", nullable=false) |
||
| 178 | public Date getDataAtualizacao() { |
||
| 179 | return dataAtualizacao; |
||
| 180 | } |
||
| 181 | public void setDataAtualizacao(Date dataAtualizacao) { |
||
| 182 | this.dataAtualizacao = dataAtualizacao; |
||
| 183 | } |
||
| 184 | |||
| 185 | @Column(name="tip_estoque_auditoria") |
||
| 186 | public String getTipoEstoqueAuditoria() { |
||
| 187 | return tipoEstoqueAuditoria; |
||
| 188 | } |
||
| 189 | public void setTipoEstoqueAuditoria(String tipoEstoqueAuditoria) { |
||
| 190 | this.tipoEstoqueAuditoria = tipoEstoqueAuditoria; |
||
| 191 | } |
||
| 192 | |||
| 193 | @Column(name="tip_verificacao", nullable=false) |
||
| 194 | public String getTipoVerificacao() { |
||
| 195 | return tipoVerificacao; |
||
| 196 | } |
||
| 197 | public void setTipoVerificacao(String tipoVerificacao) { |
||
| 198 | this.tipoVerificacao = tipoVerificacao; |
||
| 199 | } |
||
| 200 | |||
| 201 | @Transient |
||
| 202 | public Long getSequencialVenda() { |
||
| 203 | return sequencialVenda; |
||
| 204 | } |
||
| 205 | public void setSequencialVenda(Long sequencialVenda) { |
||
| 206 | this.sequencialVenda = sequencialVenda; |
||
| 207 | } |
||
| 208 | |||
| 209 | @Transient |
||
| 210 | public Long getSequencialPedido() { |
||
| 211 | return sequencialPedido; |
||
| 212 | } |
||
| 213 | public void setSequencialPedido(Long sequencialPedido) { |
||
| 214 | this.sequencialPedido = sequencialPedido; |
||
| 215 | } |
||
| 216 | |||
| 217 | @Transient |
||
| 218 | public Pedido getPedidoParaVincular() { |
||
| 219 | return pedidoParaVincular; |
||
| 220 | } |
||
| 221 | public void setPedidoParaVincular(Pedido pedidoParaVincular) { |
||
| 222 | this.pedidoParaVincular = pedidoParaVincular; |
||
| 223 | } |
||
| 224 | |||
| 225 | @Transient |
||
| 226 | public Date getDataVenda() { |
||
| 227 | return dataVenda; |
||
| 228 | } |
||
| 229 | public void setDataVenda(Date dataVenda) { |
||
| 230 | this.dataVenda = dataVenda; |
||
| 231 | } |
||
| 232 | |||
| 233 | @Transient |
||
| 234 | public Loja getLojaVenda() { |
||
| 235 | return lojaVenda; |
||
| 236 | } |
||
| 237 | public void setLojaVenda(Loja lojaVenda) { |
||
| 238 | this.lojaVenda = lojaVenda; |
||
| 239 | } |
||
| 240 | |||
| 241 | @Transient |
||
| 242 | public String getTipoDevolucao() { |
||
| 243 | return tipoDevolucao; |
||
| 244 | } |
||
| 245 | public void setTipoDevolucao(String tipoDevolucao) { |
||
| 246 | this.tipoDevolucao = tipoDevolucao; |
||
| 247 | } |
||
| 248 | |||
| 249 | @Transient |
||
| 250 | public Double getValorDevolvido() { |
||
| 251 | return valorDevolvido; |
||
| 252 | } |
||
| 253 | public void setValorDevolvido(Double valorDevolvido) { |
||
| 254 | this.valorDevolvido = valorDevolvido; |
||
| 255 | } |
||
| 256 | |||
| 257 | @Transient |
||
| 258 | public String getDadosBancarios() { |
||
| 259 | return dadosBancarios; |
||
| 260 | } |
||
| 261 | public void setDadosBancarios(String dadosBancarios) { |
||
| 262 | this.dadosBancarios = StringUtil.setarUpperCaseComTrim(dadosBancarios); |
||
| 263 | } |
||
| 264 | |||
| 265 | @Transient |
||
| 266 | public String getNumeroNotaFiscal() { |
||
| 267 | return numeroNotaFiscal; |
||
| 268 | } |
||
| 269 | public void setNumeroNotaFiscal(String numeroNotaFiscal) { |
||
| 270 | this.numeroNotaFiscal = numeroNotaFiscal; |
||
| 271 | } |
||
| 272 | |||
| 273 | @Transient |
||
| 274 | public String getNumeroLote() { |
||
| 275 | return numeroLote; |
||
| 276 | } |
||
| 277 | public void setNumeroLote(String numeroLote) { |
||
| 278 | this.numeroLote = numeroLote; |
||
| 279 | } |
||
| 280 | |||
| 281 | @Transient |
||
| 282 | public Boolean getEhDevolucaoMesmoProduto() { |
||
| 283 | return ehDevolucaoMesmoProduto; |
||
| 284 | } |
||
| 285 | public void setEhDevolucaoMesmoProduto(Boolean ehDevolucaoMesmoProduto) { |
||
| 286 | this.ehDevolucaoMesmoProduto = ehDevolucaoMesmoProduto; |
||
| 287 | } |
||
| 288 | |||
| 289 | @Transient |
||
| 290 | public Boolean aumentouEstoque() { |
||
| 291 | if (VerificadorUtil.naoEstaNulo(getQuantidadeEstoqueAnterior()) && VerificadorUtil.naoEstaNulo(getQuantidadeEstoqueNovo())) { |
||
| 292 | return getQuantidadeEstoqueAnterior() < getQuantidadeEstoqueNovo(); |
||
| 293 | } |
||
| 294 | return null; |
||
| 295 | } |
||
| 296 | |||
| 297 | @Transient |
||
| 298 | public String getTipoEstoqueAuditoriaDescricao() { |
||
| 299 | return VerificadorUtil.naoEstaNulo(getTipoEstoqueAuditoria()) ? TipoEstoqueAuditoria.parse(getTipoEstoqueAuditoria()).getDescricao() : ""; |
||
| 300 | } |
||
| 301 | |||
| 302 | @Transient |
||
| 303 | public Long getSequencialDaLoja() { |
||
| 304 | return VerificadorUtil.naoEstaNulo(getLoja()) ? getLoja().getSequencial() : null; |
||
| 305 | } |
||
| 306 | |||
| 307 | @Transient |
||
| 308 | public Boolean naoVerificado() { |
||
| 309 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoVerificacao()) ? getTipoVerificacao().equals(TipoEstoqueAuditoriaVerificacao.NAO_VERIFICADO.getValor()) : false; |
||
| 310 | } |
||
| 311 | |||
| 312 | @Transient |
||
| 313 | public Boolean verificadoSemPendencia() { |
||
| 314 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoVerificacao()) ? getTipoVerificacao().equals(TipoEstoqueAuditoriaVerificacao.VERIFICADO_SEM_PENDENCIA.getValor()) : false; |
||
| 315 | } |
||
| 316 | |||
| 317 | @Transient |
||
| 318 | public Boolean verificadoComPendencia() { |
||
| 319 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoVerificacao()) ? getTipoVerificacao().equals(TipoEstoqueAuditoriaVerificacao.VERIFICADO_COM_PENDENCIA.getValor()) : false; |
||
| 320 | } |
||
| 321 | |||
| 322 | @Transient |
||
| 323 | public Boolean ehTipoDevolucaoPorTransferencia() { |
||
| 324 | return VerificadorUtil.naoEstaNuloOuVazio(getTipoDevolucao()) ? getTipoDevolucao().equals(TipoDevolucao.TRANSFERENCIA.getValor()) : false; |
||
| 325 | } |
||
| 326 | |||
| 327 | @Transient |
||
| 328 | public String nomeDoUsuario() { |
||
| 329 | return VerificadorUtil.naoEstaNulo(getUsuario())? getUsuario().getNomeDaPessoa() : null; |
||
| 330 | } |
||
| 331 | |||
| 332 | /* |
||
| 333 | @Transient |
||
| 334 | public String nomeDoCliente() { |
||
| 335 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getNome() : null; |
||
| 336 | } |
||
| 337 | |||
| 338 | @Transient |
||
| 339 | public String cpfCnpjDoCliente() { |
||
| 340 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getCpfCnpjFormatado() : null; |
||
| 341 | } |
||
| 342 | */ |
||
| 343 | |||
| 344 | @Transient |
||
| 345 | public Integer getQuantidadeDiasDaAtualizacao() { |
||
| 346 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), getDataAtualizacao()); |
||
| 347 | } |
||
| 348 | |||
| 349 | @Transient |
||
| 350 | public String descricaoCompletaProduto() { |
||
| 351 | StringBuilder descricaoCompleta = new StringBuilder(); |
||
| 352 | if (VerificadorUtil.naoEstaNulo(getProduto())) { |
||
| 353 | descricaoCompleta.append(getProduto().getCodigo()); |
||
| 354 | descricaoCompleta.append(" - "); |
||
| 355 | if (this.getProduto().getTipo().equals(TipoProduto.CAPA.getValor())) { |
||
| 356 | descricaoCompleta.append("CAPA"); |
||
| 357 | } |
||
| 358 | if (!this.getProduto().getTipo().equals(TipoProduto.ACESSORIO.getValor())) { |
||
| 359 | descricaoCompleta.append(" "); |
||
| 360 | descricaoCompleta.append(this.getProduto().getDescricaoDoModelo()); |
||
| 361 | } |
||
| 362 | if (VerificadorUtil.naoEstaNuloOuVazio(this.getProduto().getEstilo())) { |
||
| 363 | descricaoCompleta.append(" "); |
||
| 364 | descricaoCompleta.append(this.getProduto().getDescricaoDoEstilo()); |
||
| 365 | } |
||
| 366 | descricaoCompleta.append(" "); |
||
| 367 | if (this.getProduto().getDescricao().length() > 50) { |
||
| 368 | descricaoCompleta.append(this.getProduto().getDescricao().substring(0, 50)); |
||
| 369 | } else { |
||
| 370 | descricaoCompleta.append(this.getProduto().getDescricao()); |
||
| 371 | } |
||
| 372 | if (VerificadorUtil.naoEstaNuloOuVazio(this.getProduto().getCor())) { |
||
| 373 | descricaoCompleta.append(" ("); |
||
| 374 | descricaoCompleta.append(this.getProduto().getDescricaoDaCor()); |
||
| 375 | descricaoCompleta.append(")"); |
||
| 376 | } |
||
| 377 | } |
||
| 378 | return descricaoCompleta.toString(); |
||
| 379 | } |
||
| 380 | |||
| 381 | @Override |
||
| 382 | public int hashCode() { |
||
| 383 | final int prime = 31; |
||
| 384 | int result = 1; |
||
| 385 | result = prime * result |
||
| 386 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 387 | return result; |
||
| 388 | } |
||
| 389 | |||
| 390 | @Override |
||
| 391 | public boolean equals(Object obj) { |
||
| 392 | if (this == obj) |
||
| 393 | return true; |
||
| 394 | if (obj == null) |
||
| 395 | return false; |
||
| 396 | if (getClass() != obj.getClass()) |
||
| 397 | return false; |
||
| 398 | EstoqueAuditoria other = (EstoqueAuditoria) obj; |
||
| 399 | if (sequencial == null) { |
||
| 400 | if (other.sequencial != null) |
||
| 401 | return false; |
||
| 402 | } else if (!sequencial.equals(other.sequencial)) |
||
| 403 | return false; |
||
| 404 | return true; |
||
| 405 | } |
||
| 406 | |||
| 407 | @Transient |
||
| 408 | public String getDescricaoDaLoja() { |
||
| 409 | return VerificadorUtil.naoEstaNuloOuVazio(getLoja())? getLoja().getDescricao() : ""; |
||
| 410 | } |
||
| 411 | |||
| 412 | } |