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.
Instance Method Summary collapse
-
#card_name ⇒ String?
Cardholder name from the linked Payment.
-
#currency_symbol ⇒ String
Symbol for the receipt's currency.
-
#customer_name ⇒ String?
Full name of the receipt's customer.
-
#customer_type ⇒ String?
STI type of the receipt's customer.
-
#is_not_for_a_customer? ⇒ Boolean?
Whether the receipt is attached to a non-Customer party (e.g. a vendor or employee).
-
#reference_summary(with_brackets = false) ⇒ String?
Display label for the receipt's external reference.
- #store ⇒ Store?
-
#to_s ⇒ String
"Receipt 1234".
Instance Method Details
#card_name ⇒ String?
Returns 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_symbol ⇒ String
Returns 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_name ⇒ String?
Full name of the receipt's customer.
13 14 15 |
# File 'app/concerns/models/receipt_display.rb', line 13 def customer_name customer.try(:full_name) end |
#customer_type ⇒ String?
STI type of the receipt's customer.
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).
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.
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 |
#store ⇒ Store?
63 64 65 |
# File 'app/concerns/models/receipt_display.rb', line 63 def store company&.stores&.first end |
#to_s ⇒ String
Returns "Receipt 1234".
54 55 56 |
# File 'app/concerns/models/receipt_display.rb', line 54 def to_s "Receipt #{id}" end |