Module: Crm::ShipmentsHelper

Defined in:
app/helpers/crm/shipments_helper.rb

Overview

View helper: shipments.

Instance Method Summary collapse

Instance Method Details

#container_type_icon(container_type) ⇒ Object



11
12
13
# File 'app/helpers/crm/shipments_helper.rb', line 11

def container_type_icon(container_type)
  container_type == 'pallet' ? 'pallet-alt' : 'box'
end

#friendly_shipment_status(shipment) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'app/helpers/crm/shipments_helper.rb', line 112

def friendly_shipment_status(shipment)
  addendum = ""
  if shipment.state == 'suggested'
    packing_solution = Shipping::DeterminePackaging.new.process(delivery: shipment.delivery, is_freight: shipment.delivery.ships_ltl_freight?)
    packing_solution.source_type.to_s
    addendum = " (#{packing_solution.source_type.to_s.humanize.downcase})" if packing_solution.source_type.present?
  end
  "#{friendly_status(shipment.state)}#{addendum}"
end


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
# File 'app/helpers/crm/shipments_helper.rb', line 86

def shipment_audit_link(shipment)
  return if shipment.blank?
  return if shipment.voided?

  audit = shipment.audit_result&.values
  return unless audit.present? && shipment.issues_count > 0

  badge_class = audit.size > 1 ? 'bg-danger' : 'bg-warning text-dark'
  issues_html = audit.map { |v| "#{v}" }.join('<br>')

  badge = (:a, shipment.issues_count,
    class: "badge #{badge_class} text-decoration-none",
    role: 'button',
    tabindex: 0,
    data: {
      bs_toggle: 'popover',
      bs_trigger: 'focus',
      bs_placement: 'bottom',
      bs_html: 'true',
      bs_content: issues_html
    },
    title: 'Shipping Issues')

  (:span, badge, data: { controller: 'popover' })
end

#shipment_command_options(shipment = @shipment, link_options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/crm/shipments_helper.rb', line 65

def shipment_command_options(shipment = @shipment, link_options = {})
  # class: 'btn btn-outline-primary'
  links = []
  return_path = link_options.delete(:return_path)
  with_options(link_options) do |d|
    links << d.link_to("View #{shipment.container_type.capitalize}", shipment_path(shipment.id))
    if shipment.editable? && (!shipment.delivery&.locked_for_fba? || current_user.has_role?('admin'))
      links << d.link_to('Edit', edit_shipment_path(shipment, return_path: return_path))
      links << d.link_to('Delete', shipment_path(shipment, return_path: return_path), data: { turbo_confirm: 'Are you sure?', turbo_method: :delete }) unless shipment.delivery&.incorrectly_packaged_ups_canada_order
    end
    links << d.link_to('View Ship Label', upload_path(shipment.ship_label_pdf)) if shipment.ship_label_pdf
    links << d.link_to('View Bill of Lading', upload_path(shipment.bol_pdf)) if shipment.bol_pdf
    links << d.link_to('Manifest', upload_path(shipment.manifest.manifest_pdf)) if shipment.manifest.present? && shipment.manifest.manifest_pdf.present?
    links << d.link_to('Letter Format Label', upload_path(shipment.ship_label_pdf(true))) if shipment.ship_label_pdf(true)
    links << d.link_to('Carton/UCC-128 Label', carton_label_shipment_path(shipment.id, format: :pdf)) unless shipment.suggested? || shipment.delivery.nil?
    # links << :separator
    # links += available_events_links(shipment, { return_path: return_path })
  end
  links
end

#shipment_container_type_for_select_with_iconsObject



4
5
6
7
8
9
# File 'app/helpers/crm/shipments_helper.rb', line 4

def shipment_container_type_for_select_with_icons
  Shipment.container_types_for_select.map do |ct|
    icon_symbol = container_type_icon(ct[1])
    [fa_icon(icon_symbol, text: ct[0]), ct[1]]
  end
end

#shipment_container_type_label(shipment) ⇒ Object



15
16
17
18
19
# File 'app/helpers/crm/shipments_helper.rb', line 15

def shipment_container_type_label(shipment)
  return if shipment.blank?

  fa_icon(container_type_icon(shipment.container_type), text: shipment.container_type&.titleize)
end

#shipment_contents_drop_down(shipment, main_link_class: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/crm/shipments_helper.rb', line 21

def shipment_contents_drop_down(shipment, main_link_class: nil)
  return if shipment.blank?

  label = shipment.shipment_contents.sum(:quantity)
  if label.zero?
    if shipment.child_shipments.present?
      fa_icon('layer-plus', class: 'btn', title: 'Parent Shipment, see cartons for contents')
    else
      fa_icon('empty-set', class: 'btn text-danger')
    end
  else
    opts = {}
    opts[:main_link_class] = main_link_class if main_link_class
    render_simple_drop_down [label.to_s] + shipment.shipment_contents.joins(line_item: :item).order(Item[:sku]).group(Item[:sku]).sum(:quantity).map { |sku, quantity| { tag: :p, content: "#{quantity} - #{sku}", style: 'white-space:nowrap' } }, opts
  end
end

#shipment_description(shipment) ⇒ Object



61
62
63
# File 'app/helpers/crm/shipments_helper.rb', line 61

def shipment_description(shipment)
  "#{shipment_container_type_label(shipment)} ...#{shipment.reference_number&.last(4)}".html_safe
end

#uploads_for_shipment(shipment) ⇒ Object



38
39
40
41
42
# File 'app/helpers/crm/shipments_helper.rb', line 38

def uploads_for_shipment(shipment)
  uploads = []
  uploads += shipment.uploads.to_a if shipment.present?
  uploads.sort_by { |u| [u.category.to_s, -u.created_at.to_i] }
end

#uploads_for_shipment_dropdown(shipment) ⇒ Object



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

def uploads_for_shipment_dropdown(shipment)
  links = [fa_icon('paperclip')]
  uploads_for_shipment(shipment).each do |psu|
    title = (:div, class: 'row') do
      concat (:div, psu.category.humanize.titleize, class: 'float-start') if psu.category
      concat tag.br
      concat (:p, render_datetime(psu.created_at), class: 'text-muted')
    end
    links << link_to(title,
                upload_path(psu),
                target: '_blank', rel: "noopener noreferrer")
  end
  return unless links.size > 1

  render_simple_drop_down links
end