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