Module: Models::RepSearchable::ClassMethods

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

Overview

Class methods added to the including model.

Instance Method Summary collapse

Instance Method Details

#grouped_local_sales_reps_for_select(_include_unassigned_search: true) ⇒ Hash{String => Array<Array(String, Integer)>}

Grouped rep options limited to active local sales reps.

Parameters:

  • _include_unassigned_search (Boolean) (defaults to: true)

    accepted for interface
    compatibility; ignored (unassigned search is always included)

Returns:

  • (Hash{String => Array<Array(String, Integer)>})

    grouped options
    for grouped_options_for_select



61
62
63
64
# File 'app/concerns/models/rep_searchable.rb', line 61

def grouped_local_sales_reps_for_select(_include_unassigned_search: true)
  active_reps = Employee.local_sales_reps.sorted.pluck(:full_name, :id)
  grouped_rep_for_select(active_reps: active_reps, label: 'Local Reps - Active')
end

#grouped_primary_sales_reps_for_select(_include_unassigned_search: true) ⇒ Hash{String => Array<Array(String, Integer)>}

Grouped rep options limited to active primary sales reps.

Parameters:

  • _include_unassigned_search (Boolean) (defaults to: true)

    accepted for interface
    compatibility; ignored (unassigned search is always included)

Returns:

  • (Hash{String => Array<Array(String, Integer)>})

    grouped options
    for grouped_options_for_select



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

def grouped_primary_sales_reps_for_select(_include_unassigned_search: true)
  active_reps = Employee.primary_sales_reps.active_employees.sorted.pluck(:full_name, :id)
  grouped_rep_for_select(active_reps: active_reps, label: 'Primary Reps - Active')
end

#grouped_rep_for_select(active_reps: [], label: 'Reps - Active', include_unassigned_search: true) ⇒ Hash{String => Array<Array(String, Integer)>}

Builds a grouped rep option hash for a select input.

Parameters:

  • active_reps (Array<Array(String, Integer)>) (defaults to: [])

    pre-fetched
    [full_name, id] pairs for the currently active reps of this group

  • label (String) (defaults to: 'Reps - Active')

    the optgroup label for the active reps section

  • include_unassigned_search (Boolean) (defaults to: true)

    whether to prepend an
    "Unassigned" pseudo-option under a "Special Search" group

Returns:

  • (Hash{String => Array<Array(String, Integer)>})

    group label to
    [[full_name, id], ...] pairs, suitable for grouped_options_for_select



24
25
26
27
28
29
30
31
# File 'app/concerns/models/rep_searchable.rb', line 24

def grouped_rep_for_select(active_reps: [], label: 'Reps - Active', include_unassigned_search: true)
  all_reps = Employee.select_options(active_only: false, exclude_ids: active_reps.filter_map(&:last))
  res = {}
  res['Special Search'] = [%w[Unassigned Unassigned]] if include_unassigned_search
  res[label] = active_reps if active_reps.present?
  res['All Reps Past and Present'] = all_reps
  res
end

#grouped_secondary_sales_reps_for_select(_include_unassigned_search: true) ⇒ Hash{String => Array<Array(String, Integer)>}

Grouped rep options limited to active secondary sales reps.

Parameters:

  • _include_unassigned_search (Boolean) (defaults to: true)

    accepted for interface
    compatibility; ignored (unassigned search is always included)

Returns:

  • (Hash{String => Array<Array(String, Integer)>})

    grouped options
    for grouped_options_for_select



50
51
52
53
# File 'app/concerns/models/rep_searchable.rb', line 50

def grouped_secondary_sales_reps_for_select(_include_unassigned_search: true)
  active_reps = Employee.secondary_sales_reps.sorted.pluck(:full_name, :id)
  grouped_rep_for_select(active_reps: active_reps, label: 'Secondary Reps - Active')
end

#grouped_service_reps_for_select(_include_unassigned_search: true) ⇒ Hash{String => Array<Array(String, Integer)>}

Grouped rep options limited to active service reps.

Parameters:

  • _include_unassigned_search (Boolean) (defaults to: true)

    accepted for interface
    compatibility; ignored (unassigned search is always included)

Returns:

  • (Hash{String => Array<Array(String, Integer)>})

    grouped options
    for grouped_options_for_select



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

def grouped_service_reps_for_select(_include_unassigned_search: true)
  active_reps = Employee.select_options(active_only: true)
  grouped_rep_for_select(active_reps: active_reps, label: 'Service Reps - Active')
end

#grouped_technical_reps_for_select(_include_unassigned_search: true) ⇒ Hash{String => Array<Array(String, Integer)>}

Grouped rep options limited to technical support reps.

Parameters:

  • _include_unassigned_search (Boolean) (defaults to: true)

    accepted for interface
    compatibility; ignored (unassigned search is always included)

Returns:

  • (Hash{String => Array<Array(String, Integer)>})

    grouped options
    for grouped_options_for_select



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

def grouped_technical_reps_for_select(_include_unassigned_search: true)
  active_reps = Employee.technical_support_rep_options_for_select
  grouped_rep_for_select(active_reps: active_reps, label: 'Technical Reps - Active')
end