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

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 Models::EventPublishable

#publish_event

Instance Method Details

#blocked?Boolean

Returns:

  • (Boolean)


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

def blocked?
  employee = time_off_request.employee
  department = employee.employee_record.department
    
  TimeOffBlockedDay.where("departments @> ARRAY[?]::varchar[]", department).exists?(blocked_date: self.date)
end

#holiday_nameObject



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

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

#time_off_requestTimeOffRequest



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

belongs_to  :time_off_request

#validate_step_alignmentObject



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

def validate_step_alignment
  return if amount.nil?
    
  step = 0.25
  # Check if the value is aligned with the step
  if (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
end