Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 200 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.List; |
||
| 5 | |||
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 9 | import org.springframework.context.annotation.Scope; |
||
| 10 | |||
| 11 | import br.com.ec.controller.managedbean.datamodel.ParcelaDataModel; |
||
| 12 | import br.com.ec.core.consulta.ParametrosConsulta; |
||
| 13 | import br.com.ec.core.exception.NegocioException; |
||
| 14 | import br.com.ec.core.generic.GenericService; |
||
| 15 | import br.com.ec.core.util.VerificadorUtil; |
||
| 16 | import br.com.ec.domain.dto.ParametrosVendaDTO; |
||
| 17 | import br.com.ec.domain.model.BandeiraCartao; |
||
| 18 | import br.com.ec.domain.model.Cliente; |
||
| 19 | import br.com.ec.domain.model.Conta; |
||
| 20 | import br.com.ec.domain.model.Cupom; |
||
| 21 | import br.com.ec.domain.model.FormaPagamento; |
||
| 22 | import br.com.ec.domain.model.Lancamento; |
||
| 23 | import br.com.ec.domain.model.Loja; |
||
| 24 | import br.com.ec.domain.model.Modelo; |
||
| 25 | import br.com.ec.domain.model.NotaFiscal; |
||
| 26 | import br.com.ec.domain.model.Pedido; |
||
| 27 | import br.com.ec.domain.model.PedidoProduto; |
||
| 28 | import br.com.ec.domain.model.Produto; |
||
| 29 | import br.com.ec.domain.model.Venda; |
||
| 30 | import br.com.ec.domain.model.VendaFormaPagamento; |
||
| 31 | import br.com.ec.domain.model.Vendedor; |
||
| 32 | import br.com.ec.domain.model.tipos.TipoCupom; |
||
| 33 | import br.com.ec.domain.model.tipos.TipoFrete; |
||
| 34 | import br.com.ec.domain.model.tipos.TipoSituacaoPedido; |
||
| 35 | import br.com.ec.domain.service.bandeiracartao.BandeiraCartaoService; |
||
| 36 | import br.com.ec.domain.service.cliente.ClienteService; |
||
| 37 | import br.com.ec.domain.service.conta.ContaService; |
||
| 38 | import br.com.ec.domain.service.cupom.CupomService; |
||
| 39 | import br.com.ec.domain.service.email.impl.GerenciadorEmailImpl; |
||
| 40 | import br.com.ec.domain.service.formapagamento.FormaPagamentoService; |
||
| 41 | import br.com.ec.domain.service.lancamento.LancamentoService; |
||
| 42 | import br.com.ec.domain.service.loja.LojaService; |
||
| 43 | import br.com.ec.domain.service.modelo.ModeloService; |
||
| 44 | import br.com.ec.domain.service.notafiscal.NotaFiscalService; |
||
| 45 | import br.com.ec.domain.service.parcela.ParcelaService; |
||
| 46 | import br.com.ec.domain.service.pedido.PedidoService; |
||
| 47 | import br.com.ec.domain.service.produto.ProdutoService; |
||
| 48 | import br.com.ec.domain.service.produtodaloja.ProdutoLojaService; |
||
| 49 | import br.com.ec.domain.service.seguranca.ContextoSeguranca; |
||
| 50 | import br.com.ec.domain.service.venda.VendaService; |
||
| 51 | import br.com.ec.domain.service.vendaformapagamento.VendaFormaPagamentoService; |
||
| 52 | import br.com.ec.domain.service.vendedor.VendedorService; |
||
| 53 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 54 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 55 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 56 | import br.com.ec.web.generic.AbstractBean; |
||
| 57 | import br.com.ec.web.message.LancadorMensagem; |
||
| 58 | import net.sf.jasperreports.engine.JasperExportManager; |
||
| 59 | import net.sf.jasperreports.engine.JasperPrint; |
||
| 60 | |||
| 61 | @Named |
||
| 62 | @Scope("view") |
||
| 63 | public class VendaBean extends AbstractBean<Venda> implements Serializable { |
||
| 64 | |||
| 65 | private static final long serialVersionUID = 1L; |
||
| 66 | |||
| 67 | private LojaService lojaService; |
||
| 68 | private VendaService vendaService; |
||
| 69 | private ProdutoService produtoService; |
||
| 70 | private ProdutoLojaService produtoLojaService; |
||
| 71 | private VendedorService vendedorService; |
||
| 72 | private FormaPagamentoService formaPagamentoService; |
||
| 73 | private VendaFormaPagamentoService vendaFormaPagamentoService; |
||
| 74 | private BandeiraCartaoService bandeiraCartaoService; |
||
| 75 | private ParcelaService parcelaService; |
||
| 76 | private ContaService contaAReceberService; |
||
| 77 | private ClienteService clienteService; |
||
| 78 | private ModeloService modeloService; |
||
| 79 | private NotaFiscalService notaFiscalService; |
||
| 80 | private CupomService cupomService; |
||
| 81 | private LancamentoService lancamentoService; |
||
| 82 | private PedidoService pedidoService; |
||
| 83 | private ContextoSeguranca contextoSeguranca; |
||
| 84 | |||
| 85 | private String codigoProduto; |
||
| 86 | private String codigoPedido; |
||
| 87 | private Lancamento lancamento; |
||
| 88 | private String localizacaoNova; |
||
| 89 | private String cpfCnpjCliente; |
||
| 90 | private ParametrosVendaDTO parametrosVenda; |
||
| 91 | private Venda vendaSelecionada; |
||
| 92 | private String observacaoExclusao; |
||
| 93 | private Cupom cupomSelecionado; |
||
| 94 | private Lancamento lancamentoSelecionado; |
||
| 95 | |||
| 96 | private FormaPagamento formaPagamento; |
||
| 97 | private BandeiraCartao bandeiraCartao; |
||
| 98 | private Double valorPagamento; |
||
| 99 | |||
| 100 | private List<FormaPagamento> formasDePagamentoDeCredito; |
||
| 101 | private List<BandeiraCartao> bandeirasDeDebito; |
||
| 102 | private List<BandeiraCartao> bandeirasDeCredito; |
||
| 103 | |||
| 104 | private ParcelaDataModel parcelas; |
||
| 105 | private Boolean emitirCupom = false; |
||
| 106 | private String emailParaEnvio; |
||
| 107 | |||
| 108 | private List<Vendedor> vendedoresColaboradores; |
||
| 109 | private List<Vendedor> vendedoresColaboradoresAtivos; |
||
| 110 | private List<Vendedor> vendedoresExternos; |
||
| 111 | |||
| 112 | @Inject |
||
| 113 | public VendaBean(LojaService lojaService, VendaService vendaService, ProdutoService produtoService, ProdutoLojaService produtoLojaService, |
||
| 114 | VendedorService vendedorService, FormaPagamentoService formaPagamentoService, VendaFormaPagamentoService vendaFormaPagamentoService, |
||
| 115 | BandeiraCartaoService bandeiraCartaoService, ParcelaService parcelaService, |
||
| 116 | ContaService contaAReceberService, ClienteService clienteService, ModeloService modeloService, |
||
| 117 | NotaFiscalService notaFiscalService, CupomService cupomService, LancamentoService lancamentoService, PedidoService pedidoService, |
||
| 118 | ContextoSeguranca contextoSeguranca) { |
||
| 119 | this.lojaService = lojaService; |
||
| 120 | this.vendaService = vendaService; |
||
| 121 | this.produtoService = produtoService; |
||
| 122 | this.produtoLojaService = produtoLojaService; |
||
| 123 | this.vendedorService = vendedorService; |
||
| 124 | this.formaPagamentoService = formaPagamentoService; |
||
| 125 | this.vendaFormaPagamentoService = vendaFormaPagamentoService; |
||
| 126 | this.bandeiraCartaoService = bandeiraCartaoService; |
||
| 127 | this.parcelaService = parcelaService; |
||
| 128 | this.contaAReceberService = contaAReceberService; |
||
| 129 | this.clienteService = clienteService; |
||
| 130 | this.modeloService = modeloService; |
||
| 131 | this.notaFiscalService = notaFiscalService; |
||
| 132 | this.cupomService = cupomService; |
||
| 133 | this.lancamentoService = lancamentoService; |
||
| 134 | this.pedidoService = pedidoService; |
||
| 135 | this.contextoSeguranca = contextoSeguranca; |
||
| 136 | } |
||
| 137 | |||
| 138 | @Override |
||
| 139 | public void preCarregamento() { |
||
| 140 | limparEntidade(); |
||
| 141 | } |
||
| 142 | |||
| 143 | private void setarParametrosDaLoja() { |
||
| 144 | parametrosVenda = new ParametrosVendaDTO(); |
||
| 145 | if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) { |
||
| 146 | Loja loja = new Loja(); |
||
| 147 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 148 | parametrosVenda.setLoja(lojaService.consultarPorId(loja)); |
||
| 149 | parametrosVenda.setMaquineta(parametrosVenda.getLoja().getMaquineta()); |
||
| 150 | } |
||
| 151 | parametrosVenda.setUsuario(contextoSeguranca.obterUsuario()); |
||
| 152 | } |
||
| 153 | |||
| 154 | @Override |
||
| 155 | public void preDetalhar(Venda venda) { |
||
| 156 | setEntidade(vendaService.detalharVendaCompleta(venda)); |
||
| 157 | } |
||
| 158 | |||
| 159 | @Override |
||
| 160 | public void limparEntidade() { |
||
| 161 | entidade = new Venda(); |
||
| 162 | parametrosConsulta = new ParametrosConsulta<Venda>(); |
||
| 163 | parametrosConsulta.setEntidade(entidade); |
||
| 164 | |||
| 165 | setLancamento(new Lancamento()); |
||
| 166 | setarParametrosDaLoja(); |
||
| 167 | setParcelas(new ParcelaDataModel()); |
||
| 168 | } |
||
| 169 | |||
| 170 | @Override |
||
| 171 | public GenericService<Venda> getService() { |
||
| 172 | return vendaService; |
||
| 173 | } |
||
| 174 | |||
| 175 | @Override |
||
| 176 | public Venda getEntidade() { |
||
| 177 | return entidade; |
||
| 178 | } |
||
| 179 | |||
| 180 | @Override |
||
| 181 | public Venda getId() { |
||
| 182 | return getEntidade(); |
||
| 183 | } |
||
| 184 | |||
| 185 | public String getCodigoProduto() { |
||
| 186 | return codigoProduto; |
||
| 187 | } |
||
| 188 | public void setCodigoProduto(String codigoProduto) { |
||
| 189 | this.codigoProduto = codigoProduto; |
||
| 190 | } |
||
| 191 | |||
| 192 | public String getCodigoPedido() { |
||
| 193 | return codigoPedido; |
||
| 194 | } |
||
| 195 | public void setCodigoPedido(String codigoPedido) { |
||
| 196 | this.codigoPedido = codigoPedido; |
||
| 197 | } |
||
| 198 | |||
| 199 | public Lancamento getLancamento() { |
||
| 200 | return lancamento; |
||
| 201 | } |
||
| 202 | public void setLancamento(Lancamento lancamento) { |
||
| 203 | this.lancamento = lancamento; |
||
| 204 | } |
||
| 205 | |||
| 206 | public String getLocalizacaoNova() { |
||
| 207 | return localizacaoNova; |
||
| 208 | } |
||
| 209 | public void setLocalizacaoNova(String localizacaoNova) { |
||
| 210 | this.localizacaoNova = localizacaoNova; |
||
| 211 | } |
||
| 212 | |||
| 213 | public String getCpfCnpjCliente() { |
||
| 214 | return VerificadorUtil.naoEstaNulo(cpfCnpjCliente)? cpfCnpjCliente.replace(".", "").replace("-", "") : cpfCnpjCliente; |
||
| 215 | } |
||
| 216 | public void setCpfCnpjCliente(String cpfCnpjCliente) { |
||
| 217 | this.cpfCnpjCliente = cpfCnpjCliente; |
||
| 218 | } |
||
| 219 | |||
| 220 | public ParametrosVendaDTO getParametrosVenda() { |
||
| 221 | return parametrosVenda; |
||
| 222 | } |
||
| 223 | public void setParametrosVenda(ParametrosVendaDTO parametrosVenda) { |
||
| 224 | this.parametrosVenda = parametrosVenda; |
||
| 225 | } |
||
| 226 | |||
| 227 | public Venda getVendaSelecionada() { |
||
| 228 | return vendaSelecionada; |
||
| 229 | } |
||
| 230 | public void setVendaSelecionada(Venda vendaSelecionada) { |
||
| 231 | this.vendaSelecionada = vendaSelecionada; |
||
| 232 | } |
||
| 233 | |||
| 234 | public String getObservacaoExclusao() { |
||
| 235 | return observacaoExclusao; |
||
| 236 | } |
||
| 237 | public void setObservacaoExclusao(String observacaoExclusao) { |
||
| 238 | this.observacaoExclusao = observacaoExclusao; |
||
| 239 | } |
||
| 240 | |||
| 241 | public Cupom getCupomSelecionado() { |
||
| 242 | return cupomSelecionado; |
||
| 243 | } |
||
| 244 | public void setCupomSelecionado(Cupom cupomSelecionado) { |
||
| 245 | this.cupomSelecionado = cupomSelecionado; |
||
| 246 | } |
||
| 247 | |||
| 248 | public Lancamento getLancamentoSelecionado() { |
||
| 249 | return lancamentoSelecionado; |
||
| 250 | } |
||
| 251 | public void setLancamentoSelecionado(Lancamento lancamentoSelecionado) { |
||
| 252 | this.lancamentoSelecionado = lancamentoSelecionado; |
||
| 253 | } |
||
| 254 | |||
| 255 | public FormaPagamento getFormaPagamento() { |
||
| 256 | return formaPagamento; |
||
| 257 | } |
||
| 258 | public void setFormaPagamento(FormaPagamento formaPagamento) { |
||
| 259 | this.formaPagamento = formaPagamento; |
||
| 260 | } |
||
| 261 | |||
| 262 | public BandeiraCartao getBandeiraCartao() { |
||
| 263 | return bandeiraCartao; |
||
| 264 | } |
||
| 265 | public void setBandeiraCartao(BandeiraCartao bandeiraCartao) { |
||
| 266 | this.bandeiraCartao = bandeiraCartao; |
||
| 267 | } |
||
| 268 | |||
| 269 | public Double getValorPagamento() { |
||
| 270 | return valorPagamento; |
||
| 271 | } |
||
| 272 | public void setValorPagamento(Double valorPagamento) { |
||
| 273 | this.valorPagamento = valorPagamento; |
||
| 274 | } |
||
| 275 | |||
| 276 | public List<FormaPagamento> getFormasDePagamentoDeCredito() { |
||
| 277 | if (VerificadorUtil.estaNulo(formasDePagamentoDeCredito)) { |
||
| 278 | setFormasDePagamentoDeCredito(formaPagamentoService.consultarFormasDePagamentoDeCredito()); |
||
| 279 | } |
||
| 280 | return formasDePagamentoDeCredito; |
||
| 281 | } |
||
| 282 | public void setFormasDePagamentoDeCredito(List<FormaPagamento> formasDePagamentoDeCredito) { |
||
| 283 | this.formasDePagamentoDeCredito = formasDePagamentoDeCredito; |
||
| 284 | } |
||
| 285 | |||
| 286 | public List<BandeiraCartao> getBandeirasDeDebito() { |
||
| 287 | if (VerificadorUtil.estaNulo(bandeirasDeDebito)) { |
||
| 288 | setBandeirasDeDebito(bandeiraCartaoService.consultarBandeiraCartoesDeDebito()); |
||
| 289 | } |
||
| 290 | return bandeirasDeDebito; |
||
| 291 | } |
||
| 292 | public void setBandeirasDeDebito(List<BandeiraCartao> bandeirasDeDebito) { |
||
| 293 | this.bandeirasDeDebito = bandeirasDeDebito; |
||
| 294 | } |
||
| 295 | |||
| 296 | public List<BandeiraCartao> getBandeirasDeCredito() { |
||
| 297 | if (VerificadorUtil.estaNulo(bandeirasDeCredito)) { |
||
| 298 | setBandeirasDeCredito(bandeiraCartaoService.consultarBandeiraCartoesDeCredito()); |
||
| 299 | } |
||
| 300 | return bandeirasDeCredito; |
||
| 301 | } |
||
| 302 | public void setBandeirasDeCredito(List<BandeiraCartao> bandeirasDeCredito) { |
||
| 303 | this.bandeirasDeCredito = bandeirasDeCredito; |
||
| 304 | } |
||
| 305 | |||
| 306 | public List<Venda> getConsultarTodas() { |
||
| 307 | return vendaService.consultarTodos(new Venda()); |
||
| 308 | } |
||
| 309 | |||
| 310 | public ParcelaDataModel getParcelas() { |
||
| 311 | atualizarParcelas(getParametrosVenda().getVenda()); |
||
| 312 | return parcelas; |
||
| 313 | } |
||
| 314 | public void setParcelas(ParcelaDataModel parcelas) { |
||
| 315 | this.parcelas = parcelas; |
||
| 316 | } |
||
| 317 | public void atualizarParcelas(Venda venda) { |
||
| 318 | if (VerificadorUtil.naoEstaNulo(venda)) { |
||
| 319 | setParcelas(new ParcelaDataModel(parcelaService.consultarParcelasDaVenda(getParametrosVenda().getVenda().getSequencial()))); |
||
| 320 | } |
||
| 321 | } |
||
| 322 | |||
| 323 | public Boolean getEmitirCupom() { |
||
| 324 | return emitirCupom; |
||
| 325 | } |
||
| 326 | public void setEmitirCupom(Boolean emitirCupom) { |
||
| 327 | this.emitirCupom = emitirCupom; |
||
| 328 | } |
||
| 329 | |||
| 330 | public String getEmailParaEnvio() { |
||
| 331 | return emailParaEnvio; |
||
| 332 | } |
||
| 333 | public void setEmailParaEnvio(String emailParaEnvio) { |
||
| 334 | this.emailParaEnvio = emailParaEnvio; |
||
| 335 | } |
||
| 336 | |||
| 337 | public List<Vendedor> getVendedoresColaboradores() { |
||
| 338 | if (VerificadorUtil.estaNulo(vendedoresColaboradores)) { |
||
| 339 | setVendedoresColaboradores(vendedorService.consultarVendedoresColaboradores()); |
||
| 340 | } |
||
| 341 | return vendedoresColaboradores; |
||
| 342 | } |
||
| 343 | public void setVendedoresColaboradores(List<Vendedor> vendedoresColaboradores) { |
||
| 344 | this.vendedoresColaboradores = vendedoresColaboradores; |
||
| 345 | } |
||
| 346 | |||
| 347 | public List<Vendedor> getVendedoresColaboradoresAtivos() { |
||
| 348 | if (VerificadorUtil.estaNulo(vendedoresColaboradoresAtivos)) { |
||
| 349 | setVendedoresColaboradoresAtivos(vendedorService.consultarVendedoresColaboradoresAtivos(null)); |
||
| 350 | } |
||
| 351 | return vendedoresColaboradoresAtivos; |
||
| 352 | } |
||
| 353 | public void setVendedoresColaboradoresAtivos(List<Vendedor> vendedoresColaboradoresAtivos) { |
||
| 354 | this.vendedoresColaboradoresAtivos = vendedoresColaboradoresAtivos; |
||
| 355 | } |
||
| 356 | |||
| 357 | public List<Vendedor> getVendedoresExternos() { |
||
| 358 | if (VerificadorUtil.estaNulo(vendedoresExternos)) { |
||
| 359 | setVendedoresExternos(vendedorService.consultarVendedoresExternosAtivos()); |
||
| 360 | } |
||
| 361 | return vendedoresExternos; |
||
| 362 | } |
||
| 363 | public void setVendedoresExternos(List<Vendedor> vendedoresExternos) { |
||
| 364 | this.vendedoresExternos = vendedoresExternos; |
||
| 365 | } |
||
| 366 | |||
| 367 | public TipoFrete[] getTiposFrete() { |
||
| 368 | return TipoFrete.values(); |
||
| 369 | } |
||
| 370 | |||
| 371 | /***************************************************************/ |
||
| 372 | |||
| 373 | public void selecionarCodigoProduto(String codigoProduto) { |
||
| 374 | setCodigoProduto(codigoProduto); |
||
| 375 | } |
||
| 376 | |||
| 377 | public void prepararParaAlterarVenda(final Venda venda) { |
||
| 378 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 379 | public void execute() { |
||
| 380 | parametrosVenda = new ParametrosVendaDTO(venda); |
||
| 381 | } |
||
| 382 | }); |
||
| 383 | } |
||
| 384 | |||
| 385 | public void prepararParaAlterarVendaFinanceiro(final Venda venda) { |
||
| 386 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 387 | public void execute() { |
||
| 388 | parametrosVenda = new ParametrosVendaDTO(venda); |
||
| 389 | setParcelas(new ParcelaDataModel(parcelaService.consultarParcelasDaVenda(venda.getSequencial()))); |
||
| 390 | } |
||
| 391 | }); |
||
| 392 | } |
||
| 393 | |||
| 394 | public void prepararParaExcluirVenda(final Venda venda) { |
||
| 395 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 396 | public void execute() { |
||
| 397 | setVendaSelecionada(venda); |
||
| 398 | List<NotaFiscal> notasFiscais = notaFiscalService.consultarNotasFiscais(venda); |
||
| 399 | if (!notasFiscais.isEmpty()) { |
||
| 400 | String observacao = ""; |
||
| 401 | for (NotaFiscal notaFiscal : notasFiscais) { |
||
| 402 | observacao = notaFiscal.getNumeroNotaFiscal() + "; "; |
||
| 403 | } |
||
| 404 | setObservacaoExclusao("OBS.: NOTAS FISCAIS VINCULADAS: " + observacao); |
||
| 405 | } else { |
||
| 406 | setObservacaoExclusao(""); |
||
| 407 | } |
||
| 408 | } |
||
| 409 | }); |
||
| 410 | } |
||
| 411 | |||
| 412 | public void consultarProduto() { |
||
| 413 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 414 | public void execute() { |
||
| 415 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 416 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 417 | getLancamento().preencher(produtoSelecionado); |
||
| 418 | } |
||
| 419 | getLancamento().setVenda(getEntidade()); |
||
| 420 | getLancamento().setAtivo(true); |
||
| 421 | } |
||
| 422 | }); |
||
| 423 | } |
||
| 424 | |||
| 425 | public void consultarProdutoPrecoPopular() { |
||
| 426 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 427 | public void execute() { |
||
| 428 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 429 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 430 | getLancamento().preencherComPrecoPopular(produtoSelecionado); |
||
| 431 | } |
||
| 432 | getLancamento().setVenda(getEntidade()); |
||
| 433 | getLancamento().setAtivo(true); |
||
| 434 | } |
||
| 435 | }); |
||
| 436 | } |
||
| 437 | |||
| 438 | public void consultarProdutoPrecoAtacado() { |
||
| 439 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 440 | public void execute() { |
||
| 441 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoOuCodigoEAN(getCodigoProduto()); |
||
| 442 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 443 | getLancamento().preencherComPrecoAtacado(produtoSelecionado); |
||
| 444 | } |
||
| 445 | getLancamento().setVenda(getEntidade()); |
||
| 446 | getLancamento().setAtivo(true); |
||
| 447 | } |
||
| 448 | }); |
||
| 449 | } |
||
| 450 | |||
| 451 | public void consultarProdutoFarma() { |
||
| 452 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 453 | public void execute() { |
||
| 454 | Produto produtoSelecionado = produtoService.consultarProdutoPorCodigoRapidoOuCodigoEAN(getCodigoProduto()); |
||
| 455 | if (VerificadorUtil.naoEstaNulo(produtoSelecionado)) { |
||
| 456 | getLancamento().preencher(produtoSelecionado); |
||
| 457 | } |
||
| 458 | getLancamento().setVenda(getEntidade()); |
||
| 459 | getLancamento().setAtivo(true); |
||
| 460 | } |
||
| 461 | }); |
||
| 462 | } |
||
| 463 | |||
| 464 | public void adicionarLancamento() { |
||
| 465 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 466 | public void execute() { |
||
| 467 | if (VerificadorUtil.estaNulo(getLancamento().getValorVenda())) { |
||
| 468 | getLancamento().setValorVenda(new Double(0.0)); |
||
| 469 | } |
||
| 470 | for (int i = 1; i <= getLancamento().getQuantidadeLancamento(); i++) { |
||
| 471 | try { |
||
| 472 | getLancamento().setObservacaoNotaFiscal(getLancamento().getObservacaoIMEI1() + " " + getLancamento().getObservacaoIMEI2()); |
||
| 473 | getLancamento().getObservacaoNotaFiscal().trim(); |
||
| 474 | getParametrosVenda().getLancamentos().add((Lancamento)getLancamento().clone()); |
||
| 475 | } catch (CloneNotSupportedException e) { |
||
| 476 | e.printStackTrace(); |
||
| 477 | } |
||
| 478 | } |
||
| 479 | // atualizarValorVendaSeForLojaFarmaciaEProdutoSemValorVenda(getLancamento()); |
||
| 480 | limparLancamento(); |
||
| 481 | LancadorMensagem.lancarSucesso("PRODUTO ADICIONADO COM SUCESSO"); |
||
| 482 | } |
||
| 483 | }); |
||
| 484 | } |
||
| 485 | |||
| 486 | public void adicionarLancamentoRestaurante() { |
||
| 487 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 488 | public void execute() { |
||
| 489 | if (VerificadorUtil.estaNulo(getLancamento().getValorVenda())) { |
||
| 490 | getLancamento().setValorVenda(new Double(0.0)); |
||
| 491 | } |
||
| 492 | for (int i = 1; i <= getLancamento().getQuantidadeLancamento(); i++) { |
||
| 493 | try { |
||
| 494 | String opcoes = ""; |
||
| 495 | for (String opcao : getLancamento().getOpcoesRestaurante()) { |
||
| 496 | opcoes = opcoes + opcao + " - "; |
||
| 497 | } |
||
| 498 | String observacoes = ""; |
||
| 499 | if (VerificadorUtil.naoEstaNuloOuVazio(opcoes)) { |
||
| 500 | observacoes = observacoes + opcoes; |
||
| 501 | } |
||
| 502 | if (VerificadorUtil.naoEstaNuloOuVazio(getLancamento().getOpcaoRestaurante())) { |
||
| 503 | observacoes = observacoes + getLancamento().getOpcaoRestaurante(); |
||
| 504 | } |
||
| 505 | if (VerificadorUtil.naoEstaNuloOuVazio(getLancamento().getObservacaoRestaurante())) { |
||
| 506 | observacoes = observacoes + " (" + getLancamento().getObservacaoRestaurante() + ")"; |
||
| 507 | } |
||
| 508 | getLancamento().setObservacao(observacoes); |
||
| 509 | getParametrosVenda().getLancamentos().add((Lancamento)getLancamento().clone()); |
||
| 510 | } catch (CloneNotSupportedException e) { |
||
| 511 | e.printStackTrace(); |
||
| 512 | } |
||
| 513 | } |
||
| 514 | limparLancamento(); |
||
| 515 | LancadorMensagem.lancarSucesso("PRODUTO ADICIONADO COM SUCESSO"); |
||
| 516 | } |
||
| 517 | }); |
||
| 518 | } |
||
| 519 | |||
| 520 | /* |
||
| 521 | * MÉTODO DA FARMÁCIA |
||
| 522 | *//* |
||
| 523 | protected void atualizarValorVendaSeForLojaFarmaciaEProdutoSemValorVenda(Lancamento lancamento) { |
||
| 524 | if (getParametrosVenda().getLoja().getSequencial().equals(ConstantesSEC.SEQUENCIAL_LOJA_FARMACIA_7)) { |
||
| 525 | if (lancamento.getProduto().tipoProdutoEhRemedioOuOutros()) { |
||
| 526 | Produto produto = produtoService.consultarProdutoPorCodigo(lancamento.getProduto().getCodigo()); |
||
| 527 | if (VerificadorUtil.estaNuloOuVazio(produto.getValorVarejo())) { |
||
| 528 | produto.setValorVarejo(lancamento.getValorVenda()); |
||
| 529 | produtoService.alterar(produto); |
||
| 530 | } |
||
| 531 | } |
||
| 532 | } |
||
| 533 | }*/ |
||
| 534 | |||
| 535 | public void removerLancamento(final Lancamento lancamento) { |
||
| 536 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 537 | public void execute() { |
||
| 538 | getParametrosVenda().getLancamentos().remove(lancamento); |
||
| 539 | LancadorMensagem.lancarSucesso("PRODUTO REMOVIDO COM SUCESSO"); |
||
| 540 | } |
||
| 541 | }); |
||
| 542 | } |
||
| 543 | |||
| 544 | public void limparLancamento() { |
||
| 545 | setLancamento(new Lancamento()); |
||
| 546 | setCodigoProduto(""); |
||
| 547 | } |
||
| 548 | |||
| 549 | public void limparPagamento() { |
||
| 550 | setBandeiraCartao(null); |
||
| 551 | setValorPagamento(null); |
||
| 552 | } |
||
| 553 | |||
| 554 | public void prepararPagamento() { |
||
| 555 | limparPagamento(); |
||
| 556 | Double subtotal = getParametrosVenda().valorTotalLancamentos() /*+ getParametrosVenda().getValorFrete() */ - getParametrosVenda().valorTotalPago(); |
||
| 557 | if (subtotal > 0) { |
||
| 558 | setValorPagamento(subtotal); |
||
| 559 | } |
||
| 560 | } |
||
| 561 | |||
| 562 | public void prepararPagamentoComCupom() { |
||
| 563 | prepararPagamento(); |
||
| 564 | setCupomSelecionado(new Cupom()); |
||
| 565 | } |
||
| 566 | |||
| 567 | public void adicionarPagamentoEmDinheiro() { |
||
| 568 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 569 | public void execute() { |
||
| 570 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DINHEIRO)); |
||
| 571 | } |
||
| 572 | }); |
||
| 573 | } |
||
| 574 | |||
| 575 | public void adicionarPagamentoEmPagseguro() { |
||
| 576 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 577 | public void execute() { |
||
| 578 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_PAGSEGURO)); |
||
| 579 | } |
||
| 580 | }); |
||
| 581 | } |
||
| 582 | |||
| 583 | public void adicionarPagamentoEmPix() { |
||
| 584 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 585 | public void execute() { |
||
| 586 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_PIX)); |
||
| 587 | } |
||
| 588 | }); |
||
| 589 | } |
||
| 590 | |||
| 591 | public void adicionarPagamentoComOutros() { |
||
| 592 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 593 | public void execute() { |
||
| 594 | adicionarPagamento(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_OUTROS)); |
||
| 595 | } |
||
| 596 | }); |
||
| 597 | } |
||
| 598 | |||
| 599 | private void adicionarPagamento(FormaPagamento formaPagamento) { |
||
| 600 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), formaPagamentoService.consultarPorId(formaPagamento)); |
||
| 601 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 602 | adicionarPagamento(vendaFormaPagamento); |
||
| 603 | } |
||
| 604 | |||
| 605 | public void adicionarPagamentoEmDebito() { |
||
| 606 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 607 | public void execute() { |
||
| 608 | FormaPagamento formaPagamento = formaPagamentoService.consultarPorId(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DEBITO)); |
||
| 609 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), formaPagamento, getBandeiraCartao()); |
||
| 610 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 611 | verificarPagamentoNoCartao(formaPagamento); |
||
| 612 | adicionarPagamento(vendaFormaPagamento); |
||
| 613 | } |
||
| 614 | }); |
||
| 615 | } |
||
| 616 | |||
| 617 | public void adicionarPagamentoEmCredito() { |
||
| 618 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 619 | public void execute() { |
||
| 620 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), getFormaPagamento(), getBandeiraCartao()); |
||
| 621 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 622 | verificarPagamentoNoCartao(getFormaPagamento()); |
||
| 623 | adicionarPagamento(vendaFormaPagamento); |
||
| 624 | } |
||
| 625 | }); |
||
| 626 | } |
||
| 627 | |||
| 628 | public void adicionarPagamentoComCupom() { |
||
| 629 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 630 | public void execute() { |
||
| 631 | FormaPagamento formaPagamento = formaPagamentoService.consultarPorId(new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_CUPOM)); |
||
| 632 | VendaFormaPagamento vendaFormaPagamento = new VendaFormaPagamento(getEntidade(), formaPagamento); |
||
| 633 | vendaFormaPagamento.setValorPagamento(getValorPagamento()); |
||
| 634 | vendaFormaPagamento.setCupom(getCupomSelecionado()); |
||
| 635 | adicionarPagamento(vendaFormaPagamento); |
||
| 636 | } |
||
| 637 | }); |
||
| 638 | } |
||
| 639 | |||
| 640 | public void adicionarPagamento(final VendaFormaPagamento vendaFormaPagamento) { |
||
| 641 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 642 | public void execute() { |
||
| 643 | verificarPagamento(vendaFormaPagamento); |
||
| 644 | getParametrosVenda().getLancamentosPagamentos().add(vendaFormaPagamento); |
||
| 645 | setFormaPagamento(null); |
||
| 646 | setValorPagamento(null); |
||
| 647 | setCupomSelecionado(null); |
||
| 648 | LancadorMensagem.lancarSucesso("PAGAMENTO ADICIONADO COM SUCESSO"); |
||
| 649 | } |
||
| 650 | |||
| 651 | private void verificarPagamento(VendaFormaPagamento vendaFormaPagamento) { |
||
| 652 | if (VerificadorUtil.estaNulo(getValorPagamento())) { |
||
| 653 | throw new NegocioException("VALOR DE PAGAMENTO INCORRETO"); |
||
| 654 | } |
||
| 655 | if (getValorPagamento().equals(new Double(0))) { |
||
| 656 | throw new NegocioException("VALOR DE PAGAMENTO INCORRETO"); |
||
| 657 | } |
||
| 658 | /* |
||
| 659 | for (VendaFormaPagamento pagamento : getParametrosVenda().getLancamentosPagamentos()) { |
||
| 660 | if (pagamento.getCodigoDaFormaPagamento().equals(vendaFormaPagamento.getCodigoDaFormaPagamento())) { |
||
| 661 | throw new NegocioException("FORMA DE PAGAMENTO JÁ EXISTE"); |
||
| 662 | } |
||
| 663 | } |
||
| 664 | */ |
||
| 665 | } |
||
| 666 | }); |
||
| 667 | } |
||
| 668 | |||
| 669 | protected void verificarPagamentoNoCartao(FormaPagamento formaPagamento) { |
||
| 670 | if (VerificadorUtil.estaNulo(getBandeiraCartao())) { |
||
| 671 | throw new RuntimeException("É OBRIGATÓRIO INFORMAR A BANDEIRA"); |
||
| 672 | } |
||
| 673 | if (VerificadorUtil.estaNulo(formaPagamento)) { |
||
| 674 | throw new RuntimeException("É OBRIGATÓRIO INFORMAR A BANDEIRA"); |
||
| 675 | } |
||
| 676 | } |
||
| 677 | |||
| 678 | public void removerPagamento(final VendaFormaPagamento pagamento) { |
||
| 679 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 680 | public void execute() { |
||
| 681 | getParametrosVenda().getLancamentosPagamentos().remove(pagamento); |
||
| 682 | LancadorMensagem.lancarSucesso("PRODUTO REMOVIDO COM SUCESSO"); |
||
| 683 | } |
||
| 684 | }); |
||
| 685 | } |
||
| 686 | |||
| 687 | public void selecionarCliente(final Cliente cliente) { |
||
| 688 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 689 | public void execute() { |
||
| 690 | cliente.setAtivo(true); |
||
| 691 | clienteService.alterar(cliente); |
||
| 692 | getParametrosVenda().setCliente(clienteService.consultarClientePorCpfCnpj(cliente.getCpfCnpj())); |
||
| 693 | setCpfCnpjCliente(null); |
||
| 694 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 695 | } |
||
| 696 | }); |
||
| 697 | } |
||
| 698 | |||
| 699 | public void retirarCliente() { |
||
| 700 | getParametrosVenda().setCliente(null); |
||
| 701 | } |
||
| 702 | |||
| 703 | public List<Vendedor> consultarVendedoresColaboradores() { |
||
| 704 | return vendedorService.consultarVendedoresColaboradores(); |
||
| 705 | } |
||
| 706 | |||
| 707 | public List<Vendedor> consultarVendedoresColaboradoresAtivos() { |
||
| 708 | return vendedorService.consultarVendedoresColaboradoresAtivos(null); |
||
| 709 | } |
||
| 710 | |||
| 711 | public List<Vendedor> consultarVendedoresExternos() { |
||
| 712 | return vendedorService.consultarVendedoresExternosAtivos(); |
||
| 713 | } |
||
| 714 | |||
| 715 | public void iniciarNovaVenda() { |
||
| 716 | Loja lojaSelecionada = getParametrosVenda().getLoja(); |
||
| 717 | setParametrosVenda(new ParametrosVendaDTO()); |
||
| 718 | getParametrosVenda().setLoja(lojaSelecionada); |
||
| 719 | getParametrosVenda().setMaquineta(lojaSelecionada.getMaquineta()); |
||
| 720 | getParametrosVenda().setUsuario(contextoSeguranca.obterUsuario()); |
||
| 721 | } |
||
| 722 | |||
| 723 | public void iniciarVenda() { |
||
| 724 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 725 | public void execute() { |
||
| 726 | LancadorMensagem.lancarSucessoRedirecionandoTela("VENDA REALIZADA COM SUCESSO!", "/sistema/pdv.xhtml?sequencialLoja=" + getParametrosVenda().getLoja().getSequencial()); |
||
| 727 | } |
||
| 728 | }); |
||
| 729 | } |
||
| 730 | |||
| 731 | public void cadastrarVendaSemCupom() { |
||
| 732 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 733 | public void execute() { |
||
| 734 | vendaService.cadastrarVendaPeloPDV(getParametrosVenda()); |
||
| 735 | iniciarNovaVenda(); |
||
| 736 | LancadorMensagem.lancarSucesso("VENDA REALIZADA COM SUCESSO!"); |
||
| 737 | } |
||
| 738 | }); |
||
| 739 | } |
||
| 740 | |||
| 741 | public void cadastrarVendaComCupom() { |
||
| 742 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 743 | public void execute() { |
||
| 744 | setVendaSelecionada(vendaService.cadastrarVendaPeloPDV(getParametrosVenda())); |
||
| 745 | preCarregamento(); |
||
| 746 | getParametrosVenda().setLoja(getVendaSelecionada().getLoja()); |
||
| 747 | getParametrosVenda().setMaquineta(getParametrosVenda().getLoja().getMaquineta()); |
||
| 748 | setEmitirCupom(true); |
||
| 749 | LancadorMensagem.lancarSucesso("VENDA REALIZADA COM SUCESSO"); |
||
| 750 | } |
||
| 751 | }); |
||
| 752 | } |
||
| 753 | |||
| 754 | public void cadastrarVendaFarma() { |
||
| 755 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 756 | public void execute() { |
||
| 757 | vendaService.cadastrarVendaPeloPDV(getParametrosVenda()); |
||
| 758 | LancadorMensagem.lancarSucessoRedirecionandoTela("VENDA REALIZADA COM SUCESSO!", "/sistema/pdv.xhtml?sequencialLoja=" + getParametrosVenda().getLoja().getSequencial()); |
||
| 759 | } |
||
| 760 | }); |
||
| 761 | } |
||
| 762 | |||
| 763 | public void cadastrarVendaRestaurante() { |
||
| 764 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 765 | public void execute() { |
||
| 766 | setVendaSelecionada(vendaService.cadastrarVendaPeloPDV(getParametrosVenda())); |
||
| 767 | preCarregamento(); |
||
| 768 | getParametrosVenda().setLoja(getVendaSelecionada().getLoja()); |
||
| 769 | getParametrosVenda().setMaquineta(getParametrosVenda().getLoja().getMaquineta()); |
||
| 770 | getVendaSelecionada().setEmitirComanda(true); |
||
| 771 | setEmitirCupom(true); |
||
| 772 | LancadorMensagem.lancarSucesso("VENDA REALIZADA COM SUCESSO"); |
||
| 773 | } |
||
| 774 | }); |
||
| 775 | } |
||
| 776 | |||
| 777 | public void alterarVenda(final Boolean verificarJustificativa) { |
||
| 778 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 779 | public void execute() { |
||
| 780 | if (verificarJustificativa) { |
||
| 781 | if (VerificadorUtil.estaNuloOuVazio(getParametrosVenda().getVenda().getJustificativaParaExcluir())) { |
||
| 782 | throw new NegocioException("JUSTIFICATIVA OBRIGATÓRIA"); |
||
| 783 | } |
||
| 784 | } |
||
| 785 | vendaService.alterarVenda(getParametrosVenda(), contextoSeguranca.obterUsuario(), verificarJustificativa); |
||
| 786 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 787 | LancadorMensagem.lancarSucesso("VENDA ALTERADA COM SUCESSO"); |
||
| 788 | } |
||
| 789 | }); |
||
| 790 | } |
||
| 791 | |||
| 792 | public void excluirVendaSelecionada() { |
||
| 793 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 794 | public void execute() { |
||
| 795 | if (VerificadorUtil.estaNuloOuVazio(getVendaSelecionada().getJustificativaParaExcluir())) { |
||
| 796 | throw new RuntimeException("É OBRIGATÓRIO JUSTIFICAR"); |
||
| 797 | } |
||
| 798 | vendaService.excluirVenda(getVendaSelecionada(), contextoSeguranca.obterUsuario()); |
||
| 799 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 800 | LancadorMensagem.lancarSucesso("VENDA EXCLUÍDA COM SUCESSO"); |
||
| 801 | } |
||
| 802 | }); |
||
| 803 | } |
||
| 804 | |||
| 805 | public void excluirVenda(final Venda venda) { |
||
| 806 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 807 | public void execute() { |
||
| 808 | vendaService.excluirVenda(venda, contextoSeguranca.obterUsuario()); |
||
| 809 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 810 | LancadorMensagem.lancarSucesso("VENDA EXCLUÍDA COM SUCESSO"); |
||
| 811 | } |
||
| 812 | }); |
||
| 813 | } |
||
| 814 | |||
| 815 | public String verificarFinanceiro(Venda venda) { |
||
| 816 | Conta contaAReceber = new Conta(); |
||
| 817 | contaAReceber.setVenda(venda); |
||
| 818 | contaAReceber.setIndicadorAtivo(true); |
||
| 819 | if (contaAReceberService.obterQuantidadeDeRegistrosPassandoEntidade(contaAReceber) == 0) { |
||
| 820 | return "NENHUMA"; |
||
| 821 | } |
||
| 822 | return parcelaService.verificarPossuiParcelaAberta(venda) ? "PENDENTE" : "QUITADO"; |
||
| 823 | } |
||
| 824 | |||
| 825 | public void prepararEnvioCupomEmail() { |
||
| 826 | setEmailParaEnvio(getVendaSelecionada().getEmailDoCliente()); |
||
| 827 | } |
||
| 828 | |||
| 829 | public void enviarCupomPorEmail() { |
||
| 830 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 831 | public void execute() { |
||
| 832 | lancarExcecaoCasoEmailNaoInformado(); |
||
| 833 | try { |
||
| 834 | JasperPrint relatorio = notaFiscalService.retornarRelatorio(getVendaSelecionada()); |
||
| 835 | byte[] arquivo = JasperExportManager.exportReportToPdf(relatorio); |
||
| 836 | new GerenciadorEmailImpl() |
||
| 837 | .comEmailsDestino(getEmailParaEnvio()) |
||
| 838 | .comAssunto("CUPOM EMITIDO POR ESPAÇO CASE") |
||
| 839 | .comConteudoHtml("OBRIGADO PELA PREFERÊNCIA!") |
||
| 840 | .adicionarAnexo("CUPOM.pdf", arquivo, "pdf") |
||
| 841 | .enviar(); |
||
| 842 | LancadorMensagem.lancarSucesso("Cupom enviado por email."); |
||
| 843 | } catch (Exception e) { |
||
| 844 | e.printStackTrace(); |
||
| 845 | } |
||
| 846 | } |
||
| 847 | |||
| 848 | private void lancarExcecaoCasoEmailNaoInformado() { |
||
| 849 | if (VerificadorUtil.estaNuloOuVazio(getEmailParaEnvio())) { |
||
| 850 | throw new NegocioException("Obrigatório informar o email de destino"); |
||
| 851 | } |
||
| 852 | } |
||
| 853 | }); |
||
| 854 | } |
||
| 855 | |||
| 856 | /*************************************************/ |
||
| 857 | |||
| 858 | public void informarEtico() { |
||
| 859 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 860 | public void execute() { |
||
| 861 | alterarCategoria(new Long(343), "ÉTICO"); |
||
| 862 | } |
||
| 863 | }); |
||
| 864 | } |
||
| 865 | |||
| 866 | public void informarGenerico() { |
||
| 867 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 868 | public void execute() { |
||
| 869 | alterarCategoria(new Long(340), "GENÉRICO"); |
||
| 870 | } |
||
| 871 | }); |
||
| 872 | } |
||
| 873 | |||
| 874 | public void informarSimilar() { |
||
| 875 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 876 | public void execute() { |
||
| 877 | alterarCategoria(new Long(338), "SIMILAR"); |
||
| 878 | } |
||
| 879 | }); |
||
| 880 | } |
||
| 881 | |||
| 882 | public void informarOutros() { |
||
| 883 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 884 | public void execute() { |
||
| 885 | alterarCategoria(new Long(339), "OUTROS"); |
||
| 886 | } |
||
| 887 | }); |
||
| 888 | } |
||
| 889 | |||
| 890 | public void alterarCategoria(final Long sequencialModelo, final String modelo) { |
||
| 891 | Modelo modeloNovo = new Modelo(); |
||
| 892 | modeloNovo.setSequencial(sequencialModelo); |
||
| 893 | modeloService.consultarPorId(modeloNovo); |
||
| 894 | getLancamento().getProduto().setModelo(modeloNovo); |
||
| 895 | produtoService.alterar(getLancamento().getProduto()); |
||
| 896 | setCodigoProduto(""); |
||
| 897 | LancadorMensagem.lancarSucesso("CATEGORIA ALTERADA PARA " + modelo); |
||
| 898 | } |
||
| 899 | |||
| 900 | public void informarLocalizacao() { |
||
| 901 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 902 | public void execute() { |
||
| 903 | produtoLojaService.alterarLocalizacao(getLocalizacaoNova(), getLancamento().getProduto(), getParametrosVenda().getLoja()); |
||
| 904 | LancadorMensagem.lancarSucesso("LOCALIZAÇÃO ALTERADA PARA " + getLocalizacaoNova()); |
||
| 905 | setCodigoProduto(""); |
||
| 906 | setLocalizacaoNova(""); |
||
| 907 | } |
||
| 908 | }); |
||
| 909 | } |
||
| 910 | |||
| 911 | public void prepararAdicionarCupom(Lancamento lancamento) { |
||
| 912 | setLancamentoSelecionado(lancamento); |
||
| 913 | setCupomSelecionado(new Cupom()); |
||
| 914 | } |
||
| 915 | |||
| 916 | public void consultarCupom(final String tipoCupom) { |
||
| 917 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 918 | public void execute() { |
||
| 919 | setCupomSelecionado(cupomService.consultarCupomPorCodigo(getCupomSelecionado().getCodigo())); |
||
| 920 | verificarCupomValido(); |
||
| 921 | verificarInclusaoDoCupom(getCupomSelecionado(), tipoCupom); |
||
| 922 | getCupomSelecionado().setLancamento(getLancamentoSelecionado()); |
||
| 923 | |||
| 924 | if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getValor())) { |
||
| 925 | setValorPagamento(getCupomSelecionado().getValor()); |
||
| 926 | } else if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getPercentual())) { |
||
| 927 | setValorPagamento(getCupomSelecionado().getLancamento().getValorVenda() * getCupomSelecionado().getPercentual() / 100); |
||
| 928 | } |
||
| 929 | } |
||
| 930 | |||
| 931 | private void verificarCupomValido() { |
||
| 932 | if (VerificadorUtil.estaNulo(getCupomSelecionado())) { |
||
| 933 | setCupomSelecionado(new Cupom()); |
||
| 934 | throw new NegocioException("CUPOM NÃO LOCALIZADO"); |
||
| 935 | } else { |
||
| 936 | if (!getCupomSelecionado().valido() || !getCupomSelecionado().getAtivo()) { |
||
| 937 | setCupomSelecionado(new Cupom()); |
||
| 938 | throw new NegocioException("CUPOM INVÁLIDO"); |
||
| 939 | } |
||
| 940 | if (getCupomSelecionado().getLimiteUtilizacao()) { |
||
| 941 | Integer vendasComCupom = lancamentoService.obterQuantidadeVendasComCupom(getCupomSelecionado()); |
||
| 942 | vendasComCupom += vendaFormaPagamentoService.obterQuantidadePagamentosComCupom(getCupomSelecionado()); |
||
| 943 | if (vendasComCupom > 0) { |
||
| 944 | setCupomSelecionado(new Cupom()); |
||
| 945 | throw new NegocioException("CUPOM JÁ UTILIZADO ANTERIORMENTE"); |
||
| 946 | } |
||
| 947 | } |
||
| 948 | } |
||
| 949 | } |
||
| 950 | |||
| 951 | private void verificarInclusaoDoCupom(Cupom cupom, String tipoCupom) { |
||
| 952 | if (TipoCupom.PROMOCIONAL.getValor().equals(tipoCupom)) { |
||
| 953 | if (!cupom.getTipoCupom().equals(TipoCupom.PROMOCIONAL.getValor())) { |
||
| 954 | setCupomSelecionado(new Cupom()); |
||
| 955 | throw new NegocioException("PERMITIDO APENAS PARA CUPONS PROMOCIONAIS"); |
||
| 956 | } |
||
| 957 | if (getLancamentoSelecionado().getProduto().getProdutoEmPromocao()) { |
||
| 958 | setCupomSelecionado(new Cupom()); |
||
| 959 | throw new NegocioException("AÇÃO NÃO PERMITIDA: PRODUTO JÁ EM PROMOÇÃO"); |
||
| 960 | } |
||
| 961 | } else if (TipoCupom.REEMBOLSO.getValor().equals(tipoCupom)) { |
||
| 962 | if (!cupom.getTipoCupom().equals(TipoCupom.REEMBOLSO.getValor())) { |
||
| 963 | setCupomSelecionado(new Cupom()); |
||
| 964 | throw new NegocioException("PERMITIDO APENAS PARA CUPONS DE REEMBOLSO"); |
||
| 965 | } |
||
| 966 | } |
||
| 967 | } |
||
| 968 | }); |
||
| 969 | } |
||
| 970 | |||
| 971 | public void adicionarCupom() { |
||
| 972 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 973 | public void execute() { |
||
| 974 | verificarSeValorMaiorDesconto(getValorPagamento()); |
||
| 975 | verificarSeCupomJaFoiAdicionado(getCupomSelecionado(), getParametrosVenda().getLancamentos()); |
||
| 976 | for (Lancamento lancamento : getParametrosVenda().getLancamentos()) { |
||
| 977 | if (lancamento.equals(getCupomSelecionado().getLancamento())) { |
||
| 978 | lancamento.setCupom(getCupomSelecionado()); |
||
| 979 | lancamento.setValorVarejo(lancamento.getValorVarejo() - getValorPagamento()); |
||
| 980 | lancamento.setValorVenda(lancamento.getValorVenda() - getValorPagamento()); |
||
| 981 | break; |
||
| 982 | } |
||
| 983 | } |
||
| 984 | LancadorMensagem.lancarSucesso("CUPOM ADICIONADO COM SUCESSO"); |
||
| 985 | } |
||
| 986 | |||
| 987 | private void verificarSeCupomJaFoiAdicionado(Cupom cupomSelecionado, List<Lancamento> lancamentos) { |
||
| 988 | if (cupomSelecionado.getLimiteUtilizacao()) { |
||
| 989 | for (Lancamento lancamento : getParametrosVenda().getLancamentos()) { |
||
| 990 | if (VerificadorUtil.naoEstaNulo(lancamento.getCupom())) { |
||
| 991 | if (lancamento.getCupom().equals(cupomSelecionado)) { |
||
| 992 | throw new RuntimeException("CUPOM JÁ FOI UTILIZADO"); |
||
| 993 | } |
||
| 994 | } |
||
| 995 | } |
||
| 996 | } |
||
| 997 | } |
||
| 998 | |||
| 999 | private void verificarSeValorMaiorDesconto(Double valorPagamento) { |
||
| 1000 | if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getValor())) { |
||
| 1001 | if (valorPagamento > getCupomSelecionado().getValor()) { |
||
| 1002 | throw new RuntimeException("VALOR DO DESCONTO ACIMA DO PERMITIDO"); |
||
| 1003 | } |
||
| 1004 | } else if (VerificadorUtil.naoEstaNulo(getCupomSelecionado().getPercentual())) { |
||
| 1005 | if (valorPagamento > getCupomSelecionado().getLancamento().getValorVenda() * getCupomSelecionado().getPercentual() / 100) { |
||
| 1006 | throw new RuntimeException("VALOR DO DESCONTO ACIMA DO PERMITIDO"); |
||
| 1007 | } |
||
| 1008 | } |
||
| 1009 | } |
||
| 1010 | }); |
||
| 1011 | } |
||
| 1012 | |||
| 1013 | public void removerCupom(Lancamento lancamento) { |
||
| 1014 | for (Lancamento lancamentoVendas : getParametrosVenda().getLancamentos()) { |
||
| 1015 | if (lancamentoVendas.equals(lancamento)) { |
||
| 1016 | lancamentoVendas.setCupom(null); |
||
| 1017 | lancamentoVendas.setValorVarejo(lancamento.getValorVarejo() + getValorPagamento()); |
||
| 1018 | lancamentoVendas.setValorVenda(lancamento.getValorVenda() + getValorPagamento()); |
||
| 1019 | break; |
||
| 1020 | } |
||
| 1021 | } |
||
| 1022 | LancadorMensagem.lancarSucesso("CUPOM REMOVIDO COM SUCESSO"); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | public void vincularPedido() { |
||
| 1026 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 1027 | public void execute() { |
||
| 1028 | Pedido pedido = new Pedido(); |
||
| 1029 | pedido.setSequencial(new Long(getCodigoPedido())); |
||
| 1030 | getParametrosVenda().setPedidoVinculado(pedidoService.consultarPedidoCompleto(pedido)); |
||
| 1031 | if (VerificadorUtil.naoEstaNulo(getParametrosVenda().getPedidoVinculado())) { |
||
| 1032 | if (getParametrosVenda().getPedidoVinculado().getTipoSituacao().equals(TipoSituacaoPedido.FINALIZADO.getValor()) || |
||
| 1033 | getParametrosVenda().getPedidoVinculado().getTipoSituacao().equals(TipoSituacaoPedido.FINALIZADO_COM_VENDAS.getValor())) { |
||
| 1034 | throw new NegocioException("VÍNCULO NÃO REALIZADO: PEDIDO JÁ FINALIZADO"); |
||
| 1035 | } |
||
| 1036 | getParametrosVenda().setObservacao("PEDIDO VINCULADO: " + getParametrosVenda().getPedidoVinculado().getSequencial() + ". " + getParametrosVenda().getObservacao()); |
||
| 1037 | Vendedor vendedorPedido = vendedorService.consultarVendedorPorPessoa(getParametrosVenda().getPedidoVinculado().getUsuarioPedido().getPessoa()); |
||
| 1038 | if (VerificadorUtil.naoEstaNulo(vendedorPedido)) { |
||
| 1039 | getParametrosVenda().setVendedor(vendedorPedido); |
||
| 1040 | } |
||
| 1041 | |||
| 1042 | for (PedidoProduto pedidoProduto : getParametrosVenda().getPedidoVinculado().getProdutos()) { |
||
| 1043 | Integer quantidadeProduto = 1; |
||
| 1044 | while (quantidadeProduto <= pedidoProduto.getQuantidade()) { |
||
| 1045 | Lancamento lancamento = new Lancamento(); |
||
| 1046 | lancamento.preencher(pedidoProduto.getProduto()); |
||
| 1047 | lancamento.setValorVenda(pedidoProduto.getValor()); |
||
| 1048 | lancamento.setObservacao(pedidoProduto.getObservacao()); |
||
| 1049 | getParametrosVenda().getLancamentos().add(lancamento); |
||
| 1050 | quantidadeProduto++; |
||
| 1051 | } |
||
| 1052 | } |
||
| 1053 | |||
| 1054 | if (VerificadorUtil.naoEstaNulo(getParametrosVenda().getPedidoVinculado().getCliente())) { |
||
| 1055 | getParametrosVenda().setCliente(getParametrosVenda().getPedidoVinculado().getCliente()); |
||
| 1056 | } |
||
| 1057 | setCodigoPedido(""); |
||
| 1058 | LancadorMensagem.lancarSucesso("PEDIDO " + getParametrosVenda().getPedidoVinculado().getSequencial() + " VINCULADO"); |
||
| 1059 | } else { |
||
| 1060 | LancadorMensagem.lancarErro("PEDIDO NÃO ENCONTRADO"); |
||
| 1061 | } |
||
| 1062 | } |
||
| 1063 | }); |
||
| 1064 | } |
||
| 1065 | |||
| 1066 | } |