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)


33
34
35
# File 'app/services/report/customer_performance_command.rb', line 33

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

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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



64
65
66
# File 'app/services/report/customer_performance_command.rb', line 64

def grouping_options
  Report::CustomerPerformance::GROUPINGS
end

#period1_humanizedObject



52
53
54
# File 'app/services/report/customer_performance_command.rb', line 52

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

#period1_rangeObject



44
45
46
# File 'app/services/report/customer_performance_command.rb', line 44

def period1_range
  (period1_gteq && period1_lteq && period1_gteq)..period1_lteq
end

#period2_humanizedObject



56
57
58
# File 'app/services/report/customer_performance_command.rb', line 56

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

#period2_rangeObject



48
49
50
# File 'app/services/report/customer_performance_command.rb', line 48

def period2_range
  (period2_gteq && period2_lteq && period2_gteq)..period2_lteq
end

#periodsObject



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

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

#success?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/services/report/customer_performance_command.rb', line 60

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