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 =
Recognised finalized states.
%i[reached missed cancelled].freeze
Models::Auditable::ALWAYS_IGNORED
Constants included
from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
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
config
#after_commit
#publish_event
Instance Attribute Details
#description ⇒ Object
38
|
# File 'app/models/employee_goal.rb', line 38
validates :description, presence: true
|
#due_date ⇒ Object
39
|
# File 'app/models/employee_goal.rb', line 39
validates :due_date, presence: true
|
#earned_reward ⇒ Object
42
|
# File 'app/models/employee_goal.rb', line 42
validates :earned_reward, numericality: { greather_than_or_equal: 0 }, if: -> { reached? && potential_reward.present? }
|
43
|
# File 'app/models/employee_goal.rb', line 43
validates :employee_comments, presence: { message: 'required when goal missed.' }, if: :missed?
|
#name ⇒ Object
37
|
# File 'app/models/employee_goal.rb', line 37
validates :name, presence: true, uniqueness: { scope: :employee_review_id }
|
#potential_reward ⇒ Object
41
|
# File 'app/models/employee_goal.rb', line 41
validates :potential_reward, numericality: { greather_than_or_equal: 0 }, if: -> { potential_reward.present? }
|
44
|
# File 'app/models/employee_goal.rb', line 44
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
51
|
# File 'app/models/employee_goal.rb', line 51
scope :active, -> { where(EmployeeGoal[:state].not_eq('cancelled')) }
|
.departments_for_select ⇒ Object
88
89
90
|
# File 'app/models/employee_goal.rb', line 88
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
84
85
86
|
# File 'app/models/employee_goal.rb', line 84
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
100
101
102
|
# File 'app/models/employee_goal.rb', line 100
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
92
93
94
|
# File 'app/models/employee_goal.rb', line 92
def employee
employee_review&.employee_record&.employee
end
|
#employee_name ⇒ Object
96
97
98
|
# File 'app/models/employee_goal.rb', line 96
def employee_name
employee&.full_name
end
|
Validations:
34
|
# File 'app/models/employee_goal.rb', line 34
belongs_to :employee_review, inverse_of: :employee_goals, optional: true
|
#finalized? ⇒ Boolean
112
113
114
|
# File 'app/models/employee_goal.rb', line 112
def finalized?
FINALIZED_STATES.include? state
end
|
#possible_events ⇒ Object
104
105
106
|
# File 'app/models/employee_goal.rb', line 104
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
108
109
110
|
# File 'app/models/employee_goal.rb', line 108
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|