This commit is contained in:
Myat Zin Wai Maw
2019-11-19 14:59:45 +06:30
parent 8b2da5e3da
commit 5a3f328789
16 changed files with 299 additions and 238 deletions

View File

@@ -7,6 +7,7 @@ class Sale < ApplicationRecord
belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee"
belongs_to :customer, :optional => true
belongs_to :shift_sale
belongs_to :shop
has_many :sale_items
has_many :sale_discount_items
has_many :sale_discounts
@@ -1502,10 +1503,10 @@ end
return tax
end
def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type)
def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type,shop)
if (!from.nil? && !to.nil?) && (from != "" && to!="")
if current_user.nil?
query = Sale.top_bottom(today,nil,from,to,from_time,to_time)
query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time)
if type == "top"
query = query.group('i.product_name')
@@ -1516,7 +1517,7 @@ end
end
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.top_bottom(today,nil,from,to,from_time,to_time)
query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time)
if type == "top"
query = query.group('i.product_name')
.order("SUM(i.qty) DESC").limit(20)
@@ -1525,9 +1526,9 @@ end
.order("SUM(i.qty) ASC").limit(20)
end
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user.id,shop)
if !shift.nil?
query = Sale.top_bottom(today,shift,from,to,from_time,to_time)
query = Sale.top_bottom(shop,today,shift,from,to,from_time,to_time)
if type == "top"
query = query.group('i.product_name')
.order("SUM(i.qty) DESC").limit(20)
@@ -1540,7 +1541,7 @@ end
end
else
if current_user.nil?
query = Sale.top_bottom(today).group('i.product_name')
query = Sale.top_bottom(shop,today).group('i.product_name')
if type == "top"
query = query.order("SUM(i.qty) DESC").limit(20)
@@ -1549,16 +1550,16 @@ end
end
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.top_bottom(today).group('i.product_name')
query = Sale.top_bottom(shop,today).group('i.product_name')
if type == "top"
query = query.order("SUM(i.qty) DESC").limit(20)
elsif type == "bottom"
query = query.order("SUM(i.qty) ASC").limit(20)
end
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user.id,shop)
if !shift.nil?
query = Sale.top_bottom(today,shift).group('i.product_name')
query = Sale.top_bottom(shop,today,shift).group('i.product_name')
if type == "top"
query = query.order("SUM(i.qty) DESC").limit(20)
elsif type == "bottom"
@@ -1570,52 +1571,52 @@ end
end
end
def self.hourly_sales(today,current_user,from,to,from_time,to_time)
def self.hourly_sales(today,current_user,from,to,from_time,to_time,shop)
if (!from.nil? && !to.nil?) && (from != "" && to!="")
if current_user.nil?
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)
query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time)
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time)
query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time)
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user.id,shop)
if !shift.nil?
query = Sale.hourly_sale_data(today,shift,from,to,from_time,to_time)
query = Sale.hourly_sale_data(shop,today,shift,from,to,from_time,to_time)
end
end
end
else
if current_user.nil?
query = Sale.hourly_sale_data(today)
query = Sale.hourly_sale_data(shop,today)
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
query = Sale.hourly_sale_data(today)
query = Sale.hourly_sale_data(shop,today)
else
shift = ShiftSale.current_open_shift(current_user.id)
shift = ShiftSale.current_open_shift(current_user.id,shop)
if !shift.nil?
query = Sale.hourly_sale_data(today,shift)
query = Sale.hourly_sale_data(shop,today,shift)
end
end
end
end
end
def self.employee_sales(today,current_user,from,to,from_time,to_time)
def self.employee_sales(today,current_user,from,to,from_time,to_time,shop)
shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
ShiftSale.current_open_shift(current_user.id)
ShiftSale.current_open_shift(current_user.id,shop)
end
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
query = employee_sale(today, shift, from, to, from_time, to_time)
query = employee_sale(shop,today, shift, from, to, from_time, to_time)
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount,
CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card'
ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name")
end
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count")
def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
query = shop.sales.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count")
.where('sale_status = "completed"')
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1627,15 +1628,15 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
return query
end
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
query = shop.sales.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.where('sales.sale_status = "completed" 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")')
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
@@ -1646,20 +1647,20 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.sum("sp.payment_amount")
end
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop)
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
query = SalePayment.credits
.joins(:sale)
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id")
.where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed')
.where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code)
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.merge(Sale.date_between(from, to))
@@ -1670,7 +1671,7 @@ end
query = query.merge(Sale.date_on(today))
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1678,8 +1679,8 @@ end
return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)")
end
def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,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')
def self.summary_sale_receipt(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.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"')
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
@@ -1690,15 +1691,15 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.first()
end
def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("distinct sp.payment_method")
def self.total_payment_methods(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.select("distinct sp.payment_method")
.where('sales.sale_status = "completed"')
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1710,17 +1711,17 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
return query
end
def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.payment_sale(shop,payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount")
query = shop.sales.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount")
.joins(:sale_payments)
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
.completed
@@ -1741,15 +1742,15 @@ end
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query.first
end
def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
total_dinein_takeaway = self.total_dinein_takeaway(today,current_user,from,to,from_time,to_time)
def self.total_customer(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
total_dinein_takeaway = self.total_dinein_takeaway(shop,today,current_user,from,to,from_time,to_time)
dinein_cnt = 0
takeaway_cnt = 0
if !total_dinein_takeaway.nil?
@@ -1758,7 +1759,7 @@ end
takeaway_cnt = total_dinein_takeaway[0].total_take_cus
end
end
membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time)
membership_cnt = self.total_membership(shop,today,current_user,from,to,from_time,to_time)
member_cnt = 0
if !membership_cnt.nil?
member_cnt = membership_cnt.total_memb_cus
@@ -1771,8 +1772,8 @@ end
return total_cus, dinein_cnt, takeaway_cnt, member_cnt
end
def self.total_dinein_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus")
def self.total_dinein_takeaway(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and c.membership_id is null')
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1784,15 +1785,15 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.first()
end
def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
def self.total_membership(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.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 ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))')
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1804,7 +1805,7 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1857,8 +1858,8 @@ end
# query = query.first()
# end
def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("count(distinct sale_orders.order_id) as total_order")
def self.total_order(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.select("count(distinct sale_orders.order_id) as total_order")
.joins(:sale_orders)
.completed
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1871,7 +1872,7 @@ end
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1879,8 +1880,8 @@ end
query = query.first
end
def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("distinct b.id as account_id, b.title as title")
def self.total_account(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.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"')
@@ -1893,15 +1894,15 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
return query
end
def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
def self.account_data(shop,account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.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}'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1913,15 +1914,15 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
query = query.first
end
def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
def self.top_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.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'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
@@ -1933,7 +1934,7 @@ end
query = query.date_on(today)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user.id,shop)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1942,8 +1943,8 @@ end
.first()
end
def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
def self.total_foc_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'")
if (!from.nil? && !to.nil?) && (from != "" && to!="")
query = query.date_between(from, to)
@@ -2096,9 +2097,9 @@ def unique_tax_profiles(order_source, customer_id)
return tax_data
end
def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.top_bottom(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
query = shop.sales.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,i.product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
if !from_time.nil? && !to_time.nil?
@@ -2112,7 +2113,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = query.where("shift_sale_id='#{shift.id}'")
end
else
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
query = shop.sales.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
" i.price as unit_price,i.product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
@@ -2124,9 +2125,9 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
return query
end
def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
def self.hourly_sale_data(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
query = Sale.select("grand_total")
query = shop.sales.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)
else
@@ -2138,7 +2139,7 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
.order('receipt_date')
else
query = Sale.select("grand_total")
query = shop.sales.select("grand_total")
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
if !shift.nil?
query = query.where("shift_sale_id='#{shift.id}'")
@@ -2150,8 +2151,8 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=
return query
end
def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = Sale.joins(:cashier)
def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
query = shop.sales.joins(:cashier)
.joins(:sale_payments)
.paid.completed
if !from.nil? && !to.nil?