Module: Crm::Reports::OrdersReportHelper

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

Overview

View helpers for the CRM orders report: variance percentage indicators and
money/number formatting for the order-origin breakdown.

Instance Method Summary collapse

Instance Method Details

#order_origin_values_format_of(value) ⇒ String, ActiveSupport::SafeBuffer

Formats a money value with its currency symbol.

Parameters:

  • value (Numeric, nil)

    the amount to format

Returns:

  • (String, ActiveSupport::SafeBuffer)

    the formatted amount, or a -
    placeholder when value is nil or zero



37
38
39
40
41
42
43
44
45
# File 'app/helpers/crm/reports/orders_report_helper.rb', line 37

def order_origin_values_format_of(value)
  return (:span, "-", class: "text-body-secondary") unless value

  if value.zero?
    (:span, "-", class: "text-body-secondary")
  else
    humanized_money_with_symbol(value)
  end
end

#order_origin_values_format_without_symbol_of(value) ⇒ String, ActiveSupport::SafeBuffer

Formats a value as a delimited number without a currency symbol.

Parameters:

  • value (Numeric, nil)

    the value to format

Returns:

  • (String, ActiveSupport::SafeBuffer)

    the formatted number, or a -
    placeholder when value is nil or zero



52
53
54
55
56
57
58
59
60
# File 'app/helpers/crm/reports/orders_report_helper.rb', line 52

def order_origin_values_format_without_symbol_of(value)
  return (:span, "-", class: "text-body-secondary") unless value

  if value.zero?
    (:span, "-", class: "text-body-secondary")
  else
    number_with_delimiter(value)
  end
end

#order_origin_var_percentage_of(var_value) ⇒ ActiveSupport::SafeBuffer

Renders a variance percentage with an up/down arrow icon, colored green
for positive and red for negative values.

Parameters:

  • var_value (Numeric, nil)

    the percentage variance

Returns:

  • (ActiveSupport::SafeBuffer)

    the variance HTML, or a - placeholder
    when var_value is nil or zero



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/crm/reports/orders_report_helper.rb', line 14

def order_origin_var_percentage_of(var_value)
  return (:span, "-", class: "text-body-secondary") unless var_value

  if var_value.positive?
    (:span, class: "text-success") do
      fa_icon("arrow-up", family: :solid, class: "fa-xs me-1") +
        "#{var_value} %"
    end
  elsif var_value.negative?
    (:span, class: "text-danger") do
      fa_icon("arrow-down", family: :solid, class: "fa-xs me-1") +
        "#{var_value} %"
    end
  else
    (:span, "-", class: "text-body-secondary")
  end
end