check manager account login error in dashboard

This commit is contained in:
phyusin
2018-03-09 10:55:28 +06:30
parent df76988f01
commit d7d5f8afc7
2 changed files with 41 additions and 40 deletions

View File

@@ -1181,7 +1181,7 @@ end
if current_user.nil? if current_user.nil?
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total") total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
else 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") total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
else else
shift = ShiftSale.current_open_shift(current_user.id) shift = ShiftSale.current_open_shift(current_user.id)
@@ -1195,7 +1195,7 @@ end
if current_user.nil? 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(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
else 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") total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
else else
shift = ShiftSale.current_open_shift(current_user.id) shift = ShiftSale.current_open_shift(current_user.id)
@@ -1213,7 +1213,7 @@ end
if current_user.nil? if current_user.nil?
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
else 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 total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
else else
shift = ShiftSale.current_open_shift(current_user.id) shift = ShiftSale.current_open_shift(current_user.id)
@@ -1226,7 +1226,7 @@ end
if current_user.nil? 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(receipt_date,"%Y-%m-%d") = ?',today).count
else 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 total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
else else
shift = ShiftSale.current_open_shift(current_user.id) 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") .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount") .sum("sp.payment_amount")
else 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) 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") .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount") .sum("sp.payment_amount")
@@ -1264,7 +1264,7 @@ end
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount") .sum("sp.payment_amount")
else 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) 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") .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount") .sum("sp.payment_amount")
@@ -1287,7 +1287,7 @@ end
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount") .sum("payment_amount")
else 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) 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") .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount") .sum("payment_amount")
@@ -1306,7 +1306,7 @@ end
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount") .sum("payment_amount")
else 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) 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") .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount") .sum("payment_amount")
@@ -1329,7 +1329,7 @@ end
.where('sale_status = "completed" and receipt_date between ? and ?',from,to) .where('sale_status = "completed" and receipt_date between ? and ?',from,to)
.first() .first()
else 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') 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) .where('sale_status = "completed" and receipt_date between ? and ?',from,to)
.first() .first()
@@ -1348,7 +1348,7 @@ end
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
.first() .first()
else 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') 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(receipt_date,"%Y-%m-%d") = ?',today)
.first() .first()
@@ -1371,7 +1371,7 @@ end
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) .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") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
else else
if current_user.role == 'administrator' if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct sp.payment_method") query = Sale.select("distinct sp.payment_method")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) .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") .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) .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") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
else else
if current_user.role == 'administrator' if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct sp.payment_method") 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(sales.receipt_date,"%Y-%m-%d") = ?',today)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
@@ -1417,7 +1417,7 @@ end
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() 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 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") query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card' 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) 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 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() 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 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") query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card' 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) 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) .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() .first()
else 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") query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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) .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) .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() .first()
else 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") query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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(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) .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() .first()
else 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") query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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) .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) .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() .first()
else 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") query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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(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) .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() .first()
else 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") query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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) .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) .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() .first()
else 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") query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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(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) .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() .first()
else 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") query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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) .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) .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() .first()
else 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") query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id") .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(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) .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
.first() .first()
else 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") 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 sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_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) .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.first() .first()
else 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") 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 sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_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") .joins("JOIN accounts as b ON b.id = a.account_id")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
else 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") 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 sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_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") .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(sales.receipt_date,"%Y-%m-%d") = ?',today)
else 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") 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 sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_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) .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
.first() .first()
else 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") 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") .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) .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) .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.first() .first()
else 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") 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") .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) .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") .order("SUM(a.qty) DESC")
.first() .first()
else 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") 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") .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) .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") .order("SUM(a.qty) DESC")
.first() .first()
else 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") 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") .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) .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) .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") .sum("a.qty")
else 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") 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) .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") .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) .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") .sum("a.qty")
else 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") 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) .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") .sum("a.qty")

View File

@@ -218,22 +218,21 @@
<% end %> <% end %>
<% end %> <% end %>
<% if current_user.role == 'administrator' %> <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<% else %> <% else %>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"> <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<% end %> <% end %>
<% if !@total_customer.nil? && @total_customer.to_i > 0 %>
<div class="card"> <div class="card">
<div class="body"> <div class="body">
<h6><%= t :customer %></h6> <h6><%= t :customer %></h6>
<table class="table"> <table class="table">
<% if !@total_customer.nil? %>
<tr> <tr>
<td><%= t("views.right_panel.detail.total") %> <%= t :customer %> : </td> <td><%= t("views.right_panel.detail.total") %> <%= t :customer %> : </td>
<td align="right"><%= @total_customer %></td> <td align="right"><%= @total_customer %></td>
</tr> </tr>
<% end %>
<% if !@total_dinein.nil? %> <% if !@total_dinein.nil? %>
<tr> <tr>
<td><%= t("views.right_panel.detail.dine_in") %> : </td> <td><%= t("views.right_panel.detail.dine_in") %> : </td>
@@ -261,12 +260,13 @@
</table> </table>
</div> </div>
</div> </div>
<% end %>
</div> </div>
<% if current_user.role == 'administrator' %> <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
</div> </div>
<% end %> <% end %>
<% if current_user.role == 'administrator' %> <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<% else %> <% else %>
@@ -313,8 +313,9 @@
</div> </div>
</div> </div>
</div> </div>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
</div> </div>
</div> <% end %>
<% end %> <% end %>
</div> </div>
</div> </div>