Module: OpportunitiesHelper

Defined in:
app/helpers/opportunities_helper.rb

Overview

View helper: opportunities.

Instance Method Summary collapse

Instance Method Details

#append_opportunity_participants_hash(opportunity, parties_hash = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'app/helpers/opportunities_helper.rb', line 24

def append_opportunity_participants_hash(opportunity, parties_hash = {})
  opportunity.opportunity_participants.each do |opp_par|
    titles = [opp_par.party.full_name]
    titles << "(#{opp_par.role})" if opp_par.role.present?
    parties_hash[titles.join(' ')] = { party: opp_par.party, collapsed: true, contact_point_id: opp_par.contact_point_id }
  end
end

#build_opportunity_party_hash(opportunity) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/opportunities_helper.rb', line 16

def build_opportunity_party_hash(opportunity)
  parties_hash = {}
  parties_hash["#{opportunity.contact.full_name} (Primary)"] = opportunity.contact if opportunity.contact
  parties_hash["#{opportunity.customer.full_name} (Customer)"] = { party: opportunity.customer, collapsed: false } if opportunity.contact != opportunity.customer
  append_opportunity_participants_hash(opportunity, parties_hash)
  parties_hash
end

#gather_opp_contact_points(_opp) ⇒ Object



32
33
34
35
36
37
# File 'app/helpers/opportunities_helper.rb', line 32

def gather_opp_contact_points(_opp)
  phones = [] +
           @opportunity.primary_party.contact_points.contactable.limit(3) +
           @opportunity.customer.contact_points.contactable.limit(3)
  phones.compact.uniq
end

#opportunity_command_options(opportunity = @opportunity) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/opportunities_helper.rb', line 69

def opportunity_command_options(opportunity = @opportunity)
  actions = []
  actions << link_to('Edit', edit_opportunity_path(opportunity))
  actions << link_to('Edit Participants', participants_opportunity_path(opportunity))
  actions << link_to('Edit Rooms/Areas', rooms_opportunity_path(opportunity))
  if opportunity.room_configurations.any?(&:has_plans?)
    actions << link_to('Refresh All Room/Area Plans', refresh_all_room_plans_opportunity_path(opportunity), data: { turbo_confirm: 'Are you sure? This can take a little while...', turbo_method: :post })
  end
  actions << link_to('Delete', opportunity_path(opportunity), data: { turbo_confirm: 'Are you sure?', turbo_method: :delete }) if opportunity.ok_to_delete?
  actions << link_to('Move', move_opportunity_path(opportunity))
  actions << link_to('Copy', copy_opportunity_path(opportunity))
  actions << link_to('Merge', merge_opportunity_path(opportunity)) if can? :merge, opportunity
  actions << link_to('Mark as duplicate of...', mark_as_duplicate_opportunity_path(opportunity)) if can? :update, opportunity
  actions.compact
end

#opportunity_contact_panel(party, options = {}) ⇒ ActiveSupport::SafeBuffer

Panel for an opportunity contact with a dropdown (View/Edit) and body
showing organization, role, and contact details.

Parameters:

  • party (Contact, Customer, Party)

    the party to display

  • options (Hash) (defaults to: {})

    display options

Options Hash (options):

  • :role (String)

    participant role label shown in the body

  • :contact_point_id (Integer)

    preselected contact point
    passed to the contact partial

Returns:

  • (ActiveSupport::SafeBuffer)

    the rendered panel



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

def opportunity_contact_panel(party, options = {})
  panel(party.full_name, false, mode: :dropdown) do |section|
    if section == :dropdown
      concat (:li, link_to('View', polymorphic_path(party), class: 'dropdown-item'))
      concat (:li, link_to('Edit', polymorphic_path(party, action: :edit), class: 'dropdown-item'))
    else
      concat attr_display 'Organization', party.customer.try(:full_name), true if party.is_a? Contact
      concat attr_display 'Role', options[:role], true
      concat render partial: '/contacts/contact_in_panel',
                    locals: {
                        contact: party,
                        contact_point_id: options[:contact_point_id]
                    }
    end
  end
end

#opportunity_name_with_age(opp) ⇒ Object



52
53
54
55
56
# File 'app/helpers/opportunities_helper.rb', line 52

