Subversion Repositories Integrator Subversion

Rev

Rev 286 | Rev 387 | 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()));
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()));
113
        }
114
 
115
        public void iniciarParcelaAPagar(Pagamento pagamento) {
116
                entidade = new Parcela();
117
                entidade.setContaBancaria(new ContaBancaria(ContaBancaria.getContaCaixa()));
118
                Conta conta = new Conta(TipoConta.CONTA_A_PAGAR.getValor());
119
                conta.setLoja(pagamento.getLoja());
120
                entidade.setConta(conta);
121
                entidade.setDataPagamento(pagamento.getData());
122
                entidade.setDataVencimento(pagamento.getData());
123
                entidade.setObservacao(pagamento.getDescricao());
124
                entidade.setValor(pagamento.getValor());
125
        }
126
 
127
        public void depositar() {
128
        new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
129
                        public void execute() {
130
                                parcelaService.lancarParcela(getEntidade());
131
                                LancadorMensagem.lancarSucesso("DEPÓSITO REALIZADO COM SUCESSO!");
132
                        }
133
                });
134
    }
135
 
136
        public void pagar() {
137
        new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
138
                        public void execute() {
139
                                parcelaService.lancarParcela(getEntidade());
140
                                LancadorMensagem.lancarSucesso("PAGAMENTO REALIZADO COM SUCESSO!");
141
                        }
142
                });
143
    }
144
 
145
        public void cancelarParcela() {
146
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
147
                        public void execute() {
148
                                parcelaService.cancelarParcela(getEntidade());
149
                                LancadorMensagem.lancarSucesso("PAGAMENTO CANCELADO COM SUCESSO!");
150
                        }
151
                });
152
        }
153
 
154
        public void selecionarCategoria(Categoria categoria) {
155
                getEntidade().getConta().setCategoria(categoria);
156
        }
157
 
158
        public void retirarCategoria() {
159
                getEntidade().getConta().setCategoria(null);
160
        }
161
 
162
        public void selecionarPessoa(Pessoa pessoa) {
163
                getEntidade().getConta().setPessoa(pessoa);
164
        }
165
 
166
        public void retirarPessoa() {
167
                getEntidade().getConta().setPessoa(null);
168
        }
169
 
170
        @Override
171
        public void alterar() {
172
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
173
                        public void execute() {
174
                                modificarEntidadeAntesDaOperacao();
175
                                getService().alterar(getEntidade());
176
                                contaService.alterar(getEntidade().getConta());
177
                                limparEntidade();
178
                                modificarEntidadeDepoisDaOperacao();
179
                                LancadorMensagem.lancarSucesso(getMensagens().get(IDENTIFICADOR_MENSAGEM_ALTERADO_COM_SUCESSO));
180
                        }
181
                });
182
        }
183
 
184
        public void inicializarParcelaAReceber(final Conta conta) {
185
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
186
                        public void execute() {
187
                                Parcela parcela = new Parcela();
188
                                parcela.setIndicadorAtivo(true);
189
                                if (VerificadorUtil.naoEstaNulo(conta)) {
190
                                        parcela.setConta(conta);
191
                                        if (VerificadorUtil.naoEstaNulo(conta.getVenda())) {
192
                                                parcela.setDataEmissao(conta.getVenda().getDataVenda());
193
                                                parcela.setObservacao("PARCELA DA VENDA: " + conta.getSequencialDaVenda());
194
                                        } else {
195
                                                parcela.setDataEmissao(DataUtils.getDataAtual());
196
                                        }
197
                                }
198
                                setEntidade(parcela);
199
                        }
200
                });
201
        }
202
 
203
        public void inicializarParcelaAPagar(final Conta conta) {
204
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
205
                        public void execute() {
206
                                Parcela parcela = new Parcela();
207
                                parcela.setIndicadorAtivo(true);
208
                                if (VerificadorUtil.naoEstaNulo(conta)) {
209
                                        parcela.setDataEmissao(DataUtils.getDataAtual());
210
                                        parcela.setConta(conta);
211
                                        parcela.setObservacao("PARCELA: " + conta.getSequencial());
212
                                }
213
                                setEntidade(parcela);
214
                        }
215
                });
216
        }
217
 
218
        public void cadastrarFinalizandoPagamento(final Pagamento pagamento) {
219
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
220
                        public void execute() {
221
                                parcelaService.lancarParcela(getEntidade());
222
                                limparEntidade();
223
                                pagamento.setLancado(true);
224
                                pagamentoService.alterar(pagamento);
225
                                LancadorMensagem.lancarSucesso("Conta lançada e pagamento finalizado com sucesso!");
226
                        }
227
                });
228
        }
229
 
288 espaco 230
        public void iniciarTransferenciaContaBancaria() {
286 espaco 231
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
232
                        public void execute() {
288 espaco 233
                                ContaBancariaTransferencia transferenciaContaBancaria = new ContaBancariaTransferencia();
286 espaco 234
                                transferenciaContaBancaria.setDataOperacao(DataUtils.getDataAtual());
235
                                setTransferenciaContaBancaria(transferenciaContaBancaria);
236
                        }
237
                });
238
        }
239
 
240
        public void transferirContaBancaria() {
241
        new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
242
                        public void execute() {
288 espaco 243
                                contaBancariaTransferenciaService.cadastrar(getTransferenciaContaBancaria());
244
                                setTransferenciaContaBancaria(null);
286 espaco 245
                                LancadorMensagem.lancarSucesso("TRANSFERÊNCIA REALIZADA COM SUCESSO!");
246
                        }
247
                });
248
    }
249
 
288 espaco 250
        public void consultarUltimasTransferencias() {
251
        new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
252
                        public void execute() {
253
                                setTransferenciasContaBancaria(contaBancariaTransferenciaService.consultarUltimasTransferencias());
254
                        }
255
                });
256
    }
257
 
258
        public void excluirTransferenciaBancaria(final ContaBancariaTransferencia contaBancariaTransferencia) {
259
        new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
260
                        public void execute() {
261
                                contaBancariaTransferenciaService.excluir(contaBancariaTransferencia);
262
                                consultarUltimasTransferencias();
263
                                LancadorMensagem.lancarSucesso("TRANSFERÊNCIA EXCLUÍDA COM SUCESSO!");
264
                        }
265
                });
266
    }
267
 
106 espaco 268
}