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"
}
}
}
},

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details

#companies_for_displayHash{Integer => String}

Companies keyed by id with their display labels.

Returns:

  • (Hash{Integer => String})

    company labels by id



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

def companies_for_display
  channel_revenues_result[:company_ids].index_with { |id| Company.find(id).company_label }
end

Link to the invoice search scoped to a channel/company/period slice.

Parameters:

  • label (String, Numeric)

    link label (usually the revenue figure)

  • period (Symbol) (defaults to: nil)

    :period1 or :period2

  • report_grouping (String, nil) (defaults to: nil)

    report grouping filter

  • company_ids (Array<Integer>, nil) (defaults to: nil)

    company ids (defaults to all in the result)

  • currency_symbol (String, nil) (defaults to: nil)

    currency symbol for currency formatting

  • style (String, nil) (defaults to: nil)

    inline CSS style

  • css_class (String, nil) (defaults to: nil)

    CSS classes

Returns:

  • (String)

    HTML link

Raises:

  • (RuntimeError)

    when period is not :period1 or :period2



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 116

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_endTime

End of the first comparison period.

Returns:

  • (Time)

    period 1 range end



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

def period1_range_end
  channel_revenues_result[:period1_range].last
end

#period1_range_startTime

Start of the first comparison period.

Returns:

  • (Time)

    period 1 range start



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

def period1_range_start
  channel_revenues_result[:period1_range].first
end

#period2_range_endTime

End of the second comparison period.

Returns:

  • (Time)

    period 2 range end



100
101
102
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 100

def period2_range_end
  channel_revenues_result[:period2_range].last
end

#period2_range_startTime

Start of the second comparison period.

Returns:

  • (Time)

    period 2 range start



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

def period2_range_start
  channel_revenues_result[:period2_range].first
end

#primary_sales_rep_idObject

Alias for Channel_revenues_result#primary_sales_rep_id

Returns:

  • (Object)

    Channel_revenues_result#primary_sales_rep_id

See Also:



104
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 104

delegate :primary_sales_rep_id, to: :channel_revenues_result