Rev 259 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 259 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.Date; |
||
| 6 | import java.util.List; |
||
| 7 | |||
| 8 | import javax.persistence.Column; |
||
| 9 | import javax.persistence.Entity; |
||
| 10 | import javax.persistence.GeneratedValue; |
||
| 11 | import javax.persistence.GenerationType; |
||
| 12 | import javax.persistence.Id; |
||
| 13 | import javax.persistence.JoinColumn; |
||
| 14 | import javax.persistence.ManyToOne; |
||
| 15 | import javax.persistence.SequenceGenerator; |
||
| 16 | import javax.persistence.Table; |
||
| 17 | import javax.persistence.Transient; |
||
| 18 | import javax.validation.constraints.Size; |
||
| 19 | |||
| 20 | import org.hibernate.annotations.ForeignKey; |
||
| 21 | |||
| 22 | import br.com.ec.core.util.StringUtil; |
||
| 23 | import br.com.ec.core.util.VerificadorUtil; |
||
| 24 | |||
| 25 | @Entity |
||
| 26 | @Table(name="sec_lancamento", schema="sc_sec") |
||
| 27 | public class Lancamento implements Serializable, Cloneable { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private Long sequencial; |
||
| 32 | private Venda venda; |
||
| 508 | blopes | 33 | private Produto produto; |
| 259 | espaco | 34 | private Double valorCompra; |
| 35 | private Double valorVarejo; |
||
| 36 | private Double valorVenda; |
||
| 37 | private String observacao; |
||
| 38 | private String observacaoNotaFiscal; |
||
| 39 | private Date dataValidacaoVivo; |
||
| 40 | private Date dataBaixaVivo; |
||
| 41 | private Double valorRecebidoVivo; |
||
| 42 | private Date dataRecebidoVivo; |
||
| 43 | private Boolean ativo; |
||
| 44 | |||
| 45 | // private Cupom cupom; |
||
| 46 | |||
| 47 | private Integer quantidadeLancamento = 1; |
||
| 48 | private String observacaoIMEI1; |
||
| 49 | private String observacaoIMEI2; |
||
| 50 | |||
| 51 | private String observacaoRestaurante = "COMPLETO"; |
||
| 52 | private String opcaoRestaurante = ""; |
||
| 53 | private List<String> opcoesRestaurante = new ArrayList<String>(); |
||
| 54 | |||
| 55 | @Id |
||
| 56 | @SequenceGenerator(name = "sq_lancamento") |
||
| 57 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 58 | @Column(name="seq_lancamento", nullable=false) |
||
| 59 | public Long getSequencial() { |
||
| 60 | return sequencial; |
||
| 61 | } |
||
| 62 | public void setSequencial(Long sequencial) { |
||
| 63 | this.sequencial = sequencial; |
||
| 64 | } |
||
| 65 | |||
| 66 | @ManyToOne |
||
| 67 | @ForeignKey(name = "fk_lancamento_venda") |
||
| 68 | @JoinColumn(name="seq_venda", referencedColumnName="seq_venda", insertable=true, updatable=false) |
||
| 69 | public Venda getVenda() { |
||
| 70 | return venda; |
||
| 71 | } |
||
| 72 | public void setVenda(Venda venda) { |
||
| 73 | this.venda = venda; |
||
| 74 | } |
||
| 508 | blopes | 75 | |
| 259 | espaco | 76 | @ManyToOne |
| 77 | @ForeignKey(name = "fk_lancamento_produto") |
||
| 78 | @JoinColumn(name="seq_produto", referencedColumnName="seq_produto", insertable=true, updatable=false) |
||
| 79 | public Produto getProduto() { |
||
| 80 | return produto; |
||
| 81 | } |
||
| 82 | public void setProduto(Produto produto) { |
||
| 83 | this.produto = produto; |
||
| 84 | } |
||
| 508 | blopes | 85 | |
| 259 | espaco | 86 | @Column(name="val_compra") |
| 87 | public Double getValorCompra() { |
||
| 88 | return valorCompra; |
||
| 89 | } |
||
| 90 | public void setValorCompra(Double valorCompra) { |
||
| 91 | this.valorCompra = valorCompra; |
||
| 92 | } |
||
| 93 | |||
| 94 | @Column(name="val_varejo") |
||
| 95 | public Double getValorVarejo() { |
||
| 96 | return valorVarejo; |
||
| 97 | } |
||
| 98 | public void setValorVarejo(Double valorVarejo) { |
||
| 99 | this.valorVarejo = valorVarejo; |
||
| 100 | } |
||
| 101 | |||
| 102 | @Column(name="val_venda") |
||
| 103 | public Double getValorVenda() { |
||
| 104 | return valorVenda; |
||
| 105 | } |
||
| 106 | public void setValorVenda(Double valorVenda) { |
||
| 107 | this.valorVenda = valorVenda; |
||
| 108 | } |
||
| 109 | |||
| 110 | @Column(name="dsc_observacao") |
||
| 111 | @Size(max = 1000, message = "Limite de caracteres ultrapassado: Observação") |
||
| 112 | public String getObservacao() { |
||
| 113 | return observacao; |
||
| 114 | } |
||
| 115 | public void setObservacao(String observacao) { |
||
| 116 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 117 | } |
||
| 118 | |||
| 119 | @Column(name="dsc_observacao_notafiscal") |
||
| 120 | @Size(max = 200, message = "Limite de caracteres ultrapassado: Observação da Nota Fiscal") |
||
| 121 | public String getObservacaoNotaFiscal() { |
||
| 122 | return observacaoNotaFiscal; |
||
| 123 | } |
||
| 124 | public void setObservacaoNotaFiscal(String observacaoNotaFiscal) { |
||
| 125 | this.observacaoNotaFiscal = StringUtil.setarUpperCaseComTrim(observacaoNotaFiscal); |
||
| 126 | } |
||
| 127 | |||
| 128 | @Column(name="dat_validacao_vivo") |
||
| 129 | public Date getDataValidacaoVivo() { |
||
| 130 | return dataValidacaoVivo; |
||
| 131 | } |
||
| 132 | public void setDataValidacaoVivo(Date dataValidacaoVivo) { |
||
| 133 | this.dataValidacaoVivo = dataValidacaoVivo; |
||
| 134 | } |
||
| 135 | |||
| 136 | @Column(name="dat_baixa_vivo") |
||
| 137 | public Date getDataBaixaVivo() { |
||
| 138 | return dataBaixaVivo; |
||
| 139 | } |
||
| 140 | public void setDataBaixaVivo(Date dataBaixaVivo) { |
||
| 141 | this.dataBaixaVivo = dataBaixaVivo; |
||
| 142 | } |
||
| 143 | |||
| 144 | @Column(name="val_recebido_vivo") |
||
| 145 | public Double getValorRecebidoVivo() { |
||
| 146 | return valorRecebidoVivo; |
||
| 147 | } |
||
| 148 | public void setValorRecebidoVivo(Double valorRecebidoVivo) { |
||
| 149 | this.valorRecebidoVivo = valorRecebidoVivo; |
||
| 150 | } |
||
| 151 | |||
| 152 | @Column(name="dat_recebido_vivo") |
||
| 153 | public Date getDataRecebidoVivo() { |
||
| 154 | return dataRecebidoVivo; |
||
| 155 | } |
||
| 156 | public void setDataRecebidoVivo(Date dataRecebidoVivo) { |
||
| 157 | this.dataRecebidoVivo = dataRecebidoVivo; |
||
| 158 | } |
||
| 159 | |||
| 160 | @Column(name="ind_ativo", nullable=false) |
||
| 161 | public Boolean getAtivo() { |
||
| 162 | return ativo; |
||
| 163 | } |
||
| 164 | public void setAtivo(Boolean ativo) { |
||
| 165 | this.ativo = ativo; |
||
| 166 | } |
||
| 167 | /* |
||
| 168 | @ManyToOne |
||
| 169 | @ForeignKey(name="fk_lancamento_cupom") |
||
| 170 | @JoinColumn(name = "seq_cupom", nullable=true) |
||
| 171 | public Cupom getCupom() { |
||
| 172 | return cupom; |
||
| 173 | } |
||
| 174 | public void setCupom(Cupom cupom) { |
||
| 175 | this.cupom = cupom; |
||
| 176 | } |
||
| 177 | */ |
||
| 178 | @Transient |
||
| 179 | public Integer getQuantidadeLancamento() { |
||
| 180 | return quantidadeLancamento; |
||
| 181 | } |
||
| 182 | public void setQuantidadeLancamento(Integer quantidadeLancamento) { |
||
| 183 | this.quantidadeLancamento = quantidadeLancamento; |
||
| 184 | } |
||
| 185 | |||
| 186 | @Transient |
||
| 187 | public String getObservacaoIMEI1() { |
||
| 188 | return observacaoIMEI1; |
||
| 189 | } |
||
| 190 | public void setObservacaoIMEI1(String observacaoIMEI1) { |
||
| 191 | this.observacaoIMEI1 = observacaoIMEI1; |
||
| 192 | } |
||
| 193 | |||
| 194 | @Transient |
||
| 195 | public String getObservacaoIMEI2() { |
||
| 196 | return observacaoIMEI2; |
||
| 197 | } |
||
| 198 | public void setObservacaoIMEI2(String observacaoIMEI2) { |
||
| 199 | this.observacaoIMEI2 = observacaoIMEI2; |
||
| 200 | } |
||
| 201 | |||
| 202 | @Transient |
||
| 203 | public String getObservacaoRestaurante() { |
||
| 204 | return observacaoRestaurante; |
||
| 205 | } |
||
| 206 | public void setObservacaoRestaurante(String observacaoRestaurante) { |
||
| 207 | this.observacaoRestaurante = observacaoRestaurante; |
||
| 208 | } |
||
| 209 | |||
| 210 | @Transient |
||
| 211 | public String getOpcaoRestaurante() { |
||
| 212 | return opcaoRestaurante; |
||
| 213 | } |
||
| 214 | public void setOpcaoRestaurante(String opcaoRestaurante) { |
||
| 215 | this.opcaoRestaurante = opcaoRestaurante; |
||
| 216 | } |
||
| 217 | |||
| 218 | @Transient |
||
| 219 | public List<String> getOpcoesRestaurante() { |
||
| 220 | return opcoesRestaurante; |
||
| 221 | } |
||
| 222 | public void setOpcoesRestaurante(List<String> opcoesRestaurante) { |
||
| 223 | this.opcoesRestaurante = opcoesRestaurante; |
||
| 224 | } |
||
| 225 | |||
| 226 | @Override |
||
| 227 | public int hashCode() { |
||
| 228 | final int prime = 31; |
||
| 229 | int result = 1; |
||
| 230 | result = prime * result |
||
| 231 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 232 | return result; |
||
| 233 | } |
||
| 234 | |||
| 235 | @Override |
||
| 236 | public boolean equals(Object obj) { |
||
| 237 | if (this == obj) |
||
| 238 | return true; |
||
| 239 | if (obj == null) |
||
| 240 | return false; |
||
| 241 | if (getClass() != obj.getClass()) |
||
| 242 | return false; |
||
| 243 | Lancamento other = (Lancamento) obj; |
||
| 244 | if (sequencial == null) { |
||
| 245 | if (other.sequencial != null) { |
||
| 246 | return false; |
||
| 247 | } else {return false;} |
||
| 248 | } else if (!sequencial.equals(other.sequencial)) |
||
| 249 | return false; |
||
| 250 | return true; |
||
| 251 | } |
||
| 252 | |||
| 253 | @Override |
||
| 254 | public Lancamento clone() throws CloneNotSupportedException { |
||
| 255 | return (Lancamento) super.clone(); |
||
| 256 | } |
||
| 257 | /* |
||
| 258 | @Transient |
||
| 259 | public void preencher(Produto produtoSelecionado) { |
||
| 260 | this.setProduto(produtoSelecionado); |
||
| 261 | this.setValorCompra(produtoSelecionado.getValorCompra()); |
||
| 262 | if (produtoSelecionado.getProdutoEmPromocao()) { |
||
| 263 | this.setValorVarejo(produtoSelecionado.getValorVarejoPromocional()); |
||
| 264 | this.setValorVenda(produtoSelecionado.getValorVarejoPromocional()); |
||
| 265 | } else { |
||
| 266 | this.setValorVarejo(produtoSelecionado.getValorVarejo()); |
||
| 267 | this.setValorVenda(produtoSelecionado.getValorVarejo()); |
||
| 268 | } |
||
| 269 | } |
||
| 270 | |||
| 271 | @Transient |
||
| 272 | public void preencherComPrecoPopular(Produto produtoSelecionado) { |
||
| 273 | this.setProduto(produtoSelecionado); |
||
| 274 | this.setValorCompra(produtoSelecionado.getValorCompra()); |
||
| 275 | this.setValorVarejo(produtoSelecionado.getValorVarejoPopular()); |
||
| 276 | this.setValorVenda(produtoSelecionado.getValorVarejoPopular()); |
||
| 277 | } |
||
| 278 | |||
| 279 | @Transient |
||
| 280 | public void preencherComPrecoAtacado(Produto produtoSelecionado) { |
||
| 281 | this.setProduto(produtoSelecionado); |
||
| 282 | this.setValorCompra(produtoSelecionado.getValorCompra()); |
||
| 283 | this.setValorVarejo(produtoSelecionado.getValorAtacado()); |
||
| 284 | this.setValorVenda(produtoSelecionado.getValorAtacado()); |
||
| 285 | } |
||
| 286 | |||
| 287 | @Transient |
||
| 288 | public String tipoDoProduto() { |
||
| 289 | return VerificadorUtil.naoEstaNulo(this.getProduto()) ? this.getProduto().getTipo() : ""; |
||
| 290 | } |
||
| 291 | */ |
||
| 292 | @Transient |
||
| 293 | public Double valorDescontos() { |
||
| 294 | if (VerificadorUtil.estaNulo(getValorVarejo())) { |
||
| 295 | return getValorVenda(); |
||
| 296 | } |
||
| 297 | return getValorVarejo() - getValorVenda(); |
||
| 298 | } |
||
| 299 | |||
| 300 | @Transient |
||
| 301 | public String valorPercentualDescontos() { |
||
| 302 | if (VerificadorUtil.estaNulo(getValorVarejo())) { |
||
| 303 | return "0%"; |
||
| 304 | } |
||
| 305 | return StringUtil.formatarPercentual((getValorVarejo() - getValorVenda()) / getValorVarejo()); |
||
| 306 | } |
||
| 307 | |||
| 308 | @Transient |
||
| 309 | public Boolean comDescontos() { |
||
| 310 | if (VerificadorUtil.naoEstaNulo(getValorVarejo()) && VerificadorUtil.naoEstaNulo(getValorVenda())) { |
||
| 311 | return getValorVarejo() > getValorVenda(); |
||
| 312 | } |
||
| 313 | return false; |
||
| 314 | } |
||
| 315 | /* |
||
| 316 | @Transient |
||
| 317 | public Boolean comDescontosAcimaDoPermitido() { |
||
| 318 | if (VerificadorUtil.naoEstaNulo(getValorVarejo()) && VerificadorUtil.naoEstaNulo(getValorVenda())) { |
||
| 319 | if (getProduto().getValorVarejo() < 100) { |
||
| 320 | Double valorDesconto = getValorVarejo() - getValorVenda(); |
||
| 321 | return valorDesconto > ConstantesSEC.Venda.LIMITE_DESCONTO_ABAIXO_100; |
||
| 322 | } else { |
||
| 323 | Double percentualDesconto = 100 - (getValorVenda()*100/getValorVarejo()); |
||
| 324 | return percentualDesconto > ConstantesSEC.Venda.LIMITE_PERCENTUAL_DESCONTO_ACIMA_100; |
||
| 325 | } |
||
| 326 | } |
||
| 327 | return false; |
||
| 328 | } |
||
| 329 | |||
| 330 | @Transient |
||
| 331 | public String getDescricaoNotaFiscal() { |
||
| 332 | StringBuilder descricaoCompleta = new StringBuilder(); |
||
| 333 | descricaoCompleta.append(this.getProduto().getDescricaoNotaFiscal(this.getObservacaoNotaFiscal())); |
||
| 334 | return descricaoCompleta.toString().trim(); |
||
| 335 | } |
||
| 336 | |||
| 337 | @Transient |
||
| 338 | public String getDescricaoComanda() { |
||
| 339 | StringBuilder descricaoCompleta = new StringBuilder(); |
||
| 340 | descricaoCompleta.append(this.getProduto().getDescricaoNotaFiscal(this.getObservacao())); |
||
| 341 | return descricaoCompleta.toString().trim(); |
||
| 342 | } |
||
| 343 | |||
| 344 | @Transient |
||
| 345 | public Long getSequencialDoCupom() { |
||
| 346 | return VerificadorUtil.naoEstaNulo(getCupom())? getCupom().getSequencial() : null; |
||
| 347 | } |
||
| 348 | */ |
||
| 349 | } |