Rev 235 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.Collections; |
||
| 6 | import java.util.Comparator; |
||
| 7 | import java.util.Date; |
||
| 8 | import java.util.List; |
||
| 9 | |||
| 10 | import javax.persistence.CascadeType; |
||
| 11 | import javax.persistence.Column; |
||
| 12 | import javax.persistence.Entity; |
||
| 13 | import javax.persistence.GeneratedValue; |
||
| 14 | import javax.persistence.GenerationType; |
||
| 15 | import javax.persistence.Id; |
||
| 16 | import javax.persistence.JoinColumn; |
||
| 17 | import javax.persistence.ManyToOne; |
||
| 18 | import javax.persistence.OneToMany; |
||
| 19 | import javax.persistence.SequenceGenerator; |
||
| 20 | import javax.persistence.Table; |
||
| 21 | import javax.persistence.Transient; |
||
| 22 | import javax.validation.constraints.NotNull; |
||
| 23 | |||
| 24 | import org.hibernate.annotations.ForeignKey; |
||
| 25 | |||
| 195 | espaco | 26 | import br.com.ec.core.generic.identidade.Identidade; |
| 27 | import br.com.ec.core.interfaces.Alterar; |
||
| 28 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 231 | espaco | 29 | import br.com.ec.core.util.DataUtils; |
| 195 | espaco | 30 | import br.com.ec.core.util.VerificadorUtil; |
| 106 | espaco | 31 | import br.com.ec.domain.dto.TransferenciaProdutoDTO; |
| 235 | espaco | 32 | import br.com.ec.domain.model.tipos.TipoProduto; |
| 106 | espaco | 33 | |
| 34 | @Entity |
||
| 35 | @Table(name="sec_transferencia", schema="sc_sec") |
||
| 36 | public class Transferencia implements Serializable, Identidade { |
||
| 37 | |||
| 38 | private static final long serialVersionUID = 1L; |
||
| 39 | |||
| 40 | private Long sequencial; |
||
| 41 | private Loja lojaSaida; |
||
| 42 | private Loja lojaEntrada; |
||
| 43 | private Date dataSolicitacao; |
||
| 44 | private Boolean conferido; |
||
| 45 | private Date dataFinalizacao; |
||
| 46 | private NotaFiscal notaFiscalRemessa; |
||
| 231 | espaco | 47 | private Date dataHoraInicioTransporte; |
| 48 | private Usuario usuarioTransportador; |
||
| 49 | private Usuario usuarioReceptor; |
||
| 106 | espaco | 50 | |
| 51 | private List<TransferenciaProduto> listaProdutos; |
||
| 52 | private List<TransferenciaProdutoDTO> produtosDTO; |
||
| 53 | |||
| 54 | @Override |
||
| 55 | @Transient |
||
| 56 | public Object getId() { |
||
| 57 | return this.getSequencial(); |
||
| 58 | } |
||
| 59 | @Override |
||
| 60 | public void setId(Object id) { |
||
| 61 | this.sequencial = (Long) id; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Id |
||
| 65 | @SequenceGenerator(name = "sq_transferencia") |
||
| 66 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 67 | @Column(name="seq_transferencia", nullable=false) |
||
| 68 | public Long getSequencial() { |
||
| 69 | return sequencial; |
||
| 70 | } |
||
| 71 | public void setSequencial(Long sequencial) { |
||
| 72 | this.sequencial = sequencial; |
||
| 73 | } |
||
| 74 | |||
| 75 | @ManyToOne |
||
| 76 | @ForeignKey(name="fk_transferencia_loja_saida") |
||
| 77 | @JoinColumn(name = "seq_loja_saida", nullable = false) |
||
| 78 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de saída", groups = {Cadastrar.class, Alterar.class}) |
||
| 79 | public Loja getLojaSaida() { |
||
| 80 | return lojaSaida; |
||
| 81 | } |
||
| 82 | public void setLojaSaida(Loja lojaSaida) { |
||
| 83 | this.lojaSaida = lojaSaida; |
||
| 84 | } |
||
| 85 | |||
| 86 | @ManyToOne |
||
| 87 | @ForeignKey(name="fk_transferencia_loja_entrada") |
||
| 88 | @JoinColumn(name = "seq_loja_entrada", nullable = false) |
||
| 89 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de destino", groups = {Cadastrar.class, Alterar.class}) |
||
| 90 | public Loja getLojaEntrada() { |
||
| 91 | return lojaEntrada; |
||
| 92 | } |
||
| 93 | public void setLojaEntrada(Loja lojaEntrada) { |
||
| 94 | this.lojaEntrada = lojaEntrada; |
||
| 95 | } |
||
| 96 | |||
| 97 | @NotNull(message = "Parâmetro obrigatório não preenchido: Data da Solicitação", groups = {Cadastrar.class, Alterar.class}) |
||
| 98 | @Column(name="dat_solicitacao") |
||
| 99 | public Date getDataSolicitacao() { |
||
| 100 | return dataSolicitacao; |
||
| 101 | } |
||
| 102 | public void setDataSolicitacao(Date dataSolicitacao) { |
||
| 103 | this.dataSolicitacao = dataSolicitacao; |
||
| 104 | } |
||
| 105 | |||
| 305 | espaco | 106 | @Column(name="ind_conferido") |
| 106 | espaco | 107 | @NotNull(message = "Parâmetro obrigatório não preenchido: Transferência conferida", groups = {Cadastrar.class, Alterar.class}) |
| 108 | public Boolean getConferido() { |
||
| 109 | return conferido; |
||
| 110 | } |
||
| 111 | public void setConferido(Boolean conferido) { |
||
| 112 | this.conferido = conferido; |
||
| 113 | } |
||
| 114 | |||
| 115 | @Column(name="dat_finalizacao") |
||
| 116 | public Date getDataFinalizacao() { |
||
| 117 | return dataFinalizacao; |
||
| 118 | } |
||
| 119 | public void setDataFinalizacao(Date dataFinalizacao) { |
||
| 120 | this.dataFinalizacao = dataFinalizacao; |
||
| 121 | } |
||
| 122 | |||
| 123 | @ManyToOne |
||
| 124 | @ForeignKey(name="fk_transferencia_notafiscalremessa") |
||
| 125 | @JoinColumn(name = "seq_nota_fiscal") |
||
| 126 | public NotaFiscal getNotaFiscalRemessa() { |
||
| 127 | return notaFiscalRemessa; |
||
| 128 | } |
||
| 129 | public void setNotaFiscalRemessa(NotaFiscal notaFiscalRemessa) { |
||
| 130 | this.notaFiscalRemessa = notaFiscalRemessa; |
||
| 131 | } |
||
| 132 | |||
| 231 | espaco | 133 | @Column(name="dth_inicio_transporte") |
| 134 | public Date getDataHoraInicioTransporte() { |
||
| 135 | return dataHoraInicioTransporte; |
||
| 136 | } |
||
| 137 | public void setDataHoraInicioTransporte(Date dataHoraInicioTransporte) { |
||
| 138 | this.dataHoraInicioTransporte = dataHoraInicioTransporte; |
||
| 139 | } |
||
| 140 | public String dataHoraInicioTransporteFormatado() { |
||
| 141 | return DataUtils.converterDataComHorarioParaString(getDataHoraInicioTransporte()); |
||
| 142 | } |
||
| 143 | |||
| 144 | @ManyToOne |
||
| 145 | @ForeignKey(name="fk_transferencia_usuairo_transportador") |
||
| 146 | @JoinColumn(name = "seq_usuario_transportador", nullable = true) |
||
| 147 | public Usuario getUsuarioTransportador() { |
||
| 148 | return usuarioTransportador; |
||
| 149 | } |
||
| 150 | public void setUsuarioTransportador(Usuario usuarioTransportador) { |
||
| 151 | this.usuarioTransportador = usuarioTransportador; |
||
| 152 | } |
||
| 153 | |||
| 154 | @ManyToOne |
||
| 155 | @ForeignKey(name="fk_transferencia_usuairo_receptor") |
||
| 156 | @JoinColumn(name = "seq_usuario_receptor", nullable = true) |
||
| 157 | public Usuario getUsuarioReceptor() { |
||
| 158 | return usuarioReceptor; |
||
| 159 | } |
||
| 160 | public void setUsuarioReceptor(Usuario usuarioReceptor) { |
||
| 161 | this.usuarioReceptor = usuarioReceptor; |
||
| 162 | } |
||
| 163 | |||
| 106 | espaco | 164 | @OneToMany(mappedBy="transferencia", cascade=CascadeType.ALL, orphanRemoval=true) |
| 165 | public List<TransferenciaProduto> getListaProdutos() { |
||
| 166 | return listaProdutos; |
||
| 167 | } |
||
| 168 | public void setListaProdutos(List<TransferenciaProduto> listaProdutos) { |
||
| 169 | this.listaProdutos = listaProdutos; |
||
| 170 | } |
||
| 171 | |||
| 172 | @Transient |
||
| 173 | public List<TransferenciaProdutoDTO> getProdutosDTO() { |
||
| 174 | return produtosDTO; |
||
| 175 | } |
||
| 176 | public void setProdutosDTO(List<TransferenciaProdutoDTO> produtosDTO) { |
||
| 177 | this.produtosDTO = produtosDTO; |
||
| 178 | } |
||
| 179 | |||
| 180 | @Override |
||
| 181 | public int hashCode() { |
||
| 182 | final int prime = 31; |
||
| 183 | int result = 1; |
||
| 184 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 185 | return result; |
||
| 186 | } |
||
| 187 | @Override |
||
| 188 | public boolean equals(Object obj) { |
||
| 189 | if (this == obj) |
||
| 190 | return true; |
||
| 191 | if (obj == null) |
||
| 192 | return false; |
||
| 193 | if (getClass() != obj.getClass()) |
||
| 194 | return false; |
||
| 195 | Transferencia other = (Transferencia) obj; |
||
| 196 | if (sequencial == null) { |
||
| 197 | if (other.sequencial != null) |
||
| 198 | return false; |
||
| 199 | } else if (!sequencial.equals(other.sequencial)) |
||
| 200 | return false; |
||
| 201 | return true; |
||
| 202 | } |
||
| 203 | |||
| 204 | @Transient |
||
| 205 | public Object getSequencialDaLojaEntrada() { |
||
| 206 | return VerificadorUtil.naoEstaNulo(getLojaEntrada())? getLojaEntrada().getSequencial() : null; |
||
| 207 | } |
||
| 208 | |||
| 209 | @Transient |
||
| 210 | public Object getSequencialDaLojaSaida() { |
||
| 211 | return VerificadorUtil.naoEstaNulo(getLojaSaida())? getLojaSaida().getSequencial() : null; |
||
| 212 | } |
||
| 213 | |||
| 214 | @Transient |
||
| 215 | public List<TransferenciaProduto> getProdutosOrdenados() { |
||
| 216 | List<TransferenciaProduto> produtosOrdenados = null; |
||
| 217 | if (VerificadorUtil.naoEstaNulo(getListaProdutos())) { |
||
| 218 | produtosOrdenados = new ArrayList<TransferenciaProduto>(getListaProdutos()); |
||
| 219 | Collections.sort(produtosOrdenados, new Comparator<TransferenciaProduto>() { |
||
| 220 | public int compare(TransferenciaProduto p1, TransferenciaProduto p2) { |
||
| 221 | return p1.getProduto().getDescricaoDoModelo().compareTo(p2.getProduto().getDescricaoDoModelo()); |
||
| 222 | }; |
||
| 223 | }); |
||
| 224 | } |
||
| 225 | return produtosOrdenados; |
||
| 226 | } |
||
| 227 | |||
| 228 | public void adicionarProduto(TransferenciaProduto produto) { |
||
| 229 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 230 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 231 | } |
||
| 232 | getListaProdutos().add(produto); |
||
| 233 | } |
||
| 234 | |||
| 235 | public void removerProduto(TransferenciaProduto transferenciaProduto) { |
||
| 236 | if (!VerificadorUtil.isListaNulaOuVazia(getListaProdutos())) { |
||
| 237 | getListaProdutos().remove(transferenciaProduto); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | |||
| 241 | public void removerProduto(TransferenciaProdutoDTO transferenciaProdutoDTO) { |
||
| 242 | if (!VerificadorUtil.isListaNulaOuVazia(getProdutosDTO())) { |
||
| 243 | getProdutosDTO().remove(transferenciaProdutoDTO); |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | public boolean verificarSeProdutoJaConstaNaLista(TransferenciaProduto transferenciaProduto) { |
||
| 248 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 249 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 250 | } |
||
| 251 | for (TransferenciaProduto item : getListaProdutos()) { |
||
| 252 | if (item.equals(transferenciaProduto)) { |
||
| 253 | return true; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | return false; |
||
| 257 | } |
||
| 258 | |||
| 259 | public boolean verificarSeProdutoJaConstaNaLista(Long sequencialProduto) { |
||
| 260 | if (VerificadorUtil.estaNulo(getProdutosDTO())) { |
||
| 261 | setProdutosDTO(new ArrayList<TransferenciaProdutoDTO>()); |
||
| 262 | } |
||
| 263 | for (TransferenciaProdutoDTO item : getProdutosDTO()) { |
||
| 264 | if (item.getSequencialProduto().equals(sequencialProduto)) { |
||
| 265 | return true; |
||
| 266 | } |
||
| 267 | } |
||
| 268 | return false; |
||
| 269 | } |
||
| 270 | |||
| 271 | @Transient |
||
| 235 | espaco | 272 | private Integer quantidadeProdutos(String tipoProduto) { |
| 106 | espaco | 273 | Integer quantidadeTotal = 0; |
| 274 | if (VerificadorUtil.naoEstaNuloOuVazio(getProdutosDTO())) { |
||
| 275 | for (TransferenciaProdutoDTO transferenciaProduto : getProdutosDTO()) { |
||
| 235 | espaco | 276 | if (transferenciaProduto.ehTipoProduto(tipoProduto)) { |
| 106 | espaco | 277 | quantidadeTotal = quantidadeTotal + transferenciaProduto.getQuantidade(); |
| 278 | } |
||
| 279 | } |
||
| 280 | } |
||
| 281 | return quantidadeTotal; |
||
| 282 | } |
||
| 283 | |||
| 235 | espaco | 284 | @Transient |
| 285 | public Integer quantidadeProdutosTipoCapa() { |
||
| 286 | return quantidadeProdutos(TipoProduto.CAPA.getValor()); |
||
| 287 | } |
||
| 288 | |||
| 289 | @Transient |
||
| 290 | public Integer quantidadeProdutosTipoPelicula() { |
||
| 291 | return quantidadeProdutos(TipoProduto.PELICULA.getValor()); |
||
| 292 | } |
||
| 293 | |||
| 294 | @Transient |
||
| 295 | public Integer quantidadeProdutosTipoOutrosExcetoCapaEePelicula() { |
||
| 296 | Integer quantidadeTotal = 0; |
||
| 297 | if (VerificadorUtil.naoEstaNuloOuVazio(getProdutosDTO())) { |
||
| 298 | for (TransferenciaProdutoDTO transferenciaProduto : getProdutosDTO()) { |
||
| 299 | if (!transferenciaProduto.ehTipoProduto(TipoProduto.CAPA.getValor()) && |
||
| 300 | !transferenciaProduto.ehTipoProduto(TipoProduto.PELICULA.getValor())) { |
||
| 301 | quantidadeTotal = quantidadeTotal + transferenciaProduto.getQuantidade(); |
||
| 302 | } |
||
| 303 | } |
||
| 304 | } |
||
| 305 | return quantidadeTotal; |
||
| 306 | } |
||
| 307 | |||
| 106 | espaco | 308 | } |