Class: Report::CustomerPerformanceCommand

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

Overview

Command pattern to encapsulate parameters necessary to run a presence report

Instance Method Summary collapse

Instance Method Details

#customer_identity_grouping?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/services/report/customer_performance_command.rb', line 31

def customer_identity_grouping?
  grouping.to_s == 'customer_identity'
end

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/report/customer_performance_command.rb', line 18

def execute
  return unless valid?
  @results = Report::CustomerPerformance.new(
              periods: periods,
              grouping: grouping.to_sym,
              report_groupings: report_groupings,
              buying_group_ids: buying_group_ids,
              profile_ids: profile_ids,
              company_ids: company_ids,
              state_codes: state_codes,
              primary_sales_rep_ids: primary_sales_rep_ids).perform
end

#grouping_optionsObject



62
63
64
# File 'app/services/report/customer_performance_command.rb', line 62

def grouping_options
  Report::CustomerPerformance::GROUPINGS
end

#period1_humanizedObject



50
51
52
# File 'app/services/report/customer_performance_command.rb', line 50

def period1_humanized
  "From #{period1_range.first} until #{period1_range.last}"
end

#period1_rangeObject



42
43
44
# File 'app/services/report/customer_performance_command.rb', line 42

def period1_range
  period1_gteq && period1_lteq && period1_gteq..period1_lteq
end

#period2_humanizedObject



54
55
56
# File 'app/services/report/customer_performance_command.rb', line 54

def period2_humanized
  "From #{period2_range.first} until #{period2_range.last}"
end

#period2_rangeObject



46
47
48
# File 'app/services/report/customer_performance_command.rb', line 46

def period2_range
  period2_gteq && period2_lteq && period2_gteq..period2_lteq
end

#periodsObject



35
36
37
38
39
40
# File 'app/services/report/customer_performance_command.rb', line 35

def periods
  p = []
  p << period1_range
  p << period2_range if period2_gteq.present? && period2_lteq.present?
  p
end

#success?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/services/report/customer_performance_command.rb', line 58

def success?
  valid? && @results.success?
end