Module: ContactDisplay
- Extended by:
- ActiveSupport::Concern
- Included in:
- Contact
- Defined in:
- app/models/concerns/contact_display.rb
Overview
Display helpers, formatting, CRM links, and lookup methods for Contact.
Instance Method Summary collapse
- #all_addresses ⇒ Object
-
#build_default_contact_points(required = nil) ⇒ Object
:reek:ControlParameter.
- #colleagues ⇒ Object
- #country ⇒ Object
- #first_address ⇒ Object
- #guest? ⇒ Boolean
- #last_invoice_shipping_cost ⇒ Object
- #locale ⇒ Object
- #main_address ⇒ Object
- #open_activities_counter ⇒ Object
- #options_for_reports_to ⇒ Object
- #reference_number ⇒ Object
- #shipping_amount_last_30_days ⇒ Object
- #shipping_amount_last_month ⇒ Object
- #state ⇒ Object
- #supplier_contact? ⇒ Boolean
- #timezone ⇒ Object
- #to_label ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#all_addresses ⇒ Object
59 60 61 62 63 64 |
# File 'app/models/concerns/contact_display.rb', line 59 def all_addresses addrs = [] addrs.concat(addresses) addrs.concat(customer.all_addresses) addrs.uniq end |
#build_default_contact_points(required = nil) ⇒ Object
:reek:ControlParameter
66 67 68 69 70 71 |
# File 'app/models/concerns/contact_display.rb', line 66 def build_default_contact_points(required = nil) # :reek:ControlParameter %w[phone fax email].each do |cat| contact_points.build(category: cat, required: required == cat ? '1' : nil) if contact_points.none? { |cp| cp.category == cat } end self end |
#colleagues ⇒ Object
77 78 79 80 81 |
# File 'app/models/concerns/contact_display.rb', line 77 def colleagues return Contact.none unless customer customer.contacts.where.not(id:) end |
#country ⇒ Object
47 48 49 |
# File 'app/models/concerns/contact_display.rb', line 47 def country super || customer&.catalog&.store&.country end |
#first_address ⇒ Object
55 56 57 |
# File 'app/models/concerns/contact_display.rb', line 55 def first_address super || customer&.first_address end |
#guest? ⇒ Boolean
91 92 93 |
# File 'app/models/concerns/contact_display.rb', line 91 def guest? false end |
#last_invoice_shipping_cost ⇒ Object
17 18 19 |
# File 'app/models/concerns/contact_display.rb', line 17 def last_invoice_shipping_cost customer.nil? ? 0 : customer.last_invoice_shipping_cost end |
#locale ⇒ Object
21 22 23 |
# File 'app/models/concerns/contact_display.rb', line 21 def locale customer&.locale || super end |
#main_address ⇒ Object
51 52 53 |
# File 'app/models/concerns/contact_display.rb', line 51 def main_address addresses.first || customer&.main_address end |
#open_activities_counter ⇒ Object
73 74 75 |
# File 'app/models/concerns/contact_display.rb', line 73 def open_activities_counter all_activities.open_activities.visible_by_default.size end |
#options_for_reports_to ⇒ Object
83 84 85 86 87 88 89 |
# File 'app/models/concerns/contact_display.rb', line 83 def res = customer || supplier return if res.nil? contacts = res.contacts.where(Contact[:id].not_eq(id.to_i)).order(:inactive).reverse_order contacts.map { |c| [(c.inactive? ? "#{c.full_name} (inactive)" : c.full_name), c.id] } end |
#reference_number ⇒ Object
29 30 31 |
# File 'app/models/concerns/contact_display.rb', line 29 def reference_number "CT#{id}" end |
#shipping_amount_last_30_days ⇒ Object
13 14 15 |
# File 'app/models/concerns/contact_display.rb', line 13 def shipping_amount_last_30_days customer.nil? ? 0 : customer.shipping_amount_last_30_days end |
#shipping_amount_last_month ⇒ Object
9 10 11 |
# File 'app/models/concerns/contact_display.rb', line 9 def shipping_amount_last_month customer.nil? ? 0 : customer.shipping_amount_last_month end |
#state ⇒ Object
25 26 27 |
# File 'app/models/concerns/contact_display.rb', line 25 def state inactive ? 'inactive' : 'active' end |
#supplier_contact? ⇒ Boolean
95 96 97 |
# File 'app/models/concerns/contact_display.rb', line 95 def supplier_contact? supplier.present? end |
#timezone ⇒ Object
43 44 45 |
# File 'app/models/concerns/contact_display.rb', line 43 def timezone ActiveSupport::TimeZone.find_tzinfo(timezone_name) || customer&.timezone end |
#to_label ⇒ Object
33 34 35 |
# File 'app/models/concerns/contact_display.rb', line 33 def to_label to_s end |
#to_s ⇒ Object
37 38 39 40 41 |
# File 'app/models/concerns/contact_display.rb', line 37 def to_s label_parts = [full_name] label_parts << "#{customer.full_name} [#{customer.reference_number}]" if customer label_parts.join(' - ') end |