From 74175df8f529e2efffd25646463a753bc0ccc3ea Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 13 Aug 2018 11:44:59 +0630 Subject: [PATCH] update credit sale with foc --- app/models/sale_payment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 9aac5236..8b6bb646 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -878,9 +878,9 @@ class SalePayment < ApplicationRecord .joins("INNER JOIN orders o ON o.order_id = so.order_id") if params[:type] == "cashier" - query = query.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' AND o.source='#{params[:type]}' OR o.source='emenu' END) and s.sale_status = 'completed' #{receipt_no} #{customer}") + query = query.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' AND o.source='#{params[:type]}' OR o.source='emenu' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}") else - query = query.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' AND o.source='#{params[:type]}' END) and s.sale_status = 'completed' #{receipt_no} #{customer}") + query = query.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' AND o.source='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}") end query = query.group("s.receipt_no") .order("s.receipt_date ASC, s.receipt_no ASC")