Module: PurchaseOrderHelper

Defined in:
app/helpers/purchase_order_helper.rb

Overview

View helper: purchase order.

Instance Method Summary collapse

Instance Method Details

Renders a link to the purchase order search showing the on-order count for a store item.

Parameters:

Options Hash (options):

  • show_zero (Boolean)

    render the link even when the count is zero (defaults to true)

  • set_limit (Integer)

    search result limit (defaults to 50)

Returns:

  • (String, nil)

    the link HTML, or nil when the item is not in an AVAILABLE location



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/purchase_order_helper.rb', line 38

def item_on_order_count_link(store_item, options = {})
  return unless store_item.location == 'AVAILABLE'

  options.reverse_merge!({ show_zero: true, set_limit: 50 })
  item_states = %w[not_receipted partially_receipted]
  po_states = %w[partially_receipted pending_fulfillment shipped]
  options[:query_params] = {
    item_states: item_states,
    store_id_in: [store_item.store_id],
    item_ids: [store_item.item_id],
    state_in: po_states
  }
  options[:selected_columns] = %i[purchase_order_link state order_date promised_delivery_date item_count_filtered carrier_full_name supplier_link]

  options[:aggregate_method] = :sum
  options[:aggregate_column] = "(#{PurchaseOrderSearch.item_filtered_without_items_already_receipted_sql([store_item.item_id], item_states)})"
  # options[:link_method] = :link
  query_template_link(PurchaseOrderSearch, nil, options).first
end

#purchase_order_command_options(purchase_order = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/purchase_order_helper.rb', line 5

def purchase_order_command_options(purchase_order = nil)
  purchase_order ||= @purchase_order
  opts = []
  if can?(:manage, purchase_order)
    opts << purchase_order.human_state_name.titleize
    opts << link_to(fa_icon('pen-to-square', text: 'Edit'), edit_purchase_order_path(purchase_order)) if purchase_order.can_be_edited?
    opts << link_to('Cancel', cancel_purchase_order_path(purchase_order), data: { turbo_confirm: 'Are you sure?', turbo_method: :put }) if purchase_order.can_be_cancelled?
    opts << link_to('Service Fulfilled', service_fulfilled_purchase_order_path(purchase_order), data: { turbo_method: :put }) if purchase_order.pending_service_fulfillment?
    opts << link_to('Transmit', transmit_purchase_order_path(purchase_order)) unless purchase_order.cancelled?
    opts << link_to('Regenerate PDF', regenerate_pdf_purchase_order_path(purchase_order))
    opts << link_to('Print Serial Number Labels', print_serial_number_labels_purchase_order_path(purchase_order)) if purchase_order.serial_numbers.any?
  end
  opts
end

#purchase_order_item_parent_sku(poi) ⇒ Object



58
59
60
61
62
# File 'app/helpers/purchase_order_helper.rb', line 58

def purchase_order_item_parent_sku(poi)
  return unless (lip = poi.line_item&.parent)

  tag.br + tag.small("#{lip.sku} (#{lip.quantity})", class: 'text-body-secondary')
end

#purchase_order_tab_options(purchase_order) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/purchase_order_helper.rb', line 20

def purchase_order_tab_options(purchase_order)
  menu_options = { line_items: { remote_href: tab_line_items_purchase_order_path(purchase_order) } }
  if can?(:manage, purchase_order)
    menu_options[:activities] = { remote_href: purchase_order_activities_path(@purchase_order, selected_activity: params[:selected_activity]) }
    menu_options[:attachments] = { remote_href: tab_attachments_purchase_order_path(purchase_order) }
    menu_options[:receipts] = { remote_href: tab_receipts_purchase_order_path(@purchase_order) }
    menu_options[:shipments] = { remote_href: tab_shipments_purchase_order_path(@purchase_order) }
    menu_options[:communications] = { remote_href: purchase_order_communications_path(@purchase_order) }
  end
  menu_options
end