Module: ReportHelper
- Defined in:
- app/helpers/report_helper.rb
Overview
Helpers for generating expenses reports
Instance Method Summary collapse
-
#filter_datepicker(name) ⇒ Object
Outputs a date picker for filtering the expenses report with a given scope.
-
#filter_select(name, collection, value_method = :id, text_method = :name) ⇒ Object
Outputs a dropdown for filtering the expenses report with a given scope.
-
#filter_text_field(name) ⇒ Object
Outputs a text input for filtering the expenses report with a given scope.
-
#html_value_for(field, expense) ⇒ Object
Outputs the html representation of the field for a given TravelExpenseReport instance.
-
#html_value_for_event_country(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_event_end_date(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_event_name(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_event_start_date(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_reimbursement_state(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_request_id(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_sum_amount(expense) ⇒ Object
Called from html_value_for.
-
#html_value_for_user_country(expense) ⇒ Object
Called from html_value_for.
-
#value_for_request_state(expense) ⇒ Object
Called from html_value_for and xlsx_value_for.
-
#xlsx_style_for(field) ⇒ Hash
Style for the axlsx template for a given field.
-
#xlsx_style_for_sum_amount ⇒ Object
Called from xlsx_style_for.
-
#xlsx_value_for(field, expense) ⇒ Object
Return the value of a field for a given TravelExpenseReport instance, in a format useful to the axlsx template.
-
#xlsx_value_for_event_country(expense) ⇒ Object
Called from xlsx_value_for.
-
#xlsx_value_for_user_country(expense) ⇒ Object
Called from xlsx_value_for.
-
#xslx_value_for_reimbursement_state(expense) ⇒ Object
Called from xlsx_value_for.
Instance Method Details
#filter_datepicker(name) ⇒ Object
Outputs a date picker for filtering the expenses report with a given scope
16 17 18 19 20 |
# File 'app/helpers/report_helper.rb', line 16 def filter_datepicker(name) value = @filter&.[](name) data = { 'date-autoclose' => true, 'date-format' => 'yyyy-mm-dd', 'date-language' => I18n.locale.to_s } text_field_tag "filter[#{name}]", value, class: 'date-without-time dpicker form-control input-sm', data: data end |
#filter_select(name, collection, value_method = :id, text_method = :name) ⇒ Object
Outputs a dropdown for filtering the expenses report with a given scope
8 9 10 11 12 13 |
# File 'app/helpers/report_helper.rb', line 8 def filter_select(name, collection, value_method = :id, text_method = :name) value = @filter&.[](name) = content_tag(:option, t(:expenses_report_all), value: '') << (collection, value_method, text_method, value) select_tag "filter[#{name}]", , class: 'form-control input-sm' end |
#filter_text_field(name) ⇒ Object
Outputs a text input for filtering the expenses report with a given scope
23 24 25 26 |
# File 'app/helpers/report_helper.rb', line 23 def filter_text_field(name) value = @filter&.[](name) text_field_tag "filter[#{name}]", value, class: 'form-control input-sm' end |
#html_value_for(field, expense) ⇒ Object
Outputs the html representation of the field for a given TravelExpenseReport instance.
34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/report_helper.rb', line 34 def html_value_for(field, expense) if respond_to? :"html_value_for_#{field}" send(:"html_value_for_#{field}", expense) elsif respond_to? :"value_for_#{field}" send(:"value_for_#{field}", expense) else expense.value_for field end end |
#html_value_for_event_country(expense) ⇒ Object
Called from html_value_for
106 107 108 |
# File 'app/helpers/report_helper.rb', line 106 def html_value_for_event_country(expense) content_tag(:span, expense[:event_country], title: t("countries.#{expense[:event_country]}")) end |
#html_value_for_event_end_date(expense) ⇒ Object
Called from html_value_for
124 125 126 |
# File 'app/helpers/report_helper.rb', line 124 def html_value_for_event_end_date(expense) l(expense.value_for(:event_end_date)) end |
#html_value_for_event_name(expense) ⇒ Object
Called from html_value_for
88 89 90 |
# File 'app/helpers/report_helper.rb', line 88 def html_value_for_event_name(expense) link_to expense[:event_name], event_path(expense[:event_id]) end |
#html_value_for_event_start_date(expense) ⇒ Object
Called from html_value_for
118 119 120 |
# File 'app/helpers/report_helper.rb', line 118 def html_value_for_event_start_date(expense) l(expense.value_for(:event_start_date)) end |
#html_value_for_reimbursement_state(expense) ⇒ Object
Called from html_value_for
69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/report_helper.rb', line 69 def html_value_for_reimbursement_state(expense) state = expense.value_for(:reimbursement_state) if state.blank? '' else state = Reimbursement.human_state_name(state) link_to(state, request_reimbursement_path(expense[:request_id])) end end |
#html_value_for_request_id(expense) ⇒ Object
Called from html_value_for
94 95 96 |
# File 'app/helpers/report_helper.rb', line 94 def html_value_for_request_id(expense) link_to "##{expense[:request_id]}", request_path(expense[:request_id]) end |
#html_value_for_sum_amount(expense) ⇒ Object
Called from html_value_for
100 101 102 |
# File 'app/helpers/report_helper.rb', line 100 def html_value_for_sum_amount(expense) number_to_currency(expense.value_for(:sum_amount) || 0, unit: '') end |
#html_value_for_user_country(expense) ⇒ Object
Called from html_value_for
112 113 114 |
# File 'app/helpers/report_helper.rb', line 112 def html_value_for_user_country(expense) content_tag(:span, expense[:user_country], title: t("countries.#{expense[:user_country]}")) end |
#value_for_request_state(expense) ⇒ Object
Called from html_value_for and xlsx_value_for
63 64 65 |
# File 'app/helpers/report_helper.rb', line 63 def value_for_request_state(expense) TravelSponsorship.human_state_name expense.value_for(:request_state) end |
#xlsx_style_for(field) ⇒ Hash
Style for the axlsx template for a given field
144 145 146 |
# File 'app/helpers/report_helper.rb', line 144 def xlsx_style_for(field) send(:"xlsx_style_for_#{field}") if respond_to? :"xlsx_style_for_#{field}" end |
#xlsx_style_for_sum_amount ⇒ Object
Called from xlsx_style_for
150 151 152 |
# File 'app/helpers/report_helper.rb', line 150 def xlsx_style_for_sum_amount { num_fmt: 2 } end |
#xlsx_value_for(field, expense) ⇒ Object
Return the value of a field for a given TravelExpenseReport instance, in a format useful to the axlsx template.
50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/report_helper.rb', line 50 def xlsx_value_for(field, expense) if respond_to? :"xlsx_value_for_#{field}" send(:"xlsx_value_for_#{field}", expense) elsif respond_to? :"value_for_#{field}" send(:"value_for_#{field}", expense) else expense.value_for field end end |
#xlsx_value_for_event_country(expense) ⇒ Object
Called from xlsx_value_for
136 137 138 |
# File 'app/helpers/report_helper.rb', line 136 def xlsx_value_for_event_country(expense) country_label(expense.value_for(:event_country)) end |
#xlsx_value_for_user_country(expense) ⇒ Object
Called from xlsx_value_for
130 131 132 |
# File 'app/helpers/report_helper.rb', line 130 def xlsx_value_for_user_country(expense) country_label(expense.value_for(:user_country)) end |
#xslx_value_for_reimbursement_state(expense) ⇒ Object
Called from xlsx_value_for
81 82 83 84 |
# File 'app/helpers/report_helper.rb', line 81 def xslx_value_for_reimbursement_state(expense) state = expense.value_for(:reimbursement_state) state.blank? ? '' : Reimbursement.human_state_name(state) end |