Class: Admin::OverviewController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/overview_controller.rb

Overview

this clas was inspired (heavily) from the mephisto admin architecture

Instance Method Summary collapse

Instance Method Details

#get_report_dataObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/admin/overview_controller.rb', line 28

def get_report_data
  opts = case params[:name]
    when "7_days" then {:from => (Time.new().to_date - 1.week).to_s(:db)}
    when "14_days" then {:from => (Time.new().to_date - 2.week).to_s(:db)}
    when "this_month" then {:from => Date.new(Time.now.year, Time.now.month, 1).to_s(:db), :to => Date.new(Time.now.year, Time.now.month, -1).to_s(:db)}
    when "last_month" then {:from => (Date.new(Time.now.year, Time.now.month, 1) - 1.month).to_s(:db), :to => (Date.new(Time.now.year, Time.now.month, -1) - 1.month).to_s(:db)}
    when "this_year" then {:from => Date.new(Time.now.year, 1, 1).to_s(:db)}
    when "last_year" then {:from => Date.new(Time.now.year - 1, 1, 1).to_s(:db), :to => Date.new(Time.now.year - 1, 12, -1).to_s(:db)}
  end

  case params[:report]
    when "orders_by_day"
      opts[:value] = params[:value]

      render :js => "[[" + orders_by_day(opts).map { |day| "['#{day[0]}',#{day[1]}]" }.join(",") + "]]"
    when "orders_totals"
      render :js => [:orders_total => orders_total(opts).to_i, :orders_line_total => orders_line_total(opts).to_i,
        :orders_adjustment_total => orders_adjustment_total(opts).to_i, :orders_credit_total => orders_credit_total(opts).to_i ].to_json
  end
end

#indexObject

todo, add rss feed of information that is happening



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/admin/overview_controller.rb', line 7

def index
  @show_dashboard = show_dashboard
  return unless @show_dashboard

  p = {:from => (Time.new().to_date  - 1.week).to_s(:db), :value => "Count"}
  @orders_by_day = orders_by_day(p)
  @orders_line_total = orders_line_total(p)
  @orders_total = orders_total(p)
  @orders_adjustment_total = orders_adjustment_total(p)
  @orders_credit_total = orders_credit_total(p)

  @best_selling_variants = best_selling_variants
  @top_grossing_variants = top_grossing_variants
  @last_five_orders = last_five_orders
  @biggest_spenders = biggest_spenders
  @out_of_stock_products = out_of_stock_products
  @best_selling_taxons = best_selling_taxons

  @pie_colors = [ "#0093DA", "#FF3500", "#92DB00", "#1AB3FF", "#FFB800"]
end