Module: EmployeeSelectOptions::ClassMethods
- Defined in:
- app/models/concerns/employee_select_options.rb
Overview
Class-level select-option helpers.
Instance Method Summary collapse
- #activity_assignment_options_for_select ⇒ Object
- #all_active_employees_sms_numbers(rep_ids: nil, format_for_select: false) ⇒ Object
- #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
- #blog_author_options_for_select ⇒ Object
- #customer_service_manager ⇒ Object
- #engineering_rep_options_for_select(show_working_status: false) ⇒ Object
- #for_sales_rep_assignment_queue(_store, role) ⇒ Object
- #format_for_select(reps, show_working_status: false) ⇒ Object
- #local_sales_rep_options_for_select(show_working_status: false) ⇒ Object
- #managers_select_options ⇒ Object
- #phone_employees_select_options ⇒ Object
- #primary_sales_rep_options_for_select(show_working_status: false) ⇒ Object
- #sales_rep_options_for_select ⇒ Object
- #secondary_sales_rep_options_for_select(show_working_status: false) ⇒ Object
- #select_options(exclude_ids: [], active_only: true) ⇒ Object
- #sms_enabled_for_select ⇒ Object
- #technical_support_rep_options_for_select(show_working_status: false) ⇒ Object
Instance Method Details
#activity_assignment_options_for_select ⇒ Object
35 36 37 |
# File 'app/models/concerns/employee_select_options.rb', line 35 def 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 (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 ⇒ Object
39 40 41 |
# File 'app/models/concerns/employee_select_options.rb', line 39 def [['No Author', nil]] + blog_employees.sorted.pluck(:full_name, :id) end |
#customer_service_manager ⇒ Object
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 (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 (show_working_status: false) format_for_select(local_sales_reps.active_employees.sorted, show_working_status:) end |
#managers_select_options ⇒ Object
9 10 11 |
# File 'app/models/concerns/employee_select_options.rb', line 9 def active_employees.sorted.pluck(:full_name, :id) end |
#phone_employees_select_options ⇒ Object
18 19 20 |
# File 'app/models/concerns/employee_select_options.rb', line 18 def 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 (show_working_status: false) format_for_select(primary_sales_reps.active_employees.sorted, show_working_status:) end |
#sales_rep_options_for_select ⇒ Object
43 44 45 |
# File 'app/models/concerns/employee_select_options.rb', line 43 def 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 (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 (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 ⇒ Object
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 (show_working_status: false) format_for_select(technical_support_reps.active_employees.sorted, show_working_status:) end |