Class: Crm::Report::CustomerPerformanceResultsPresenter

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

Overview

Presenter: customer performance results presenter.

Instance Method Summary collapse

Instance Method Details

#check_boxString?

Checkbox to pin the customer when grouped by customer identity.

Returns:

  • (String, nil)

    checkbox HTML, or nil for other groupings



35
36
37
38
39
# File 'app/presenters/crm/report/customer_performance_results_presenter.rb', line 35

def check_box
  return unless grouping == :customer_identity

  h.check_box_tag 'customer_ids[]', customer_id, false, { form: 'pin_customers' }
end

Table cell linking the grouping value to a drilled-down report view.

Returns:

  • (ActiveSupport::SafeBuffer)

    one or two <td> cells



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/presenters/crm/report/customer_performance_results_presenter.rb', line 9

def group_link
  case grouping
  when :customer_identity
    h. :td, h.link_to(customer_name, h.customer_path(customer_id))
  when :state_code
    state = State.find_by(code: group_identifier)
    title = state.try(:name) || "Other"
    region = state.try(:region) || "Other"
    h.(:td, h.link_to(title, { action: :show, command: { grouping: :customer_identity, state_codes: [group_identifier] } })) +
      h.(:td, region)
  when :report_grouping
    h. :td, h.link_to(group_identifier, { action: :show, command: { grouping: :customer_identity, report_groupings: [group_identifier] } })
  when :profile_name
    h. :td, h.link_to(group_identifier, { action: :show, command: { grouping: :customer_identity, profile_ids: [profile_ids] } })
  when :buying_group_ids
    h. :td, h.link_to(group_identifier, { action: :show, command: { grouping: :customer_identity, buying_group_ids: [buying_group_id] } })
  when :primary_sales_rep_id
    primary_rep = Employee.find(group_identifier)
    h. :td, h.link_to(primary_rep.full_name, { action: :show, command: { grouping: :customer_identity, primary_sales_rep_ids: [group_identifier] } })
  else
    h. :td, group_identifier
  end
end

Link to the invoice search for one period's sales revenue.

Parameters:

  • period_index (Integer)

    index into #periods

Returns:

  • (String)

    HTML link with the revenue amount



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/presenters/crm/report/customer_performance_results_presenter.rb', line 44

def sales_revenue_link(period_index)
  period_data = periods[period_index]
  options = { show_zero: true, counter_class: '' }
  options[:num_records] = period_data.sales_revenue
  options[:format] = :currency
  options[:query_params] = {}
  options[:query_params][:gl_date_gteq] = period_data.period.first
  options[:query_params][:gl_date_lteq] = period_data.period.last

  options[:query_params][:customer_id_eq] = customer_id if customer_id.present?
  options[:query_params][:buying_group_id_in] = buying_group_ids if buying_group_ids.present?
  options[:query_params][:profile_id_in] = profile_ids if profile_ids.present?
  options[:query_params][:company_id_in] = company_ids if company_ids.present?
  options[:query_params][:state_code_in] = state_codes if state_codes.present?
  options[:query_params][:report_grouping] = report_groupings if report_groupings.present?
  options[:query_params][:primary_sales_rep_id_includes] = primary_sales_rep_ids if primary_sales_rep_ids.present?
  h.query_template_link(InvoiceSearch, nil, options)[0]
end