Merge branch 'adminbsb_ui_changes' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
phyusin
2018-07-23 18:00:42 +06:30

View File

@@ -864,9 +864,14 @@ class SalePayment < ApplicationRecord
.joins("INNER JOIN customers c ON c.customer_id = s.customer_id")
.joins("INNER JOIN sale_orders so ON so.sale_id = s.sale_id")
.joins("INNER JOIN orders o ON o.order_id = so.order_id")
.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' and o.source='#{params[:type]}' #{receipt_no} #{customer}")
.group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC")
.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' #{receipt_no} #{customer}")
if params[:type] == "cashier"
query = query.where("and o.source='#{params[:type]}' OR 0.source='emenu'")
else
query = query.where("and o.source='#{params[:type]}'")
end
query = query.group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC")
return query
end