Files
sx-fc/app/controllers/origami/dashboard_controller.rb
2018-06-18 10:39:52 +06:30

100 lines
4.0 KiB
Ruby

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)
@display_type = Lookup.find_by_lookup_type("display_type")
@sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(today,current_user)
if !@total_payment_methods.nil?
@total_payment_methods.each do |payment|
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay"
pay = Sale.payment_sale('card', today, current_user)
@sale_data.push({'card' => pay.payment_amount})
else
pay = Sale.payment_sale(payment.payment_method, today, current_user)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
end
else
@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_order = Sale.total_order(today,current_user)
@total_accounts = Sale.total_account(today,current_user)
@account_data = Array.new
if !@total_accounts.nil?
@total_accounts.each do |account|
acc = Sale.account_data(account.account_id, today,current_user)
if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
end
else
@account_data = nil
end
@top_items = Sale.top_items(today,current_user)
@total_foc_items = Sale.total_foc_items(today,current_user)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@current_user = current_user
#dine-in cashier
dinein_cashier = Lookup.collection_of('dinein_cashier')
@dinein_cashier = 0
if !dinein_cashier[0].nil?
@dinein_cashier = dinein_cashier[0][1]
end
#quick service
quick_service = Lookup.collection_of('quick_service')
@quick_service = 0
if !quick_service[0].nil?
@quick_service = quick_service[0][1]
end
#order reservation
order_reservation = Lookup.collection_of('order_reservation')
@order_reservation = 0
if !order_reservation.empty?
order_reservation.each do |order_reserve|
if order_reserve[0] == 'OrderReservation'
@order_reservation = order_reserve[1]
end
end
end
end
def get_all_menu
@menus = Menu.all
end
end