Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.scs.web.managebean.relatorio; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.Calendar; |
||
| 6 | import java.util.Properties; |
||
| 7 | |||
| 8 | import javax.annotation.PostConstruct; |
||
| 9 | import javax.annotation.Resource; |
||
| 10 | import javax.faces.bean.ManagedBean; |
||
| 11 | import javax.faces.context.FacesContext; |
||
| 12 | |||
| 13 | import net.sf.jasperreports.engine.JasperPrint; |
||
| 14 | |||
| 15 | import org.primefaces.model.StreamedContent; |
||
| 16 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 17 | import org.springframework.context.annotation.Scope; |
||
| 18 | import org.springframework.stereotype.Component; |
||
| 19 | |||
| 20 | import br.gov.al.saude.framework.core.callback.SetadorPessoaCallback; |
||
| 21 | import br.gov.al.saude.framework.core.exception.RelatorioException; |
||
| 22 | import br.gov.al.saude.framework.core.model.pessoa.PessoaDTO; |
||
| 23 | import br.gov.al.saude.framework.core.util.DataUtils; |
||
| 24 | import br.gov.al.saude.framework.core.util.RelatorioUtils; |
||
| 25 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 26 | import br.gov.al.saude.framework.security.context.ContextoSeguranca; |
||
| 27 | import br.gov.al.saude.framework.web.exception.VerificadorLancamentoException; |
||
| 28 | import br.gov.al.saude.framework.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 29 | import br.gov.al.saude.framework.web.exception.VerificadorLancamentoException.CommandRelatorioStreamedContent; |
||
| 30 | import br.gov.al.saude.framework.web.util.IndraJSFUtils; |
||
| 31 | import br.gov.al.saude.framework.web.util.URLUtils; |
||
| 32 | import br.gov.al.saude.sca.model.usuario.view.UsuarioView; |
||
| 33 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 34 | import br.gov.al.saude.scs.core.application.relatorio.RelatorioFacade; |
||
| 35 | import br.gov.al.saude.scs.core.application.turma.TurmaFacade; |
||
| 36 | import br.gov.al.saude.scs.model.Capacitacao; |
||
| 37 | import br.gov.al.saude.scs.model.Turma; |
||
| 38 | import br.gov.al.saude.scs.model.TurmaParticipante; |
||
| 39 | import br.gov.al.saude.scs.model.dto.TurmaDTO; |
||
| 40 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioCapacitacaoPorParticipante; |
||
| 41 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioCapacitacaoPorPeriodo; |
||
| 42 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioDespesas; |
||
| 43 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioParticipantePorTurma; |
||
| 44 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioParticipantesFaltantes; |
||
| 45 | |||
| 46 | @Component |
||
| 47 | @ManagedBean |
||
| 48 | @Scope("view") |
||
| 49 | public class RelatorioBean implements Serializable, SetadorPessoaCallback { |
||
| 50 | |||
| 51 | private static final long serialVersionUID = 1L; |
||
| 52 | |||
| 53 | @Resource(name = "scgModalProperties") |
||
| 54 | private Properties properties; |
||
| 55 | |||
| 56 | private TurmaFacade turmaFacade; |
||
| 57 | private RelatorioFacade relatorioFacade; |
||
| 58 | private String identificadorComponente; |
||
| 59 | |||
| 60 | private PessoaFisicaView pessoaFisica; |
||
| 61 | private Capacitacao capacitacao; |
||
| 62 | private Turma turma; |
||
| 63 | private TurmaParticipante turmaParticipante; |
||
| 64 | private ParametrosRelatorioCapacitacaoPorParticipante parametrosRelatorioCapacitacaoPorParticipante; |
||
| 65 | private ParametrosRelatorioCapacitacaoPorPeriodo parametrosRelatorioCapacitacaoPorPeriodo; |
||
| 66 | private ParametrosRelatorioParticipantePorTurma parametrosRelatorioParticipantePorTurma; |
||
| 67 | private ParametrosRelatorioDespesas parametrosRelatorioDespesas; |
||
| 68 | private ParametrosRelatorioParticipantesFaltantes parameParticipantesFaltantes; |
||
| 69 | private ContextoSeguranca contextoSeguranca; |
||
| 70 | private ArrayList<Integer> listaAnos; |
||
| 71 | private TurmaDTO turmaDTO; |
||
| 72 | |||
| 73 | @Autowired |
||
| 74 | public RelatorioBean(TurmaFacade turmaFacade, ContextoSeguranca contextoSeguranca, RelatorioFacade relatorioFacade) { |
||
| 75 | this.turmaFacade = turmaFacade; |
||
| 76 | this.contextoSeguranca = contextoSeguranca; |
||
| 77 | this.relatorioFacade = relatorioFacade; |
||
| 78 | } |
||
| 79 | |||
| 80 | @PostConstruct |
||
| 81 | public void init() { |
||
| 82 | String idPessoaCadastrada = getContext().getExternalContext().getRequestParameterMap().get(IndraJSFUtils.ID_PESSOA_CADASTRADA); |
||
| 83 | popularObjetoSeIdPessoaDiferenteDeNulo(idPessoaCadastrada); |
||
| 84 | } |
||
| 85 | |||
| 86 | ///////////// INICIO METODOS GETS & SETS ////////// |
||
| 87 | |||
| 88 | protected Properties getProperties() { |
||
| 89 | return properties; |
||
| 90 | } |
||
| 91 | |||
| 92 | public FacesContext getContext() { |
||
| 93 | return FacesContext.getCurrentInstance(); |
||
| 94 | } |
||
| 95 | |||
| 96 | public PessoaFisicaView getPessoaFisica() { |
||
| 97 | if(VerificadorUtil.estaNulo(pessoaFisica)){ |
||
| 98 | pessoaFisica = new PessoaFisicaView(); |
||
| 99 | } |
||
| 100 | return pessoaFisica; |
||
| 101 | } |
||
| 102 | |||
| 103 | public void setPessoaFisica(PessoaFisicaView pessoaFisica) { |
||
| 104 | this.pessoaFisica = pessoaFisica; |
||
| 105 | } |
||
| 106 | |||
| 107 | public TurmaFacade getTurmaFacade() { |
||
| 108 | return turmaFacade; |
||
| 109 | } |
||
| 110 | |||
| 111 | public void setTurmaFacade(TurmaFacade turmaFacade) { |
||
| 112 | this.turmaFacade = turmaFacade; |
||
| 113 | } |
||
| 114 | |||
| 115 | public ParametrosRelatorioCapacitacaoPorParticipante getParametrosRelatorioCapacitacaoPorParticipante() { |
||
| 116 | return parametrosRelatorioCapacitacaoPorParticipante; |
||
| 117 | } |
||
| 118 | |||
| 119 | public void setParametrosRelatorioCapacitacaoPorParticipante(ParametrosRelatorioCapacitacaoPorParticipante parametrosRelatorioCapacitacaoPorParticipante) { |
||
| 120 | this.parametrosRelatorioCapacitacaoPorParticipante = parametrosRelatorioCapacitacaoPorParticipante; |
||
| 121 | } |
||
| 122 | |||
| 123 | public ParametrosRelatorioParticipantePorTurma getParametrosRelatorioParticipantePorTurma() { |
||
| 124 | return parametrosRelatorioParticipantePorTurma; |
||
| 125 | } |
||
| 126 | |||
| 127 | public void setParametrosRelatorioParticipantePorTurma(ParametrosRelatorioParticipantePorTurma parametrosRelatorioParticipantePorTurma) { |
||
| 128 | this.parametrosRelatorioParticipantePorTurma = parametrosRelatorioParticipantePorTurma; |
||
| 129 | } |
||
| 130 | |||
| 131 | public ParametrosRelatorioCapacitacaoPorPeriodo getParametrosRelatorioCapacitacaoPorPeriodo() { |
||
| 132 | return parametrosRelatorioCapacitacaoPorPeriodo; |
||
| 133 | } |
||
| 134 | |||
| 135 | public void setParametrosRelatorioCapacitacaoPorPeriodo(ParametrosRelatorioCapacitacaoPorPeriodo parametrosRelatorioCapacitacaoPorPeriodo) { |
||
| 136 | this.parametrosRelatorioCapacitacaoPorPeriodo = parametrosRelatorioCapacitacaoPorPeriodo; |
||
| 137 | } |
||
| 138 | |||
| 139 | public ParametrosRelatorioDespesas getParametrosRelatorioDespesas() { |
||
| 140 | return parametrosRelatorioDespesas; |
||
| 141 | } |
||
| 142 | |||
| 143 | public void setParametrosRelatorioDespesas(ParametrosRelatorioDespesas parametrosRelatorioDespesas) { |
||
| 144 | this.parametrosRelatorioDespesas = parametrosRelatorioDespesas; |
||
| 145 | } |
||
| 146 | |||
| 147 | public ParametrosRelatorioParticipantesFaltantes getParameParticipantesFaltantes() { |
||
| 148 | return parameParticipantesFaltantes; |
||
| 149 | } |
||
| 150 | |||
| 151 | public void setParameParticipantesFaltantes(ParametrosRelatorioParticipantesFaltantes parameParticipantesFaltantes) { |
||
| 152 | this.parameParticipantesFaltantes = parameParticipantesFaltantes; |
||
| 153 | } |
||
| 154 | |||
| 155 | public UsuarioView getUsuario() { |
||
| 156 | return (UsuarioView) contextoSeguranca.obterUserIndra().getPrincipal(); |
||
| 157 | } |
||
| 158 | |||
| 159 | public ArrayList<Integer> getListaAnos() { |
||
| 160 | return listaAnos; |
||
| 161 | } |
||
| 162 | |||
| 163 | public void setListaAnos(ArrayList<Integer> listaAnos) { |
||
| 164 | this.listaAnos = listaAnos; |
||
| 165 | } |
||
| 166 | |||
| 167 | public Capacitacao getCapacitacao() { |
||
| 168 | return capacitacao; |
||
| 169 | } |
||
| 170 | |||
| 171 | public void setCapacitacao(Capacitacao capacitacao) { |
||
| 172 | this.capacitacao = capacitacao; |
||
| 173 | } |
||
| 174 | |||
| 175 | public TurmaDTO getTurmaDTO() { |
||
| 176 | if(VerificadorUtil.estaNulo(turmaDTO)){ |
||
| 177 | turmaDTO = new TurmaDTO(); |
||
| 178 | } |
||
| 179 | return turmaDTO; |
||
| 180 | } |
||
| 181 | |||
| 182 | public void setTurmaDTO(TurmaDTO turmaDTO) { |
||
| 183 | this.turmaDTO = turmaDTO; |
||
| 184 | } |
||
| 185 | |||
| 186 | public Turma getTurma() { |
||
| 187 | return turma; |
||
| 188 | } |
||
| 189 | |||
| 190 | public void setTurma(Turma turma) { |
||
| 191 | this.turma = turma; |
||
| 192 | } |
||
| 193 | |||
| 194 | public TurmaParticipante getTurmaParticipante() { |
||
| 195 | return turmaParticipante; |
||
| 196 | } |
||
| 197 | |||
| 198 | public void setTurmaParticipante(TurmaParticipante turmaParticipante) { |
||
| 199 | this.turmaParticipante = turmaParticipante; |
||
| 200 | } |
||
| 201 | |||
| 202 | ///////////// FIM METODOS GETS & SETS ////////// |
||
| 203 | |||
| 204 | ///////////// INICIO METODOS MODAL ///////////// |
||
| 205 | |||
| 206 | @Override |
||
| 207 | public void irParaCadastroDePessoa() { |
||
| 208 | String urlCadastroPessoa = getProperties().getProperty(SetadorPessoaCallback.URL_SCG_CADASTRO_PESSOA); |
||
| 209 | String urlCompleta = URLUtils.montarUrlDeCallBackIhAdicionarNaUrl(urlCadastroPessoa); |
||
| 210 | armazenarObjetoNaSessaoIhRedirecionarUrl(urlCompleta); |
||
| 211 | } |
||
| 212 | |||
| 213 | @Override |
||
| 214 | public void irParaAlteracaoDePessoa(Long idPessoa) { |
||
| 215 | String urlCadastroPessoa = getProperties().getProperty(SetadorPessoaCallback.URL_SCG_CADASTRO_PESSOA); |
||
| 216 | String urlCompleta = URLUtils.montarUrlDeCallBackPassandoIdentificadorPessoaParaAlterar(urlCadastroPessoa, idPessoa); |
||
| 217 | armazenarObjetoNaSessaoIhRedirecionarUrl(urlCompleta); |
||
| 218 | } |
||
| 219 | |||
| 220 | private void armazenarObjetoNaSessaoIhRedirecionarUrl(String urlCompleta) { |
||
| 221 | try { |
||
| 222 | getContext().getExternalContext().redirect(urlCompleta); |
||
| 223 | } catch (Exception e) { |
||
| 224 | e.printStackTrace(); |
||
| 225 | } |
||
| 226 | } |
||
| 227 | |||
| 228 | @Override |
||
| 229 | public void setarPessoa(final PessoaDTO pessoaDTO) { |
||
| 230 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 231 | @Override |
||
| 232 | public void execute() { |
||
| 233 | pessoaFisica = turmaFacade.consultarPessoa(pessoaDTO.getId()); |
||
| 234 | } |
||
| 235 | }); |
||
| 236 | } |
||
| 237 | |||
| 238 | protected void popularObjetoSeIdPessoaDiferenteDeNulo(final String idPessoaCadastrada) { |
||
| 239 | if(VerificadorUtil.naoEstaNuloOuVazio(idPessoaCadastrada)) { |
||
| 240 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 241 | @Override |
||
| 242 | public void execute() { |
||
| 243 | if (VerificadorUtil.naoEstaNuloOuVazio(idPessoaCadastrada)) { |
||
| 244 | if(!idPessoaCadastrada.equals("0")) { |
||
| 245 | pessoaFisica = turmaFacade.consultarPessoa(Long.valueOf(idPessoaCadastrada)); |
||
| 246 | } |
||
| 247 | } |
||
| 248 | } |
||
| 249 | }); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | public String getIdentificadorComponente() { |
||
| 254 | return identificadorComponente; |
||
| 255 | } |
||
| 256 | |||
| 257 | public void setIdentificadorComponente(String identificadorComponente) { |
||
| 258 | this.identificadorComponente = identificadorComponente; |
||
| 259 | } |
||
| 260 | |||
| 261 | ///////////// FIM METODOS MODAL ///////////// |
||
| 262 | |||
| 263 | public Boolean isValorMenorQueSetentaEhCinco(Double valor){ |
||
| 264 | return valor < 75.0; |
||
| 265 | } |
||
| 266 | |||
| 267 | private void carregarAnos() { |
||
| 268 | listaAnos = new ArrayList<Integer>(); |
||
| 269 | int anoAtual = DataUtils.obterCalendario(DataUtils.getDataAtual()).get(Calendar.YEAR) - 10; |
||
| 270 | int anoFinal = anoAtual + 20; |
||
| 271 | for (int i = anoAtual; i < anoFinal; i++) { |
||
| 272 | listaAnos.add(i); |
||
| 273 | } |
||
| 274 | } |
||
| 275 | |||
| 276 | public void limparTurmaDTO(){ |
||
| 277 | setTurmaDTO(null); |
||
| 278 | setTurma(null); |
||
| 279 | } |
||
| 280 | |||
| 281 | public void limparTurmaParticipante(){ |
||
| 282 | setTurmaParticipante(null); |
||
| 283 | } |
||
| 284 | |||
| 285 | public void prepararRelatorioCapacitacaoPorParticipante(){ |
||
| 286 | parametrosRelatorioCapacitacaoPorParticipante = new ParametrosRelatorioCapacitacaoPorParticipante(); |
||
| 287 | carregarAnos(); |
||
| 288 | } |
||
| 289 | |||
| 290 | public void prepararRelatorioParticipantePorTurma(){ |
||
| 291 | parametrosRelatorioParticipantePorTurma = new ParametrosRelatorioParticipantePorTurma(); |
||
| 292 | } |
||
| 293 | |||
| 294 | public void prepararRelatorioCapacitacaoPorPeriodo(){ |
||
| 295 | parametrosRelatorioCapacitacaoPorPeriodo = new ParametrosRelatorioCapacitacaoPorPeriodo(); |
||
| 296 | } |
||
| 297 | |||
| 298 | public void prepararRelatorioDespesas(){ |
||
| 299 | parametrosRelatorioDespesas = new ParametrosRelatorioDespesas(); |
||
| 300 | carregarAnos(); |
||
| 301 | } |
||
| 302 | |||
| 303 | public void prepararRelatorioParticipantesFaltantes(){ |
||
| 304 | parameParticipantesFaltantes = new ParametrosRelatorioParticipantesFaltantes(); |
||
| 305 | carregarAnos(); |
||
| 306 | } |
||
| 307 | |||
| 308 | public void consultarParticipantesTurma(){ |
||
| 309 | turma = turmaFacade.consultarTurmaComParticipantes(getTurmaDTO().getSequencialTurma()); |
||
| 310 | } |
||
| 311 | |||
| 312 | public StreamedContent emitirRelatorioCapacitacaoPorParticipante(){ |
||
| 313 | getParametrosRelatorioCapacitacaoPorParticipante().setSequencialParticipante(getPessoaFisica().getSequencialPessoa()); |
||
| 314 | getParametrosRelatorioCapacitacaoPorParticipante().setUsuarioLogado(getUsuario()); |
||
| 315 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 316 | @Override |
||
| 317 | public StreamedContent execute() throws RelatorioException, Exception { |
||
| 318 | JasperPrint relatorio = relatorioFacade.emitirRelatorioCapacitacaoPorParticipante(getParametrosRelatorioCapacitacaoPorParticipante()); |
||
| 319 | return RelatorioUtils.gerarPdf(relatorio, "rel_capacitacao_por_part"); |
||
| 320 | } |
||
| 321 | }); |
||
| 322 | } |
||
| 323 | |||
| 324 | public StreamedContent emitirRelatorioParticipantePorTurma(){ |
||
| 325 | getParametrosRelatorioParticipantePorTurma().setSequencialTurma(getTurmaDTO().getSequencialTurma()); |
||
| 326 | getParametrosRelatorioParticipantePorTurma().setUsuarioLogado(getUsuario()); |
||
| 327 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 328 | @Override |
||
| 329 | public StreamedContent execute() throws RelatorioException, Exception { |
||
| 330 | JasperPrint relatorio = relatorioFacade.emitirRelatorioParticipantePorTurma(getParametrosRelatorioParticipantePorTurma()); |
||
| 331 | return RelatorioUtils.gerarPdf(relatorio, "rel_part_por_turma"); |
||
| 332 | } |
||
| 333 | }); |
||
| 334 | } |
||
| 335 | |||
| 336 | public StreamedContent emitirRelatorioCapacitacaoPorPeriodo(){ |
||
| 337 | getParametrosRelatorioCapacitacaoPorPeriodo().setUsuarioLogado(getUsuario()); |
||
| 338 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 339 | @Override |
||
| 340 | public StreamedContent execute() throws RelatorioException, Exception { |
||
| 341 | JasperPrint relatorio = relatorioFacade.emitirRelatorioCapacitacaoPorPeriodo(getParametrosRelatorioCapacitacaoPorPeriodo()); |
||
| 342 | return RelatorioUtils.gerarPdf(relatorio, "rel_cap_por_turma"); |
||
| 343 | } |
||
| 344 | }); |
||
| 345 | } |
||
| 346 | |||
| 347 | public StreamedContent emitirRelatorioDespesas(){ |
||
| 348 | getParametrosRelatorioDespesas().setUsuarioLogado(getUsuario()); |
||
| 349 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 350 | @Override |
||
| 351 | public StreamedContent execute() throws RelatorioException, Exception { |
||
| 352 | JasperPrint relatorio = relatorioFacade.emitirRelatorioDespesas(getParametrosRelatorioDespesas()); |
||
| 353 | return RelatorioUtils.gerarPdf(relatorio, "rel_despesas"); |
||
| 354 | } |
||
| 355 | }); |
||
| 356 | } |
||
| 357 | |||
| 358 | public StreamedContent emitirRelatorioParticipantesFaltantes(){ |
||
| 359 | getParameParticipantesFaltantes().setUsuarioLogado(getUsuario()); |
||
| 360 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 361 | @Override |
||
| 362 | public StreamedContent execute() throws RelatorioException, Exception { |
||
| 363 | JasperPrint relatorio = relatorioFacade.emitirRelatorioParticipantesFaltantes(getParameParticipantesFaltantes()); |
||
| 364 | return RelatorioUtils.gerarPdf(relatorio, "rel_part_faltantes"); |
||
| 365 | } |
||
| 366 | }); |
||
| 367 | } |
||
| 368 | |||
| 369 | public StreamedContent emitirCertificado(){ |
||
| 370 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 371 | @Override |
||
| 372 | public StreamedContent execute() throws RelatorioException, Exception { |
||
| 373 | JasperPrint relatorio = relatorioFacade.emitirCertificado(getTurmaParticipante()); |
||
| 374 | return RelatorioUtils.gerarPdf(relatorio, "certificado"); |
||
| 375 | } |
||
| 376 | }); |
||
| 377 | } |
||
| 378 | |||
| 379 | } |