Class: Crm::WarehousePresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/crm/warehouse_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from Crm::BasePresenter

Instance Method Details

#current_shipping_document_print_profile_for_storeObject



203
204
205
# File 'app/presenters/crm/warehouse_presenter.rb', line 203

def current_shipping_document_print_profile_for_store
  store.current_shipping_document_print_profile
end

#current_shipping_document_print_profile_for_userObject



199
200
201
# File 'app/presenters/crm/warehouse_presenter.rb', line 199

def current_shipping_document_print_profile_for_user
  store.current_shipping_document_print_profile(h.current_user.employee_record.id)
end

#current_shipping_label_print_profileObject



207
208
209
# File 'app/presenters/crm/warehouse_presenter.rb', line 207

def current_shipping_label_print_profile
  store.current_shipping_label_print_profile(h.current_user.employee_record.id)
end

#cycle_count_open_counterObject



101
102
103
# File 'app/presenters/crm/warehouse_presenter.rb', line 101

def cycle_count_open_counter
  store.cycle_counts.where(state: 'draft').size
end

#delivery_select_ship_or_voidObject



105
106
107
108
109
110
# File 'app/presenters/crm/warehouse_presenter.rb', line 105

def delivery_select_ship_or_void
  deliveries = Delivery.joins(:order).includes(:destination_address, :origin_address, :shipping_option, { order: { customer: { catalog: :store } } },
                                               { shipments: :manifest }).where(state: %w[pending_ship_labels pending_ship_confirm]).order(Order[:reference_number])
  deliveries = deliveries.select { |d| d.valid_for_generating_ship_labels? || d.valid_for_voiding_ship_labels? }
  deliveries.map { |d| ["#{d.order.reference_number} - #{d.state}", d.order.reference_number] }
end


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'app/presenters/crm/warehouse_presenter.rb', line 177

def print_profiles_info
  links = []
  links << :separator
  links << if (p = current_shipping_document_print_profile)
             h.link_to("Default Warehouse Documents: #{p.name}", h.printer_path(p.printer_id, return_path: h.warehouse_path(store)), class: 'dropdown-item')
           else
             h.link_to('Default Documents Printer Not Set', h.printers_path, class: 'dropdown-item')
           end
  links << if (p = current_shipping_document_print_profile_for_user)
             h.link_to("User Documents: #{p.name}", h.printer_path(p.printer_id, return_path: h.warehouse_path(store)), class: 'dropdown-item')
           else
             h.link_to('User Documents Printer Not Set', h.printers_path, class: 'dropdown-item')
           end
  links << if (p = current_shipping_label_print_profile)
             h.link_to("Labels: #{p.name}", h.printer_path(p.printer_id, return_path: h.warehouse_path(store)), class: 'dropdown-item')
           else
             h.link_to('Labels Printer Not Set', h.printers_path, class: 'dropdown-item')
           end
  links << h.link_to('Manage Printers', h.printers_path, class: 'dropdown-item')
  links
end


165
166
167
# File 'app/presenters/crm/warehouse_presenter.rb', line 165

def show_speedee_manifest_browser_link
  supported_carrier?('SpeedeeDelivery')
end


169
170
171
# File 'app/presenters/crm/warehouse_presenter.rb', line 169

def show_speedee_manifest_link
  supported_carrier?('SpeedeeDelivery') && Delivery.with_shipment_carrier('SpeedeeDelivery').exists?(state: ['pending_manifest_completion'])
end


173
174
175
# File 'app/presenters/crm/warehouse_presenter.rb', line 173

def show_speedee_summary_link
  supported_carrier?('SpeedeeDelivery') && Delivery.with_shipment_carrier('SpeedeeDelivery').exists?(state: ['pending_ship_confirm'])
end

#supported_carrier?(carrier_name) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
# File 'app/presenters/crm/warehouse_presenter.rb', line 161

def supported_carrier?(carrier_name)
  SUPPORTED_SHIPPING_CARRIERS[store.country_iso3.to_sym]&.include?(carrier_name)
end


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/presenters/crm/warehouse_presenter.rb', line 112

