Class: EmployeeGoal
Overview
== Schema Information
Table name: employee_goals
Database name: primary
id :integer not null, primary key
description :text
due_date :date not null
earned_reward :decimal(6, 2)
employee_comments :text
name :string(255) not null
potential_reward :decimal(6, 2)
state :string(255) not null
supervisor_comments :text
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
employee_review_id :integer
updater_id :integer
Indexes
employee_review_id_name (employee_review_id,name)
employee_review_id_state (employee_review_id,state)
Constant Summary
collapse
- FINALIZED_STATES =
%i[reached missed cancelled].freeze
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#description ⇒ Object
36
|
# File 'app/models/employee_goal.rb', line 36
validates :description, presence: true
|
#due_date ⇒ Object
37
|
# File 'app/models/employee_goal.rb', line 37
validates :due_date, presence: true
|
#earned_reward ⇒ Object
40
|
# File 'app/models/employee_goal.rb', line 40
validates :earned_reward, numericality: { greather_than_or_equal: 0 }, if: -> { reached? && potential_reward.present? }
|
41
|
# File 'app/models/employee_goal.rb', line 41
validates :employee_comments, presence: { message: 'required when goal missed.' }, if: :missed?
|
#name ⇒ Object
35
|
# File 'app/models/employee_goal.rb', line 35
validates :name, presence: true, uniqueness: { scope: :employee_review_id }
|
#potential_reward ⇒ Object
39
|
# File 'app/models/employee_goal.rb', line 39
validates :potential_reward, numericality: { greather_than_or_equal: 0 }, if: -> { potential_reward.present? }
|
42
|
# File 'app/models/employee_goal.rb', line 42
validates :supervisor_comments, presence: { message: 'required when goal missed.' }, if: :missed?
|
Class Method Details
.active ⇒ ActiveRecord::Relation<EmployeeGoal>
A relation of EmployeeGoals that are active. Active Record Scope
49
|
# File 'app/models/employee_goal.rb', line 49
scope :active, -> { where(EmployeeGoal[:state].not_eq('cancelled')) }
|
.departments_for_select ⇒ Object
86
87
88
|
# File 'app/models/employee_goal.rb', line 86
def self.departments_for_select
joins(employee_review: :employee_record).distinct.pluck(EmployeeRecord[:department]).compact.sort
end
|
.finalized ⇒ ActiveRecord::Relation<EmployeeGoal>
A relation of EmployeeGoals that are finalized. Active Record Scope
.states_for_select ⇒ Object
82
83
84
|
# File 'app/models/employee_goal.rb', line 82
def self.states_for_select
state_machines[:state].states.map { |s| [s.name.to_s.titleize, s.name.to_s] }.sort
end
|
.unfinalized ⇒ ActiveRecord::Relation<EmployeeGoal>
A relation of EmployeeGoals that are unfinalized. Active Record Scope
Instance Method Details
#allocated_reward_in_other_goals ⇒ Object
98
99
100
|
# File 'app/models/employee_goal.rb', line 98
def allocated_reward_in_other_goals
employee_review.employee_goals.where.not(employee_goals: { id: id.to_i }).sum(:potential_reward) || 0.00
end
|
#employee ⇒ Object
90
91
92
|
# File 'app/models/employee_goal.rb', line 90
def employee
employee_review&.employee_record&.employee
end
|
#employee_name ⇒ Object
94
95
96
|
# File 'app/models/employee_goal.rb', line 94
def employee_name
employee&.full_name
end
|
Validations:
32
|
# File 'app/models/employee_goal.rb', line 32
belongs_to :employee_review, inverse_of: :employee_goals, optional: true
|
#finalized? ⇒ Boolean
110
111
112
|
# File 'app/models/employee_goal.rb', line 110
def finalized?
FINALIZED_STATES.include? state
end
|
#possible_events ⇒ Object
102
103
104
|
# File 'app/models/employee_goal.rb', line 102
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
106
107
108
|
# File 'app/models/employee_goal.rb', line 106
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|