add filter in dashboard and Transaction/Sale

This commit is contained in:
phyusin
2018-03-26 16:42:17 +06:30
parent 6bb833aff3
commit 4b78de3f9a
6 changed files with 972 additions and 230 deletions

View File

@@ -86,64 +86,72 @@ class HomeController < ApplicationController
today = DateTime.now.strftime('%Y-%m-%d')
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()
if !@from_time.nil? && @to_time.nil?
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
else
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
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()
if !@from_time.nil? && @to_time.nil?
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
else
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
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)
@top_products = Sale.top_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty')
@bottom_products = Sale.bottom_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty')
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
@employee_sales = Sale.employee_sales(today,@from,@to)
@employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time)
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
@inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance)
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
@total_sale = Sale.total_sale(today,current_user,@from,@to)
@total_count = Sale.total_count(today,current_user,@from,@to)
@total_card = Sale.total_card_sale(today,current_user,@from,@to)
@total_credit = Sale.credit_payment(today,current_user,@from,@to)
@total_sale = Sale.total_sale(today,current_user,@from,@to,@from_time,@to_time)
@total_count = Sale.total_count(today,current_user,@from,@to,@from_time,@to_time)
@total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time)
@total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time)
@sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to)
@total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time)
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"
pay = Sale.payment_sale('card', today, current_user,@from,@to)
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay"
pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({'card' => pay.payment_amount})
else
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to)
pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
end
end
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to)
@total_customer = Sale.total_customer(today,current_user,@from,@to)
@total_dinein = Sale.total_dinein(today,current_user,@from,@to)
@total_takeaway = Sale.total_takeaway(today,current_user,@from,@to)
@total_other_customer = Sale.total_other_customer(today,current_user,@from,@to)
@total_membership = Sale.total_membership(today,current_user,@from,@to)
@summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time)
@total_customer = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time)
@total_dinein = Sale.total_dinein(today,current_user,@from,@to,@from_time,@to_time)
@total_takeaway = Sale.total_takeaway(today,current_user,@from,@to,@from_time,@to_time)
@total_other_customer = Sale.total_other_customer(today,current_user,@from,@to,@from_time,@to_time)
@total_membership = Sale.total_membership(today,current_user,@from,@to,@from_time,@to_time)
@total_order = Sale.total_order(today,current_user,@from,@to)
@total_accounts = Sale.total_account(today,current_user,@from,@to)
@total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time)
@total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time)
@account_data = Array.new
if !@total_accounts.nil?
@total_accounts.each do |account|
acc = Sale.account_data(account.account_id, today,current_user,@from,@to)
acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time)
if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
end
end
@top_items = Sale.top_items(today,current_user,@from,@to)
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to)
@top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time)
@total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
@@ -202,12 +210,15 @@ class HomeController < ApplicationController
to_time = params[:to_time]
if from.present? && to.present?
f_date = DateTime.parse(from)
t_date = DateTime.parse(to)
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
from = f_time.beginning_of_day.utc.getlocal
to = t_time.end_of_day.utc.getlocal
# f_date = DateTime.parse(from)
# t_date = DateTime.parse(to)
# f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
# t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
# from = f_time.beginning_of_day.utc.getlocal
# to = t_time.end_of_day.utc.getlocal
from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d')
to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d')
end
return from, to, from_time, to_time