Subversion Repositories Integrator Subversion

Rev

Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
package br.com.ec.controller.managedbean;
2
 
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStreamReader;
6
import java.io.Serializable;
7
import java.util.ArrayList;
8
import java.util.Calendar;
9
import java.util.Date;
10
import java.util.List;
11
 
12
import javax.inject.Inject;
13
import javax.inject.Named;
14
 
15
import org.apache.commons.lang.time.DateUtils;
16
import org.primefaces.event.FileUploadEvent;
17
import org.primefaces.model.file.UploadedFile;
18
import org.springframework.context.annotation.Scope;
19
 
20
import br.com.ec.domain.dto.CartaoBandeiraDTO;
21
import br.com.ec.domain.dto.CartaoDTO;
22
import br.com.ec.domain.dto.CartaoDataDTO;
23
import br.com.ec.domain.dto.CartaoResumoDTO;
24
import br.com.ec.domain.dto.CartaoResumoGeralDTO;
25
import br.com.ec.domain.model.FormaPagamento;
26
import br.com.ec.domain.model.Maquineta;
27
import br.com.ec.domain.model.VendaFormaPagamento;
28
import br.com.ec.domain.model.tipos.TipoCartao;
29
import br.com.ec.domain.service.bandeiracartao.BandeiraCartaoService;
30
import br.com.ec.domain.service.formapagamento.FormaPagamentoService;
31
import br.com.ec.domain.service.parcela.ParcelaService;
32
import br.com.ec.domain.service.vendaformapagamento.VendaFormaPagamentoService;
33
import br.com.ec.domain.shared.ConstantesSEC;
34
import br.com.ec.domain.shared.Ordenador;
35
import br.com.ec.domain.shared.OrdenadorImpl;
36
import br.edu.cesmac.core.exception.NegocioException;
37
import br.edu.cesmac.core.generic.GenericService;
38
import br.edu.cesmac.core.util.DataUtils;
39
import br.edu.cesmac.core.util.StringUtil;
40
import br.edu.cesmac.core.util.VerificadorUtil;
41
import br.edu.cesmac.web.exception.VerificadorLancamentoException;
42
import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean;
43
import br.edu.cesmac.web.generic.AbstractBean;
44
import br.edu.cesmac.web.message.LancadorMensagem;
45
import br.edu.cesmac.web.util.DataUtil;
46
 
