Class: Crm::OrderDashboardController

Inherits:
CrmController show all
Includes:
Controllers::RequireTurboFrame
Defined in:
app/controllers/crm/order_dashboard_controller.rb

Overview

Controller: order dashboard.

Constant Summary collapse

TAB_ACTIONS =

Tab fragments never render standalone — non-frame hits redirect to the
dashboard with the tab preselected.

%i[tab_pending tab_profit_review tab_in_cr_hold tab_back_order tab_pending_release_authorization tab_pending_payment tab_future_release tab_pre_pack tab_awaiting_carrier_assignment tab_awaiting_deliveries tab_orders_need_attention tab_dropship_orders_need_attention].freeze

Constants included from Controllers::ReferenceFindable

Controllers::ReferenceFindable::ID_EMBEDDED_PATTERNS

Constants included from Controllers::AnalyticsEvents

Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY

Constants included from Controllers::ErrorRendering

Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES

Instance Method Summary collapse

Methods included from Controllers::RequireTurboFrame

require_in_pane_tab_frames, require_turbo_frame

Methods inherited from CrmController

#access_denied, #context_id, #context_object, #crm_home_path, #current_ability, #default_url_options, #download_temp, #get_tempfile_path_for_download, #init_status_job_collector, #initialize_crm_lazy_chunks, #persist_enqueued_status_jobs, #record_not_found, #redirect_to_job_or_fallback, #render_edit_action, #set_context, #set_download_path, #stash_file_for_temp_download, #sync_admin_presence_cookie, #touch_employee_last_seen

Methods inherited from ApplicationController

#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #set_report_errors_for, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y

Methods included from Controllers::ReturnPathHandling

#check_for_return_path, #redirect_to_return_path_or_default

Methods included from Controllers::AnalyticsEvents

#consume_queued_analytics_events, #registration_lead_type, #track_event

Methods included from Controllers::DeviceDetection

#device_detector, #is_ie?

Methods included from Controllers::SubdomainDetection

#is_crm_request?, #is_www_request?, #json_request?

Methods included from Controllers::TurboSafeRedirect

#redirect_to

Methods included from Controllers::TrackingDetection

#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?

Methods included from Controllers::AcceleratedFileSending

#send_file_accelerated, #send_upload_accelerated

Methods included from Controllers::ErrorRendering

#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback

Methods included from Controllers::TurnstileVerification

#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!

Methods included from Controllers::CloudflareCaching

edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session

Methods included from Controllers::Webpackable

#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?

Methods included from Controllers::Localizable

#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale

Methods included from Controllers::Authenticable

#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak

Methods included from UrlsHelper

#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?

Instance Method Details

#do_import_vc_orders_from_csvvoid

This method returns an undefined value.

Creates Amazon VC procurement orders from an uploaded CSV, flashing
per-row errors and info messages before redirecting to the Amazon tab.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/controllers/crm/order_dashboard_controller.rb', line 139

def do_import_vc_orders_from_csv
  imported_vc_orders_csv = params.dig(:upload, :imported_vc_orders_csv)
  res = Order::CreateVcProcurementOrdersFromCsv.new({ csv_attachment: imported_vc_orders_csv, user: current_user }).process
  if res.errors.any?
    flash[:error] = view_context.tag.ul do
      view_context.safe_join(res.errors.map { |msg| view_context.tag.li(msg) })
    end
  end

  flash[:info] = "#{res.orders.size} orders created.".html_safe + view_context.tag.ul do
    view_context.safe_join(res.info_msgs.map { |msg| view_context.tag.li(msg) })
  end
  redirect_to order_dashboard_path(report_grouping: 'Amazon')
end

#get_orders_from_selectionsActiveRecord::Relation

Base order scope for the dashboard, filtered by the selections loaded
in #set_variables.

Returns:

  • (ActiveRecord::Relation)

    orders matching the current filters



173
174
175
176
177
178
179
# File 'app/controllers/crm/order_dashboard_controller.rb', line 173

def get_orders_from_selections
  orders = Order.by_report_grouping_all_when_nil(@report_grouping)
  orders = orders.by_company_id(@company_id.to_i) if @company_id.present?
  orders = orders.by_primary_rep_id(@sales_rep_id.to_i) if @sales_rep_id.present?
  orders = orders.order("#{@sort_by} #{@sort_direction}") if @sort_by.present? && @sort_direction.present?
  orders
end

#import_vc_orders_from_csvvoid

This method returns an undefined value.

Renders the Amazon VC procurement order CSV upload form.



133
# File 'app/controllers/crm/order_dashboard_controller.rb', line 133

def import_vc_orders_from_csv; end

#indexvoid

This method returns an undefined value.

Renders the dashboard shell with the default (unfiltered) order selection.



16
17
18
# File 'app/controllers/crm/order_dashboard_controller.rb', line 16

def index
  @orders = get_orders_from_selections
end

#set_variablesvoid

This method returns an undefined value.

Loads the filter/sort selections shared by every dashboard tab from
params (company, report grouping, sales rep, sort column/direction).



158
159
160
161
162
163
164
165
166
167
# File 'app/controllers/crm/order_dashboard_controller.rb', line 158

def set_variables
  @company_id = params[:company_id]
  @report_groupings = SalesGoal.channels_for_select
  @report_grouping = params[:report_grouping]
  @sales_rep_options = Employee.sales_rep_options_for_select
  @sales_rep_id = params[:sales_rep_id]
  @sales_rep_name = Employee.find(@sales_rep_id.to_i)&.full_name if @sales_rep_id.present?
  @sort_by = params[:sort_by] if params[:sort_by].present? && ['orders.id', 'parties.full_name', 'orders.line_total', 'orders.future_release_date', 'orders.updated_at', 'orders.created_at'].include?(params[:sort_by])
  @sort_direction = params[:sort_direction] if params[:sort_direction].present? && %w[DESC ASC].include?(params[:sort_direction])
