Class: Crm::ManagerScheduleGridSlot

Inherits:
Object
  • Object
show all
Defined in:
app/services/crm/manager_schedule_grid_slot.rb

Overview

Classifies each 30-minute slot for the manager employee-status schedule grid, including
partial-day approved PTO using TimeOffRequestDate#planned_work_day (planned work window).

Class Method Summary collapse

Class Method Details

.cell_kind(slot:, slot_end:, schedule_day:, time_off_request_date:, ongoing_time_off_request:) ⇒ Object

Returns Symbol one of :off, :working, :lunch, :pto.

Returns:

  • Symbol one of :off, :working, :lunch, :pto



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/crm/manager_schedule_grid_slot.rb', line 8

def self.cell_kind(slot:, slot_end:, schedule_day:, time_off_request_date:, ongoing_time_off_request:)
  return :off if schedule_day.blank? || !schedule_day.hours.to_f.positive?

  start_hour = schedule_day.start_time.hour + (schedule_day.start_time.min / 60.0)
  end_hour = schedule_day.end_time.hour + (schedule_day.end_time.min / 60.0)
  end_hour = 24.0 if end_hour < start_hour

  lunch_start = lunch_start_hour(schedule_day)
  lunch_end = lunch_end_hour(schedule_day)
  baseline_work = range_overlap?(slot, slot_end, start_hour, end_hour)
  baseline_lunch = lunch_start && lunch_end && range_overlap?(slot, slot_end, lunch_start, lunch_end)

  return :off unless baseline_work

  if ongoing_time_off_request.blank?
    return :lunch if baseline_lunch
    return :working
  end

  if TimeOffPartialDay.hour_unit_partial_day?(
    time_off_request_date: time_off_request_date,
    schedule_day_hours: schedule_day.hours,
    time_off_request: ongoing_time_off_request
  )
    planned = TimeOffPartialDay.planned_inner_hash(time_off_request_date)
    if planned[:start_time].present? && planned[:end_time].present?
      if overlaps_planned_net_work?(slot, slot_end, planned)
        return :working
      end
      if overlaps_planned_lunch_only?(slot, slot_end, planned)
        return :lunch
      end
      return :pto
    end
  end

  :pto
end