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