def warehouse_command_links
  links = []
  links += warehouse_switch_links
  links << :separator
  links << h.link_to('View Inventory', h.inventory_stores_path, class: 'dropdown-item')
  links << h.link_to('Tech Bench', h.tech_bench_dashboard_path(store_id: store.id), class: 'dropdown-item')
  cycle_count_label = 'Cycle Counts '.html_safe
  cycle_count_label << h.tag.span(cycle_count_open_counter, class: 'badge rounded-pill bg-info') if cycle_count_open_counter.positive?
  links << h.link_to(cycle_count_label, h.cycle_counts_path, class: 'dropdown-item')

  if (serial_numbers_counter = store.query_serial_numbers_pending_print.size).positive?
    links << h.link_to('Serial Numbers to Print '.html_safe + h.tag.span(serial_numbers_counter, class: 'badge rounded-pill bg-info'), h.serial_numbers_warehouse_path(store), class: 'dropdown-item')
  end

  (Store::CARRIERS_FOR_MASS_SHIP_CONFIRM[store.name] || []).each_with_index do |carrier, index|
    links << :separator if index.zero?

    counter = store.mass_ship_confirm_counter(carrier)
    next unless counter.positive?

    mass_ship_confirm_label = "End of Day ship confirm for #{carrier} ".html_safe
    mass_ship_confirm_label << h.tag.span(counter, class: 'badge rounded-pill bg-info')
    links << h.link_to(mass_ship_confirm_label, h.mass_ship_confirm_warehouse_path(store, mass_ship_confirm_for_carrier: carrier), class: 'dropdown-item')
  end

  links << :separator

  if show_speedee_manifest_link || show_speedee_summary_link
    if show_speedee_manifest_link
      links << h.link_to('Speedee Delivery End of Day Close and transmit Manifest', h.speedee_delivery_close_warehouse_path(store), class: 'dropdown-item',
                                                                                    data: { turbo_method: :post, turbo_confirm: 'Are you sure? This will close all current Speedee Delivery shipments and mark them as pending ship confirm.' })
    end
    # links << h.link_to("Speedee Delivery End of Day Driver Summary", h.speedee_delivery_summary_pdf_warehouse_path(store), class: 'dropdown-item')
    links << h.link_to('Speedee Delivery End of Day Driver Summary', h.speedee_summary_warehouse_path(store, format: 'pdf'), class: 'dropdown-item', target: '_blank', rel: 'noopener') if show_speedee_summary_link
  end

  links << h.link_to('Speedee Delivery Manifest Browser', h.speedee_manifests_path, class: 'dropdown-item') if show_speedee_manifest_browser_link

  links << :separator

  links << h.link_to('Manage Storage Locations', h.store_storage_locations_path(store), class: 'dropdown-item')

  links << h.link_to('Manage Warehouse Packages', h.store_warehouse_packages_path(store), class: 'dropdown-item')

  links += print_profiles_info

  links
end


90
91
92
93
94
95
96
97
98
99
# File 'app/presenters/crm/warehouse_presenter.rb', line 90

def warehouse_switch_links
  links = ["#{fa_icon('warehouse')} #{store.short_name}"]
  # Only show stores with id 1 or 2, or stores where warmlyyours_warehouse? returns true
  allowed_stores = Store.where.not(id: store.id)
                        .where('id IN (?) OR owner = ?', [Store::WARMLYYOURS_US_ID, Store::WARMLYYOURS_CA_ID], 'warmlyyours')
  allowed_stores.each do |s|
    links << h.link_to("Switch to #{s.name}", h.warehouse_path(s), class: 'dropdown-item')
  end
  links
end

#warehouse_tab_optionsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/presenters/crm/warehouse_presenter.rb', line 8

