Skip to content

Instantly share code, notes, and snippets.

@saferodrigo
Created May 4, 2016 20:07
Show Gist options
  • Save saferodrigo/c3a23e67ea01172bcbc58fafc21c8ea7 to your computer and use it in GitHub Desktop.
Save saferodrigo/c3a23e67ea01172bcbc58fafc21c8ea7 to your computer and use it in GitHub Desktop.
#encoding: utf-8
module ProcessosHelper
def self.notificar_despacho(processoId)
interesses = ProcessoInteresse.where("processo_id = ?", processoId)
interesses.each do |i|
n = Notificacao.new
n.pessoa_id = i.pessoa_id
n.processo_id = processoId
n.mensagem = ""
n.lida = false
if n.save == false
ActiveRecord::Rollback
end
end
end
def self.notificar(processoId)
interesses = ProcessoInteresse.where("processo_id = ?", processoId)
interesses.each do |i|
n = Notificacao.new
n.pessoa_id = i.pessoa_id
n.processo_id = processoId
n.mensagem = ""
n.lida = false
if n.save == false
ActiveRecord::Rollback
end
end
end
def self.notificar_com_excessao(processoId, usuario_id_ignorar)
interesses = ProcessoInteresse.where("processo_id = ? AND pessoa_id != ?", processoId, usuario_id_ignorar)
interesses.each do |i|
n = Notificacao.new
n.pessoa_id = i.pessoa_id
n.processo_id = processoId
n.mensagem = ""
n.lida = false
if n.save == false
ActiveRecord::Rollback
end
end
end
def self.etiqueta_antiga(processo)
larguraMaxima = 340
margenEsquerda = 40
margenEsquerda2 = 120
pdf = Prawn::Document.new :page_layout => :landscape, :page_size => [275, 410], :margin => [0, 0, 0, 0]
size = 12
categoria = ""
if (processo.categoria == 1)
categoria = "Processo Administrativo"
elsif (processo.categoria == 2)
categoria = "Processo Legislativo"
# elsif (processo.categoria == 3)
# categoria = "Processo Financeiro"
end
pdf.font_families.update("Arial" => {
:normal => {:file => "#{Rails.root.to_s}/app/assets/images/Arial.ttf"},
:bold => {:file => "#{Rails.root.to_s}/app/assets/images/Arial_Bold.ttf"}
})
pdf.font "Arial"
pdf.move_cursor_to 260
if (processo.categoria == Processo::CATEGORIA_LEGISLATIVO)
pdf.span(larguraMaxima, :position => margenEsquerda) do
pdf.text categoria, :size => 18, :inline_format => true, :style => :bold, :align => :center
end
pdf.move_down 7
end
if processo.legislativo?
dados_legislativos = ProcessoLegislativo.where(:processo_id => processo.id).first
end
up = 13
pdf.span(larguraMaxima/2, :position => margenEsquerda) do
pdf.text "<b>Data da autuação:</b> "+processo.data.strftime("%d/%m/%Y"), :size => size, :inline_format => true
if dados_legislativos
pdf.text "<b>Número Projeto:</b>" + dados_legislativos.projeto_numero.to_s, :size => size, :inline_format => true if !dados_legislativos.projeto_numero.to_s.vazia?
up = 26 if !dados_legislativos.projeto_numero.to_s.vazia?
end
end
pdf.move_up up
pdf.span((larguraMaxima/2), :position => (larguraMaxima/2 + 40)) do
pdf.text "<b>Nº do Processo:</b> "+processo.numero, :size => size, :inline_format => true
end
if processo.legislativo?
dados_legislativos = ProcessoLegislativo.where(:processo_id => processo.id).first
if dados_legislativos.numero_oficio_mensagem != nil or dados_legislativos.numero_oficio_mensagem != ""
pdf.span((larguraMaxima/2), :position => (larguraMaxima/2 + 40)) do
pdf.text "<b>Nº Ofício MSG:</b> " + dados_legislativos.numero_oficio_mensagem.to_s, :size => size, :inline_format => true
end
end
end
pdf.move_down 4
pdf.span(margenEsquerda2, :position => margenEsquerda) do
pdf.text "<b>Origem: </b>", :size => size, :inline_format => true
end
pdf.move_up 12
pdf.span(larguraMaxima- margenEsquerda2, :position => margenEsquerda2) do
if (processo.orgao_externo_id == 0)
pdf.text "ASSEMBLEIA LEGISLATIVA - GO", :size => size, :inline_format => true
elsif (processo.orgao_externo_id > 0)
pdf.text processo.orgao_externo.nome.mb_chars.upcase, :size => size, :inline_format => true
end
end
pdf.move_down 3
if (processo.categoria == Processo::CATEGORIA_LEGISLATIVO)
pdf.span(margenEsquerda2, :position => margenEsquerda) do
pdf.text "<b>Nº: </b>", :size => size, :inline_format => true
end
pdf.move_up 12
pdf.span(larguraMaxima-margenEsquerda2, :position => margenEsquerda2) do
pdf.text processo.numero_projeto, :size => size, :inline_format => true
end
pdf.move_down 3
end
foram = [];
textoAutor = ""
textoInteressado = ""
if (processo.envolvidos)
processo.envolvidos.includes(:tipo_envolvimento).order("tipo_envolvimentos.descricao ASC").each do |i|
if (i.tipo_envolvimento.id == TipoEnvolvimento::AUTOR)
if (i.interessado_id)
textoAutor+= i.interessado.nome.mb_chars.upcase + "; "
elsif (i.orgao_externo_id)
textoAutor+= i.orgao_externo.nome.mb_chars.upcase+"; "
end
elsif (i.tipo_envolvimento.id == TipoEnvolvimento::INTERESSADO)
if (i.interessado_id)
textoInteressado+= i.interessado.nome.mb_chars.upcase + "; "
elsif (i.orgao_externo_id)
textoInteressado+= i.orgao_externo.nome.mb_chars.upcase+"; "
end
end
end
end
if (textoAutor != "")
pdf.span(80, :position => margenEsquerda) do
pdf.text "<b>Autor:</b> ", :size => size, :inline_format => true
end
pdf.move_up 12
pdf.span(220, :position => margenEsquerda2) do
pdf.text textoAutor, :size => size, :inline_format => true
end
pdf.move_down 3
end
if (textoInteressado != "")
pdf.span(80, :position => margenEsquerda) do
pdf.text "<b>Interessado:</b> ", :size => size, :inline_format => true
end
pdf.move_up 12
pdf.span(220, :position => margenEsquerda2) do
pdf.text textoInteressado, :size => size, :inline_format => true
end
pdf.move_down 3
end
pdf.span(70, :position => margenEsquerda) do
pdf.text "<b>Tipo: </b>", :size => size, :inline_format => true
end
pdf.move_up 9
pdf.span(100, :position => margenEsquerda2) do
pdf.text processo.sub_tipo.tipo.descricao.mb_chars.upcase, :size => size, :inline_format => true
end
pdf.move_down 3
pdf.span(70, :position => margenEsquerda) do
pdf.text "<b>Sub tipo: </b>", :size => size, :inline_format => true
end
pdf.move_up 10
pdf.span(230, :position => margenEsquerda2) do
pdf.text processo.sub_tipo.descricao.mb_chars.upcase, :size => size, :inline_format => true
end
pdf.move_down 3
pdf.span(270, :position => margenEsquerda) do
pdf.text "<b>Assunto: </b>", :size => size, :inline_format => true
end
pdf.move_down 5
pdf.span(larguraMaxima, :position => margenEsquerda) do
pdf.text processo.assunto[0, 200].mb_chars.upcase, :size => size, :inline_format => true
end
pdf.move_down 35
barcode = Barby::Code128B.new(processo.numero)
pdf.span(larguraMaxima, :position => margenEsquerda) do
barcode.annotate_pdf(pdf, :x => 100, :y => 0, :height => 30)
pdf.move_down 2
pdf.text processo.numero, :align => :center, :size => 9
end
return pdf
end
def self.etiqueta_nova(processo)
larguraMaxima = 280
margenEsquerda = 160
margenEsquerda2 = 200
pdf = Prawn::Document.new :page_layout => :landscape, :margin => [0, 0, 0, 10], :page_size => [70.4, 140]
size = 8
categoria = ""
if (processo.categoria_id == Processo::CATEGORIA_ADMINISTRATIVO)
categoria = "PROCESSO ADMINISTRATIVO"
elsif (processo.categoria_id == Processo::CATEGORIA_LEGISLATIVO)
categoria = "PROCESSO LEGISLATIVO"
end
pdf.font_families.update("Arial" => {
:normal => {:file => "#{Rails.root.to_s}/app/assets/images/Arial.ttf"},
:bold => {:file => "#{Rails.root.to_s}/app/assets/images/Arial_Bold.ttf"}
})
pdf.font "Arial"
pdf.move_cursor_to 780
pdf.span(larguraMaxima, :position => margenEsquerda) do
pdf.text categoria, :size => 6, :inline_format => true, :align => :center
end
pdf.move_down 1
pdf.span(larguraMaxima, :position => margenEsquerda) do
pdf.text "Nº " + processo.numero, :size => 12, :inline_format => true, :align => :center, :style => :bold
end
pdf.move_down 3
if processo.legislativo?
dados_legislativos = ProcessoLegislativo.where(:processo_id => processo.id).first
end
largura_tabela = 270
numero_oficio_msg = ""
label_numero_oficio_msg = ""
numero_oficio = ""
label_numero_oficio = ""
numero_documento = ""
label_numero_documento = ""
numero_documento = ""
label_documento = ""
pdf.move_up 2
pdf.text "<b>Data Autuação:</b> " + processo.data.strftime("%d/%m/%Y"), :size => size - 1, :inline_format => true, :align => :center
pdf.move_down 2
up = 0
if dados_legislativos
valor_numero_projeto = dados_legislativos.projeto_numero.to_s
if !valor_numero_projeto.to_s.vazia?
numero_documento = valor_numero_projeto
label_documento = "Projeto :"
end
valor_numero_oficio = dados_legislativos.num_oficio.to_s
if !valor_numero_oficio.to_s.vazia? && numero_documento.to_s.vazia?
numero_documento = valor_numero_oficio
label_documento = "Nº Ofício:"
end
valor_numero_oficio_msg = dados_legislativos.numero_oficio_mensagem.to_s
if !valor_numero_oficio_msg.to_s.vazia? && numero_documento.to_s.vazia?
numero_documento = valor_numero_oficio_msg
label_documento = "Nº Ofício MSG:"
end
tabela = [
[
{:content => label_documento, :width => 60, :align => :left, :size => size},
{:content => numero_documento, :align => :left, :size => size}
]
]
else
valor_numero_documento = processo.numero_documento.to_s
if !valor_numero_documento.to_s.vazia?
numero_documento = valor_numero_documento
label_numero_documento = "Nº Documento:"
end
tabela = [
[
{:content => label_numero_documento, :width => 60, :size => size},
{:content => numero_documento, :size => size}
]
]
end
pdf.table tabela, :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1
rows(0..10).columns([0, 2]).font_style = :bold
end
pdf.move_up up
origem = "ASSEMBLEIA LEGISLATIVA - GO"
origem = processo.orgao_externo.nome.mb_chars.upcase.to_s if processo.orgao_externo_id != 0
tabela2 = [
[
{:content => "Origem:", :width => 60},
{:content => origem, :width => 210}
]
]
textoAutor = ""
textoInteressado = ""
if (processo.envolvidos)
processo.envolvidos.includes(:tipo_envolvimento).order("tipo_envolvimentos.descricao ASC").each do |i|
if (i.tipo_envolvimento.id == TipoEnvolvimento::AUTOR)
if (i.interessado_id)
textoAutor+= i.interessado.nome.mb_chars.upcase + "; "
elsif (i.orgao_externo_id)
textoAutor+= i.orgao_externo.nome.mb_chars.upcase+"; "
end
elsif (i.tipo_envolvimento.id == TipoEnvolvimento::INTERESSADO)
if (i.interessado_id)
textoInteressado+= i.interessado.nome.mb_chars.upcase + "; "
elsif (i.orgao_externo_id)
textoInteressado+= i.orgao_externo.nome.mb_chars.upcase+"; "
end
end
end
end
if !textoAutor.to_s.vazia?
tabela2.push([
"Autor:",
textoAutor.to_s
])
end
if !textoInteressado.to_s.vazia?
tabela2.push([
"Interessado:",
textoInteressado.to_s
])
end
tabela2.push(
[
"Tipo:",
processo.sub_tipo.tipo.descricao.mb_chars.upcase.to_s
]
)
tabela2.push(
[
"Subtipo:",
processo.sub_tipo.descricao.mb_chars.upcase.to_s
]
)
pdf.table tabela2, :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1, :size => size
rows(0..10).columns(0).font_style = :bold
end
pdf.table [
[
"Assunto:"
],
[
{:content => processo.assunto[0, 400].mb_chars.upcase.to_s, :align => :justify}
]
], :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1, :size => size
rows(0).columns(0).font_style = :bold
end
pdf.move_down 35
barcode = Barby::Code128B.new(processo.numero)
pdf.span(larguraMaxima, :position => margenEsquerda) do
barcode.annotate_pdf(pdf, :x => 70, :y => 0, :height => 30)
pdf.move_down 2
pdf.text processo.numero, :align => :center, :size => 9
end
return pdf
end
def self.espelho_pdf(processo)
size = 9
size2 = 10
size3 = 16
size4 = 13
pdf = Prawn::Document.new
pdf.font_families.update("Times" => {
:normal => {:file => "#{Rails.root.to_s}/app/assets/images/times_new_roman.ttf"},
:bold => {:file => "#{Rails.root.to_s}/app/assets/images/times_new_roman_bold.ttf"},
:italic => {:file => "#{Rails.root.to_s}/app/assets/images/times_new_roman_italic.ttf"},
:bold_italic => {:file => "#{Rails.root.to_s}/app/assets/images/times_new_roman_bold_italic.ttf"}
})
pdf.font "Times"
pdf.move_cursor_to 750
pdf.image Rails.root.to_s+ "/app/assets/images/brasao_alego_colorido_pequeno.png", :height => 80, :position => :center
pdf.move_down 5
pdf.text "ESTADO DE GOIÁS", :leading => 2, :size => 11, :align => :center
pdf.text "ASSEMBLEIA LEGISLATIVA", :leading => 2, :size => 11, :align => :center
pdf.move_down 10
pdf.font "Helvetica"
pdf.text "PROCESSO #{processo.categoria.descricao} #{processo.numero}".upcase, :style => :bold, :size => 27
pdf.move_down 5
pdf.font_size = size
origem = ""
autores_txt = ""
envolvidos_txt = ""
if (processo.orgao_externo_id == 0)
origem = "Origem: <strong>ASSEMBLEIA LEGISLATIVA - GO</strong>"
elsif (processo.orgao_externo_id > 0)
origem = "Origem: <strong>" + processo.orgao_externo.nome.mb_chars.upcase + "</strong>"
end
autores = []
interessados = []
if (processo.envolvidos)
processo.envolvidos.includes(:tipo_envolvimento).order("tipo_envolvimentos.descricao ASC").each do |i|
if (i.tipo_envolvimento.id == TipoEnvolvimento::AUTOR)
if (i.interessado_id)
autores.push(i.interessado.nome.mb_chars.upcase)
elsif (i.orgao_externo_id)
autores.push(i.orgao_externo.nome.mb_chars.upcase)
end
elsif (i.tipo_envolvimento.id == TipoEnvolvimento::INTERESSADO)
if (i.interessado_id)
interessados.push(i.interessado.nome.mb_chars.upcase)
elsif (i.orgao_externo_id)
interessados.push(i.orgao_externo.nome.mb_chars.upcase)
end
end
end
end
# Autores
if autores.any?
autores_txt = "Autor: <strong>#{autores.join(", ")}</strong>"
end
# Interessados
if interessados.any?
envolvidos_txt = "Interessados: <strong>#{interessados.join(", ")}</strong>"
end
numero_documento = ""
numero_documento = "Número Documento: <strong>#{processo.numero_documento}</strong>" if !processo.numero_documento.to_s.vazia? && !processo.legislativo?
pdf.table [
[
{:content => "Data autuação: <strong>#{processo.data.strftime("%d/%m/%Y")}</strong>", :inline_format => true, :width => 270},
{:content => "Tipo: <strong>#{processo.sub_tipo.tipo.descricao.mb_chars.upcase}</strong>", :inline_format => true, :width => 270}
],
[
{:content => origem, :inline_format => true},
{:content => "Subtipo: <strong>#{processo.sub_tipo.descricao.mb_chars.upcase}</strong>", :inline_format => true},
],
[
{:content => autores_txt, :inline_format => true},
{:content => envolvidos_txt, :inline_format => true}
],
[
{:content => numero_documento, :inline_format => true}, ""
],
[
{:content => "Assunto: <strong>" + processo.assunto.html_safe + "</strong>", :inline_format => true, :colspan => 2}
]
], :width => 540, :cell_style => {:borders => []} do
cells.style :padding => 1
end
pdf.move_down 15
# DADOS LEGISLATIVOS
if processo.legislativo? && processo.processo_legislativos.any?
dados_legislativos = processo.processo_legislativos.first
subtipo_descricao = processo.sub_tipo.nome_apresentavel
protocolo_numero_oficio_mensagem = "Número ofício mensagem: <strong>#{dados_legislativos.numero_oficio_mensagem}</strong>" if !dados_legislativos.numero_oficio_mensagem.to_s.vazia?
protocolo_numero_oficio = "Número ofício: <strong>#{dados_legislativos.num_oficio}</strong>" if !dados_legislativos.num_oficio.to_s.vazia?
if protocolo_numero_oficio || protocolo_numero_oficio_mensagem
titulo_protocolo = "<strong>Protocolo</strong>"
end
autografo_numero_autografo = "Número autógrafo #{subtipo_descricao}: <strong>#{dados_legislativos.num_autografo}</strong>" if !dados_legislativos.num_autografo.to_s.vazia?
autografo_data_autografo = "Data autógrafo #{subtipo_descricao}: <strong>#{dados_legislativos.data_autografo.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_autografo
autografo_numero_oficio = "Número do Ofício: <strong>#{dados_legislativos.autografo_numero_oficio}</strong>" if !dados_legislativos.autografo_numero_oficio.to_s.vazia?
autografo_data_envio_governadoria = "Data de envio a governadoria: <strong>#{dados_legislativos.data_envio_governadoria.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_envio_governadoria
autografo_data_oficio = "Data ofício: <strong>#{dados_legislativos.autografo_data_oficio.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.autografo_data_oficio
if autografo_numero_autografo || autografo_data_autografo || autografo_numero_oficio || autografo_data_envio_governadoria || autografo_data_oficio
titulo_autografo = ""
titulo_autografo = "<br/>" if titulo_protocolo
titulo_autografo += "<strong>Autógrafo</strong>"
end
lei_numero = "Número #{subtipo_descricao}: <strong>#{dados_legislativos.num_lei}</strong>" if !dados_legislativos.num_lei.to_s.vazia?
lei_data = "Data #{subtipo_descricao}: <strong>#{dados_legislativos.data_lei.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_lei
lei_diario = "Número diário oficial: <strong>#{dados_legislativos.num_diario}</strong>" if !dados_legislativos.num_diario.to_s.vazia?
lei_diario_data = "Data diário oficial: <strong>#{dados_legislativos.data_diario.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_diario
lei_numero_da_promulgacao = "Número diário oficial de promulgação: <strong>#{dados_legislativos.numero_dop}</strong>" if !dados_legislativos.numero_dop.to_s.vazia?
lei_data_da_promulgacao = "Data diário oficial de promulgação: <strong>#{dados_legislativos.data_dop.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_dop
lei_numero_da = "Número diário da assembleia: <strong>#{dados_legislativos.numero_da}</strong>" if !dados_legislativos.numero_da.to_s.vazia?
lei_data_da = "Data diário da assembleia: <strong>#{dados_legislativos.data_da.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_da
if lei_numero || lei_data || lei_diario || lei_diario_data || lei_diario_data || lei_numero_da_promulgacao || lei_numero_da
titulo_lei = "<strong>Dados legislativos</strong>"
end
veto_votacao = "Votação Veto: <strong>#{dados_legislativos.votacao_veto}</strong>" if !dados_legislativos.votacao_veto.to_s.vazia?
veto_data = "Data Veto: <strong>#{dados_legislativos.data_veto.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.data_veto
veto_numero_oficio = "Número Ofício: <strong>#{dados_legislativos.veto_numero_oficio}</strong>" if !dados_legislativos.veto_numero_oficio.to_s.vazia?
veto_data_envio = "Data Envio: <strong>#{dados_legislativos.veto_data_envio.strftime("%d/%m/%Y")}</strong>" if dados_legislativos.veto_data_envio
veto_situacao = "Situação: <strong>#{dados_legislativos.situacao_veto}</strong>" if !dados_legislativos.situacao_veto.to_s.vazia?
if veto_votacao || veto_data || veto_numero_oficio || veto_data_envio || veto_situacao
titulo_veto = ""
titulo_veto = "<br/>" if titulo_lei
titulo_veto = "<br/><strong>Veto</strong>"
end
if titulo_lei || titulo_protocolo || titulo_veto || titulo_autografo
pdf.text "<strong>Informações legislativas</strong>", :inline_format => true, :size => size3
end
coluna1 = []
coluna2 = []
coluna1.push(titulo_protocolo) if titulo_protocolo
coluna1.push(protocolo_numero_oficio_mensagem) if protocolo_numero_oficio_mensagem
coluna1.push(protocolo_numero_oficio) if protocolo_numero_oficio
coluna1.push(titulo_autografo) if titulo_autografo
coluna1.push(autografo_numero_autografo) if autografo_numero_autografo
coluna1.push(autografo_data_autografo) if autografo_data_autografo
coluna1.push(autografo_numero_oficio) if autografo_numero_oficio
coluna1.push(autografo_data_oficio) if autografo_data_oficio
coluna1.push(autografo_data_envio_governadoria) if autografo_data_envio_governadoria
coluna2.push(titulo_lei) if titulo_lei
coluna2.push(lei_numero) if lei_numero
coluna2.push(lei_data) if lei_data
coluna2.push(lei_diario) if lei_diario
coluna2.push(lei_diario_data) if lei_diario_data
coluna2.push(lei_numero_da_promulgacao) if lei_numero_da_promulgacao
coluna2.push(lei_data_da_promulgacao) if lei_data_da_promulgacao
coluna2.push(lei_numero_da) if lei_numero_da
coluna2.push(lei_data_da) if lei_data_da
coluna2.push(titulo_veto) if titulo_veto
coluna2.push(veto_votacao) if veto_votacao
coluna2.push(veto_data) if veto_data
coluna2.push(veto_numero_oficio) if veto_numero_oficio
coluna2.push(veto_data_envio) if veto_data_envio
coluna2.push(veto_situacao) if veto_situacao
pdf.table [
[
{:content => coluna1.join("<br/>"), :inline_format => true, :width => 270},
{:content => coluna2.join("<br/>"), :inline_format => true, :width => 270}
]
], :width => 540, :cell_style => {:borders => []} do
cells.style :padding => 1, :size => size2
end
end
#tramitação
acoes = ProcessoAcao.where(:processo_id => processo.id).order("created_at DESC")
pdf.move_down 20
linhas = [
[
{:content => "Data", :width => 100},
{:content => "Lotação", :width => 140},
{:content => "Ação", :width => 300}
]
]
acoes.each do |a|
linhas.push(
[
a.created_at.strftime("%d/%m/%Y às %H:%M"),
(a.lotacao_id ? a.lotacao.descricao : ""),
{:content => a.acao.html_safe, :inline_format => true}
]
)
end
pdf.table linhas, :width => 540 do
rows(0).columns(0..2).background_color = "424242"
rows(0).columns(0..2).text_color = "ffffff"
rows(0).columns(0..2).size = size4
rows(0).columns(0..2).font_style = :bold
linha = 1
while (linha < linhas.count)
if linha % 2 == 0
rows(linha).columns(0..2).background_color = "eeeeee"
end
linha += 1
end
end
return pdf
end
def self.path_pdf_completo(processo)
path_pdf_final = Rails.root.to_s + "/app/assets/tmp/processo_"+ processo.numero + "_" + Time.new.to_i.to_s + ".pdf"
documentos_anexos = Anexo.find_by_sql(
"
SELECT * FROM (
(
SELECT d.id, 'documento' as tipo, d.modelo_documento_id, '' as arquivo, d.created_at
FROM documentos as d WHERE d.processo_id = #{processo.id} AND d.assinado IS TRUE
)
UNION
(
SELECT a.id, 'anexo' as tipo, '0' as modelo_documento_id, a.arquivo, a.created_at
FROM anexos as a WHERE a.processo_id = #{processo.id}
)
) as union_sql ORDER BY created_at ASC
"
)
if documentos_anexos.size == 1
d = documentos_anexos.first
pdf_file = ""
if d.tipo == 'anexo'
pdf_file = Rails.root.to_s + "/app/assets/processos/anexos/" + d.arquivo
elsif d.tipo == "documento"
pdf_file = DocumentosHelper.gerar_path(d)
if !DocumentosHelper.checar_existencia_arquivo_fisico?(d)
pdf_file = DocumentosHelper.gerar_arquivo_fisico(d)
end
end
path_pdf_final = pdf_file
elsif documentos_anexos.size > 1
paths = []
documentos_anexos.each do |d|
pdf_file = ""
if d.tipo == 'anexo'
pdf_file = Rails.root.to_s + "/app/assets/processos/anexos/" + d.arquivo
elsif d.tipo == "documento"
pdf_file = DocumentosHelper.gerar_path(d)
if !DocumentosHelper.checar_existencia_arquivo_fisico?(d)
pdf_file = DocumentosHelper.gerar_arquivo_fisico(d)
end
end
paths << pdf_file
end
command_path = "/usr/local/bin/pdfunite " + paths.join(" ") + " " + path_pdf_final
system(command_path)
end
return path_pdf_final
end
def self.zip(processo)
dir = Rails.root.to_s + "/app/assets/tmp/"
if !File.exists?(dir)
Dir.mkdir(dir)
end
dirInto = "processo_#{processo.numero}"
dirIntoDocumentos = dirInto + "/documentos"
zipFileName = "processo_#{processo.numero}.zip"
zipFilePath = dir + zipFileName
if FileTest.exists?(zipFilePath)
FileUtils.rm(zipFilePath)
end
documentosCriados = []
nomes = []
zip = Zip::ZipFile.open(zipFilePath, Zip::ZipFile::CREATE) do |z|
z.mkdir(dirIntoDocumentos)
processo.anexos.order("created_at ASC").each do |anexo|
descricao_formatada = anexo.descricao.gsub(/[^0-9a-zA-Z]/, "")
nomeArquivo = anexo.arquivo
if nomes.include?(descricao_formatada)
descricao_formatada = descricao_formatada + "_" + nomes.size.to_s
end
anexoPath = Rails.root.to_s + "/app/assets/processos/anexos/" + anexo.arquivo
if File.exists?(anexoPath)
z.add("#{dirIntoDocumentos}/#{descricao_formatada}.pdf", anexoPath)
nomes.push(descricao_formatada)
end
end
processo.documentos.where("documentos.assinado = TRUE").order("created_at ASC").each do |d|
pdf = ModelosHelper.pdf(d.id, d.modelo_documento_id)
if (pdf)
if !File.exists?(dir + processo.id.to_s + "/")
Dir.mkdir(dir + processo.id.to_s + "/");
end
filename = dir + "#{processo.id.to_s}_#{d.id}_.pdf"
documentosCriados << filename
pdf.render_file(filename);
z.add("#{dirIntoDocumentos}/#{d.modelo_documento.nome_action}_#{d.id}.pdf", filename)
end
end
end
documentosCriados.each do |a|
FileUtils.rm(a)
end
return zipFilePath
end
def self.capa_pdf(processo)
larguraMaxima = 280
margenEsquerda = 140
margenEsquerda2 = 200
largura_tabela = 300
fundo = Rails.root.to_s+ "/app/assets/images/capa_processo.jpg"
pdf = Prawn::Document.new :page_layout => :portrait, :margin => [0, 0, 0, 100], :page_size => "A4"
pdf.image fundo, :width => pdf.bounds.width + 101, :height => pdf.bounds.height, :at => [-101, pdf.bounds.height]
size = 8
categoria = ""
pdf.move_cursor_to 370
if (processo.categoria_id == Processo::CATEGORIA_ADMINISTRATIVO)
categoria = "PROCESSO ADMINISTRATIVO"
elsif (processo.categoria_id == Processo::CATEGORIA_LEGISLATIVO)
categoria = "PROCESSO LEGISLATIVO"
end
pdf.font_families.update("Arial" => {
:normal => {:file => "#{Rails.root.to_s}/app/assets/images/Arial.ttf"},
:bold => {:file => "#{Rails.root.to_s}/app/assets/images/Arial_Bold.ttf"}
})
pdf.font "Arial"
#pdf.move_cursor_to 780
pdf.table [
[{:content => categoria, :size => 6, :inline_format => true, :align => :center}],
[{:content => "Nº " + processo.numero, :size => 12, :inline_format => true, :align => :center, :font_style => :bold}]
], :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1
end
pdf.move_down 3
if processo.legislativo?
dados_legislativos = ProcessoLegislativo.where(:processo_id => processo.id).first
end
numero_oficio_msg = ""
label_numero_oficio_msg = ""
numero_oficio = ""
label_numero_oficio = ""
numero_documento = ""
label_numero_documento = ""
numero_documento = ""
label_documento = ""
up = 0
if dados_legislativos
valor_numero_projeto = dados_legislativos.projeto_numero.to_s
if !valor_numero_projeto.to_s.vazia?
numero_documento = valor_numero_projeto
label_documento = "Projeto :"
end
valor_numero_oficio = dados_legislativos.num_oficio.to_s
if !valor_numero_oficio.to_s.vazia? && numero_documento.to_s.vazia?
numero_documento = valor_numero_oficio
label_documento = "Nº Ofício:"
end
valor_numero_oficio_msg = dados_legislativos.numero_oficio_mensagem.to_s
if !valor_numero_oficio_msg.to_s.vazia? && numero_documento.to_s.vazia?
numero_documento = valor_numero_oficio_msg
label_documento = "Nº Ofício MSG:"
end
tabela = [
[
{:content => "Data Autuação:", :width => 65},
{:content => processo.data.strftime("%d/%m/%Y"), :width => 90},
{:content => label_documento, :width => 65, :align => :right},
{:content => numero_documento, :align => :right}
]
]
else
valor_numero_documento = processo.numero_documento.to_s
if !valor_numero_documento.to_s.vazia?
numero_documento = valor_numero_documento
label_numero_documento = "Nº Documento:"
end
tabela = [
[
{:content => "Data Autuação:", :width => 65},
{:content => processo.data.strftime("%d/%m/%Y")},
{:content => label_numero_documento, :width => 65},
{:content => numero_documento}
]
]
end
pdf.table tabela, :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1, :size => size
rows(0..10).columns([0, 2]).font_style = :bold
end
pdf.move_up up
origem = "ASSEMBLEIA LEGISLATIVA - GO"
origem = processo.orgao_externo.nome.mb_chars.upcase.to_s if processo.orgao_externo_id != 0
tabela2 = [
[
{:content => "Origem:", :width => 50},
{:content => origem}
]
]
textoAutor = ""
textoInteressado = ""
if (processo.envolvidos)
processo.envolvidos.includes(:tipo_envolvimento).order("tipo_envolvimentos.descricao ASC").each do |i|
if (i.tipo_envolvimento.id == TipoEnvolvimento::AUTOR)
if (i.interessado_id)
textoAutor+= i.interessado.nome.mb_chars.upcase + "; "
elsif (i.orgao_externo_id)
textoAutor+= i.orgao_externo.nome.mb_chars.upcase+"; "
end
elsif (i.tipo_envolvimento.id == TipoEnvolvimento::INTERESSADO)
if (i.interessado_id)
textoInteressado+= i.interessado.nome.mb_chars.upcase + "; "
elsif (i.orgao_externo_id)
textoInteressado+= i.orgao_externo.nome.mb_chars.upcase+"; "
end
end
end
end
if !textoAutor.to_s.vazia?
tabela2.push([
"Autor:",
textoAutor.to_s
])
end
if !textoInteressado.to_s.vazia?
tabela2.push([
"Interessado:",
textoInteressado.to_s
])
end
tabela2.push(
[
"Tipo:",
processo.sub_tipo.tipo.descricao.mb_chars.upcase.to_s
]
)
tabela2.push(
[
"Subtipo:",
processo.sub_tipo.descricao.mb_chars.upcase.to_s
]
)
pdf.table tabela2, :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1, :size => size
rows(0..10).columns(0).font_style = :bold
end
pdf.table [
[
"Assunto:"
],
[
{:content => processo.assunto[0, 400].mb_chars.upcase.to_s, :align => :justify}
]
], :width => largura_tabela, :position => :center, :cell_style => {:borders => []} do
cells.style :padding => 1, :size => size
rows(0).columns(0).font_style = :bold
end
pdf.move_down 35
barcode = Barby::Code128B.new(processo.numero)
pdf.span(larguraMaxima, :position => :center) do
barcode.annotate_pdf(pdf, :x => 70, :y => 0, :height => 30)
pdf.move_down 2
pdf.text processo.numero, :align => :center, :size => 9
end
return pdf
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment