reduce query in dashboard

This commit is contained in:
phyusin
2018-06-18 10:29:30 +06:30
parent 86b83125e6
commit b9a8912f01
5 changed files with 141 additions and 284 deletions

View File

@@ -3,26 +3,7 @@ class Origami::DashboardController < BaseOrigamiController
def index
@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()
# @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)
# @employee_sales = Sale.employee_sales(today)
# .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
# @inventories = StockJournal.inventory_balances(today).sum(:balance)
# @total_sale = Sale.total_sale(today,current_user)
# @total_count = Sale.total_count(today,current_user)
# @total_card = Sale.total_card_sale(today,current_user)
# @total_credit = Sale.credit_payment(today,current_user)
@sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(today,current_user)
if !@total_payment_methods.nil?
@@ -39,11 +20,8 @@ class Origami::DashboardController < BaseOrigamiController
@sale_data = nil
end
@summ_sale = Sale.summary_sale_receipt(today,current_user)
@total_customer = Sale.total_customer(today,current_user)
@total_dinein = Sale.total_dinein(today,current_user)
@total_takeaway = Sale.total_takeaway(today,current_user)
@total_other_customer = Sale.total_other_customer(today,current_user)
@total_membership = Sale.total_membership(today,current_user)
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time)
# @total_other_customer = Sale.total_other_customer(today,current_user)
@total_order = Sale.total_order(today,current_user)
@total_accounts = Sale.total_account(today,current_user)