Rev 195 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 597 | blopes | 4 | import java.util.List; |
| 106 | espaco | 5 | |
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 9 | import org.springframework.context.annotation.Scope; |
||
| 10 | |||
| 195 | espaco | 11 | import br.com.ec.core.generic.GenericService; |
| 12 | import br.com.ec.core.util.DataUtils; |
||
| 106 | espaco | 13 | import br.com.ec.domain.dto.ParametrosFecharCaixaDTO; |
| 14 | import br.com.ec.domain.dto.ParametrosReceberCaixaDTO; |
||
| 597 | blopes | 15 | import br.com.ec.domain.model.Conta; |
| 16 | import br.com.ec.domain.model.ContaBancaria; |
||
| 106 | espaco | 17 | import br.com.ec.domain.model.Loja; |
| 597 | blopes | 18 | import br.com.ec.domain.model.Pagamento; |
| 19 | import br.com.ec.domain.model.Parcela; |
||
| 106 | espaco | 20 | import br.com.ec.domain.model.Venda; |
| 597 | blopes | 21 | import br.com.ec.domain.model.tipos.TipoConta; |
| 22 | import br.com.ec.domain.model.tipos.TipoFrequencia; |
||
| 106 | espaco | 23 | import br.com.ec.domain.model.tipos.TipoSituacaoVenda; |
| 24 | import br.com.ec.domain.service.automatizador.AutomatizadorService; |
||
| 25 | import br.com.ec.domain.service.fecharcaixa.FecharCaixaService; |
||
| 597 | blopes | 26 | import br.com.ec.domain.service.pagamento.PagamentoService; |
| 27 | import br.com.ec.domain.service.parcela.ParcelaService; |
||
| 106 | espaco | 28 | import br.com.ec.domain.service.venda.VendaService; |
| 597 | blopes | 29 | import br.com.ec.domain.service.vigencia.VigenciaService; |
| 30 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 195 | espaco | 31 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 32 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 33 | import br.com.ec.web.generic.AbstractBean; |
||
| 34 | import br.com.ec.web.message.LancadorMensagem; |
||
| 106 | espaco | 35 | |
| 36 | @Named |
||
| 37 | @Scope("view") |
||
| 38 | public class ReceberCaixaBean extends AbstractBean<Object> implements Serializable { |
||
| 39 | |||
| 40 | private static final long serialVersionUID = 1L; |
||
| 41 | |||
| 42 | private AutomatizadorService automatizadorService; |
||
| 43 | private FecharCaixaService fecharCaixaService; |
||
| 44 | private VendaService vendaService; |
||
| 597 | blopes | 45 | private ParcelaService parcelaService; |
| 46 | private PagamentoService pagamentoService; |
||
| 47 | private VigenciaService vigenciaService; |
||
| 106 | espaco | 48 | |
| 49 | private ParametrosReceberCaixaDTO parametrosReceberCaixa; |
||
| 50 | private ParametrosFecharCaixaDTO parametrosFecharCaixa; |
||
| 51 | |||
| 52 | @Inject |
||
| 597 | blopes | 53 | public ReceberCaixaBean(AutomatizadorService automatizadorService, FecharCaixaService fecharCaixaService, VendaService vendaService, |
| 54 | ParcelaService parcelaService, PagamentoService pagamentoService, VigenciaService vigenciaService) { |
||
| 106 | espaco | 55 | this.automatizadorService = automatizadorService; |
| 56 | this.fecharCaixaService = fecharCaixaService; |
||
| 57 | this.vendaService = vendaService; |
||
| 597 | blopes | 58 | this.parcelaService = parcelaService; |
| 59 | this.pagamentoService = pagamentoService; |
||
| 60 | this.vigenciaService = vigenciaService; |
||
| 106 | espaco | 61 | } |
| 62 | |||
| 63 | @Override |
||
| 64 | public void preCarregamento() { |
||
| 65 | parametrosReceberCaixa = new ParametrosReceberCaixaDTO(); |
||
| 66 | parametrosFecharCaixa = new ParametrosFecharCaixaDTO(); |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | public void limparEntidade() {} |
||
| 71 | |||
| 72 | @Override |
||
| 73 | public GenericService<Object> getService() { |
||
| 74 | return null; |
||
| 75 | } |
||
| 76 | |||
| 77 | @Override |
||
| 78 | public Object getEntidade() { |
||
| 79 | return entidade; |
||
| 80 | } |
||
| 81 | |||
| 82 | @Override |
||
| 83 | public Object getId() { |
||
| 84 | return getEntidade(); |
||
| 85 | } |
||
| 86 | |||
| 87 | public ParametrosReceberCaixaDTO getParametrosReceberCaixa() { |
||
| 88 | return parametrosReceberCaixa; |
||
| 89 | } |
||
| 90 | public void setParametrosReceberCaixa(ParametrosReceberCaixaDTO parametrosReceberCaixa) { |
||
| 91 | this.parametrosReceberCaixa = parametrosReceberCaixa; |
||
| 92 | } |
||
| 93 | |||
| 94 | public ParametrosFecharCaixaDTO getParametrosFecharCaixa() { |
||
| 95 | return parametrosFecharCaixa; |
||
| 96 | } |
||
| 97 | public void setParametrosFecharCaixa(ParametrosFecharCaixaDTO parametrosFecharCaixa) { |
||
| 98 | this.parametrosFecharCaixa = parametrosFecharCaixa; |
||
| 99 | } |
||
| 100 | |||
| 101 | /********************************************************************/ |
||
| 102 | |||
| 103 | public void prepararRecebimentoCaixa() { |
||
| 104 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 105 | public void execute() { |
||
| 106 | getParametrosReceberCaixa().setValorRecebimentoEmDinheiro(automatizadorService.calcularReceberDia(getParametrosReceberCaixa().getLoja(), getParametrosReceberCaixa().getDataRecebimento())); |
||
| 107 | getParametrosReceberCaixa().setContaBancariaRecebimento(null); |
||
| 108 | setParametrosFecharCaixa(new ParametrosFecharCaixaDTO(getParametrosReceberCaixa().getLoja(), getParametrosReceberCaixa().getDataRecebimento())); |
||
| 109 | setParametrosFecharCaixa(fecharCaixaService.iniciarFechamentoCaixa(getParametrosFecharCaixa())); |
||
| 110 | } |
||
| 111 | }); |
||
| 112 | } |
||
| 113 | |||
| 114 | public void realizarRecebimentoCaixa() { |
||
| 115 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 116 | public void execute() { |
||
| 117 | automatizadorService.finalizarReceberDia(getParametrosReceberCaixa()); |
||
| 597 | blopes | 118 | gerarPagamentos(getParametrosFecharCaixa().getListaPagamentos()); |
| 106 | espaco | 119 | prepararRecebimentoCaixa(); |
| 120 | LancadorMensagem.lancarSucesso("RECEBIMENTO REALIZADO COM SUCESSO"); |
||
| 121 | } |
||
| 122 | }); |
||
| 123 | } |
||
| 124 | |||
| 597 | blopes | 125 | private void gerarPagamentos(final List<Pagamento> listaPagamentos) { |
| 126 | for (Pagamento pagamento : listaPagamentos) { |
||
| 127 | if (pagamento.getGerarPagamento()) { |
||
| 128 | Conta conta = new Conta(TipoConta.CONTA_A_PAGAR.getValor()); |
||
| 129 | conta.setCategoria(pagamento.getCategoriaGerarPagamento()); |
||
| 130 | conta.setLoja(pagamento.getLoja()); |
||
| 131 | conta.setTipoFrequencia(TipoFrequencia.UNICA.getValor()); |
||
| 132 | conta.setVigencia(vigenciaService.consultarVigenciaDoPeriodo(pagamento.getData())); |
||
| 133 | |||
| 134 | Parcela parcela = new Parcela(); |
||
| 135 | parcela.setContaBancaria(new ContaBancaria(ConstantesSEC.ContaBancaria.CONTA_BANCARIA_CAIXA_1L)); |
||
| 136 | parcela.setIndicadorOficial(false); |
||
| 137 | parcela.setIndicadorNegociacao(false); |
||
| 138 | parcela.setDataVencimento(pagamento.getData()); |
||
| 139 | parcela.setDataPagamento(pagamento.getData()); |
||
| 140 | parcela.setValor(pagamento.getValor()); |
||
| 141 | parcela.setObservacao(pagamento.getDescricao()); |
||
| 142 | |||
| 143 | parcela.setConta(conta); |
||
| 144 | parcelaService.lancarParcela(parcela); |
||
| 145 | |||
| 146 | pagamento.setLancado(true); |
||
| 147 | pagamentoService.alterar(pagamento); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 106 | espaco | 152 | public Boolean temVendasConferidasOuNovas() { |
| 153 | for (Venda venda : getParametrosFecharCaixa().getListaVendas()) { |
||
| 154 | if (venda.getTipoSituacao().equals(TipoSituacaoVenda.NOVO.getValor()) || venda.getTipoSituacao().equals(TipoSituacaoVenda.CONFERIDO.getValor())) { |
||
| 155 | return true; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | return false; |
||
| 159 | } |
||
| 160 | |||
| 161 | public Boolean todasVendasConferidas(Loja loja) { |
||
| 162 | Venda venda = new Venda(); |
||
| 163 | venda.setTipoSituacao(TipoSituacaoVenda.NOVO.getValor()); |
||
| 164 | if (vendaService.obterQuantidadeDeVendasPorLojaEePeriodo(venda, DataUtils.getDataAtual(), DataUtils.getDataAtual()) > 0) { |
||
| 165 | return false; |
||
| 166 | } |
||
| 167 | return true; |
||
| 168 | } |
||
| 169 | |||
| 170 | } |