Module: EmployeeSelectOptions::ClassMethods

Defined in:
app/models/concerns/employee_select_options.rb

Overview

Class-level select-option helpers.

Instance Method Summary collapse

Instance Method Details

#activity_assignment_options_for_selectObject



35
36
37
# File 'app/models/concerns/employee_select_options.rb', line 35

def activity_assignment_options_for_select
  active_employees.sorted.pluck(:full_name, :id)
end

#all_active_employees_sms_numbers(rep_ids: nil, format_for_select: false) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'app/models/concerns/employee_select_options.rb', line 88

def all_active_employees_sms_numbers(rep_ids: nil, format_for_select: false)
  employees = Employee.active_employees
  employees = employees.where(id: rep_ids) if rep_ids.present?
  contact_points = ContactPoint.joins(:party).merge(employees).company_sms_numbers.order(:detail)
  if format_for_select
    contact_points.map { |cp| ["#{cp.formatted_for_sms} - #{cp.party.full_name}", cp.formatted_for_sms] }.uniq
  else
    contact_points.map(&:formatted_for_sms).uniq
  end
end

#assigned_sales_rep_options_for_select(role_types: %i[primary_sales_rep_id secondary_sales_rep_id local_sales_rep_id],, customer_ids: nil) ⇒ Object



47
48
49
50
51
52
53
54
# File 'app/models/concerns/employee_select_options.rb', line 47

def assigned_sales_rep_options_for_select(role_types: %i[primary_sales_rep_id secondary_sales_rep_id local_sales_rep_id], customer_ids: nil)
  rep_ids = role_types.flat_map do |r|
    customers = Customer.where.not(r => nil)
    customers = customers.where(id: customer_ids) if customer_ids.present?
    customers.pluck("distinct #{r}")
  end.uniq
  Employee.where(id: rep_ids).order(:full_name).pluck(:full_name, :id)
end

#blog_author_options_for_selectObject



39
40
41
# File 'app/models/concerns/employee_select_options.rb', line 39

def blog_author_options_for_select
  [['No Author', nil]] + blog_employees.sorted.pluck(:full_name, :id)
end

#customer_service_managerObject



84
85
86
# File 'app/models/concerns/employee_select_options.rb', line 84

def customer_service_manager
  Employee.joins(account: :roles).where(Role[:name].eq('customer_service_manager')).first
end

#engineering_rep_options_for_select(show_working_status: false) ⇒ Object



76
77
78
# File 'app/models/concerns/employee_select_options.rb', line 76

def engineering_rep_options_for_select(show_working_status: false)
  format_for_select(engineers.active_employees.sorted, show_working_status:)
end

#for_sales_rep_assignment_queue(_store, role) ⇒ Object



31
32
33
# File 'app/models/concerns/employee_select_options.rb', line 31

def for_sales_rep_assignment_queue(_store, role)
  active_employees.joins(:employee_record).where(employee_records: { role.to_sym => true }).sorted
end

#format_for_select(reps, show_working_status: false) ⇒ Object



56
57
58
59
60
61
62
# File 'app/models/concerns/employee_select_options.rb', line 56

def format_for_select(reps, show_working_status: false)
  reps.map do |r|
    rep_name = r.full_name
    rep_name = "#{rep_name} (#{r.work_status_on_day(Date.current).to_s.humanize})" if show_working_status
    [rep_name, r.id]
  end
end

#local_sales_rep_options_for_select(show_working_status: false) ⇒ Object



72
73
74
# File 'app/models/concerns/employee_select_options.rb', line 72

def local_sales_rep_options_for_select(show_working_status: false)
  format_for_select(local_sales_reps.active_employees.sorted, show_working_status:)
end

#managers_select_optionsObject



9
10
11
# File 'app/models/concerns/employee_select_options.rb', line 9

def managers_select_options
  active_employees.sorted.pluck(:full_name, :id)
end

#phone_employees_select_optionsObject



18
19
20
# File 'app/models/concerns/employee_select_options.rb', line 18

def phone_employees_select_options
  active_employees.joins(:employee_phone_status).sorted.pluck(:full_name, :id)
end

#primary_sales_rep_options_for_select(show_working_status: false) ⇒ Object



64
65
66
# File 'app/models/concerns/employee_select_options.rb', line 64

def primary_sales_rep_options_for_select(show_working_status: false)
  format_for_select(primary_sales_reps.active_employees.sorted, show_working_status:)
end

#sales_rep_options_for_selectObject



43
44
45
# File 'app/models/concerns/employee_select_options.rb', line 43

def sales_rep_options_for_select
  sales_reps.active_employees.sorted.pluck(:full_name, :id)
end

#secondary_sales_rep_options_for_select(show_working_status: false) ⇒ Object



68
69
70
# File 'app/models/concerns/employee_select_options.rb', line 68

def secondary_sales_rep_options_for_select(show_working_status: false)
  format_for_select(secondary_sales_reps.active_employees.sorted, show_working_status:)
end

#select_options(exclude_ids: [], active_only: true) ⇒ Object



13
14
15
16
# File 'app/models/concerns/employee_select_options.rb', line 13

def select_options(exclude_ids: [], active_only: true)
  scope = active_only ? active_employees : Employee.all
  scope.where.not(id: exclude_ids).sorted.pluck(:full_name, :id)
end

#sms_enabled_for_selectObject



22
23
24
25
26
27
28
29
# File 'app/models/concerns/employee_select_options.rb', line 22

def sms_enabled_for_select
  active_employees
    .joins(:employee_phone_status)
    .where.not(employee_phone_statuses: { contact_point_id: nil })
    .includes(employee_phone_status: :contact_point)
    .sorted
    .map { |e| ["#{e.full_name} - #{PhoneNumber.parse_and_format(e.pbx_did, display_format: :crm)}", e.id] }
end

#technical_support_rep_options_for_select(show_working_status: false) ⇒ Object



80
81
82
# File 'app/models/concerns/employee_select_options.rb', line 80

def technical_support_rep_options_for_select(show_working_status: false)
  format_for_select(technical_support_reps.active_employees.sorted, show_working_status:)
end