Module: Models::ReceiptDisplay

Extended by:
ActiveSupport::Concern
Included in:
Receipt
Defined in:
app/concerns/models/receipt_display.rb

Overview

Presentation helpers: customer/label formatting, reference and card
summaries, currency symbol, and to_s.

See Also:

Instance Method Summary collapse

Instance Method Details

#card_nameString?

Returns cardholder name from the linked Payment.

Returns:

  • (String, nil)

    cardholder name from the linked Payment



44
45
46
# File 'app/concerns/models/receipt_display.rb', line 44

def card_name
  payment&.name
end

#currency_symbolString

Returns symbol for the receipt's currency.

Returns:

  • (String)

    symbol for the receipt's currency



49
50
51
# File 'app/concerns/models/receipt_display.rb', line 49

def currency_symbol
  Money::Currency.new(currency).symbol
end

#customer_nameString?

Full name of the receipt's customer.

Returns:

  • (String, nil)


13
14
15
# File 'app/concerns/models/receipt_display.rb', line 13

def customer_name
  customer.try(:full_name)
end

#customer_typeString?

STI type of the receipt's customer.

Returns:

  • (String, nil)


20
21
22
# File 'app/concerns/models/receipt_display.rb', line 20

def customer_type
  customer.try(:type)
end

#is_not_for_a_customer?Boolean?

Whether the receipt is attached to a non-Customer party (e.g. a vendor
or employee).

Returns:

  • (Boolean, nil)


71
72
73
# File 'app/concerns/models/receipt_display.rb', line 71

def is_not_for_a_customer?
  customer.present? and customer.class != Customer
end

#reference_summary(with_brackets = false) ⇒ String?

Display label for the receipt's external reference. Credit-card
receipts get "<card_type> <last4>"; everything else falls back to
the bare reference.

Parameters:

  • with_brackets (Boolean) (defaults to: false)

    wrap the result in parentheses

Returns:

  • (String, nil)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/concerns/models/receipt_display.rb', line 30

def reference_summary(with_brackets = false)
  ref = if category == 'Credit Card'
          card_type.blank? && reference.blank? ? nil : "#{card_type} #{reference}"
        else
          reference.presence
        end
  if ref.nil?
    nil
  else
    with_brackets == true ? "(#{ref})" : ref
  end
end

#storeStore?

First Store on the receipt's Company, used by tax and reporting
helpers. Returns nil when there is no company or no store; real DB
errors are allowed to surface rather than being swallowed.

Returns:



63
64
65
# File 'app/concerns/models/receipt_display.rb', line 63

def store
  company&.stores&.first
end

#to_sString

Returns "Receipt 1234".

Returns:

  • (String)

    "Receipt 1234"



54
55
56
# File 'app/concerns/models/receipt_display.rb', line 54

def to_s
  "Receipt #{id}"
end