end

#tab_awaiting_carrier_assignmentvoid

This method returns an undefined value.

Tab: orders awaiting carrier assignment.



95
96
97
98
99
# File 'app/controllers/crm/order_dashboard_controller.rb', line 95

def tab_awaiting_carrier_assignment
  @orders = get_orders_from_selections.in_state(:awaiting_carrier_assignment)
  @tab_frame_id = 'awaiting_carrier_assignment'
  render 'tab_orders', layout: should_render_layout?
end

#tab_awaiting_deliveriesvoid

This method returns an undefined value.

Tab: orders awaiting deliveries.



104
105
106
107
108
# File 'app/controllers/crm/order_dashboard_controller.rb', line 104

def tab_awaiting_deliveries
  @orders = get_orders_from_selections.in_state(:awaiting_deliveries)
  @tab_frame_id = 'awaiting_deliveries'
  render 'tab_orders', layout: should_render_layout?
end

#tab_back_ordervoid

This method returns an undefined value.

Tab: back-ordered orders.



50
51
52
53
54
# File 'app/controllers/crm/order_dashboard_controller.rb', line 50

def tab_back_order
  @orders = get_orders_from_selections.back_order
  @tab_frame_id = 'back_order'
  render 'tab_orders', layout: should_render_layout?
end

#tab_dropship_orders_need_attentionvoid

This method returns an undefined value.

Tab: dropship orders whose deliveries need attention (awaiting/processing
PO fulfillment).



124
125
126
127
128
# File 'app/controllers/crm/order_dashboard_controller.rb', line 124

def tab_dropship_orders_need_attention
  @orders = get_orders_from_selections.all_awaiting_deliveries.with_associations.joins(:deliveries).where("deliveries.state = 'awaiting_po_fulfillment' OR deliveries.state = 'processing_po_fulfillment'")
  @tab_frame_id = 'dropship_orders_need_attention'
  render 'tab_orders', layout: should_render_layout?
end

#tab_future_releasevoid

This method returns an undefined value.

Tab: orders with a future release date.



77
78
79
80
81
# File 'app/controllers/crm/order_dashboard_controller.rb', line 77

def tab_future_release
  @orders = get_orders_from_selections.future_release
  @tab_frame_id = 'future_release'
  render 'tab_future_orders', layout: should_render_layout?
end

#tab_in_cr_holdvoid

This method returns an undefined value.

Tab: orders held on a credit review.



41
42
43
44
45
# File 'app/controllers/crm/order_dashboard_controller.rb', line 41

def tab_in_cr_hold
  @orders = get_orders_from_selections.held
  @tab_frame_id = 'in_cr_hold'
  render 'tab_orders', layout: should_render_layout?
end

#tab_orders_need_attentionvoid

This method returns an undefined value.

Tab: orders whose deliveries need attention (quoting or awaiting/processing
PO fulfillment).



114
115
116
117
118
# File 'app/controllers/crm/order_dashboard_controller.rb', line 114

def tab_orders_need_attention
  @orders = get_orders_from_selections.all_awaiting_deliveries.with_associations.joins(:deliveries).where("deliveries.state = 'quoting' OR deliveries.state = 'awaiting_po_fulfillment' OR deliveries.state = 'processing_po_fulfillment'")
  @tab_frame_id = 'orders_need_attention'
  render 'tab_orders', layout: should_render_layout?
end

#tab_pendingvoid

This method returns an undefined value.

Tab: orders awaiting release (pending scope).



23
24
25
26
27
# File 'app/controllers/crm/order_dashboard_controller.rb', line 23

def tab_pending
  @orders = get_orders_from_selections.pending
  @tab_frame_id = 'pending'
  render 'tab_orders', layout: should_render_layout?
end

#tab_pending_paymentvoid

This method returns an undefined value.

Tab: orders awaiting payment.



68
69
70
71
72
# File 'app/controllers/crm/order_dashboard_controller.rb', line 68

def tab_pending_payment
  @orders = get_orders_from_selections.in_state(:pending_payment)
  @tab_frame_id = 'pending_payment'
  render 'tab_orders', layout: should_render_layout?
end

#tab_pending_release_authorizationvoid

This method returns an undefined value.

Tab: orders awaiting release authorization.



59
60
61
62
63
# File 'app/controllers/crm/order_dashboard_controller.rb', line 59

def tab_pending_release_authorization
  @orders = get_orders_from_selections.in_state(:pending_release_authorization)
  @tab_frame_id = 'pending_release_authorization'
  render 'tab_orders', layout: should_render_layout?
end

#tab_pre_packvoid

This method returns an undefined value.

Tab: orders in the pre-pack state.



86
87
88
89
90
# File 'app/controllers/crm/order_dashboard_controller.rb', line 86

def tab_pre_pack
  @orders = get_orders_from_selections.in_state(:pre_pack)
  @tab_frame_id = 'pre_pack'
  render 'tab_orders', layout: should_render_layout?
end

#tab_profit_reviewvoid

This method returns an undefined value.

Tab: orders flagged for profit review.



32
33
34
35
36
# File 'app/controllers/crm/order_dashboard_controller.rb', line 32

def tab_profit_review
  @orders = get_orders_from_selections.profit_review
  @tab_frame_id = 'profit_review'
  render 'tab_orders', layout: should_render_layout?
end