Class: Report::KpiTimeOnTask::KpiTimeOnTask

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

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

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



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
46
47
48
49
50
51
52
53
54
# File 'app/services/report/kpi_time_on_task/kpi_time_on_task.rb', line 19

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

  results = ActiveRecord::Base.connection.execute(sql).to_a.map{ |r| r.symbolize_keys }
end

.result_report(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/services/report/kpi_time_on_task/kpi_time_on_task.rb', line 8

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].map(&:presence).compact

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

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