Module: ReimbursementsHelper
- Defined in:
- app/helpers/reimbursements_helper.rb
Overview
Helpers for reimbursements' views
Instance Method Summary collapse
-
#can_read_pdf_for?(reimb) ⇒ Boolean
Checks whether the current user should be authorized to read the pdf version of a reimbursement, since the pdf version includes information about the user profile and bank information.
- #check_request_bank_value(account, field) ⇒ Object
-
#check_request_link(reimbursement) ⇒ String
Outputs a link to the reimbursement's check request only if everything related to check requests is configured.
- #check_request_reimb_value(reimb, field) ⇒ Object
-
#check_request_value(reimb, field) ⇒ String
Outputs the value for the given reimbursement of one of the check request's fields.
-
#manual_authorized_amount_is_needed_for?(reimb) ⇒ Boolean
Checks whether some manual adjustment of 'authorized amount' is required for a reimbursement.
-
#reimbursement_acceptance_file(reimbursement) ⇒ String
Outputs the download link to acceptance_file, with instructions to attach it if needed.
-
#reimbursement_attachments(reimbursement) ⇒ String
Outputs a comma-separated list of attachments for a given reimbursement, including the download link.
-
#reimbursement_links(reimbursement) ⇒ String
Outputs a comma-separated list of links for a given reimbursement,.
-
#reimbursement_payments(reimbursement) ⇒ String
Outputs a table containing payments, with edit and destroy links where allowed.
Instance Method Details
#can_read_pdf_for?(reimb) ⇒ Boolean
Checks whether the current user should be authorized to read the pdf version of a reimbursement, since the pdf version includes information about the user profile and bank information.
190 191 192 |
# File 'app/helpers/reimbursements_helper.rb', line 190 def can_read_pdf_for?(reimb) can?(:read, reimb) && can?(:read, reimb.user.profile) && (reimb.bank_account.nil? || can?(:read, reimb.bank_account)) end |
#check_request_bank_value(account, field) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/helpers/reimbursements_helper.rb', line 162 def check_request_bank_value(account, field) is_iban = account.format == 'iban' case field.to_s.to_sym when :name account.bank_name when :holder account.holder when :iban is_iban ? account.iban : '' when :bic is_iban ? account.bic : '' when :national_code is_iban ? '' : account.national_bank_code when :national_account is_iban ? '' : account.national_account_code when :country is_iban ? '' : country_label(account.country_code) when :postal_address is_iban ? '' : account.bank_postal_address end end |
#check_request_link(reimbursement) ⇒ String
Outputs a link to the reimbursement's check request only if everything related to check requests is configured
113 114 115 116 117 118 119 |
# File 'app/helpers/reimbursements_helper.rb', line 113 def check_request_link(reimbursement) return '' if Rails.configuration.site['check_request_layout'].blank? return '' if Rails.configuration.site['check_request_template'].blank? url = check_request_request_reimbursement_path(reimbursement.request) link_to t(:check_request), url, class: 'btn btn-default' end |
#check_request_reimb_value(reimb, field) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/reimbursements_helper.rb', line 137 def check_request_reimb_value(reimb, field) case field.to_sym when :amount expenses_sum(reimb, :authorized) when :full_name reimb.user.profile.full_name when :date l(Date.today) when :postal_address reimb.user.profile.postal_address when :city reimb.user.profile.location when :country country_label(reimb.user.profile.country_code) when :zip_code reimb.user.profile.zip_code when :phone_number reimb.user.profile.phone_number when :label reimb.label when :email reimb.user.email end end |
#check_request_value(reimb, field) ⇒ String
Outputs the value for the given reimbursement of one of the check request's fields
127 128 129 130 131 132 133 134 135 |
# File 'app/helpers/reimbursements_helper.rb', line 127 def check_request_value(reimb, field) if field.to_s.start_with?('bank_') account = reimb.bank_account field = field[5..-1].to_sym check_request_bank_value(account, field) else check_request_reimb_value(reimb, field) end end |
#manual_authorized_amount_is_needed_for?(reimb) ⇒ Boolean
Checks whether some manual adjustment of 'authorized amount' is required for a reimbursement
198 199 200 |
# File 'app/helpers/reimbursements_helper.rb', line 198 def (reimb) reimb.expenses.any? { |r| !r. } end |
#reimbursement_acceptance_file(reimbursement) ⇒ String
Outputs the download link to acceptance_file, with instructions to attach it if needed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/reimbursements_helper.rb', line 39 def reimbursement_acceptance_file(reimbursement) out = if reimbursement.acceptance_file.blank? t('show_for.blank').html_safe else link_to(reimbursement.acceptance_file.file.filename, request_reimbursement_acceptance_path(reimbursement.request)) end links = [] links << link_to(t(:pdf_format), request_reimbursement_path(reimbursement.request, format: :pdf)) if can_read_pdf_for?(reimbursement) && reimbursement.editable? links << link_to(t(:send_reimbursement_acceptance), new_request_reimbursement_acceptance_path(reimbursement.request), remote: true) if can? :submit, reimbursement info = if can? :submit, reimbursement t(:reimbursement_acceptance_intro).html_safe else info = if reimbursement.acceptance_file.blank? t(:reimbursement_acceptance_blank).html_safe else t(:reimbursement_acceptance_update).html_safe end end info << content_tag(:p, links.join(' | ').html_safe, class: 'text-right') unless links.empty? out << content_tag(:div, info, class: 'alert alert-info') unless info.empty? out end |
#reimbursement_attachments(reimbursement) ⇒ String
Outputs a comma-separated list of attachments for a given reimbursement, including the download link
12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/reimbursements_helper.rb', line 12 def (reimbursement) if reimbursement..empty? I18n.t('show_for.blank') else req = reimbursement.request links = reimbursement..map { |a| link_to(a.title, (req, a)) } links.join(', ').html_safe end end |
#reimbursement_links(reimbursement) ⇒ String
Outputs a comma-separated list of links for a given reimbursement,
26 27 28 29 30 31 32 |
# File 'app/helpers/reimbursements_helper.rb', line 26 def reimbursement_links(reimbursement) if reimbursement.links.empty? I18n.t('show_for.blank') else reimbursement.links.map { |a| link_to(a.title, a.url) }.join(', ').html_safe end end |
#reimbursement_payments(reimbursement) ⇒ String
Outputs a table containing payments, with edit and destroy links where allowed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/reimbursements_helper.rb', line 69 def reimbursement_payments(reimbursement) payments = reimbursement.payments.order(:date).accessible_by(current_ability) if payments.empty? content_tag(:p, I18n.t('show_for.blank')) else header = content_tag(:th, Payment.human_attribute_name(:date)) header << content_tag(:th, Payment.human_attribute_name(:method)) header << content_tag(:th, Payment.human_attribute_name(:subject)) header << content_tag(:th, Payment.human_attribute_name(:amount), class: 'text-right') header << content_tag(:th, '') req = reimbursement.request rows = payments.map do |payment| p = content_tag(:td, l(payment.date, format: :long)) p << content_tag(:td, payment.method) p << content_tag(:td, payment.subject) p << content_tag(:td, number_to_currency(payment.amount, unit: payment.currency), class: 'text-right') links = [] links << link_to(t('helpers.links.edit'), edit_request_reimbursement_payment_path(req, payment)) if can? :update, payment if can? :destroy, payment links << link_to(t('helpers.links.destroy'), request_reimbursement_payment_path(req, payment), data: { confirm: t('helpers.links.confirm') }, method: :delete) end links << link_to(Payment.human_attribute_name(:file), file_request_reimbursement_payment_path(req, payment)) if can?(:update, payment) && !payment.file.blank? p << if links.empty? content_tag(:td, '') else content_tag(:td, "#{payment.code} (#{links.join(' | ')})".html_safe) end content_tag(:tr, p.html_safe) end content_tag(:table, content_tag(:thead, content_tag(:tr, header.html_safe)) + content_tag(:tbody, rows.join('').html_safe), class: 'table table-condensed', id: 'reimbursement-payments') end end |