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