Class: Search::PurchaseOrderPresenter

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

Overview

Row presenter for PurchaseOrderSearch — renders the cells in the CRM purchase
order search/results table. Wraps a ViewPurchaseOrder projection rather than
a fully-loaded PurchaseOrder so the search grid stays light.

Direct Known Subclasses

PurchaseOrderTextPresenter

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

Partial-rendered items report for the purchase order.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


31
32
33
34
35
# File 'app/presenters/search/purchase_order_presenter.rb', line 31

def items_report_link
  return unless r.has_columns?(:items_report)

  h.render partial: '/purchase_orders/search_items_report', locals: { items_report: r.items_report, search_result: r }
end

#order_dateString

Purchase order date rendered through the shared render_date helper.

Returns:

  • (String)


66
67
68
# File 'app/presenters/search/purchase_order_presenter.rb', line 66

def order_date
  h.render_date r.order_date
end

#promised_delivery_dateString

Promised delivery date rendered through the shared render_date helper.

Returns:

  • (String)


59
60
61
# File 'app/presenters/search/purchase_order_presenter.rb', line 59

def promised_delivery_date
  h.render_date r.promised_delivery_date
end

Linked purchase order reference number → purchase order show page.

Returns:

  • (ActiveSupport::SafeBuffer)


14
15
16
# File 'app/presenters/search/purchase_order_presenter.rb', line 14

def purchase_order_link
  h.link_to r.reference_number, h.purchase_order_path(r.id)
end

Linked supplier name → supplier show page; nil when the user lacks read
permission or the required columns are not selected.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


22
23
24
25
26
# File 'app/presenters/search/purchase_order_presenter.rb', line 22

def supplier_link
  return unless r.has_columns?(:supplier_full_name, :supplier_id) && h.can?(:read, Supplier)

  h.link_to r.supplier_full_name, h.supplier_path(r.supplier_id)
end

#termsActiveSupport::SafeBuffer, ...

Payment terms; shows a lock icon when the user cannot manage item costs.

Returns:

  • (ActiveSupport::SafeBuffer, String, nil)


50
51
52
53
54
# File 'app/presenters/search/purchase_order_presenter.rb', line 50

def terms
  return h.fa_icon('lock') unless h.can?(:manage_item_costs, r)

  r.terms
end

#total_costsActiveSupport::SafeBuffer, String

Total cost formatted as currency; shows a lock icon when the user cannot
manage item costs.

Returns:

  • (ActiveSupport::SafeBuffer, String)


41
42
43
44
45
# File 'app/presenters/search/purchase_order_presenter.rb', line 41

def total_costs
  return h.fa_icon('lock') unless h.can?(:manage_item_costs, r)

  h.number_to_currency(r.total_cost || 0)
end