Class: TimeOffType

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

Overview

== Schema Information

Table name: time_off_types
Database name: primary

id :bigint not null, primary key
accrues_pto(Whether this time off accrues PTO) :boolean default(TRUE), not null
can_split_days(Whether this time off can be split into partial days) :boolean default(TRUE), not null
color :string
exclude_from_overlapping_rules :boolean default(FALSE)
expiry_rule(When the accrued time expires (e.g., end of month, Dec 31, nil for instance-based types)) :string
icon :string
instance_based(Whether this type is granted per instance (e.g., bereavement)) :boolean default(FALSE), not null
max_days(Maximum days allowed per instance or accrual period) :decimal(10, 2)
name :string
notes :text
paid(Whether this time off is paid) :boolean default(TRUE), not null
period_length(Length of the accrual period (e.g., 1 month, 1 year, etc.)) :string
prior_pto_days(Number of PTO days required before eligibility) :integer default(0)
requires_prior_pto(Whether prior PTO is required for eligibility) :boolean default(FALSE), not null
rollover_allowed(Whether unused time rolls over to the next period) :boolean default(FALSE), not null
rollover_cap(Maximum amount of time that can roll over) :decimal(10, 2) default(0.0)
tracking_type :string default("deduction"), not null
unit :string
unlimited(Whether this time off has no maximum limit or unlimited instances) :boolean default(FALSE), not null
created_at :datetime not null
updated_at :datetime not null

Indexes

index_time_off_types_on_accrues_pto (accrues_pto)
index_time_off_types_on_can_split_days (can_split_days)
index_time_off_types_on_exclude_from_overlapping_rules (exclude_from_overlapping_rules)
index_time_off_types_on_instance_based (instance_based)
index_time_off_types_on_name (name) UNIQUE
index_time_off_types_on_paid (paid)
index_time_off_types_on_requires_prior_pto (requires_prior_pto)
index_time_off_types_on_rollover_allowed (rollover_allowed)
index_time_off_types_on_tracking_type (tracking_type)
index_time_off_types_on_unit (unit)
index_time_off_types_on_unlimited (unlimited)

Constant Summary collapse

BANKED_TIME_ID =
8
SHORT_TERM_DISABILITY_ID =
5
VACATION_ID =
1
TRACKING_TYPES =
%w[accrual deduction]

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#tracking_typeObject (readonly)



58
# File 'app/models/time_off_type.rb', line 58

validates :tracking_type, inclusion: { in: TRACKING_TYPES }

Class Method Details

.type_list(include_unit = false) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'app/models/time_off_type.rb', line 64

def self.type_list(include_unit = false)
  all.order(:id).map do |a|
    if include_unit
      ["#{a.name} (in #{a.unit.pluralize})", a.id, { 'data-description': a.notes }]
    else
      [a.name, a.id, { 'data-description': a.notes }]
    end
  end
end

.unit_listObject



60
61
62
# File 'app/models/time_off_type.rb', line 60

def self.unit_list
  %w[hour day]
end

Instance Method Details

#accrual?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/time_off_type.rb', line 74

def accrual?
  tracking_type == 'accrual'
end

#deduction?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/time_off_type.rb', line 78

def deduction?
  tracking_type == 'deduction'
end

#time_off_policiesActiveRecord::Relation<TimeOffPolicy>

Returns:

See Also:



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

has_many :time_off_policies

#time_off_requestsActiveRecord::Relation<TimeOffRequest>

Returns:

See Also:



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

has_many :time_off_requests