Created
October 25, 2014 15:03
-
-
Save erickpereira/193d146ec38226d5f06c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrcamentosController < ApplicationController | |
#... | |
def show | |
@orcamento = @cliente.orcamentos.find(params[:id]) | |
respond_to do |format| | |
format.html | |
format.pdf do | |
filename = "Orç " + @orcamento.cliente.nome + " " + @orcamento.id.to_s | |
pdf = PdfOrcamento.new(@cliente,@cliente.orcamentos.find(params[:id])) | |
send_data(pdf.generate.render, :type => "application/pdf", :filename => filename, :disposition => 'attachment') | |
end | |
end | |
end | |
#... | |
end | |
class PdfOrcamento < Prawn::Document | |
def initialize(cliente, orcamento) | |
@cliente = cliente | |
@orcamento = orcamento | |
end | |
def generate | |
Prawn::Document.new(options) do |pdf| | |
pdfOrcamento(pdf) | |
end | |
end | |
protected | |
def pdfOrcamento(pdf) | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 30, :align => :center) do | |
pdf.font_size(30) do | |
pdf.move_down 2 | |
pdf.stroke_bounds | |
pdf.text "Orçamento" , :align => :center | |
pdf.move_up 35 | |
pdf.text "Nº:" + @orcamento.id.to_s , :align => :right | |
end | |
end | |
pdf.move_down 15 | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 20, :align => :center) do | |
pdf.move_down 4 | |
pdf.stroke_bounds | |
pdf.text "Dados do cliente" , :align => :center | |
end | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 80) do | |
pdf.move_down 4 | |
pdf.text " Cliente: " + @cliente.nome | |
pdf.text " Endereço: " + @cliente.endereco | |
pdf.text " Bairro: " + @cliente.bairro | |
pdf.text " Cidade: " + @cliente.municipio | |
pdf.text " Telefone: " + @cliente.telefone | |
pdf.stroke_bounds | |
end | |
pdf.move_down 15 | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 20, :align => :center) do | |
pdf.move_down 4 | |
pdf.stroke_bounds | |
pdf.text "Dados do orçamento" , :align => :center | |
end | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 60) do | |
pdf.move_down 4 | |
pdf.text " Descrição: " + @orcamento.descricao | |
pdf.text " Situação: " + @orcamento.situacao | |
pdf.text " Validade: " + I18n.l(@orcamento.validade, format: :long).to_s | |
pdf.stroke_bounds | |
end | |
pdf.move_down 15 | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 20, :align => :center) do | |
pdf.move_down 4 | |
pdf.stroke_bounds | |
pdf.text "Itens do orçamento" , :align => :center | |
end | |
cont = 1 | |
@orcamento.items.each do |item| | |
cont = cont + 1 | |
if 0.eql?(cont.remainder 5) | |
pdf.start_new_page | |
pdf.move_cursor_to 710 | |
end | |
pdf.bounding_box([0, pdf.cursor], :width => 550, :height => 129) do | |
pdf.move_down 4 | |
pdf.text "Descrição: " + item.descricao | |
pdf.text "Equipamento: " + item.produto | |
pdf.text "Serviço: " + item.tipo_Servico | |
pdf.text "Quantidade: " + item.qtdequipamento.to_s | |
pdf.text "Potência: " + item.potencia + " " + item.unidade_medida | |
pdf.text "Valor: R$ " + item.valor.to_s | |
pdf.text " Inf Adicionais " + item.info | |
pdf.stroke_bounds | |
#pdf.stroke_horizontal_rule | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment