Merge pull request #1297 from nabinhait/hotfix

Hotfix
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 dea5fb5..fc58418 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
@@ -140,13 +140,13 @@
 			and ifnull(gle.%(account_type)s, 0) > 0 
 	   		and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) 
 				from `tabGL Entry` 
-	        	where against_voucher_type = '%(dt)s' 
+	        	where account = '%(acc)s'
+				and against_voucher_type = '%(dt)s' 
 	        	and against_voucher = gle.voucher_no 
 	        	and voucher_no != gle.voucher_no) 
-					!= abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)
-			) 
-			and if(gle.voucher_type='Sales Invoice', (select is_pos from `tabSales Invoice` 
-				where name=gle.voucher_no), 0)=0
+					!= abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) 
+			and if(gle.voucher_type='Sales Invoice', ifnull((select is_pos from `tabSales Invoice` 
+				where name=gle.voucher_no), 0), 0)=0
 			%(mcond)s
 	    ORDER BY gle.posting_date desc, gle.voucher_no desc 
 	    limit %(start)s, %(page_len)s""" % {
diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py
index 855b7d1..2f5716e 100644
--- a/accounts/report/general_ledger/general_ledger.py
+++ b/accounts/report/general_ledger/general_ledger.py
@@ -72,6 +72,11 @@
 		
 	if filters.get("voucher_no"):
 		conditions.append("voucher_no=%(voucher_no)s")
+		
+		
+	from webnotes.widgets.reportview import build_match_conditions
+	match_conditions = build_match_conditions("GL Entry")
+	if match_conditions: conditions.append(match_conditions)
 	
 	return "and {}".format(" and ".join(conditions)) if conditions else ""
 
diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py
index 252a091..0cf0602 100644
--- a/startup/schedule_handlers.py
+++ b/startup/schedule_handlers.py
@@ -53,6 +53,10 @@
 	# email digest
 	from setup.doctype.email_digest.email_digest import send
 	run_fn(send)
+	
+	# auto close support tickets
+	from support.doctype.support_ticket.support_ticket import auto_close_tickets
+	run_fn(auto_close_tickets)
 		
 def execute_weekly():
 	from setup.doctype.backup_manager.backup_manager import take_backups_weekly
diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py
index 33cb023..67ed9f6 100644
--- a/support/doctype/support_ticket/get_support_mails.py
+++ b/support/doctype/support_ticket/get_support_mails.py
@@ -52,11 +52,6 @@
 			subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \
 			msg = cstr(response))
 		
-	def auto_close_tickets(self):
-		webnotes.conn.sql("""update `tabSupport Ticket` set status = 'Closed' 
-			where status = 'Replied' 
-			and date_sub(curdate(),interval 15 Day) > modified""")
-
 def get_support_mails():
 	if cint(webnotes.conn.get_value('Email Settings', None, 'sync_support_mails')):
 		SupportMailbox()
diff --git a/support/doctype/support_ticket/support_ticket.py b/support/doctype/support_ticket/support_ticket.py
index fd79583..3030a14 100644
--- a/support/doctype/support_ticket/support_ticket.py
+++ b/support/doctype/support_ticket/support_ticket.py
@@ -66,4 +66,9 @@
 def set_status(name, status):
 	st = webnotes.bean("Support Ticket", name)
 	st.doc.status = status
-	st.save()
\ No newline at end of file
+	st.save()
+		
+def auto_close_tickets():
+	webnotes.conn.sql("""update `tabSupport Ticket` set status = 'Closed' 
+		where status = 'Replied' 
+		and date_sub(curdate(),interval 15 Day) > modified""")
\ No newline at end of file