Class: Search::OutgoingPaymentPresenter

Inherits:
BasePresenter
  • Object
show all
Includes:
Presenters::Timeable
Defined in:
app/presenters/search/outgoing_payment_presenter.rb

Overview

Presenter: outgoing payment presenter.

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from BasePresenter

Instance Method Details

#amountString

Currency-formatted payment amount in USD.

Returns:

  • (String)


58
59
60
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 58

def amount
  h.number_to_currency(r.amount, unit: currency_symbol)
end

#currency_symbolString

Always-USD currency symbol — the search index materializes
amounts in USD regardless of the payment's native currency.

Returns:

  • (String)


52
53
54
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 52

def currency_symbol
  Money::Currency.new('USD').symbol
end

Hourglass icon linking to the linked Job, when present.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


64
65
66
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 64

def job_link
  r.job_id.nil? ? nil : h.link_to(h.fa_icon("hourglass-half"), h.job_path(r.job_id))
end

#last_printed_atString

Localized cheque-print timestamp.

Returns:

  • (String)


76
77
78
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 76

def last_printed_at
  h.render_datetime(r.last_printed_at)
end

Link to the payee Party — same polymorphic dispatch as
#supplier_link but rendered red when the payee differs from
the supplier (a third-party payment).

Returns:

  • (ActiveSupport::SafeBuffer)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 35

def payee_link
  path = case r.payee_type
         when 'Supplier'
           h.supplier_path(r.payee_id)
         when 'Employee'
           h.employee_path(r.payee_id)
         when 'Contact'
           h.contact_path(r.payee_id)
         when 'Customer'
           h.customer_path(r.payee_id)
         end
  h.link_to(r.payee_name, path, style: r.payee_id == r.supplier_id ? '' : 'color:red')
end

#payment_dateString

Localized payment date.

Returns:

  • (String)


70
71
72
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 70

def payment_date
  h.render_date(r.payment_date)
end

#payment_detailsActiveSupport::SafeBuffer

Button + Bootstrap modal trigger for the payment-items
breakdown (#payment_details_modal).

Returns:

  • (ActiveSupport::SafeBuffer)


83
84
85
86
87
88
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 83

def payment_details
  h. :span do
    h.concat h.button_tag "Details", class: 'btn btn-outline-primary', 'data-bs-toggle': 'modal', 'data-bs-target': "#payment_details_#{r.id}"
    h.concat payment_details_modal
  end
end

#payment_details_modalActiveSupport::SafeBuffer

The modal body that #payment_details pops — renders the
outgoing_payments/payment_items_preview partial with totals.

Returns:

  • (ActiveSupport::SafeBuffer)


93
94
95
96
97
98
99
100
101
102
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 93

def payment_details_modal
  h.modal_dialog("payment_details_#{r.id}", nil, true) do
    h.concat h.modal_dialog_header "Payment Details"
    body = h.modal_dialog_body do
      h.render partial: "outgoing_payments/payment_items_preview",
locals: { outgoing_payment: r.outgoing_payment, outgoing_payment_items: r.outgoing_payment_items, total_gross: r.outgoing_payment_items.to_a.sum(&:gross_amount), total_payment: r.outgoing_payment_items.to_a.sum(&:amount) }
    end
    h.concat body
  end
end

Link to the OutgoingPayment detail page.

Returns:

  • (ActiveSupport::SafeBuffer)


10
11
12
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 10

def payment_link
  h.link_to(r.reference_number, h.outgoing_payment_path(r.id))
end

Link to the supplier Party, polymorphic across
Supplier / Employee / Contact / Customer.

Returns:

  • (ActiveSupport::SafeBuffer)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/presenters/search/outgoing_payment_presenter.rb', line 17

def supplier_link
  path = case r.supplier_type
         when 'Supplier'
           h.supplier_path(r.supplier_id)
         when 'Employee'
           h.employee_path(r.supplier_id)
         when 'Contact'
           h.contact_path(r.supplier_id)
         when 'Customer'
           h.customer_path(r.supplier_id)
         end
  h.link_to(r.supplier_name, path)
end