fixes in payemnt reconciliation
diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js
index 06c014c..022f900 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js
+++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js
@@ -44,7 +44,8 @@
 		    and (ifnull(gle.against_voucher, '') = '' \
 		        or ifnull(gle.against_voucher, '') = gle.voucher_no ) \
 			and ifnull(gle.%(account_type)s, 0) > 0 \
-		    and (select ifnull(abs(sum(debit) - sum(credit)), 0) from `tabGL Entry` \
+		    and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) \
+				from `tabGL Entry` \
 		        where against_voucher_type = '%(dt)s' \
 		        and against_voucher = gle.voucher_no \
 		        and voucher_no != gle.voucher_no \
diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
index d585cea..b75142b 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
+++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
@@ -39,16 +39,14 @@
 			(self.doc.voucher_type, self.doc.voucher_no, self.doc.account))
 			
 		total_amount = total_amount and flt(total_amount[0][0]) or 0
-		
 		reconciled_payment = webnotes.conn.sql("""
-			select sum(%s) - sum(%s) from `tabGL Entry` where 
+			select sum(ifnull(%s, 0)) - sum(ifnull(%s, 0)) from `tabGL Entry` where 
 			against_voucher = %s and voucher_no != %s
 			and account = %s and ifnull(is_cancelled, 'No') = 'No'""" % 
 			((self.doc.account_type == 'debit' and 'credit' or 'debit'), self.doc.account_type, 
 			 	'%s', '%s', '%s'), (self.doc.voucher_no, self.doc.voucher_no, self.doc.account))
 			
 		reconciled_payment = reconciled_payment and flt(reconciled_payment[0][0]) or 0
-		
 		ret = {
 			'total_amount': total_amount,	
 			'pending_amt_to_reconcile': total_amount - reconciled_payment