Rev 740 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 424 | blopes | 1 | package br.com.ec.controller; |
| 2 | |||
| 648 | blopes | 3 | import java.io.IOException; |
| 424 | blopes | 4 | import java.io.Serializable; |
| 553 | blopes | 5 | import java.util.ArrayList; |
| 434 | espaco | 6 | import java.util.Date; |
| 553 | blopes | 7 | import java.util.List; |
| 424 | blopes | 8 | |
| 648 | blopes | 9 | import javax.annotation.PostConstruct; |
| 424 | blopes | 10 | import javax.inject.Inject; |
| 11 | import javax.inject.Named; |
||
| 12 | |||
| 430 | espaco | 13 | import org.primefaces.event.FileUploadEvent; |
| 14 | import org.primefaces.model.StreamedContent; |
||
| 15 | import org.primefaces.model.file.UploadedFile; |
||
| 424 | blopes | 16 | import org.springframework.context.annotation.Scope; |
| 17 | |||
| 18 | import br.com.ec.controller.consultademanda.AvaliacaoConsultaPorDemanda; |
||
| 19 | import br.com.ec.core.consulta.ParametrosConsulta; |
||
| 20 | import br.com.ec.core.generic.GenericService; |
||
| 430 | espaco | 21 | import br.com.ec.core.util.VerificadorUtil; |
| 22 | import br.com.ec.domain.dto.AvaliacaoDTO; |
||
| 429 | espaco | 23 | import br.com.ec.domain.dto.FolhaPagamentoDTO; |
| 430 | espaco | 24 | import br.com.ec.domain.dto.FolhaPagamentoFuncionarioDTO; |
| 553 | blopes | 25 | import br.com.ec.domain.dto.FolhaPagamentoFuncionarioExtraidoDTO; |
| 721 | blopes | 26 | import br.com.ec.domain.dto.ParcelaDTO; |
| 648 | blopes | 27 | import br.com.ec.domain.dto.VigenciaDTO; |
| 424 | blopes | 28 | import br.com.ec.domain.model.Avaliacao; |
| 698 | blopes | 29 | import br.com.ec.domain.model.tipos.TipoSituacoesVigencia; |
| 648 | blopes | 30 | import br.com.ec.domain.service.AvaliacaoService; |
| 427 | espaco | 31 | import br.com.ec.domain.service.FolhaPagamentoService; |
| 439 | espaco | 32 | import br.com.ec.domain.service.ParcelaService; |
| 648 | blopes | 33 | import br.com.ec.domain.service.VigenciaService; |
| 424 | blopes | 34 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 35 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 430 | espaco | 36 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandRelatorioStreamedContent; |
| 424 | blopes | 37 | import br.com.ec.web.generic.AbstractBean; |
| 430 | espaco | 38 | import br.com.ec.web.message.LancadorMensagem; |
| 424 | blopes | 39 | import br.com.ec.web.util.TipoOperacao; |
| 40 | |||
| 41 | @Named |
||
| 42 | @Scope("view") |
||
| 43 | public class FolhaPagamentoBean extends AbstractBean<Avaliacao> implements Serializable { |
||
| 44 | |||
| 45 | private static final long serialVersionUID = 1L; |
||
| 46 | |||
| 429 | espaco | 47 | private FolhaPagamentoDTO folhaPagamentoDTO; |
| 648 | blopes | 48 | private VigenciaDTO vigenciaSelecionada; |
| 429 | espaco | 49 | |
| 648 | blopes | 50 | private FolhaPagamentoService folhaPagamentoService; |
| 51 | private VigenciaService vigenciaService; |
||
| 52 | private AvaliacaoService avaliacaoService; |
||
| 53 | |||
| 430 | espaco | 54 | private UploadedFile arquivoParaImportacao; |
| 742 | blopes | 55 | private List<byte[]> arquivosImportados; |
| 56 | |||
| 430 | espaco | 57 | private String tituloEmail = "CONTRACHEQUE"; |
| 434 | espaco | 58 | private Date dataPagamento = new Date(); |
| 430 | espaco | 59 | |
| 439 | espaco | 60 | private ParcelaService parcelaService; |
| 427 | espaco | 61 | |
| 424 | blopes | 62 | private AvaliacaoConsultaPorDemanda lazy; |
| 63 | private ParametrosConsulta<Avaliacao> parametrosConsultaAvaliacao; |
||
| 64 | |||
| 65 | @Inject |
||
| 648 | blopes | 66 | public FolhaPagamentoBean(AvaliacaoConsultaPorDemanda lazy, FolhaPagamentoService folhaPagamentoService, VigenciaService vigenciaService, |
| 67 | AvaliacaoService avaliacaoService, ParcelaService parcelaService) { |
||
| 424 | blopes | 68 | this.lazy = lazy; |
| 427 | espaco | 69 | this.folhaPagamentoService = folhaPagamentoService; |
| 648 | blopes | 70 | this.vigenciaService= vigenciaService; |
| 71 | this.avaliacaoService = avaliacaoService; |
||
| 439 | espaco | 72 | this.parcelaService = parcelaService; |
| 424 | blopes | 73 | } |
| 74 | |||
| 75 | @Override |
||
| 76 | public void preCarregamento() { |
||
| 77 | parametrosConsultaAvaliacao = new ParametrosConsulta<Avaliacao>(); |
||
| 78 | parametrosConsultaAvaliacao.setEntidade(new Avaliacao()); |
||
| 79 | prepararConsultaDemanda(); |
||
| 80 | limparEntidade(); |
||
| 81 | } |
||
| 648 | blopes | 82 | |
| 83 | @PostConstruct |
||
| 84 | private void posCarregamento() { |
||
| 698 | blopes | 85 | if (VerificadorUtil.naoEstaNulo(getParametro("vigencia"))) { |
| 86 | setVigenciaSelecionada(vigenciaService.consultarVigencia(new Long(getParametro("vigencia").toString()))); |
||
| 87 | if (VerificadorUtil.naoEstaNulo(getVigenciaSelecionada())) { |
||
| 88 | detalharFolhaPagamento(); |
||
| 648 | blopes | 89 | } |
| 90 | } |
||
| 698 | blopes | 91 | } |
| 92 | |||
| 93 | private void detalharFolhaPagamento() { |
||
| 648 | blopes | 94 | AvaliacaoDTO avaliacaoDTO = avaliacaoService.consultarAvaliacao(getVigenciaSelecionada().getSequencial()); |
| 95 | if (VerificadorUtil.naoEstaNulo(avaliacaoDTO)) { |
||
| 96 | setFolhaPagamentoDTO(folhaPagamentoService.detalharFolhaPagamento(avaliacaoDTO)); |
||
| 97 | } |
||
| 742 | blopes | 98 | if (VerificadorUtil.naoEstaNuloOuVazio(getArquivosImportados())) { |
| 99 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(getArquivosImportados(), getFolhaPagamentoDTO())); |
||
| 100 | } |
||
| 648 | blopes | 101 | } |
| 424 | blopes | 102 | |
| 103 | @Override |
||
| 104 | public void limparEntidade() { |
||
| 105 | setEntidade(new Avaliacao()); |
||
| 106 | } |
||
| 107 | |||
| 108 | @Override |
||
| 109 | public GenericService<Avaliacao> getService() { |
||
| 427 | espaco | 110 | return folhaPagamentoService; |
| 424 | blopes | 111 | } |
| 112 | |||
| 113 | @Override |
||
| 114 | public Avaliacao getEntidade() { |
||
| 115 | return entidade; |
||
| 116 | } |
||
| 117 | |||
| 118 | @Override |
||
| 119 | public void preConsultar() { |
||
| 120 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 121 | } |
||
| 429 | espaco | 122 | |
| 123 | @Override |
||
| 124 | public void preAlterar(Avaliacao avaliacao) { |
||
| 125 | super.preAlterar(avaliacao); |
||
| 430 | espaco | 126 | setFolhaPagamentoDTO(folhaPagamentoService.detalharFolhaPagamento(new AvaliacaoDTO(avaliacao.getSequencial(), avaliacao.getSequencialDaVigencia(), avaliacao.getDescricaoDaVigencia()))); |
| 429 | espaco | 127 | } |
| 424 | blopes | 128 | |
| 129 | @Override |
||
| 130 | public Avaliacao getId() { |
||
| 131 | return getEntidade(); |
||
| 132 | } |
||
| 133 | |||
| 134 | public AvaliacaoConsultaPorDemanda getLazy() { |
||
| 135 | return lazy; |
||
| 136 | } |
||
| 137 | public void setLazy(AvaliacaoConsultaPorDemanda lazy) { |
||
| 138 | this.lazy = lazy; |
||
| 139 | } |
||
| 140 | public void prepararConsultaDemanda() { |
||
| 141 | lazy.setarParametrosConsulta(getParametrosConsultaAvaliacao()); |
||
| 142 | } |
||
| 143 | |||
| 144 | public ParametrosConsulta<Avaliacao> getParametrosConsultaAvaliacao() { |
||
| 145 | return parametrosConsultaAvaliacao; |
||
| 146 | } |
||
| 147 | public void setParametrosConsultaAvaliacao(ParametrosConsulta<Avaliacao> parametrosConsultaAvaliacao) { |
||
| 148 | this.parametrosConsultaAvaliacao = parametrosConsultaAvaliacao; |
||
| 149 | } |
||
| 150 | |||
| 429 | espaco | 151 | public FolhaPagamentoDTO getFolhaPagamentoDTO() { |
| 152 | return folhaPagamentoDTO; |
||
| 153 | } |
||
| 154 | public void setFolhaPagamentoDTO(FolhaPagamentoDTO folhaPagamentoDTO) { |
||
| 155 | this.folhaPagamentoDTO = folhaPagamentoDTO; |
||
| 156 | } |
||
| 157 | |||
| 648 | blopes | 158 | public VigenciaDTO getVigenciaSelecionada() { |
| 159 | return vigenciaSelecionada; |
||
| 160 | } |
||
| 161 | public void setVigenciaSelecionada(VigenciaDTO vigenciaSelecionada) { |
||
| 162 | this.vigenciaSelecionada = vigenciaSelecionada; |
||
| 163 | } |
||
| 164 | |||
| 430 | espaco | 165 | public UploadedFile getArquivoParaImportacao() { |
| 166 | return arquivoParaImportacao; |
||
| 167 | } |
||
| 168 | public void setArquivoParaImportacao(UploadedFile arquivoParaImportacao) { |
||
| 169 | this.arquivoParaImportacao = arquivoParaImportacao; |
||
| 170 | } |
||
| 171 | |||
| 742 | blopes | 172 | public List<byte[]> getArquivosImportados() { |
| 173 | return arquivosImportados; |
||
| 174 | } |
||
| 175 | public void setArquivosImportados(List<byte[]> arquivosImportados) { |
||
| 176 | this.arquivosImportados = arquivosImportados; |
||
| 177 | } |
||
| 178 | |||
| 430 | espaco | 179 | public String getTituloEmail() { |
| 180 | return tituloEmail; |
||
| 181 | } |
||
| 182 | public void setTituloEmail(String tituloEmail) { |
||
| 183 | this.tituloEmail = tituloEmail; |
||
| 184 | } |
||
| 185 | |||
| 434 | espaco | 186 | public Date getDataPagamento() { |
| 187 | return dataPagamento; |
||
| 188 | } |
||
| 189 | public void setDataPagamento(Date dataPagamento) { |
||
| 190 | this.dataPagamento = dataPagamento; |
||
| 191 | } |
||
| 192 | |||
| 553 | blopes | 193 | public List<FolhaPagamentoFuncionarioExtraidoDTO> funcionariosExtraidosForaDaAvaliacao() { |
| 194 | List<FolhaPagamentoFuncionarioExtraidoDTO> extraidosForaDaAvaliacao = new ArrayList<FolhaPagamentoFuncionarioExtraidoDTO>(); |
||
| 740 | blopes | 195 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO())) { |
| 196 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO().getFuncionariosExtraidos())) { |
||
| 197 | for (FolhaPagamentoFuncionarioExtraidoDTO extraido : getFolhaPagamentoDTO().getFuncionariosExtraidos()) { |
||
| 198 | if (!extraido.getAdicionado()) { |
||
| 199 | extraidosForaDaAvaliacao.add(extraido); |
||
| 200 | } |
||
| 553 | blopes | 201 | } |
| 202 | } |
||
| 203 | } |
||
| 204 | return extraidosForaDaAvaliacao; |
||
| 205 | } |
||
| 206 | |||
| 717 | blopes | 207 | public Double valorTotalImportadoSemAusentes() { |
| 208 | Double valorTotalForaDaAvaliacao = new Double(0.0); |
||
| 209 | List<FolhaPagamentoFuncionarioExtraidoDTO> extraidosForaDaAvaliacao = new ArrayList<FolhaPagamentoFuncionarioExtraidoDTO>(); |
||
| 210 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO().getFuncionariosExtraidos())) { |
||
| 211 | for (FolhaPagamentoFuncionarioExtraidoDTO extraido : getFolhaPagamentoDTO().getFuncionariosExtraidos()) { |
||
| 212 | if (!extraido.getAdicionado()) { |
||
| 213 | valorTotalForaDaAvaliacao += extraido.getValorVencimentos(); |
||
| 214 | extraidosForaDaAvaliacao.add(extraido); |
||
| 215 | } |
||
| 216 | } |
||
| 217 | return getFolhaPagamentoDTO().getValorTotalImportado() - valorTotalForaDaAvaliacao; |
||
| 218 | } |
||
| 219 | return valorTotalForaDaAvaliacao; |
||
| 220 | } |
||
| 221 | |||
| 424 | blopes | 222 | /**************************************************/ |
| 223 | |||
| 648 | blopes | 224 | public void redirecionarGestaoMensal() { |
| 225 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 226 | public void execute() { |
||
| 227 | try { |
||
| 228 | LancadorMensagem.redirecionarTela("/sistema/gestao_mensal/gestao_mensal.xhtml"); |
||
| 229 | } catch (IOException e) { |
||
| 230 | e.printStackTrace(); |
||
| 231 | } |
||
| 232 | } |
||
| 233 | }); |
||
| 234 | } |
||
| 235 | |||
| 430 | espaco | 236 | public void uploadArquivoEspacoCase() { |
| 237 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 238 | public void execute() { |
||
| 742 | blopes | 239 | setArquivosImportados(folhaPagamentoService.uploadArquivo(getArquivoParaImportacao().getContent())); |
| 240 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(getArquivosImportados(), getFolhaPagamentoDTO())); |
||
| 439 | espaco | 241 | setTituloEmail(getTituloEmail() + " " + getFolhaPagamentoDTO().getAvaliacaoDTO().getVigenciaDTO().getDescricao()); |
| 430 | espaco | 242 | LancadorMensagem.lancarSucesso("ARQUIVO IMPORTADO COM SUCESSO!"); |
| 243 | } |
||
| 244 | }); |
||
| 245 | } |
||
| 246 | |||
| 742 | blopes | 247 | public void uploadArquivoEspacoCase(final FileUploadEvent e) { |
| 248 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 249 | public void execute() { |
||
| 250 | setArquivosImportados(folhaPagamentoService.uploadArquivo(e.getFile().getContent())); |
||
| 251 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(getArquivosImportados(), getFolhaPagamentoDTO())); |
||
| 252 | } |
||
| 253 | }); |
||
| 254 | } |
||
| 255 | |||
| 430 | espaco | 256 | public void selecionarTodosParaEnviarEmail() { |
| 257 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 258 | public void execute() { |
||
| 259 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 260 | if (folhaPagamentoFuncionario.getEnviarEmail()) { |
||
| 261 | folhaPagamentoFuncionario.setEnviarEmail(false); |
||
| 262 | } else { |
||
| 263 | folhaPagamentoFuncionario.setEnviarEmail(true); |
||
| 264 | } |
||
| 265 | } |
||
| 266 | } |
||
| 267 | }); |
||
| 268 | } |
||
| 269 | |||
| 270 | public void atualizarValoresImportados() { |
||
| 271 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 272 | public void execute() { |
||
| 273 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 274 | if (VerificadorUtil.naoEstaNulo(folhaPagamentoFuncionario.getValorSalarioImportado()) && |
||
| 439 | espaco | 275 | !VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
| 276 | folhaPagamentoFuncionario.getParcelas().get(0).setValor(folhaPagamentoFuncionario.getValorSalarioImportado()); |
||
| 277 | folhaPagamentoService.atualizarValorParcela(folhaPagamentoFuncionario.getParcelas().get(0)); |
||
| 430 | espaco | 278 | } |
| 279 | } |
||
| 280 | LancadorMensagem.lancarSucesso("VALORES ATUALIZADOS COM SUCESSO"); |
||
| 281 | } |
||
| 282 | }); |
||
| 283 | } |
||
| 284 | |||
| 721 | blopes | 285 | public void atualizarCentrosDeCustos() { |
| 286 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 287 | public void execute() { |
||
| 288 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 722 | blopes | 289 | if (!VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
| 721 | blopes | 290 | if (VerificadorUtil.naoEstaNulo(folhaPagamentoFuncionario.getParcelas().get(0))) { |
| 291 | ParcelaDTO parcela = folhaPagamentoFuncionario.getParcelas().get(0); |
||
| 292 | Long sequencialConta = parcela.getContaDTO().getSequencial(); |
||
| 293 | folhaPagamentoService.atualizarCentroDeCustos(sequencialConta, folhaPagamentoFuncionario.getAvaliacaoFuncionarioDTO().getSequencialDaLoja()); |
||
| 294 | } |
||
| 295 | } |
||
| 296 | } |
||
| 297 | detalharFolhaPagamento(); |
||
| 722 | blopes | 298 | LancadorMensagem.lancarSucesso("CENTROS DE CUSTOS ATUALIZADOS COM SUCESSO"); |
| 721 | blopes | 299 | } |
| 300 | }); |
||
| 301 | } |
||
| 302 | |||
| 434 | espaco | 303 | public void efetuarPagamentos() { |
| 304 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 305 | public void execute() { |
||
| 439 | espaco | 306 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
| 307 | if (!VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
||
| 308 | parcelaService.efetuarPagamentoRecebimento(folhaPagamentoFuncionario.getParcelas().get(0), getDataPagamento()); |
||
| 698 | blopes | 309 | vigenciaService.alterarSituacaoFolha(getVigenciaSelecionada().getSequencial(), TipoSituacoesVigencia.EM_ANDAMENTO_A.getValor()); |
| 439 | espaco | 310 | } |
| 311 | } |
||
| 722 | blopes | 312 | detalharFolhaPagamento(); |
| 434 | espaco | 313 | LancadorMensagem.lancarSucesso("PAGAMENTOS EFETUADOS COM SUCESSO"); |
| 314 | } |
||
| 315 | }); |
||
| 316 | } |
||
| 317 | |||
| 698 | blopes | 318 | public void finalizarFolhaPagamento() { |
| 319 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 320 | public void execute() { |
||
| 321 | vigenciaService.alterarSituacaoFolha(getVigenciaSelecionada().getSequencial(), TipoSituacoesVigencia.FINALIZADO_F.getValor()); |
||
| 322 | setArquivoParaImportacao(null); |
||
| 323 | redirecionarGestaoMensal(); |
||
| 324 | LancadorMensagem.lancarSucesso("FOLHA DE PAGAMENTO FINALIZADA COM SUCESSO"); |
||
| 325 | } |
||
| 326 | }); |
||
| 327 | } |
||
| 328 | |||
| 430 | espaco | 329 | public StreamedContent downloadRecibos() throws Exception { |
| 330 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 331 | @Override |
||
| 332 | public StreamedContent execute() { |
||
| 439 | espaco | 333 | return folhaPagamentoService.downloadRecibos(getFolhaPagamentoDTO()); |
| 430 | espaco | 334 | } |
| 335 | }); |
||
| 336 | } |
||
| 337 | |||
| 742 | blopes | 338 | public void enviarRecibosSeparadamente() throws Exception { |
| 439 | espaco | 339 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
| 340 | public void execute() { |
||
| 341 | folhaPagamentoService.enviarRecibosPorEmail(getFolhaPagamentoDTO(), getTituloEmail()); |
||
| 342 | LancadorMensagem.lancarSucesso("RECIBOS ENVIADOS COM SUCESSO!"); |
||
| 343 | } |
||
| 344 | }); |
||
| 345 | } |
||
| 346 | |||
| 347 | public StreamedContent downloadArquivoFolhaBanco(String codigoBanco) throws Exception { |
||
| 430 | espaco | 348 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
| 349 | @Override |
||
| 350 | public StreamedContent execute() { |
||
| 439 | espaco | 351 | return folhaPagamentoService.downloadArquivoFolhaBanco(getFolhaPagamentoDTO(), codigoBanco); |
| 430 | espaco | 352 | } |
| 353 | }); |
||
| 354 | } |
||
| 355 | |||
| 424 | blopes | 356 | } |