[cleanup] SMS, and added item filter in stock balance
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 820e42d..81427fe 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -57,8 +57,6 @@
 			// var percent_paid = cint(flt(doc.base_grand_total - doc.outstanding_amount) / flt(doc.base_grand_total) * 100);
 			// cur_frm.dashboard.add_progress(percent_paid + "% Paid", percent_paid);
 
-			cur_frm.add_custom_button(__('Send SMS'), cur_frm.cscript.send_sms, 'icon-mobile-phone');
-
 			if(cint(doc.update_stock)!=1) {
 				// show Make Delivery Note button only if Sales Invoice is not created from Delivery Note
 				var from_delivery_note = false;
@@ -394,10 +392,7 @@
 	}
 }
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
 
 cur_frm.set_query("debit_to", function(doc) {
 	return{
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 6564f57..30affb8 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -27,8 +27,6 @@
 				cur_frm.add_custom_button(__('Stop'), cur_frm.cscript['Stop Purchase Order'],
 					"icon-exclamation", "btn-default");
 
-			cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms, "icon-mobile-phone", true);
-
 		} else if(doc.docstatus===0) {
 			cur_frm.cscript.add_from_mappers();
 		}
@@ -216,10 +214,7 @@
 	}
 }
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
 
 cur_frm.cscript.schedule_date = function(doc, cdt, cdn) {
 	cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "schedule_date");
diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js
index b2eab16..bc78f92 100644
--- a/erpnext/crm/doctype/lead/lead.js
+++ b/erpnext/crm/doctype/lead/lead.js
@@ -31,7 +31,6 @@
 				frappe.boot.doctype_icons["Customer"], "btn-default");
 			this.frm.add_custom_button(__("Create Opportunity"), this.create_opportunity,
 				frappe.boot.doctype_icons["Opportunity"], "btn-default");
-			cur_frm.add_custom_button(__("Send SMS"), this.frm.cscript.send_sms, "icon-mobile-phone");
 		}
 
 		if(!this.frm.doc.__islocal) {
@@ -56,8 +55,5 @@
 
 $.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm}));
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
 
diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js
index 10cfc3a..47c7f6b 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.js
+++ b/erpnext/crm/doctype/opportunity/opportunity.js
@@ -81,8 +81,7 @@
 			cur_frm.add_custom_button(__('Opportunity Lost'),
 				cur_frm.cscript['Declare Opportunity Lost'], "icon-remove", "btn-default");
 
-		cur_frm.add_custom_button(__('Send SMS'), cur_frm.cscript.send_sms,
-			"icon-mobile-phone", true);
+		
 	}
 }
 
@@ -149,10 +148,7 @@
 	dialog.show();
 }
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
 
 cur_frm.cscript.company = function(doc, cdt, cdn) {
 	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
diff --git a/erpnext/patches/v5_0/rename_total_fields.py b/erpnext/patches/v5_0/rename_total_fields.py
index 4e980ce..d8a591d 100644
--- a/erpnext/patches/v5_0/rename_total_fields.py
+++ b/erpnext/patches/v5_0/rename_total_fields.py
@@ -41,11 +41,10 @@
 def execute():
 	for doctypes, fields in [[selling_doctypes, selling_renamed_fields], [buying_doctypes, buying_renamed_fields]]:
 		for dt in doctypes:
+			meta = frappe.get_meta(dt)
+			frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
 			base_net_total = frappe.db.sql("select sum(ifnull({0}, 0)) from `tab{1}`".format(fields[0][1], dt))[0][0]
 			if not base_net_total:
-				meta = frappe.get_meta(dt)
-				frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
-
 				for f in fields:
 					if meta.get_field(f[0]):
 						rename_field(dt, f[0], f[1])
diff --git a/erpnext/patches/v5_0/update_item_desc_and_image.py b/erpnext/patches/v5_0/update_item_desc_and_image.py
index 371dd2f..296ac0a 100644
--- a/erpnext/patches/v5_0/update_item_desc_and_image.py
+++ b/erpnext/patches/v5_0/update_item_desc_and_image.py
@@ -10,15 +10,12 @@
 	"BOM Item", "Opportunity Item" , "Quotation Item" , "Sales Order Item" , "Delivery Note Item" , \
 	"Material Request Item" , "Purchase Receipt Item" , "Stock Entry Detail"]
 	for dt in dt_list:
+		frappe.reload_doctype(dt)
 		names = frappe.db.sql("""select name, description from `tab{0}` doc where doc.description is not null""".format(dt),as_dict=1)
 		for d in names:
-			try:
-				data = d.description
-				image_url = find_first_image(data)
-				desc =  re.sub("\<img[^>]+\>", "", data)
-				
-				frappe.db.sql("""update `tab{0}` doc set doc.description = %s, doc.image = %s 
-					where doc.name = %s """.format(dt),(desc, image_url, d.name))
-			except:
-				pass
-	
\ No newline at end of file
+			data = d.description
+			image_url = find_first_image(data)
+			desc =  re.sub("\<img[^>]+\>", "", data)
+
+			frappe.db.sql("""update `tab{0}` set description = %s, image = %s
+				where name = %s """.format(dt),(desc, image_url, d.name))
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index c8b028b..1dca837 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -56,6 +56,19 @@
 		this.show_item_wise_taxes();
 		this.set_dynamic_labels();
 		erpnext.pos.make_pos_btn(this.frm);
