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)


35
36
37
# File 'app/services/hr_lite/overview_query.rb', line 35

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

#flagged_todayObject



18
19
20
# File 'app/services/hr_lite/overview_query.rb', line 18

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

#kpisObject



26
27
28
29
30
31
32
33
# File 'app/services/hr_lite/overview_query.rb', line 26

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

#missing_checkout_yesterdayObject



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

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_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