47
@Named
48
@Scope("view")
49
public class CartoesGerenciadorBean extends AbstractBean<CartaoDTO> implements Serializable {
50
 
51
        private static final long serialVersionUID = 1L;
52
 
53
        private ParcelaService parcelaService;
54
        private VendaFormaPagamentoService vendaFormaPagamentoService;
55
        private BandeiraCartaoService bandeiraCartaoService;
56
        private FormaPagamentoService formaPagamentoService;
57
 
58
        private List<CartaoDTO> cartoes;
59
        private List<CartaoDTO> cartoesGerados;
60
        private CartaoResumoGeralDTO cartaoResumoGeral;
61
        private CartaoResumoDTO cartaoResumo;
62
 
63
        private Date dataVendas;
64
        private List<VendaFormaPagamento> listaVendaFormaPagamento;
65
        private List<CartaoDataDTO> listaDatas;
66
 
67
        private List<Maquineta> maquinetasSelecionadas;
68
        private Boolean indicadorVerificarMaquinetas = false;
69
        private String tipoArquivoSelecionado = ConstantesSEC.ArquivoBanco.ARQUIVO_BANCO_REDE_1;
70
 
71
        private List<String> linhas;
72
        private UploadedFile arquivoParaUpload;
73
        private Ordenador ordenador;
74
 
75
        @Inject
76
        public CartoesGerenciadorBean(ParcelaService parcelaService, VendaFormaPagamentoService vendaFormaPagamentoService,
77
                        BandeiraCartaoService bandeiraCartaoService, FormaPagamentoService formaPagamentoService) {
78
                this.parcelaService = parcelaService;
79
                this.vendaFormaPagamentoService = vendaFormaPagamentoService;
80
                this.bandeiraCartaoService = bandeiraCartaoService;
81
                this.formaPagamentoService = formaPagamentoService;
82
                this.ordenador = new OrdenadorImpl();
83
        }      
84
 
85
        @Override
86
        public void preCarregamento() {
87
                setDataVendas(DataUtils.getDataAtual());
88
                setCartaoResumoGeral(new CartaoResumoGeralDTO());
89
        }
90
 
91
        @Override
92
        public void limparEntidade() {
93
                setEntidade(new CartaoDTO());
94
                setCartoes(null);
95
                setCartoesGerados(null);
96
                setCartaoResumo(null);
97
        }
98
 
99
        @Override
100
        public GenericService<CartaoDTO> getService() {
101
                return null;
102
        }
103
 
104
        @Override
105
        public CartaoDTO getEntidade() {
106
                return entidade;
107
        }
108
 
109
        @Override
110
        public CartaoDTO getId() {
111
                return getEntidade();
112
        }
113
 
114
        public List<CartaoDTO> getCartoes() {
115
                return cartoes;
116
        }
117
        public void setCartoes(List<CartaoDTO> cartoes) {
118
                this.cartoes = cartoes;
119
        }
120
 
121
        public List<CartaoDTO> getCartoesGerados() {
122
                return cartoesGerados;
123
        }
124
        public void setCartoesGerados(List<CartaoDTO> cartoesGerados) {
125
                this.cartoesGerados = cartoesGerados;
126
        }
127
 
128
        public CartaoResumoGeralDTO getCartaoResumoGeral() {
129
                return cartaoResumoGeral;
130
        }
131
        public void setCartaoResumoGeral(CartaoResumoGeralDTO cartaoResumoGeral) {
132
                this.cartaoResumoGeral = cartaoResumoGeral;
133
        }
134
 
135
        public CartaoResumoDTO getCartaoResumo() {
136
                return cartaoResumo;
137
        }
138
        public void setCartaoResumo(CartaoResumoDTO cartaoResumo) {
139
                this.cartaoResumo = cartaoResumo;
140
        }
141
 
142
        public Date getDataVendas() {
143
                return dataVendas;
144
        }
145
        public void setDataVendas(Date dataVendas) {
146
                this.dataVendas = dataVendas;
147
        }
148
 
149
        public List<VendaFormaPagamento> getListaVendaFormaPagamento() {
150
                return listaVendaFormaPagamento;
151
        }
152
        public void setListaVendaFormaPagamento(List<VendaFormaPagamento> listaVendaFormaPagamento) {
153
                this.listaVendaFormaPagamento = listaVendaFormaPagamento;
154
        }
155
 
156
        public List<CartaoDataDTO> getListaDatas() {
157
                return listaDatas;
158
        }
159
        public void setListaDatas(List<CartaoDataDTO> listaDatas) {
160
                this.listaDatas = listaDatas;
161
        }
162
 
163
        public List<Maquineta> getMaquinetasSelecionadas() {
164
                return maquinetasSelecionadas;
165
        }
166
        public void setMaquinetasSelecionadas(List<Maquineta> maquinetasSelecionadas) {
167
                this.maquinetasSelecionadas = maquinetasSelecionadas;
168
        }
169
        public String maquinetasSelecionadasDescricao() {
170
                String descricao = "";
171
                for (Maquineta m : getMaquinetasSelecionadas()) {
172
                        descricao = descricao + m.getEmpresaAdquirente().getDescricao() + ": " + m.getDescricao() + "; ";
173
                }
174
                return descricao;
175
        }
176
 
177
        public Boolean getIndicadorVerificarMaquinetas() {
178
                return indicadorVerificarMaquinetas;
179
        }
180
        public void setIndicadorVerificarMaquinetas(Boolean indicadorVerificarMaquinetas) {
181
                this.indicadorVerificarMaquinetas = indicadorVerificarMaquinetas;
182
        }
183
 
184
        public String getTipoArquivoSelecionado() {
185
                return tipoArquivoSelecionado;
186
        }
187
        public void setTipoArquivoSelecionado(String tipoArquivoSelecionado) {
188
                this.tipoArquivoSelecionado = tipoArquivoSelecionado;
189
        }
190
 
191
        public List<String> getLinhas() {
192
                return linhas;
193
        }
194
        public void setLinhas(List<String> linhas) {
195
                this.linhas = linhas;
196
        }
197
 
198
        public UploadedFile getArquivoParaUpload() {
199
                return arquivoParaUpload;
200
        }
201
        public void setArquivoParaUpload(UploadedFile arquivoParaUpload) {
202
                this.arquivoParaUpload = arquivoParaUpload;
203
        }
204
 
205
        public void atualizarConsultaComArquivo() {
206
                limparEntidade();
207
                cartaoResumo = new CartaoResumoDTO();
208
                consultarComArquivo();
209
        }
210
 
211
        public void uploadArquivoCsv(final FileUploadEvent e) {
212
        new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
213
                        public void execute() {
214
                                limparEntidade();
215
                                BufferedReader reader = null;
216
                                List<String> linhas = new ArrayList<String>();
217
                                try {
218
                                        reader = new BufferedReader(new InputStreamReader(e.getFile().getInputStream()));
219
                                        String linha = reader.readLine();
220
                                        cartaoResumo = new CartaoResumoDTO();
221
                                while ((linha = reader.readLine()) != null) {
222
                                        linhas.add(linha);
223
                                }
224
                                } catch (Exception ex) {
225
                                        ex.printStackTrace();
226
                                } finally {
227
                                        try {
228
                                                reader.close();
229
                                        } catch (IOException exc) {
230
                                                exc.printStackTrace();
231
                                        }
232
                                }
233
                                setLinhas(linhas);
234
                                consultarComArquivo();
235
                        }
236
                });
237
    }
238
 
239
        public void consultarComArquivo() {
240
                try {
241
                        if (getTipoArquivoSelecionado().equals(ConstantesSEC.ArquivoBanco.ARQUIVO_BANCO_REDE_1)) {
242
                                arquivoBancoRede(getCartaoResumoGeral().getDataInicialVendasSelecionada(), getCartaoResumoGeral().getDataFinalVendasSelecionada(), getMaquinetasSelecionadas(), getIndicadorVerificarMaquinetas());
243
                        }
244
                        if (getTipoArquivoSelecionado().equals(ConstantesSEC.ArquivoBanco.ARQUIVO_BANCO_SAFRA_2)) {
245
                                arquivoBancoSafra(getCartaoResumoGeral().getDataInicialVendasSelecionada(), getCartaoResumoGeral().getDataFinalVendasSelecionada());
246
                        }
247
                setListaVendaFormaPagamento(vendaFormaPagamentoService.consultarLancamentosCartoesNoPeriodo(getCartaoResumoGeral().getDataInicialVendasSelecionada(), getCartaoResumoGeral().getDataFinalVendasSelecionada(), null, getMaquinetasSelecionadas()));
248
                for (VendaFormaPagamento vendaFormaPagamento : getListaVendaFormaPagamento()) {
249
                        if (VerificadorUtil.estaNulo(vendaFormaPagamento.getCupom())) {
250
                                preencherDados(vendaFormaPagamento);
251
                        }
252
                }
253
 
254
                List<CartaoResumoDTO> resumosPorDia = new ArrayList<CartaoResumoDTO>();
255
                        Date dataSelecionada = getCartaoResumoGeral().getDataInicialVendasSelecionada();
256
                        while (DataUtils.dataEstaIgualOuEntrePeriodos(dataSelecionada, DataUtils.getDataComHorarioMinimo(getCartaoResumoGeral().getDataInicialVendasSelecionada()), DataUtils.getDataComHorarioMinimo(getCartaoResumoGeral().getDataFinalVendasSelecionada()))) {
257
                                CartaoResumoDTO resumoPorDia = new CartaoResumoDTO();
258
                                resumoPorDia.setDataResumo(dataSelecionada);
259
                                for (CartaoBandeiraDTO cartaoPorBandeira : cartaoResumo.getCartoesPorBandeira()) {
260
                                        if (DataUtils.dataEstaIgualOuEntrePeriodos(cartaoPorBandeira.getData(), DataUtils.getDataComHorarioMinimo(dataSelecionada), DataUtils.getDataComHorarioMaximo(dataSelecionada))) {
261
                                                resumoPorDia.getCartoesPorBandeira().add(cartaoPorBandeira);
262
                                        }
263
                                }
264
                                dataSelecionada = DataUtils.acrescentarDias(dataSelecionada, 1);
265
                                resumoPorDia.somarValores();
266
                                resumosPorDia.add(resumoPorDia);
267
                        }
268
                        cartaoResumo.setCartoesPorBandeira((List<CartaoBandeiraDTO>) ordenador.ordenar(cartaoResumo.getCartoesPorBandeira()));
269
                        getCartaoResumoGeral().setCartoesResumo(resumosPorDia);
270
                } catch (Exception e) {
271
                        throw new NegocioException(e.getMessage());
272
                } finally {
273
                        cartaoResumo.setCartoesPorBandeira((List<CartaoBandeiraDTO>) ordenador.ordenar(cartaoResumo.getCartoesPorBandeira()));
274
                }
275
        }
276
 
277
        private void arquivoBancoRede(Date dataInicial, Date dataFinal, List<Maquineta> maquinetasSelecionadas, Boolean indicadorVerificarMaquinetas) {
278
                for (String linha : getLinhas()) {
279
                        Boolean adicionar = true;
280
                String[] dadosSeparados = linha.split(";");
281
                Date dataLinha = DataUtil.retornarDataApartirString("dd/MM/yyyy hh:mm:ss", dadosSeparados[0] + " " + dadosSeparados[1]);
282
                if (DataUtils.dataEstaIgualOuEntrePeriodos(DataUtil.retornarDataFormatada("dd/MM/yyyy", dataLinha), dataInicial, dataFinal)) {
283
                        if (indicadorVerificarMaquinetas) {
284
                                if (!maquinetasSelecionadas.isEmpty()) {
285
                                        for (Maquineta maquinetaSelecionada : maquinetasSelecionadas) {
286
                                                adicionar = false;
287
                                                String maquineta = dadosSeparados[19];
288
                                                if (maquinetaSelecionada.getDescricao().equals(maquineta)) {
289
                                                        adicionar = true;
290
                                                        break;
291
                                                }
292
                                        }
293
                                }
294
                        }
295
                        if (adicionar) {
296
                                        CartaoDTO cartao = new CartaoDTO();
297
                                        cartao.setBandeira(StringUtil.setarUpperCaseComTrim(dadosSeparados[5]));
298
                                FormaPagamento formaPagamento = null;
299
                                String bandeira = StringUtil.setarUpperCaseComTrim(dadosSeparados[4]);
300
                                String tipoCartao = null;
301
                                if (bandeira.equals("DÉBITO") || bandeira.equals("DéBITO")) {
302
                                        tipoCartao = TipoCartao.DEBITO.getValor();
303
                                        formaPagamento = new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DEBITO);
304
                                        if (cartao.getBandeira().equals("MASTERCARD")) {
305
                                                cartao.setBandeira("MAESTRO");
306
                                        }
307
                                } else {
308
                                        tipoCartao = TipoCartao.CREDITO.getValor();
309
                                        String parcelas = dadosSeparados[3];
310
                                        formaPagamento = new FormaPagamento(FormaPagamento.recuperarCodigoDaFormaDePagamento(parcelas));
311
                                }
312
                                cartao.setBrutoImportado(new Double(dadosSeparados[2].replace(".", "").replace(",", ".")));
313
                                preencherDadosArquivo(dataLinha, cartao, formaPagamento, tipoCartao);
314
                        }
315
                        }
316
                }
317
        }
318
 
319
        private void arquivoBancoSafra(Date dataInicial, Date dataFinal) {
320
                for (String linha : getLinhas()) {
321
                String[] dadosSeparados = linha.split(";");
322
                Date dataLinha = DataUtil.retornarDataApartirString("dd/MM/yyyy hh.mm.ss", dadosSeparados[4] + " " + dadosSeparados[5]);
323
                if (DataUtils.dataEstaIgualOuEntrePeriodos(DataUtil.retornarDataFormatada("dd/MM/yyyy", dataLinha), dataInicial, dataFinal)) {
324
                                CartaoDTO cartao = new CartaoDTO();
325
                                cartao.setBandeira(StringUtil.setarUpperCaseComTrim(dadosSeparados[7]));
326
                        FormaPagamento formaPagamento = null;
327
                        String bandeira = StringUtil.setarUpperCaseComTrim(dadosSeparados[9]);
328
                        String tipoCartao = null;
329
                        if (bandeira.equals("00")) {
330
                                tipoCartao = TipoCartao.DEBITO.getValor();
331
                                formaPagamento = new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DEBITO);
332
                                if (cartao.getBandeira().equals("MASTERCARD")) {
333
                                        cartao.setBandeira("MAESTRO");
334
                                }
335
                        } else {
336
                                String parcelas = "";
337
                                if (bandeira.substring(0, 1).equals("0")) {
338
                                        parcelas = dadosSeparados[9].substring(1);
339
                                } else {
340
                                        parcelas = dadosSeparados[9];
341
                                }
342
                                tipoCartao = TipoCartao.CREDITO.getValor();
343
                                formaPagamento = new FormaPagamento(FormaPagamento.recuperarCodigoDaFormaDePagamento(parcelas));
344
                        }
345
                        cartao.setBrutoImportado(new Double(dadosSeparados[11].replace(".", "").replace(",", ".")));
346
                        preencherDadosArquivo(dataLinha, cartao, formaPagamento, tipoCartao);
347
                        }
348
                }
