Class: Tienda::DashboardController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tienda/dashboard_controller.rb

Instance Method Summary collapse

Instance Method Details

#homeObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/tienda/dashboard_controller.rb', line 6

def home
  @last_30_days_orders = {}
  end_date = Date.today
  start_date = end_date - 30.days
  last_30_days_orders = Tienda::Order.received.group('DATE(created_at)').where(created_at: start_date..end_date).count
  (start_date..end_date).each do |day|
    @last_30_days_orders[day] = last_30_days_orders[day] || 0
  end
  @sales_by_category = Tienda::Order.received.joins(products: [:product_category]).where(created_at: start_date..end_date).group('tienda_product_categories.name').count
  @users_count = Tienda::User.count
end