Sha256: e55cb68e023826371af9dd07c363f010f014a82acffa285ce70f1c82d2c138e9

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'prawn/measurement_extensions'
# Unescape HTML
def html_unescape(value)
  # Return an empty string when value is nil.
  return '' unless value

  result = value

  result.gsub!(/<div>|<p>|<br>/, '')
  result.gsub!(/<\/div>|<\/p>|<\/br>|<br[ ]*\/>/, "\n")

  return result
end

prawn_document(:page_size => 'A4',  :top_margin => 60, :left_margin => 50, :right_margin => 55, :renderer => Prawn::LetterDocument) do |pdf|
  receiver = @debit_invoice.customer
  sender = @debit_invoice.company

  # Header
  pdf.header(sender)

  pdf.move_down 60

  # Address
  pdf.indent 320 do
    pdf.full_address(receiver.vcard)
  end

  pdf.move_down 60

  # Place'n'Date
  pdf.indent 320 do
    pdf.text sender.vcard.locality + ", " + I18n.l(Date.today, :format => :long)
  end

  # Subject
  pdf.move_down 60
  pdf.text @debit_invoice.to_s, :style => :bold

  # Freetext
  pdf.text " "
  pdf.text html_unescape(@debit_invoice.text), :inline_format => true if @debit_invoice.present?
  pdf.text " "

  # Line Items
  pdf.text " "
  pdf.line_items_table(@debit_invoice, @debit_invoice.line_items)

  # Closing
  pdf.text " "
  pdf.closing(@debit_invoice.company, @debit_invoice.due_date)

  # Footer
  pdf.bounding_box [12 - pdf.bounds.absolute_left, 23 - pdf.bounds.absolute_bottom], :width => pdf.bounds.width do
    pdf.esr_recipe(@debit_invoice, BankAccount.find_by_code('1020'), sender)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bookyt-0.0.1 app/views/debit_invoices/letter.pdf.prawn