349
        }
350
 
351
        private void preencherDadosArquivo(Date data, CartaoDTO cartao, FormaPagamento formaPagamento, String tipoCartao) {
352
                cartao.setFormaDePagamento(formaPagamentoService.consultarPorId(formaPagamento));
353
                if (VerificadorUtil.naoEstaNulo(cartao.getBandeira())) {
354
                        if (cartao.getBandeira().equals("AMEX")) {
355
                                cartao.setBandeira("AMERICAN EXPRESS");
356
                        }
357
                        if (cartao.getBandeira().equals("HIPC")) {
358
                                cartao.setBandeira("HIPERCARD");
359
                        }
360
                }
361
 
362
                CartaoBandeiraDTO cartaoFormaDePagamento = new CartaoBandeiraDTO();
363
                cartaoFormaDePagamento.setBandeira(bandeiraCartaoService.consultarBandeiraCartoao(cartao.getBandeira(), tipoCartao));
364
                if (VerificadorUtil.estaNulo(cartaoFormaDePagamento.getBandeira())) {
365
                        cartaoFormaDePagamento.setBandeira(bandeiraCartaoService.consultarBandeiraCartoao("OUTROS", tipoCartao));
366
                }
367
                cartaoFormaDePagamento.setBrutoImportado(cartao.getBrutoImportado());
368
                cartaoFormaDePagamento.setFormaPagamento(cartao.getFormaDePagamento());
369
                cartaoFormaDePagamento.setData(DataUtil.retornarDataFormatada("dd/MM/yyyy", data));
370
                cartaoResumo.adicionarPagamentoImportado(cartaoFormaDePagamento);
371
        }
372
 
373
        private void preencherDados(VendaFormaPagamento vendaFormaPagamento) {
374
                CartaoBandeiraDTO cartaoFormaDePagamento = new CartaoBandeiraDTO();
375
                cartaoFormaDePagamento.setBandeira(vendaFormaPagamento.getBandeiraCartao());
376
                cartaoFormaDePagamento.setBruto(vendaFormaPagamento.getValorPagamento());
377
                cartaoFormaDePagamento.setFormaPagamento(vendaFormaPagamento.getFormaPagamento());
378
                cartaoFormaDePagamento.setData(DataUtil.retornarDataFormatada("dd/MM/yyyy", vendaFormaPagamento.getVenda().getDataVenda()));
379
                cartaoResumo.adicionarPagamento(cartaoFormaDePagamento);
380
        }
381
 
