Class: PurchaseOrder::PdfGenerator

Inherits:
BaseService show all
Includes:
Pdf::Base
Defined in:
app/services/purchase_order/pdf_generator.rb

Constant Summary

Constants included from Pdf::Base

Pdf::Base::FONT, Pdf::Base::NIMBUS_SANS_PATH, Pdf::Base::NIMBUS_SANS_PATH_BOLD, Pdf::Base::WY_LOGO_PATH

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #process, #tagged_logger

Constructor Details

#initialize(purchase_order) ⇒ PdfGenerator

Returns a new instance of PdfGenerator.



4
5
6
7
8
# File 'app/services/purchase_order/pdf_generator.rb', line 4

def initialize(purchase_order)
  @po = purchase_order
  @store = @po.store
  @currency_symbol = Money::Currency.new(purchase_order.currency).symbol
end

Instance Method Details

#generateObject



10
11
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
# File 'app/services/purchase_order/pdf_generator.rb', line 10

def generate
  composer = build_composer(margin: [100, 40, 60, 40])

  add_header(composer)
  add_po_details(composer)
  add_line_items(composer)

  if @po.drop_ship?
    composer.formatted_text([
                              { text: 'Please e-mail ', style: { font: "#{FONT} bold", font_size: 11, line_height: 12 } },
                              { text: ACCOUNTS_PAYABLE_EMAIL, style: { font: "#{FONT} bold", font_size: 11, fill_color: '0000ed', underline: true, line_height: 12 } },
                              { text: ' with tracking numbers, weight and shipping dimensions for each package shipped, and the total actual shipping cost. Please make sure you include PO NUMBER ',
                                style: { font: "#{FONT} bold", font_size: 11, line_height: 12 } },
                              { text: @po.reference_number, style: { font: "#{FONT} bold", font_size: 11, line_height: 12 } },
                              { text: '. Thank You!', style: { font: "#{FONT} bold", font_size: 11, line_height: 12 } }
                            ],
                            style: { font: FONT, font_size: 11 }, align: :left, padding: [10, 0, 5, 0])
  end

  composer.formatted_text(
    [{ text: 'For questions, please contact Accounting at (800) 875-5285 ext. 623, or email ', style: { font: "#{FONT} bold", font_size: 11 } },
     { text: 'ap@warmlyyours.com', style: { font: "#{FONT} bold", font_size: 10, fill_color: '0000ed', underline: true } }], style: { padding: [@po.drop_ship? ? 5 : 10, 0] }
  )

  add_headers_and_footers(composer)

  buffer = StringIO.new
  composer.write(buffer, optimize: true)
  buffer.string
end