Class: Search::OrderPresenter

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

Overview

HTML presenter for order search results backed by ViewOrder.

Direct Known Subclasses

OrderTextPresenter

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

Returns a link to the associated contact, if available.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


155
156
157
158
159
# File 'app/presenters/search/order_presenter.rb', line 155

def contact_link
  return unless r.has_columns?(:contact_full_name, :contact_id)

  h.link_to r.contact_full_name, h.contact_path(r.contact_id)
end

#couponsString?

Returns a sentence listing the coupon codes applied to the order.

Returns:

  • (String, nil)


137
138
139
140
141
# File 'app/presenters/search/order_presenter.rb', line 137

def coupons
  return unless r.has_columns?(:coupons)

  r.coupons.to_sentence
end

#currency_symbolString

Returns the symbol for the USD currency.

Returns:

  • (String)


72
73
74
# File 'app/presenters/search/order_presenter.rb', line 72

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

Returns a link to the associated customer, if available.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


128
129
130
131
132
# File 'app/presenters/search/order_presenter.rb', line 128

def customer_link
  return unless r.has_columns?(:customer_full_name, :customer_id)

  h.link_to r.customer_full_name, h.customer_path(r.customer_id)
end

#estimated_costString?

Returns the estimated cost formatted as currency, for managers only.

Returns:

  • (String, nil)


100
101
102
103
104
105
106
# File 'app/presenters/search/order_presenter.rb', line 100

def estimated_cost
  return unless .is_manager?
  return unless r.has_columns?(:estimated_cost, :currency)
  return unless r.estimated_cost

  h.number_to_currency r.estimated_cost, unit: currency_symbol
end

#estimated_profit_marginString?

Returns the estimated profit margin formatted as a percentage, for managers only.

Returns:

  • (String, nil)


111
112
113
114
115
116
# File 'app/presenters/search/order_presenter.rb', line 111

def estimated_profit_margin
  return unless .is_manager?
  return unless r.has_columns?(:estimated_profit_margin)

  h.number_to_percentage r.estimated_profit_margin, precision: 2
end

#gross_revenueString

Returns the gross revenue formatted as currency.

Returns:

  • (String)


79
80
81
# File 'app/presenters/search/order_presenter.rb', line 79

def gross_revenue
  h.number_to_currency (r.line_total || 0.00), unit: currency_symbol
end

#has_pending_drop_ship_deliveriesActiveSupport::SafeBuffer

Returns a yes/no indicator for pending drop-ship deliveries.

Returns:

  • (ActiveSupport::SafeBuffer)


121
122
123
# File 'app/presenters/search/order_presenter.rb', line 121

def has_pending_drop_ship_deliveries
  h.y r.has_pending_drop_ship_deliveries
end

#msrpString

Returns the MSRP formatted as currency.

Returns:

  • (String)


93
94
95
# File 'app/presenters/search/order_presenter.rb', line 93

def msrp
  h.number_to_currency (r.line_total_msrp || 0.00), unit: currency_symbol
end

#notes_indicatorActiveSupport::SafeBuffer

Returns a notes popover for the order notes.

Returns:

  • (ActiveSupport::SafeBuffer)


65
66
67
# File 'app/presenters/search/order_presenter.rb', line 65

def notes_indicator
  h.notes_popover r.notes
end

Returns a link to the associated opportunity, if available.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


49
50
51
52
53
# File 'app/presenters/search/order_presenter.rb', line 49

def opportunity_link
  return unless r.has_columns?(:opportunity_name, :opportunity_id)

  h.link_to r.opportunity_name, h.opportunity_path(r.opportunity_id)
end

Returns a link to the order using its reference number or cart id.

Returns:

  • (ActiveSupport::SafeBuffer)


15
16
17
# File 'app/presenters/search/order_presenter.rb', line 15

def order_link
  h.link_to r.reference_number || "Cart id #{r.id}", h.order_path(r.id)
end

Returns a link to the original order, if one exists.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


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

def original_order_link
  return nil if r.original_order_id.nil?

  h.link_to r.original_order_reference_number, h.order_path(r.original_order_id)
end

Returns a link to the associated RMA, if one exists.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


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

def rma_link
  return nil if r.rma_id.nil?

  h.link_to r.credit_rma_number, h.rma_path(r.rma_id)
end

Returns a link to the SPIFF rep, if available.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


146
147
148
149
150
# File 'app/presenters/search/order_presenter.rb', line 146

def spiff_rep_link
  return unless r.has_columns?(:spiff_rep_full_name, :spiff_rep_id)

  h.link_to r.spiff_rep_full_name, h.contact_path(r.spiff_rep_id)
end

#stateString

Returns the human-readable order state name.

Returns:

  • (String)


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

def state
  Order.human_state_name(r.state)
end

Returns a link to the associated support case, if one exists.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


40
41
42
43
44
# File 'app/presenters/search/order_presenter.rb', line 40

def support_case_link
  return nil if r.support_case_id.nil?

  h.link_to r.support_case_number, h.support_case_path(r.support_case_id)
end

#total_revenueString

Returns the total revenue formatted as currency.

Returns:

  • (String)


86
87
88
# File 'app/presenters/search/order_presenter.rb', line 86

def total_revenue
  h.number_to_currency (r.total || 0.00), unit: currency_symbol
end