Class: ActivityTypeAssignmentQueue
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActivityTypeAssignmentQueue
- Includes:
- Models::Auditable
- Defined in:
- app/models/activity_type_assignment_queue.rb
Overview
Links an activity assignment queue to the activity types
== Schema Information
Table name: activity_type_assignment_queues
Database name: primary
id :integer not null, primary key
activity_type_id :integer not null
assignment_queue_id :integer not null
company_id :integer not null
fallback_employee_id :integer
Indexes
activity_type_assignment_queues_assignment_queue_id_idx (assignment_queue_id)
activity_type_assignment_queues_company_id_idx (company_id)
idx_activity_types_assignment_queues (activity_type_id,assignment_queue_id,company_id) UNIQUE
Foreign Keys
activity_type_assignment_queues_activity_type_id_fk (activity_type_id => activity_types.id)
activity_type_assignment_queues_assignment_queue_id_fk (assignment_queue_id => assignment_queues.id)
activity_type_assignment_queues_company_id_fk (company_id => companies.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
-
#activity_type ⇒ ActivityType?
The activity type this record belongs to.
-
#assignment_queue ⇒ AssignmentQueue?
The assignment queue this record belongs to.
-
#company ⇒ Company?
The company this record belongs to.
-
#fallback_employee ⇒ Employee?
The fallback employee this record belongs to.
Methods included from Models::Auditable
Class Method Summary collapse
-
.employees_id_by_role_id(rid) ⇒ Object
Employees id by role id.
Instance Method Summary collapse
-
#get_first_resource(customer, current_user_id = nil, target_date = nil, priority = nil, assignment_matrix = nil, resource = nil, options = {}) ⇒ Integer?
The id of the first available rep.
-
#get_full_queue_resources(c, current_user_id = nil) ⇒ Object
Get full queue resources.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.employees_id_by_role_id(rid) ⇒ Object
Employees id by role id.
130 131 132 |
# File 'app/models/activity_type_assignment_queue.rb', line 130 def self.employees_id_by_role_id(rid) Employee.active_employees.by_direct_role_id(rid).ids end |
Instance Method Details
#activity_type ⇒ ActivityType?
Returns the activity type this record belongs to.
30 |
# File 'app/models/activity_type_assignment_queue.rb', line 30 belongs_to :activity_type, inverse_of: :activity_type_assignment_queues, optional: true |
#assignment_queue ⇒ AssignmentQueue?
Returns the assignment queue this record belongs to.
34 |
# File 'app/models/activity_type_assignment_queue.rb', line 34 belongs_to :assignment_queue, inverse_of: :activity_type_assignment_queues, optional: true |
#company ⇒ Company?
Returns the company this record belongs to.
32 |
# File 'app/models/activity_type_assignment_queue.rb', line 32 belongs_to :company, inverse_of: :activity_type_assignment_queues, optional: true |
#fallback_employee ⇒ Employee?
Returns the fallback employee this record belongs to.
36 |
# File 'app/models/activity_type_assignment_queue.rb', line 36 belongs_to :fallback_employee, class_name: 'Employee', optional: true |
#get_first_resource(customer, current_user_id = nil, target_date = nil, priority = nil, assignment_matrix = nil, resource = nil, options = {}) ⇒ Integer?
Returns the id of the first available rep.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/activity_type_assignment_queue.rb', line 52 def get_first_resource(customer, current_user_id = nil, target_date = nil, priority = nil, assignment_matrix = nil, resource = nil, = {}) excluded_rep_ids ||= [] # Here we will maintain an array of rep that have been skipped so we can be more efficient in reprocessing. assigned_rep_id = nil queue_entries = [] + assignment_queue.queue rep_ids = queue_entries.map do |queue_entry| AssignmentQueue.interpolate_with_customer(queue_entry, customer, current_user_id, target_date, excluded_rep_ids, assignment_matrix, resource) end rep_ids = rep_ids.compact.uniq # Keep it tidy if rep_ids.empty? # Unassignable, try fallback assigned_rep_id = fallback_employee_id raise AssignmentQueue::UnassignableActivity unless assigned_rep_id else rep_ids.each do |rep_id| logger.debug " ** Queue entry yielded rep id #{rep_id}" can_take_activities = false if block_given? # Use the block to determine rep availabilities. can_take_activities = yield(rep_id) elsif target_date.nil? || [:ignore_target_date] can_take_activities = true else rep = Employee.find(rep_id) can_take_activities = rep.can_take_activities_on_day?(target_date, priority) end if can_take_activities assigned_rep_id = rep_id break else logger.debug " ** Rep #{rep_id} is not working or unable to take more activities on #{target_date}, skipping" excluded_rep_ids << rep_id end end end assigned_rep_id end |
#get_full_queue_resources(c, current_user_id = nil) ⇒ Object
Get full queue resources.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/activity_type_assignment_queue.rb', line 97 def get_full_queue_resources(c, current_user_id = nil) queue_entries = [] assignment_queue.queue.each do |q| case q when 'primary_sales_rep' queue_entries << c.try(:primary_sales_rep_id) when 'primary_sales_rep_backup' queue_entries << c.try(:primary_sales_rep).try(:backup_rep_id) when 'secondary_sales_rep' queue_entries << c.secondary_sales_rep_id when 'local_sales_rep' queue_entries << c.local_sales_rep_id when 'service_rep' queue_entries << c.service_rep_id when 'current_user' queue_entries << current_user_id else t, eid = q.split('|') case t when 'Employee' queue_entries << eid.to_i when 'LBR' queue_entries += self.class.employees_id_by_role_id(eid.to_i).shuffle end end queue_entries = queue_entries.uniq.compact break if !activity_type.priority_tier? && queue_entries.present? # only need one entry for low tiers end queue_entries end |