|
|
|
|
@@ -1294,7 +1294,7 @@ end
|
|
|
|
|
query = query.group('mi.name')
|
|
|
|
|
.order("SUM(i.qty) DESC").limit(20)
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
|
|
|
|
" i.price as unit_price,mi.name as product_name")
|
|
|
|
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
|
|
|
|
@@ -1335,7 +1335,7 @@ end
|
|
|
|
|
.group('mi.name')
|
|
|
|
|
.order("SUM(i.qty) DESC").limit(20)
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
|
|
|
|
" i.price as unit_price,mi.name as product_name")
|
|
|
|
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
|
|
|
|
@@ -1375,7 +1375,7 @@ end
|
|
|
|
|
query = query.group('mi.name')
|
|
|
|
|
.order("SUM(i.qty) ASC").limit(20)
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
|
|
|
|
" i.price as unit_price,mi.name as product_name")
|
|
|
|
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
|
|
|
|
@@ -1416,7 +1416,7 @@ end
|
|
|
|
|
.group('mi.name')
|
|
|
|
|
.order("SUM(i.qty) ASC").limit(20)
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
|
|
|
|
" i.price as unit_price,mi.name as product_name")
|
|
|
|
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
|
|
|
|
@@ -1452,7 +1452,7 @@ end
|
|
|
|
|
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
|
|
|
|
.order('receipt_date')
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("grand_total")
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time)
|
|
|
|
|
@@ -1470,7 +1470,7 @@ end
|
|
|
|
|
else
|
|
|
|
|
query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id)
|
|
|
|
|
end
|
|
|
|
|
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
|
|
|
|
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
|
|
|
|
.order('receipt_date')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1479,20 +1479,20 @@ end
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = Sale.select("grand_total")
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
|
|
|
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
|
|
|
|
.order('receipt_date')
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("grand_total")
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
|
|
|
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
|
|
|
|
.order('receipt_date')
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.select("grand_total")
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
|
|
|
|
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
|
|
|
|
|
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
|
|
|
|
|
.order('receipt_date')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1513,7 +1513,7 @@ end
|
|
|
|
|
query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name")
|
|
|
|
|
.order("e.name")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
|
|
|
|
|
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
@@ -1546,7 +1546,7 @@ end
|
|
|
|
|
.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name")
|
|
|
|
|
.order("e.name")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
|
|
|
|
|
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
|
|
|
|
|
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
|
|
|
|
|
@@ -1575,7 +1575,7 @@ end
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).sum("grand_total")
|
|
|
|
|
else
|
|
|
|
|
@@ -1596,14 +1596,14 @@ end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today).sum("grand_total")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today).sum("grand_total")
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id)
|
|
|
|
|
.sum("grand_total")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1620,7 +1620,7 @@ end
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).count
|
|
|
|
|
else
|
|
|
|
|
@@ -1639,14 +1639,14 @@ end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',today,today).count
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',today,today).count
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id = ?',today,shift.id).count
|
|
|
|
|
total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id = ?',today,today,shift.id).count
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1666,7 +1666,7 @@ end
|
|
|
|
|
.sum("sp.payment_amount")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to,from_time,to_time)
|
|
|
|
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
@@ -1693,18 +1693,18 @@ end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today)
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today,today)
|
|
|
|
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
.sum("sp.payment_amount")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today)
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today,today)
|
|
|
|
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
.sum("sp.payment_amount")
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',today,shift.id)
|
|
|
|
|
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',today,today,shift.id)
|
|
|
|
|
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
.sum("sp.payment_amount")
|
|
|
|
|
end
|
|
|
|
|
@@ -1726,7 +1726,7 @@ end
|
|
|
|
|
.sum("payment_amount")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
|
|
|
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
|
|
|
|
@@ -1753,18 +1753,18 @@ end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today)
|
|
|
|
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
|
|
|
|
.sum("payment_amount")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today)
|
|
|
|
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
|
|
|
|
.sum("payment_amount")
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ? and s.shift_sale_id=?',today,shift.id)
|
|
|
|
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',today,today,shift.id)
|
|
|
|
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
|
|
|
|
.sum("payment_amount")
|
|
|
|
|
end
|
|
|
|
|
@@ -1786,7 +1786,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
|
|
|
|
@@ -1814,18 +1814,18 @@ end
|
|
|
|
|
else
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id)
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1846,7 +1846,7 @@ end
|
|
|
|
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.select("distinct sp.payment_method")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
|
|
|
|
@@ -1874,18 +1874,18 @@ end
|
|
|
|
|
else
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = Sale.select("distinct sp.payment_method")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("distinct sp.payment_method")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.select("distinct sp.payment_method")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -1918,7 +1918,7 @@ 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()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
if payment_method == 'card'
|
|
|
|
|
@@ -1969,7 +1969,7 @@ end
|
|
|
|
|
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
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
|
|
|
|
if payment_method == 'card'
|
|
|
|
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today)
|
|
|
|
|
@@ -2021,7 +2021,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
|
|
|
|
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
|
|
|
|
@@ -2054,20 +2054,20 @@ end
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
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)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
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)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
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 and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -2090,7 +2090,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.select("count(sales.customer_id) as total_take_cus")
|
|
|
|
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
|
|
|
|
@@ -2123,20 +2123,20 @@ end
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
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)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
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)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
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 and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -2159,7 +2159,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
|
|
|
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
|
|
|
|
@@ -2188,20 +2188,20 @@ end
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_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 not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_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 not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_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 not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -2222,7 +2222,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(sales.customer_id) as total_cus")
|
|
|
|
|
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
@@ -2251,20 +2251,20 @@ end
|
|
|
|
|
if current_user.nil?
|
|
|
|
|
query = Sale.select("count(sales.customer_id) 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") = ? and c.customer_type is null and c.membership_id is null',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(sales.customer_id) 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") = ? and c.customer_type is null and c.membership_id is null',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.select("count(sales.customer_id) 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") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -2286,7 +2286,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
|
|
|
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
|
|
|
|
@@ -2318,14 +2318,14 @@ end
|
|
|
|
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
|
|
|
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
|
|
|
|
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
|
|
|
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
|
|
|
|
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
@@ -2333,7 +2333,7 @@ end
|
|
|
|
|
query = Sale.select("count(distinct a.order_id) as total_order")
|
|
|
|
|
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
|
|
|
|
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -2353,7 +2353,7 @@ end
|
|
|
|
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
|
|
|
|
@@ -2381,20 +2381,20 @@ end
|
|
|
|
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
|
|
|
|
|
else
|
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
|
|
|
if !shift.nil?
|
|
|
|
|
query = Sale.select("distinct b.id as account_id, b.title as title")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.joins("JOIN accounts as b ON b.id = a.account_id")
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@@ -2414,7 +2414,7 @@ end
|
|
|
|
|
.first()
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
@@ -2446,7 +2446,7 @@ end
|
|
|
|
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
|
|
|
|
@@ -2478,7 +2478,7 @@ end
|
|
|
|
|
.order("SUM(a.qty) DESC")
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
@@ -2514,7 +2514,7 @@ end
|
|
|
|
|
.order("SUM(a.qty) DESC")
|
|
|
|
|
.first()
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
|
|
|
|
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
|
|
|
|
@@ -2548,7 +2548,7 @@ end
|
|
|
|
|
.sum("a.qty")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
if !from_time.nil? && !to_time.nil?
|
|
|
|
|
query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time)
|
|
|
|
|
@@ -2577,7 +2577,7 @@ end
|
|
|
|
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
|
|
|
|
.sum("a.qty")
|
|
|
|
|
else
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager'
|
|
|
|
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account'
|
|
|
|
|
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
|
|
|
|
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
|
|
|
|
.sum("a.qty")
|
|
|
|
|
|