change query for dashboard and time for checkin channel
This commit is contained in:
@@ -983,11 +983,11 @@ end
|
||||
end
|
||||
|
||||
def self.employee_sales(today)
|
||||
query = Sale.select("e.name as employee_name,(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE sp.payment_amount END) as total_amount")
|
||||
.where('sales.payment_status="paid" and sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
query = Sale.select('(CASE WHEN (sp.payment_method="mpu" or sp.payment_method="visa" or sp.payment_method="master" or sp.payment_method="jcb") THEN "card" ELSE sp.payment_method END) as payment_name, (CASE WHEN sp.payment_method="cash" THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount')
|
||||
.joins("join employees e on e.id=sales.cashier_id")
|
||||
.joins("join sale_payments sp on sp.sale_id=sales.sale_id")
|
||||
.group("sp.payment_method","e.name")
|
||||
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
|
||||
.group('payment_method','e.name')
|
||||
.order('e.name')
|
||||
end
|
||||
|
||||
@@ -1042,20 +1042,22 @@ end
|
||||
end
|
||||
|
||||
def self.total_customer(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_cus")
|
||||
query = Sale.select("(CASE WHEN (c.customer_type='Dinein' or c.customer_type='Takeaway') THEN count(sales.customer_id) ELSE count(distinct sales.customer_id) END) as total_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.order('sales.sale_id ASC')
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_dinein(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_dinein_cus")
|
||||
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_takeaway(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_take_cus")
|
||||
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
||||
.first()
|
||||
|
||||
Reference in New Issue
Block a user