Rev 422 | Rev 600 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 422 | Rev 577 | ||
|---|---|---|---|
| Line 47... | Line 47... | ||
| 47 | import br.com.ec.domain.model.NotaFiscal; |
47 | import br.com.ec.domain.model.NotaFiscal; |
| 48 | import br.com.ec.domain.model.Pedido; |
48 | import br.com.ec.domain.model.Pedido; |
| 49 | import br.com.ec.domain.model.PedidoHistorico; |
49 | import br.com.ec.domain.model.PedidoHistorico; |
| 50 | import br.com.ec.domain.model.Produto; |
50 | import br.com.ec.domain.model.Produto; |
| 51 | import br.com.ec.domain.model.Usuario; |
51 | import br.com.ec.domain.model.Usuario; |
| - | 52 | import br.com.ec.domain.model.UsuarioPerfil; |
|
| 52 | import br.com.ec.domain.model.Venda; |
53 | import br.com.ec.domain.model.Venda; |
| 53 | import br.com.ec.domain.model.VendaFormaPagamento; |
54 | import br.com.ec.domain.model.VendaFormaPagamento; |
| 54 | import br.com.ec.domain.model.Vendedor; |
55 | import br.com.ec.domain.model.Vendedor; |
| 55 | import br.com.ec.domain.model.Vigencia; |
56 | import br.com.ec.domain.model.Vigencia; |
| 56 | import br.com.ec.domain.model.tipos.TipoEmitirNotaFiscal; |
57 | import br.com.ec.domain.model.tipos.TipoEmitirNotaFiscal; |
| Line 73... | Line 74... | ||
| 73 | import br.com.ec.domain.service.modelo.ModeloService; |
74 | import br.com.ec.domain.service.modelo.ModeloService; |
| 74 | import br.com.ec.domain.service.parcela.ParcelaService; |
75 | import br.com.ec.domain.service.parcela.ParcelaService; |
| 75 | import br.com.ec.domain.service.pedido.PedidoService; |
76 | import br.com.ec.domain.service.pedido.PedidoService; |
| 76 | import br.com.ec.domain.service.produto.ProdutoService; |
77 | import br.com.ec.domain.service.produto.ProdutoService; |
| 77 | import br.com.ec.domain.service.produtodaloja.ProdutoLojaService; |
78 | import br.com.ec.domain.service.produtodaloja.ProdutoLojaService; |
| - | 79 | import br.com.ec.domain.service.usuario.UsuarioService; |
|
| 78 | import br.com.ec.domain.service.venda.VendaService; |
80 | import br.com.ec.domain.service.venda.VendaService; |
| 79 | import br.com.ec.domain.service.vendaformapagamento.VendaFormaPagamentoService; |
81 | import br.com.ec.domain.service.vendaformapagamento.VendaFormaPagamentoService; |
| 80 | import br.com.ec.domain.service.vendavivo.VendaVivoService; |
82 | import br.com.ec.domain.service.vendavivo.VendaVivoService; |
| 81 | import br.com.ec.domain.service.vendedor.VendedorService; |
83 | import br.com.ec.domain.service.vendedor.VendedorService; |
| 82 | import br.com.ec.domain.service.vigencia.VigenciaService; |
84 | import br.com.ec.domain.service.vigencia.VigenciaService; |
| Line 107... | Line 109... | ||
| 107 | private ModeloService modeloService; |
109 | private ModeloService modeloService; |
| 108 | private CupomService cupomService; |
110 | private CupomService cupomService; |
| 109 | private BancoHorasService bancoHorasService; |
111 | private BancoHorasService bancoHorasService; |
| 110 | private EstoqueAuditoriaService estoqueAuditoriaService; |
112 | private EstoqueAuditoriaService estoqueAuditoriaService; |
| 111 | private VigenciaService vigenciaService; |
113 | private VigenciaService vigenciaService; |
| - | 114 | private UsuarioService usuarioService; |
|
| 112 | 115 | ||
| 113 | private Ordenador ordenador; |
116 | private Ordenador ordenador; |
| 114 | private NotaFiscalRepository notaFiscalRepository; |
117 | private NotaFiscalRepository notaFiscalRepository; |
| 115 | 118 | ||
| 116 | @Autowired |
119 | @Autowired |
| Line 118... | Line 121... | ||
| 118 | VendaFormaPagamentoService vendaFormaPagamentoService, ProdutoService produtoService, ProdutoLojaService produtoLojaService, |
121 | VendaFormaPagamentoService vendaFormaPagamentoService, ProdutoService produtoService, ProdutoLojaService produtoLojaService, |
| 119 | VendedorService vendedorService, FuncionarioService funcionarioService, LojaService lojaService, PedidoService pedidoService, |
122 | VendedorService vendedorService, FuncionarioService funcionarioService, LojaService lojaService, PedidoService pedidoService, |
| 120 | ParcelaService parcelaService, AvaliacaoService avaliacaoService, AvaliacaoFuncionarioService avaliacaoFuncionarioService, |
123 | ParcelaService parcelaService, AvaliacaoService avaliacaoService, AvaliacaoFuncionarioService avaliacaoFuncionarioService, |
| 121 | AvaliacaoLojaService avaliacaoLojaService, VendaVivoService vendaVivoService, ModeloService modeloService, CupomService cupomService, |
124 | AvaliacaoLojaService avaliacaoLojaService, VendaVivoService vendaVivoService, ModeloService modeloService, CupomService cupomService, |
| 122 | BancoHorasService bancoHorasService, EstoqueAuditoriaService estoqueAuditoriaService, VigenciaService vigenciaService, |
125 | BancoHorasService bancoHorasService, EstoqueAuditoriaService estoqueAuditoriaService, VigenciaService vigenciaService, |
| 123 | NotaFiscalRepository notaFiscalRepository) { |
- | |
| - | 126 | UsuarioService usuarioService, NotaFiscalRepository notaFiscalRepository) { |
|
| 124 | super(validador); |
127 | super(validador); |
| 125 | this.vendaRepository = vendaRepository; |
128 | this.vendaRepository = vendaRepository; |
| 126 | this.funcionarioService = funcionarioService; |
129 | this.funcionarioService = funcionarioService; |
| 127 | this.lancamentoService = lancamentoService; |
130 | this.lancamentoService = lancamentoService; |
| 128 | this.vendaFormaPagamentoService = vendaFormaPagamentoService; |
131 | this.vendaFormaPagamentoService = vendaFormaPagamentoService; |
| Line 139... | Line 142... | ||
| 139 | this.modeloService = modeloService; |
142 | this.modeloService = modeloService; |
| 140 | this.cupomService = cupomService; |
143 | this.cupomService = cupomService; |
| 141 | this.bancoHorasService = bancoHorasService; |
144 | this.bancoHorasService = bancoHorasService; |
| 142 | this.estoqueAuditoriaService = estoqueAuditoriaService; |
145 | this.estoqueAuditoriaService = estoqueAuditoriaService; |
| 143 | this.vigenciaService = vigenciaService; |
146 | this.vigenciaService = vigenciaService; |
| - | 147 | this.usuarioService = usuarioService; |
|
| 144 | this.notaFiscalRepository = notaFiscalRepository; |
148 | this.notaFiscalRepository = notaFiscalRepository; |
| 145 | this.ordenador = new OrdenadorImpl(); |
149 | this.ordenador = new OrdenadorImpl(); |
| 146 | }
|
150 | }
|
| 147 | 151 | ||
| 148 | @Override |
152 | @Override |
| Line 366... | Line 370... | ||
| 366 | pedidoService.alterar(pedidoVinculado); |
370 | pedidoService.alterar(pedidoVinculado); |
| 367 | }
|
371 | }
|
| 368 | }
|
372 | }
|
| 369 | 373 | ||
| 370 | private void enviarAlertasPorEmail(ParametrosVendaDTO parametrosVenda, Venda venda) { |
374 | private void enviarAlertasPorEmail(ParametrosVendaDTO parametrosVenda, Venda venda) { |
| - | 375 | Boolean enviarAlerta = false; |
|
| - | 376 | String emailsDestino = ""; |
|
| - | 377 | String assuntoAlerta = ""; |
|
| 371 | if (descontosEmProdutosSuperiores(parametrosVenda)) { |
378 | if (descontosEmProdutosSuperiores(parametrosVenda)) { |
| 372 | new GerenciadorEmailImpl() |
- | |
| 373 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO) |
- | |
| 374 | .comAssunto("ESPAÇO CASE - VENDA COM DESCONTO SUPERIOR : " + DataUtils.converterDataParaString(DataUtils.getDataAtual())) |
- | |
| 375 | .comConteudo(montarDadosDaVenda(venda, venda.getUsuario(), parametrosVenda.getLancamentos(), parametrosVenda.getLancamentosPagamentos())) |
- | |
| 376 | .enviar(); |
- | |
| - | 379 | enviarAlerta = true; |
|
| - | 380 | emailsDestino = ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO; |
|
| - | 381 | assuntoAlerta = "ESPAÇO CASE - VENDA COM DESCONTO SUPERIOR : " + DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
|
| 377 | }
|
382 | }
|
| 378 | if (produtosComDescontoECupom(parametrosVenda)) { |
383 | if (produtosComDescontoECupom(parametrosVenda)) { |
| - | 384 | enviarAlerta = true; |
|
| - | 385 | emailsDestino = ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO; |
|
| - | 386 | assuntoAlerta = "ESPAÇO CASE - VENDA COM PRODUTO COM DESCONTO E CUPOM PROMOCIONAL : " + DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
|
| - | 387 | }
|
|
| - | 388 | if (possuiMaisDeDuasFormasDePagamento(parametrosVenda)) { |
|
| - | 389 | enviarAlerta = true; |
|
| - | 390 | emailsDestino = ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO; |
|
| - | 391 | assuntoAlerta = "ESPAÇO CASE - VENDA SUSPEITA COM MAIS DE 2 FORMAS DE PAGAMENTO : " + DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
|
| - | 392 | }
|
|
| - | 393 | if (enviarAlerta) { |
|
| 379 | new GerenciadorEmailImpl() |
394 | new GerenciadorEmailImpl() |
| 380 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_SUPERVISAO) |
- | |
| 381 | .comAssunto("ESPAÇO CASE - VENDA COM PRODUTO COM DESCONTO E CUPOM PROMOCIONAL : " + DataUtils.converterDataParaString(DataUtils.getDataAtual())) |
- | |
| - | 395 | .comEmailsDestino(emailsDestino) |
|
| - | 396 | .comAssunto(assuntoAlerta) |
|
| 382 | .comConteudo(montarDadosDaVenda(venda, venda.getUsuario(), parametrosVenda.getLancamentos(), parametrosVenda.getLancamentosPagamentos())) |
397 | .comConteudo(montarDadosDaVenda(venda, venda.getUsuario(), parametrosVenda.getLancamentos(), parametrosVenda.getLancamentosPagamentos())) |
| 383 | .enviar(); |
398 | .enviar(); |
| 384 | }
|
399 | }
|
| 385 | }
|
400 | }
|
| 386 | 401 | ||
| - | 402 | private Boolean possuiMaisDeDuasFormasDePagamento(ParametrosVendaDTO parametrosVenda) { |
|
| - | 403 | return parametrosVenda.getLancamentosPagamentos().size() > 2; |
|
| - | 404 | }
|
|
| - | 405 | ||
| 387 | /*
|
406 | /*
|
| 388 | private void enviarAlertasPorEmail(ParametrosVendaDTO parametrosVenda, Venda venda) {
|
407 | private void enviarAlertasPorEmail(ParametrosVendaDTO parametrosVenda, Venda venda) {
|
| 389 | if (pagamentoDividido(parametrosVenda)) {
|
408 | if (pagamentoDividido(parametrosVenda)) {
|
| 390 | if (descontoEmProdutos(parametrosVenda)) {
|
409 | if (descontoEmProdutos(parametrosVenda)) {
|
| 391 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual());
|
410 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual());
|
| Line 460... | Line 479... | ||
| 460 | }
|
479 | }
|
| 461 | 480 | ||
| 462 | @Override |
481 | @Override |
| 463 | public void alterarVenda(ParametrosVendaDTO parametrosVenda, Usuario usuario, Boolean verificarJustificativa) { |
482 | public void alterarVenda(ParametrosVendaDTO parametrosVenda, Usuario usuario, Boolean verificarJustificativa) { |
| 464 | verificarLancamentos(parametrosVenda.getLancamentos()); |
483 | verificarLancamentos(parametrosVenda.getLancamentos()); |
| - | 484 | lancarExcecaoSeUsuarioNaoTiverPermissao(parametrosVenda, usuario, verificarJustificativa); |
|
| 465 | lancarExcecaoCasoNaoSejaInformadoCamposObrigatorios(parametrosVenda); |
485 | lancarExcecaoCasoNaoSejaInformadoCamposObrigatorios(parametrosVenda); |
| 466 | lancarExcecaoSeValoresNaoSaoIguais(parametrosVenda); |
486 | lancarExcecaoSeValoresNaoSaoIguais(parametrosVenda); |
| 467 | if (verificarJustificativa) {enviarEmailAlteracoes(parametrosVenda, usuario);} |
487 | if (verificarJustificativa) {enviarEmailAlteracoes(parametrosVenda, usuario);} |
| 468 | atualizarDadosDaVenda(parametrosVenda); |
488 | atualizarDadosDaVenda(parametrosVenda); |
| 469 | alterarLancamentos(parametrosVenda); |
489 | alterarLancamentos(parametrosVenda); |
| 470 | alterarPagamentos(parametrosVenda); |
490 | alterarPagamentos(parametrosVenda); |
| 471 | alterar(parametrosVenda.getVenda()); |
491 | alterar(parametrosVenda.getVenda()); |
| 472 | alterarSituacaoPedido(parametrosVenda.getPedidoVinculado(), parametrosVenda.getVenda()); |
492 | alterarSituacaoPedido(parametrosVenda.getPedidoVinculado(), parametrosVenda.getVenda()); |
| - | 493 | }
|
|
| - | 494 | ||
| - | 495 | private void lancarExcecaoSeUsuarioNaoTiverPermissao(ParametrosVendaDTO parametrosVenda, Usuario usuario, Boolean verificarJustificativa) { |
|
| - | 496 | if (verificarJustificativa) { |
|
| - | 497 | for (UsuarioPerfil usuarioPerfil : usuario.getPerfis()) { |
|
| - | 498 | if (usuarioPerfil.getPerfil().getCodigo().equals(ConstantesSEC.PERFIL_LOJA_9)) { |
|
| - | 499 | throw new NegocioException("USUÁRIO SEM PERMISSÃO PARA ESTA OPERAÇÃO"); |
|
| - | 500 | }
|
|
| - | 501 | }
|
|
| - | 502 | ||
| - | 503 | if (!parametrosVenda.getVendedor().equals(parametrosVenda.getVenda().getVendedor())) { |
|
| - | 504 | Usuario usuarioDetalhe = usuarioService.detalhar(usuario); |
|
| - | 505 | if (VerificadorUtil.naoEstaNulo(usuarioDetalhe.getPessoa())) { |
|
| - | 506 | if (!parametrosVenda.getVenda().getVendedor().getPessoa().equals(usuarioDetalhe.getPessoa())) { |
|
| - | 507 | throw new NegocioException("OPERAÇÃO SÓ PODE SER REALIZADA PELO VENDEDOR ATUAL"); |
|
| - | 508 | }
|
|
| - | 509 | } else { |
|
| - | 510 | throw new NegocioException("USUÁRIO SEM PERMISSÃO PARA ESTA OPERAÇÃO"); |
|
| - | 511 | }
|
|
| - | 512 | }
|
|
| - | 513 | }
|
|
| 473 | }
|
514 | }
|
| 474 | 515 | ||
| 475 | private void enviarEmailAlteracoes(ParametrosVendaDTO parametrosVenda, Usuario usuario) { |
516 | private void enviarEmailAlteracoes(ParametrosVendaDTO parametrosVenda, Usuario usuario) { |
| 476 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
517 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
| 477 | StringBuilder conteudo = new StringBuilder(); |
518 | StringBuilder conteudo = new StringBuilder(); |