Merge pull request #5203 from nabinhait/credit_limit_fix

[fix] Ignore closed sales order in credit limit validation
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index a1b3846..acc70df 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -118,7 +118,7 @@
 
 	setup_sms: function() {
 		var me = this;
-		if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)
+		if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped", "Closed"], this.frm.doc.status)
 			&& this.frm.doctype != "Purchase Invoice") {
 			this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
 		}
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 8a7da63..df91d63 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -199,7 +199,7 @@
 		select sum(base_grand_total*(100 - per_billed)/100)
 		from `tabSales Order`
 		where customer=%s and docstatus = 1 and company=%s
-		and per_billed < 100 and status != 'Stopped'""", (customer, company))
+		and per_billed < 100 and status != 'Closed'""", (customer, company))
 
 	outstanding_based_on_so = flt(outstanding_based_on_so[0][0]) if outstanding_based_on_so else 0.0
 
@@ -210,7 +210,7 @@
 		where
 			dn.name = dn_item.parent
 			and dn.customer=%s and dn.company=%s
-			and dn.docstatus = 1 and dn.status != 'Stopped'
+			and dn.docstatus = 1 and dn.status not in ('Closed', 'Stopped')
 			and ifnull(dn_item.against_sales_order, '') = ''
 			and ifnull(dn_item.against_sales_invoice, '') = ''""", (customer, company), as_dict=True)