Class: InvoiceCreator::Services::InvoicePrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/invoice_creator/services/invoice_printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(presenter:) ⇒ InvoicePrinter

Returns a new instance of InvoicePrinter.



7
8
9
10
# File 'lib/invoice_creator/services/invoice_printer.rb', line 7

def initialize(presenter:)
  @presenter = presenter
  @prawn = Prawn::Document.new
end

Instance Method Details



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/invoice_creator/services/invoice_printer.rb', line 12

def print
  @prawn.define_grid(:columns => 5, :rows => 8, :gutter => 10)

  @prawn.grid([0,3], [0,4]).bounding_box do
    @prawn.text "<b>INVOICE</b>", size: 30, align: :right, inline_format: true
  end

  @prawn.grid([1,3], [1,4]).bounding_box do
    @prawn.text "<b>Invoice#</b> #{@presenter.invoice_identifier}", align: :right, inline_format: true
    @prawn.move_down 5
    @prawn.text "<b>Invoice Date</b> #{@presenter.date}", align: :right, inline_format: true
    @prawn.move_down 5
    @prawn.text "<b>Due Date</b> #{@presenter.due_date}", align: :right, inline_format: true
  end

  @prawn.grid([0,0], [0,2]).bounding_box do
    @prawn.text "<b>From</b>", align: :left, inline_format: true
    @prawn.text @presenter.from
  end

  @prawn.grid([1,0], [1,2]).bounding_box do
    @prawn.text "<b>To</b>", align: :left, inline_format: true
    @prawn.text @presenter.to
  end

  @prawn.table([%w[Item HRS/QTY Rate Amount], *rows], row_colors: ["F0F0F0", "FFFFFF"], width: 550)

  @prawn.move_down 20
  @prawn.text "<b>Total (#{@presenter.currency_abbreviation}) #{@presenter.total}</b>", align: :right, inline_format: true
  @prawn.move_down 20
  @prawn.stroke_horizontal_rule
  @prawn.move_down 20

  @prawn.text @presenter.extra_info, inline_format: true

  @prawn.render_file @presenter.filename
end