Class: AssignmentQueue

Inherits:
ApplicationRecord show all
Extended by:
Memery
Includes:
Memery, Models::Auditable
Defined in:
app/models/assignment_queue.rb

Overview

== Schema Information

Table name: assignment_queues
Database name: primary

id :integer not null, primary key
queue :string(255) default([]), not null, is an Array
created_at :datetime not null
updated_at :datetime
creator_id :integer
updater_id :integer

Indexes

idx_assignment_queues_queue (queue) UNIQUE

Defined Under Namespace

Classes: UnassignableActivity

Constant Summary collapse

VARIABLE_OPTIONS =
[['Logged-in User', 'current_user'],
['Primary Sales Rep', 'primary_sales_rep'],
['Primary Sales Rep Backup', 'primary_sales_rep_backup'],
['Secondary Sales Rep', 'secondary_sales_rep'],
['Local Sales Rep', 'local_sales_rep'],
['Service Rep', 'service_rep']].freeze
TICKET_VARIABLE_OPTIONS =
[['Assigned Rep', 'ticket_assigned_rep']].freeze

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater

Methods inherited from ApplicationRecord

ransackable_associations, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#lbr_methodObject

Returns the value of attribute lbr_method.



47
48
49
# File 'app/models/assignment_queue.rb', line 47

def lbr_method
  @lbr_method
end

Class Method Details

.containing_entry_namedActiveRecord::Relation<AssignmentQueue>

A relation of AssignmentQueues that are containing entry named. Active Record Scope

Returns:

See Also:



31
32
33
34
35
36
37
# File 'app/models/assignment_queue.rb', line 31

scope :containing_entry_named, ->(val) {
  return all if val.blank?
  matching = queue_select_options
               .select { |label, _| label.downcase.include?(val.to_s.downcase) }
               .map(&:last)
  matching.any? ? where("queue && ARRAY[?]::varchar[]", matching) : none
}

.employee_select_optionsObject

Builds a list of possible employees to use in activity assignment queues



87
88
89
# File 'app/models/assignment_queue.rb', line 87

def employee_select_options
  Employee.select_options.map { |o| [o[0], "Employee|#{o[1]}"] }
end

.grouped_queue_select_optionsObject

Returns a grouped list of queue options suitable for an options for select grouped



67
68
69
70
71
72
73
74
# File 'app/models/assignment_queue.rb', line 67

def grouped_queue_select_options
  {
    'Customer Roles' => VARIABLE_OPTIONS,
    'Support Case Roles' => TICKET_VARIABLE_OPTIONS,
    'Least Busy by Role' => role_select_options,
    'Employees' => employee_select_options
  }
end

.interpolate_with_customer(q, c, current_user_id = nil, target_date = nil, excluded_rep_ids = [], assignment_matrix = nil, resource = nil) ⇒ Object

Based on a queue entry and a customer determines the appropriate resource id to return
q is the queue entry type
c is the customer
current_user_id is the logged in customer
target_date is when the task is due
time_sensitive is true when the activity MUST be assigned to someone working on that day.
excluded_rep_ids a list of rep to not include in possible return values.



121
122
123
124
125
126
127
128
129
# File 'app/models/assignment_queue.rb', line 121

def interpolate_with_customer(q, c, current_user_id = nil, target_date = nil, excluded_rep_ids = [], assignment_matrix = nil, resource = nil)
  target_date ||= Date.current

  cache_key = [:interpolate_with_customer, q, [c.class.name, c.id], current_user_id, target_date,
               excluded_rep_ids, assignment_matrix, resource && [resource.class.name, resource.id]]
  fetch_cached(*cache_key) do
    compute_interpolate_with_customer(q, c, current_user_id, target_date, excluded_rep_ids, assignment_matrix, resource)
  end
end

.least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix = nil) ⇒ Object

Queries database to find out the least busy rep



132
133
134
135
136
# File 'app/models/assignment_queue.rb', line 132

def least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix = nil)
  fetch_cached(:least_busy_rep_by_role, target_date, role_id, excluded_rep_ids, assignment_matrix) do
    compute_least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix)
  end
end

.queue_select_optionsObject

Builds a list of possible queue values, variable role based values and individuals



82
83
84
# File 'app/models/assignment_queue.rb', line 82

def queue_select_options
  [] + VARIABLE_OPTIONS + TICKET_VARIABLE_OPTIONS + role_select_options + employee_select_options
end

.queue_value_expanded(q) ⇒ Object

Translates a queue value to a friendly name



96
97
98
99
100
101
102
103
104
# File 'app/models/assignment_queue.rb', line 96

def queue_value_expanded(q)
  match = queue_select_options.detect { |e| e[1] == q }
  if match
    match[0]
  else
    logger.error " !!! queue_value_expanded: Could not determine the value of q -> #{q}"
    raise "Value of q missing in table #{q}"
  end
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



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

def self.ransackable_attributes(_auth_object = nil)
  %w[id queue created_at updated_at]
end

.ransackable_scopes(_auth_object = nil) ⇒ Object



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

def self.ransackable_scopes(_auth_object = nil)
  %i[containing_entry_named]
end

.rep_id_for_backup(rep_id) ⇒ Object



106
107
108
109
110
111
112
# File 'app/models/assignment_queue.rb', line 106

def rep_id_for_backup(rep_id)
  return nil unless rep_id

  fetch_cached(:rep_id_for_backup, rep_id) do
    EmployeeRecord.where(party_id: rep_id).pick(:backup_rep_id)
  end
end

.role_select_optionsObject



91
92
93
# File 'app/models/assignment_queue.rb', line 91

def role_select_options
  Role.select_options.map { |r| [r[0], "LBR|#{r[1]}"] }
end

.select_optionsObject

Provides a list of assignment queues to select from



62
63
64
# File 'app/models/assignment_queue.rb', line 62

def select_options
  all.to_a.reject { |aq| aq.name.nil? }.sort_by(&:name).map { |aq| ["#{aq.name} [#{aq.id}]", aq.id] }
end

.valid_valuesObject

Returns a list of valid values for the queue type selection



77
78
79
# File 'app/models/assignment_queue.rb', line 77

def valid_values
  queue_select_options.map { |e| e[1] }
end

Instance Method Details

#activity_type_assignment_queuesActiveRecord::Relation<ActivityTypeAssignmentQueue>

Returns:

See Also:



22
# File 'app/models/assignment_queue.rb', line 22

has_many :activity_type_assignment_queues, inverse_of: :assignment_queue

#activity_typesActiveRecord::Relation<ActivityType>

Returns:

See Also:



23
# File 'app/models/assignment_queue.rb', line 23

has_many :activity_types, through: :activity_type_assignment_queues

#nameObject



210
211
212
213
214
# File 'app/models/assignment_queue.rb', line 210

def name
  queue.map { |e| self.class.queue_value_expanded(e) }.join(' -> ')
rescue StandardError
  nil
end