diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index ee54bd46..c4ca54b6 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -65,7 +65,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) - @hourly_sales = Sale.hourly_sales(today) + @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) @employee_sales = Sale.employee_sales(today).sum(:grand_total) diff --git a/app/models/sale.rb b/app/models/sale.rb index c3b9cb5a..87ff1fe7 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -854,7 +854,9 @@ end end def self.hourly_sales(today) - query= Sale.select("grand_total").where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + query= Sale.select("grand_total") + .where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .group("date_format(receipt_date, '%I %p')") end def self.employee_sales(today)