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