Class: SalesRepWeight
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SalesRepWeight
- Includes:
- Models::Auditable
- Defined in:
- app/models/sales_rep_weight.rb
Overview
== Schema Information
Table name: sales_rep_weights
Database name: primary
id :integer not null, primary key
remaining :integer default(0), not null
role :string(255) not null
weight :integer default(0), not null
employee_id :integer not null
sales_rep_queue_entry_id :integer not null
Indexes
idx_sales_rep_weights (sales_rep_queue_entry_id,role,employee_id) UNIQUE
sales_rep_weights_employee_id_idx (employee_id)
Foreign Keys
sales_rep_weights_employee_id_fk (employee_id => parties.id) ON DELETE => cascade
sales_rep_weights_sales_rep_queue_entry_id_fk (sales_rep_queue_entry_id => sales_rep_queue_entries.id) ON DELETE => cascade
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
- #remaining ⇒ Object readonly
- #role ⇒ Object readonly
- #weight ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Class Method Summary collapse
-
.assignable ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are assignable.
-
.local_sales_reps ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are local sales reps.
-
.primary_sales_reps ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are primary sales reps.
-
.secondary_sales_reps ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are secondary sales reps.
-
.with_employee_sorted ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are with employee sorted.
Instance Method Summary collapse
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
#remaining ⇒ Object (readonly)
31 |
# File 'app/models/sales_rep_weight.rb', line 31 validates :remaining, numericality: { only_integer: true, less_than_or_equal_to: :weight } |
#role ⇒ Object (readonly)
32 33 |
# File 'app/models/sales_rep_weight.rb', line 32 validates :role, inclusion: { in: %w(primary_sales_rep secondary_sales_rep local_sales_rep), message: "%{value} is not a valid role" } |
#weight ⇒ Object (readonly)
30 |
# File 'app/models/sales_rep_weight.rb', line 30 validates :weight, numericality: { only_integer: true, greater_than: 0 } |
Class Method Details
.assignable ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are assignable. Active Record Scope
39 |
# File 'app/models/sales_rep_weight.rb', line 39 scope :assignable, -> { where(SalesRepWeight[:remaining].gt(0)) } |
.local_sales_reps ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are local sales reps. Active Record Scope
42 |
# File 'app/models/sales_rep_weight.rb', line 42 scope :local_sales_reps, -> { where(role: :local_sales_rep) } |
.primary_sales_reps ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are primary sales reps. Active Record Scope
40 |
# File 'app/models/sales_rep_weight.rb', line 40 scope :primary_sales_reps, -> { where(role: :primary_sales_rep) } |
.secondary_sales_reps ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are secondary sales reps. Active Record Scope
41 |
# File 'app/models/sales_rep_weight.rb', line 41 scope :secondary_sales_reps, -> { where(role: :secondary_sales_rep) } |
.with_employee_sorted ⇒ ActiveRecord::Relation<SalesRepWeight>
A relation of SalesRepWeights that are with employee sorted. Active Record Scope
43 |
# File 'app/models/sales_rep_weight.rb', line 43 scope :with_employee_sorted, -> { joins(:employee).order(Employee[:full_name]) } |
Instance Method Details
#effective_remaining ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/sales_rep_weight.rb', line 45 def effective_remaining # if rep is not working, weight is going to return 0 # after 4pm, you need to be working the next day to have a weight if Time.current.hour > 16 || !Date.current.on_weekday? check_date = Date.current.next_business_day else check_date = Date.current end if employee.working_on_day?(check_date) remaining else 0 end end |
#employee ⇒ Employee
28 |
# File 'app/models/sales_rep_weight.rb', line 28 belongs_to :employee, optional: true |
#sales_rep_queue_entry ⇒ SalesRepQueueEntry
Validations:
27 |
# File 'app/models/sales_rep_weight.rb', line 27 belongs_to :sales_rep_queue_entry, inverse_of: :sales_rep_weights, optional: true |