check manager account login error in dashboard
This commit is contained in:
@@ -1181,7 +1181,7 @@ end
|
||||
if current_user.nil?
|
||||
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
@@ -1195,7 +1195,7 @@ end
|
||||
if current_user.nil?
|
||||
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
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")
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
@@ -1213,7 +1213,7 @@ end
|
||||
if current_user.nil?
|
||||
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
@@ -1226,7 +1226,7 @@ end
|
||||
if current_user.nil?
|
||||
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
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
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
@@ -1245,7 +1245,7 @@ end
|
||||
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
.sum("sp.payment_amount")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
query = Sale.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)
|
||||
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
.sum("sp.payment_amount")
|
||||
@@ -1264,7 +1264,7 @@ end
|
||||
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
.sum("sp.payment_amount")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
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")',today)
|
||||
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
.sum("sp.payment_amount")
|
||||
@@ -1287,7 +1287,7 @@ end
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.sum("payment_amount")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to)
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.sum("payment_amount")
|
||||
@@ -1306,7 +1306,7 @@ end
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.sum("payment_amount")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
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)
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.sum("payment_amount")
|
||||
@@ -1329,7 +1329,7 @@ end
|
||||
.where('sale_status = "completed" and receipt_date between ? and ?',from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 receipt_date between ? and ?',from,to)
|
||||
.first()
|
||||
@@ -1348,7 +1348,7 @@ end
|
||||
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
.first()
|
||||
@@ -1371,7 +1371,7 @@ end
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
query = Sale.select("distinct sp.payment_method")
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
@@ -1390,7 +1390,7 @@ end
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
query = Sale.select("distinct sp.payment_method")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
@@ -1417,7 +1417,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'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 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)
|
||||
@@ -1448,7 +1448,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'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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")',today)
|
||||
@@ -1493,7 +1493,7 @@ end
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
|
||||
@@ -1515,7 +1515,7 @@ end
|
||||
.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()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
@@ -1541,7 +1541,7 @@ end
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
|
||||
@@ -1563,7 +1563,7 @@ end
|
||||
.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()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
@@ -1589,7 +1589,7 @@ end
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
|
||||
@@ -1611,7 +1611,7 @@ end
|
||||
.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)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
@@ -1637,7 +1637,7 @@ end
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
|
||||
@@ -1659,7 +1659,7 @@ end
|
||||
.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)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
@@ -1686,7 +1686,7 @@ end
|
||||
.where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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")
|
||||
@@ -1711,7 +1711,7 @@ end
|
||||
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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")
|
||||
@@ -1739,7 +1739,7 @@ end
|
||||
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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")
|
||||
@@ -1761,7 +1761,7 @@ end
|
||||
.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)
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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")
|
||||
@@ -1787,7 +1787,7 @@ end
|
||||
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ?",from,to)
|
||||
@@ -1809,7 +1809,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'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
@@ -1837,7 +1837,7 @@ end
|
||||
.order("SUM(a.qty) DESC")
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ?",from,to)
|
||||
@@ -1865,7 +1865,7 @@ end
|
||||
.order("SUM(a.qty) DESC")
|
||||
.first()
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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)
|
||||
@@ -1894,7 +1894,7 @@ end
|
||||
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
|
||||
.sum("a.qty")
|
||||
else
|
||||
if current_user.role == 'administrator'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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 sales.receipt_date between ? and ?",from,to)
|
||||
.sum("a.qty")
|
||||
@@ -1913,7 +1913,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'
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user