Module: Models::EmployeeSelectOptions::ClassMethods
- Defined in:
- app/concerns/models/employee_select_options.rb
Overview
Class-level select-option helpers.
Instance Method Summary collapse
-
#activity_assignment_options_for_select ⇒ Array<Array(String, Integer)>
Builds select options of active employees for activity assignment.
-
#all_active_employees_sms_numbers(rep_ids: nil, format_for_select: false) ⇒ Array<String>, Array<Array(String, String)>
Returns distinct formatted SMS numbers for active employees, optionally scoped to specific reps and formatted as select options.
-
#assigned_sales_rep_options_for_select(role_types: %i[primary_sales_rep_id secondary_sales_rep_id local_sales_rep_id],, customer_ids: nil) ⇒ Array<Array(String, Integer)>
Builds select options of employees currently assigned as a sales rep on any customer, for the given rep role columns.
-
#blog_author_options_for_select ⇒ Array<Array(String, Integer, nil)>
Builds select options of employees allowed to author blog posts, prepended with a "No Author" blank option.
-
#customer_service_manager ⇒ Employee?
Finds the employee holding the customer_service_manager role.
-
#engineering_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active engineering reps.
-
#for_sales_rep_assignment_queue(_store, role) ⇒ ActiveRecord::Relation<Employee>
Returns active employees whose employee record flags them for the given role, used by the sales rep assignment queue.
-
#format_for_select(reps, show_working_status: false) ⇒ Array<Array(String, Integer)>
Formats a collection of reps into select options, optionally appending each rep's working status for the current day to the label.
-
#local_sales_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active local sales reps.
-
#managers_select_options ⇒ Array<Array(String, Integer)>
Builds select options of active employees eligible to be managers.
-
#phone_employees_select_options ⇒ Array<Array(String, Integer)>
Builds select options of active employees who have a phone status.
-
#primary_sales_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active primary sales reps.
-
#sales_rep_options_for_select ⇒ Array<Array(String, Integer)>
Builds select options of active sales reps.
-
#secondary_sales_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active secondary sales reps.
-
#select_options(exclude_ids: [], active_only: true) ⇒ Array<Array(String, Integer)>
Builds select options of employees, optionally excluding ids and limiting to active employees.
-
#sms_enabled_for_select ⇒ Array<Array(String, Integer)>
Builds select options of active employees with an SMS contact point, including their formatted phone number in the label.
-
#technical_support_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active technical support reps.
Instance Method Details
#activity_assignment_options_for_select ⇒ Array<Array(String, Integer)>
Builds select options of active employees for activity assignment.
60 61 62 |
# File 'app/concerns/models/employee_select_options.rb', line 60 def active_employees.sorted.pluck(:full_name, :id) end |
#all_active_employees_sms_numbers(rep_ids: nil, format_for_select: false) ⇒ Array<String>, Array<Array(String, String)>
Returns distinct formatted SMS numbers for active employees, optionally
scoped to specific reps and formatted as select options.
162 163 164 165 166 167 168 169 170 171 |
# File 'app/concerns/models/employee_select_options.rb', line 162 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) ⇒ Array<Array(String, Integer)>
Builds select options of employees currently assigned as a sales rep on
any customer, for the given rep role columns.
85 86 87 88 89 90 91 92 |
# File 'app/concerns/models/employee_select_options.rb', line 85 def (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_select ⇒ Array<Array(String, Integer, nil)>
Builds select options of employees allowed to author blog posts,
prepended with a "No Author" blank option.
68 69 70 |
# File 'app/concerns/models/employee_select_options.rb', line 68 def [['No Author', nil]] + blog_employees.sorted.pluck(:full_name, :id) end |
#customer_service_manager ⇒ Employee?
Finds the employee holding the customer_service_manager role.
151 152 153 |
# File 'app/concerns/models/employee_select_options.rb', line 151 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) ⇒ Array<Array(String, Integer)>
Builds select options of active engineering reps.
136 137 138 |
# File 'app/concerns/models/employee_select_options.rb', line 136 def (show_working_status: false) format_for_select(engineers.active_employees.sorted, show_working_status:) end |
#for_sales_rep_assignment_queue(_store, role) ⇒ ActiveRecord::Relation<Employee>
Returns active employees whose employee record flags them for the given
role, used by the sales rep assignment queue.
53 54 55 |
# File 'app/concerns/models/employee_select_options.rb', line 53 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) ⇒ Array<Array(String, Integer)>
Formats a collection of reps into select options, optionally appending
each rep's working status for the current day to the label.
100 101 102 103 104 105 106 |
# File 'app/concerns/models/employee_select_options.rb', line 100 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) ⇒ Array<Array(String, Integer)>
Builds select options of active local sales reps.
128 129 130 |
# File 'app/concerns/models/employee_select_options.rb', line 128 def (show_working_status: false) format_for_select(local_sales_reps.active_employees.sorted, show_working_status:) end |
#managers_select_options ⇒ Array<Array(String, Integer)>
Builds select options of active employees eligible to be managers.
12 13 14 |
# File 'app/concerns/models/employee_select_options.rb', line 12 def active_employees.sorted.pluck(:full_name, :id) end |
#phone_employees_select_options ⇒ Array<Array(String, Integer)>
Builds select options of active employees who have a phone status.
30 31 32 |
# File 'app/concerns/models/employee_select_options.rb', line 30 def active_employees.joins(:employee_phone_status).sorted.pluck(:full_name, :id) end |
#primary_sales_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active primary sales reps.
112 113 114 |
# File 'app/concerns/models/employee_select_options.rb', line 112 def (show_working_status: false) format_for_select(primary_sales_reps.active_employees.sorted, show_working_status:) end |
#sales_rep_options_for_select ⇒ Array<Array(String, Integer)>
Builds select options of active sales reps.
75 76 77 |
# File 'app/concerns/models/employee_select_options.rb', line 75 def sales_reps.active_employees.sorted.pluck(:full_name, :id) end |
#secondary_sales_rep_options_for_select(show_working_status: false) ⇒ Array<Array(String, Integer)>
Builds select options of active secondary sales reps.
120 121 122 |
# File 'app/concerns/models/employee_select_options.rb', line 120 def (show_working_status: false) format_for_select(secondary_sales_reps.active_employees.sorted, show_working_status:) end |
#select_options(exclude_ids: [], active_only: true) ⇒ Array<Array(String, Integer)>
Builds select options of employees, optionally excluding ids and
limiting to active employees.
22 23 24 25 |
# File 'app/concerns/models/employee_select_options.rb', line 22 def (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_select ⇒ Array<Array(String, Integer)>
Builds select options of active employees with an SMS contact point,
including their formatted phone number in the label.
38 39 40 41 42 43 44 45 |
# File 'app/concerns/models/employee_select_options.rb', line 38 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) ⇒ Array<Array(String, Integer)>
Builds select options of active technical support reps.
144 145 146 |
# File 'app/concerns/models/employee_select_options.rb', line 144 def (show_working_status: false) format_for_select(technical_support_reps.active_employees.sorted, show_working_status:) end |