Skip to content

Instantly share code, notes, and snippets.

@esmerino
Created April 6, 2016 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmerino/6646c5971eb8010dab1c76912bb885e7 to your computer and use it in GitHub Desktop.
Save esmerino/6646c5971eb8010dab1c76912bb885e7 to your computer and use it in GitHub Desktop.
class ReportResumoPorFuncionarioMatriz < Prawn::Document
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TextHelper
def initialize(params = {})
super(:page_size => "A4", :page_layout => :landscape)
@pedidos = params.fetch(:pedidos)
body
end
def body
image "#{Rails.root.to_s+"/app/assets/images/logo.jpg"}", :at => [0, 530]
repeat(:all, :dynamic => true) do
font_size(8) do
draw_text "#{page_number}/#{page_count}", :at => [730, 530]
end
end
move_down 8
font_size(13) do
text "RESUMO POR FUNCIONÁRIOS", align: :center
end
stroke do
move_down 40
horizontal_rule
end
move_down 4
font_size(9) do
text "Emitido em #{Time.now.strftime("%d/%m/%Y")}", align: :right
end
move_down 8
@pedidos.each do |pedido|
data_head = [
["<b>Empresa:</b> #{pedido.nome_fantasia}", "<b>Cnpj:</b> #{pedido.cnpj}", "<b>Pedido:<b> #{pedido.id}"],
]
table(data_head, cell_style: { size: 9, border_width: 0, inline_format: true, padding: 2 }) do
column(0).style align: :left, width: 469
column(1).style align: :left, width: 150
column(2).style align: :left, width: 150
end
data = [["<b>Nome</b>", "<b>CPF</b>",
"<b>Matrícula</b>", "<b>Departamento</b>",
"<b>Total</b>"]]
@total = []
pedido.pedido_funcionario_produtos
.select("nome, cpf, matricula, departamento, sum(total) as total")
.group("nome, cpf, matricula, departamento").map do |pedido_funcionario_produto|
@total << pedido_funcionario_produto.total
data << [pedido_funcionario_produto.nome,
pedido_funcionario_produto.cpf,
pedido_funcionario_produto.matricula,
pedido_funcionario_produto.departamento,
number_to_currency(pedido_funcionario_produto.total)
]
end
data << ["","","","", number_to_currency(@total.reduce(&:+))]
table(data, cell_style: { size: 6, border_width: 0.5, inline_format: true, padding: 2, background_color: "dcdcdc"}) do
column(0).style align: :left, width: 350
column(1).style align: :center, width: 80
column(2).style align: :center, width: 80
column(3).style align: :center, width: 170
column(4).style align: :right, width: 80
end
move_down 8
end
end
def filename
"Resumo por Funcionários"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment