Class: ActivityPerformanceReport

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

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.



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

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(options)
end

Class Method Details

.parametersObject



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

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



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

def perform
  if @range_start and @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.inject({}) do |r, val| 
      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
      r
    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