382
        public void verificarLancamentos() {
383
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
384
                        public void execute() {
385
                                limparEntidade();
386
                                List<VendaFormaPagamento> preLancamentos = new ArrayList<VendaFormaPagamento>();
387
                                preLancamentos = vendaFormaPagamentoService.consultarLancamentosCartoesNoPeriodo(dataVendas, dataVendas, null, getMaquinetasSelecionadas());
388
                                setListaVendaFormaPagamento(preLancamentos);
389
 
390
                                cartoes = new ArrayList<CartaoDTO>();
391
                                cartaoResumo = new CartaoResumoDTO();
392
                                for (VendaFormaPagamento vendaFormaPagamento : preLancamentos) {
393
                                        if (VerificadorUtil.estaNulo(vendaFormaPagamento.getCupom())) {
394
                                                CartaoDTO cartao = new CartaoDTO();
395
                                                cartao.setBandeira(vendaFormaPagamento.getBandeiraCartao().getDescricao());
396
                                                cartao.setFormaDePagamento(vendaFormaPagamento.getFormaPagamento());
397
                                                cartao.setBruto(vendaFormaPagamento.getValorPagamento());
398
                                                cartao.setDataVenda(vendaFormaPagamento.getVenda().getDataVenda());
399
 
400
                                                if (parcelaService.verificarPossuiParcelaAberta(vendaFormaPagamento.getVenda())) {
401
                                                        cartao.setParcelaGerada(true);
402
                                                        cartao.setGerarParcela(false);
403
                                                } else {
404
                                                        cartao.setParcelaGerada(false);
405
                                                        cartao.setGerarParcela(true);
406
                                                }
407
                                                cartao.setVendaFormaPagamento(vendaFormaPagamento);
408
                                                cartoes.add(cartao);
409
 
410
                                                CartaoBandeiraDTO cartaoFormaDePagamento = new CartaoBandeiraDTO();
411
                                                cartaoFormaDePagamento.setBandeira(vendaFormaPagamento.getBandeiraCartao());
412
                                                cartaoFormaDePagamento.setBruto(vendaFormaPagamento.getValorPagamento());
413
                                                cartaoFormaDePagamento.setFormaPagamento(vendaFormaPagamento.getFormaPagamento());
414
                                                cartaoResumo.adicionarPagamento(cartaoFormaDePagamento);
415
                                        }
416
                                }
417
                                cartoes = (List<CartaoDTO>) ordenador.ordenar(cartoes);
418
                                cartaoResumo.setCartoesPorBandeira((List<CartaoBandeiraDTO>) ordenador.ordenar(cartaoResumo.getCartoesPorBandeira()));
419
                        }
420
                });
421
        }
422
 
423
        public void consultarLancamentos() {
424
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
425
                        public void execute() {
426
                                limparEntidade();
427
                                List<CartaoDTO> cartoesGerados = parcelaService.consultarContasDosCartoes(dataVendas, dataVendas);
428
                                adicionarDatasGeradas(cartoesGerados);
429
                                setCartoesGerados(cartoesGerados);
430
                                LancadorMensagem.lancarSucesso("PARCELAS GERADAS COM SUCESSO");
431
                        }
432
                });
433
        }
434
 
435
        public void gerarLancamentos() {
436
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
437
                        public void execute() {
438
                                listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>();
439
                                for (CartaoDTO cartao : cartoes) {
440
                                        if (cartao.getGerarParcela()) {
441
                                                listaVendaFormaPagamento.add(cartao.getVendaFormaPagamento());
442
                                        }
443
                                }
444
                                limparEntidade();
445
                                List<CartaoDTO> cartoesGerados = parcelaService.gerarContasDosCartoes(listaVendaFormaPagamento);
446
                                adicionarDatasGeradas(cartoesGerados);
447
                                setCartoesGerados(cartoesGerados);
448
                                LancadorMensagem.lancarSucesso("PARCELAS GERADAS COM SUCESSO");
449
                        }
450
 
451
                });
452
        }
453
 
454
        private void adicionarDatasGeradas(List<CartaoDTO> cartoesGerados) {
455
                listaDatas = new ArrayList<CartaoDataDTO>();
456
                for (CartaoDTO cartaoGerado : cartoesGerados) {
457
                        CartaoDataDTO cartaoDataDTO = new CartaoDataDTO();
458
                        cartaoDataDTO.setDataVenda(DateUtils.truncate(cartaoGerado.getParcela().getDataVencimento(), Calendar.DATE));
459
                        cartaoDataDTO.setDataNovaVenda(DateUtils.truncate(cartaoGerado.getParcela().getDataVencimento(), Calendar.DATE));
460
                        boolean adicionar = true;
461
                        for (CartaoDataDTO dataAdicionada : listaDatas) {
462
                                if (dataAdicionada.getDataVenda().equals(cartaoDataDTO.getDataVenda())) {
463
                                        adicionar = false;
464
                                        break;
465
                                }
466
                        }
467
                        if (adicionar) {
468
                                listaDatas.add(cartaoDataDTO);
469
                        }
470
                }
471
        }
472
 
473
        public void atualizarDatasCartoes() {
474
                for (CartaoDTO cartaoGerado : getCartoesGerados()) {
475
                        for (CartaoDataDTO dataAdicionada : getListaDatas()) {
476
                                Date dataTruncada = DateUtils.truncate(cartaoGerado.getParcela().getDataVencimento(), Calendar.DATE);
477
                                if (dataAdicionada.getDataVenda().equals(dataTruncada)) {
478
                                        Date novaData = atualizarParaNovaData(cartaoGerado.getParcela().getDataVencimento(), dataAdicionada.getDataNovaVenda());
479
                                        cartaoGerado.getParcela().setDataVencimento(novaData);
480
                                }
481
                        }
482
                }
483
                adicionarDatasGeradas(getCartoesGerados());
484
                salvarAlteracoesCartoes();
485
        }
