show cashier dashboard view

This commit is contained in:
phyusin
2018-02-19 13:46:08 +06:30
parent 150ff66446
commit dc5cd84f5c
6 changed files with 351 additions and 69 deletions

View File

@@ -89,6 +89,8 @@ class ApplicationController < ActionController::Base
end
def current_user
puts "session"
puts session[:session_token]
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
end

View File

@@ -77,42 +77,42 @@ class HomeController < ApplicationController
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
@inventories = StockJournal.inventory_balances(today).sum(:balance)
@total_sale = Sale.total_sale(today)
@total_count = Sale.total_count(today)
@total_card = Sale.total_card_sale(today)
@total_credit = Sale.credit_payment(today)
@total_sale = Sale.total_sale(today,current_user)
@total_count = Sale.total_count(today,current_user)
@total_card = Sale.total_card_sale(today,current_user)
@total_credit = Sale.credit_payment(today,current_user)
@sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(today)
@total_payment_methods = Sale.total_payment_methods(today,current_user)
@total_payment_methods.each do |payment|
if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb"
pay = Sale.payment_sale('card', today)
pay = Sale.payment_sale('card', today, current_user)
@sale_data.push({'card' => pay.payment_amount})
else
pay = Sale.payment_sale(payment.payment_method, today)
pay = Sale.payment_sale(payment.payment_method, today, current_user)
@sale_data.push({payment.payment_method => pay.payment_amount})
end
end
@summ_sale = Sale.summary_sale_receipt(today)
@total_customer = Sale.total_customer(today)
@total_dinein = Sale.total_dinein(today)
@total_takeaway = Sale.total_takeaway(today)
@total_other_customer = Sale.total_other_customer(today)
@total_membership = Sale.total_membership(today)
@summ_sale = Sale.summary_sale_receipt(today,current_user)
@total_customer = Sale.total_customer(today,current_user)
@total_dinein = Sale.total_dinein(today,current_user)
@total_takeaway = Sale.total_takeaway(today,current_user)
@total_other_customer = Sale.total_other_customer(today,current_user)
@total_membership = Sale.total_membership(today,current_user)
@total_order = Sale.total_order(today)
@total_accounts = Sale.total_account(today)
@total_order = Sale.total_order(today,current_user)
@total_accounts = Sale.total_account(today,current_user)
@account_data = Array.new
@total_accounts.each do |account|
acc = Sale.account_data(account.account_id, today)
acc = Sale.account_data(account.account_id, today,current_user)
if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
end
@top_items = Sale.top_items(today)
@total_foc_items = Sale.total_foc_items(today)
@top_items = Sale.top_items(today,current_user)
@total_foc_items = Sale.total_foc_items(today,current_user)
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()

View File

