Module: Crm::ShipmentsHelper

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

Instance Method Summary collapse

Instance Method Details

#container_type_icon(container_type) ⇒ Object



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

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

#friendly_shipment_status(shipment) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'app/helpers/crm/shipments_helper.rb', line 123

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


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

def shipment_audit_link(shipment)
  return unless shipment.present?
  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



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/crm/shipments_helper.rb', line 64

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))
	   unless shipment.delivery&.incorrectly_packaged_ups_canada_order
				links << d.link_to('Delete', shipment_path(shipment, return_path: return_path), data: { turbo_confirm: 'Are you sure?', turbo_method: :delete })
	   end
    end
  if shipment.ship_label_pdf
	  links << d.link_to('View Ship Label', upload_path(shipment.ship_label_pdf))
    end
    if shipment.bol_pdf
		links << d.link_to('View Bill of Lading', upload_path(shipment.bol_pdf))
	end
	if shipment.manifest.present? and shipment.manifest.manifest_pdf.present?
		links << d.link_to('Manifest', upload_path(shipment.manifest.manifest_pdf))
	end
  if shipment.ship_label_pdf(letter_format=true)
	  links << d.link_to('Letter Format Label', upload_path(shipment.ship_label_pdf(letter_format=true)))
  end
    unless shipment.suggested? || shipment.delivery.nil?
      links << d.link_to('Carton/UCC-128 Label', carton_label_shipment_path(shipment.id, format: :pdf))
    end
    #links << :separator
    #links += available_events_links(shipment, { return_path: return_path })
  end
  links
end

#shipment_container_type_for_select_with_iconsObject



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

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



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

def shipment_container_type_label(shipment)
  return unless shipment.present?
  fa_icon(container_type_icon(shipment.container_type), text: shipment.container_type&.titleize)
end

#shipment_contents_drop_down(shipment, main_link_class: nil) ⇒ Object



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

def shipment_contents_drop_down(shipment, main_link_class: nil)
  return unless shipment.present?
  label = shipment.shipment_contents.sum(:quantity)
  if label.zero?
    if shipment.child_shipments.present?
      return fa_icon('layer-plus', class: 'btn', title: 'Parent Shipment, see cartons for contents')
    else
      return 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



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

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

#uploads_for_shipment(shipment) ⇒ Object



35
36
37
38
39
# File 'app/helpers/crm/shipments_helper.rb', line 35

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



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

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
  if links.size > 1
    return render_simple_drop_down links
  else
    return nil
  end
end