Class: TimeOffPolicy

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/time_off_policy.rb

Overview

== Schema Information

Table name: time_off_policies
Database name: primary

id :bigint not null, primary key
accrual_frequency :string
accrual_interval :decimal(, )
accrual_rate :decimal(, )
accrual_rollover :decimal(, )
annual_accrual_timing :string
custom_accrual_date :date
effective_date :date
expiry_date :date
hours_per_week :integer
max_rollover(Maximum amount of time that can roll over) :decimal(10, 2) default(0.0)
max_tenure(Maximum tenure (in years) for this policy to apply (null = no upper limit)) :decimal(5, 2)
min_tenure(Minimum tenure (in years) for this policy to apply) :decimal(5, 2)
monthly_accrual_day :integer
name :string
notes :text
unlimited(Whether the policy offers unlimited accrual) :boolean default(FALSE), not null
weekly_accrual_day :integer
created_at :datetime not null
updated_at :datetime not null
parent_policy_id(References the preceding policy in the sequence) :integer
time_off_type_id :integer

Indexes

index_time_off_policies_on_time_off_type_id (time_off_type_id)

Foreign Keys

fk_rails_... (parent_policy_id => time_off_policies.id)
fk_rails_... (time_off_type_id => time_off_types.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class 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

#publish_event

Instance Attribute Details

#annual_accrual_timingObject (readonly)



52
# File 'app/models/time_off_policy.rb', line 52

validates :annual_accrual_timing, inclusion: { in: %w[beginning_of_year end_of_year], message: "must be 'beginning_of_year' or 'end_of_year'" }, allow_blank: true

#hours_per_weekObject (readonly)



53
# File 'app/models/time_off_policy.rb', line 53

validates :hours_per_week, presence: true, numericality: { only_integer: true, greater_than: 0 }

#monthly_accrual_dayObject (readonly)



51
# File 'app/models/time_off_policy.rb', line 51

validates :monthly_accrual_day, inclusion: { in: 1..31, message: "must be between 1 and 31" }, allow_nil: true

#weekly_accrual_dayObject (readonly)



50
# File 'app/models/time_off_policy.rb', line 50

validates :weekly_accrual_day, inclusion: { in: 0..6, message: "must be between 0 (Sunday) and 6 (Saturday)" }, allow_nil: true

Class Method Details

.accrual_period_listObject



55
56
57
# File 'app/models/time_off_policy.rb', line 55

def self.accrual_period_list
    ['weekly', 'annual']
end

.for_manager_policies_tabActiveRecord::Relation<TimeOffPolicy>

A relation of TimeOffPolicies that are for manager policies tab. Active Record Scope

Returns:

See Also:



42
# File 'app/models/time_off_policy.rb', line 42

scope :for_manager_policies_tab, -> { includes(:time_off_type, :time_off_policy_assignments) }

.policy_listObject



59
60
61
# File 'app/models/time_off_policy.rb', line 59

def self.policy_list 
    all.select{|a| [a.id, a.name]}
end

Instance Method Details

#child_policiesActiveRecord::Relation<TimeOffPolicy>

Returns:

See Also:



46
# File 'app/models/time_off_policy.rb', line 46

has_many    :child_policies, class_name: 'TimeOffPolicy', foreign_key: 'parent_policy_id'

#employeesActiveRecord::Relation<Employee>

Returns:

See Also:



48
# File 'app/models/time_off_policy.rb', line 48

has_many    :employees, through: :time_off_policy_assignments

#parent_policyTimeOffPolicy



45
# File 'app/models/time_off_policy.rb', line 45

belongs_to  :parent_policy, class_name: 'TimeOffPolicy', optional: true

#time_off_policy_assignmentsActiveRecord::Relation<TimeOffPolicyAssignment>

Returns:

See Also:



47
# File 'app/models/time_off_policy.rb', line 47

has_many    :time_off_policy_assignments

#time_off_typeTimeOffType



44
# File 'app/models/time_off_policy.rb', line 44

belongs_to  :time_off_type