From ff3a844880c1e2a09c5b2d4c6cd4ecb1a9da6c24 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 24 Jul 2018 10:30:51 +0630 Subject: [PATCH] chagne credit query --- app/models/sale_payment.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 0a718ac8..93395250 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -864,11 +864,11 @@ 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' #{receipt_no} #{customer}") + if params[:type] == "cashier" - query = query.where("and o.source='#{params[:type]}' OR o.source='emenu'") + 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' END) and s.sale_status = 'completed' AND o.source='#{params[:type]}' OR o.source='emenu' #{receipt_no} #{customer}") else - query = query.where("and o.source='#{params[:type]}'") + 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' END) and s.sale_status = 'completed' AND o.source='#{params[:type]}' #{receipt_no} #{customer}") end query = query.group("s.receipt_no") .order("s.receipt_date ASC, s.receipt_no ASC")