Class: Prawn::LetterDocument

Inherits:
Document
  • Object
show all
Includes:
ActionView::Helpers::TranslationHelper, ApplicationHelper, EsrRecipe, Measurements
Defined in:
lib/prawn/letter_document.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#currency_fmt, #current_tenant, #engine_stylesheet_link_tag, #icon_delete_link_to, #icon_edit_link_to, #list_item_actions_for, #show_new_form

Constructor Details

#initialize(opts = {}) ⇒ LetterDocument

Returns a new instance of LetterDocument.



11
12
13
14
15
16
17
# File 'lib/prawn/letter_document.rb', line 11

def initialize(opts = {})
  super
  
  # Default Font
  font  'Helvetica'
  font_size 11
end

Instance Method Details

#closing(sender, due_date) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/prawn/letter_document.rb', line 78

def closing(sender, due_date)
  text I18n.t('letters.debit_invoice.closing', :due_date => due_date), :align => :justify

  text " "
  text " "

  text I18n.t('letters.greetings')
  text " "
  text "#{sender.vcard.full_name}"
end


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/prawn/letter_document.rb', line 36

def footer(sender, )
  repeat :all do
    bounding_box [bounds.left, 35], :width => 120, :height => 40 do
      font_size 7 do
        vcard = sender.vcard

        text "Begünstigter:"
        text vcard.full_name
        text vcard.extended_address unless vcard.extended_address.blank?
        text vcard.street_address
        text vcard.postal_code + " " + vcard.locality
      end
    end

    if  and .bank
      bounding_box [bounds.left + 190, 35], :width => 120, :height => 40 do
        font_size 7 do
          vcard = .bank.vcard

          text "Bank:"
          text vcard.full_name
          text vcard.street_address if vcard.street_address.present?
          locality = [vcard.postal_code, vcard.locality].compact.join(', ')
          text locality if locality.present?
        end
      end

      bounding_box [bounds.left + 360, 35], :width => 120, :height => 40 do
        font_size 7 do
          vcard = .bank.vcard

          text "Konto:"
          text "IBAN: " + .iban if .iban.present?
          text "SWIFT: " + .bank.swift if .bank.swift.present?
          text "Clearing: " + .bank.clearing if .bank.clearing.present?
          text "PC-Konto: " + .pc_id if .pc_id.present?
        end
      end
    end
  end
end

#full_address(vcard) ⇒ Object

Draws the full address of a vcard



20
21
22
23
24
# File 'lib/prawn/letter_document.rb', line 20

def full_address(vcard)
  vcard.full_address_lines.each do |line|
    text line
  end
end

#header(sender) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/prawn/letter_document.rb', line 26

def header(sender)
  repeat :all do
    # TODO use uploaded file from tenant
    # TODO think about requiring prawn-fast-png or only use PNGs with no transparency
    # You better use a bigger file as it gives better resolution
     = ::Rails.root.join("public/system/images/letter-logo.png")
    image , :height => 50, :at => [0, bounds.top + 20] if .exist?
  end
end

#line_items_table(invoice, line_items) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/prawn/letter_document.rb', line 89

def line_items_table(invoice, line_items)
  content = line_items.collect do |item|

    if item.times == 1
      if item.quantity == "x"
        amount = ""
      elsif item.quantity == "overall"
        amount = t('line_items.quantity.overall')
      else
        amount = "#{item.times} #{t(item.quantity, :scope => 'line_items.quantity')}"
      end
    else
      amount = "#{currency_fmt(item.times)} #{t(item.quantity, :scope => 'line_items.quantity')}"
    end

   price = currency_fmt(item.price)

   [item.title, item.date, amount, price, currency_fmt(item.total_amount)]
  end

  total = ["Total", nil, nil, nil, currency_fmt(invoice.amount)]

  rows = content + [total]
  table(rows, :width => bounds.width) do

    # General cell styling
    cells.valign  = :top
    cells.borders = []

    # Columns
    columns(2..4).align = :right
    column(1).width = 65
    column(2).width = 75
    column(3).width = 65
    column(4).width = 65
    column(0).padding_left = 0
    column(-1).padding_right = 0

    # Footer styling
    row(-1).font_style = :bold
  end
end

#payment_order(sender, bank_account, invoice) ⇒ Object



132
133
134
# File 'lib/prawn/letter_document.rb', line 132

def payment_order(sender, , invoice)
  draw_text invoice.esr9(), :at => [cm2pt(5.2), 0]
end