Module: OutgoingPaymentsHelper
- Defined in:
- app/helpers/outgoing_payments_helper.rb
Overview
== Schema Information
Table name: payments
id :integer not null, primary key
category :string(255)
company_id :integer
supplier_id :integer
reference_number :string(255)
amount :decimal(10, 2)
payment_date :date
currency :string(255)
bank_account_id :integer
exchange_rate :float
state :string(255)
remark :text
creator_id :integer
updater_id :integer
created_at :datetime
updated_at :datetime
check_state :string(255)
job_id :string(255)
reversal_date :date
Constant Summary collapse
- PAYMENT_STATE_BADGES =
{ 'draft' => 'text-bg-secondary', 'applied' => 'text-bg-success', 'voided' => 'text-bg-danger' }.freeze
- PAYMENT_CATEGORY_BADGES =
{ 'ach' => ['text-bg-primary', 'fa-arrows-left-right'], 'cash' => ['text-bg-secondary', 'fa-money-bill'], 'check' => ['text-bg-info', 'fa-money-check'], 'debit_card' => ['text-bg-dark', 'fa-credit-card'], 'e_billpay' => ['text-bg-secondary', 'fa-file-invoice'], 'non_cash' => ['text-bg-secondary', 'fa-ban'], 'paypal' => ['text-bg-warning', 'fa-paypal'], 'wire_transfer' => ['text-bg-primary', 'fa-building-columns'] }.freeze
- CHECK_STATE_BADGES =
{ 'pending_review' => 'text-bg-warning', 'queued' => 'text-bg-primary', 'generated' => 'text-bg-info', 'printed' => 'text-bg-success', 'reprinted' => 'text-bg-secondary' }.freeze
Instance Method Summary collapse
- #check_audit_history(check) ⇒ Object
- #check_command_options(payment, check) ⇒ Object
- #check_state_badge(state) ⇒ Object
- #outgoing_payment_command_options(payment) ⇒ Object
- #payment_category_badge(category) ⇒ Object
- #payment_state_badge(state) ⇒ Object
Instance Method Details
#check_audit_history(check) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/outgoing_payments_helper.rb', line 103 def check_audit_history(check) links = [] if check.last_printed_by links << check.last_printed_by.try(:full_name) end check.print_audit.each do |audit| date_parsed = Time.zone.parse(audit[:printed_on]) rescue nil links << { tag: :span, content: "Printed by #{audit[:printed_by]} on #{date_parsed&.to_fs(:crm_default)}", class: 'mb-0 px-2', style: 'white-space:nowrap' } end links end |
#check_command_options(payment, check) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/outgoing_payments_helper.rb', line 92 def (payment, check) links = [] unless check.uploads.empty? links << link_to("Print", print_check_outgoing_payment_path(payment, check_id: check.id)) end if user_has_role?("accounting_rep") links << link_to("Preview Pdf", check_path(check, format: :pdf)) end links end |
#check_state_badge(state) ⇒ Object
64 65 66 67 68 69 |
# File 'app/helpers/outgoing_payments_helper.rb', line 64 def check_state_badge(state) return nil if state.blank? css = CHECK_STATE_BADGES.fetch(state.to_s, 'text-bg-secondary') content_tag(:span, state.to_s.humanize, class: "badge #{css}") end |
#outgoing_payment_command_options(payment) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/helpers/outgoing_payments_helper.rb', line 71 def (payment) links = [] if payment.category == 'check' && !payment.voided? links << fa_icon('shuffle', text: "#{payment.human_state_name.titleize} and #{payment.human_check_state_name.titleize}") else links << fa_icon('shuffle', text: payment.human_state_name.titleize) end links << link_to("Edit", edit_outgoing_payment_path(payment)) unless @outgoing_payment.editing_locked? links << link_to("Pay Items", pay_items_outgoing_payment_path(@outgoing_payment)) if @outgoing_payment.draft? links << link_to("Approve Check", approve_check_outgoing_payment_path(@outgoing_payment)) if @outgoing_payment.pending_review? && !@outgoing_payment.voided? if payment.can_print_check? unless payment.checks.any? and payment.checks.all? {|c| c.uploads.empty?} links << link_to(payment.checks.any? ? "Reprint Check" : "Print Check", print_check_outgoing_payment_path(payment)) end end links << link_to("Void", void_outgoing_payment_path(@outgoing_payment), data: { turbo_confirm: "Are you sure you want to void this payment? Any linked vouchers or credit memos will be marked as unpaid." }) if !@outgoing_payment.voided? links << link_to("Reverse", reverse_outgoing_payment_path(@outgoing_payment)) if !@outgoing_payment.voided? links << link_to("Delete", payment, data: { turbo_confirm: "Are you sure you want to delete this payment?", turbo_method: :delete }) if payment.draft? links end |
#payment_category_badge(category) ⇒ Object
57 58 59 60 61 62 |
# File 'app/helpers/outgoing_payments_helper.rb', line 57 def payment_category_badge(category) css, icon = PAYMENT_CATEGORY_BADGES.fetch(category.to_s, ['text-bg-secondary', 'fa-circle-dollar']) content_tag(:span, class: "badge #{css} d-inline-flex align-items-center gap-1") do content_tag(:i, nil, class: "fa-regular #{icon}") + ' ' + category.to_s.humanize end end |
#payment_state_badge(state) ⇒ Object
52 53 54 55 |
# File 'app/helpers/outgoing_payments_helper.rb', line 52 def payment_state_badge(state) css = PAYMENT_STATE_BADGES.fetch(state.to_s, 'text-bg-secondary') content_tag(:span, state.to_s.humanize, class: "badge #{css}") end |