[general ledger] group by voucher option
diff --git a/accounts/page/general_ledger/general_ledger.js b/accounts/page/general_ledger/general_ledger.js
index a462b70..dfba26c 100644
--- a/accounts/page/general_ledger/general_ledger.js
+++ b/accounts/page/general_ledger/general_ledger.js
@@ -63,11 +63,21 @@
 					open_btn: true,
 					doctype: "dataContext.voucher_type"
 				}},
+			{id: "against_voucher_type", name: "Against Voucher Type", 
+				field: "against_voucher_type", width: 120},
+			{id: "against_voucher", name: "Against Voucher", 
+				field: "against_voucher", width: 160,
+				link_formatter: {
+					filter_input: "against_voucher",
+					open_btn: true,
+					doctype: "dataContext.against_voucher_type"
+				}},
 			{id: "remarks", name: "Remarks", field: "remarks", width: 200,
 				formatter: this.text_formatter},
 				
 		];
 	},
+	
 	filters: [
 		{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
 			filter: function(val, item, opts) {
@@ -96,6 +106,7 @@
 			return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
 		}},
 		{fieldtype: "Check", label: "Group by Ledger"},
+		{fieldtype: "Check", label: "Group by Voucher"},
 		{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
 		{fieldtype:"Button", label: "Reset Filters"}
 	],
@@ -116,9 +127,14 @@
 			me.filter_inputs.group_by_ledger
 				.parent().toggle(!!(me.account_by_name[$(this).val()] 
 					&& me.account_by_name[$(this).val()].group_or_ledger==="Group"));
+					
+			me.filter_inputs.group_by_voucher
+				.parent().toggle(!!(me.account_by_name[$(this).val()] 
+					&& me.account_by_name[$(this).val()].group_or_ledger==="Ledger"));
 		});
 		
 		this.trigger_refresh_on_change(["group_by_ledger"]);
+		this.trigger_refresh_on_change(["group_by_voucher"]);
 	},
 	setup_account_filter: function(company_filter) {
 		var me = this;
@@ -139,12 +155,14 @@
 	init_filter_values: function() {
 		this._super();
 		this.filter_inputs.group_by_ledger.parent().toggle(false);
+		this.filter_inputs.group_by_voucher.parent().toggle(false);
 		this.filter_inputs.company.change();
 		this.filter_inputs.account.change();
 	},
 	apply_filters_from_route: function() {
 		this._super();
 		this.filter_inputs.group_by_ledger.parent().toggle(false);
+		this.filter_inputs.group_by_voucher.parent().toggle(false);
 		this.filter_inputs.company.change();
 		this.filter_inputs.account.change();
 	},
@@ -196,13 +214,21 @@
 				if(!grouped_ledgers[item.account]) {
 					grouped_ledgers[item.account] = {
 						entries: [],
+						entries_group_by_voucher: {},
 						opening: me.make_summary_row("Opening", item.account),
 						totals: me.make_summary_row("Totals", item.account),
 						closing: me.make_summary_row("Closing (Opening + Totals)",
 							item.account)
 					};
 				}
-
+				
+				if(!grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]) {
+					grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] = {
+						entries: [],
+						totals: me.make_summary_row("Totals", item.voucher_no)
+					}
+				}
+				
 				if(date < from_date || item.is_opening=="Yes") {
 					opening.debit += item.debit;
 					opening.credit += item.credit;
@@ -215,6 +241,11 @@
 
 					grouped_ledgers[item.account].totals.debit += item.debit;
 					grouped_ledgers[item.account].totals.credit += item.credit;
+					
+					grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]
+						.totals.debit += item.debit;
+					grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]
+						.totals.credit += item.credit;
 				}
 				if(item.account) {
 					item.against_account = me.voucher_accounts[item.voucher_type + ":"
@@ -224,6 +255,9 @@
 				if(me.apply_filters(item) && item.is_opening=="No") {
 					out.push(item);
 					grouped_ledgers[item.account].entries.push(item);
+					
+					grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]
+						.entries.push(item);
 				}
 			}
 		});
@@ -241,6 +275,11 @@
 					out = this.group_data_by_ledger(grouped_ledgers);
 			}
 			
+			if(this.account_by_name[this.account].group_or_ledger==="Ledger"
+				&& this.group_by_voucher) {
+					out = this.group_data_by_voucher(grouped_ledgers);
+			}
+			
 			opening = me.get_balance(me.account_by_name[me.account].debit_or_credit, opening)
 			closing = me.get_balance(me.account_by_name[me.account].debit_or_credit, closing)
 			
@@ -283,6 +322,28 @@
 		return [{id: "_blank_first", _no_format: true, debit: "", credit: ""}].concat(out);
 	},
 	
+	group_data_by_voucher: function(grouped_ledgers) {
+		var me = this;
+		var out = []
+		$.each(Object.keys(grouped_ledgers).sort(), function(i, account) {
+			if(grouped_ledgers[account].entries.length) {
+				$.each(Object.keys(grouped_ledgers[account].entries_group_by_voucher).sort(),
+				 	function(j, voucher) {
+						if(grouped_ledgers[account].entries_group_by_voucher[voucher]
+							.entries.length) {
+							out = out.concat(grouped_ledgers[account]
+								.entries_group_by_voucher[voucher].entries)
+								.concat([
+									grouped_ledgers[account].entries_group_by_voucher[voucher]
+									.totals, {id: "_blank" + j, _no_format: true, 
+									debit: "", credit: ""}]);
+						}
+				});
+			}
+		});
+		return [{id: "_blank_first", _no_format: true, debit: "", credit: ""}].concat(out);
+	},
+	
 	get_balance: function(debit_or_credit, balance) {
 		if(debit_or_credit == "Debit") {
 			balance.debit -= balance.credit; balance.credit = 0;
diff --git a/patches/september_2012/repost_stock.py b/patches/september_2012/repost_stock.py
index 9720701..deb2186 100644
--- a/patches/september_2012/repost_stock.py
+++ b/patches/september_2012/repost_stock.py
@@ -22,7 +22,7 @@
 	i=0
 	for d in res:
 	    try:
-	        update_entries_after({ "item_code": d[0], "warehouse": d[1]	})
+			update_entries_after({ "item_code": d[0], "warehouse": d[1]})
 	    except:
 	        pass
 	    i += 1
diff --git a/startup/report_data_map.py b/startup/report_data_map.py
index 501db4f..ae3a53f 100644
--- a/startup/report_data_map.py
+++ b/startup/report_data_map.py
@@ -47,8 +47,9 @@
 		"order_by": "lft"
 	},
 	"GL Entry": {
-		"columns": ["name", "account", "posting_date", "cost_center", "debit", "credit", "is_opening",
-			"company", "voucher_type", "voucher_no", "remarks"],
+		"columns": ["name", "account", "posting_date", "cost_center", "debit", "credit", 
+			"is_opening", "company", "voucher_type", "voucher_no", "remarks",
+			"against_voucher_type", "against_voucher"],
 		"conditions": ["ifnull(is_cancelled, 'No')='No'"],
 		"order_by": "posting_date, account",
 		"links": {