Rev 195 | Go to most recent revision | Details | 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; |
||
| 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.domain.model.Loja; |
||
| 12 | import br.com.ec.domain.model.Pagamento; |
||
| 13 | import br.com.ec.domain.model.Usuario; |
||
| 14 | import br.com.ec.domain.service.loja.LojaService; |
||
| 15 | import br.com.ec.domain.service.pagamento.PagamentoService; |
||
| 16 | import br.com.ec.domain.service.usuario.UsuarioService; |
||
| 17 | import br.edu.cesmac.core.generic.GenericService; |
||
| 18 | import br.edu.cesmac.core.util.DataUtils; |
||
| 19 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 20 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 21 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 22 | import br.edu.cesmac.web.generic.AbstractBean; |
||
| 23 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 24 | |||
| 25 | @Named |
||
| 26 | @Scope("view") |
||
| 27 | public class PagamentoBean extends AbstractBean<Pagamento> implements Serializable { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private Pagamento pagamentoSelecionado; |
||
| 32 | private Loja lojaSelecionada; |
||
| 33 | private String senhaUsuario; |
||
| 34 | |||
| 35 | private PagamentoService pagamentoService; |
||
| 36 | private LojaService lojaService; |
||
| 37 | private UsuarioService usuarioService; |
||
| 38 | |||
| 39 | @Inject |
||
| 40 | public PagamentoBean(PagamentoService pagamentoService, LojaService lojaService, UsuarioService usuarioService) { |
||
| 41 | this.pagamentoService = pagamentoService; |
||
| 42 | this.lojaService = lojaService; |
||
| 43 | this.usuarioService = usuarioService; |
||
| 44 | } |
||
| 45 | |||
| 46 | @Override |
||
| 47 | public void preCarregamento() { |
||
| 48 | entidade = new Pagamento(); |
||
| 49 | entidade.setLoja(getLojaSelecionada()); |
||
| 50 | entidade.setLancado(false); |
||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | public void limparEntidade() { |
||
| 55 | setEntidade(new Pagamento()); |
||
| 56 | } |
||
| 57 | |||
| 58 | @Override |
||
| 59 | public GenericService<Pagamento> getService() { |
||
| 60 | return pagamentoService; |
||
| 61 | } |
||
| 62 | |||
| 63 | @Override |
||
| 64 | public Pagamento getEntidade() { |
||
| 65 | return entidade; |
||
| 66 | } |
||
| 67 | |||
| 68 | @Override |
||
| 69 | public Pagamento getId() { |
||
| 70 | return getEntidade(); |
||
| 71 | } |
||
| 72 | |||
| 73 | public Pagamento getPagamentoSelecionado() { |
||
| 74 | return pagamentoSelecionado; |
||
| 75 | } |
||
| 76 | public void setPagamentoSelecionado(Pagamento pagamentoSelecionado) { |
||
| 77 | this.pagamentoSelecionado = pagamentoSelecionado; |
||
| 78 | } |
||
| 79 | |||
| 80 | public Loja getLojaSelecionada() { |
||
| 81 | if (VerificadorUtil.estaNulo(lojaSelecionada)) { |
||
| 82 | Loja loja = new Loja(); |
||
| 83 | loja.setSequencial(new Long(getParametro("sequencialLoja").toString())); |
||
| 84 | lojaSelecionada = lojaService.consultarPorId(loja); |
||
| 85 | } |
||
| 86 | return lojaSelecionada; |
||
| 87 | } |
||
| 88 | public void setLojaSelecionada(Loja lojaSelecionada) { |
||
| 89 | this.lojaSelecionada = lojaSelecionada; |
||
| 90 | } |
||
| 91 | |||
| 92 | public String getSenhaUsuario() { |
||
| 93 | return senhaUsuario; |
||
| 94 | } |
||
| 95 | public void setSenhaUsuario(String senhaUsuario) { |
||
| 96 | this.senhaUsuario = senhaUsuario; |
||
| 97 | } |
||
| 98 | |||
| 99 | public Integer quantidadePagamentosEmAberto(Loja loja) { |
||
| 100 | return pagamentoService.quantidadePagamentosEmAberto(loja); |
||
| 101 | } |
||
| 102 | |||
| 103 | public Double valorTotalPagamentosDoDia(Loja loja) { |
||
| 104 | List<Pagamento> pagamentosDoDia = pagamentoService.consultarPagamentosDoDia(loja.getSequencial(), DataUtils.getDataAtual()); |
||
| 105 | Double valorTotal = new Double(0.0); |
||
| 106 | for (Pagamento pagamento : pagamentosDoDia) { |
||
| 107 | valorTotal = valorTotal + pagamento.getValor(); |
||
| 108 | } |
||
| 109 | return valorTotal; |
||
| 110 | } |
||
| 111 | |||
| 112 | @Override |
||
| 113 | public void cadastrar() { |
||
| 114 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 115 | public void execute() { |
||
| 116 | getEntidade().setLoja(getLojaSelecionada()); |
||
| 117 | Usuario usuario = verificarSenhaUsuario(); |
||
| 118 | getEntidade().setUsuario(usuario); |
||
| 119 | getService().cadastrar(getEntidade()); |
||
| 120 | setSenhaUsuario(""); |
||
| 121 | LancadorMensagem.lancarSucesso("Pagamento cadastrado com sucesso!"); |
||
| 122 | } |
||
| 123 | }); |
||
| 124 | } |
||
| 125 | |||
| 126 | private Usuario verificarSenhaUsuario() { |
||
| 127 | return usuarioService.consultarUsuarioPorSenha(getSenhaUsuario()); |
||
| 128 | } |
||
| 129 | |||
| 130 | public void finalizar(final Pagamento pagamento) { |
||
| 131 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 132 | public void execute() { |
||
| 133 | pagamento.setLancado(true); |
||
| 134 | getService().alterar(pagamento); |
||
| 135 | LancadorMensagem.lancarSucesso("Pagamento finalizado com sucesso!"); |
||
| 136 | } |
||
| 137 | }); |
||
| 138 | } |
||
| 139 | |||
| 140 | public void retirarLancamento(final Pagamento pagamento) { |
||
| 141 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 142 | public void execute() { |
||
| 143 | pagamento.setLancado(false); |
||
| 144 | getService().alterar(pagamento); |
||
| 145 | LancadorMensagem.lancarSucesso("Lançamento do pagamento retirado com sucesso!"); |
||
| 146 | } |
||
| 147 | }); |
||
| 148 | } |
||
| 149 | |||
| 150 | public void excluir(final Pagamento pagamento) { |
||
| 151 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 152 | public void execute() { |
||
| 153 | getService().excluir(pagamento); |
||
| 154 | LancadorMensagem.lancarSucesso("Pagamento excluĂdo com sucesso!"); |
||
| 155 | } |
||
| 156 | }); |
||
| 157 | } |
||
| 158 | |||
| 159 | } |