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