Module: Crm::Reports::ChannelRevenueHelper
- Defined in:
- app/helpers/crm/reports/channel_revenue_helper.rb
Overview
View helper for the CRM channel revenue report
(Crm::Reports::ChannelRevenueController), rendering change indicators and
the business-day summary for a report period.
Instance Method Summary collapse
-
#business_day_breakdown(breakdown) ⇒ ActiveSupport::SafeBuffer
One-line business-day summary under a period date range.
-
#cr_change_indicator(prev_value, cur_value) ⇒ ActiveSupport::SafeBuffer
Renders a Bootstrap change indicator comparing the previous period value to the current period value (up/down arrow plus percentage change).
Instance Method Details
#business_day_breakdown(breakdown) ⇒ ActiveSupport::SafeBuffer
One-line business-day summary under a period date range.
e.g. "12 business days (WY-US) · not counted: weekends, Independence Day (Jul 3)"
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/crm/reports/channel_revenue_helper.rb', line 47 def business_day_breakdown(breakdown) breakdown = breakdown.with_indifferent_access count = breakdown[:count].to_i matching = breakdown[:matching_label].presence || 'USA' holidays = Array(breakdown[:holidays]) by_company = breakdown[:by_company] || {} not_counted = ['weekends'] holidays.each do |h| h = h.with_indifferent_access date = begin Date.iso8601(h[:date]).strftime('%b %-d') rescue StandardError h[:date] end not_counted << "#{h[:name]} (#{date})" end parts = [ tag.strong("#{count} business #{'day'.pluralize(count)}"), tag.span(" (#{matching})", class: 'text-body-secondary'), tag.span(" · not counted: #{not_counted.join(', ')}", class: 'text-body-secondary') ] if by_company.size > 1 && by_company.values.uniq.size > 1 other = by_company.map { |label, n| "#{label} #{n}" }.join(', ') parts << tag.span(" · other calendars: #{other}", class: 'text-body-secondary fst-italic') end tag.div(safe_join(parts), class: 'form-text business-day-breakdown mb-1') end |
#cr_change_indicator(prev_value, cur_value) ⇒ ActiveSupport::SafeBuffer
Renders a Bootstrap change indicator comparing the previous period value
to the current period value (up/down arrow plus percentage change).
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/crm/reports/channel_revenue_helper.rb', line 15 def cr_change_indicator(prev_value, cur_value) return content_tag(:span, '-', class: 'text-body-secondary') if prev_value.blank? && cur_value.blank? prev = prev_value.to_f cur = cur_value.to_f percentage_text = if prev.zero? cur.zero? ? '0%' : "#{cur.abs.round(0)}%" else "#{(((cur - prev) / prev) * 100).abs.round(1)}%" end if cur > prev content_tag(:span, class: 'text-success') do fa_icon('arrow-up', family: :solid, class: 'fa-xs me-1') + percentage_text end elsif cur < prev content_tag(:span, class: 'text-danger') do fa_icon('arrow-down', family: :solid, class: 'fa-xs me-1') + percentage_text end else content_tag(:span, class: 'text-body-secondary') do fa_icon('minus', family: :solid, class: 'fa-xs me-1') + percentage_text end end end |