Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/page/accounts_browser/accounts_browser.js b/accounts/page/accounts_browser/accounts_browser.js
index e5a30b0..fb011ca 100644
--- a/accounts/page/accounts_browser/accounts_browser.js
+++ b/accounts/page/accounts_browser/accounts_browser.js
@@ -135,8 +135,7 @@
 	show_ledger: function() {
 		var me = this;
 		var node = me.selected_node();
-		wn.set_route('Report', 'GL Entry', 'General Ledger', 
-			this.ctype + '=' + node.data('label'));
+		wn.set_route("general-ledger", "account=" + node.data('label'));
 	},
 	new_node: function() {
 		if(this.ctype=='Account') {
diff --git a/accounts/page/general_ledger/general_ledger.js b/accounts/page/general_ledger/general_ledger.js
index 8e70619..ecc8626 100644
--- a/accounts/page/general_ledger/general_ledger.js
+++ b/accounts/page/general_ledger/general_ledger.js
@@ -45,6 +45,9 @@
 					open_btn: true,
 					doctype: "'Account'"
 				}},
+			{id: "against_accont", name: "Against Account", field: "against_account", 
+				width: 240, hidden: this.is_default("account")},
+
 			{id: "debit", name: "Debit", field: "debit", width: 100,
 				formatter: this.currency_formatter},
 			{id: "credit", name: "Credit", field: "credit", width: 100,
@@ -139,9 +142,11 @@
 		var data = wn.report_dump.data["GL Entry"];
 		var out = [];
 		
-		if(!this.account_by_name)
+		if(!this.account_by_name) {
 			this.account_by_name = this.make_name_map(wn.report_dump.data["Account"]);
-			
+			this.make_voucher_acconuts_map();
+		}
+		
 		var me = this;
 		
 		var from_date = dateutil.str_to_obj(this.from_date);
@@ -167,7 +172,7 @@
 				: true) && (me.voucher_no ? item.voucher_no==me.voucher_no : true)) {
 				var date = dateutil.str_to_obj(item.posting_date);
 				
-				if(date < from_date) {
+				if(date < from_date || item.is_opening=="Yes") {
 					opening.debit += item.debit;
 					opening.credit += item.credit;
 				} else if(date <= to_date) {
@@ -175,7 +180,12 @@
 					totals.credit += item.credit;
 				}
 
-				if(me.apply_filters(item)) {
+				if(me.account) {
+					item.against_account = me.voucher_accounts[item.voucher_type + ":"
+						+ item.voucher_no][(item.debit > 0 ? "credits" : "debits")].join(", ");					
+				}
+
+				if(me.apply_filters(item) && item.is_opening=="No") {
 					out.push(item);
 				}
 			}
@@ -189,6 +199,8 @@
 							
 		
 		if(!me.is_default("account")) {
+			me.appframe.set_title("General Ledger: " + me.account);
+			
 			if(me.account_by_name[me.account].debit_or_credit == "Debit") {
 				opening.debit -= opening.credit; opening.credit = 0;
 				closing.debit -= closing.credit; closing.credit = 0;
@@ -198,11 +210,34 @@
 			}
 			var out = [opening].concat(out).concat([totals, closing]);
 		} else {
+			me.appframe.set_title("General Ledger");
 			var out = out.concat([totals]);
 		}
 					
 		this.data = out;
 	},
+	
+	make_voucher_acconuts_map: function() {
+		this.voucher_accounts = {};
+		var data = wn.report_dump.data["GL Entry"];
+		for(var i=0, j=data.length; i<j; i++) {
+			var gl = data[i];
+			
+			if(!this.voucher_accounts[gl.voucher_type + ":" + gl.voucher_no])
+				this.voucher_accounts[gl.voucher_type + ":" + gl.voucher_no] = {
+					debits: [],
+					credits: []
+				}
+				
+			var va = this.voucher_accounts[gl.voucher_type + ":" + gl.voucher_no];
+			if(gl.debit > 0) {
+				va.debits.push(gl.account);
+			} else {
+				va.credits.push(gl.account);
+			}
+		}
+	},
+	
 	get_plot_data: function() {
 		var data = [];
 		var me = this;
diff --git a/public/js/startup.js b/public/js/startup.js
index c845ab2..4efc2a3 100644
--- a/public/js/startup.js
+++ b/public/js/startup.js
@@ -108,7 +108,7 @@
 					}
 				}
 				
-				show_in_circle('unread_messages', r.message.unread_messages.length);
+				show_in_circle('unread_messages', r.message.unread_messages);
 				show_in_circle('open_support_tickets', r.message.open_support_tickets);
 				show_in_circle('things_todo', r.message.things_todo);
 				show_in_circle('todays_events', r.message.todays_events);
diff --git a/public/js/toolbar.js b/public/js/toolbar.js
index a04c225..17f79dc 100644
--- a/public/js/toolbar.js
+++ b/public/js/toolbar.js
@@ -87,18 +87,9 @@
 
 erpnext.toolbar.set_new_comments = function(new_comments) {
 	var navbar_nc = $('.navbar-new-comments');
-	if(wn.container.page && wn.container.page.page_name=="messages") 
-		return;
-	if(new_comments && new_comments.length>0) {
-		navbar_nc.text(new_comments.length);
+	if(cint(new_comments)) {
 		navbar_nc.addClass('navbar-new-comments-true')
-		$.each(new_comments, function(i, v) {
-			var msg = 'New Message: ' + (v[1].length<=100 ? v[1] : (v[1].substr(0, 100) + "..."));
-			var id = v[0].replace('/', '-');
-			if(!$('#' + id)[0]) { 
-				show_alert(msg).attr("id", id);
-			}
-		});
+		navbar_nc.text(new_comments);
 	} else {
 		navbar_nc.removeClass('navbar-new-comments-true');
 		navbar_nc.text(0);
diff --git a/startup/startup.py b/startup/startup.py
index b761225..828239e 100644
--- a/startup/startup.py
+++ b/startup/startup.py
@@ -20,12 +20,12 @@
 def get_unread_messages():
 	"returns unread (docstatus-0 messages for a user)"
 	return webnotes.conn.sql("""\
-		SELECT name, comment
+		SELECT count(*)
 		FROM `tabComment`
 		WHERE comment_doctype IN ('My Company', 'Message')
 		AND comment_docname = %s
 		AND ifnull(docstatus,0)=0
-		""", webnotes.user.name, as_list=1)
+		""", webnotes.user.name)[0][0]
 
 def get_open_support_tickets():
 	"""Returns a count of open support tickets"""
diff --git a/utilities/page/messages/messages.js b/utilities/page/messages/messages.js
index 6d13155..625fe5b 100644
--- a/utilities/page/messages/messages.js
+++ b/utilities/page/messages/messages.js
@@ -33,12 +33,14 @@
 	<div class="all-messages"></div>').appendTo($(wrapper).find('.layout-main-section'));
 	
 	erpnext.messages = new erpnext.Messages(wrapper);
+	erpnext.toolbar.set_new_comments(0);
 }
 
 $(wn.pages.messages).bind('show', function() {
 	// remove alerts
 	$('#alert-container .alert').remove();
 	
+	erpnext.toolbar.set_new_comments(0);	
 	erpnext.messages.show();
 	setTimeout("erpnext.messages.refresh()", 17000);
 })