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

Whether customer identity grouping.

Returns:

  • (Boolean)


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

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

#executeObject

Run the report with the given filters and store the result.

Returns:

  • (Object)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/report/customer_performance_command.rb', line 20

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

Grouping options.

Returns:

  • (Object)


82
83
84
# File 'app/services/report/customer_performance_command.rb', line 82

def grouping_options
  Report::CustomerPerformance::GROUPINGS
end

#period1_humanizedObject

Period1 humanized.

Returns:

  • (Object)


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

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

#period1_rangeObject

Period1 range.

Returns:

  • (Object)


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

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

#period2_humanizedObject

Period2 humanized.

Returns:

  • (Object)


70
71
72
# File 'app/services/report/customer_performance_command.rb', line 70

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

#period2_rangeObject

Period2 range.

Returns:

  • (Object)


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

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

#periodsObject

Periods.

Returns:

  • (Object)


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

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

#success?Boolean

Whether the command validated and ran successfully.

Returns:

  • (Boolean)


76
77
78
# File 'app/services/report/customer_performance_command.rb', line 76

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