Merge branch 'crm' of bitbucket.org:code2lab/sxrestaurant
This commit is contained in:
@@ -445,6 +445,7 @@ class Sale < ApplicationRecord
|
||||
total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
|
||||
IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total,
|
||||
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
|
||||
IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount,
|
||||
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
|
||||
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj")
|
||||
.where("(sale_status = ? OR sale_status = ?) AND receipt_date between ? and ? AND total_amount != 0", 'completed', 'void', from_date, to_date)
|
||||
@@ -454,6 +455,7 @@ class Sale < ApplicationRecord
|
||||
old_grand_total = sale.old_grand_total
|
||||
total_discount = sale.total_discount
|
||||
void_amount = sale.void_amount
|
||||
total_change_amount = sale.total_change_amount
|
||||
total = {:sale_date => pay.sale_date,
|
||||
:mpu_amount => pay.mpu_amount,
|
||||
:master_amount => pay.master_amount,
|
||||
@@ -464,6 +466,7 @@ class Sale < ApplicationRecord
|
||||
:credit_amount => pay.credit_amount,
|
||||
:foc_amount => pay.foc_amount,
|
||||
:total_discount => total_discount,
|
||||
:total_change_amount => total_change_amount,
|
||||
:grand_total => grand_total,
|
||||
:old_grand_total => old_grand_total,
|
||||
:void_amount => void_amount,
|
||||
@@ -514,7 +517,7 @@ def self.get_by_shiftsales(from,to)
|
||||
return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
|
||||
end
|
||||
|
||||
# def self.get_by_shiftsales(employee,from,to)
|
||||
# def self.get_by_shiftsales(from,to)
|
||||
# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date')
|
||||
# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id")
|
||||
# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to)
|
||||
@@ -529,23 +532,23 @@ end
|
||||
|
||||
# void = Sale.select("SUM(sales.grand_total) AS grand_total")
|
||||
# .joins("join shift_sales sh on sh.id = sales.shift_sale_id")
|
||||
# .where('sales.sales_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id)
|
||||
# .where('sales.sale_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id)
|
||||
# .sum(:grand_total)
|
||||
# cash = all_total.select('sr.payment_type')
|
||||
# .where('sr.payment_type = "cash"')
|
||||
# .sum(:amount)
|
||||
|
||||
# credit = all_total.where('sr.payment_type = "credit"')
|
||||
# credit = all_total.where('sr.payment_type = "creditnote"')
|
||||
# .sum(:amount)
|
||||
|
||||
# accept_credit = all_total.select('ci.amout')
|
||||
# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id")
|
||||
# .where('sr.payment_type = "credit"')
|
||||
# .where('sr.payment_type = "creditnote"')
|
||||
# .sum(:amout)
|
||||
|
||||
|
||||
|
||||
# foc = all_total.where('sales.payment_type = "foc" and sales.sales_status = "completed"')
|
||||
# foc = all_total.where('sales.payment_type = "foc" and sales.sale_status = "completed"')
|
||||
# .sum(:grand_total)
|
||||
|
||||
# card = all_total.select('payment_type')
|
||||
@@ -571,6 +574,31 @@ end
|
||||
# return sale_arr
|
||||
# end
|
||||
|
||||
# def self.get_receipt_no_list(from,to)
|
||||
# sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
|
||||
# end
|
||||
|
||||
def self.get_by_shift_sale(from,to,status)
|
||||
query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date,shift_closed_at As closing_date," +
|
||||
" grand_total AS grand_total, cash_sales AS cash," +
|
||||
"total_taxes AS total_tax,total_discounts As total_discount")
|
||||
.order("shift_sales.id DESC")
|
||||
return query = query.where("shift_sales.shift_started_at between ? and ?" + " or shift_sales.shift_closed_at between ? and ?",from,to ,from,to )
|
||||
end
|
||||
|
||||
def self.get_separate_tax(from,to,payment_type=nil)
|
||||
|
||||
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
|
||||
.joins("INNER JOIN sales ON sales.id = sale_taxes.sale_id")
|
||||
.group("sale_taxes.tax_name")
|
||||
|
||||
return query = query.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
|
||||
end
|
||||
|
||||
def grand_total_after_rounding
|
||||
return self.grand_total.to_f + self.rounding_adjustment.to_f
|
||||
end
|
||||
|
||||
def get_cash_amount
|
||||
cash = 0.0
|
||||
self.sale_payments.each do |pay|
|
||||
@@ -616,8 +644,4 @@ end
|
||||
def generate_custom_id
|
||||
self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL")
|
||||
end
|
||||
|
||||
def self.get_receipt_no_list(from,to)
|
||||
sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user