Module: OrdersHelper

Defined in:
app/helpers/orders_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_order_party_hash(order) ⇒ Object



15
16
17
18
19
20
21
22
# File 'app/helpers/orders_helper.rb', line 15

def build_order_party_hash(order)
  parties_hash = {}
  primary_party = order.opportunity && (order.primary_party != order.opportunity.primary_party) ? order.opportunity.primary_party : order.primary_party
  parties_hash["#{primary_party.full_name} (Primary)"] = primary_party
  parties_hash["#{order.customer.full_name} (Billing Customer)"] = { party: order.customer } if order.customer != primary_party
  append_opportunity_participants_hash(order.opportunity, parties_hash) if order.opportunity
  parties_hash
end

#carrier_tag(shipment_entry) ⇒ Object



39
40
41
42
43
44
45
# File 'app/helpers/orders_helper.rb', line 39

def carrier_tag(shipment_entry)
  if shipment_entry.carrier_icon
    image_tag(shipment_entry.carrier_icon)
  elsif shipment_entry.carrier.present?
    fa_icon('truck', text: shipment_entry.carrier)
  end
end

#cod_text(order) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/orders_helper.rb', line 47

def cod_text(order)
  return '' if order.nil?

  if order.cod_collection_type == 'no_check'
    'COD (certified check or money order required)'
  elsif order.cod_collection_type == 'check'
    'COD (business check)'
  else
    ''
  end
end

#create_new_order_button(context_object) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
# File 'app/helpers/orders_helper.rb', line 135

def create_new_order_button(context_object)
  actions = []
  Order::UNRESTRICTED_ORDER_TYPES.each do |order_type, order_type_label|
    next unless can?(:create, Order.new(order_type: order_type))

    actions << link_to(order_type_label,
                       polymorphic_path([context_object, :order], action: :new, order_type: order_type),
                       class: 'dropdown-item', data: { turbo_submits_with: 'Please wait...' })
  end
  render_simple_drop_down(['Create new order'] + actions)
end

#display_order_update_alerts(order) ⇒ Object



127
128
129
# File 'app/helpers/orders_helper.rb', line 127

def display_order_update_alerts(order)
  render partial: '/shared/order_alerts', locals: { order: order }
end

#display_ship_insurance_alerts(order) ⇒ Object



131
132
133
# File 'app/helpers/orders_helper.rb', line 131

def display_ship_insurance_alerts(order)
  render partial: '/shared/ship_insurance_alerts', locals: { ship_quotable: order }
end

#fields_for_order_shipping_cost(shipping_cost) ⇒ Object



4
5
6
7
# File 'app/helpers/orders_helper.rb', line 4

def fields_for_order_shipping_cost(shipping_cost, &)
  prefix = shipping_cost.new_record? ? 'new' : 'existing'
  fields_for("order[#{prefix}_shipping_cost_attributes][]", shipping_cost, &)
end

#has_prepurchased_label?(order) ⇒ Boolean

Returns true if the order has an active pre-purchased shipping label
that would be voided by cancel/hold/fraud actions.

Parameters:

  • order (Order)

    The order to check

Returns:

  • (Boolean)


176
177
178
# File 'app/helpers/orders_helper.rb', line 176

def has_prepurchased_label?(order)
  order&.has_early_purchased_label? == true
end

#order_command_options(order_presenter) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/orders_helper.rb', line 59

def order_command_options(order_presenter)
  opts = []
  opts << if order_presenter.awaiting_future_deliveries?
            'Awaiting Future Deliveries'
          else
            order_presenter.order.human_state_name.titleize
          end
  state_description = order_presenter.order.try(:state_description)
  opts << { content: state_description } if state_description.present?
  # opts << { class: 'divider' }
  opts += order_presenter.actions
  opts.compact
end

#order_tab_optionsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/helpers/orders_helper.rb', line 85

