Class: ActivityPerformanceReport
- Defined in:
- app/reports/activity_performance_report.rb
Overview
Report: activity performance report.
Instance Attribute Summary
Attributes inherited from Report
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = nil) ⇒ ActivityPerformanceReport
constructor
A new instance of ActivityPerformanceReport.
- #pdf_options ⇒ Object
- #perform ⇒ Object
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( = nil) ||= {} @range_start = self.class.parse_date([:range_start]) || Date.current.beginning_of_month @range_end = self.class.parse_date([:range_end]) || Date.current.end_of_month @range_end = @range_start if @range_start > @range_end super end |
Class Method Details
.parameters ⇒ Object
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_options ⇒ Object
44 45 46 |
# File 'app/reports/activity_performance_report.rb', line 44 def super.merge({ orientation: "Landscape" }) end |
#perform ⇒ 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 |
# 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 |