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