dashboard update

This commit is contained in:
phyusin
2018-03-23 18:06:53 +06:30
parent 3e8c3f8225
commit e0fe0ee8ab
5 changed files with 70 additions and 15 deletions

View File

@@ -80,14 +80,21 @@ class HomeController < ApplicationController
end
def dashboard
@from, @to = get_date_range_from_params
@from, @to, @from_time, @to_time = get_date_range_from_params
@shop = Shop.first
today = DateTime.now.strftime('%Y-%m-%d')
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
if !@from.nil? && !@to.nil?
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
else
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
end
if !@from.nil? && !@to.nil?
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
else
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
end
@top_products = Sale.top_products(today,@from,@to).sum('i.qty')
@bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty')
@hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total)
@@ -190,7 +197,9 @@ class HomeController < ApplicationController
def get_date_range_from_params
from = params[:from]
to = params[:to]
to = params[:to]
from_time = params[:from_time]
to_time = params[:to_time]
if from.present? && to.present?
f_date = DateTime.parse(from)
@@ -201,7 +210,7 @@ class HomeController < ApplicationController
to = t_time.end_of_day.utc.getlocal
end
return from, to
return from, to, from_time, to_time
end
#Shop Name in Navbor