Class: Crm::Report::ChannelRevenueResultsPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Crm::Report::ChannelRevenueResultsPresenter
- 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
-
#primary_sales_rep_id ⇒ Object
Alias for Channel_revenues_result#primary_sales_rep_id.
Instance Method Summary collapse
-
#companies_for_display ⇒ Hash{Integer => String}
Companies keyed by id with their display labels.
-
#invoiced_channel_link(label:, period: nil, report_grouping: nil, company_ids: nil, currency_symbol: nil, style: nil, css_class: nil) ⇒ String
Link to the invoice search scoped to a channel/company/period slice.
-
#period1_range_end ⇒ Time
End of the first comparison period.
-
#period1_range_start ⇒ Time
Start of the first comparison period.
-
#period2_range_end ⇒ Time
End of the second comparison period.
-
#period2_range_start ⇒ Time
Start of the second comparison period.
Instance Method Details
#companies_for_display ⇒ Hash{Integer => String}
Companies keyed by id with their display labels.
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 |
#invoiced_channel_link(label:, period: nil, report_grouping: nil, company_ids: nil, currency_symbol: nil, style: nil, css_class: nil) ⇒ String
Link to the invoice search scoped to a channel/company/period slice.
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] = { show_zero: true, counter_class: '' } [:num_records] = label [:format] = currency_symbol ? :currency : :plain [:currency_symbol] = currency_symbol [:query_params] = {} [:style] = style [:class] = css_class if css_class [:query_params][:company_id_in] = [company_ids].flatten [:query_params][:gl_date_gteq] = period_range.first [:query_params][:gl_date_lteq] = period_range.last [:query_params][:report_grouping] = [report_grouping] if report_grouping [:query_params][:invoice_type_in] = channel_revenues_result[:invoice_types] [:query_params][:primary_sales_rep_id_includes] = channel_revenues_result[:primary_sales_rep_ids] h.query_template_link(InvoiceSearch, nil, )[0] end |
#period1_range_end ⇒ Time
End of the first comparison period.
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_start ⇒ Time
Start of the first comparison period.
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_end ⇒ Time
End of the second comparison period.
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_start ⇒ Time
Start of the second comparison period.
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_id ⇒ Object
Alias for Channel_revenues_result#primary_sales_rep_id
104 |
# File 'app/presenters/crm/report/channel_revenue_results_presenter.rb', line 104 delegate :primary_sales_rep_id, to: :channel_revenues_result |