Skip to content

Instantly share code, notes, and snippets.

@pedromtavares
Created March 26, 2010 12:35
Show Gist options
  • Save pedromtavares/344836 to your computer and use it in GitHub Desktop.
Save pedromtavares/344836 to your computer and use it in GitHub Desktop.
class CustomReports
def self.relatorio_geral(imobiliaria,tipo, collection, block)
RGhost::Document.new :paper => :A4, :margin_left => 0.2, :margin_right => 0.2, :margin_bottom => 2 do |doc|
doc.define_tags do
tag :small, :name => 'Verdana', :size => 12
tag :default, :name => 'Verdana', :size => 15
tag :title, :name => 'Verdana', :size => 17
tag :header1, :name => 'Verdana', :size => 20
tag :header2, :name => 'Verdana', :size => 26
end
doc.before_page_create do |chunk|
chunk.text_in :x => 1, :y => 29, :write => imobiliaria.nome, :tag => :small
chunk.text_in :x => 16, :y => 29, :write => I18n.l(Time.now, :format => :short), :tag => :small
chunk.text_in :x=> 18, :y=> 1, :text => "Página %current_page%", :tag => :small
end
2.times {doc.next_row}
doc.show "Relatório de #{tipo.capitalize}", :with => :header2, :align => :page_center
2.times {doc.next_row}
doc.rails_grid :x => -3 do |grid|
grid.even_row do |r|
r.background_row(:content => {:fill => true, :color => '#FFF'})
end
grid.before_row do |r|
r.horizontal_line(:top, :size => 20.5 )
end
block.call(grid)
grid.data(collection)
end
end
end
end
block = lambda do |grid|
grid.column :nome, :title => "Nome", :format => Default
unless lambda{contato.blank?}
grid.column 'contato.email', :title => "Email", :width => 2.5, :format => Default
grid.column 'contato.telefone', :title => "Telefone", :width => 2.5, :format => Default
grid.column 'contato.celular', :title => "Celular", :width => 2.5, :format => Default
end
grid.column :cpf, :title => "CPF", :width => 2, :format => Default
grid.column :cnpj, :title => "CNPJ", :width => 2, :format => Default
unless lambda{endereco.blank?}
grid.column 'endereco.bairro', :title => "Bairro", :width => 2.5
grid.column 'endereco.cidade', :title => "Cidade", :width => 2.5
end
end
CustomReports.relatorio_geral imobiliaria_atual, 'clientes', @clientes, block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment