Class: Crm::Report::ChannelRevenueResultsPresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
app/presenters/crm/report/channel_revenue_results_presenter.rb

Overview

Wrapper to presents the following structure

{
:company_ids => [
[0] 1,
[1] 2,
[2] 4
],
:period1_range => [
[0] Mon, 18 Sep 2023 05:33:06.444267000 CDT -05:00,
[1] Wed, 18 Oct 2023 05:33:06.444345000 CDT -05:00
],
:period2_range => [
[0] Fri, 23 Sep 2022 05:33:06.444364000 CDT -05:00,
[1] Sun, 23 Oct 2022 05:33:06.444381000 CDT -05:00
],
:primary_sales_rep_id => nil,
:invoice_types => nil,
:consolidated_currency => true,
:channel_revenues => [
[ 0] {
:channel_name => "Amazon",
:primary_sales_rep_id => nil,
:invoice_types => nil,
:company_ids => [
[0] 1,
[1] 2,
[2] 4
],
:period1 => [
[0] Mon, 18 Sep 2023 05:31:01.896912000 CDT -05:00,
[1] Wed, 18 Oct 2023 05:31:01.896992000 CDT -05:00
],
:period2 => [
[0] Fri, 23 Sep 2022 05:31:01.897010000 CDT -05:00,
[1] Sun, 23 Oct 2022 05:31:01.897027000 CDT -05:00
],
:company_results => {
1 => {
:period1 => {
:gross_revenue_consolidated => 114809.97,
:gross_revenue_native => 114809.97,
:invoices_count => 322,
:native_currency => "USD"
},
:period2 => {
:gross_revenue_consolidated => 64200.31,
:gross_revenue_native => 64200.31,
:invoices_count => 285,
:native_currency => "USD"
}
},
2 => {
:period1 => {
:gross_revenue_consolidated => 33729.79,
:gross_revenue_native => 45779.51,
:invoices_count => 150,
:native_currency => "CAD"
},
:period2 => {
:gross_revenue_consolidated => 29222.82,
:gross_revenue_native => 39819.7,
:invoices_count => 70,
:native_currency => "CAD"
}
}
}
},

Instance Method Summary collapse

Instance Method Details

#companies_for_displayObject



73
74
75
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 73

def companies_for_display
  channel_revenues_result[:company_ids].each_with_object({}) {|id, hsh| hsh[id] = Company.find(id).company_label }
end


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 97

def invoiced_channel_link(label:, period: nil, report_grouping: nil, company_ids: nil, currency_symbol: nil, style: nil, css_class: nil)
  period_range = case period
                 when :period1
                   channel_revenues_result[:period1_range]
                 when :period2
                   channel_revenues_result[:period2_range]
                 else
                   raise "Invalid period, should be :period1 or :period2"
                 end
  company_ids ||= channel_revenues_result[:company_ids]

  options = { show_zero: true, counter_class: '' }
  options[:num_records] = label
  options[:format] = currency_symbol ? :currency : :plain
  options[:currency_symbol] = currency_symbol
  options[:query_params] = {}
  options[:style] = style
  options[:class] = css_class if css_class
  options[:query_params][:company_id_in] = [company_ids].flatten
  options[:query_params][:gl_date_gteq] =  period_range.first
  options[:query_params][:gl_date_lteq] =  period_range.last
  options[:query_params][:report_grouping] = [report_grouping] if report_grouping
  options[:query_params][:invoice_type_in] = channel_revenues_result[:invoice_types]
  options[:query_params][:primary_sales_rep_id_includes] = channel_revenues_result[:primary_sales_rep_ids]

  h.query_template_link(InvoiceSearch, nil, options)[0]
end

#period1_range_endObject



81
82
83
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 81

def period1_range_end
  channel_revenues_result[:period1_range].last
end

#period1_range_startObject



77
78
79
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 77

def period1_range_start
  channel_revenues_result[:period1_range].first
end

#period2_range_endObject



89
90
91
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 89

def period2_range_end
  channel_revenues_result[:period2_range].last
end

#period2_range_startObject



85
86
87
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 85

def period2_range_start
  channel_revenues_result[:period2_range].first
end

#primary_sales_rep_idObject



93
94
95
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 93

def primary_sales_rep_id
  channel_revenues_result.primary_sales_rep_id
end