Class: Report::KpiTimeOnTask::KpiTimeOnTask

Inherits:
Object
  • Object
show all
Defined in:
app/services/report/kpi_time_on_task/kpi_time_on_task.rb

Overview

Service object: kpi time on task.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.data_result(start_time, end_time, departments, employee_ids) ⇒ Object

Data result.

Parameters:

  • start_time (Time)
  • end_time (Time)
  • departments (Object)
  • employee_ids (Array<Integer>)

Returns:

  • (Object)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/services/report/kpi_time_on_task/kpi_time_on_task.rb', line 38

def self.data_result(start_time, end_time, departments, employee_ids)
  departments = departments.map { |d| "'#{d}'" }.join(',') if departments.present?
  departments_sql = departments.present? ? " and department in (#{departments})" : ' '
  if employee_ids.present?
    employee_ids = employee_ids.join(',')
    employee_ids_sql = " and employee_id in (#{employee_ids})"
  else
    employee_ids_sql = " and employee_id not in (116,6791405,5620978,69,155,150282,6791406,85)"
  end

  sql = <<-SQL.squish
    select employee_id,employee_name,department,(sum(business_day) - sum(day_off)) as days_worked,
          sum(activities) as act_cmp_created,
          sum(accs_created) as accs_created,
          sum(opp_created) as opp_created,
          sum(ord_created) as ord_created,
          sum(rmas_created) as rmas_created,
          sum(sc_created) as sc_created,
          sum(comm_sent) as comm_sent,
          sum(emails) as emails,
          sum(sms) as sms_sent,
          sum(time_avbl) as time_avbl,
          sum(inbounds) as out_call,
          sum(outbounds) as in_call,
          sum(missed_call) as missed_call,
          sum(talk_time) as talk_time
    from view_kpis_time_on_tasks
    where date between '#{start_time}' and '#{end_time}'
    #{departments_sql}
    #{employee_ids_sql}
    group by employee_id, employee_name, department
    order by employee_name;
  SQL

  ActiveRecord::Base.lease_connection.execute(sql).to_a.map(&:symbolize_keys)
end

.result_report(options = {}) ⇒ Result

Returns time-on-task KPI data.

Parameters:

  • options (Hash) (defaults to: {})

    report filter options

Options Hash (options):

  • period1_gteq (Date)

    start of the reporting period

  • period1_lteq (Date)

    end of the reporting period

  • departments (Array<String>)

    departments to include

  • employee_ids (Array<Integer>)

    employees to include (blank entries ignored)

Returns:

  • (Result)

    time-on-task KPI data



21
22
23
24
25
26
27
28
29
30
# File 'app/services/report/kpi_time_on_task/kpi_time_on_task.rb', line 21

def self.result_report(options = {})
  start_date = options[:period1_gteq]
  end_date = options[:period1_lteq]
  departments = options[:departments].map(&:presence).uniq.compact.sort
  employee_ids = options[:employee_ids].filter_map(&:presence)

  data = data_result(start_date, end_date, departments, employee_ids)

  Result.new(success: true, data: data)
end