current shop changes
This commit is contained in:
@@ -847,7 +847,6 @@ def self.daily_sales_list(from,to,shop_code)
|
||||
ELSE 0 END as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
||||
|
||||
.along_with_sale_payments_except_void_between(from, to)
|
||||
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
||||
.group("sale_id").to_sql
|
||||
@@ -1580,10 +1579,11 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.top_bottom_products(current_user,from,to,type)
|
||||
def self.top_bottom_products(current_user,from,to,type,current_shop)
|
||||
puts @current_shop
|
||||
query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id")
|
||||
.completed
|
||||
.where("qty > 0 AND price > 0 AND shop_code='#{shop.shop_code}'")
|
||||
.where("qty > 0 AND price > 0 AND shop_code='#{current_shop.shop_code}'")
|
||||
.group("SUBSTRING_INDEX(product_name, ' - ', 1)")
|
||||
|
||||
if !from.nil? && !to.nil?
|
||||
@@ -1607,9 +1607,8 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.hourly_sales(current_user,from,to)
|
||||
def self.hourly_sales(current_user,from,to, current_shop)
|
||||
query = Sale.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '#{Time.zone.formatted_offset}'), '%I %p')")
|
||||
|
||||
.order('receipt_date').completed
|
||||
|
||||
if !from.nil? && !to.nil?
|
||||
@@ -1626,7 +1625,7 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.employee_sales(current_user,from,to)
|
||||
def self.employee_sales(current_user,from,to, current_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)
|
||||
@@ -1635,8 +1634,7 @@ end
|
||||
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
|
||||
|
||||
|
||||
query = employee_sale(shift, from, to)
|
||||
|
||||
query = employee_sale(shift, from, to, current_shop)
|
||||
.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'
|
||||
@@ -1682,14 +1680,14 @@ end
|
||||
end
|
||||
|
||||
|
||||
def self.credit_payment(current_user=nil,from=nil,to=nil)
|
||||
def self.credit_payment(current_user=nil,from=nil,to=nil, current_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 = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code)
|
||||
.where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',current_shop.shop_code)
|
||||
|
||||
if (!from.nil? && !to.nil?)
|
||||
query = query.merge(Sale.receipt_date_between(from, to))
|
||||
@@ -1727,7 +1725,6 @@ end
|
||||
def self.total_payment_methods(current_user=nil,from=nil,to=nil)
|
||||
query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method")
|
||||
.where("sales.sale_status = 'completed'")
|
||||
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
.group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END")
|
||||
|
||||
@@ -1893,11 +1890,11 @@ end
|
||||
# end
|
||||
|
||||
|
||||
def self.total_order(current_user=nil,from=nil,to=nil)
|
||||
def self.total_order(current_user=nil,from=nil,to=nil, current_shop)
|
||||
|
||||
query = Sale.select("count(distinct sale_orders.order_id) as total_order")
|
||||
.joins(:sale_orders)
|
||||
.where("shop_code='#{shop.shop_code}'")
|
||||
.where("shop_code='#{current_shop.shop_code}'")
|
||||
.completed
|
||||
|
||||
if (!from.nil? && !to.nil?)
|
||||
@@ -2109,11 +2106,11 @@ def unique_tax_profiles(order_source, customer_id)
|
||||
end
|
||||
|
||||
|
||||
def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil, current_shop)
|
||||
|
||||
query = Sale.joins(:cashier)
|
||||
.joins(:sale_payments)
|
||||
.paid.completed.where("sales.shop_code='#{shop.shop_code}'")
|
||||
.paid.completed.where("sales.shop_code='#{current_shop.shop_code}'")
|
||||
if !from.nil? && !to.nil?
|
||||
query = query.receipt_date_between(from, to)
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ class StockJournal < ApplicationRecord
|
||||
end
|
||||
|
||||
|
||||
def self.inventory_balances(from,to, shop)
|
||||
def self.inventory_balances(from,to, current_shop)
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
.group("mii.item_instance_name")
|
||||
|
||||
Reference in New Issue
Block a user