Class: Report::GrossSalesReport::GrossSalesReportCommand

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

Overview

Command pattern to encapsulate parameters necessary to run a presence report

Constant Summary collapse

GROUPING_OPTIONS =

attribute :year, Integer, default: :default_year

[%w[year year], %w[quarter quarter], %w[month month], %w[week week]].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.company_optionsObject

Company options.

Returns:

  • (Object)


15
16
17
# File 'app/services/report/gross_sales_report/gross_sales_report_command.rb', line 15

def self.company_options
  @company_options ||= Company.sales_companies.pluck(:name, :country_iso3)
end

.default_company_idsObject

Default company ids.

Returns:

  • (Object)


47
48
49
# File 'app/services/report/gross_sales_report/gross_sales_report_command.rb', line 47

def self.default_company_ids
  @default_company_ids ||= Company.sales_companies.ids
end

Instance Method Details

#executeObject

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

Returns:

  • (Object)


25
26
27
28
29
# File 'app/services/report/gross_sales_report/gross_sales_report_command.rb', line 25

def execute
  return unless valid?

  @result = Report::GrossSalesReport::GrossSalesReport.total_report(attributes)
end

#success?Boolean

Whether the command validated and ran successfully.

Returns:

  • (Boolean)


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

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