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 | import java.util.List; |
||
| 6 | |||
| 7 | import javax.persistence.CascadeType; |
||
| 8 | import javax.persistence.Column; |
||
| 9 | import javax.persistence.Entity; |
||
| 10 | import javax.persistence.FetchType; |
||
| 11 | import javax.persistence.GeneratedValue; |
||
| 12 | import javax.persistence.GenerationType; |
||
| 13 | import javax.persistence.Id; |
||
| 14 | import javax.persistence.JoinColumn; |
||
| 15 | import javax.persistence.ManyToOne; |
||
| 16 | import javax.persistence.OneToMany; |
||
| 17 | import javax.persistence.Table; |
||
| 18 | import javax.persistence.Transient; |
||
| 19 | import javax.validation.constraints.NotNull; |
||
| 20 | |||
| 21 | import org.hibernate.annotations.ForeignKey; |
||
| 22 | |||
| 23 | import br.com.ec.domain.model.tipos.TipoCorProduto; |
||
| 24 | import br.com.ec.domain.model.tipos.TipoEstiloProduto; |
||
| 25 | import br.com.ec.domain.model.tipos.TipoGenero; |
||
| 26 | import br.com.ec.domain.model.tipos.TipoProduto; |
||
| 27 | import br.com.ec.domain.model.tipos.TipoSituacaoPedido; |
||
| 28 | import br.edu.cesmac.core.interfaces.Alterar; |
||
| 29 | import br.edu.cesmac.core.interfaces.Cadastrar; |
||
| 30 | import br.edu.cesmac.core.util.DataUtils; |
||
| 31 | import br.edu.cesmac.core.util.StringUtil; |
||
| 32 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 33 | |||
| 34 | @Entity |
||
| 35 | @Table(name="sec_pedido", schema="sc_sec") |
||
| 36 | public class Pedido implements Serializable { |
||
| 37 | |||
| 38 | private static final long serialVersionUID = 1L; |
||
| 39 | |||
| 40 | private Long sequencial; |
||
| 41 | private Loja loja; |
||
| 42 | private Date dataPedido; |
||
| 43 | private Usuario usuarioPedido; |
||
| 44 | |||
| 45 | private Cliente cliente; |
||
| 46 | private String contatoCliente; |
||
| 47 | private Modelo modelo; |
||
| 48 | private String genero; |
||
| 49 | private String tipoProduto; |
||
| 50 | private String estiloProduto; |
||
| 51 | private String corProduto; |
||
| 52 | |||
| 53 | private String observacao; |
||
| 54 | private Usuario usuarioAtendimento; |
||
| 55 | private String tipoSituacao; |
||
| 56 | private Date dataUltimaAlteracaoSituacao; |
||
| 57 | private Date dataSolicitadoParaComprar; |
||
| 58 | |||
| 59 | private List<PedidoHistorico> historico; |
||
| 60 | private List<PedidoProduto> produtos; |
||
| 61 | |||
| 62 | @Id |
||
| 63 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 64 | @Column(name="seq_pedido", nullable=false) |
||
| 65 | public Long getSequencial() { |
||
| 66 | return sequencial; |
||
| 67 | } |
||
| 68 | public void setSequencial(Long sequencial) { |
||
| 69 | this.sequencial = sequencial; |
||
| 70 | } |
||
| 71 | |||
| 72 | @ManyToOne |
||
| 73 | @ForeignKey(name="fk_pedido_loja") |
||
| 74 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja do pedido", groups = {Cadastrar.class, Alterar.class}) |
||
| 75 | @JoinColumn(name = "seq_loja", referencedColumnName="seq_loja", nullable=false) |
||
| 76 | public Loja getLoja() { |
||
| 77 | return loja; |
||
| 78 | } |
||
| 79 | public void setLoja(Loja loja) { |
||
| 80 | this.loja = loja; |
||
| 81 | } |
||
| 82 | |||
| 83 | @ManyToOne |
||
| 84 | @ForeignKey(name="fk_pedido_usuario") |
||
| 85 | @NotNull(message = "Parâmetro obrigatório não preenchido: Usuário do pedido", groups = {Cadastrar.class, Alterar.class}) |
||
| 86 | @JoinColumn(name = "seq_usuario_pedido", nullable=false) |
||
| 87 | public Usuario getUsuarioPedido() { |
||
| 88 | return usuarioPedido; |
||
| 89 | } |
||
| 90 | public void setUsuarioPedido(Usuario usuarioPedido) { |
||
| 91 | this.usuarioPedido = usuarioPedido; |
||
| 92 | } |
||
| 93 | |||
| 94 | @ManyToOne |
||
| 95 | @ForeignKey(name="fk_pedido_usuarioatend") |
||
| 96 | @JoinColumn(name = "seq_usuario_atendimento", nullable=true) |
||
| 97 | public Usuario getUsuarioAtendimento() { |
||
| 98 | return usuarioAtendimento; |
||
| 99 | } |
||
| 100 | public void setUsuarioAtendimento(Usuario usuarioAtendimento) { |
||
| 101 | this.usuarioAtendimento = usuarioAtendimento; |
||
| 102 | } |
||
| 103 | |||
| 104 | @ManyToOne |
||
| 105 | @ForeignKey(name="fk_pedido_cliente") |
||
| 106 | // @NotNull(message = "Parâmetro obrigatório não preenchido: Cliente do pedido", groups = {Cadastrar.class, Alterar.class}) |
||
| 107 | @JoinColumn(name = "seq_cliente", referencedColumnName="seq_cliente", nullable=true) |
||
| 108 | public Cliente getCliente() { |
||
| 109 | return cliente; |
||
| 110 | } |
||
| 111 | public void setCliente(Cliente cliente) { |
||
| 112 | this.cliente = cliente; |
||
| 113 | } |
||
| 114 | |||
| 115 | @Column(name="dsc_contato_cliente") |
||
| 116 | public String getContatoCliente() { |
||
| 117 | return contatoCliente; |
||
| 118 | } |
||
| 119 | public void setContatoCliente(String contatoCliente) { |
||
| 120 | this.contatoCliente = StringUtil.setarUpperCaseComTrim(contatoCliente); |
||
| 121 | } |
||
| 122 | |||
| 123 | @ManyToOne |
||
| 124 | @ForeignKey(name="fk_pedido_modelo") |
||
| 125 | @NotNull(message = "Parâmetro obrigatório não preenchido: Modelo do produto", groups = {Cadastrar.class, Alterar.class}) |
||
| 126 | @JoinColumn(name = "seq_modelo", referencedColumnName="seq_modelo", nullable=true) |
||
| 127 | public Modelo getModelo() { |
||
| 128 | return modelo; |
||
| 129 | } |
||
| 130 | public void setModelo(Modelo modelo) { |
||
| 131 | this.modelo = modelo; |
||
| 132 | } |
||
| 133 | |||
| 134 | @NotNull(message = "Parâmetro obrigatório não preenchido: Gênero do produto", groups = {Cadastrar.class, Alterar.class}) |
||
| 135 | @Column(name="tip_genero_produto") |
||
| 136 | public String getGenero() { |
||
| 137 | return genero; |
||
| 138 | } |
||
| 139 | public void setGenero(String genero) { |
||
| 140 | this.genero = genero; |
||
| 141 | } |
||
| 142 | |||
| 143 | @Column(name="tip_tipo_produto") |
||
| 144 | public String getTipoProduto() { |
||
| 145 | return tipoProduto; |
||
| 146 | } |
||
| 147 | public void setTipoProduto(String tipoProduto) { |
||
| 148 | this.tipoProduto = tipoProduto; |
||
| 149 | } |
||
| 150 | |||
| 151 | @Column(name="tip_estilo_produto") |
||
| 152 | public String getEstiloProduto() { |
||
| 153 | return estiloProduto; |
||
| 154 | } |
||
| 155 | public void setEstiloProduto(String estiloProduto) { |
||
| 156 | this.estiloProduto = estiloProduto; |
||
| 157 | } |
||
| 158 | |||
| 159 | @Column(name="tip_cor_produto") |
||
| 160 | public String getCorProduto() { |
||
| 161 | return corProduto; |
||
| 162 | } |
||
| 163 | public void setCorProduto(String corProduto) { |
||
| 164 | this.corProduto = corProduto; |
||
| 165 | } |
||
| 166 | |||
| 167 | @Column(name="obs_pedido") |
||
| 168 | public String getObservacao() { |
||
| 169 | return observacao; |
||
| 170 | } |
||
| 171 | public void setObservacao(String observacao) { |
||
| 172 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 173 | } |
||
| 174 | |||
| 175 | @Column(name="tip_situacao") |
||
| 176 | public String getTipoSituacao() { |
||
| 177 | return tipoSituacao; |
||
| 178 | } |
||
| 179 | public void setTipoSituacao(String tipoSituacao) { |
||
| 180 | this.tipoSituacao = tipoSituacao; |
||
| 181 | } |
||
| 182 | |||
| 183 | @Column(name="dth_pedido", nullable=false) |
||
| 184 | public Date getDataPedido() { |
||
| 185 | return dataPedido; |
||
| 186 | } |
||
| 187 | public void setDataPedido(Date dataPedido) { |
||
| 188 | this.dataPedido = dataPedido; |
||
| 189 | } |
||
| 190 | |||
| 191 | @Column(name="dth_alteracao_situacao") |
||
| 192 | public Date getDataUltimaAlteracaoSituacao() { |
||
| 193 | return dataUltimaAlteracaoSituacao; |
||
| 194 | } |
||
| 195 | public void setDataUltimaAlteracaoSituacao(Date dataUltimaAlteracaoSituacao) { |
||
| 196 | this.dataUltimaAlteracaoSituacao = dataUltimaAlteracaoSituacao; |
||
| 197 | } |
||
| 198 | |||
| 199 | @Column(name="dth_solicitacao_compra") |
||
| 200 | public Date getDataSolicitadoParaComprar() { |
||
| 201 | return dataSolicitadoParaComprar; |
||
| 202 | } |
||
| 203 | public void setDataSolicitadoParaComprar(Date dataSolicitadoParaComprar) { |
||
| 204 | this.dataSolicitadoParaComprar = dataSolicitadoParaComprar; |
||
| 205 | } |
||
| 206 | |||
| 207 | @OneToMany(mappedBy="pedido", cascade=CascadeType.ALL, orphanRemoval=true) |
||
| 208 | public List<PedidoHistorico> getHistorico() { |
||
| 209 | return historico; |
||
| 210 | } |
||
| 211 | public void setHistorico(List<PedidoHistorico> historico) { |
||
| 212 | this.historico = historico; |
||
| 213 | } |
||
| 214 | |||
| 215 | @OneToMany(mappedBy="pedido", cascade=CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true) |
||
| 216 | public List<PedidoProduto> getProdutos() { |
||
| 217 | return produtos; |
||
| 218 | } |
||
| 219 | public void setProdutos(List<PedidoProduto> produtos) { |
||
| 220 | this.produtos = produtos; |
||
| 221 | } |
||
| 222 | |||
| 223 | @Override |
||
| 224 | public int hashCode() { |
||
| 225 | final int prime = 31; |
||
| 226 | int result = 1; |
||
| 227 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 228 | return result; |
||
| 229 | } |
||
| 230 | |||
| 231 | @Override |
||
| 232 | public boolean equals(Object obj) { |
||
| 233 | if (this == obj) |
||
| 234 | return true; |
||
| 235 | if (obj == null) |
||
| 236 | return false; |
||
| 237 | if (getClass() != obj.getClass()) |
||
| 238 | return false; |
||
| 239 | Pedido other = (Pedido) obj; |
||
| 240 | if (sequencial == null) { |
||
| 241 | if (other.sequencial != null) |
||
| 242 | return false; |
||
| 243 | } else if (!sequencial.equals(other.sequencial)) |
||
| 244 | return false; |
||
| 245 | return true; |
||
| 246 | } |
||
| 247 | |||
| 248 | @Transient |
||
| 249 | public String getDescricaoDoModelo() { |
||
| 250 | return VerificadorUtil.naoEstaNulo(modelo)? modelo.getDescricao() : ""; |
||
| 251 | } |
||
| 252 | |||
| 253 | @Transient |
||
| 254 | public String getDescricaoDoTipoProduto() { |
||
| 255 | return VerificadorUtil.naoEstaNulo(tipoProduto)? TipoProduto.parse(tipoProduto).getDescricao() : ""; |
||
| 256 | } |
||
| 257 | |||
| 258 | @Transient |
||
| 259 | public String getDescricaoDoEstiloProduto() { |
||
| 260 | return VerificadorUtil.naoEstaNulo(estiloProduto)? TipoEstiloProduto.parse(estiloProduto).getDescricao() : ""; |
||
| 261 | } |
||
| 262 | |||
| 263 | @Transient |
||
| 264 | public String getDescricaoDaCorProduto() { |
||
| 265 | return VerificadorUtil.naoEstaNulo(corProduto)? TipoCorProduto.parse(corProduto).getDescricao() : ""; |
||
| 266 | } |
||
| 267 | |||
| 268 | @Transient |
||
| 269 | public String getDescricaoDoGeneroProduto() { |
||
| 270 | return VerificadorUtil.naoEstaNulo(genero)? TipoGenero.parse(genero).getDescricao() : ""; |
||
| 271 | } |
||
| 272 | |||
| 273 | @Transient |
||
| 274 | public String getNomeDoCliente() { |
||
| 275 | return VerificadorUtil.naoEstaNulo(cliente)? cliente.getNome() : ""; |
||
| 276 | } |
||
| 277 | |||
| 278 | @Transient |
||
| 279 | public String getContatoDoCliente() { |
||
| 280 | return VerificadorUtil.naoEstaNulo(cliente)? cliente.getContato() : ""; |
||
| 281 | } |
||
| 282 | |||
| 283 | @Transient |
||
| 284 | public String getInformacoesBasicasDoCliente() { |
||
| 285 | return VerificadorUtil.naoEstaNulo(cliente)? getNomeDoCliente() + " " + getContatoCliente(): getContatoCliente(); |
||
| 286 | } |
||
| 287 | |||
| 288 | /* |
||
| 289 | @Transient |
||
| 290 | public String getDescricaoComModeloCompleta() { |
||
| 291 | String descricaoCompleta = ""; |
||
| 292 | if (VerificadorUtil.naoEstaNuloOuVazio(getDescricaoDoModelo())) { |
||
| 293 | descricaoCompleta = getDescricaoDoModelo() + " - "; |
||
| 294 | } |
||
| 295 | return descricaoCompleta + getDescricao(); |
||
| 296 | } |
||
| 297 | */ |
||
| 298 | |||
| 299 | @Transient |
||
| 300 | public Long getSequencialDoModelo() { |
||
| 301 | return VerificadorUtil.naoEstaNulo(modelo)? modelo.getSequencial() : null; |
||
| 302 | } |
||
| 303 | |||
| 304 | @Transient |
||
| 305 | public Long getSequencialDaLoja() { |
||
| 306 | return VerificadorUtil.naoEstaNulo(loja)? loja.getSequencial() : null; |
||
| 307 | } |
||
| 308 | |||
| 309 | @Transient |
||
| 310 | public String getDescricaoDaLoja() { |
||
| 311 | return VerificadorUtil.naoEstaNulo(loja)? loja.getDescricao() : null; |
||
| 312 | } |
||
| 313 | |||
| 314 | @Transient |
||
| 315 | public Boolean foiAtendido() { |
||
| 316 | return TipoSituacaoPedido.FINALIZADO.getValor().equals(tipoSituacao) || |
||
| 317 | TipoSituacaoPedido.FINALIZADO_COM_VENDAS.getValor().equals(tipoSituacao); |
||
| 318 | } |
||
| 319 | |||
| 320 | @Transient |
||
| 321 | public String getDescricaoDaSituacao() { |
||
| 322 | return TipoSituacaoPedido.parse(getTipoSituacao()).getDescricao(); |
||
| 323 | } |
||
| 324 | |||
| 325 | @Transient |
||
| 326 | public Integer getQuantidadeDiasPedido() { |
||
| 327 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), getDataPedido()); |
||
| 328 | } |
||
| 329 | |||
| 330 | @Transient |
||
| 331 | public Integer getQuantidadeDiasAtendimento() { |
||
| 332 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), getDataUltimaAlteracaoSituacao()); |
||
| 333 | } |
||
| 334 | |||
| 335 | @Transient |
||
| 336 | public String getImagemCronometroPedido() { |
||
| 337 | Integer quantidadeDias = getQuantidadeDiasPedido(); |
||
| 338 | if (quantidadeDias < 15) { |
||
| 339 | return "cronometro_verde_sembg"; |
||
| 340 | } |
||
| 341 | if (quantidadeDias < 30) { |
||
| 342 | return "cronometro_amarelo_sembg"; |
||
| 343 | } |
||
| 344 | return "cronometro_vermelho_sembg"; |
||
| 345 | } |
||
| 346 | |||
| 347 | @Transient |
||
| 348 | public String getCorSituacaoPedido() { |
||
| 349 | return getTipoSituacao().equals(TipoSituacaoPedido.NOVO.getValor())? "gray" : |
||
| 350 | getTipoSituacao().equals(TipoSituacaoPedido.ENTRAR_EM_CONTATO.getValor())? "#c5c536" : |
||
| 351 | getTipoSituacao().equals(TipoSituacaoPedido.AGUARDANDO_RETORNO_CLIENTE.getValor())? "#3399CC" : |
||
| 352 | getTipoSituacao().equals(TipoSituacaoPedido.PENDENTE.getValor())? "orange" : |
||
| 353 | getTipoSituacao().equals(TipoSituacaoPedido.FINALIZADO.getValor())? "green" : |
||
| 354 | getTipoSituacao().equals(TipoSituacaoPedido.FINALIZADO_COM_VENDAS.getValor())? "green" : "black"; |
||
| 355 | } |
||
| 356 | |||
| 357 | @Transient |
||
| 358 | public String getCorPedido() { |
||
| 359 | Integer quantidadeDias = getQuantidadeDiasPedido(); |
||
| 360 | if (quantidadeDias < 15) { |
||
| 361 | return "green"; |
||
| 362 | } |
||
| 363 | return "red"; |
||
| 364 | } |
||
| 365 | |||
| 366 | @Transient |
||
| 367 | public String getCorPedidoAtendimento() { |
||
| 368 | Integer quantidadeDias = getQuantidadeDiasAtendimento(); |
||
| 369 | if (quantidadeDias < 15) { |
||
| 370 | return "green"; |
||
| 371 | } |
||
| 372 | return "red"; |
||
| 373 | } |
||
| 374 | |||
| 375 | @Transient |
||
| 376 | public Double getValorTotalProdutos() { |
||
| 377 | Double total = 0.0; |
||
| 378 | if (VerificadorUtil.naoEstaNuloOuVazio(getProdutos())) { |
||
| 379 | for (PedidoProduto pedidoProduto : getProdutos()) { |
||
| 380 | if (VerificadorUtil.naoEstaNulo(pedidoProduto.getValor())) { |
||
| 381 | total = total + (pedidoProduto.getValor() * pedidoProduto.getQuantidade()); |
||
| 382 | } |
||
| 383 | } |
||
| 384 | } |
||
| 385 | return total; |
||
| 386 | } |
||
| 387 | |||
| 388 | } |