Rev 468 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 468 | blopes | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Date; |
||
| 495 | blopes | 5 | import java.util.List; |
| 468 | blopes | 6 | |
| 495 | blopes | 7 | import javax.persistence.CascadeType; |
| 468 | blopes | 8 | import javax.persistence.Column; |
| 9 | import javax.persistence.Entity; |
||
| 495 | blopes | 10 | import javax.persistence.FetchType; |
| 468 | blopes | 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; |
||
| 495 | blopes | 16 | import javax.persistence.OneToMany; |
| 468 | blopes | 17 | import javax.persistence.SequenceGenerator; |
| 18 | import javax.persistence.Table; |
||
| 19 | import javax.persistence.Transient; |
||
| 20 | import javax.validation.constraints.Size; |
||
| 21 | |||
| 22 | import org.hibernate.annotations.ForeignKey; |
||
| 23 | |||
| 24 | import br.com.ec.core.util.VerificadorUtil; |
||
| 25 | |||
| 26 | @Entity |
||
| 27 | @Table(name="sec_compra_produto", schema="sc_sec") |
||
| 28 | public class CompraProduto implements Serializable { |
||
| 29 | |||
| 30 | private static final long serialVersionUID = 1L; |
||
| 31 | |||
| 32 | private Long sequencial; |
||
| 33 | private Compra compra; |
||
| 34 | private Produto produto; |
||
| 35 | private Double valorCompra; |
||
| 36 | private Integer quantidade; |
||
| 37 | private String unidadeComercial; |
||
| 38 | private Integer quantidadeUnidadeComercial; |
||
| 39 | private Double valorUnidadeComercial; |
||
| 40 | private String unidadeTributaria; |
||
| 41 | private Integer quantidadeUnidadeTributaria; |
||
| 42 | private Double valorUnidadeTributaria; |
||
| 43 | private Double valorDesconto; |
||
| 44 | private Boolean indicadorValorTotalNota; |
||
| 45 | private String informacoesAdicionais; |
||
| 46 | |||
| 47 | private String codigoProdutoNotaFiscal; |
||
| 48 | private String descricaoProdutoNotaFiscal; |
||
| 49 | |||
| 50 | private String codigoNCM; |
||
| 51 | private Boolean indicadorSolicitarContagem = false; |
||
| 52 | private Integer estoqueAtualProduto; |
||
| 53 | |||
| 54 | // MEDICAMENTO |
||
| 55 | private String lote; |
||
| 56 | private Integer quantidadeLote; |
||
| 57 | private Date dataFabricacao; |
||
| 58 | private Date dataValidade; |
||
| 59 | private Double valorPrecoMaximo; |
||
| 60 | |||
| 61 | public CompraProduto() { |
||
| 62 | setUnidadeComercial("UN"); |
||
| 63 | setUnidadeTributaria("UN"); |
||
| 64 | } |
||
| 65 | |||
| 66 | public CompraProduto(Long sequencial) { |
||
| 67 | this.sequencial = sequencial; |
||
| 68 | setUnidadeComercial("UN"); |
||
| 69 | setUnidadeTributaria("UN"); |
||
| 70 | } |
||
| 71 | |||
| 72 | @Id |
||
| 73 | @SequenceGenerator(name = "sq_compraproduto") |
||
| 74 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 75 | @Column(name="seq_compraproduto", nullable=false) |
||
| 76 | public Long getSequencial() { |
||
| 77 | return sequencial; |
||
| 78 | } |
||
| 79 | public void setSequencial(Long sequencial) { |
||
| 80 | this.sequencial = sequencial; |
||
| 81 | } |
||
| 82 | |||
| 83 | @ManyToOne |
||
| 84 | @ForeignKey(name = "fk_compra_compraproduto") |
||
| 85 | @JoinColumn(name="seq_compra", referencedColumnName="seq_compra", insertable=true, updatable=false) |
||
| 86 | public Compra getCompra() { |
||
| 87 | return compra; |
||
| 88 | } |
||
| 89 | public void setCompra(Compra compra) { |
||
| 90 | this.compra = compra; |
||
| 91 | } |
||
| 92 | |||
| 93 | @ManyToOne |
||
| 94 | @ForeignKey(name = "fk_prooduto_compraproduto") |
||
| 95 | @JoinColumn(name="seq_produto", referencedColumnName="seq_produto", insertable=true, updatable=false) |
||
| 96 | public Produto getProduto() { |
||
| 97 | return produto; |
||
| 98 | } |
||
| 99 | public void setProduto(Produto produto) { |
||
| 100 | this.produto = produto; |
||
| 101 | } |
||
| 102 | |||
| 103 | @Column(name="val_compra") |
||
| 104 | public Double getValorCompra() { |
||
| 105 | return valorCompra; |
||
| 106 | } |
||
| 107 | public void setValorCompra(Double valorCompra) { |
||
| 108 | this.valorCompra = valorCompra; |
||
| 109 | } |
||
| 110 | |||
| 111 | @Column(name="qtd_compra", nullable=false) |
||
| 112 | public Integer getQuantidade() { |
||
| 113 | return quantidade; |
||
| 114 | } |
||
| 115 | public void setQuantidade(Integer quantidade) { |
||
| 116 | this.quantidade = quantidade; |
||
| 117 | } |
||
| 118 | |||
| 119 | @Column(name="dsc_unidade_comercial") |
||
| 120 | public String getUnidadeComercial() { |
||
| 121 | return unidadeComercial; |
||
| 122 | } |
||
| 123 | public void setUnidadeComercial(String unidadeComercial) { |
||
| 124 | this.unidadeComercial = unidadeComercial; |
||
| 125 | } |
||
| 126 | |||
| 127 | @Column(name="qtd_unidade_comercial") |
||
| 128 | public Integer getQuantidadeUnidadeComercial() { |
||
| 129 | return quantidadeUnidadeComercial; |
||
| 130 | } |
||
| 131 | public void setQuantidadeUnidadeComercial(Integer quantidadeUnidadeComercial) { |
||
| 132 | this.quantidadeUnidadeComercial = quantidadeUnidadeComercial; |
||
| 133 | } |
||
| 134 | |||
| 135 | @Column(name="val_unidade_comercial") |
||
| 136 | public Double getValorUnidadeComercial() { |
||
| 137 | return valorUnidadeComercial; |
||
| 138 | } |
||
| 139 | public void setValorUnidadeComercial(Double valorUnidadeComercial) { |
||
| 140 | this.valorUnidadeComercial = valorUnidadeComercial; |
||
| 141 | } |
||
| 142 | |||
| 143 | @Column(name="dsc_unidade_tributaria") |
||
| 144 | public String getUnidadeTributaria() { |
||
| 145 | return unidadeTributaria; |
||
| 146 | } |
||
| 147 | public void setUnidadeTributaria(String unidadeTributaria) { |
||
| 148 | this.unidadeTributaria = unidadeTributaria; |
||
| 149 | } |
||
| 150 | |||
| 151 | @Column(name="qtd_unidade_tributaria") |
||
| 152 | public Integer getQuantidadeUnidadeTributaria() { |
||
| 153 | return quantidadeUnidadeTributaria; |
||
| 154 | } |
||
| 155 | public void setQuantidadeUnidadeTributaria(Integer quantidadeUnidadeTributaria) { |
||
| 156 | this.quantidadeUnidadeTributaria = quantidadeUnidadeTributaria; |
||
| 157 | } |
||
| 158 | |||
| 159 | @Column(name="val_unidade_tributaria") |
||
| 160 | public Double getValorUnidadeTributaria() { |
||
| 161 | return valorUnidadeTributaria; |
||
| 162 | } |
||
| 163 | public void setValorUnidadeTributaria(Double valorUnidadeTributaria) { |
||
| 164 | this.valorUnidadeTributaria = valorUnidadeTributaria; |
||
| 165 | } |
||
| 166 | |||
| 167 | @Column(name="val_desconto") |
||
| 168 | public Double getValorDesconto() { |
||
| 169 | return valorDesconto; |
||
| 170 | } |
||
| 171 | public void setValorDesconto(Double valorDesconto) { |
||
| 172 | this.valorDesconto = valorDesconto; |
||
| 173 | } |
||
| 174 | |||
| 175 | @Column(name="ind_valor_total_nota") |
||
| 176 | public Boolean getIndicadorValorTotalNota() { |
||
| 177 | return indicadorValorTotalNota; |
||
| 178 | } |
||
| 179 | public void setIndicadorValorTotalNota(Boolean indicadorValorTotalNota) { |
||
| 180 | this.indicadorValorTotalNota = indicadorValorTotalNota; |
||
| 181 | } |
||
| 182 | |||
| 183 | @Column(name="dsc_informacoes_adicionais") |
||
| 184 | @Size(max = 250, message = "Limite de caracteres ultrapassado: Informações Adicionais") |
||
| 185 | public String getInformacoesAdicionais() { |
||
| 186 | return informacoesAdicionais; |
||
| 187 | } |
||
| 188 | public void setInformacoesAdicionais(String informacoesAdicionais) { |
||
| 189 | this.informacoesAdicionais = informacoesAdicionais; |
||
| 190 | } |
||
| 191 | |||
| 192 | @Column(name="dsc_lote") |
||
| 193 | @Size(max = 20, message = "Limite de caracteres ultrapassado: Lote") |
||
| 194 | public String getLote() { |
||
| 195 | return lote; |
||
| 196 | } |
||
| 197 | public void setLote(String lote) { |
||
| 198 | this.lote = lote; |
||
| 199 | } |
||
| 200 | |||
| 201 | @Column(name="qtd_lote") |
||
| 202 | public Integer getQuantidadeLote() { |
||
| 203 | return quantidadeLote; |
||
| 204 | } |
||
| 205 | public void setQuantidadeLote(Integer quantidadeLote) { |
||
| 206 | this.quantidadeLote = quantidadeLote; |
||
| 207 | } |
||
| 208 | |||
| 209 | @Column(name="dat_fabricacao") |
||
| 210 | public Date getDataFabricacao() { |
||
| 211 | return dataFabricacao; |
||
| 212 | } |
||
| 213 | public void setDataFabricacao(Date dataFabricacao) { |
||
| 214 | this.dataFabricacao = dataFabricacao; |
||
| 215 | } |
||
| 216 | |||
| 217 | @Column(name="dat_validade") |
||
| 218 | public Date getDataValidade() { |
||
| 219 | return dataValidade; |
||
| 220 | } |
||
| 221 | public void setDataValidade(Date dataValidade) { |
||
| 222 | this.dataValidade = dataValidade; |
||
| 223 | } |
||
| 224 | |||
| 225 | @Column(name="val_preco_maximo") |
||
| 226 | public Double getValorPrecoMaximo() { |
||
| 227 | return valorPrecoMaximo; |
||
| 228 | } |
||
| 229 | public void setValorPrecoMaximo(Double valorPrecoMaximo) { |
||
| 230 | this.valorPrecoMaximo = valorPrecoMaximo; |
||
| 231 | } |
||
| 232 | |||
| 233 | @Column(name="dsc_codigoproduto_notafiscal") |
||
| 234 | @Size(max = 100, message = "Limite de caracteres ultrapassado: Código do Fornecedor") |
||
| 235 | public String getCodigoProdutoNotaFiscal() { |
||
| 236 | return codigoProdutoNotaFiscal; |
||
| 237 | } |
||
| 238 | public void setCodigoProdutoNotaFiscal(String codigoProdutoNotaFiscal) { |
||
| 239 | this.codigoProdutoNotaFiscal = codigoProdutoNotaFiscal; |
||
| 240 | } |
||
| 241 | |||
| 242 | @Column(name="dsc_produto_notafiscal") |
||
| 243 | @Size(max = 250, message = "Limite de caracteres ultrapassado: Descrição do Fornecedor") |
||
| 244 | public String getDescricaoProdutoNotaFiscal() { |
||
| 245 | return descricaoProdutoNotaFiscal; |
||
| 246 | } |
||
| 247 | public void setDescricaoProdutoNotaFiscal(String descricaoProdutoNotaFiscal) { |
||
| 248 | this.descricaoProdutoNotaFiscal = descricaoProdutoNotaFiscal; |
||
| 249 | } |
||
| 250 | |||
| 251 | /*********************************************/ |
||
| 252 | |||
| 253 | @Transient |
||
| 254 | public String getCodigoNCM() { |
||
| 255 | return codigoNCM; |
||
| 256 | } |
||
| 257 | public void setCodigoNCM(String codigoNCM) { |
||
| 258 | this.codigoNCM = codigoNCM; |
||
| 259 | } |
||
| 260 | |||
| 261 | @Transient |
||
| 262 | public Boolean getIndicadorSolicitarContagem() { |
||
| 263 | return indicadorSolicitarContagem; |
||
| 264 | } |
||
| 265 | public void setIndicadorSolicitarContagem(Boolean indicadorSolicitarContagem) { |
||
| 266 | this.indicadorSolicitarContagem = indicadorSolicitarContagem; |
||
| 267 | } |
||
| 268 | |||
| 269 | @Transient |
||
| 270 | public Integer getEstoqueAtualProduto() { |
||
| 271 | return estoqueAtualProduto; |
||
| 272 | } |
||
| 273 | public void setEstoqueAtualProduto(Integer estoqueAtualProduto) { |
||
| 274 | this.estoqueAtualProduto = estoqueAtualProduto; |
||
| 275 | } |
||
| 276 | |||
| 277 | @Transient |
||
| 278 | public Loja getLojaDaCompra() { |
||
| 279 | return VerificadorUtil.naoEstaNulo(getCompra())? getCompra().getLoja() : null; |
||
| 280 | } |
||
| 281 | |||
| 282 | @Override |
||
| 283 | public int hashCode() { |
||
| 284 | final int prime = 31; |
||
| 285 | int result = 1; |
||
| 286 | result = prime * result |
||
| 287 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 288 | return result; |
||
| 289 | } |
||
| 290 | |||
| 291 | @Override |
||
| 292 | public boolean equals(Object obj) { |
||
| 293 | if (this == obj) |
||
| 294 | return true; |
||
| 295 | if (obj == null) |
||
| 296 | return false; |
||
| 297 | if (getClass() != obj.getClass()) |
||
| 298 | return false; |
||
| 299 | CompraProduto other = (CompraProduto) obj; |
||
| 300 | if (sequencial == null) { |
||
| 301 | if (other.sequencial != null) { |
||
| 302 | return false; |
||
| 303 | } else {return false;} |
||
| 304 | } else if (!sequencial.equals(other.sequencial)) |
||
| 305 | return false; |
||
| 306 | return true; |
||
| 307 | } |
||
| 308 | |||
| 309 | @Transient |
||
| 310 | public Tributacao getTributacaoDoProduto() { |
||
| 311 | return VerificadorUtil.naoEstaNulo(getProduto())? getProduto().getTributacao() : null; |
||
| 312 | } |
||
| 313 | |||
| 314 | @Transient |
||
| 315 | public Double retornarPercentualLucroBrutoUnidadeComercial() { |
||
| 316 | try { |
||
| 317 | Produto produtoClone = produto.clone(); |
||
| 318 | if (VerificadorUtil.naoEstaNulo(getValorUnidadeComercial()) && VerificadorUtil.naoEstaNulo(getProduto().getValorVarejo())) { |
||
| 319 | getProduto().setValorCompra(getValorUnidadeComercial()); |
||
| 320 | produtoClone.setValorCompra(getValorUnidadeComercial()); |
||
| 321 | produtoClone.setValorVarejoSimulacao(produtoClone.getValorVarejo()); |
||
| 322 | } |
||
| 323 | return produtoClone.calculoMargemAposCustos(); |
||
| 324 | } catch (CloneNotSupportedException e) { |
||
| 325 | e.printStackTrace(); |
||
| 326 | } |
||
| 327 | return 0.0; |
||
| 328 | } |
||
| 329 | |||
| 330 | @Transient |
||
| 331 | public String retornarCorPercentualLucroBrutoUnidadeComercial() { |
||
| 332 | try { |
||
| 333 | Produto produtoClone = produto.clone(); |
||
| 334 | if (VerificadorUtil.naoEstaNulo(getValorUnidadeComercial()) && VerificadorUtil.naoEstaNulo(getProduto().getValorVarejo())) { |
||
| 335 | getProduto().setValorCompra(getValorUnidadeComercial()); |
||
| 336 | produtoClone.setValorCompra(getValorUnidadeComercial()); |
||
| 337 | produtoClone.setValorVarejoSimulacao(produtoClone.getValorVarejo()); |
||
| 338 | } |
||
| 339 | return produtoClone.retornarCorMargemLucro(); |
||
| 340 | } catch (CloneNotSupportedException e) { |
||
| 341 | e.printStackTrace(); |
||
| 342 | } |
||
| 343 | return "black"; |
||
| 344 | } |
||
| 345 | |||
| 346 | @Transient |
||
| 347 | public void atualizarDadosNfe(br.com.swconsultoria.nfe.schema_4.enviNFe.TNFe.InfNFe.Det produtoNota) { |
||
| 348 | this.setUnidadeComercial(produtoNota.getProd().getUCom()); |
||
| 349 | if (VerificadorUtil.naoEstaNulo(produtoNota.getProd().getQCom())) { |
||
| 350 | this.setQuantidade(new Double(produtoNota.getProd().getQCom()).intValue()); |
||
| 351 | } |
||
| 352 | this.setUnidadeTributaria(produtoNota.getProd().getUTrib()); |
||
| 353 | if (VerificadorUtil.naoEstaNulo(produtoNota.getProd().getQTrib())) { |
||
| 354 | this.setQuantidadeUnidadeTributaria(new Double(produtoNota.getProd().getQTrib()).intValue()); |
||
| 355 | } |
||
| 356 | if (VerificadorUtil.naoEstaNulo(produtoNota.getProd().getVUnTrib())) { |
||
| 357 | this.setValorUnidadeTributaria(new Double(produtoNota.getProd().getVUnTrib())); |
||
| 358 | } |
||
| 359 | if (VerificadorUtil.naoEstaNulo(produtoNota.getProd().getVDesc())) { |
||
| 360 | this.setValorDesconto(new Double(produtoNota.getProd().getVDesc())); |
||
| 361 | } |
||
| 362 | this.setIndicadorValorTotalNota(produtoNota.getProd().getIndTot().equals("1")); |
||
| 363 | this.setInformacoesAdicionais(produtoNota.getInfAdProd()); |
||
| 364 | this.setCodigoProdutoNotaFiscal(produtoNota.getProd().getCProd()); |
||
| 365 | this.setDescricaoProdutoNotaFiscal(produtoNota.getProd().getXProd()); |
||
| 366 | |||
| 367 | this.setCodigoNCM(produtoNota.getProd().getNCM()); |
||
| 368 | |||
| 369 | /* |
||
| 370 | if (VerificadorUtil.naoEstaNuloOuVazio(produtoNota.getProd().getMed())) { |
||
| 371 | for (nfce.java.TNFe.InfNFe.Det.Prod.Med medicamento : produtoNota.getProd().getMed()) { |
||
| 372 | if (VerificadorUtil.naoEstaNuloOuVazio(medicamento.getNLote())) { |
||
| 373 | this.setLote(medicamento.getNLote()); |
||
| 374 | } |
||
| 375 | if (VerificadorUtil.naoEstaNuloOuVazio(medicamento.getQLote())) { |
||
| 376 | this.setQuantidadeLote(new Double(medicamento.getQLote()).intValue()); |
||
| 377 | } |
||
| 378 | if (VerificadorUtil.naoEstaNuloOuVazio(medicamento.getDFab())) { |
||
| 379 | this.setDataFabricacao(DataUtil.retornarDataApartirString("yyyy-MM-dd", medicamento.getDFab())); |
||
| 380 | } |
||
| 381 | if (VerificadorUtil.naoEstaNuloOuVazio(medicamento.getDVal())) { |
||
| 382 | this.setDataValidade(DataUtil.retornarDataApartirString("yyyy-MM-dd", medicamento.getDVal())); |
||
| 383 | } |
||
| 384 | if (VerificadorUtil.naoEstaNuloOuVazio(medicamento.getVPMC())) { |
||
| 385 | this.setValorPrecoMaximo(new Double(medicamento.getVPMC())); |
||
| 386 | } |
||
| 387 | } |
||
| 388 | } |
||
| 389 | */ |
||
| 390 | } |
||
| 391 | |||
| 392 | @Transient |
||
| 393 | public void atualizarAliquotas(Fornecedor fornecedor) { |
||
| 394 | if (VerificadorUtil.naoEstaNulo(getProduto())) { |
||
| 395 | getProduto().atualizarAliquotas(fornecedor); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | } |