Rev 439 | Rev 648 | 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 | |||
| 3 | import java.io.Serializable; |
||
| 553 | blopes | 4 | import java.util.ArrayList; |
| 434 | espaco | 5 | import java.util.Date; |
| 553 | blopes | 6 | import java.util.List; |
| 424 | blopes | 7 | |
| 8 | import javax.inject.Inject; |
||
| 9 | import javax.inject.Named; |
||
| 10 | |||
| 430 | espaco | 11 | import org.primefaces.event.FileUploadEvent; |
| 12 | import org.primefaces.model.StreamedContent; |
||
| 13 | import org.primefaces.model.file.UploadedFile; |
||
| 424 | blopes | 14 | import org.springframework.context.annotation.Scope; |
| 15 | |||
| 16 | import br.com.ec.controller.consultademanda.AvaliacaoConsultaPorDemanda; |
||
| 17 | import br.com.ec.core.consulta.ParametrosConsulta; |
||
| 18 | import br.com.ec.core.generic.GenericService; |
||
| 430 | espaco | 19 | import br.com.ec.core.util.VerificadorUtil; |
| 20 | import br.com.ec.domain.dto.AvaliacaoDTO; |
||
| 429 | espaco | 21 | import br.com.ec.domain.dto.FolhaPagamentoDTO; |
| 430 | espaco | 22 | import br.com.ec.domain.dto.FolhaPagamentoFuncionarioDTO; |
| 553 | blopes | 23 | import br.com.ec.domain.dto.FolhaPagamentoFuncionarioExtraidoDTO; |
| 424 | blopes | 24 | import br.com.ec.domain.model.Avaliacao; |
| 427 | espaco | 25 | import br.com.ec.domain.service.FolhaPagamentoService; |
| 439 | espaco | 26 | import br.com.ec.domain.service.ParcelaService; |
| 424 | blopes | 27 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 28 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 430 | espaco | 29 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandRelatorioStreamedContent; |
| 424 | blopes | 30 | import br.com.ec.web.generic.AbstractBean; |
| 430 | espaco | 31 | import br.com.ec.web.message.LancadorMensagem; |
| 424 | blopes | 32 | import br.com.ec.web.util.TipoOperacao; |
| 33 | |||
| 34 | @Named |
||
| 35 | @Scope("view") |
||
| 36 | public class FolhaPagamentoBean extends AbstractBean<Avaliacao> implements Serializable { |
||
| 37 | |||
| 38 | private static final long serialVersionUID = 1L; |
||
| 39 | |||
| 429 | espaco | 40 | private FolhaPagamentoDTO folhaPagamentoDTO; |
| 41 | |||
| 430 | espaco | 42 | private UploadedFile arquivoParaImportacao; |
| 43 | private String tituloEmail = "CONTRACHEQUE"; |
||
| 434 | espaco | 44 | private Date dataPagamento = new Date(); |
| 430 | espaco | 45 | |
| 427 | espaco | 46 | private FolhaPagamentoService folhaPagamentoService; |
| 439 | espaco | 47 | private ParcelaService parcelaService; |
| 427 | espaco | 48 | |
| 424 | blopes | 49 | private AvaliacaoConsultaPorDemanda lazy; |
| 50 | private ParametrosConsulta<Avaliacao> parametrosConsultaAvaliacao; |
||
| 51 | |||
| 52 | @Inject |
||
| 439 | espaco | 53 | public FolhaPagamentoBean(AvaliacaoConsultaPorDemanda lazy, FolhaPagamentoService folhaPagamentoService, ParcelaService parcelaService) { |
| 424 | blopes | 54 | this.lazy = lazy; |
| 427 | espaco | 55 | this.folhaPagamentoService = folhaPagamentoService; |
| 439 | espaco | 56 | this.parcelaService = parcelaService; |
| 424 | blopes | 57 | } |
| 58 | |||
| 59 | @Override |
||
| 60 | public void preCarregamento() { |
||
| 61 | parametrosConsultaAvaliacao = new ParametrosConsulta<Avaliacao>(); |
||
| 62 | parametrosConsultaAvaliacao.setEntidade(new Avaliacao()); |
||
| 63 | prepararConsultaDemanda(); |
||
| 64 | limparEntidade(); |
||
| 65 | } |
||
| 66 | |||
| 67 | @Override |
||
| 68 | public void limparEntidade() { |
||
| 69 | setEntidade(new Avaliacao()); |
||
| 70 | } |
||
| 71 | |||
| 72 | @Override |
||
| 73 | public GenericService<Avaliacao> getService() { |
||
| 427 | espaco | 74 | return folhaPagamentoService; |
| 424 | blopes | 75 | } |
| 76 | |||
| 77 | @Override |
||
| 78 | public Avaliacao getEntidade() { |
||
| 79 | return entidade; |
||
| 80 | } |
||
| 81 | |||
| 82 | @Override |
||
| 83 | public void preConsultar() { |
||
| 84 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 85 | } |
||
| 429 | espaco | 86 | |
| 87 | @Override |
||
| 88 | public void preAlterar(Avaliacao avaliacao) { |
||
| 89 | super.preAlterar(avaliacao); |
||
| 430 | espaco | 90 | setFolhaPagamentoDTO(folhaPagamentoService.detalharFolhaPagamento(new AvaliacaoDTO(avaliacao.getSequencial(), avaliacao.getSequencialDaVigencia(), avaliacao.getDescricaoDaVigencia()))); |
| 429 | espaco | 91 | } |
| 424 | blopes | 92 | |
| 93 | @Override |
||
| 94 | public Avaliacao getId() { |
||
| 95 | return getEntidade(); |
||
| 96 | } |
||
| 97 | |||
| 98 | public AvaliacaoConsultaPorDemanda getLazy() { |
||
| 99 | return lazy; |
||
| 100 | } |
||
| 101 | public void setLazy(AvaliacaoConsultaPorDemanda lazy) { |
||
| 102 | this.lazy = lazy; |
||
| 103 | } |
||
| 104 | public void prepararConsultaDemanda() { |
||
| 105 | lazy.setarParametrosConsulta(getParametrosConsultaAvaliacao()); |
||
| 106 | } |
||
| 107 | |||
| 108 | public ParametrosConsulta<Avaliacao> getParametrosConsultaAvaliacao() { |
||
| 109 | return parametrosConsultaAvaliacao; |
||
| 110 | } |
||
| 111 | public void setParametrosConsultaAvaliacao(ParametrosConsulta<Avaliacao> parametrosConsultaAvaliacao) { |
||
| 112 | this.parametrosConsultaAvaliacao = parametrosConsultaAvaliacao; |
||
| 113 | } |
||
| 114 | |||
| 429 | espaco | 115 | public FolhaPagamentoDTO getFolhaPagamentoDTO() { |
| 116 | return folhaPagamentoDTO; |
||
| 117 | } |
||
| 118 | public void setFolhaPagamentoDTO(FolhaPagamentoDTO folhaPagamentoDTO) { |
||
| 119 | this.folhaPagamentoDTO = folhaPagamentoDTO; |
||
| 120 | } |
||
| 121 | |||
| 430 | espaco | 122 | public UploadedFile getArquivoParaImportacao() { |
| 123 | return arquivoParaImportacao; |
||
| 124 | } |
||
| 125 | public void setArquivoParaImportacao(UploadedFile arquivoParaImportacao) { |
||
| 126 | this.arquivoParaImportacao = arquivoParaImportacao; |
||
| 127 | } |
||
| 128 | |||
| 129 | public String getTituloEmail() { |
||
| 130 | return tituloEmail; |
||
| 131 | } |
||
| 132 | public void setTituloEmail(String tituloEmail) { |
||
| 133 | this.tituloEmail = tituloEmail; |
||
| 134 | } |
||
| 135 | |||
| 434 | espaco | 136 | public Date getDataPagamento() { |
| 137 | return dataPagamento; |
||
| 138 | } |
||
| 139 | public void setDataPagamento(Date dataPagamento) { |
||
| 140 | this.dataPagamento = dataPagamento; |
||
| 141 | } |
||
| 142 | |||
| 553 | blopes | 143 | public List<FolhaPagamentoFuncionarioExtraidoDTO> funcionariosExtraidosForaDaAvaliacao() { |
| 144 | List<FolhaPagamentoFuncionarioExtraidoDTO> extraidosForaDaAvaliacao = new ArrayList<FolhaPagamentoFuncionarioExtraidoDTO>(); |
||
| 145 | if (VerificadorUtil.naoEstaNuloOuVazio(getFolhaPagamentoDTO().getFuncionariosExtraidos())) { |
||
| 146 | for (FolhaPagamentoFuncionarioExtraidoDTO extraido : getFolhaPagamentoDTO().getFuncionariosExtraidos()) { |
||
| 147 | if (!extraido.getAdicionado()) { |
||
| 148 | extraidosForaDaAvaliacao.add(extraido); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | return extraidosForaDaAvaliacao; |
||
| 153 | } |
||
| 154 | |||
| 424 | blopes | 155 | /**************************************************/ |
| 156 | |||
| 430 | espaco | 157 | public void uploadArquivoEspacoCase() { |
| 158 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 159 | public void execute() { |
||
| 160 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(getArquivoParaImportacao().getContent(), getFolhaPagamentoDTO())); |
||
| 439 | espaco | 161 | setTituloEmail(getTituloEmail() + " " + getFolhaPagamentoDTO().getAvaliacaoDTO().getVigenciaDTO().getDescricao()); |
| 430 | espaco | 162 | LancadorMensagem.lancarSucesso("ARQUIVO IMPORTADO COM SUCESSO!"); |
| 163 | } |
||
| 164 | }); |
||
| 165 | } |
||
| 166 | |||
| 167 | public void selecionarTodosParaEnviarEmail() { |
||
| 168 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 169 | public void execute() { |
||
| 170 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 171 | if (folhaPagamentoFuncionario.getEnviarEmail()) { |
||
| 172 | folhaPagamentoFuncionario.setEnviarEmail(false); |
||
| 173 | } else { |
||
| 174 | folhaPagamentoFuncionario.setEnviarEmail(true); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | }); |
||
| 179 | } |
||
| 180 | |||
| 181 | public void uploadArquivoEspacoCase(final FileUploadEvent e) { |
||
| 182 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 183 | public void execute() { |
||
| 184 | setFolhaPagamentoDTO(folhaPagamentoService.importarFolhaPagamento(e.getFile().getContent(), getFolhaPagamentoDTO())); |
||
| 185 | } |
||
| 186 | }); |
||
| 187 | } |
||
| 188 | |||
| 189 | public void atualizarValoresImportados() { |
||
| 190 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 191 | public void execute() { |
||
| 192 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
||
| 193 | if (VerificadorUtil.naoEstaNulo(folhaPagamentoFuncionario.getValorSalarioImportado()) && |
||
| 439 | espaco | 194 | !VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
| 195 | folhaPagamentoFuncionario.getParcelas().get(0).setValor(folhaPagamentoFuncionario.getValorSalarioImportado()); |
||
| 196 | folhaPagamentoService.atualizarValorParcela(folhaPagamentoFuncionario.getParcelas().get(0)); |
||
| 430 | espaco | 197 | } |
| 198 | } |
||
| 199 | LancadorMensagem.lancarSucesso("VALORES ATUALIZADOS COM SUCESSO"); |
||
| 200 | } |
||
| 201 | }); |
||
| 202 | } |
||
| 203 | |||
| 434 | espaco | 204 | public void efetuarPagamentos() { |
| 205 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 206 | public void execute() { |
||
| 439 | espaco | 207 | for (FolhaPagamentoFuncionarioDTO folhaPagamentoFuncionario : getFolhaPagamentoDTO().getFuncionarios()) { |
| 208 | if (!VerificadorUtil.isListaNulaOuVazia(folhaPagamentoFuncionario.getParcelas())) { |
||
| 209 | parcelaService.efetuarPagamentoRecebimento(folhaPagamentoFuncionario.getParcelas().get(0), getDataPagamento()); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | setArquivoParaImportacao(null); |
||
| 434 | espaco | 213 | LancadorMensagem.lancarSucesso("PAGAMENTOS EFETUADOS COM SUCESSO"); |
| 214 | } |
||
| 215 | }); |
||
| 216 | } |
||
| 217 | |||
| 430 | espaco | 218 | public StreamedContent downloadRecibos() throws Exception { |
| 219 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 220 | @Override |
||
| 221 | public StreamedContent execute() { |
||
| 439 | espaco | 222 | return folhaPagamentoService.downloadRecibos(getFolhaPagamentoDTO()); |
| 430 | espaco | 223 | } |
| 224 | }); |
||
| 225 | } |
||
| 226 | |||
| 439 | espaco | 227 | public void enviarRecibos() throws Exception { |
| 228 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 229 | public void execute() { |
||
| 230 | folhaPagamentoService.enviarRecibosPorEmail(getFolhaPagamentoDTO(), getTituloEmail()); |
||
| 231 | LancadorMensagem.lancarSucesso("RECIBOS ENVIADOS COM SUCESSO!"); |
||
| 232 | } |
||
| 233 | }); |
||
| 234 | } |
||
| 235 | |||
| 236 | public StreamedContent downloadArquivoFolhaBanco(String codigoBanco) throws Exception { |
||
| 430 | espaco | 237 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
| 238 | @Override |
||
| 239 | public StreamedContent execute() { |
||
| 439 | espaco | 240 | return folhaPagamentoService.downloadArquivoFolhaBanco(getFolhaPagamentoDTO(), codigoBanco); |
| 430 | espaco | 241 | } |
| 242 | }); |
||
| 243 | } |
||
| 244 | |||
| 424 | blopes | 245 | } |