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