Module: ContactsHelper

Defined in:
app/helpers/contacts_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_contact_party_hash(contact) ⇒ Object



11
12
13
14
15
16
# File 'app/helpers/contacts_helper.rb', line 11

def build_contact_party_hash(contact)
  parties_hash = {}
  parties_hash["#{contact.full_name}"] = contact
  parties_hash["#{contact.customer.full_name} (Customer)"] = { party: contact.customer, collapsed: false } if contact.customer
  parties_hash
end

#contact_command_options(contact) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/contacts_helper.rb', line 45

def contact_command_options(contact)
  [].tap do |links|
    links << link_to(fa_icon('wrench', text: 'Edit'), edit_contact_path(contact))
    links << link_to('Restore', restore_contact_path(contact), data: { turbo_method: :put }) if contact.customer && contact.inactive?
    links << if contact.open_support_case_participant?
               { content: 'Cannot be deactivated because it is a participant of an open support case.', class: 'dropdown-item-text text-muted' }
             else
               confirm_message = if contact.ok_to_delete?
                                   'Are you sure? This action will permanently delete the contact.'
                                 elsif contact.support_case_participant?
                                   'This contact is a support case participant and cannot be deleted. It will be marked as inactive and the contact login (if any) will be removed.'
                                 else
                                   'Are you sure? This action will mark the contact as inactive and remove the contact login (if any). It will also unassign any open opportunities, orders or services assigned to this contact.'
                                 end
               link_to(fa_icon('trash', text: (contact.ok_to_delete? ? 'Delete' : 'Deactivate')),
                       contact_path(contact),
                       data: { turbo_confirm: confirm_message, turbo_method: :delete })
             end
  end
end


35
36
37
38
# File 'app/helpers/contacts_helper.rb', line 35

def contact_multiple_visits_link(contact, most_recent)
  display_text = "#{contact.visits.size} visit(s) (Last was #{time_ago_in_words(most_recent.started_at)} ago)"
  link_to(fa_icon('magnifying-glass-plus', text: display_text), contact_visits_path(contact))
end

#contact_quick_info(contact) ⇒ Object



18
19
20
21
22
# File 'app/helpers/contacts_helper.rb', line 18

def contact_quick_info(contact)
  info = []
  info << fa_icon('user-tie', text: contact.customer.primary_sales_rep.name_and_extension, title: 'Primary Sales Rep') if contact.customer&.respond_to?('primary_sales_rep') && contact.customer.primary_sales_rep
  info
end


40
41
42
43
# File 'app/helpers/contacts_helper.rb', line 40

def contact_single_visit_link(most_recent)
  display_text = "#{time_ago_in_words(most_recent.started_at)} ago"
  link_to(fa_icon('magnifying-glass-plus', text: display_text), visit_path(most_recent))
end

#contact_tab_options(contact = @contact) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/helpers/contacts_helper.rb', line 66

def contact_tab_options(contact = @contact)
  hsh = {}
  hsh[:main] = { remote_href: tab_main_contact_path(contact) }
  hsh[:contacts] = { remote_href: tab_contacts_contact_path(contact) }
  hsh[:activities] = { counter: contact.open_activities_counter, remote_href: contact_activities_path(contact, selected_activity: params[:selected_activity]) }
  hsh[:communications] = { remote_href: contact_communications_path(contact) }
  hsh[:sms] = { remote_href: contact_sms_messages_path(contact), counter: contact.sms_messages.where(unread: true).size }

  unless contact.supplier_contact?
    hsh[:opportunities] = { counter: contact.all_opportunities.open_opportunities.size,
                            remote_href: contact_opportunities_path(contact) }
  end
  hsh[:tickets] = { title: 'Tickets',
                    counter_html: tech_counter_badge(contact.support_cases),
                    remote_href: show_tickets_tab_contact_path(contact) }
  hsh[:attachments] = { counter: contact.all_uploads.size, remote_href: contact_uploads_path(contact) }
  if contact.customer && !contact.supplier_contact?
    hsh[:topics] = { remote_href: show_profiling_tab_contact_path(contact) }
    hsh[:training] = { remote_href: show_training_tab_contact_path(contact) }
    hsh[:certifications] = { remote_href: show_certifications_tab_contact_path(contact) }
    hsh[:orders] = { counter: contact.orders.non_credit.in_progress.size, remote_href: contact_orders_path(contact) }
    hsh[:orders_spiff] = { remote_href: tab_orders_spiff_contact_path(contact) }
    hsh[:merge] = { remote_href: tab_merge_contact_path(contact) }
  end
  hsh[:digital_assets] = { counter: contact.digital_assets.size, remote_href: tab_digital_assets_contact_path(contact) }
  hsh
end


24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/contacts_helper.rb', line 24

def contact_visits_link(contact)
  most_recent = contact.visits.order(:started_at).reverse_order.first
  return '-' unless most_recent

  if contact.visits.size > 1
    contact_multiple_visits_link(contact, most_recent)
  else
    contact_single_visit_link(most_recent)
  end
end

#render_contact_info_bar(contact, role: nil, note: nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/contacts_helper.rb', line 94

def render_contact_info_bar(contact, role: nil, note: nil)
  list = []
  list << fa_icon('building', text: contact.customer.full_name) if contact.is_a?(Contact) && contact.customer

  list << fa_icon('diagram-project', text: role, title: 'Project Role') if role.present?

  list << fa_icon('user-tag', text: contact.job_title, title: 'Job Title') if contact.job_title.present? && contact.job_title != role

  list << fa_icon('note-sticky', text: note) if note.present?

  return unless list.present?

  (:ul, list.map { |e| (:span, e, class: 'text-muted me-2') }.join.html_safe, class: 'list-unstyled')
end

#setup_contact(contact) ⇒ Object



2
3
4
5
6
7
8
9
# File 'app/helpers/contacts_helper.rb', line 2

def setup_contact(contact)
  contact.tap do |c|
    c.contact_points.build({ category: ContactPoint::PHONE }) if c.contact_points.find_by(category: ContactPoint::PHONE).nil?
    c.contact_points.build({ category: ContactPoint::CELL }) if c.contact_points.find_by(category: ContactPoint::CELL).nil?
    c.contact_points.build({ category: ContactPoint::FAX }) if c.contact_points.find_by(category: ContactPoint::FAX).nil?
    c.contact_points.build({ category: ContactPoint::EMAIL }) if c.contact_points.find_by(category: ContactPoint::EMAIL).nil?
  end
end