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