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 | |||
| 5 | import javax.inject.Inject; |
||
| 6 | import javax.inject.Named; |
||
| 7 | |||
| 8 | import org.springframework.context.annotation.Scope; |
||
| 9 | |||
| 10 | import br.com.ec.core.generic.GenericService; |
||
| 11 | import br.com.ec.core.util.DataUtils; |
||
| 12 | import br.com.ec.domain.dto.ParametrosFecharCaixaDTO; |
||
| 13 | import br.com.ec.domain.dto.ParametrosReceberCaixaDTO; |
||
| 14 | import br.com.ec.domain.model.Loja; |
||
| 15 | import br.com.ec.domain.model.Venda; |
||
| 16 | import br.com.ec.domain.model.tipos.TipoSituacaoVenda; |
||
| 17 | import br.com.ec.domain.service.automatizador.AutomatizadorService; |
||
| 18 | import br.com.ec.domain.service.fecharcaixa.FecharCaixaService; |
||
| 19 | import br.com.ec.domain.service.venda.VendaService; |
||
| 20 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 21 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 22 | import br.com.ec.web.generic.AbstractBean; |
||
| 23 | import br.com.ec.web.message.LancadorMensagem; |
||
| 24 | |||
| 25 | @Named |
||
| 26 | @Scope("view") |
||
| 27 | public class ReceberCaixaBean extends AbstractBean<Object> implements Serializable { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private AutomatizadorService automatizadorService; |
||
| 32 | private FecharCaixaService fecharCaixaService; |
||
| 33 | private VendaService vendaService; |
||
| 34 | |||
| 35 | private ParametrosReceberCaixaDTO parametrosReceberCaixa; |
||
| 36 | private ParametrosFecharCaixaDTO parametrosFecharCaixa; |
||
| 37 | |||
| 38 | @Inject |
||
| 39 | public ReceberCaixaBean(AutomatizadorService automatizadorService, FecharCaixaService fecharCaixaService, VendaService vendaService) { |
||
| 40 | this.automatizadorService = automatizadorService; |
||
| 41 | this.fecharCaixaService = fecharCaixaService; |
||
| 42 | this.vendaService = vendaService; |
||
| 43 | } |
||
| 44 | |||
| 45 | @Override |
||
| 46 | public void preCarregamento() { |
||
| 47 | parametrosReceberCaixa = new ParametrosReceberCaixaDTO(); |
||
| 48 | parametrosFecharCaixa = new ParametrosFecharCaixaDTO(); |
||
| 49 | } |
||
| 50 | |||
| 51 | @Override |
||
| 52 | public void limparEntidade() {} |
||
| 53 | |||
| 54 | @Override |
||
| 55 | public GenericService<Object> getService() { |
||
| 56 | return null; |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public Object getEntidade() { |
||
| 61 | return entidade; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public Object getId() { |
||
| 66 | return getEntidade(); |
||
| 67 | } |
||
| 68 | |||
| 69 | public ParametrosReceberCaixaDTO getParametrosReceberCaixa() { |
||
| 70 | return parametrosReceberCaixa; |
||
| 71 | } |
||
| 72 | public void setParametrosReceberCaixa(ParametrosReceberCaixaDTO parametrosReceberCaixa) { |
||
| 73 | this.parametrosReceberCaixa = parametrosReceberCaixa; |
||
| 74 | } |
||
| 75 | |||
| 76 | public ParametrosFecharCaixaDTO getParametrosFecharCaixa() { |
||
| 77 | return parametrosFecharCaixa; |
||
| 78 | } |
||
| 79 | public void setParametrosFecharCaixa(ParametrosFecharCaixaDTO parametrosFecharCaixa) { |
||
| 80 | this.parametrosFecharCaixa = parametrosFecharCaixa; |
||
| 81 | } |
||
| 82 | |||
| 83 | /********************************************************************/ |
||
| 84 | |||
| 85 | public void prepararRecebimentoCaixa() { |
||
| 86 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 87 | public void execute() { |
||
| 88 | getParametrosReceberCaixa().setValorRecebimentoEmDinheiro(automatizadorService.calcularReceberDia(getParametrosReceberCaixa().getLoja(), getParametrosReceberCaixa().getDataRecebimento())); |
||
| 89 | getParametrosReceberCaixa().setContaBancariaRecebimento(null); |
||
| 90 | setParametrosFecharCaixa(new ParametrosFecharCaixaDTO(getParametrosReceberCaixa().getLoja(), getParametrosReceberCaixa().getDataRecebimento())); |
||
| 91 | setParametrosFecharCaixa(fecharCaixaService.iniciarFechamentoCaixa(getParametrosFecharCaixa())); |
||
| 92 | } |
||
| 93 | }); |
||
| 94 | } |
||
| 95 | |||
| 96 | public void realizarRecebimentoCaixa() { |
||
| 97 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 98 | public void execute() { |
||
| 99 | automatizadorService.finalizarReceberDia(getParametrosReceberCaixa()); |
||
| 100 | prepararRecebimentoCaixa(); |
||
| 101 | LancadorMensagem.lancarSucesso("RECEBIMENTO REALIZADO COM SUCESSO"); |
||
| 102 | } |
||
| 103 | }); |
||
| 104 | } |
||
| 105 | |||
| 106 | public Boolean temVendasConferidasOuNovas() { |
||
| 107 | for (Venda venda : getParametrosFecharCaixa().getListaVendas()) { |
||
| 108 | if (venda.getTipoSituacao().equals(TipoSituacaoVenda.NOVO.getValor()) || venda.getTipoSituacao().equals(TipoSituacaoVenda.CONFERIDO.getValor())) { |
||
| 109 | return true; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | |||
| 115 | public Boolean todasVendasConferidas(Loja loja) { |
||
| 116 | Venda venda = new Venda(); |
||
| 117 | venda.setTipoSituacao(TipoSituacaoVenda.NOVO.getValor()); |
||
| 118 | if (vendaService.obterQuantidadeDeVendasPorLojaEePeriodo(venda, DataUtils.getDataAtual(), DataUtils.getDataAtual()) > 0) { |
||
| 119 | return false; |
||
| 120 | } |
||
| 121 | return true; |
||
| 122 | } |
||
| 123 | |||
| 124 | } |