Module: BudgetHelper
- Defined in:
- app/helpers/budget_helper.rb
Overview
View helper: budget.
Constant Summary collapse
- ZERO_DISPLAY =
Em dash for zero values - cleaner for management reports
'—'.freeze
Instance Method Summary collapse
- #budget_cell(amount, fact, accumulated, additional_class = nil) ⇒ Object
- #fact_cells(fact, _dimension) ⇒ Object
-
#format_amount(amount) ⇒ Object
Format number for display, showing em dash for zeros.
- #linked_cell(amount, fact, period, additional_class = nil) ⇒ Object
- #number_with_delimiter_acc(number) ⇒ Object
- #percentage_cell(percentage, is_revenue, additional_class = nil) ⇒ Object
- #standard_cell(amount, additional_class = nil) ⇒ Object
Instance Method Details
#budget_cell(amount, fact, accumulated, additional_class = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/budget_helper.rb', line 69 def budget_cell(amount, fact, accumulated, additional_class = nil) css_classes = [additional_class] css_classes << 'danger' if amount < 0 css_classes << 'zero-value' if amount.zero? cell_content = if amount.zero? ZERO_DISPLAY else link_to(number_with_delimiter_acc(amount), show_budgets_for_fact_budgets_path(fact_id: fact.id, accumulated: accumulated)) end content_tag('td', cell_content, class: css_classes.compact.join(' ')) end |
#fact_cells(fact, _dimension) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/budget_helper.rb', line 7 def fact_cells(fact, _dimension) cells = +'' if fact.nil? 8.times do cells << content_tag('td', '--', class: 'budget-current zero-value') end 8.times do cells << content_tag('td', '--', class: 'previous-year zero-value') end else cells << budget_cell(fact.budget_month, fact, false, 'budget-current') cells << linked_cell(fact.actual_month, fact, 'current-month', 'budget-current') cells << standard_cell(fact.budget_month_diff, 'budget-current') cells << percentage_cell(fact.budget_month_percent, fact.is_revenue?, 'budget-current') cells << budget_cell(fact.budget_accumulated, fact, true, 'budget-current') cells << linked_cell(fact.actual_accumulated, fact, 'current-accumulated', 'budget-current') cells << standard_cell(fact.budget_accumulated_diff, 'budget-current') cells << percentage_cell(fact.budget_accumulated_percent, fact.is_revenue?, 'budget-current') cells << linked_cell(fact.actual_month_previous, fact, 'previous-month', 'previous-year') cells << linked_cell(fact.actual_month, fact, 'current-month', 'previous-year') cells << standard_cell(fact.actual_month_previous_diff, 'previous-year') cells << percentage_cell(fact.actual_month_previous_percent, fact.is_revenue?, 'previous-year') cells << linked_cell(fact.actual_accumulated_previous, fact, 'previous-accumulated', 'previous-year') cells << linked_cell(fact.actual_accumulated, fact, 'current-accumulated', 'previous-year') cells << standard_cell(fact.actual_accumulated_previous_diff, 'previous-year') cells << percentage_cell(fact.actual_accumulated_previous_percent, fact.is_revenue?, 'previous-year') end cells.html_safe end |
#format_amount(amount) ⇒ Object
Format number for display, showing em dash for zeros
45 46 47 |
# File 'app/helpers/budget_helper.rb', line 45 def format_amount(amount) amount.zero? ? ZERO_DISPLAY : number_with_delimiter_acc(amount) end |
#linked_cell(amount, fact, period, additional_class = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/budget_helper.rb', line 56 def linked_cell(amount, fact, period, additional_class = nil) css_classes = [additional_class] css_classes << 'danger' if amount < 0 css_classes << 'zero-value' if amount.zero? cell_content = if amount.zero? ZERO_DISPLAY else link_to(number_with_delimiter_acc(amount), show_ledger_entries_for_fact_budgets_path(fact_id: fact.id, period: period)) end content_tag('td', cell_content, class: css_classes.compact.join(' ')) end |
#number_with_delimiter_acc(number) ⇒ Object
40 41 42 |
# File 'app/helpers/budget_helper.rb', line 40 def number_with_delimiter_acc(number) number < 0 ? "(#{number_with_delimiter(-number)})" : number_with_delimiter(number) end |
#percentage_cell(percentage, is_revenue, additional_class = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/budget_helper.rb', line 82 def percentage_cell(percentage, is_revenue, additional_class = nil) css_classes = [additional_class] if percentage.zero? css_classes << 'zero-value' return content_tag('td', ZERO_DISPLAY, class: css_classes.compact.join(' ')) end if ((is_revenue == true) && (percentage < 0)) || ((is_revenue == false) && (percentage > 0)) fa_icon = content_tag('i', '', class: 'fa fa-arrow-down') css_classes << 'danger' elsif ((is_revenue == true) && (percentage > 0)) || ((is_revenue == false) && (percentage < 0)) fa_icon = content_tag('i', '', class: 'fa fa-arrow-up') css_classes << 'ok' else fa_icon = '' end content_tag('td', number_to_percentage(percentage, precision: 1) + fa_icon, class: css_classes.compact.join(' ')) end |
#standard_cell(amount, additional_class = nil) ⇒ Object
49 50 51 52 53 54 |
# File 'app/helpers/budget_helper.rb', line 49 def standard_cell(amount, additional_class = nil) css_classes = [additional_class] css_classes << 'danger' if amount < 0 css_classes << 'zero-value' if amount.zero? content_tag('td', format_amount(amount), class: css_classes.compact.join(' ')) end |