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