Module: OpportunitiesHelper

Defined in:
app/helpers/opportunities_helper.rb

Instance Method Summary collapse

Instance Method Details

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



21
22
23
24
25
26
27
# File 'app/helpers/opportunities_helper.rb', line 21

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



13
14
15
16
17
18
19
# File 'app/helpers/opportunities_helper.rb', line 13

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



29
30
31
32
33
34
# File 'app/helpers/opportunities_helper.rb', line 29

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/opportunities_helper.rb', line 66

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))
  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 }) if opportunity.room_configurations.any? do |rc|
    rc.has_plans?
  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.compact
end

#opportunity_contact_panel(party, options = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/helpers/opportunities_helper.rb', line 81

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



49
50
51
52
53
# File 'app/helpers/opportunities_helper.rb', line 49

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



98
99
100
101
102
103
104
105
106
# File 'app/helpers/opportunities_helper.rb', line 98

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



55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/opportunities_helper.rb', line 55

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



108
109
110
111
112
113
114
115
116
117
118
119
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
# File 'app/helpers/opportunities_helper.rb', line 108

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: opportunity_room_configurations_path(@opportunity)
    },
    activities: {
      counter: @opportunity.open_activities_counter,
      remote_href: opportunity_activities_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: opportunity_communications_path(@opportunity)
    },
    sms: {
      counter: @opportunity.sms_messages.unread.size,
      remote_href: opportunity_sms_messages_path(@opportunity)
    },
    attachments: {
      counter: @opportunity.all_uploads.size,
      remote_href: opportunity_uploads_path(@opportunity)
    },
    digital_assets: {
      counter: @opportunity.digital_assets.size,
      remote_href: tab_digital_assets_opportunity_path(@opportunity)
    }
  }
end

#opportunity_tool_tip(opp) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/opportunities_helper.rb', line 36

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



2
3
4
5
6
# File 'app/helpers/opportunities_helper.rb', line 2

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

#setup_opportunity_participants(opp) ⇒ Object



8
9
10
11
# File 'app/helpers/opportunities_helper.rb', line 8

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