Class: TimeOffRequestDate

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

Overview

== Schema Information

Table name: time_off_request_dates
Database name: primary

id :bigint not null, primary key
amount :decimal(, )
date :date
notes :text
planned_work_day :jsonb not null
created_at :datetime not null
updated_at :datetime not null
time_off_request_id :integer

Indexes

index_time_off_request_dates_on_date (date)
index_time_off_request_dates_on_time_off_request_id (time_off_request_id)

Foreign Keys

fk_rails_... (time_off_request_id => time_off_requests.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#blocked?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'app/models/time_off_request_date.rb', line 44

def blocked?
  employee = time_off_request.employee
  department = employee.employee_record.department

  TimeOffBlockedDay.where("departments @> ARRAY[?]::varchar[]", department).exists?(blocked_date: date)
end

#holiday_nameObject



51
52
53
54
55
# File 'app/models/time_off_request_date.rb', line 51

def holiday_name
  employee = time_off_request.employee
  holiday = employee.company.company_holidays.find_by(holiday_date: date)
  holiday&.holiday_name
end

#time_off_requestTimeOffRequest



28
# File 'app/models/time_off_request_date.rb', line 28

belongs_to :time_off_request

#validate_step_alignmentObject



34
35
36
37
38
39
40
41
42
# File 'app/models/time_off_request_date.rb', line 34

def validate_step_alignment
  return if amount.nil?

  step = 0.25
  # Check if the value is aligned with the step
  return unless (amount % step).nonzero?

  errors.add(:amount, "incorrect. If you are choosing partial time off for some of the deays, the amount of time must be in increments of #{step} (e.g., 0.25 = 15 minutes, 0.50 = 30 minutes, 0.75 = 45 minutes, 1.00 = 1 hour, etc.)")
end