Class: Report::SalesRepRanking::SalesRepRankingCommand

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

Overview

Command pattern to encapsulate parameters necessary to run a presence report

Constant Summary collapse

HIDDEN_PRIMARY_REP_IDS =

Reps excluded from the dropdown entirely — Hamidullah Sakhizada (21820949)

[21_820_949].to_set.freeze
DESELECTED_PRIMARY_REP_IDS =

Reps available in the dropdown but not pre-selected — Elodie Pasek (85), Laura Brodt-Saunders (155)

(HIDDEN_PRIMARY_REP_IDS + [85, 155]).freeze

Instance Method Summary collapse

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/report/sales_rep_ranking/sales_rep_ranking_command.rb', line 16

def execute
  # Normalize incoming params: treat blanks as defaults and ensure arrays
  normalized = attributes.dup
  normalized[:period1_gteq] = default_date_start if normalized[:period1_gteq].blank?
  normalized[:period1_lteq] = default_date_end if normalized[:period1_lteq].blank?
  normalized[:report_groupings] = Array(normalized[:report_groupings]).map(&:presence).compact
  normalized[:primary_sales_rep_ids] = Array(normalized[:primary_sales_rep_ids])

  # Apply normalized values back to the command for validation/state
  self.period1_gteq = normalized[:period1_gteq]
  self.period1_lteq = normalized[:period1_lteq]
  self.report_groupings = normalized[:report_groupings]
  self.primary_sales_rep_ids = normalized[:primary_sales_rep_ids]

  unless valid?
    # Return a safe empty result so views can render without nil errors
    return Report::SalesRepRanking::SalesRepRanking::Result.new(
      success: false,
      data: [],
      start_date: period1_gteq,
      end_date: period1_lteq
    )
  end

  @result = Report::SalesRepRanking::SalesRepRanking.total_report(normalized)
end

#success?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/services/report/sales_rep_ranking/sales_rep_ranking_command.rb', line 43

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