Module: PurchaseOrderHelper

Defined in:
app/helpers/purchase_order_helper.rb

Instance Method Summary collapse

Instance Method Details



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

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/purchase_order_helper.rb', line 4

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
    if purchase_order.can_be_edited?
      opts << link_to(fa_icon('pen-to-square', text: 'Edit'), edit_purchase_order_path(purchase_order))
    end
    if purchase_order.can_be_cancelled?
      opts << link_to('Cancel', cancel_purchase_order_path(purchase_order), data: { turbo_confirm: 'Are you sure?', turbo_method: :put })
    end
    if purchase_order.pending_service_fulfillment?
      opts << link_to('Service Fulfilled', service_fulfilled_purchase_order_path(purchase_order), data: { turbo_method: :put })
    end
    unless purchase_order.cancelled?
      opts << link_to('Transmit', transmit_purchase_order_path(purchase_order))
    end
    opts << link_to('Regenerate PDF', regenerate_pdf_purchase_order_path(purchase_order))
    if purchase_order.serial_numbers.any?
      opts << link_to('Print Serial Number Labels', print_serial_number_labels_purchase_order_path(purchase_order))
    end
  end
  opts
end

#purchase_order_item_parent_sku(poi) ⇒ Object



61
62
63
64
# File 'app/helpers/purchase_order_helper.rb', line 61

def purchase_order_item_parent_sku(poi)
  return unless lip = poi.line_item&.parent
  tag.br + tag.small("#{lip.sku} (#{lip.quantity})", class: 'text-muted')
end

#purchase_order_tab_options(purchase_order) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/purchase_order_helper.rb', line 29

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