Rev 195 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | 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.HashSet; |
||
| 7 | import java.util.List; |
||
| 8 | import java.util.Set; |
||
| 9 | |||
| 10 | import javax.persistence.CascadeType; |
||
| 11 | import javax.persistence.Column; |
||
| 12 | import javax.persistence.Entity; |
||
| 13 | import javax.persistence.FetchType; |
||
| 14 | import javax.persistence.GeneratedValue; |
||
| 15 | import javax.persistence.GenerationType; |
||
| 16 | import javax.persistence.Id; |
||
| 17 | import javax.persistence.JoinColumn; |
||
| 18 | import javax.persistence.ManyToOne; |
||
| 19 | import javax.persistence.OneToMany; |
||
| 20 | import javax.persistence.SequenceGenerator; |
||
| 21 | import javax.persistence.Table; |
||
| 22 | import javax.persistence.Transient; |
||
| 23 | import javax.validation.constraints.NotNull; |
||
| 24 | import javax.validation.constraints.Size; |
||
| 25 | |||
| 26 | import org.hibernate.annotations.ForeignKey; |
||
| 27 | |||
| 195 | espaco | 28 | import br.com.ec.core.interfaces.Alterar; |
| 29 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 30 | import br.com.ec.core.util.DataUtils; |
||
| 31 | import br.com.ec.core.util.StringUtil; |
||
| 32 | import br.com.ec.core.util.VerificadorUtil; |
||
| 106 | espaco | 33 | import br.com.ec.domain.dto.ParametrosVendaDTO; |
| 34 | import br.com.ec.domain.model.tipos.TipoSituacaoVenda; |
||
| 35 | |||
| 36 | @Entity |
||
| 37 | @Table(name="sec_venda", schema="sc_sec") |
||
| 38 | public class Venda implements Serializable { |
||
| 39 | |||
| 40 | private static final long serialVersionUID = 1L; |
||
| 41 | |||
| 42 | private Long sequencial; |
||
| 43 | private Loja loja; |
||
| 44 | private Cliente cliente; |
||
| 45 | private Usuario usuario; |
||
| 46 | private Vendedor vendedor; |
||
| 47 | private Vendedor indicacao; |
||
| 48 | private Date dataVenda; |
||
| 49 | private String observacao; |
||
| 50 | private String tipoSituacao; |
||
| 51 | private String notaFiscal; |
||
| 52 | private Maquineta maquineta; |
||
| 53 | // private String tipoFrete; |
||
| 54 | // private Double valorFrete; |
||
| 55 | private Set<Lancamento> listaLancamentos; |
||
| 56 | private Set<VendaFormaPagamento> listaVendaFormaPagamentos; |
||
| 57 | |||
| 58 | private String tipoSituacaoFinanceira; |
||
| 59 | private String justificativaParaExcluir; |
||
| 60 | |||
| 61 | private Boolean permitirEmissaoNotaFiscal = false; |
||
| 62 | private Boolean emitirNotaFiscal = false; |
||
| 63 | private Boolean emitirComanda = false; |
||
| 64 | private Boolean cpfCnpjNaNotaFiscal = false; |
||
| 65 | |||
| 66 | public Venda() { |
||
| 67 | listaLancamentos = new HashSet<Lancamento>(); |
||
| 68 | listaVendaFormaPagamentos = new HashSet<VendaFormaPagamento>(); |
||
| 69 | setEmitirNotaFiscal(false); |
||
| 70 | // setTipoFrete(ConstantesSEC.NotaFiscal.Transporte.SEM_OCORRENCIA_TRANSPORTE_9); |
||
| 71 | } |
||
| 72 | |||
| 73 | public Venda(Loja loja, Usuario usuario) { |
||
| 74 | this.loja = loja; |
||
| 75 | this.usuario = usuario; |
||
| 76 | } |
||
| 77 | |||
| 78 | public Venda(Loja loja, Usuario usuario, Vendedor vendedor, Vendedor indicacao) { |
||
| 79 | this.loja = loja; |
||
| 80 | this.usuario = usuario; |
||
| 81 | this.vendedor = vendedor; |
||
| 82 | this.indicacao = indicacao; |
||
| 83 | } |
||
| 84 | |||
| 85 | public Venda(Loja loja, Usuario usuario, Vendedor vendedor, Vendedor indicacao, String observacao, String notaFiscal) { |
||
| 86 | this.loja = loja; |
||
| 87 | this.usuario = usuario; |
||
| 88 | this.vendedor = vendedor; |
||
| 89 | this.indicacao = indicacao; |
||
| 90 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 91 | this.notaFiscal = notaFiscal; |
||
| 92 | } |
||
| 93 | |||
| 94 | public Venda(Loja loja, Usuario usuario, Set<Lancamento> listaLancamentos, Set<VendaFormaPagamento> listaVendaFormaPagamentos) { |
||
| 95 | this.listaLancamentos = listaLancamentos; |
||
| 96 | this.listaVendaFormaPagamentos = listaVendaFormaPagamentos; |
||
| 97 | this.loja = loja; |
||
| 98 | this.usuario = usuario; |
||
| 99 | } |
||
| 100 | |||
| 101 | public Venda(ParametrosVendaDTO parametrosVenda) { |
||
| 102 | this.loja = parametrosVenda.getLoja(); |
||
| 103 | this.usuario = parametrosVenda.getUsuario(); |
||
| 104 | this.vendedor = parametrosVenda.getVendedor(); |
||
| 105 | this.cliente = parametrosVenda.getCliente(); |
||
| 106 | this.indicacao = parametrosVenda.getIndicacao(); |
||
| 107 | this.observacao = StringUtil.setarUpperCaseComTrim(parametrosVenda.getObservacao()); |
||
| 108 | this.notaFiscal = parametrosVenda.getNotaFiscal(); |
||
| 109 | this.cpfCnpjNaNotaFiscal = parametrosVenda.getCpfCnpjNaNotaFiscal(); |
||
| 110 | } |
||
| 111 | |||
| 112 | @Id |
||
| 113 | @SequenceGenerator(name = "sq_venda") |
||
| 114 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 115 | @Column(name="seq_venda", nullable=false) |
||
| 116 | public Long getSequencial() { |
||
| 117 | return sequencial; |
||
| 118 | } |
||
| 119 | public void setSequencial(Long sequencial) { |
||
| 120 | this.sequencial = sequencial; |
||
| 121 | } |
||
| 122 | |||
| 123 | @ManyToOne |
||
| 124 | @ForeignKey(name="fk_venda_loja") |
||
| 125 | @NotNull(message = "Informe a loja", groups = {Cadastrar.class, Alterar.class}) |
||
| 126 | @JoinColumn(name = "seq_loja", nullable = false) |
||
| 127 | public Loja getLoja() { |
||
| 128 | return loja; |
||
| 129 | } |
||
| 130 | public void setLoja(Loja loja) { |
||
| 131 | this.loja = loja; |
||
| 132 | } |
||
| 133 | |||
| 134 | @ManyToOne |
||
| 135 | @ForeignKey(name="fk_venda_cliente") |
||
| 136 | @JoinColumn(name = "seq_cliente", nullable = true) |
||
| 137 | public Cliente getCliente() { |
||
| 138 | return cliente; |
||
| 139 | } |
||
| 140 | public void setCliente(Cliente cliente) { |
||
| 141 | this.cliente = cliente; |
||
| 142 | } |
||
| 143 | |||
| 144 | @ManyToOne |
||
| 145 | @ForeignKey(name="fk_venda_usuario") |
||
| 146 | @JoinColumn(name = "seq_usuario", nullable = false) |
||
| 147 | public Usuario getUsuario() { |
||
| 148 | return usuario; |
||
| 149 | } |
||
| 150 | public void setUsuario(Usuario usuario) { |
||
| 151 | this.usuario = usuario; |
||
| 152 | } |
||
| 153 | |||
| 154 | @ManyToOne |
||
| 155 | @ForeignKey(name="fk_venda_vendedor") |
||
| 156 | @NotNull(message = "Informe o vendedor", groups = {Cadastrar.class, Alterar.class}) |
||
| 157 | @JoinColumn(name = "seq_vendedor", nullable = true) |
||
| 158 | public Vendedor getVendedor() { |
||
| 159 | return vendedor; |
||
| 160 | } |
||
| 161 | public void setVendedor(Vendedor vendedor) { |
||
| 162 | this.vendedor = vendedor; |
||
| 163 | } |
||
| 164 | |||
| 165 | @ManyToOne |
||
| 166 | @ForeignKey(name="fk_venda_indicacao") |
||
| 167 | @JoinColumn(name = "seq_indicacao", nullable = true) |
||
| 168 | public Vendedor getIndicacao() { |
||
| 169 | return indicacao; |
||
| 170 | } |
||
| 171 | public void setIndicacao(Vendedor indicacao) { |
||
| 172 | this.indicacao = indicacao; |
||
| 173 | } |
||
| 174 | |||
| 175 | @Column(name="dth_venda") |
||
| 176 | public Date getDataVenda() { |
||
| 177 | return dataVenda; |
||
| 178 | } |
||
| 179 | public void setDataVenda(Date dataVenda) { |
||
| 180 | this.dataVenda = dataVenda; |
||
| 181 | } |
||
| 182 | |||
| 183 | @Column(name="dsc_observacao") |
||
| 184 | @Size(max = 1000, message = "Limite de caracteres ultrapassado: Observação") |
||
| 185 | public String getObservacao() { |
||
| 186 | return observacao; |
||
| 187 | } |
||
| 188 | public void setObservacao(String observacao) { |
||
| 189 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 190 | } |
||
| 191 | |||
| 192 | @Column(name="tip_situacao") |
||
| 193 | public String getTipoSituacao() { |
||
| 194 | return tipoSituacao; |
||
| 195 | } |
||
| 196 | public void setTipoSituacao(String tipoSituacao) { |
||
| 197 | this.tipoSituacao = tipoSituacao; |
||
| 198 | } |
||
| 199 | |||
| 200 | @Transient |
||
| 201 | public String getTipoSituacaoDescricao() { |
||
| 202 | return TipoSituacaoVenda.parse(getTipoSituacao()).getDescricao(); |
||
| 203 | } |
||
| 204 | |||
| 205 | @Column(name="dsc_nota_fiscal") |
||
| 206 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Nota Fiscal") |
||
| 207 | public String getNotaFiscal() { |
||
| 208 | return notaFiscal; |
||
| 209 | } |
||
| 210 | public void setNotaFiscal(String notaFiscal) { |
||
| 211 | this.notaFiscal = notaFiscal; |
||
| 212 | } |
||
| 213 | |||
| 214 | @ManyToOne |
||
| 215 | @ForeignKey(name = "fk_venda_maquineta") |
||
| 216 | @JoinColumn(name="seq_maquineta", referencedColumnName="seq_maquineta", insertable=true, updatable=true) |
||
| 217 | public Maquineta getMaquineta() { |
||
| 218 | return maquineta; |
||
| 219 | } |
||
| 220 | public void setMaquineta(Maquineta maquineta) { |
||
| 221 | this.maquineta = maquineta; |
||
| 222 | } |
||
| 223 | |||
| 224 | /*@Column(name="tip_frete") |
||
| 225 | public String getTipoFrete() { |
||
| 226 | return tipoFrete; |
||
| 227 | } |
||
| 228 | public void setTipoFrete(String tipoFrete) { |
||
| 229 | this.tipoFrete = tipoFrete; |
||
| 230 | } |
||
| 231 | |||
| 232 | @Column(name="val_frete") |
||
| 233 | public Double getValorFrete() { |
||
| 234 | return valorFrete; |
||
| 235 | } |
||
| 236 | public void setValorFrete(Double valorFrete) { |
||
| 237 | this.valorFrete = valorFrete; |
||
| 238 | }*/ |
||
| 239 | |||
| 240 | @OneToMany(mappedBy="venda", cascade=CascadeType.ALL, fetch=FetchType.LAZY, orphanRemoval=true) |
||
| 241 | public Set<Lancamento> getListaLancamentos() { |
||
| 242 | return listaLancamentos; |
||
| 243 | } |
||
| 244 | public void setListaLancamentos(Set<Lancamento> listaLancamentos) { |
||
| 245 | this.listaLancamentos = listaLancamentos; |
||
| 246 | } |
||
| 247 | |||
| 248 | @OneToMany(mappedBy="venda", cascade=CascadeType.ALL, fetch=FetchType.LAZY, orphanRemoval=true) |
||
| 249 | public Set<VendaFormaPagamento> getListaVendaFormaPagamentos() { |
||
| 250 | return listaVendaFormaPagamentos; |
||
| 251 | } |
||
| 252 | public void setListaVendaFormaPagamentos(Set<VendaFormaPagamento> listaVendaFormaPagamentos) { |
||
| 253 | this.listaVendaFormaPagamentos = listaVendaFormaPagamentos; |
||
| 254 | } |
||
| 255 | |||
| 256 | @Transient |
||
| 257 | public String getTipoSituacaoFinanceira() { |
||
| 258 | return tipoSituacaoFinanceira; |
||
| 259 | } |
||
| 260 | @Transient |
||
| 261 | public void setTipoSituacaoFinanceira(String tipoSituacaoFinanceira) { |
||
| 262 | this.tipoSituacaoFinanceira = tipoSituacaoFinanceira; |
||
| 263 | } |
||
| 264 | |||
| 265 | @Transient |
||
| 266 | public String getJustificativaParaExcluir() { |
||
| 267 | return justificativaParaExcluir; |
||
| 268 | } |
||
| 269 | public void setJustificativaParaExcluir(String justificativaParaExcluir) { |
||
| 270 | this.justificativaParaExcluir = StringUtil.setarUpperCaseComTrim(justificativaParaExcluir); |
||
| 271 | } |
||
| 272 | |||
| 273 | @Transient |
||
| 274 | public Boolean getPermitirEmissaoNotaFiscal() { |
||
| 275 | return permitirEmissaoNotaFiscal; |
||
| 276 | } |
||
| 277 | public void setPermitirEmissaoNotaFiscal(Boolean permitirEmissaoNotaFiscal) { |
||
| 278 | this.permitirEmissaoNotaFiscal = permitirEmissaoNotaFiscal; |
||
| 279 | } |
||
| 280 | public void verificarSePermiteEmissaoNotaFiscal() { |
||
| 281 | setPermitirEmissaoNotaFiscal(this.getLoja().emissaoNotaFiscalPermitida()); |
||
| 282 | } |
||
| 283 | |||
| 284 | @Transient |
||
| 285 | public Boolean getEmitirNotaFiscal() { |
||
| 286 | return emitirNotaFiscal; |
||
| 287 | } |
||
| 288 | public void setEmitirNotaFiscal(Boolean emitirNotaFiscal) { |
||
| 289 | this.emitirNotaFiscal = emitirNotaFiscal; |
||
| 290 | } |
||
| 291 | |||
| 292 | @Transient |
||
| 293 | public Boolean getEmitirComanda() { |
||
| 294 | return emitirComanda; |
||
| 295 | } |
||
| 296 | public void setEmitirComanda(Boolean emitirComanda) { |
||
| 297 | this.emitirComanda = emitirComanda; |
||
| 298 | } |
||
| 299 | |||
| 300 | @Transient |
||
| 301 | public Boolean getCpfCnpjNaNotaFiscal() { |
||
| 302 | return cpfCnpjNaNotaFiscal; |
||
| 303 | } |
||
| 304 | public void setCpfCnpjNaNotaFiscal(Boolean cpfCnpjNaNotaFiscal) { |
||
| 305 | this.cpfCnpjNaNotaFiscal = cpfCnpjNaNotaFiscal; |
||
| 306 | } |
||
| 307 | |||
| 308 | @Transient |
||
| 309 | public List<Lancamento> getLancamentos() { |
||
| 310 | List<Lancamento> lancamentos = new ArrayList<Lancamento>(); |
||
| 311 | lancamentos.addAll(listaLancamentos); |
||
| 312 | return lancamentos; |
||
| 313 | } |
||
| 314 | |||
| 315 | @Transient |
||
| 316 | public List<Lancamento> getLancamentosValidos() { |
||
| 317 | List<Lancamento> lancamentos = new ArrayList<Lancamento>(); |
||
| 318 | for (Lancamento lancamento : listaLancamentos) { |
||
| 319 | if (lancamento.getAtivo()) { |
||
| 320 | lancamentos.add(lancamento); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | return lancamentos; |
||
| 324 | } |
||
| 325 | |||
| 326 | @Transient |
||
| 327 | public List<VendaFormaPagamento> getVendaFormaPagamentos() { |
||
| 328 | List<VendaFormaPagamento> pagamentos = new ArrayList<VendaFormaPagamento>(); |
||
| 329 | pagamentos.addAll(listaVendaFormaPagamentos); |
||
| 330 | return pagamentos; |
||
| 331 | } |
||
| 332 | /* |
||
| 333 | @Transient |
||
| 334 | public List<Parcela> getParcelas() { |
||
| 335 | List<Parcela> parcelas = new ArrayList<Parcela>(); |
||
| 336 | parcelas.addAll(listaParcelas); |
||
| 337 | return parcelas; |
||
| 338 | } |
||
| 339 | */ |
||
| 340 | @Transient |
||
| 341 | public Double getTotalLancamentos() { |
||
| 342 | Double total = 0.0; |
||
| 343 | for (Lancamento lancamento : getLancamentos()) { |
||
| 344 | total = total + lancamento.getValorVenda(); |
||
| 345 | } |
||
| 346 | return total; |
||
| 347 | } |
||
| 348 | |||
| 349 | @Transient |
||
| 350 | public Double getTotalVenda() { |
||
| 351 | Double total = new Double(0.0); |
||
| 352 | for (Lancamento lancamento : getLancamentos()) { |
||
| 353 | if (lancamento.getAtivo()) { |
||
| 354 | total = total + lancamento.getValorVenda(); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | return total; |
||
| 358 | } |
||
| 359 | |||
| 360 | @Transient |
||
| 361 | public Double getTotalPago() { |
||
| 362 | Double total = new Double(0.0); |
||
| 363 | for (VendaFormaPagamento pagamento : getVendaFormaPagamentos()) { |
||
| 364 | total = total + pagamento.getValorPagamento(); |
||
| 365 | } |
||
| 366 | return total; |
||
| 367 | } |
||
| 368 | |||
| 369 | @Transient |
||
| 370 | public Double getTotalPagoEmDinheiro() { |
||
| 371 | Double total = new Double(0.0); |
||
| 372 | for (VendaFormaPagamento pagamento : getVendaFormaPagamentos()) { |
||
| 373 | if (pagamento.getFormaPagamento().formaPagamentoEhDinheiro()) { |
||
| 374 | total = total + pagamento.getValorPagamento(); |
||
| 375 | } |
||
| 376 | } |
||
| 377 | return total; |
||
| 378 | } |
||
| 379 | |||
| 380 | @Transient |
||
| 381 | public Double getTotalPagoEmCupom() { |
||
| 382 | Double total = new Double(0.0); |
||
| 383 | for (VendaFormaPagamento pagamento : getVendaFormaPagamentos()) { |
||
| 384 | if (pagamento.getFormaPagamento().formaPagamentoEhCupom()) { |
||
| 385 | total = total + pagamento.getValorPagamento(); |
||
| 386 | } |
||
| 387 | } |
||
| 388 | return total; |
||
| 389 | } |
||
| 390 | |||
| 391 | @Transient |
||
| 689 | blopes | 392 | public Double getTotalPagoEmCashback() { |
| 393 | Double total = new Double(0.0); |
||
| 394 | for (VendaFormaPagamento pagamento : getVendaFormaPagamentos()) { |
||
| 395 | if (pagamento.getFormaPagamento().formaPagamentoEhCashback()) { |
||
| 396 | total = total + pagamento.getValorPagamento(); |
||
| 397 | } |
||
| 398 | } |
||
| 399 | return total; |
||
| 400 | } |
||
| 401 | |||
| 402 | @Transient |
||
| 106 | espaco | 403 | public String getProdutosVendidos() { |
| 404 | StringBuilder produtosVendidos = new StringBuilder(); |
||
| 405 | for (Lancamento lancamento : getLancamentos()) { |
||
| 406 | if (lancamento.getAtivo()) { |
||
| 407 | produtosVendidos.append("["); |
||
| 408 | produtosVendidos.append(lancamento.getProduto().getCodigoProdutoPadrao()); |
||
| 409 | produtosVendidos.append(": "); |
||
| 410 | produtosVendidos.append(lancamento.getProduto().getDescricaoDoModelo()); |
||
| 411 | produtosVendidos.append(", "); |
||
| 412 | produtosVendidos.append(lancamento.getProduto().getDescricao()); |
||
| 413 | produtosVendidos.append(" POR R$ "); |
||
| 414 | produtosVendidos.append(StringUtil.formatarValor(lancamento.getValorVenda())); |
||
| 415 | produtosVendidos.append("] "); |
||
| 416 | } |
||
| 417 | } |
||
| 418 | return produtosVendidos.toString(); |
||
| 419 | } |
||
| 420 | |||
| 421 | @Transient |
||
| 422 | public Long getSequencialDaLoja() { |
||
| 423 | return VerificadorUtil.naoEstaNulo(loja)? loja.getSequencial() : null; |
||
| 424 | } |
||
| 425 | |||
| 426 | @Transient |
||
| 427 | public Long getSequencialDoVendedor() { |
||
| 428 | return VerificadorUtil.naoEstaNulo(vendedor)? vendedor.getSequencial() : null; |
||
| 429 | } |
||
| 430 | |||
| 431 | @Transient |
||
| 432 | public String getLinhaPorSituacao() { |
||
| 433 | if (getTipoSituacao().equals(TipoSituacaoVenda.NOVO.getValor())) return "linha-novo"; |
||
| 434 | if (getTipoSituacao().equals(TipoSituacaoVenda.CONFERIDO.getValor())) return "linha-conferido"; |
||
| 435 | if (getTipoSituacao().equals(TipoSituacaoVenda.FINALIZADO.getValor())) return "linha-finalizado"; |
||
| 436 | if (getTipoSituacao().equals(TipoSituacaoVenda.PENDENCIAS.getValor())) return "linha-pendencias"; |
||
| 437 | return "even-row"; |
||
| 438 | } |
||
| 439 | |||
| 440 | @Transient |
||
| 441 | public String getNomeVendedorDaVenda() { |
||
| 442 | return VerificadorUtil.naoEstaNulo(getVendedor())? getVendedor().getNomeDaPessoa() : null; |
||
| 443 | } |
||
| 444 | |||
| 445 | @Transient |
||
| 446 | public Integer getQuantidadeDiasDaVenda() { |
||
| 447 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), getDataVenda()); |
||
| 448 | } |
||
| 449 | |||
| 450 | @Override |
||
| 451 | public int hashCode() { |
||
| 452 | final int prime = 31; |
||
| 453 | int result = 1; |
||
| 454 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 455 | return result; |
||
| 456 | } |
||
| 457 | |||
| 458 | @Override |
||
| 459 | public boolean equals(Object obj) { |
||
| 460 | if (this == obj) |
||
| 461 | return true; |
||
| 462 | if (obj == null) |
||
| 463 | return false; |
||
| 464 | if (getClass() != obj.getClass()) |
||
| 465 | return false; |
||
| 466 | Venda other = (Venda) obj; |
||
| 467 | if (sequencial == null) { |
||
| 468 | if (other.sequencial != null) |
||
| 469 | return false; |
||
| 470 | } else if (!sequencial.equals(other.sequencial)) |
||
| 471 | return false; |
||
| 472 | return true; |
||
| 473 | } |
||
| 474 | |||
| 475 | @Transient |
||
| 476 | public Pessoa getPessoaJuridicaDaLoja() { |
||
| 477 | return VerificadorUtil.naoEstaNulo(getLoja())? getLoja().getPessoaJuridica() : null; |
||
| 478 | } |
||
| 479 | |||
| 480 | @Transient |
||
| 481 | public String montarDadosDaVenda(List<Lancamento> lancamentos, List<VendaFormaPagamento> pagamentos) { |
||
| 482 | StringBuilder conteudo = new StringBuilder(); |
||
| 483 | //conteudo.append("OPERAÇÃO REALIZADA POR: " + this.getUsuario().getNome() + "\n"); |
||
| 484 | conteudo.append("VENDA ID: " + this.getSequencial() + "\n"); |
||
| 485 | conteudo.append("DATA: " + DataUtils.converterDataComHorarioParaString(this.getDataVenda()) + "\n"); |
||
| 486 | conteudo.append("LOJA: " + this.getLoja().getDescricao() + "\n"); |
||
| 487 | conteudo.append("VENDEDOR: " + this.getVendedor().getNomeDaPessoa() + "\n"); |
||
| 488 | conteudo.append("TOTAL: " + valorTotalVenda(lancamentos) + "\n"); |
||
| 489 | conteudo.append("OBS.: " + this.getObservacao() + "\n"); |
||
| 490 | if (VerificadorUtil.naoEstaNuloOuVazio(this.getJustificativaParaExcluir())) { |
||
| 491 | conteudo.append("JUSTIFICATIVA: " + this.getJustificativaParaExcluir() + "\n"); |
||
| 492 | } else { |
||
| 493 | conteudo.append("SEM JUSTIFICATIVA\n"); |
||
| 494 | } |
||
| 495 | conteudo.append("__________________________________________________\n\n"); |
||
| 496 | for (Lancamento lancamento : lancamentos) { |
||
| 497 | conteudo.append(lancamento.getProduto().getCodigoProdutoPadrao() + " | "); |
||
| 498 | conteudo.append(lancamento.getProduto().getDescricaoComModeloCompleta() + ", "); |
||
| 499 | conteudo.append("R$" + lancamento.getValorVenda()); |
||
| 500 | if (lancamento.comDescontos()) { |
||
| 501 | conteudo.append(" (COM DESCONTO DE R$" + lancamento.valorDescontos() + ")"); |
||
| 502 | } |
||
| 503 | conteudo.append("\n"); |
||
| 504 | } |
||
| 505 | conteudo.append("__________________________________________________\n\n"); |
||
| 506 | for (VendaFormaPagamento pagamento : pagamentos) { |
||
| 507 | if (VerificadorUtil.naoEstaNulo(pagamento.getBandeiraCartao())) { |
||
| 508 | conteudo.append(pagamento.getFormaPagamento().getDescricao() + " - " + pagamento.getBandeiraCartao().getDescricao() + ": R$" + pagamento.getValorPagamento() + "\n"); |
||
| 509 | } else { |
||
| 510 | conteudo.append(pagamento.getFormaPagamento().getDescricao() + ": R$" + pagamento.getValorPagamento() + "\n"); |
||
| 511 | } |
||
| 512 | conteudo.append("\n"); |
||
| 513 | } |
||
| 514 | return conteudo.toString(); |
||
| 515 | } |
||
| 516 | |||
| 517 | @Transient |
||
| 518 | private Double valorTotalVenda(List<Lancamento> lancamentos) { |
||
| 519 | Double total = new Double(0.0); |
||
| 520 | for (Lancamento lancamento : lancamentos) { |
||
| 521 | if (lancamento.getAtivo()) { |
||
| 522 | total = total + lancamento.getValorVenda(); |
||
| 523 | } |
||
| 524 | } |
||
| 525 | return total; |
||
| 526 | } |
||
| 527 | |||
| 528 | @Transient |
||
| 529 | public String getEmailDoCliente() { |
||
| 530 | return VerificadorUtil.naoEstaNulo(getCliente())? getCliente().getEmail() : ""; |
||
| 531 | } |
||
| 532 | |||
| 533 | @Transient |
||
| 534 | public String getCertificadoDaLoja() { |
||
| 535 | return VerificadorUtil.naoEstaNulo(getLoja())? getLoja().getDescricaoCertificado() : ""; |
||
| 536 | } |
||
| 537 | |||
| 538 | @Transient |
||
| 539 | public String getDescricaoMaquineta() { |
||
| 540 | return VerificadorUtil.naoEstaNulo(getMaquineta())? getMaquineta().descricaoCompleta() : "NENHUMA"; |
||
| 541 | } |
||
| 542 | |||
| 543 | } |