class Receipts::Invoice

Attributes

attributes[R]
bill_to[R]
company[R]
custom_font[R]
due_date[R]
id[R]
issue_date[R]
line_items[R]
message[R]
product[R]
status[R]
subheading[R]

Public Class Methods

new(attributes) click to toggle source
Calls superclass method
# File lib/receipts/invoice.rb, line 8
def initialize(attributes)
  @attributes = attributes
  @id = attributes.fetch(:id)
  @company = attributes.fetch(:company)
  @line_items = attributes.fetch(:line_items)
  @custom_font = attributes.fetch(:font, {})
  @message = attributes.fetch(:message) { default_message }
  @subheading = attributes.fetch(:subheading) { default_subheading }
  @bill_to = Array(attributes.fetch(:bill_to)).join("\n")
  @issue_date = attributes.fetch(:issue_date)
  @due_date = attributes.fetch(:due_date)
  @status = attributes.fetch(:status)

  super(page_size: "LETTER")

  setup_fonts if custom_font.any?
  generate
end

Private Instance Methods

charge_details() click to toggle source
# File lib/receipts/invoice.rb, line 70
def charge_details
  move_down 30

  borders = line_items.length - 2

  table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true, overflow: :shrink_to_fit}) do
    cells.padding = 10
    cells.borders = []
    row(0..borders).borders = [:bottom]
  end
end
default_message() click to toggle source
# File lib/receipts/invoice.rb, line 29
def default_message
  "For questions, contact us anytime at <color rgb='326d92'><link href='mailto:#{company.fetch(:email)}?subject=Charge ##{id}'><b>#{company.fetch(:email)}</b></link></color>."
end
default_subheading() click to toggle source
# File lib/receipts/invoice.rb, line 33
def default_subheading
  "INVOICE #%{id}"
end
description() click to toggle source
# File lib/receipts/invoice.rb, line 51
def description
  move_down 8
  text label(subheading % {id: id}), inline_format: true, leading: 4
end
generate() click to toggle source
# File lib/receipts/invoice.rb, line 37
def generate
  header
  description
  invoice_details
  charge_details
  footer
end
header(height: 24) click to toggle source
# File lib/receipts/invoice.rb, line 45
def header(height: 24)
  logo = company[:logo]
  return if logo.nil?
  image load_image(logo), height: height
end
invoice_details() click to toggle source
# File lib/receipts/invoice.rb, line 56
def invoice_details
  move_down 10
  font_size 9

  line_items = [
    [{content: "#{label("BILL TO")}\n#{bill_to}", rowspan: 3, padding: [0, 12, 0, 0]}, "#{label("INVOICE DATE")}\n#{issue_date}"],
    ["#{label("DUE DATE")}\n#{due_date}"],
    ["#{label("STATUS")}\n#{status}"]
  ]
  table(line_items, width: bounds.width, cell_style: {inline_format: true, overflow: :shrink_to_fit}) do
    cells.borders = []
  end
end