def warehouse_tab_options
  hsh = {}

  unsorted_groups = store.query_warehouse_deliveries_grouped_counters
  sorted_groups = unsorted_groups.sort_by { |(state, _counter)| warehouse_tab_sort_list.index(state) || 10 }

  sorted_groups.each do |state, counter|
    hsh[state.to_sym] = { counter:, remote_href: h.public_send("tab_#{state}_warehouse_path", store) }
  end
  if (orders_need_attention_counter = store.query_warehouse_orders_need_attention.size).positive?
    hsh[:orders_need_attention] = { counter: orders_need_attention_counter, remote_href: h.tab_orders_need_attention_warehouse_path(store) }
  end
  if (awaiting_carrier_assignment_orders_counter = store.query_awaiting_carrier_assignment_orders.size).positive?
    hsh[:awaiting_carrier_assignment] = { counter: awaiting_carrier_assignment_orders_counter, remote_href: h.tab_awaiting_carrier_assignment_orders_warehouse_path(store) }
  end
  if (held_orders_counter = store.query_warehouse_held_orders.size).positive?
    hsh[:held_orders] = { counter: held_orders_counter, remote_href: h.tab_held_orders_warehouse_path(store) }
  end
  if (back_orders_counter = store.query_warehouse_back_orders.size).positive?
    hsh[:back_orders] = { counter: back_orders_counter, remote_href: h.tab_back_orders_warehouse_path(store) }
  end
  if (recently_shipped_counter = store.query_recently_shipped.size).positive?
    hsh[:shipped_invoiced] = { title: 'Fulfilled today',
                               counter: recently_shipped_counter,
                               remote_href: h.tab_shipped_invoiced_warehouse_path(store) }
  end
  if (amazon_orders_counter = store.query_warehouse_amazon_orders.size).positive?
    hsh[:amazon_items] = { counter: amazon_orders_counter,
                           remote_href: h.tab_amazon_items_warehouse_path(store) }
  end

  hsh[:po_inbound] = {
    counter: store.query_warehouse_purchase_orders_shipped.size,
    remote_href: h.search_and_show_searches_path(
      type: 'PurchaseOrderSearch',
      query_params: { state_in: %w[shipped pending_fulfillment partially_receipted], store_id_in: [store.id] },
      sort_columns: ['promised_delivery_date asc'],
      selected_columns: %i[purchase_order_link state items_report_link supplier_link carrier_full_name promised_delivery_date order_date total_weight item_count],
      links: {},
      target_id: 'po_inbound'
    )
  }

  hsh[:backordered_items] = {
    counter: Query::StoreItemQuery.new.out_of_stock_items_on_backorders_count(store.id),
    remote_href: h.tab_backordered_items_warehouse_path(store)
  }

  hsh[:serial_numbers] = {
    counter: store.query_serial_numbers_pending_print.size,
    remote_href: h.tab_serial_numbers_warehouse_path(store)
  }

  hsh[:rmas_pending_to_receive_today] = {
    counter: Rma.joins(:return_shipments)
                .where('shipments.estimated_delivery_date = ?', Date.today)
                .where('shipments.tracking_state in (?)', %w[in_transit delivered exception delivery_attempt delivered_to_collection_location])
                .where(company_id: store.id).select('rmas.*,shipments.estimated_delivery_date,shipments.tracking_state').uniq.size,
    remote_href: h.tab_rmas_pending_to_receive_today_warehouse_path(store)
  }

  if (items_need_packaging_review_counter = Item.active.where('review_product_weight_flag IS true OR review_product_packaging_flag IS true').size).positive?
    hsh[:items_need_packaging_review] = {
      counter: items_need_packaging_review_counter,
      remote_href: h.tab_items_need_packaging_review_warehouse_path(store)
    }
  end

  if (store_items_in_restock_counter = Query::StoreItemQuery.new.restock_items_query(store.id).size).positive?
    hsh[:items_need_restock] = {
      counter: store_items_in_restock_counter,
      remote_href: h.tab_items_need_restock_warehouse_path(store)
    }
  end

  hsh
end

#warehouse_tab_sort_listObject



86
87
88
# File 'app/presenters/crm/warehouse_presenter.rb', line 86

def warehouse_tab_sort_list
  %w[at_warehouse picking pending_ship_labels pending_ship_label_review pending_pickup_confirm pending_ship_confirm future_release pre_pack]
end

#warehouse_tabsObject



4
5
6
# File 'app/presenters/crm/warehouse_presenter.rb', line 4

def warehouse_tabs
  h.tab_panel(warehouse_tab_options)
end