Class: HrLite::OverviewQuery

Inherits:
Object
  • Object
show all
Defined in:
app/services/hr_lite/overview_query.rb

Overview

Feeds both the admin overview board and the daily leadership digest — one source, so they always agree. Sections return Relations (callers paginate or cap as they see fit).

Instance Method Summary collapse

Constructor Details

#initialize(date: Date.current) ⇒ OverviewQuery

Returns a new instance of OverviewQuery.



6
7
8
# File 'app/services/hr_lite/overview_query.rb', line 6

def initialize(date: Date.current)
  @date = date
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/services/hr_lite/overview_query.rb', line 46

def empty?
  kpis.values.all?(&:zero?)
end

#flagged_todayObject



29
30
31
# File 'app/services/hr_lite/overview_query.rb', line 29

def flagged_today
  AttendanceRecord.for_date(@date).flagged.includes(:user)
end

#kpisObject



37
38
39
40
41
42
43
44
# File 'app/services/hr_lite/overview_query.rb', line 37

def kpis
  {
    pending: pending_requests.count + pending_comp_offs.count + pending_regularizations.count,
    on_leave: on_leave_today.count,
    flagged: flagged_today.count,
    missing_checkout: missing_checkout_yesterday.count
  }
end

#missing_checkout_yesterdayObject



33
34
35
# File 'app/services/hr_lite/overview_query.rb', line 33

def missing_checkout_yesterday
  AttendanceRecord.for_date(@date - 1).missing_checkout.includes(:user)
end

#on_leave_todayObject



14
15
16
# File 'app/services/hr_lite/overview_query.rb', line 14

def on_leave_today
  LeaveRequest.active_on(@date).includes(:leave_type, :user).order(:start_date)
end

#pending_comp_offsObject

Comp-off and regularization are approvals too. Counting leave alone made the board announce "All present and accounted for" while both queues still had work in them.



21
22
23
# File 'app/services/hr_lite/overview_query.rb', line 21

def pending_comp_offs
  CompOffRequest.pending.includes(:user).recent_first
end

#pending_regularizationsObject



25
26
27
# File 'app/services/hr_lite/overview_query.rb', line 25

def pending_regularizations
  RegularizationRequest.pending.includes(:user).recent_first
end

#pending_requestsObject



10
11
12
# File 'app/services/hr_lite/overview_query.rb', line 10

def pending_requests
  LeaveRequest.pending.includes(:leave_type, :user).order(:created_at)
end