add top10 and bottom10 products in dashboard
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h4><i class="material-icons md-24">dashboard</i><%= (t :top) + " " + (t :products) %></h4>
|
||||
@@ -67,6 +67,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h4><i class="material-icons md-24">dashboard</i><%= (t :bottom) + " " + (t :products) %></h4>
|
||||
<!-- <canvas id="top_products" class="col-md-12"></canvas> -->
|
||||
<%= pie_chart @bottom_products %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||
|
||||
@@ -68,6 +68,7 @@ en:
|
||||
booking_details: "Booking Details"
|
||||
inventory_definitions: "Inventory Definitions"
|
||||
sale_audits: "Sale Audits"
|
||||
bottom: "Bottom"
|
||||
|
||||
views:
|
||||
btn:
|
||||
|
||||
Reference in New Issue
Block a user