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