Rev 669 | Rev 671 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 667 | blopes | 1 | package br.com.ec.controller; |
| 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.List; |
||
| 9 | |||
| 10 | import javax.inject.Inject; |
||
| 11 | import javax.inject.Named; |
||
| 12 | |||
| 13 | import org.primefaces.model.file.UploadedFile; |
||
| 14 | import org.springframework.context.annotation.Scope; |
||
| 15 | |||
| 16 | import br.com.ec.core.exception.NegocioException; |
||
| 17 | import br.com.ec.core.generic.GenericService; |
||
| 18 | import br.com.ec.core.util.DataUtils; |
||
| 19 | import br.com.ec.core.util.VerificadorUtil; |
||
| 20 | import br.com.ec.domain.dto.AntecipacaoDTO; |
||
| 21 | import br.com.ec.domain.dto.ConciliacaoBancariaDTO; |
||
| 22 | import br.com.ec.domain.dto.ConciliacaoBancariaLancamentoDTO; |
||
| 23 | import br.com.ec.domain.dto.ConciliacaoBancariaLancamentoDetalhadoDTO; |
||
| 24 | import br.com.ec.domain.dto.ExtratoAntecipacaoArquivoDTO; |
||
| 25 | import br.com.ec.domain.dto.ExtratoBancarioArquivoDTO; |
||
| 26 | import br.com.ec.domain.dto.ExtratoBancoDTO; |
||
| 27 | import br.com.ec.domain.model.tipos.TipoExtratoBancarioCsv; |
||
| 28 | import br.com.ec.domain.model.tipos.TipoExtratoBanco; |
||
| 29 | import br.com.ec.domain.service.ConciliacaoBancariaService; |
||
| 30 | import br.com.ec.domain.service.ExtratoBancoService; |
||
| 669 | blopes | 31 | import br.com.ec.domain.service.ParcelaService; |
| 667 | blopes | 32 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 33 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 34 | import br.com.ec.web.generic.AbstractBean; |
||
| 35 | import br.com.ec.web.message.LancadorMensagem; |
||
| 36 | |||
| 37 | @Named |
||
| 38 | @Scope("view") |
||
| 39 | public class AntecipacaoBean extends AbstractBean<AntecipacaoDTO> implements Serializable { |
||
| 40 | |||
| 41 | private static final long serialVersionUID = 1L; |
||
| 42 | |||
| 43 | private UploadedFile arquivoParaAntecipacao; |
||
| 44 | |||
| 45 | private ConciliacaoBancariaService conciliacaoBancariaService; |
||
| 669 | blopes | 46 | private ParcelaService parcelaService; |
| 667 | blopes | 47 | private ExtratoBancoService extratoBancoService; |
| 48 | |||
| 49 | @Inject |
||
| 669 | blopes | 50 | public AntecipacaoBean(ConciliacaoBancariaService conciliacaoBancariaService, ParcelaService parcelaService, ExtratoBancoService extratoBancoService) { |
| 667 | blopes | 51 | this.conciliacaoBancariaService = conciliacaoBancariaService; |
| 669 | blopes | 52 | this.parcelaService = parcelaService; |
| 667 | blopes | 53 | this.extratoBancoService = extratoBancoService; |
| 54 | } |
||
| 55 | |||
| 56 | @Override |
||
| 57 | public GenericService<AntecipacaoDTO> getService() { |
||
| 58 | return null; |
||
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | public AntecipacaoDTO getId() { |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | @Override |
||
| 67 | public void preCarregamento() { |
||
| 68 | limparEntidade(); |
||
| 69 | } |
||
| 70 | |||
| 71 | @Override |
||
| 72 | public void limparEntidade() { |
||
| 73 | setEntidade(new AntecipacaoDTO()); |
||
| 74 | } |
||
| 75 | |||
| 76 | public UploadedFile getArquivoParaAntecipacao() { |
||
| 77 | return arquivoParaAntecipacao; |
||
| 78 | } |
||
| 79 | public void setArquivoParaAntecipacao(UploadedFile arquivoParaAntecipacao) { |
||
| 80 | this.arquivoParaAntecipacao = arquivoParaAntecipacao; |
||
| 81 | } |
||
| 82 | |||
| 83 | public TipoExtratoBancarioCsv[] getTiposExtratosBancariosCsv() { |
||
| 84 | return TipoExtratoBancarioCsv.values(); |
||
| 85 | } |
||
| 86 | |||
| 87 | public TipoExtratoBanco[] getTiposExtratoBanco() { |
||
| 88 | return TipoExtratoBanco.values(); |
||
| 89 | } |
||
| 90 | |||
| 91 | /*******************************************/ |
||
| 92 | |||
| 93 | public void uploadArquivoAntecipacao() { |
||
| 94 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 95 | public void execute() { |
||
| 96 | ExtratoAntecipacaoArquivoDTO extratoAntecipacaoArquivoDTO = conciliacaoBancariaService.uploadArquivoAntecipacao(getArquivoParaAntecipacao()); |
||
| 669 | blopes | 97 | conciliacaoBancariaService.conciliarAntecipacao(extratoAntecipacaoArquivoDTO); |
| 670 | blopes | 98 | getEntidade().setExtratoAntecipacaoArquivoDTO(extratoAntecipacaoArquivoDTO); |
| 667 | blopes | 99 | LancadorMensagem.lancarSucesso("ARQUIVO IMPORTADO COM SUCESSO!"); |
| 100 | } |
||
| 101 | }); |
||
| 102 | } |
||
| 103 | |||
| 104 | public void removerArquivoExtratoBancarioAnexado(final ExtratoBancarioArquivoDTO extratoBancarioArquivoDTO) { |
||
| 105 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 106 | public void execute() { |
||
| 107 | // extratoBancarioArquivoDTO.setDadosExtratoBancoSemCategoriaDTO(new ArrayList<ExtratoBancoDTO>()); |
||
| 108 | // getEntidade().getArquivosExtratoBancarioParaCadastrarDTO().remove(extratoBancarioArquivoDTO); |
||
| 109 | LancadorMensagem.lancarSucesso("ARQUIVO REMOVIDO COM SUCESSO"); |
||
| 110 | } |
||
| 111 | }); |
||
| 112 | } |
||
| 113 | |||
| 114 | public void cadastrarExtratosSelecionados(final ExtratoBancarioArquivoDTO extratoBancarioArquivoDTO) { |
||
| 115 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 116 | public void execute() { |
||
| 117 | // extratoBancoService.cadastrarExtratosBancariosAnexado(extratoBancarioArquivoDTO); |
||
| 118 | // getEntidade().getArquivosExtratoBancarioParaCadastrarDTO().remove(extratoBancarioArquivoDTO); |
||
| 119 | // consultarConciliacaoBancaria(); |
||
| 120 | LancadorMensagem.lancarSucesso("EXTRATO BANCÁRIO CADASTRADO COM SUCESSO"); |
||
| 121 | } |
||
| 122 | }); |
||
| 123 | } |
||
| 124 | |||
| 125 | public void excluirExtratosSelecionados(final ExtratoBancarioArquivoDTO extratoBancarioArquivoDTO) { |
||
| 126 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 127 | public void execute() { |
||
| 128 | // extratoBancoService.excluirExtratosBancariosSelecionados(extratoBancarioArquivoDTO); |
||
| 129 | // getEntidade().getArquivosExtratoBancarioParaCadastrarDTO().remove(extratoBancarioArquivoDTO); |
||
| 130 | // consultarConciliacaoBancaria(); |
||
| 131 | LancadorMensagem.lancarSucesso("EXTRATO BANCÁRIO CADASTRADO COM SUCESSO"); |
||
| 132 | } |
||
| 133 | }); |
||
| 134 | } |
||
| 135 | |||
| 136 | /*******************************************/ |
||
| 137 | |||
| 138 | public void atualizarObservacaoPagamentos(final ConciliacaoBancariaLancamentoDTO conciliacaoBancariaLancamentoDTO) { |
||
| 139 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 140 | public void execute() { |
||
| 141 | // conciliacaoBancariaService.atualizarObservacaoPagamentos(conciliacaoBancariaLancamentoDTO); |
||
| 142 | LancadorMensagem.lancarSucesso("CONCILIAÇÃO ATUALIZADA COM SUCESSO"); |
||
| 143 | } |
||
| 144 | }); |
||
| 145 | } |
||
| 146 | |||
| 147 | public void conciliar(final ConciliacaoBancariaLancamentoDTO conciliacaoBancariaLancamentoDTO) { |
||
| 148 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 149 | public void execute() { |
||
| 150 | // conciliacaoBancariaService.realizarConciliacao(conciliacaoBancariaLancamentoDTO); |
||
| 151 | // consultarConciliacaoBancaria(); |
||
| 152 | LancadorMensagem.lancarSucesso("CONCILIAÇÃO REALIZADA COM SUCESSO"); |
||
| 153 | } |
||
| 154 | }); |
||
| 155 | } |
||
| 156 | |||
| 157 | public void conciliarExtratosComArquivos(final ConciliacaoBancariaLancamentoDTO conciliacaoBancariaLancamentoDTO) { |
||
| 158 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 159 | public void execute() { |
||
| 160 | // if (VerificadorUtil.estaNulo(getEntidade().getVigenciaDTO())) { |
||
| 161 | // throw new NegocioException("SELECIONE A VIGÊNCIA"); |
||
| 162 | // } |
||
| 163 | // List<ConciliacaoBancariaLancamentoDTO> conciliacoes = new ArrayList<ConciliacaoBancariaLancamentoDTO>(); |
||
| 164 | // conciliacoes.add(conciliacaoBancariaLancamentoDTO); |
||
| 165 | // extratoBancoService.conciliarExtratosComArquivos(conciliacoes); |
||
| 166 | // consultarConciliacaoBancaria(); |
||
| 167 | LancadorMensagem.lancarSucesso("EXTRATOS ATUALIZADOS COM SUCESSO"); |
||
| 168 | } |
||
| 169 | }); |
||
| 170 | } |
||
| 171 | |||
| 172 | public void prepararAlterarExtratoSelecionado(final ExtratoBancoDTO extratoBancoDTO) { |
||
| 173 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 174 | public void execute() { |
||
| 175 | // setExtratoBancoDTOParaAlterar(extratoBancoDTO); |
||
| 176 | } |
||
| 177 | }); |
||
| 178 | } |
||
| 179 | |||
| 180 | public void removerExtratoSelecionado() { |
||
| 181 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 182 | public void execute() { |
||
| 183 | // extratoBancoService.excluirDadoExtratoBancoSelecionado(getExtratoBancoDTOParaAlterar()); |
||
| 184 | // consultarConciliacaoBancaria(); |
||
| 185 | LancadorMensagem.lancarSucesso("DADO DO EXTRATO BANCÁRIO EXCLUÍDO COM SUCESSO"); |
||
| 186 | } |
||
| 187 | }); |
||
| 188 | } |
||
| 189 | |||
| 190 | public void atualizarDadoExtratoBanco() { |
||
| 191 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 192 | public void execute() { |
||
| 193 | // extratoBancoService.alterarDadosExtratoBanco(getExtratoBancoDTOParaAlterar()); |
||
| 194 | LancadorMensagem.lancarSucesso("DADO DO EXTRATO BANCÁRIO ATUALIZADO COM SUCESSO"); |
||
| 195 | } |
||
| 196 | }); |
||
| 197 | } |
||
| 198 | |||
| 199 | /* |
||
| 200 | public void atualizarDadosArquivosExtratoBancario(final ConciliacaoBancariaLancamentoDTO conciliacaoBancariaLancamentoDTO) { |
||
| 201 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 202 | public void execute() { |
||
| 203 | if (VerificadorUtil.estaNulo(getEntidade().getVigenciaDTO())) { |
||
| 204 | throw new NegocioException("SELECIONE A VIGÊNCIA"); |
||
| 205 | } |
||
| 206 | extratoBancoService.atualizarExtratosAnexados(getEntidade()); |
||
| 207 | //consultarConciliacaoBancaria(); |
||
| 208 | LancadorMensagem.lancarSucesso("EXTRATOS ATUALIZADOS COM SUCESSO"); |
||
| 209 | } |
||
| 210 | }); |
||
| 211 | } |
||
| 212 | */ |
||
| 213 | |||
| 214 | public List<String> extrairLinhasArquivo(UploadedFile arquivo) { |
||
| 215 | BufferedReader reader = null; |
||
| 216 | List<String> linhas = new ArrayList<String>(); |
||
| 217 | try { |
||
| 218 | reader = new BufferedReader(new InputStreamReader(arquivo.getInputStream())); |
||
| 219 | String linha = reader.readLine(); |
||
| 220 | linha = reader.readLine(); |
||
| 221 | linha = reader.readLine(); |
||
| 222 | while ((linha = reader.readLine()) != null) { |
||
| 223 | linhas.add(linha); |
||
| 224 | } |
||
| 225 | } catch (Exception ex) { |
||
| 226 | ex.printStackTrace(); |
||
| 227 | } finally { |
||
| 228 | try { |
||
| 229 | reader.close(); |
||
| 230 | } catch (IOException exc) { |
||
| 231 | exc.printStackTrace(); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | return linhas; |
||
| 235 | } |
||
| 236 | |||
| 237 | /*******************************************************/ |
||
| 238 | |||
| 239 | } |