Module: CustomerContacts
- Extended by:
- ActiveSupport::Concern
- Includes:
- Memery
- Included in:
- Customer
- Defined in:
- app/models/concerns/customer_contacts.rb
Overview
Aggregate emails, communications, contactable override, contact management.
Instance Method Summary collapse
- #account_team ⇒ Object
- #all_addresses ⇒ Object (also: #all_billing_addresses)
- #all_addresses_including_contacts ⇒ Object
- #all_contact_points ⇒ Object
- #all_emails ⇒ Object
- #all_my_active_party_ids ⇒ Object
- #all_my_party_ids ⇒ Object
- #all_notification_channels ⇒ Object
- #all_phone_numbers ⇒ Object
- #all_related_addresses ⇒ Object
- #all_related_communications ⇒ Object
-
#contact_select_options(active_only: false) ⇒ Object
:reek:BooleanParameter :reek:ControlParameter.
- #contactable? ⇒ Boolean
- #contacts_and_self ⇒ Object
- #contacts_and_self_callable_contact_points ⇒ Object
- #contacts_and_self_callable_options_for_select ⇒ Object
- #contacts_and_self_contact_points_by_category(category) ⇒ Object
- #contacts_and_self_contact_points_by_category_options_for_select(category) ⇒ Object
- #email ⇒ Object
- #generate_guest_account ⇒ Object
- #guess_best_callable_contact_point ⇒ Object
- #guess_best_contact_point_by_category(category) ⇒ Object
- #lead_score_pass? ⇒ Boolean
- #obfuscated_email ⇒ Object
- #primary_contact ⇒ Object
- #primary_rep ⇒ Object
- #secondary_rep ⇒ Object
- #self_and_contacts_party_ids_arr ⇒ Object
- #sms_enabled_numbers ⇒ Object
Instance Method Details
#account_team ⇒ Object
126 127 128 129 130 |
# File 'app/models/concerns/customer_contacts.rb', line 126 def account_team team = [] team << local_sales_rep << primary_sales_rep << secondary_sales_rep team.compact.uniq end |
#all_addresses ⇒ Object Also known as: all_billing_addresses
108 109 110 |
# File 'app/models/concerns/customer_contacts.rb', line 108 def all_addresses Address.where(party_id: [id, parent_id].compact) end |
#all_addresses_including_contacts ⇒ Object
104 105 106 |
# File 'app/models/concerns/customer_contacts.rb', line 104 def all_addresses_including_contacts Address.where(party_id: [id, *contact_ids].flatten.compact).order(:id) end |
#all_contact_points ⇒ Object
58 59 60 |
# File 'app/models/concerns/customer_contacts.rb', line 58 def all_contact_points ContactPoint.joins(:party).merge(contacts_and_self) end |
#all_emails ⇒ Object
18 19 20 |
# File 'app/models/concerns/customer_contacts.rb', line 18 def all_emails ContactPoint.emails.where(party_id: all_my_active_party_ids).pluck(:detail).uniq end |
#all_my_active_party_ids ⇒ Object
53 54 55 |
# File 'app/models/concerns/customer_contacts.rb', line 53 def all_my_active_party_ids ([id] + contacts.active.order(:full_name).pluck(:id)).compact.uniq end |
#all_my_party_ids ⇒ Object
49 50 51 |
# File 'app/models/concerns/customer_contacts.rb', line 49 def all_my_party_ids ([id] + contacts.pluck(:id)).compact.uniq end |
#all_notification_channels ⇒ Object
138 139 140 |
# File 'app/models/concerns/customer_contacts.rb', line 138 def all_notification_channels NotificationChannel.for_customer(self) end |
#all_phone_numbers ⇒ Object
22 23 24 |
# File 'app/models/concerns/customer_contacts.rb', line 22 def all_phone_numbers ContactPoint.dialable.where(party_id: all_my_active_party_ids).pluck(:detail).uniq end |
#all_related_addresses ⇒ Object
114 115 116 |
# File 'app/models/concerns/customer_contacts.rb', line 114 def ([billing_address, shipping_address, mailing_address] + addresses.to_a).flatten.compact.uniq end |
#all_related_communications ⇒ Object
10 11 12 |
# File 'app/models/concerns/customer_contacts.rb', line 10 def Query::CustomerRelatedCommunications.call(self) end |
#contact_select_options(active_only: false) ⇒ Object
:reek:BooleanParameter :reek:ControlParameter
26 27 28 29 30 |
# File 'app/models/concerns/customer_contacts.rb', line 26 def (active_only: false) # :reek:BooleanParameter :reek:ControlParameter contacts_to_use = contacts.order(:inactive) contacts_to_use = contacts_to_use.active if active_only contacts_to_use.pluck(:full_name, :id) end |
#contactable? ⇒ Boolean
44 45 46 47 |
# File 'app/models/concerns/customer_contacts.rb', line 44 def contactable? contact_points.exists? || ContactPoint.where(party_id: contacts.active.select(:id)).exists? end |
#contacts_and_self ⇒ Object
40 41 42 |
# File 'app/models/concerns/customer_contacts.rb', line 40 def contacts_and_self Party.where(id: all_my_active_party_ids) end |
#contacts_and_self_callable_contact_points ⇒ Object
62 63 64 |
# File 'app/models/concerns/customer_contacts.rb', line 62 def contacts_and_self_callable_contact_points all_contact_points.voice_callable end |
#contacts_and_self_callable_options_for_select ⇒ Object
70 71 72 73 74 75 |
# File 'app/models/concerns/customer_contacts.rb', line 70 def contacts_and_self_callable_contact_points.includes(:party).map do |contact_point| party_label = party_label_for_contact_point(contact_point) ["#{contact_point} (#{party_label})", contact_point.id] end end |
#contacts_and_self_contact_points_by_category(category) ⇒ Object
66 67 68 |
# File 'app/models/concerns/customer_contacts.rb', line 66 def contacts_and_self_contact_points_by_category(category) ContactPoint.where(category: category).where(party_id: all_my_active_party_ids) end |
#contacts_and_self_contact_points_by_category_options_for_select(category) ⇒ Object
77 78 79 80 81 82 |
# File 'app/models/concerns/customer_contacts.rb', line 77 def (category) contacts_and_self_contact_points_by_category(category).includes(:party).map do |contact_point| party_label = party_label_for_contact_point(contact_point, capitalize: true) ["#{contact_point} (#{party_label})", contact_point.id] end end |
#email ⇒ Object
96 97 98 |
# File 'app/models/concerns/customer_contacts.rb', line 96 def email super || contacts.active.first&.email || contacts.active.last&.email end |
#generate_guest_account ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/models/concerns/customer_contacts.rb', line 142 def generate_guest_account return { success: false } if account.present? || email.nil? acct = build_account acct.login = Account.get_unique_login_for_email(email) acct.email = email acct.require_password = false if acct.save { success: true, account: acct } else { success: false, errors: acct.errors. } end end |
#guess_best_callable_contact_point ⇒ Object
84 85 86 |
# File 'app/models/concerns/customer_contacts.rb', line 84 def guess_best_callable_contact_point contacts_and_self_callable_contact_points.first end |
#guess_best_contact_point_by_category(category) ⇒ Object
88 89 90 |
# File 'app/models/concerns/customer_contacts.rb', line 88 def guess_best_contact_point_by_category(category) contacts_and_self_contact_points_by_category(category).first end |
#lead_score_pass? ⇒ Boolean
36 37 38 |
# File 'app/models/concerns/customer_contacts.rb', line 36 def lead_score_pass? lead_verification_score.to_i > 50 end |
#obfuscated_email ⇒ Object
100 101 102 |
# File 'app/models/concerns/customer_contacts.rb', line 100 def email&.gsub(/(?<=.{2}).*@.*(?=\S{2})/, '****@****') end |
#primary_contact ⇒ Object
92 93 94 |
# File 'app/models/concerns/customer_contacts.rb', line 92 def primary_contact person? ? self : contacts.first end |
#primary_rep ⇒ Object
118 119 120 |
# File 'app/models/concerns/customer_contacts.rb', line 118 def primary_rep primary_sales_rep end |
#secondary_rep ⇒ Object
122 123 124 |
# File 'app/models/concerns/customer_contacts.rb', line 122 def secondary_rep secondary_sales_rep end |
#self_and_contacts_party_ids_arr ⇒ Object
32 33 34 |
# File 'app/models/concerns/customer_contacts.rb', line 32 def self_and_contacts_party_ids_arr [id] + contact_ids end |
#sms_enabled_numbers ⇒ Object
14 15 16 |
# File 'app/models/concerns/customer_contacts.rb', line 14 def sms_enabled_numbers ContactPoint.where(party_id: [id] + contact_ids).sms_numbers.order(:detail).map(&:formatted_for_sms) end |