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
127 128 129 130 131 |
# File 'app/models/concerns/customer_contacts.rb', line 127 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
109 110 111 |
# File 'app/models/concerns/customer_contacts.rb', line 109 def all_addresses Address.where(party_id: [id, parent_id].compact) end |
#all_addresses_including_contacts ⇒ Object
105 106 107 |
# File 'app/models/concerns/customer_contacts.rb', line 105 def all_addresses_including_contacts Address.where(party_id: [id, *contact_ids].flatten.compact).order(:id) end |
#all_contact_points ⇒ Object
59 60 61 |
# File 'app/models/concerns/customer_contacts.rb', line 59 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
54 55 56 |
# File 'app/models/concerns/customer_contacts.rb', line 54 def all_my_active_party_ids ([id] + contacts.active.order(:full_name).ids).compact.uniq end |
#all_my_party_ids ⇒ Object
50 51 52 |
# File 'app/models/concerns/customer_contacts.rb', line 50 def all_my_party_ids ([id] + contacts.ids).compact.uniq end |
#all_notification_channels ⇒ Object
139 140 141 |
# File 'app/models/concerns/customer_contacts.rb', line 139 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
115 116 117 |
# File 'app/models/concerns/customer_contacts.rb', line 115 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
27 28 29 30 31 |
# File 'app/models/concerns/customer_contacts.rb', line 27 def (active_only: false) 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
45 46 47 48 |
# File 'app/models/concerns/customer_contacts.rb', line 45 def contactable? contact_points.exists? || ContactPoint.where(party_id: contacts.active.select(:id)).exists? end |
#contacts_and_self ⇒ Object
41 42 43 |
# File 'app/models/concerns/customer_contacts.rb', line 41 def contacts_and_self Party.where(id: all_my_active_party_ids) end |
#contacts_and_self_callable_contact_points ⇒ Object
63 64 65 |
# File 'app/models/concerns/customer_contacts.rb', line 63 def contacts_and_self_callable_contact_points all_contact_points.voice_callable end |
#contacts_and_self_callable_options_for_select ⇒ Object
71 72 73 74 75 76 |
# File 'app/models/concerns/customer_contacts.rb', line 71 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
67 68 69 |
# File 'app/models/concerns/customer_contacts.rb', line 67 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
78 79 80 81 82 83 |
# File 'app/models/concerns/customer_contacts.rb', line 78 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
97 98 99 |
# File 'app/models/concerns/customer_contacts.rb', line 97 def email super || contacts.active.first&.email || contacts.active.last&.email end |
#generate_guest_account ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/concerns/customer_contacts.rb', line 143 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
85 86 87 |
# File 'app/models/concerns/customer_contacts.rb', line 85 def guess_best_callable_contact_point contacts_and_self_callable_contact_points.first end |
#guess_best_contact_point_by_category(category) ⇒ Object
89 90 91 |
# File 'app/models/concerns/customer_contacts.rb', line 89 def guess_best_contact_point_by_category(category) contacts_and_self_contact_points_by_category(category).first end |
#lead_score_pass? ⇒ Boolean
37 38 39 |
# File 'app/models/concerns/customer_contacts.rb', line 37 def lead_score_pass? lead_verification_score.to_i > 50 end |
#obfuscated_email ⇒ Object
101 102 103 |
# File 'app/models/concerns/customer_contacts.rb', line 101 def email&.gsub(/(?<=.{2}).*@.*(?=\S{2})/, '****@****') end |
#primary_contact ⇒ Object
93 94 95 |
# File 'app/models/concerns/customer_contacts.rb', line 93 def primary_contact person? ? self : contacts.first end |
#primary_rep ⇒ Object
119 120 121 |
# File 'app/models/concerns/customer_contacts.rb', line 119 def primary_rep primary_sales_rep end |
#secondary_rep ⇒ Object
123 124 125 |
# File 'app/models/concerns/customer_contacts.rb', line 123 def secondary_rep secondary_sales_rep end |
#self_and_contacts_party_ids_arr ⇒ Object
33 34 35 |
# File 'app/models/concerns/customer_contacts.rb', line 33 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 |