Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.inova10.simulador
- import java.text.SimpleDateFormat;
- import grails.plugins.springsecurity.Secured;
- import org.codehaus.groovy.grails.commons.ConfigurationHolder
- import grails.converters.*
- import com.inova10.simulador.calculos.*
- import java.text.*
- @Secured(['ROLE_ADMIN'])
- class RelatorioAdminController {
- private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
- def exportService
- private ArrayList trabalhadoresInstanceList = Trabalhador.getAll()
- def index = { }
- def relatorioRh = {
- [trabalhadoresList:new ArrayList()]
- }
- def manipularUsuario = {
- def trabalhadorInstance = Trabalhador.findByCpf(params.id)
- session.setAttribute("trabalhador",trabalhadorInstance)
- redirect(controller:"trabalhador",action:"show")
- }
- private def numeroTrabalhadoresSexo(ArrayList trabalhadores){
- int m = 0
- int f = 0
- for(Trabalhador t:trabalhadores){
- if(t.sexo.equals("M")){
- m++
- }else{
- f++
- }
- }
- return [m:m, f:f]
- }
- def exportRelatorio (ArrayList trabalhadorList, String titulo){
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
- if(params?.format && params.format != "html"){
- String filename = "${params["action"]}_${sdf.format(new Date())}"
- response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
- response.setHeader("Content-disposition", "attachment; filename=${filename}.${params.extension}")
- List fields = ["ocorrencia", "nome", "cpf", "identificador", "sexo"]
- Map labels = ["ocorrencia": "Ocorrência", "nome": "Nome", "cpf":"CPF","identificador":"Matrícula","sexo":"Sexo"]
- def upperCase = { domain, value ->
- return value.toUpperCase()
- }
- def formatDate = {domain, value->
- SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- return format.format(value)
- }
- def formatSexo = {domain, value->
- if(value.equals("M"))return "Masculino"
- return "Feminino"
- }
- def qtdSexo = numeroTrabalhadoresSexo(trabalhadorList)
- String title = """${titulo}
- Total de trabalhadores: ${trabalhadorList.size()}
- Número de trabalhadores por sexo:
- Masculino: ${qtdSexo.m}
- Feminino: ${qtdSexo.f}"""
- Map formatters = [nome: upperCase, ocorrencia:formatDate, sexo:formatSexo]
- Map parameters = [title: title, "column.widths": [0.1, 0.7, 0.2, 0.1, 0.1]]
- exportService.export(params.format, response.outputStream,trabalhadorList, fields, labels,formatters, parameters)
- }
- }
- def exportRelatorio (ArrayList trabalhadorList, String titulo, String label){
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
- if(params?.format && params.format != "html"){
- String filename = "${params["action"]}_${sdf.format(new Date())}"
- response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
- response.setHeader("Content-disposition", "attachment; filename=${filename}.${params.extension}")
- List fields = ["ocorrencia", "nome", "cpf", "identificador", "sexo"]
- Map labels = ["ocorrencia": "${label}", "nome": "Nome", "cpf":"CPF","identificador":"Matrícula","sexo":"Sexo"]
- def upperCase = { domain, value ->
- return value.toUpperCase()
- }
- def formatDate = {domain, value->
- SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- return format.format(value)
- }
- def formatSexo = {domain, value->
- if(value.equals("M"))return "Masculino"
- return "Feminino"
- }
- def qtdSexo = numeroTrabalhadoresSexo(trabalhadorList)
- String title = """${titulo}
- Total de trabalhadores: ${trabalhadorList.size()}
- Número de trabalhadores por sexo:
- Masculino: ${qtdSexo.m}
- Feminino: ${qtdSexo.f}"""
- Map formatters = [nome: upperCase, ocorrencia:formatDate, sexo:formatSexo]
- Map parameters = [title: title, "column.widths": [0.1, 0.7, 0.2, 0.1, 0.1]]
- exportService.export(params.format, response.outputStream,trabalhadorList, fields, labels,formatters, parameters)
- }
- }
- private ArrayList geraRelatorio(String regraDescricao){
- ArrayList trabalhadoresList = new ArrayList()
- for(TrabalhadorRelatorio t: trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def r = new RegrasAposentadoriaFactory(intervalos, t);
- def regraTrabalhador = r.getInstance(regraDescricao)
- regraTrabalhador.calcula()
- if(regraTrabalhador.possivel == null){
- t = null
- }else{
- if(!regraTrabalhador.possivel.class.name.equals("java.util.Date"))t = null
- }
- if(t){
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, regraTrabalhador.possivel)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort()
- exportRelatorio(trabalhadoresList, message(code:regraDescricao))
- return trabalhadoresList
- }
- private ArrayList geraRelatorio(String regraDescricao, String label){
- ArrayList trabalhadoresList = new ArrayList()
- for(TrabalhadorRelatorio t: trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def r = new RegrasAposentadoriaFactory(intervalos, t);
- def regraTrabalhador = r.getInstance(regraDescricao)
- regraTrabalhador.calcula()
- if(regraTrabalhador.possivel == null){
- t = null
- }else{
- if(!regraTrabalhador.possivel.class.name.equals("java.util.Date"))t = null
- }
- if(t){
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, regraTrabalhador.possivel)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort()
- exportRelatorio(trabalhadoresList, message(code:regraDescricao), label)
- return trabalhadoresList
- }
- def tempoCarreira = {
- ArrayList trabalhadoresList = new ArrayList()
- flash.message = "SERVIDORES POR TEMPO NA CARREIRA"
- for(Trabalhador t:trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def intervalosTrabalho = AjudaAposentadoria.filtraIntervalosTrabalho(intervalos);
- def intervalosCarreira = AjudaAposentadoria.filtraCarreira(intervalosTrabalho);
- if(0<intervalosCarreira.size()){
- intervalosCarreira.sort()
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, intervalosCarreira.last().fim)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort{ a, b -> b.ocorrencia <=> a.ocorrencia }
- exportRelatorio(trabalhadoresList, (String)flash.message)
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- def tempoServicoPublico = {
- ArrayList trabalhadoresList = new ArrayList()
- flash.message = "SERVIDORES POR TEMPO SERVIÇO DE PÚBLICO"
- for(Trabalhador t:trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def intervalosTrabalho = AjudaAposentadoria.filtraIntervalosTrabalho(intervalos);
- def intervalosServicoPublico = AjudaAposentadoria.filtraTipo(intervalosTrabalho);
- if(0<intervalosServicoPublico.size()){
- intervalosServicoPublico.sort()
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, intervalosServicoPublico.last().fim)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort{ a, b -> b.ocorrencia <=> a.ocorrencia }
- exportRelatorio(trabalhadoresList, (String)flash.message)
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- def isencaoPSSDireitoAdquiridoRolGeral = {
- ArrayList trabalhadoresList = new ArrayList()
- flash.message = "ISENÇÃO PSS - DIREITO ADQUIRIDO - Rol Geral"
- for(TrabalhadorRelatorio t: trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def r = new RegrasAposentadoriaFactory(intervalos, t);
- ArrayList regrasTrabalhador = new ArrayList()
- regrasTrabalhador.add(r.getInstance("regra1.descricao"))
- regrasTrabalhador.add(r.getInstance("regra3.descricao"))
- regrasTrabalhador.add(r.getInstance("regra5.descricao"))
- regrasTrabalhador.each{obj->
- obj.calcula()
- if(obj.possivel == null)t=null
- if(obj.possivel){
- t=t
- if(obj.descricao.equals("regra1.descricao"))obj.possivel = sdf.parse("16/12/1998")
- if(obj.descricao.equals("regra1.descricao")
- ||obj.descricao.equals("regra5.descricao")){
- obj.possivel = sdf.parse("19/02/2004")
- }
- }
- }
- if(t){
- regrasTrabalhador.sort()
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, regrasTrabalhador.last().possivel)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort()
- exportRelatorio(trabalhadoresList, (String)flash.message,"Dt. ISENÇÃO do PSS")
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. ISENÇÃO do PSS"])
- }
- def isencaoPssDireitoAadquiridoRegraAnteriorEC98Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra1.descricao","Dt. ISENÇÃO do PSS")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("16/12/1998")
- }
- flash.message = "ISENÇÃO PSS – DIREITO ADQUIRIDO - Regra Anterior a EC20/1998 - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. ISENÇÃO do PSS"])
- }
- def isencaoPssDireitoAdquiridoRegraGeralEC98Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra3.descricao","Dt. ISENÇÃO do PSS")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("19/02/2004")
- }
- flash.message = "ISENÇÃO PSS – DIREITO ADQUIRIDO - Regra Geral Vigência EC20/1998 - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. ISENÇÃO do PSS"])
- }
- def isencaoPssDireitoAdquiridoRegraTransicaoEC98Art8Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra5.descricao","Dt. ISENÇÃO do PSS")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("19/02/2004")
- }
- flash.message = "ISENÇÃO PSS – DIREITO ADQUIRIDO - Regra de Transição Vigência EC20/1998 – Artigo 8o - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. ISENÇÃO do PSS"])
- }
- def abonoDireitoAdquiridoRolGeral = {
- ArrayList trabalhadoresList = new ArrayList()
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO – Rol Geral"
- for(TrabalhadorRelatorio t: trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def r = new RegrasAposentadoriaFactory(intervalos, t);
- ArrayList regrasTrabalhador = new ArrayList()
- regrasTrabalhador.add(r.getInstance("regra1.descricao"))
- regrasTrabalhador.add(r.getInstance("regra2.descricao"))
- regrasTrabalhador.add(r.getInstance("regra3.descricao"))
- regrasTrabalhador.add(r.getInstance("regra4.descricao"))
- regrasTrabalhador.add(r.getInstance("regra5.descricao"))
- regrasTrabalhador.add(r.getInstance("regra6.descricao"))
- regrasTrabalhador.each{obj->
- obj.calcula()
- if(obj.possivel == null)t=null
- if(obj.possivel){
- t=t
- if(obj.descricao.equals("regra1.descricao")
- ||obj.descricao.equals("regra5.descricao")){
- obj.possivel = sdf.parse("20/05/2004")
- }
- if(obj.descricao.equals("regra2.descricao")
- ||obj.descricao.equals("regra4.descricao")
- ||obj.descricao.equals("regra6.descricao")){
- obj.possivel = sdf.parse("31/12/2003")
- }
- if(obj.descricao.equals("regra3.descricao"))obj.possivel = sdf.parse("20/02/2004")
- }
- }
- if(t){
- regrasTrabalhador.sort()
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, regrasTrabalhador[0].possivel)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort()
- exportRelatorio(trabalhadoresList, (String)flash.message, "Dt. Abono")
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoDireitoAdquiridoRegraAnteriorEC98Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra1.descricao","Dt. Abono")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("20/05/2004")
- }
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO - Regra Anterior EC 20/1998 - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoDireitoAdquiridoRegraAnteriorEC98Proporcional = {
- ArrayList trabalhadoresList = geraRelatorio("regra2.descricao","Dt. Abono")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("31/12/2003")
- }
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO - Regra Anterior EC 20/1998 - Proporcional"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoDireitoAdquiridoRegraGeralEC98Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra3.descricao","Dt. Abono")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("20/02/2004")
- }
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO - Regra Geral Vigência EC 20/98 - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoDireitoAdquiridoRegraGeralEC98Idade = {
- ArrayList trabalhadoresList = geraRelatorio("regra4.descricao","Dt. Abono")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("31/12/2003")
- }
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO - Regra Geral Vigência EC 20/98 – POR IDADE"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoDireitoAdquiridoRegraTransicaoEC98Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra5.descricao","Dt. Abono")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("20/05/2004")
- }
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO - Regra de Transição Vigência EC 20/98 - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoDireitoAdquiridoRegraTransicaoEC98Proporcional = {
- ArrayList trabalhadoresList = geraRelatorio("regra6.descricao","Dt. Abono")
- trabalhadoresList.each{obj->
- obj.ocorrencia = sdf.parse("31/12/2003")
- }
- flash.message = "ABONO DE PERMANÊNCIA – DIREITO ADQUIRIDO - Regra de Transição Vigência EC 20/98 - PROPORCIONAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoRegraGeralEC41VoluntariaIntegral = {
- ArrayList trabalhadoresList = geraRelatorio("regra7.descricao","Dt. Abono")
- flash.message = "ABONO DE PERMANÊNCIA – REGRA GERAL Vigência EC 41/2003 – VOLUNTÁRIA - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def abonoRegraTransicaoEC41Art2Integral = {
- ArrayList trabalhadoresList = geraRelatorio("regra11.descricao","Dt. Abono")
- flash.message = "ABONO DE PERMANÊNCIA – REGRA DE TRANSIÇÃO – Vigência EC 41/2003 - Artigo 2o - INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList),label:"Dt. Abono"])
- }
- def regraAtuaisRolGeral = {
- ArrayList trabalhadoresList = new ArrayList()
- flash.message = "APOSENTADORIA REGRAS ATUAIS Vigência EC 41/2003 – Rol Geral"
- for(TrabalhadorRelatorio t: trabalhadoresInstanceList){
- def intervalos = AjudaAposentadoria.criaIntervalosTempo(t)
- def r = new RegrasAposentadoriaFactory(intervalos, t);
- ArrayList regrasTrabalhador = new ArrayList()
- regrasTrabalhador.add(r.getInstance("regra8.descricao"))
- regrasTrabalhador.add(r.getInstance("regra9.descricao"))
- regrasTrabalhador.add(r.getInstance("regra12.descricao"))
- regrasTrabalhador.add(r.getInstance("regra13.descricao"))
- regrasTrabalhador.each{obj->
- obj.calcula()
- if(obj.possivel == null){
- t = null
- }else{
- if(!obj.possivel.class.name.equals("java.util.Date"))t = null
- }
- }
- if(t){
- regrasTrabalhador.sort()
- TrabalhadorRelatorio tRelatorio = new TrabalhadorRelatorio(t, regrasTrabalhador.last().possivel)
- trabalhadoresList.add(tRelatorio)
- }
- }
- trabalhadoresList.sort()
- exportRelatorio(trabalhadoresList, (String)flash.message)
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- def aposentadoriaRegraGeralEC41VoluntariaIdade = {
- ArrayList trabalhadoresList = geraRelatorio("regra8.descricao")
- flash.message = "APOSENTADORIA REGRA GERAL Vigência EC 41/2003 – VOLUNTÁRIA-POR IDADE"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- def aposentadoriaRegraGeralEC41Compulsoria = {
- ArrayList trabalhadoresList = geraRelatorio("regra12.descricao")
- flash.message = "APOSENTADORIA REGRA GERAL Vigência EC 41/2003 – COMPULSÓRIA"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- def aposentadoriaRegraTransicaoEC47Art3 = {
- ArrayList trabalhadoresList = geraRelatorio("regra13.descricao")
- flash.message = "APOSENTADORIA REGRA DE TRANSIÇÃO Vigência EC 47/2005 – Artigo 3o – INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- def aposentadoriaRegraTransicaoEC41Art6 = {
- ArrayList trabalhadoresList = geraRelatorio("regra9.descricao")
- flash.message = "APOSENTADORIA REGRA DE TRANSIÇÃO Vigência EC 41/2003 – Artigo 6o – INTEGRAL"
- render(view: "relatorioRh", model:[trabalhadoresList:trabalhadoresList, qtdSexo:numeroTrabalhadoresSexo(trabalhadoresList)])
- }
- }
- class TrabalhadorRelatorio extends Trabalhador implements Comparable {
- TrabalhadorRelatorio(Trabalhador trabalhador, Date ocorrencia){
- this.cpf = trabalhador.cpf
- this.identificador = trabalhador.identificador
- this.nome = trabalhador.nome
- this.sexo = trabalhador.sexo
- this.ocorrencia = ocorrencia
- }
- Date ocorrencia
- public int compareTo(Object o){
- return ocorrencia.compareTo(o.ocorrencia)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement