Module: Crm::Reports::OpportunityConversionHelper

Defined in:
app/helpers/crm/reports/opportunity_conversion_helper.rb

Overview

View helpers for the CRM opportunity conversion report: sales rep naming
and period-over-period variance calculations against last year's results.

See Also:

  • OpportunityConversionController

Instance Method Summary collapse

Instance Method Details

#last_year_pct_value(data, column) ⇒ Float

Computes the variance of a row's value against the matching rows from
last year's results (same time_measurement).

Parameters:

  • data (Hash)

    the current-period result row

  • column (String, Symbol)

    the column to compare

Returns:

  • (Float)

    the variance rounded to two decimals



24
25
26
# File 'app/helpers/crm/reports/opportunity_conversion_helper.rb', line 24

def last_year_pct_value(data, column)
  (data[column].to_f - @last_year_results.select { |b| b["time_measurement"] == data["time_measurement"] }.sum { |b| b[column].to_f }).round(2).to_f
end

#rep_nameString

Returns the full name of the sales rep assigned to the report, falling
back to "WarmlyYours" when no rep is available.

Returns:

  • (String)

    the rep's full name or "WarmlyYours"



12
13
14
15
16
# File 'app/helpers/crm/reports/opportunity_conversion_helper.rb', line 12

def rep_name
  @sales_rep.first.full_name
rescue StandardError
  "WarmlyYours"
end

#totals_last_year(data, column) ⇒ Float

Computes the variance of a row's value against last year's total row.

Parameters:

  • data (Hash)

    the current-period result row

  • column (String, Symbol)

    the column to compare

Returns:

  • (Float)

    the variance rounded to two decimals



33
34
35
# File 'app/helpers/crm/reports/opportunity_conversion_helper.rb', line 33

def totals_last_year(data, column)
  (data[column].to_f - @last_year_total_results[column].to_f).round(2).to_f
end