Module: OpportunitiesHelper
- Defined in:
- app/helpers/opportunities_helper.rb
Overview
View helper: opportunities.
Instance Method Summary collapse
- #append_opportunity_participants_hash(opportunity, parties_hash = {}) ⇒ Object
- #build_opportunity_party_hash(opportunity) ⇒ Object
- #gather_opp_contact_points(_opp) ⇒ Object
- #opportunity_command_options(opportunity = @opportunity) ⇒ Object
- #opportunity_contact_panel(party, options = {}) ⇒ Object
- #opportunity_name_with_age(opp) ⇒ Object
- #opportunity_quick_info(opportunity = @opportunity) ⇒ Object
- #opportunity_state_options(opportunity = @opportunity) ⇒ Object
- #opportunity_tab_options ⇒ Object
- #opportunity_tool_tip(opp) ⇒ Object
- #setup_opportunity(opp) ⇒ Object
- #setup_opportunity_participants(opp) ⇒ Object
Instance Method Details
#append_opportunity_participants_hash(opportunity, parties_hash = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/helpers/opportunities_helper.rb', line 23 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
15 16 17 18 19 20 21 |
# File 'app/helpers/opportunities_helper.rb', line 15 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
31 32 33 34 35 36 |
# File 'app/helpers/opportunities_helper.rb', line 31 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/opportunities_helper.rb', line 68 def (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 = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/opportunities_helper.rb', line 84 def opportunity_contact_panel(party, = {}) panel(party.full_name, false, mode: :dropdown) do |section| if section == :dropdown concat content_tag(:li, link_to('View', polymorphic_path(party), class: 'dropdown-item')) concat content_tag(: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', [:role], true concat render partial: '/contacts/contact_in_panel', locals: { contact: party, contact_point_id: [:contact_point_id] } end end end |
#opportunity_name_with_age(opp) ⇒ Object
51 52 53 54 55 |
# File 'app/helpers/opportunities_helper.rb', line 51 def opportunity_name_with_age(opp) str = [opp.name] str << content_tag(: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
101 102 103 104 105 106 107 108 109 |
# File 'app/helpers/opportunities_helper.rb', line 101 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
57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/opportunities_helper.rb', line 57 def (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_options ⇒ Object
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 149 150 151 |
# File 'app/helpers/opportunities_helper.rb', line 111 def { 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..size, remote_href: tab_communications_opportunity_path(@opportunity) }, sms: { counter: @opportunity..unread.size, remote_href: tab_sms_opportunity_path(@opportunity) }, attachments: { counter: @opportunity.all_uploads.size, remote_href: (@opportunity) }, digital_assets: { counter: @opportunity.digital_assets.size, remote_href: tab_digital_assets_opportunity_path(@opportunity) } } end |
#opportunity_tool_tip(opp) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/opportunities_helper.rb', line 38 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
4 5 6 7 8 |
# File 'app/helpers/opportunities_helper.rb', line 4 def setup_opportunity(opp) opp.tap do |o| # Nothing for now end end |
#setup_opportunity_participants(opp) ⇒ Object
10 11 12 13 |
# File 'app/helpers/opportunities_helper.rb', line 10 def setup_opportunity_participants(opp) # opp.opportunity_participants.build opp end |