Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Date; |
||
| 5 | |||
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 9 | import org.primefaces.event.SelectEvent; |
||
| 10 | import org.springframework.context.annotation.Scope; |
||
| 11 | |||
| 12 | import br.com.ec.domain.model.Categoria; |
||
| 13 | import br.com.ec.domain.model.Conta; |
||
| 14 | import br.com.ec.domain.model.ContaBancaria; |
||
| 15 | import br.com.ec.domain.model.Pagamento; |
||
| 16 | import br.com.ec.domain.model.Parcela; |
||
| 17 | import br.com.ec.domain.model.Pessoa; |
||
| 18 | import br.com.ec.domain.model.tipos.TipoConta; |
||
| 19 | import br.com.ec.domain.service.conta.ContaService; |
||
| 20 | import br.com.ec.domain.service.pagamento.PagamentoService; |
||
| 21 | import br.com.ec.domain.service.parcela.ParcelaService; |
||
| 22 | import br.edu.cesmac.core.generic.GenericService; |
||
| 23 | import br.edu.cesmac.core.util.DataUtils; |
||
| 24 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 25 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 26 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 27 | import br.edu.cesmac.web.generic.AbstractBean; |
||
| 28 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 29 | |||
| 30 | @Named |
||
| 31 | @Scope("view") |
||
| 32 | public class ParcelaBean extends AbstractBean<Parcela> implements Serializable { |
||
| 33 | |||
| 34 | private static final long serialVersionUID = 1L; |
||
| 35 | |||
| 36 | private ParcelaService parcelaService; |
||
| 37 | private ContaService contaService; |
||
| 38 | private PagamentoService pagamentoService; |
||
| 39 | |||
| 40 | @Inject |
||
| 41 | public ParcelaBean(ParcelaService parcelaService, ContaService contaService, PagamentoService pagamentoService) { |
||
| 42 | this.parcelaService = parcelaService; |
||
| 43 | this.contaService = contaService; |
||
| 44 | this.pagamentoService = pagamentoService; |
||
| 45 | } |
||
| 46 | |||
| 47 | @Override |
||
| 48 | public void preCarregamento() { |
||
| 49 | if (VerificadorUtil.estaNulo(entidade)) { |
||
| 50 | entidade = new Parcela(); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | @Override |
||
| 55 | public void limparEntidade() { |
||
| 56 | setEntidade(new Parcela()); |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public GenericService<Parcela> getService() { |
||
| 61 | return parcelaService; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public Parcela getEntidade() { |
||
| 66 | return entidade; |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | public Parcela getId() { |
||
| 71 | return getEntidade(); |
||
| 72 | } |
||
| 73 | |||
| 74 | public void onRowSelect(SelectEvent event) { |
||
| 75 | setEntidade(parcelaService.consultarPorId((Parcela) event.getObject())); |
||
| 76 | } |
||
| 77 | |||
| 78 | /***************************************************************/ |
||
| 79 | |||
| 80 | public void iniciarParcelaAReceber(ContaBancaria contaBancaria) { |
||
| 81 | entidade = new Parcela(); |
||
| 82 | entidade.setContaBancaria(contaBancaria); |
||
| 83 | entidade.setConta(new Conta(TipoConta.CONTA_A_RECEBER.getValor())); |
||
| 84 | } |
||
| 85 | |||
| 86 | public void iniciarParcelaAPagar(ContaBancaria contaBancaria) { |
||
| 87 | entidade = new Parcela(); |
||
| 88 | entidade.setContaBancaria(contaBancaria); |
||
| 89 | entidade.setConta(new Conta(TipoConta.CONTA_A_PAGAR.getValor())); |
||
| 90 | } |
||
| 91 | |||
| 92 | public void iniciarParcelaAPagar(Pagamento pagamento) { |
||
| 93 | entidade = new Parcela(); |
||
| 94 | entidade.setContaBancaria(new ContaBancaria(ContaBancaria.getContaCaixa())); |
||
| 95 | Conta conta = new Conta(TipoConta.CONTA_A_PAGAR.getValor()); |
||
| 96 | conta.setLoja(pagamento.getLoja()); |
||
| 97 | entidade.setConta(conta); |
||
| 98 | entidade.setDataPagamento(pagamento.getData()); |
||
| 99 | entidade.setDataVencimento(pagamento.getData()); |
||
| 100 | entidade.setObservacao(pagamento.getDescricao()); |
||
| 101 | entidade.setValor(pagamento.getValor()); |
||
| 102 | } |
||
| 103 | |||
| 104 | public void depositar() { |
||
| 105 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 106 | public void execute() { |
||
| 107 | parcelaService.lancarParcela(getEntidade()); |
||
| 108 | LancadorMensagem.lancarSucesso("DEPÓSITO REALIZADO COM SUCESSO!"); |
||
| 109 | } |
||
| 110 | }); |
||
| 111 | } |
||
| 112 | |||
| 113 | public void pagar() { |
||
| 114 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 115 | public void execute() { |
||
| 116 | parcelaService.lancarParcela(getEntidade()); |
||
| 117 | LancadorMensagem.lancarSucesso("PAGAMENTO REALIZADO COM SUCESSO!"); |
||
| 118 | } |
||
| 119 | }); |
||
| 120 | } |
||
| 121 | |||
| 122 | public void cancelarParcela() { |
||
| 123 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 124 | public void execute() { |
||
| 125 | parcelaService.cancelarParcela(getEntidade()); |
||
| 126 | LancadorMensagem.lancarSucesso("PAGAMENTO CANCELADO COM SUCESSO!"); |
||
| 127 | } |
||
| 128 | }); |
||
| 129 | } |
||
| 130 | |||
| 131 | public void selecionarCategoria(Categoria categoria) { |
||
| 132 | getEntidade().getConta().setCategoria(categoria); |
||
| 133 | } |
||
| 134 | |||
| 135 | public void retirarCategoria() { |
||
| 136 | getEntidade().getConta().setCategoria(null); |
||
| 137 | } |
||
| 138 | |||
| 139 | public void selecionarPessoa(Pessoa pessoa) { |
||
| 140 | getEntidade().getConta().setPessoa(pessoa); |
||
| 141 | } |
||
| 142 | |||
| 143 | public void retirarPessoa() { |
||
| 144 | getEntidade().getConta().setPessoa(null); |
||
| 145 | } |
||
| 146 | |||
| 147 | @Override |
||
| 148 | public void alterar() { |
||
| 149 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 150 | public void execute() { |
||
| 151 | modificarEntidadeAntesDaOperacao(); |
||
| 152 | getService().alterar(getEntidade()); |
||
| 153 | contaService.alterar(getEntidade().getConta()); |
||
| 154 | limparEntidade(); |
||
| 155 | modificarEntidadeDepoisDaOperacao(); |
||
| 156 | LancadorMensagem.lancarSucesso(getMensagens().get(IDENTIFICADOR_MENSAGEM_ALTERADO_COM_SUCESSO)); |
||
| 157 | } |
||
| 158 | }); |
||
| 159 | } |
||
| 160 | |||
| 161 | public void inicializarParcelaAReceber(final Conta conta) { |
||
| 162 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 163 | public void execute() { |
||
| 164 | Parcela parcela = new Parcela(); |
||
| 165 | parcela.setIndicadorAtivo(true); |
||
| 166 | if (VerificadorUtil.naoEstaNulo(conta)) { |
||
| 167 | parcela.setConta(conta); |
||
| 168 | if (VerificadorUtil.naoEstaNulo(conta.getVenda())) { |
||
| 169 | parcela.setDataEmissao(conta.getVenda().getDataVenda()); |
||
| 170 | parcela.setObservacao("PARCELA DA VENDA: " + conta.getSequencialDaVenda()); |
||
| 171 | } else { |
||
| 172 | parcela.setDataEmissao(DataUtils.getDataAtual()); |
||
| 173 | } |
||
| 174 | } |
||
| 175 | setEntidade(parcela); |
||
| 176 | } |
||
| 177 | }); |
||
| 178 | } |
||
| 179 | |||
| 180 | public void inicializarParcelaAPagar(final Conta conta) { |
||
| 181 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 182 | public void execute() { |
||
| 183 | Parcela parcela = new Parcela(); |
||
| 184 | parcela.setIndicadorAtivo(true); |
||
| 185 | if (VerificadorUtil.naoEstaNulo(conta)) { |
||
| 186 | parcela.setDataEmissao(DataUtils.getDataAtual()); |
||
| 187 | parcela.setConta(conta); |
||
| 188 | parcela.setObservacao("PARCELA: " + conta.getSequencial()); |
||
| 189 | } |
||
| 190 | setEntidade(parcela); |
||
| 191 | } |
||
| 192 | }); |
||
| 193 | } |
||
| 194 | |||
| 195 | public void cadastrarFinalizandoPagamento(final Pagamento pagamento) { |
||
| 196 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 197 | public void execute() { |
||
| 198 | parcelaService.lancarParcela(getEntidade()); |
||
| 199 | limparEntidade(); |
||
| 200 | pagamento.setLancado(true); |
||
| 201 | pagamentoService.alterar(pagamento); |
||
| 202 | LancadorMensagem.lancarSucesso("Conta lançada e pagamento finalizado com sucesso!"); |
||
| 203 | } |
||
| 204 | }); |
||
| 205 | } |
||
| 206 | |||
| 207 | } |