Rev 732 | Go to most recent revision | 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; |
| 55 | private String tituloEmail = "CONTRACHEQUE"; |
||
| 434 | espaco | 56 | private Date dataPagamento = new Date(); |
| 430 | espaco | 57 | |
| 439 | espaco | 58 | private ParcelaService parcelaService; |
| 427 | espaco | 59 | |
| 424 | blopes | 60 | private AvaliacaoConsultaPorDemanda lazy; |
| 61 | private ParametrosConsulta<Avaliacao> parametrosConsultaAvaliacao; |
||
| 62 | |||
| 63 | @Inject |
||
| 648 | blopes | 64 | public FolhaPagamentoBean(AvaliacaoConsultaPorDemanda lazy, FolhaPagamentoService folhaPagamentoService, VigenciaService vigenciaService, |
| 65 | AvaliacaoService avaliacaoService, ParcelaService parcelaService) { |
||
| 424 | blopes | 66 | this.lazy = lazy; |
| 427 | espaco | 67 | this.folhaPagamentoService = folhaPagamentoService; |
| 648 | blopes | 68 | this.vigenciaService= vigenciaService; |
| 69 | this.avaliacaoService = avaliacaoService; |
||
| 439 | espaco | 70 | this.parcelaService = parcelaService; |
| 424 | blopes | 71 | } |
| 72 | |||
| 73 | @Override |
||
| 74 | public void preCarregamento() { |
||
| 75 | parametrosConsultaAvaliacao = new ParametrosConsulta<Avaliacao>(); |
||
| 76 | parametrosConsultaAvaliacao.setEntidade(new Avaliacao()); |
||
| 77 | prepararConsultaDemanda(); |
||
| 78 | limparEntidade(); |
||
| 79 | } |
||
| 648 | blopes | 80 | |
| 81 | @PostConstruct |
||
| 82 | private void posCarregamento() { |
||
| 698 | blopes | 83 | if (VerificadorUtil.naoEstaNulo(getParametro("vigencia"))) { |
| 84 | setVigenciaSelecionada(vigenciaService.consultarVigencia(new Long(getParametro("vigencia").toString()))); |
||
| 85 | if (VerificadorUtil.naoEstaNulo(getVigenciaSelecionada())) { |
||
| 86 | detalharFolhaPagamento(); |
||
| 648 | blopes | 87 | } |
| 88 | } |
||
| 698 | blopes | 89 | } |
| 90 | |||
| 91 | private void detalharFolhaPagamento() { |
||
| 648 | blopes | 92 | AvaliacaoDTO avaliacaoDTO = avaliacaoService.consultarAvaliacao(getVigenciaSelecionada().getSequencial()); |
| 93 | if (VerificadorUtil.naoEstaNulo(avaliacaoDTO)) { |
||
| 94 | setFolhaPagamentoDTO(folhaPagamentoService.detalharFolhaPagamento(avaliacaoDTO)); |
||
| 95 | } |
||
| 96 | } |
||
| 424 | blopes | 97 | |
| 98 | @Override |
||
| 99 | public void limparEntidade() { |
||
| 100 | setEntidade(new Avaliacao()); |
||
| 101 | } |
||
| 102 | |||
| 103 | @Override |
||
| 104 | public GenericService<Avaliacao> getService() { |
||
| 427 | espaco | 105 | return folhaPagamentoService; |
| 424 | blopes | 106 | } |
| 107 | |||
| 108 | @Override |
||
| 109 | public Avaliacao getEntidade() { |
||
| 110 | return entidade; |
||
| 111 | } |
||
| 112 | |||
| 113 | @Override |
||
| 114 | public void preConsultar() { |
||
| 115 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 116 | } |
||
| 429 | espaco | 117 | |
| 118 | @Override |
||
| 119 | public void preAlterar(Avaliacao avaliacao) { |
||
| 120 | super.preAlterar(avaliacao); |
||
| 430 | espaco | 121 | setFolhaPagamentoDTO(folhaPagamentoService.detalharFolhaPagamento(new AvaliacaoDTO(avaliacao.getSequencial(), avaliacao.getSequencialDaVigencia(), avaliacao.getDescricaoDaVigencia()))); |
| 429 | espaco | 122 | } |
| 424 | blopes | 123 | |
| 124 | @Override |
||
| 125 | public Avaliacao getId() { |
||
| 126 | return getEntidade(); |
||
| 127 | } |
||
| 128 | |||
| 129 | public AvaliacaoConsultaPorDemanda getLazy() { |
||
| 130 | return lazy; |
||
| 131 | } |
||
| 132 | public void setLazy(AvaliacaoConsultaPorDemanda lazy) { |
||
| 133 | this.lazy = lazy; |
||
| 134 | } |
||
| 135 | public void prepararConsultaDemanda() { |
||
| 136 | lazy.setarParametrosConsulta(getParametrosConsultaAvaliacao()); |
||
| 137 | } |
||
| 138 | |||
| 139 | public ParametrosConsulta<Avaliacao> getParametrosConsultaAvaliacao() { |
||
| 140 | return parametrosConsultaAvaliacao; |
||
| 141 | } |
||
| 142 | public void setParametrosConsultaAvaliacao(ParametrosConsulta<Avaliacao> parametrosConsultaAvaliacao) { |
||
| 143 | this.parametrosConsultaAvaliacao = parametrosConsultaAvaliacao; |
||
| 144 | } |
||
| 145 | |||
| 429 | espaco | 146 | public FolhaPagamentoDTO getFolhaPagamentoDTO() { |
| 147 | return folhaPagamentoDTO; |
||
| 148 | } |
||
| 149 | public void setFolhaPagamentoDTO(FolhaPagamentoDTO folhaPagamentoDTO) { |
||
| 150 | this.folhaPagamentoDTO = folhaPagamentoDTO; |
||
| 151 | } |
||
| 152 | |||
| 648 | blopes | 153 | public VigenciaDTO getVigenciaSelecionada() { |
| 154 | return vigenciaSelecionada; |
||
| 155 | } |
||
| 156 | public void setVigenciaSelecionada(VigenciaDTO vigenciaSelecionada) { |
||
| 157 | this.vigenciaSelecionada = vigenciaSelecionada; |
||
| 158 | } |
||
| 159 | |||
| 430 | espaco | 160 | public UploadedFile getArquivoParaImportacao() { |
| 161 | return arquivoParaImportacao; |
||
| 162 | } |
||
| 163 | public void setArquivoParaImportacao(UploadedFile arquivoParaImportacao) { |
||
| 164 | this.arquivoParaImportacao = arquivoParaImportacao; |
||
| 165 | } |
||
| 166 | |||
| 167 | public String getTituloEmail() { |
||
| 168 | return tituloEmail; |
||
| 169 | } |
||
| 170 | public void setTituloEmail(String tituloEmail) { |
||
| 171 | this.tituloEmail = tituloEmail; |
||
| 172 | } |
||
| 173 | |||
| 434 | espaco | 174 | public Date getDataPagamento() { |
| 175 | return dataPagamento; |
||
| 176 | } |
||
| 177 | public void setDataPagamento(Date dataPagamento) { |
||
| 178 | this.dataPagamento = dataPagamento; |
||
| 179 | } |
||
| 180 | |||
| 553 | blopes | 181 | public List<FolhaPagamentoFuncionarioExtraidoDTO> funcionariosExtraidosForaDaAvaliacao() { |
| 182 | List<FolhaPagamentoFuncionarioExtraidoDTO> extraidosForaDaAvaliacao = new ArrayList<FolhaPagamentoFuncionarioExtraidoDTO>(); |
||
| 740 | blopes | 183 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO())) { |
| 184 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO().getFuncionariosExtraidos())) { |
||
| 185 | for (FolhaPagamentoFuncionarioExtraidoDTO extraido : getFolhaPagamentoDTO().getFuncionariosExtraidos()) { |
||
| 186 | if (!extraido.getAdicionado()) { |
||
| 187 | extraidosForaDaAvaliacao.add(extraido); |
||
| 188 | } |
||
| 553 | blopes | 189 | } |
| 190 | } |
||
| 191 | } |
||
| 192 | return extraidosForaDaAvaliacao; |
||
| 193 | } |
||
| 194 | |||
| 717 | blopes | 195 | public Double valorTotalImportadoSemAusentes() { |
| 196 | Double valorTotalForaDaAvaliacao = new Double(0.0); |
||
| 197 | List<FolhaPagamentoFuncionarioExtraidoDTO> extraidosForaDaAvaliacao = new ArrayList<FolhaPagamentoFuncionarioExtraidoDTO>(); |
||
| 198 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO().getFuncionariosExtraidos())) { |
||
| 199 | for (FolhaPagamentoFuncionarioExtraidoDTO extraido : getFolhaPagamentoDTO().getFuncionariosExtraidos()) { |
||
| 200 | if (!extraido.getAdicionado()) { |
||
| 201 | valorTotalForaDaAvaliacao += extraido.getValorVencimentos(); |
||
| 202 | extraidosForaDaAvaliacao.add(extraido); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | return getFolhaPagamentoDTO().getValorTotalImportado() - valorTotalForaDaAvaliacao; |
||
| 206 | } |
||
| 207 | return valorTotalForaDaAvaliacao; |
||
| 208 | } |
||
| 209 | |||
| 424 | blopes | 210 | /**************************************************/ |
| 211 | |||
| 648 | blopes | 212 | public void redirecionarGestaoMensal() { |
| 213 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 214 | public void execute() { |
||
| 215 | try { |
||
| 216 | LancadorMensagem.redirecionarTela("/sistema/gestao_mensal/gestao_mensal.xhtml"); |
||
| 217 | } catch (IOException e) { |
||
| 218 | e.printStackTrace(); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | }); |
||
| 222 | } |
||
| 223 | |||
| 430 | espaco | 224 | public void uploadArquivoEspacoCase() { |
| 225 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 226 | public void execute() { |
||
| 227 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(getArquivoParaImportacao().getContent(), getFolhaPagamentoDTO())); |
||
| 439 | espaco | 228 | setTituloEmail(getTituloEmail() + " " + getFolhaPagamentoDTO().getAvaliacaoDTO().getVigenciaDTO().getDescricao()); |
| 430 | espaco | 229 | LancadorMensagem.lancarSucesso("ARQUIVO IMPORTADO COM SUCESSO!"); |
| 230 | } |
||
| 231 | }); |
||
| 232 | } |
||
| 233 | |||
| 234 | public void selecionarTodosParaEnviarEmail() { |
||
| 235 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 236 | public void execute() { |
||
| 237 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 238 | if (folhaPagamentoFuncionario.getEnviarEmail()) { |
||
| 239 | folhaPagamentoFuncionario.setEnviarEmail(false); |
||
| 240 | } else { |
||
| 241 | folhaPagamentoFuncionario.setEnviarEmail(true); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | } |
||
| 245 | }); |
||
| 246 | } |
||
| 247 | |||
| 248 | public void uploadArquivoEspacoCase(final FileUploadEvent e) { |
||
| 249 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 250 | public void execute() { |
||
| 251 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(e.getFile().getContent(), getFolhaPagamentoDTO())); |
||
| 252 | } |
||
| 253 | }); |
||
| 254 | } |
||
| 255 | |||
| 256 | public void atualizarValoresImportados() { |
||
| 257 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 258 | public void execute() { |
||
| 259 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 260 | if (VerificadorUtil.naoEstaNulo(folhaPagamentoFuncionario.getValorSalarioImportado()) && |
||
| 439 | espaco | 261 | !VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
| 262 | folhaPagamentoFuncionario.getParcelas().get(0).setValor(folhaPagamentoFuncionario.getValorSalarioImportado()); |
||
| 263 | folhaPagamentoService.atualizarValorParcela(folhaPagamentoFuncionario.getParcelas().get(0)); |
||
| 430 | espaco | 264 | } |
| 265 | } |
||
| 266 | LancadorMensagem.lancarSucesso("VALORES ATUALIZADOS COM SUCESSO"); |
||
| 267 | } |
||
| 268 | }); |
||
| 269 | } |
||
| 270 | |||
| 721 | blopes | 271 | public void atualizarCentrosDeCustos() { |
| 272 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 273 | public void execute() { |
||
| 274 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 722 | blopes | 275 | if (!VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
| 721 | blopes | 276 | if (VerificadorUtil.naoEstaNulo(folhaPagamentoFuncionario.getParcelas().get(0))) { |
| 277 | ParcelaDTO parcela = folhaPagamentoFuncionario.getParcelas().get(0); |
||
| 278 | Long sequencialConta = parcela.getContaDTO().getSequencial(); |
||
| 279 | folhaPagamentoService.atualizarCentroDeCustos(sequencialConta, folhaPagamentoFuncionario.getAvaliacaoFuncionarioDTO().getSequencialDaLoja()); |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | detalharFolhaPagamento(); |
||
| 722 | blopes | 284 | setArquivoParaImportacao(null); |
| 285 | LancadorMensagem.lancarSucesso("CENTROS DE CUSTOS ATUALIZADOS COM SUCESSO"); |
||
| 721 | blopes | 286 | } |
| 287 | }); |
||
| 288 | } |
||
| 289 | |||
| 434 | espaco | 290 | public void efetuarPagamentos() { |
| 291 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 292 | public void execute() { |
||
| 439 | espaco | 293 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
| 294 | if (!VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
||
| 295 | parcelaService.efetuarPagamentoRecebimento(folhaPagamentoFuncionario.getParcelas().get(0), getDataPagamento()); |
||
| 698 | blopes | 296 | vigenciaService.alterarSituacaoFolha(getVigenciaSelecionada().getSequencial(), TipoSituacoesVigencia.EM_ANDAMENTO_A.getValor()); |
| 439 | espaco | 297 | } |
| 298 | } |
||
| 722 | blopes | 299 | detalharFolhaPagamento(); |
| 439 | espaco | 300 | setArquivoParaImportacao(null); |
| 434 | espaco | 301 | LancadorMensagem.lancarSucesso("PAGAMENTOS EFETUADOS COM SUCESSO"); |
| 302 | } |
||
| 303 | }); |
||
| 304 | } |
||
| 305 | |||
| 698 | blopes | 306 | public void finalizarFolhaPagamento() { |
| 307 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 308 | public void execute() { |
||
| 309 | vigenciaService.alterarSituacaoFolha(getVigenciaSelecionada().getSequencial(), TipoSituacoesVigencia.FINALIZADO_F.getValor()); |
||
| 310 | setArquivoParaImportacao(null); |
||
| 311 | redirecionarGestaoMensal(); |
||
| 312 | LancadorMensagem.lancarSucesso("FOLHA DE PAGAMENTO FINALIZADA COM SUCESSO"); |
||
| 313 | } |
||
| 314 | }); |
||
| 315 | } |
||
| 316 | |||
| 430 | espaco | 317 | public StreamedContent downloadRecibos() throws Exception { |
| 318 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 319 | @Override |
||
| 320 | public StreamedContent execute() { |
||
| 439 | espaco | 321 | return folhaPagamentoService.downloadRecibos(getFolhaPagamentoDTO()); |
| 430 | espaco | 322 | } |
| 323 | }); |
||
| 324 | } |
||
| 325 | |||
| 439 | espaco | 326 | public void enviarRecibos() throws Exception { |
| 327 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 328 | public void execute() { |
||
| 329 | folhaPagamentoService.enviarRecibosPorEmail(getFolhaPagamentoDTO(), getTituloEmail()); |
||
| 330 | LancadorMensagem.lancarSucesso("RECIBOS ENVIADOS COM SUCESSO!"); |
||
| 331 | } |
||
| 332 | }); |
||
| 333 | } |
||
| 334 | |||
| 335 | public StreamedContent downloadArquivoFolhaBanco(String codigoBanco) throws Exception { |
||
| 430 | espaco | 336 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
| 337 | @Override |
||
| 338 | public StreamedContent execute() { |
||
| 439 | espaco | 339 | return folhaPagamentoService.downloadArquivoFolhaBanco(getFolhaPagamentoDTO(), codigoBanco); |
| 430 | espaco | 340 | } |
| 341 | }); |
||
| 342 | } |
||
| 343 | |||
| 424 | blopes | 344 | } |