Rev 277 | Rev 320 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 277 | Rev 305 | ||
|---|---|---|---|
| Line 193... | Line 193... | ||
| 193 | }
|
193 | }
|
| 194 | }
|
194 | }
|
| 195 | 195 | ||
| 196 | public void reporEstoqueAoExcluirVenda(Venda venda) { |
196 | public void reporEstoqueAoExcluirVenda(Venda venda) { |
| 197 | for (Lancamento lancamento : venda.getLancamentos()) { |
197 | for (Lancamento lancamento : venda.getLancamentos()) { |
| 198 | alterarEstoqueProduto(1, venda.getLoja(), lancamento.getProduto().getCodigo()); |
- | |
| - | 198 | alterarEstoqueProduto(1, venda.getLoja(), lancamento.getProduto().getCodigo(), lancamento.getTipoPersonalizacao()); |
|
| 199 | }
|
199 | }
|
| 200 | }
|
200 | }
|
| 201 | 201 | ||
| 202 | private void excluirPagamentos(Venda venda) { |
202 | private void excluirPagamentos(Venda venda) { |
| 203 | for (VendaFormaPagamento vendaFormaPagamento : venda.getListaVendaFormaPagamentos()) { |
203 | for (VendaFormaPagamento vendaFormaPagamento : venda.getListaVendaFormaPagamentos()) { |
| Line 589... | Line 589... | ||
| 589 | parametrosVenda.getVenda().setObservacao(parametrosVenda.getObservacao()); |
589 | parametrosVenda.getVenda().setObservacao(parametrosVenda.getObservacao()); |
| 590 | parametrosVenda.getVenda().setNotaFiscal(parametrosVenda.getNotaFiscal()); |
590 | parametrosVenda.getVenda().setNotaFiscal(parametrosVenda.getNotaFiscal()); |
| 591 | parametrosVenda.getVenda().setMaquineta(parametrosVenda.getMaquineta()); |
591 | parametrosVenda.getVenda().setMaquineta(parametrosVenda.getMaquineta()); |
| 592 | if (!parametrosVenda.getVenda().getLoja().equals(parametrosVenda.getLoja())) { |
592 | if (!parametrosVenda.getVenda().getLoja().equals(parametrosVenda.getLoja())) { |
| 593 | for (Lancamento lancamento : parametrosVenda.getVenda().getLancamentos()) { |
593 | for (Lancamento lancamento : parametrosVenda.getVenda().getLancamentos()) { |
| 594 | alterarEstoqueProduto(1, parametrosVenda.getVenda().getLoja(), lancamento.getProduto().getCodigo()); |
- | |
| 595 | alterarEstoqueProduto(-1, parametrosVenda.getLoja(), lancamento.getProduto().getCodigo()); |
- | |
| - | 594 | alterarEstoqueProduto(1, parametrosVenda.getVenda().getLoja(), lancamento.getProduto().getCodigo(), lancamento.getTipoPersonalizacao()); |
|
| - | 595 | alterarEstoqueProduto(-1, parametrosVenda.getLoja(), lancamento.getProduto().getCodigo(), lancamento.getTipoPersonalizacao()); |
|
| 596 | }
|
596 | }
|
| 597 | parametrosVenda.getVenda().setLoja(parametrosVenda.getLoja()); |
597 | parametrosVenda.getVenda().setLoja(parametrosVenda.getLoja()); |
| 598 | parametrosVenda.getVenda().setMaquineta(parametrosVenda.getLoja().getMaquineta()); |
598 | parametrosVenda.getVenda().setMaquineta(parametrosVenda.getLoja().getMaquineta()); |
| 599 | }
|
599 | }
|
| 600 | parametrosVenda.getVenda().setTipoSituacao(parametrosVenda.getTipoSituacao()); |
600 | parametrosVenda.getVenda().setTipoSituacao(parametrosVenda.getTipoSituacao()); |
| Line 697... | Line 697... | ||
| 697 | if (VerificadorUtil.estaNulo(parametrosVenda.getMaquineta())) { |
697 | if (VerificadorUtil.estaNulo(parametrosVenda.getMaquineta())) { |
| 698 | throw new NegocioException("Informe a maquineta"); |
698 | throw new NegocioException("Informe a maquineta"); |
| 699 | }
|
699 | }
|
| 700 | }
|
700 | }
|
| 701 | }
|
701 | }
|
| - | 702 | if (possuiLancamentoPersonalizacao(parametrosVenda.getLancamentos())) { |
|
| - | 703 | if (VerificadorUtil.estaNulo(parametrosVenda.getCliente()) && VerificadorUtil.estaNuloOuVazio(parametrosVenda.getObservacao())) { |
|
| - | 704 | throw new NegocioException("Informe o cliente ou o contato do cliente nas observações"); |
|
| - | 705 | }
|
|
| - | 706 | }
|
|
| - | 707 | if (VerificadorUtil.estaNulo(parametrosVenda.getLoja())) { |
|
| - | 708 | throw new NegocioException("Informe a loja"); |
|
| - | 709 | }
|
|
| - | 710 | }
|
|
| - | 711 | ||
| - | 712 | private Boolean possuiLancamentoPersonalizacao(List<Lancamento> lancamentos) { |
|
| - | 713 | for (Lancamento lancamento : lancamentos) { |
|
| - | 714 | if (VerificadorUtil.naoEstaNuloOuVazio(lancamento.getTipoPersonalizacao())) { |
|
| - | 715 | return true; |
|
| - | 716 | }
|
|
| - | 717 | }
|
|
| - | 718 | return false; |
|
| 702 | }
|
719 | }
|
| 703 | 720 | ||
| 704 | private void lancarExcecaoSeValoresNaoSaoIguais(ParametrosVendaDTO parametrosVenda) { |
721 | private void lancarExcecaoSeValoresNaoSaoIguais(ParametrosVendaDTO parametrosVenda) { |
| 705 | final double TOLERANCE = 0.01; |
722 | final double TOLERANCE = 0.01; |
| 706 | if(Math.abs(parametrosVenda.valorTotalLancamentos() /*+ parametrosVenda.getValorFrete() */- parametrosVenda.valorTotalPago()) > TOLERANCE) { |
723 | if(Math.abs(parametrosVenda.valorTotalLancamentos() /*+ parametrosVenda.getValorFrete() */- parametrosVenda.valorTotalPago()) > TOLERANCE) { |
| Line 721... | Line 738... | ||
| 721 | 738 | ||
| 722 | private void excluirLancamentosRetiradosDaLista(ParametrosVendaDTO parametrosVenda, List<Lancamento> lancamentosAntigos) { |
739 | private void excluirLancamentosRetiradosDaLista(ParametrosVendaDTO parametrosVenda, List<Lancamento> lancamentosAntigos) { |
| 723 | for (Lancamento lancamentoAntigo : lancamentosAntigos) { |
740 | for (Lancamento lancamentoAntigo : lancamentosAntigos) { |
| 724 | if (!parametrosVenda.getLancamentos().contains(lancamentoAntigo)) { |
741 | if (!parametrosVenda.getLancamentos().contains(lancamentoAntigo)) { |
| 725 | lancamentoService.excluir(lancamentoAntigo); |
742 | lancamentoService.excluir(lancamentoAntigo); |
| 726 | alterarEstoqueProduto(1, parametrosVenda.getLoja(), lancamentoAntigo.getProduto().getCodigo()); |
- | |
| - | 743 | alterarEstoqueProduto(1, parametrosVenda.getLoja(), lancamentoAntigo.getProduto().getCodigo(), lancamentoAntigo.getTipoPersonalizacao()); |
|
| 727 | }
|
744 | }
|
| 728 | }
|
745 | }
|
| 729 | }
|
746 | }
|
| 730 | 747 | ||
| 731 | private void cadastrarNovosLancamentos(ParametrosVendaDTO parametrosVenda) { |
748 | private void cadastrarNovosLancamentos(ParametrosVendaDTO parametrosVenda) { |
| Line 745... | Line 762... | ||
| 745 | private void cadastrarLancamento(Loja loja, Venda venda, Lancamento lancamento) { |
762 | private void cadastrarLancamento(Loja loja, Venda venda, Lancamento lancamento) { |
| 746 | lancamento.setVenda(venda); |
763 | lancamento.setVenda(venda); |
| 747 | igualarValorVarejoComCompraSeProdutoForPadrao(lancamento); |
764 | igualarValorVarejoComCompraSeProdutoForPadrao(lancamento); |
| 748 | acrescentarValorIPISeHouver(lancamento); |
765 | acrescentarValorIPISeHouver(lancamento); |
| 749 | lancamentoService.cadastrar(lancamento); |
766 | lancamentoService.cadastrar(lancamento); |
| 750 | alterarEstoqueProduto(-1, loja, lancamento.getProduto().getCodigo()); |
- | |
| - | 767 | alterarEstoqueProduto(-1, loja, lancamento.getProduto().getCodigo(), lancamento.getTipoPersonalizacao()); |
|
| 751 | utilizarCupom(lancamento.getCupom()); |
768 | utilizarCupom(lancamento.getCupom()); |
| 752 | 769 | ||
| 753 | }
|
770 | }
|
| 754 | 771 | ||
| 755 | private void igualarValorVarejoComCompraSeProdutoForPadrao(Lancamento lancamento) { |
772 | private void igualarValorVarejoComCompraSeProdutoForPadrao(Lancamento lancamento) { |
| Line 844... | Line 861... | ||
| 844 | VendaFormaPagamento pagamentoDaVenda = new VendaFormaPagamento(); |
861 | VendaFormaPagamento pagamentoDaVenda = new VendaFormaPagamento(); |
| 845 | pagamentoDaVenda.setVenda(parametrosVenda.getVenda()); |
862 | pagamentoDaVenda.setVenda(parametrosVenda.getVenda()); |
| 846 | return vendaFormaPagamentoService.consultarPassandoEntidade(pagamentoDaVenda, 0, vendaFormaPagamentoService.obterQuantidadeDeRegistrosPassandoEntidade(pagamentoDaVenda)); |
863 | return vendaFormaPagamentoService.consultarPassandoEntidade(pagamentoDaVenda, 0, vendaFormaPagamentoService.obterQuantidadeDeRegistrosPassandoEntidade(pagamentoDaVenda)); |
| 847 | }
|
864 | }
|
| 848 | 865 | ||
| 849 | private void alterarEstoqueProduto(Integer quantidadeAlterar, Loja loja, String codigoProduto) { |
- | |
| - | 866 | private void alterarEstoqueProduto(Integer quantidadeAlterar, Loja loja, String codigoProduto, String tipoPersonalizacao) { |
|
| 850 | if (VerificadorUtil.naoEstaNulo(codigoProduto)) { |
867 | if (VerificadorUtil.naoEstaNulo(codigoProduto)) { |
| 851 | Produto produto = produtoService.consultarProdutoPorCodigo(codigoProduto); |
868 | Produto produto = produtoService.consultarProdutoPorCodigo(codigoProduto); |
| 852 | produtoLojaService.alterarEstoqueAcrescentandoQuantidadeInformada(quantidadeAlterar, produto, loja); |
- | |
| - | 869 | Loja lojaAlterarEstoque = retornarLojaParaAlteracaoEstoque(loja, tipoPersonalizacao); |
|
| - | 870 | produtoLojaService.alterarEstoqueAcrescentandoQuantidadeInformada(quantidadeAlterar, produto, lojaAlterarEstoque); |
|
| 853 | }
|
871 | }
|
| 854 | }
|
872 | }
|
| 855 | 873 | ||
| - | 874 | private Loja retornarLojaParaAlteracaoEstoque(Loja loja, String tipoPersonalizacao) { |
|
| - | 875 | if (VerificadorUtil.naoEstaNulo(tipoPersonalizacao)) { |
|
| - | 876 | return new Loja(ConstantesSEC.Personalizacao.SEQUENCIAL_LOJA_PERSONALIZACAO); |
|
| - | 877 | }
|
|
| - | 878 | return loja; |
|
| - | 879 | }
|
|
| - | 880 | ||
| 856 | private void utilizarCupom(Cupom cupom) { |
881 | private void utilizarCupom(Cupom cupom) { |
| 857 | if (VerificadorUtil.naoEstaNulo(cupom)) { |
882 | if (VerificadorUtil.naoEstaNulo(cupom)) { |
| 858 | Cupom cupomUtilizado = cupomService.consultarPorId(cupom); |
883 | Cupom cupomUtilizado = cupomService.consultarPorId(cupom); |
| 859 | cupomUtilizado.setDataHoraUtilizado(DataUtils.getDataAtual()); |
884 | cupomUtilizado.setDataHoraUtilizado(DataUtils.getDataAtual()); |
| 860 | if (VerificadorUtil.estaNulo(cupomUtilizado.getQuantidadeUtilizada())) { |
885 | if (VerificadorUtil.estaNulo(cupomUtilizado.getQuantidadeUtilizada())) { |