merge with old_town_aston req

This commit is contained in:
phyusin
2018-03-12 12:10:52 +06:30
parent 6e9ecd342b
commit 92401ab4f9
6 changed files with 99 additions and 27 deletions

View File

@@ -913,15 +913,15 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty
query = Sale.all
if shift.present?
query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sales.payment_status= 'paid' and sale_payments.payment_amount != 0", shift.to_a)
query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
elsif shift_sale_range.present?
query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.payment_status= 'paid' and sales.shift_sale_id in (?)",shift_sale_range.to_a)
query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
else
query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sales.payment_status= 'paid' and sale_payments.payment_amount != 0",from,to)
query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
end
@@ -1112,7 +1112,7 @@ end
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
.where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+
"and payment_status='paid' and sale_status= 'completed'")
"and sale_status= 'completed'")
.group('mi.name')
.order("SUM(i.qty) DESC").limit(20)
else
@@ -1120,7 +1120,7 @@ end
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
"and payment_status='paid' and sale_status= 'completed'")
"and sale_status= 'completed'")
.group('mi.name')
.order("SUM(i.qty) DESC").limit(20)
end
@@ -1132,7 +1132,7 @@ end
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
.where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+
"and payment_status='paid' and sale_status= 'completed'")
"and sale_status= 'completed'")
.group('mi.name')
.order("SUM(i.qty) ASC").limit(20)
else
@@ -1140,7 +1140,7 @@ end
" i.price as unit_price,mi.name as product_name")
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
"and payment_status='paid' and sale_status= 'completed'")
"and sale_status= 'completed'")
.group('mi.name')
.order("SUM(i.qty) ASC").limit(20)
end
@@ -1149,12 +1149,12 @@ end
def self.hourly_sales(today,from,to)
if !from.nil? && !to.nil?
query= Sale.select("grand_total")
.where('payment_status="paid" and sale_status = "completed" and receipt_date between ? and ?',from,to)
.where('sale_status = "completed" and receipt_date between ? and ?',from,to)
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
.order('receipt_date')
else
query= Sale.select("grand_total")
.where('payment_status="paid" and 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)
.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
.order('receipt_date')
end