add top10 and bottom10 products in dashboard

This commit is contained in:
phyusin
2017-11-17 10:22:04 +06:30
parent e5831f92f9
commit f333aa9a66
4 changed files with 23 additions and 2 deletions

View File

@@ -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)