Module: Crm::OrderDashboardHelper

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

Instance Method Summary collapse

Instance Method Details

#get_orders_from_selectionsObject



58
59
60
61
62
63
64
# File 'app/helpers/crm/order_dashboard_helper.rb', line 58

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

#order_dashboard_tab_optionsObject



2
3
4
5
6
7
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
# File 'app/helpers/crm/order_dashboard_helper.rb', line 2

def order_dashboard_tab_options
  hsh = {}
  params_hash = {company_id: @company_id, report_grouping: @report_grouping, sales_rep_id: @sales_rep_id, sort_by: @sort_by, sort_direction: @sort_direction}
  orders_need_attention_counter = get_orders_from_selections.all_awaiting_deliveries.with_associations.joins(:deliveries).where("deliveries.state = 'quoting'").count
  if orders_need_attention_counter > 0
    hsh[:orders_need_attention] = { counter: orders_need_attention_counter, remote_href: order_dashboard_tab_orders_need_attention_path(params_hash) }
  end
  dropship_orders_need_attention_counter = get_orders_from_selections.all_awaiting_deliveries.with_associations.joins(:deliveries).where("deliveries.state = 'awaiting_po_fulfillment' OR deliveries.state = 'processing_po_fulfillment'").count
  if dropship_orders_need_attention_counter > 0
    hsh[:dropship_orders_need_attention] = { counter: dropship_orders_need_attention_counter, remote_href: order_dashboard_tab_dropship_orders_need_attention_path(params_hash) }
  end
  pending_counter = get_orders_from_selections.pending.count
  if pending_counter > 0
    hsh[:pending] = { counter: pending_counter, remote_href: order_dashboard_tab_pending_path(params_hash) }
  end
  profit_review_counter = get_orders_from_selections.profit_review.count
  if profit_review_counter > 0
    hsh[:profit_review] = { counter: profit_review_counter, remote_href: order_dashboard_tab_profit_review_path(params_hash) }
  end
  in_cr_hold_counter = get_orders_from_selections.held.count
  if in_cr_hold_counter > 0
    hsh[:in_cr_hold] = { counter: in_cr_hold_counter, remote_href: order_dashboard_tab_in_cr_hold_path(params_hash) }
  end
  back_order_counter = get_orders_from_selections.back_order.count
  if back_order_counter > 0
    hsh[:back_order] = { counter: back_order_counter, remote_href: order_dashboard_tab_back_order_path(params_hash) }
  end
  pending_release_authorization_counter = get_orders_from_selections.in_state(:pending_release_authorization).count
  if pending_release_authorization_counter > 0
    hsh[:pending_release_authorization] = { counter: pending_release_authorization_counter, remote_href: order_dashboard_tab_pending_release_authorization_path(params_hash) }
  end
  pending_payment_counter = get_orders_from_selections.in_state(:pending_payment).count
  if pending_payment_counter > 0
    hsh[:pending_payment] = { counter: pending_payment_counter, remote_href: order_dashboard_tab_pending_payment_path(params_hash) }
  end
  pre_pack_counter = get_orders_from_selections.in_state(:pre_pack).count
  if pre_pack_counter > 0
    hsh[:pre_pack] = { counter: pre_pack_counter, remote_href: order_dashboard_tab_pre_pack_path(params_hash) }
  end
  awaiting_carrier_assignment_counter = get_orders_from_selections.in_state(:awaiting_carrier_assignment).count
  if awaiting_carrier_assignment_counter > 0
    hsh[:awaiting_carrier_assignment] = { counter: awaiting_carrier_assignment_counter, remote_href: order_dashboard_tab_awaiting_carrier_assignment_path(params_hash) }
  end
  if @report_grouping == "Amazon"
    awaiting_deliveries_counter = get_orders_from_selections.in_state(:awaiting_deliveries).count
    if awaiting_deliveries_counter > 0
      hsh[:awaiting_deliveries] = { counter: awaiting_deliveries_counter, remote_href: order_dashboard_tab_awaiting_deliveries_path(params_hash) }
    end
  end
  future_release_counter = get_orders_from_selections.future_release.count
  if future_release_counter > 0
    hsh[:future_release] = { counter: future_release_counter, remote_href: order_dashboard_tab_future_release_path(params_hash) }
  end
  hsh
end


72
73
74
75
# File 'app/helpers/crm/order_dashboard_helper.rb', line 72

def sort_column_link(sort_by, sort_by_name=nil)
  sort_by_name ||= sort_by.to_s.split(".").last.humanize.titleize
  link_to("#{sort_by_name} #{params[:sort_by] == sort_by ? (params[:sort_direction] == 'ASC' ? fa_icon('chevron-up') : fa_icon('chevron-down')) : nil}".html_safe, order_dashboard_path(params.merge(sort_by: sort_by, sort_direction: ((params[:sort_by] == sort_by && params[:sort_direction] == 'DESC') ? "ASC" : "DESC"))))
end

#stock_status_label(order) ⇒ Object



66
67
68
69
70
# File 'app/helpers/crm/order_dashboard_helper.rb', line 66

def stock_status_label(order)
  s = order.stock_status
  style = (s == :ok) ? 'success' : 'warning'
  (:span, s, class: "badge bg-#{style}", style: 'font-size: 1em')
end