Class: Payday::InvoicePresenter
- Inherits:
-
Object
- Object
- Payday::InvoicePresenter
- Defined in:
- lib/payday/invoice_presenter.rb
Overview
Turns an Invoiceable into the plain Hash the Typst template consumes.
Every currency, date and translation decision happens here, so the template stays a pure layout concern and receives nothing but literal strings.
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(invoice) ⇒ InvoicePresenter
constructor
A new instance of InvoicePresenter.
- #labels ⇒ Object
- #line_items ⇒ Object
- #stamp ⇒ Object
- #to_h ⇒ Object
- #totals ⇒ Object
Constructor Details
#initialize(invoice) ⇒ InvoicePresenter
Returns a new instance of InvoicePresenter.
11 12 13 |
# File 'lib/payday/invoice_presenter.rb', line 11 def initialize(invoice) @invoice = invoice end |
Instance Method Details
#details ⇒ Object
51 52 53 54 55 |
# File 'lib/payday/invoice_presenter.rb', line 51 def details rows = [*number_row, *due_row, *paid_row] @invoice.each_detail { |key, value| rows << [key.to_s, value.to_s] } rows end |
#labels ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/payday/invoice_presenter.rb', line 57 def labels { bill_to: t('invoice.bill_to', 'Bill To'), ship_to: t('invoice.ship_to', 'Ship To'), notes: t('invoice.notes', 'Notes'), description: t('line_item.description', 'Description'), unit_price: t('line_item.unit_price', 'Unit Price'), quantity: t('line_item.quantity', 'Quantity'), amount: t('line_item.amount', 'Amount') } end |
#line_items ⇒ Object
32 33 34 |
# File 'lib/payday/invoice_presenter.rb', line 32 def line_items @invoice.line_items.map { |line| line_item(line) } end |
#stamp ⇒ Object
44 45 46 47 48 49 |
# File 'lib/payday/invoice_presenter.rb', line 44 def stamp return t('status.refunded', 'REFUNDED') if @invoice.refunded? return t('status.paid', 'PAID') if @invoice.paid? t('status.overdue', 'OVERDUE') if @invoice.overdue? end |
#to_h ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/payday/invoice_presenter.rb', line 15 def to_h { page_size: setting(:page_size), company_name: setting(:company_name).strip, company_details: company_details, stamp: stamp, bill_to: @invoice.bill_to, ship_to: ship_to, labels: labels, details: details, line_items: line_items, totals: totals, notes: Markup.to_runs(@invoice.notes), qr_code: qr_code } end |
#totals ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/payday/invoice_presenter.rb', line 36 def totals [[t('invoice.subtotal', 'Subtotal:'), money(@invoice.subtotal), false], [tax_label, money(@invoice.tax), false], *shipping_row, *retention_row, [t('invoice.total', 'Total:'), money(@invoice.total), true]] end |