def opportunity_name_with_age(opp)
  str = [opp.name]
  str << (:span, "(created #{time_ago_in_words(opp.created_at)} ago)", style: 'font-size:0.8em;color:gray') if opp.created_at
  str.join(' ').html_safe
end

#opportunity_quick_info(opportunity = @opportunity) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'app/helpers/opportunities_helper.rb', line 110

def opportunity_quick_info(opportunity = @opportunity)
  info = []
  info << clipboard_copy(opportunity.reference_number, mode: :text, url: opportunity_url(opportunity), button_class: 'clipboard-btn px-2 nav-link')
  info << employee_badge(opportunity.primary_sales_rep, title: 'Primary Sales Rep') if opportunity.primary_sales_rep
  info << fa_icon('file-invoice-dollar', text: "MSRP: #{number_to_currency(opportunity.msrp_value)}") if opportunity.msrp_value
  info << fa_icon('file-invoice-dollar', text: "Discounted Price: #{number_to_currency(opportunity.value)}") if opportunity.value
  info << fa_icon('tags', text: "Effective Discount: #{opportunity.discount_percentage} %".html_safe) if opportunity.discount_percentage
  info
end

#opportunity_state_options(opportunity = @opportunity) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/opportunities_helper.rb', line 58

def opportunity_state_options(opportunity = @opportunity)
  actions = []
  actions << opportunity.human_state_name.titleize
  actions += available_events_links(opportunity, data: { turbo_confirm: 'Are you sure?' })
  if opportunity.try(:state_description).present?
    actions << { class: 'divider' }
    actions << { content: opportunity.try(:state_description) }
  end
  actions
end

#opportunity_tab_optionsObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/helpers/opportunities_helper.rb', line 120

def opportunity_tab_options
  {
    quotes: {
      counter: @opportunity.quotes.size,
      remote_href: opportunity_quotes_path(@opportunity)
    },
    contacts: {
      remote_href: tab_contacts_opportunity_path(@opportunity)
    },
    rooms: {
      counter: @opportunity.room_configurations.size,
      title: 'Rooms & Areas',
      remote_href: tab_rooms_opportunity_path(@opportunity)
    },
    activities: {
      counter: @opportunity.open_activities_counter,
      remote_href: tab_activities_opportunity_path(@opportunity, selected_activity: params[:selected_activity])
    },
    orders: {
      counter: @opportunity.orders.size,
      remote_href: opportunity_orders_path(@opportunity)
    },
    main: { remote_href: tab_main_opportunity_path(@opportunity) },
    communications: {
      counter: @opportunity.all_related_communications.size,
      remote_href: tab_communications_opportunity_path(@opportunity)
    },
    sms: {
      counter: @opportunity.sms_messages.unread.size,
      remote_href: tab_sms_opportunity_path(@opportunity)
    },
    attachments: {
      counter: @opportunity.all_uploads.size,
      remote_href: tab_attachments_opportunity_path(@opportunity)
    },
    digital_assets: {
      counter: @opportunity.digital_assets.size,
      remote_href: tab_digital_assets_opportunity_path(@opportunity)
    },
    outlet_purchases: {
      counter: @opportunity.outlet_purchases.size,
      title: 'Outlet Purchases',
      remote_href: tab_outlet_purchases_opportunity_path(@opportunity)
    }
  }
end

#opportunity_tool_tip(opp) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/opportunities_helper.rb', line 39

def opportunity_tool_tip(opp)
  str = []
  str << "Created on #{opp.created_at.to_fs(:crm_default)}"
  str << "        by #{opp.creator.full_name}" if opp.creator
  opp.room_configurations.last_revisions.each do |rc|
    str << "Room: #{rc.name_with_room}"
  end
  opp.quotes.each do |q|
    str << "Quote: #{q.reference_number_with_name} - #{q.state}"
  end
  str.join("\n\r")
end

#setup_opportunity(opp) ⇒ Object



5
6
7
8
9
# File 'app/helpers/opportunities_helper.rb', line 5

def setup_opportunity(opp)
  opp.tap do |o|
    # Nothing for now
  end
end

#setup_opportunity_participants(opp) ⇒ Object



11
12
13
14
# File 'app/helpers/opportunities_helper.rb', line 11

def setup_opportunity_participants(opp)
  # opp.opportunity_participants.build
  opp
end