Module: E9Crm::DealsHelper

Defined in:
app/helpers/e9_crm/deals_helper.rb

Instance Method Summary collapse

Instance Method Details

#deal_category_select_optionsObject



25
26
27
28
29
30
31
# File 'app/helpers/e9_crm/deals_helper.rb', line 25

def deal_category_select_options
  @_deal_category_select_options ||= begin
    options = MenuOption.options_for('Deal Category')
    options.unshift ['All Categories', nil]
    options_for_select(options)
  end
end

#deal_contact_selectObject



12
13
14
# File 'app/helpers/e9_crm/deals_helper.rb', line 12

def deal_contact_select
  select_tag 'contacts_ids', deal_contact_select_options
end

#deal_contact_select_optionsObject



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

def deal_contact_select_options
  @_deal_contact_select_options ||= begin
    contacts = Contact.available_to_deal(resource)

    options = contacts.map {|contact| [contact.name, contact.id] }
    options.unshift ['Add Contact', nil]
    options_for_select options
  end
end

#deal_contactsObject



79
80
81
82
83
84
# File 'app/helpers/e9_crm/deals_helper.rb', line 79

def deal_contacts
  @_eligible_responsible_contacts ||= begin
    roles = E9::Roles.list.map(&:role).select {|r| r > 'user' && r < 'e9_user' }
    User.includes(:contact).for_roles(roles).all.map(&:contact).compact.sort_by {|c| c.name.upcase }
  end
end

#deal_contacts_arrayObject



86
87
88
# File 'app/helpers/e9_crm/deals_helper.rb', line 86

def deal_contacts_array
  deal_contacts.map {|c| [c.name, c.id] }
end

#deal_date_select_options(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/e9_crm/deals_helper.rb', line 49

def deal_date_select_options(options = {})
  @_first_deal_date ||= Deal.order(:created_at).first.try(:created_at) || Date.today

  date, cdate = @_first_deal_date, Date.today

  sel_options = []

  if options[:type] == :until
    prefix = 'Up to '
    label = prefix + ' Now'
  elsif options[:type] == :in_month
    prefix = 'Closed in '
    label = 'Since Inception'
  else
    prefix = 'Since '
    label = prefix + ' Inception'
  end

  begin
    sel_options << [date.strftime("#{prefix}%B %Y"), date.strftime('%Y/%m')]
    date += 1.month
  end while date.year <= cdate.year && date.month <= cdate.month

  sel_options.reverse!

  sel_options.unshift([label, nil])

  options_for_select(sel_options)
end

#deal_offer_select_optionsObject



41
42
43
44
45
46
47
# File 'app/helpers/e9_crm/deals_helper.rb', line 41

def deal_offer_select_options
  @_deal_offer_select_options ||= begin
    options = Offer.all.map {|c| [c.name, c.id] }.sort_by {|name, id| name.upcase }
    options.unshift ['Any/No Offer', nil]
    options_for_select(options)
  end
end

#deal_owner_select_optionsObject



33
34
35
36
37
38
39
# File 'app/helpers/e9_crm/deals_helper.rb', line 33

def deal_owner_select_options
  @_deal_owner_select_options ||= begin
    options = deal_contacts_array
    options.unshift ['All Responsible', nil]
    options_for_select(options)
  end
end

#deal_status_select_optionsObject



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

def deal_status_select_options
  @_deal_status_select_options ||= begin
    options = Deal::Status::OPTIONS - %w(lead)
    options.map! {|o| [o.titleize, o] }
    options.unshift ['All Statuses', nil]
    options_for_select(options)
  end
end

#title_and_or_company(contact) ⇒ Object



90
91
92
93
# File 'app/helpers/e9_crm/deals_helper.rb', line 90

def title_and_or_company(contact)
  [contact.title, contact.company_name].
    map(&:presence).compact.join(' at ').html_safe
end