Class: WorkScheduleDay

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

Overview

== Schema Information

Table name: work_schedule_days
Database name: primary

id :bigint not null, primary key
day_of_week :integer not null
end_time :time not null
hours :float not null
lunch_end_time :time
lunch_start_time :time
notes :text
start_time :time not null
created_at :datetime not null
updated_at :datetime not null
work_schedule_id :bigint not null

Indexes

index_work_schedule_days_on_day_of_week (day_of_week)
index_work_schedule_days_on_work_schedule_id_and_day_of_week (work_schedule_id,day_of_week) UNIQUE

Foreign Keys

fk_rails_... (work_schedule_id => work_schedules.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

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 Attribute Details

#day_of_weekObject (readonly)



32
# File 'app/models/work_schedule_day.rb', line 32

validates :day_of_week, :start_time, :end_time, :hours, presence: true

#end_timeObject (readonly)



32
# File 'app/models/work_schedule_day.rb', line 32

validates :day_of_week, :start_time, :end_time, :hours, presence: true

#hoursObject (readonly)



32
# File 'app/models/work_schedule_day.rb', line 32

validates :day_of_week, :start_time, :end_time, :hours, presence: true

#start_timeObject (readonly)



32
# File 'app/models/work_schedule_day.rb', line 32

validates :day_of_week, :start_time, :end_time, :hours, presence: true

Instance Method Details

#day_nameObject



34
35
36
# File 'app/models/work_schedule_day.rb', line 34

def day_name
    Date::DAYNAMES[day_of_week]
end

#formatted_end_timeObject



42
43
44
# File 'app/models/work_schedule_day.rb', line 42

def formatted_end_time
    end_time&.strftime('%H:%M')
end

#formatted_lunch_timesObject



46
47
48
49
50
# File 'app/models/work_schedule_day.rb', line 46

def formatted_lunch_times
    return nil unless lunch_start_time && lunch_end_time

    "#{lunch_start_time.strftime('%H:%M')} - #{lunch_end_time.strftime('%H:%M')}"
end

#formatted_start_timeObject



38
39
40
# File 'app/models/work_schedule_day.rb', line 38

def formatted_start_time
    start_time&.strftime('%H:%M')
end

#time_off_request_day_payloadObject

Snapshot for time-off requests (hour-based partial days): usual weekly pattern for this weekday.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/work_schedule_day.rb', line 53

def time_off_request_day_payload
  {
    day_of_week: day_of_week,
    day_name: day_name,
    start_time: formatted_start_time,
    end_time: formatted_end_time,
    lunch_start: lunch_start_time&.strftime('%H:%M'),
    lunch_end: lunch_end_time&.strftime('%H:%M'),
    lunch_label: formatted_lunch_times,
    hours: hours,
    summary: time_off_schedule_summary_line
  }
end

#time_off_schedule_summary_lineObject



67
68
69
70
71
72
73
74
75
# File 'app/models/work_schedule_day.rb', line 67

def time_off_schedule_summary_line
  parts = []
  parts << "#{format_time_ampm(start_time)}#{format_time_ampm(end_time)}" if start_time && end_time
  if lunch_start_time && lunch_end_time
    parts << "Lunch #{format_time_ampm(lunch_start_time)} - #{format_time_ampm(lunch_end_time)}"
  end
  parts << "#{hours} h" if hours.present?
  parts.join(' · ')
end

#work_scheduleWorkSchedule



30
# File 'app/models/work_schedule_day.rb', line 30

belongs_to  :work_schedule