Class: Ubill::Invoice

Inherits:
Object
  • Object
show all
Includes:
Prawn::View, Concerns::Configurable
Defined in:
lib/ubill/invoice.rb

Constant Summary collapse

COLOR_SECONDARY =
"777777"
EXTERNAL_FONTS_DIR =
File.join(__dir__, "fonts")

Instance Method Summary collapse

Methods included from Concerns::Configurable

#configure

Constructor Details

#initialize {|_self| ... } ⇒ Invoice

Returns a new instance of Invoice.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ubill/invoice.rb', line 15

def initialize
  super()
  @recipient = {}
  @subject = ""
  @subject_info = ""
  @positions = [["#", "Beschreibung", "Einzelpreis", "Menge", "Gesamt"]]
  @total = ""
  @due = ""
  @addendum = ""

  load_external_font_families

  yield(self) if block_given?
end

Instance Method Details

#addendum(value) ⇒ Object



57
58
59
# File 'lib/ubill/invoice.rb', line 57

def addendum(value)
  @addendum = value
end

#configObject



62
63
64
# File 'lib/ubill/invoice.rb', line 62

def config
  Ubill.config
end

#documentObject



66
67
68
# File 'lib/ubill/invoice.rb', line 66

def document
  @doc ||= Prawn::Document.new(config.options)
end

#due(value) ⇒ Object



53
54
55
# File 'lib/ubill/invoice.rb', line 53

def due(value)
  @due = value
end

#heightObject



74
75
76
# File 'lib/ubill/invoice.rb', line 74

def height
  bounds.top_left[1]
end

#margin_bottomObject



86
87
88
# File 'lib/ubill/invoice.rb', line 86

def margin_bottom
  config.options[:margin][2]
end

#margin_leftObject



90
91
92
# File 'lib/ubill/invoice.rb', line 90

def margin_left
  config.options[:margin][3]
end

#margin_rightObject



82
83
84
# File 'lib/ubill/invoice.rb', line 82

def margin_right
  config.options[:margin][1]
end

#margin_topObject



78
79
80
# File 'lib/ubill/invoice.rb', line 78

def margin_top
  config.options[:margin][0]
end

#position(name:, description:, price_per_unit:, units:, price:) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/ubill/invoice.rb', line 39

def position(name:, description:, price_per_unit:, units:, price:)
  @positions << [
    @positions.size,
    "<b>#{name}</b><font size=\"9\">\n#{description}</font>",
    price_per_unit,
    units,
    price
  ]
end

#recipient(**options) ⇒ Object



30
31
32
# File 'lib/ubill/invoice.rb', line 30

def recipient(**options)
  @recipient.merge!(options)
end

#render(*args, **options) ⇒ Object



99
100
101
102
# File 'lib/ubill/invoice.rb', line 99

def render(*args, **options)
  describe
  super
end

#save_as(*args, **options) ⇒ Object



94
95
96
97
# File 'lib/ubill/invoice.rb', line 94

def save_as(*args, **options)
  describe
  super
end

#subject(title, subtitle = nil) ⇒ Object



34
35
36
37
# File 'lib/ubill/invoice.rb', line 34

def subject(title, subtitle=nil)
  @subject = title
  @subject_info = subtitle
end

#total(value) ⇒ Object



49
50
51
# File 'lib/ubill/invoice.rb', line 49

def total(value)
  @total = value
end

#widthObject



70
71
72
# File 'lib/ubill/invoice.rb', line 70

def width
  bounds.top_right[0]
end