def order_tab_options
  {
    line_items: { remote_href: tab_line_items_order_path(@order) },
    main: { remote_href: tab_main_order_path(@order) },
    contacts: { remote_href: tab_contacts_order_path(@order) },
    shipping: { remote_href: tab_shipping_order_path(@order) },
    activities: { counter: @order.open_activities_counter, remote_href: order_activities_path(@order, selected_activity: params[:selected_activity]) },
    communications: { remote_href: order_communications_path(@order) },
    sms: {
      remote_href: order_sms_messages_path(@order),
      counter: @order.sms_messages.unread.size
    },
    payments: { remote_href: tab_payments_order_path(@order) },
    rooms: {
      counter: @order.room_configurations.size,
      title: String.new('Rooms & Areas'),
      remote_href: order_room_configurations_path(@order)
    },
    attachments: {
      counter: @order.all_uploads.size,
      remote_href: order_uploads_path(@order)
    },
    tickets: {
      title: 'Tickets',
      counter_html: tech_counter_badge(@order.support_cases),
      remote_href: tab_tickets_order_path(@order)
    },
    inventory: { remote_href: tab_inventory_order_path(@order) },
    invoices: { remote_href: tab_invoices_order_path(@order) },
    rmas: { counter: @order.rmas.rma_active.size, remote_href: tab_rmas_order_path(@order) },
    credit_memos: { remote_href: tab_credit_memos_order_path(@order) },
    material_alerts: { remote_href: show_material_alerts_tab_order_path(@order) },
    reviews: { remote_href: tab_reviews_order_path(@order) },
    marketing: { title: 'Marketing', remote_href: tab_marketing_order_path(@order) },
    edi_documents: {
      title: 'EDI',
      counter: @order.edi_communication_logs.size,
      remote_href: tab_edi_documents_order_path(@order)
    }
  }.tap { |h| h.delete(:edi_documents) if h[:edi_documents][:counter].zero? }
end

#prepurchased_label_void_confirm(order, base_confirm_msg = nil) ⇒ String?

Build a confirmation message warning that a pre-purchased label will be voided.
Returns nil if the order has no active pre-purchased label.

Parameters:

  • order (Order)

    The order to check

  • base_confirm_msg (String, nil) (defaults to: nil)

    An existing confirmation message to prepend the warning to

Returns:

  • (String, nil)

    Combined warning + base message, or nil if no early label



160
161
162
163
164
165
166
167
168
169
# File 'app/helpers/orders_helper.rb', line 160

def prepurchased_label_void_confirm(order, base_confirm_msg = nil)
  return base_confirm_msg unless order&.has_early_purchased_label?

  warning = "⚠️ WARNING: This order has a pre-purchased shipping label " \
            "(#{order.early_label_carrier}#{order.early_label_tracking_number}). " \
            "This action will VOID the pre-purchased label. " \
            "A new label will need to be purchased when the order is ready to ship."

  base_confirm_msg.present? ? "#{warning}\n\n#{base_confirm_msg}" : warning
end


73
74
75
76
77
# File 'app/helpers/orders_helper.rb', line 73

def price_edit_link(order)
  return unless order.is_price_editable?

  link_to_if can?(:edit_prices, order), 'Edit Prices', url_for(controller: 'orders', action: 'price_edit', id: order.id), class: 'btn btn-outline-primary', data: { turbo_frame: '_top' }
end

#selectable_order_typesObject



79
80
81
82
83
# File 'app/helpers/orders_helper.rb', line 79

def selectable_order_types
  Order.selectable_order_types.select do |(_order_type_label, order_type)|
    can?(:create, Order.new(order_type: order_type))
  end
end

#setup_order(order) ⇒ Object



9
10
11
12
13
# File 'app/helpers/orders_helper.rb', line 9

def setup_order(order)
  order.tap do |o|
    o.opportunity ||= Opportunity.new
  end
end

#setup_order_billing_address(order) ⇒ Object



24
25
26
27
28
29
30
31
# File 'app/helpers/orders_helper.rb', line 24

def setup_order_billing_address(order)
  order.tap do |o|
    if o.billing_address.nil?
      o.billing_address = o.customer.billing_address
      o.billing_address ||= Address.new(country_iso3: @customer.catalog.store.country_iso3, party_id: o.customer_id)
    end
  end
end

#setup_order_shipping_address(order) ⇒ Object



33
34
35
36
37
# File 'app/helpers/orders_helper.rb', line 33

def setup_order_shipping_address(order)
  order.tap do |o|
    o.shipping_address = o.customer.try(:shipping_address).try(:clone) || o.customer.addresses.first.try(:clone) if o.shipping_address_id.nil?
  end
end