486
 
487
        private Date atualizarParaNovaData(Date data, Date novaData) {
488
            Calendar c = Calendar.getInstance();
489
            c.setTime(data);
490
 
491
            Calendar cal = Calendar.getInstance();
492
            cal.setTime(novaData);
493
            c.set(Calendar.DATE, cal.get(Calendar.DATE));
494
            c.set(Calendar.MONTH, cal.get(Calendar.MONTH));
495
            c.set(Calendar.YEAR, cal.get(Calendar.YEAR));
496
            return c.getTime();
497
        }
498
 
499
        public void salvarAlteracoesCartoes() {
500
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
501
                        public void execute() {
502
                                for (CartaoDTO cartao : getCartoesGerados()) {
503
                                        parcelaService.alterar(cartao.getParcela());
504
                                }
505
                                LancadorMensagem.lancarSucesso("PARCELAS ATUALIZADAS COM SUCESSO");
506
                        }
507
                });
508
        }
509
 
510
        /*
511
    public static void main(String[] args) throws Exception {
512
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\arquivo.csv")));
513
        String linha = reader.readLine();
514
 
515
        List<CartaoDTO> cartoes = new ArrayList<CartaoDTO>();
516
                CartaoResumoDTO cartaoResumo = new CartaoResumoDTO();
517
                Double valorTotalBrutoCartoes = new Double(0.0);
518
        while ((linha = reader.readLine()) != null) {
519
                String[] dadosSeparados = linha.split(";");
520
                        CartaoDTO cartao = new CartaoDTO();
521
                        cartao.setBandeira(StringUtil.setarUpperCaseComTrim(dadosSeparados[5]));
522
                FormaPagamento formaPagamento = null;
523
                String bandeira = StringUtil.setarUpperCaseComTrim(dadosSeparados[4]);
524
                String tipoCartao = null;
525
                if (bandeira.equals("DÉBITO")) {
526
                        tipoCartao = TipoCartao.DEBITO.getValor();
527
                        formaPagamento = new FormaPagamento(ConstantesSEC.FormasDePagamento.FORMAPAGAMENTO_DEBITO);
528
                } else {
529
                        tipoCartao = TipoCartao.CREDITO.getValor();
530
                        String parcelas = dadosSeparados[3];
531
                        formaPagamento = new FormaPagamento(FormaPagamento.recuperarCodigoDaFormaDePagamento(parcelas));
532
                }
533
                cartao.setFormaDePagamento(formaPagamento);
534
                        cartao.setBruto(new Double(dadosSeparados[2]));
535
                        cartao.setDataVenda(DataUtil.retornarDataApartirString("dd/MM/yyyy", dadosSeparados[0]));
536
 
537
                        cartoes.add(cartao);
538
//                              somarValoresBruto(vendaFormaPagamento.getValorPagamento(), vendaFormaPagamento.getFormaPagamento());
539
//                              somarValoresBruto(cartao.getBruto(), cartao.getFormaDePagamento());
540
 
541
                        CartaoBandeiraDTO cartaoFormaDePagamento = new CartaoBandeiraDTO();
542
 
543
                        BandeiraCartao bandeiraCartao = bandeiraCartaoService.consultarBandeiraCartoao(cartao.getBandeira(), tipoCartao);
544
                        cartaoFormaDePagamento.setBandeira(bandeiraCartao);
545
                        cartaoFormaDePagamento.setBruto(cartao.getBruto());
546
                        cartaoFormaDePagamento.setFormaPagamento(cartao.getFormaDePagamento());
547
                        cartaoResumo.adicionarPagamento(cartaoFormaDePagamento);
548
                }
549
        reader.close();
550
//            System.out.println(Arrays.toString(dadosSeparados));
551
//            System.out.println("Nome: " + dadosSeparados[0]);
552
//            System.out.println("País: " + dadosSeparados[1]);
553
//            System.out.println("Fórum: " + dadosSeparados[2]);
554
//            System.out.println("--------------------------");
555
    }
556
        */
557
        /***************************************************************/
558
 
559
}