change dashboard query

This commit is contained in:
phyusin
2018-02-22 10:10:20 +06:30
parent eafbb80f51
commit 2cb13f9a62
2 changed files with 8 additions and 8 deletions

View File

@@ -1375,7 +1375,7 @@ end
if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
@@ -1384,7 +1384,7 @@ end
if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else