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