diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d8592664..bc621bd7 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -68,6 +68,7 @@ class HomeController < ApplicationController @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @top_products = Sale.top_products(today).sum('i.qty') + @bottom_products = Sale.bottom_products(today).sum('i.qty') @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) diff --git a/app/models/sale.rb b/app/models/sale.rb index ef00fb6a..7e68e771 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -907,7 +907,17 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(5) + .order("SUM(i.qty) DESC").limit(10) + end + + def self.bottom_products(today) + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + "and payment_status='paid' and sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(10) end def self.hourly_sales(today) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 2de6f67d..bf4321be 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -58,7 +58,7 @@
-
+

dashboard<%= (t :top) + " " + (t :products) %>

@@ -67,6 +67,15 @@
+
+
+
+

dashboard<%= (t :bottom) + " " + (t :products) %>

+ + <%= pie_chart @bottom_products %> +
+
+