Class: ActivityPerformanceReport

Inherits:
Report
  • Object
show all
Defined in:
app/reports/activity_performance_report.rb

Overview

Report: activity performance report.

Instance Attribute Summary

Attributes inherited from Report

#options, #results

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Report

build, parse_date, #report_key

Constructor Details

#initialize(options = nil) ⇒ ActivityPerformanceReport

Returns a new instance of ActivityPerformanceReport.



11
12
13
14
15
16
17
# File 'app/reports/activity_performance_report.rb', line 11

def initialize(options = nil)
  options ||= {}
  @range_start = self.class.parse_date(options[:range_start]) || Date.current.beginning_of_month
  @range_end = self.class.parse_date(options[:range_end]) || Date.current.end_of_month
  @range_end = @range_start if @range_start > @range_end
  super
end

Class Method Details

.parametersObject



4
5
6
7
8
9
# File 'app/reports/activity_performance_report.rb', line 4

def self.parameters
  {
    range_start: :date,
    range_end: :date
  }
end

Instance Method Details

#pdf_optionsObject



44
45
46
# File 'app/reports/activity_performance_report.rb', line 44

def pdf_options
  super.merge({ orientation: "Landscape" })
end

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/reports/activity_performance_report.rb', line 19

def perform
  if @range_start && @range_end
    @results = { range_start: @range_start, range_end: @range_end }
    activities = Activity.non_notes
                         .completed
                         .select("assigned_resource_id, completion_datetime, original_target_datetime")
                         .completion_datetime_gteq(@range_start.beginning_of_day)
                         .completion_datetime_lteq(@range_end.end_of_day)
    # Play with this
    @results[:counters] = activities.each_with_object({}) do |val, r|
      date = val.completion_datetime.to_s.to_date
      r[val.assigned_resource_id] ||= {}
      r[val.assigned_resource_id][date] ||= 0
      r[val.assigned_resource_id][date] = r[val.assigned_resource_id][date] + 1
    end

    @results[:employees] = Employee.select("id, full_name").where(id: @results[:counters].keys).order(:full_name)
    @results[:dates] = (@range_start...@range_end).to_a
  else
    errors << "Range start and end must be specified."
    @results = nil
  end
  @results
end