Class: Report::ChannelRevenue::Command

Inherits:
BaseCommand show all
Defined in:
app/services/report/channel_revenue/command.rb

Overview

Service object: command.

Constant Summary

Constants inherited from BaseCommand

BaseCommand::ARRAY_TYPE_NAMES

Instance Attribute Summary

Attributes inherited from BaseCommand

#results

Instance Method Summary collapse

Methods inherited from BaseCommand

#[], #attributes, #email_parameters, #email_partial, #initialize

Methods included from Heatwave::AttributeNormalizing

normalize

Constructor Details

This class inherits a constructor from Report::BaseCommand

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/report/channel_revenue/command.rb', line 23

def execute
  return unless valid?

  @results = Report::ChannelRevenue::Query.report(
                      period1_range: period1_range,
                      period2_range: period2_range,
                      primary_sales_rep_ids: primary_sales_rep_ids.presence,
                      invoice_types: invoice_types,
                      company_ids: company_ids,
                      consolidated_currency: consolidated_currency
                    )
end

#invoice_types=(new_invoice_types) ⇒ Object



19
20
21
# File 'app/services/report/channel_revenue/command.rb', line 19

def invoice_types=(new_invoice_types)
  super((new_invoice_types || []).filter_map(&:presence).uniq)
end

#period1_humanizedObject



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

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

#period1_rangeObject



36
37
38
# File 'app/services/report/channel_revenue/command.rb', line 36

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

#period2_humanizedObject



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

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

#period2_rangeObject



40
41
42
# File 'app/services/report/channel_revenue/command.rb', line 40

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

#success?Boolean

Returns:

  • (Boolean)


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

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