Class: SalesRepQueue
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SalesRepQueue
- Includes:
- Models::Auditable
- Defined in:
- app/models/sales_rep_queue.rb
Overview
== Schema Information
Table name: sales_rep_queues
Database name: primary
id :integer not null, primary key
apply_paired_sales_rep :boolean
local_sales_rep_ids :integer default([]), is an Array
local_sales_rep_stack :integer default([]), is an Array
local_sales_rep_weights :integer default([]), is an Array
primary_sales_rep_ids :integer default([]), is an Array
primary_sales_rep_stack :integer default([]), is an Array
primary_sales_rep_weights :integer default([]), is an Array
secondary_sales_rep_ids :integer default([]), is an Array
secondary_sales_rep_stack :integer default([]), is an Array
secondary_sales_rep_weights :integer default([]), is an Array
created_at :datetime
updated_at :datetime
creator_id :integer
store_id :integer
updater_id :integer
Indexes
idx_store_id (store_id)
Constant Summary collapse
- SALES_REP_TYPES =
[:local_sales_rep, :primary_sales_rep, :secondary_sales_rep].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
- #store_id ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
Instance Method Summary collapse
- #first_eligible_sales_queue_entry(customer) ⇒ Object
-
#fix_order ⇒ Object
Move the empty customer filter (the default) to the bottom.
- #get_next_sales_rep_assignments_for_customer(customer) ⇒ Object
- #to_s ⇒ Object
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::EventPublishable
Instance Attribute Details
#store_id ⇒ Object (readonly)
34 |
# File 'app/models/sales_rep_queue.rb', line 34 validates :store_id, uniqueness: true |
Instance Method Details
#first_eligible_sales_queue_entry(customer) ⇒ Object
40 41 42 |
# File 'app/models/sales_rep_queue.rb', line 40 def first_eligible_sales_queue_entry(customer) sales_rep_queue_entries.to_a.detect{|qe| qe.applies_to_customer?(customer) } end |
#fix_order ⇒ Object
Move the empty customer filter (the default) to the bottom
74 75 76 |
# File 'app/models/sales_rep_queue.rb', line 74 def fix_order sales_rep_queue_entries.reject(&:customer_filter).each(&:move_to_bottom) end |
#get_next_sales_rep_assignments_for_customer(customer) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/sales_rep_queue.rb', line 44 def get_next_sales_rep_assignments_for_customer(customer) # find out which sales rep queue entry criteria apply selected_sales_reps = {} sales_rep_queue_entry_that_applies = first_eligible_sales_queue_entry(customer) return unless sales_rep_queue_entry_that_applies sales_rep_types = SALES_REP_TYPES.dup sales_rep_types.each do |sales_rep_type| if selected_sales_rep = sales_rep_queue_entry_that_applies.get_sales_rep(sales_rep_type) selected_sales_reps["#{sales_rep_type}_id".to_sym] = selected_sales_rep.id end # check if paired sales rep is to be applied and if so, that there is one defined if sales_rep_queue_entry_that_applies.apply_paired_sales_rep and backup_rep = selected_sales_rep.try(:employee_record).try(:backup_rep) # yes, so local gets applied first with paired being primary case sales_rep_type when :local_sales_rep selected_sales_reps[:primary_sales_rep_id] = backup_rep.try(:id) sales_rep_types.delete(:primary_sales_rep) when :primary_sales_rep # otherwise primary gets applied with paired being secondary selected_sales_reps[:secondary_sales_rep_id] = backup_rep.try(:id) sales_rep_types.delete(:secondary_sales_rep) end end end return selected_sales_reps end |
#sales_rep_queue_entries ⇒ ActiveRecord::Relation<SalesRepQueueEntry>
32 |
# File 'app/models/sales_rep_queue.rb', line 32 has_many :sales_rep_queue_entries, -> { order(:position) }, inverse_of: :sales_rep_queue |
#store ⇒ Store
31 |
# File 'app/models/sales_rep_queue.rb', line 31 belongs_to :store, required: true, optional: true |
#to_s ⇒ Object
78 79 80 |
# File 'app/models/sales_rep_queue.rb', line 78 def to_s store.name end |