@@ -1088,60 +1088,158 @@ end
.order("e.name")
end
def self.total_sale(today)
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
def self.total_sale(today,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")
else
if current_user.role == 'administrator'
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)
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)
.sum("grand_total")
end
end
end
end
def self.total_count(today)
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
def self.total_count(today,current_user=nil)
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'
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)
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
end
end
end
end
def self.total_card_sale(today)
payment_type = " and payment_method = 'mpu' or payment_method = 'visa' or payment_method = 'master' or payment_method = 'jcb' or payment_method = 'unionpay' "
# query = Sale.select("SUM(tax_payable_amount) AS st_amount,tax_name")
# .where('sale_status = "completed" #{payment_type} and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
# .joins("join sale_payments on sale_id = sales.sale_id")
# .group("sales.sale_id")
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)
def self.total_card_sale(today,current_user=nil)
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")',today)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
else
if current_user.role == 'administrator'
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")
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") and shift_sale_id=?',today,shift.id)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
end
end
end
end
def self.credit_payment(today)
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
def self.credit_payment(today,current_user=nil)
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)
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
else
if current_user.role == 'administrator'
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")
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)
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
end
end
end
end
def self.summary_sale_receipt(today)
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')
def self.summary_sale_receipt(today,current_user=nil)
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)
.first()
else
if current_user.role == 'administrator'
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()
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)
.first()
end
end
end
end
def self.total_payment_methods(today)
query = Sale.select("distinct sp.payment_method")
def self.total_payment_methods(today,current_user=nil)
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)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
else
if current_user.role == 'administrator'
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")
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)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
end
end
end
end
def self.payment_sale(payment_method, today)
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
def self.payment_sale(payment_method, today, current_user=nil)
if current_user.nil?
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)
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
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'
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)
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
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
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
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") and sales.shift_sale_id=?',today,shift.id)
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
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
end
end
end
def self.total_customer(today)
dinein_cnt = self.total_dinein(today)
takeaway_cnt = self.total_takeaway(today)
membership_cnt = self.total_membership(today)
def self.total_customer(today,current_user=nil)
dinein_cnt = self.total_dinein(today,current_user)
takeaway_cnt = self.total_takeaway(today,current_user)
membership_cnt = self.total_membership(today,current_user)
total_cus = 0
if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil?
@@ -1151,69 +1249,226 @@ end
return total_cus
end
def self.total_dinein(today)
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
def self.total_dinein(today,current_user=nil)
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)
.first()
else
if current_user.role == 'administrator'
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
.first()
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)
.first()
end
end
end
end
def self.total_takeaway(today)
query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
.first()
def self.total_takeaway(today,current_user=nil)
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)
.first()
else
if current_user.role == 'administrator'
query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
.first()
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)
.first()
end
end
end
end
def self.total_membership(today)
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
def self.total_membership(today,current_user=nil)
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)
.first()
else
if current_user.role == 'administrator'
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)
.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)
.first()
end
end
end
end
def self.total_other_customer(today)
query = Sale.select("count(sales.customer_id) as total_cus")
def self.total_other_customer(today,current_user=nil)
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)
.first()
else
if current_user.role == 'administrator'
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)
.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)
.first()
end
end
end
end
def self.total_order(today)
query = Sale.select("count(distinct a.order_id) as total_order")
def self.total_order(today,current_user=nil)
if current_user.nil?
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)
.first()
else
if current_user.role == 'administrator'
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)
.first()
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
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)
.first()
end
end
end
end
def self.total_account(today)
query = Sale.select("distinct b.id as account_id, b.title as title")
def self.total_account(today,current_user=nil)
if current_user.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") = ?',today)
else
if current_user.role == 'administrator'
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)
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)
end
end
end
end
def self.account_data(account_id, today)
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
def self.account_data(account_id, today, current_user=nil)
if current_user.nil?
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)
.first()
else
if current_user.role == 'administrator'
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)
.first()
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
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') = ? and sales.shift_sale_id=?",today,shift.id)
.first()
end
end
end
end
def self.top_items(today)
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
def self.top_items(today,current_user=nil)
if current_user.nil?
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)
.group("a.product_code")
.order("SUM(a.qty) DESC")
.first()
else
if current_user.role == 'administrator'
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)
.group("a.product_code")
.order("SUM(a.qty) DESC")
.first()
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
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') = ? and sales.shift_sale_id=?",today,shift.id)
.group("a.product_code")
.order("SUM(a.qty) DESC")
.first()
end
end
end
end
def self.total_foc_items(today)
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
def self.total_foc_items(today,current_user=nil)
if current_user.nil?
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")
else
if current_user.role == 'administrator'
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")
else
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
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') = ? and sales.shift_sale_id=?",today,shift.id)
.sum("a.qty")
end
end
end
end
#card sale trans data

View File

@@ -1,6 +1,7 @@
<div class="container-fluid">
<div class="block-header">
<h2><%= t :dashboard %></h2>
<!-- <h2><%= t :dashboard %></h2> -->
<h2><%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %></h2>
</div>
<% if @print_settings.precision.to_i > 0
precision = @print_settings.precision
@@ -14,6 +15,7 @@
delimiter = ""
end
%>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<!-- Widgets -->
<div class="row clearfix">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
@@ -62,11 +64,12 @@
</div>
</div>
</div>
<% end %>
<!-- #END# Widgets -->
<!-- CPU Usage -->
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="row">
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
@@ -122,10 +125,18 @@
</div>
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<% end %>
<% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'cashier' %>
<% if !@summ_sale.nil? %>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<% else %>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<% end %>
<div class="card">
<div class="body">
<h6><%= t :sale %></h6>
@@ -184,11 +195,17 @@
</div>
</div>
</div>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
</div>
<% end %>
<% end %>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<% else %>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<% end %>
<div class="card">
<div class="body">
<h6><%= t :customer %></h6>
@@ -227,10 +244,16 @@
</div>
</div>
</div>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
</div>
<% end %>
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<% else %>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<% end %>
<div class="card">
<div class="body">
<h6><%= t("views.right_panel.detail.order") %></h6>
@@ -274,6 +297,6 @@
</div>
</div>
</div>
<% end %>
</div>
<% end %>
</div>

View File

@@ -71,6 +71,7 @@ en:
bottom: "Bottom"
payment: "Payment"
backend: "Backend"
date_time: "DateTime"
views:
btn:

View File

@@ -66,6 +66,7 @@ mm:
bottom: "အရောင်းအနဲဆုံး"
payment: "ငွေပေးချေမှု"
backend: "Backend"
date_time: "DateTime"
views:
btn: