Module: OpportunitiesHelper

Defined in:
app/helpers/opportunities_helper.rb

Overview

Copyright © 2008-2013 Michael Dvorkin and contributors.

Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php


Instance Method Summary collapse

Instance Method Details

#opportunity_campaign_select(options = {}) ⇒ Object

Generates a select list with the first 25 campaigns and prepends the currently selected campaign, if any.




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

def opportunity_campaign_select(options = {})
  options[:selected] ||= @opportunity.campaign_id || 0
  selected_campaign = Campaign.find_by_id(options[:selected])
  campaigns = ([selected_campaign] + Campaign.my.order(:name).limit(25)).compact.uniq
  collection_select :opportunity, :campaign_id, campaigns, :id, :name, options,
                    :"data-placeholder" => t(:select_a_campaign),
                    :"data-url" => auto_complete_campaigns_path(format: 'json'),
                    style: "width:330px; display:none;",
                    class: 'ajax_chosen'
end

#opportunity_stage_checkbox(stage, count) ⇒ Object

Sidebar checkbox control for filtering opportunities by stage.




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

def opportunity_stage_checkbox(stage, count)
  entity_filter_checkbox(:stage, stage, count)
end

#opportunity_summary(opportunity) ⇒ Object

Opportunity summary for RSS/ATOM feeds.




15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/opportunities_helper.rb', line 15

def opportunity_summary(opportunity)
  summary, amount = [], []
  summary << (opportunity.stage ? t(opportunity.stage) : t(:other))
  summary << number_to_currency(opportunity.weighted_amount, precision: 0)
  unless %w(won lost).include?(opportunity.stage)
    amount << number_to_currency(opportunity.amount || 0, precision: 0)
    amount << (opportunity.discount ? t(:discount_number, number_to_currency(opportunity.discount, precision: 0)) : t(:no_discount))
    amount << t(:probability_number, (opportunity.probability || 0).to_s + '%')
    summary << amount.join(' ')
  end
  if opportunity.closes_on
    summary << t(:closing_date, l(opportunity.closes_on, format: :mmddyy))
  else
    summary << t(:no_closing_date)
  end
  summary.compact.join(', ')
end