+		this.setup_sms();
+	},
+
+	setup_sms: function() {
+		var me = this;
+		if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)) {
+			this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
+		}
+	},
+
+	send_sms: function() {
+		frappe.require("assets/erpnext/js/sms_manager.js");
+		var sms_man = new SMSManager(this.doc);
 	},
 
 	hide_currency_and_price_list: function() {
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index c950056..6657100 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -25,7 +25,7 @@
 				cur_frm.add_custom_button(__('Set as Lost'),
 					cur_frm.cscript['Declare Order Lost'], "icon-exclamation", "btn-default");
 			}
-			cur_frm.add_custom_button(__('Send SMS'), cur_frm.cscript.send_sms, "icon-mobile-phone");
+			
 		}
 
 		if (this.frm.doc.docstatus===0) {
@@ -159,7 +159,4 @@
 		cur_frm.email_doc(frappe.boot.notification_settings.quotation_message);
 }
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 3c3d264..5a5896c 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -45,8 +45,6 @@
 								this.make_maintenance_schedule, null, "btn-default");
 						}
 
-				cur_frm.add_custom_button(__('Send SMS'), cur_frm.cscript.send_sms, "icon-mobile-phone", true);
-
 			} else {
 				// un-stop
 				cur_frm.dashboard.set_headline_alert(__("Stopped"), "alert-danger", "icon-stop");
@@ -187,7 +185,4 @@
 	}
 };
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-};
+;
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 1668bd0..2743ffc 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -25,7 +25,7 @@
 			cur_frm.add_custom_button(__('Make Installation Note'), this.make_installation_note);
 
 		if (doc.docstatus==1) {
-			cur_frm.add_custom_button(__('Send SMS'), cur_frm.cscript.send_sms, "icon-mobile-phone");
+			
 			this.show_stock_ledger();
 			this.show_general_ledger();
 		}
@@ -240,8 +240,5 @@
 	}
 }
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
 
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index af7e7f0..6f197a8 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -3,6 +3,17 @@
 
 frappe.provide("erpnext.item");
 
+frappe.ui.form.on("Item", "refresh", function(frm) {
+	if(frm.doc.is_stock_item) {
+		frm.add_custom_button(__("Show Balance"), function() {
+			frappe.route_options = {
+				"item_code": frm.doc.name
+			}
+			frappe.set_route("query-report", "Stock Balance");
+		});
+	}
+})
+
 cur_frm.cscript.refresh = function(doc) {
 	// make sensitive fields(has_serial_no, is_stock_item, valuation_method)
 	// read only if any stock ledger entry exists
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index dbbc6e5..c7d9471 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -53,8 +53,7 @@
 				cur_frm.add_custom_button(__('Stop'),
 					cur_frm.cscript['Stop Material Request'], "icon-exclamation", "btn-default");
 			}
-			cur_frm.add_custom_button(__('Send SMS'), cur_frm.cscript.send_sms,
-				"icon-mobile-phone", true);
+			
 
 		}
 
@@ -192,7 +191,4 @@
 	}
 };
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index c89dab1..50a1073 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -14,7 +14,6 @@
 				cur_frm.add_custom_button(__('Make Purchase Invoice'), this.make_purchase_invoice,
 					frappe.boot.doctype_icons["Purchase Invoice"]);
 			}
-			cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms, "icon-mobile-phone", true);
 
 			this.show_stock_ledger();
 			this.show_general_ledger();
@@ -172,10 +171,7 @@
 		cur_frm.email_doc(frappe.boot.notification_settings.purchase_receipt_message);
 }
 
-cur_frm.cscript.send_sms = function() {
-	frappe.require("assets/erpnext/js/sms_manager.js");
-	var sms_man = new SMSManager(cur_frm.doc);
-}
+
 
 frappe.provide("erpnext.buying");
 
diff --git a/erpnext/stock/report/stock_balance/stock_balance.js b/erpnext/stock/report/stock_balance/stock_balance.js
index c0aed51..fd941ee 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.js
+++ b/erpnext/stock/report/stock_balance/stock_balance.js
@@ -16,6 +16,13 @@
 			"fieldtype": "Date",
 			"width": "80",
 			"default": frappe.datetime.get_today()
+		},
+		{
+			"fieldname": "item_code",
+			"label": __("Item"),
+			"fieldtype": "Link",
+			"width": "80",
+			"options": "Item"
 		}
 	]
 }
diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py
index daef2eb..0cb8dc5 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.py
+++ b/erpnext/stock/report/stock_balance/stock_balance.py
@@ -53,6 +53,9 @@
 	else:
 		frappe.throw(_("'To Date' is required"))
 
+	if filters.get("item_code"):
+		conditions += " and item_code = '%s'" % frappe.db.escape(filters.get("item_code"))
+
 	return conditions
 
 #get all details