merge
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
index 17027f0..3ef2776 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
@@ -45,6 +45,7 @@
 		if not in_transaction:
 			sql("start transaction")
 		
+		self.rebuid_account_tree()		
 		self.clear_account_balances()
 		self.create_account_balances()
 		self.update_opening(self.doc.company)
@@ -52,7 +53,11 @@
 		sql("commit")
 		
 		msgprint("Account balance reposted for fiscal year: " + self.doc.name)
-
+		
+	def rebuid_account_tree(self):
+		from webnotes.utils.nestedset import rebuild_tree
+		rebuild_tree('Account', 'parent_account')
+		
 	def clear_account_balances(self):
 		# balances clear - `tabAccount Balance` for fiscal year
 		sql("update `tabAccount Balance` t1, tabAccount t2 set t1.opening=0, t1.balance=0, t1.debit=0, t1.credit=0 where t1.fiscal_year=%s and t2.company = %s and t1.account = t2.name", (self.doc.name, self.doc.company))
diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js
index 7ab1e57..0e8e298 100644
--- a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js
+++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.js
@@ -38,6 +38,18 @@
 			.change(function() {
 				erpnext.coa.chart = new erpnext.ChartOfAccounts();
 			});
+			
+		erpnext.coa.fiscal_year_select = wrapper.appframe
+			.add_select("Fiscal Year", ["Loading..."]).css("width", "100px")
+			.change(function() {
+				var selected_year = $(this).val();
+				var fiscal_year = $.map(erpnext.coa.fiscal_years, function(v) {
+					return v[0] === selected_year ? v : null;
+				});
+				erpnext.coa.opening_date.val(dateutil.str_to_user(fiscal_year[1]));
+				erpnext.coa.closing_date.val(dateutil.str_to_user(fiscal_year[2]));
+				erpnext.coa.refresh_btn.click();
+			})
 
 		erpnext.coa.opening_date = wrapper.appframe.add_date("Opening Date")
 			.val(dateutil.str_to_user(sys_defaults.year_start_date));
@@ -50,7 +62,7 @@
 			.val(dateutil.obj_to_user(end_date));
 
 		erpnext.coa.refresh_btn = wrapper.appframe.add_button("Refresh", function() {
-			erpnext.coa.chart = new erpnext.ChartOfAccounts();
+			erpnext.coa.chart.refresh();
 		}, "icon-refresh");
 
 
@@ -75,6 +87,9 @@
 				erpnext.coa.waiting.toggle();
 				erpnext.coa.company_select.empty().add_options(r.message.companies)
 					.val(sys_defaults.company || r.message.companies[0]).change();
+				erpnext.coa.fiscal_year_select.empty()
+					.add_options($.map(r.message.fiscal_years, function(v) { return v[0]; }))
+					.val(sys_defaults.fiscal_year);
 				erpnext.coa.fiscal_years = r.message.fiscal_years;
 			}
 		});		
@@ -88,20 +103,44 @@
 	},
 	load_slickgrid: function() {
 		// load tree
-		wn.require('js/lib/jquery/jquery.ui.sortable');
 		wn.require('js/lib/slickgrid/slick.grid.css');
 		wn.require('js/lib/slickgrid/slick-default-theme.css');
 		wn.require('js/lib/slickgrid/jquery.event.drag.min.js');
 		wn.require('js/lib/slickgrid/slick.core.js');
-		wn.require('js/lib/slickgrid/slick.formatters.js');
 		wn.require('js/lib/slickgrid/slick.grid.js');
 		wn.require('js/lib/slickgrid/slick.dataview.js');
-		wn.dom.set_style('.slick-cell { font-size: 12px; }');		
+		wn.dom.set_style('.slick-cell { font-size: 12px; }');
 	},
 	refresh: function() {
 		this.prepare_balances();
 		this.render();
 	},
+	render: function() {
+		var me = this;
+		erpnext.coa.waiting.toggle(false);
+		this.setup_dataview();
+
+		var columns = [
+			{id: "name", name: "Account", field: "name", width: 300, cssClass: "cell-title", 
+				formatter: this.account_formatter},
+			{id: "opening_debit", name: "Opening (Dr)", field: "opening_debit", width: 100},
+			{id: "opening_credit", name: "Opening (Cr)", field: "opening_credit", width: 100},
+			{id: "debit", name: "Debit", field: "debit", width: 100},
+			{id: "credit", name: "Credit", field: "credit", width: 100},
+			{id: "closing_debit", name: "Closing (Dr)", field: "closing_debit", width: 100},
+			{id: "closing_credit", name: "Closing (Cr)", field: "closing_credit", width: 100}
+		];
+		
+		var options = {
+			editable: false,
+			enableColumnReorder: false
+		};
+
+		// initialize the grid
+		var grid = new Slick.Grid("#chart-of-accounts", this.dataView, columns, options);
+		this.add_events(grid);
+		this.grid = grid;
+	},	
 	load_data: function(company) {
 		var me = this;
 		wn.call({
@@ -112,6 +151,9 @@
 			callback: function(r) {
 				me.gl = r.message.gl;
 				me.prepare_chart(r.message.chart);
+				$.each(me.gl, function(i, v) {
+					v[1] = me.accounts[v[1]].name;
+				});
 				me.refresh();
 			}
 		})
@@ -144,9 +186,9 @@
 			}
 		});
 		this.set_indent(data, parent_map);
-		this.data = data;
+		this.accounts = data;
 		this.parent_map = parent_map;
-		this.data_by_name = data_by_name;
+		this.accounts_by_name = data_by_name;
 	},
 	prepare_balances: function() {
 		var gl = this.gl;
@@ -157,15 +199,14 @@
 		this.set_fiscal_year();
 		if (!this.fiscal_year) return;
 		
-		$.each(this.data, function(i, v) {
+		$.each(this.accounts, function(i, v) {
 			v.opening_debit = v.opening_credit = v.debit 
 				= v.credit = v.closing_debit = v.closing_credit = 0;
 		});
 		
 		$.each(gl, function(i, v) {
-			v[1] = me.data[v[1]].name;
 			var posting_date = dateutil.str_to_obj(v[0]);
-			var account = me.data_by_name[v[1]];
+			var account = me.accounts_by_name[v[1]];
 			me.update_balances(account, posting_date, v)
 		});
 		
@@ -200,11 +241,11 @@
 	update_groups: function() {
 		// update groups
 		var me= this;
-		$.each(this.data, function(i, account) {
+		$.each(this.accounts, function(i, account) {
 			// update groups
 			var parent = me.parent_map[account.name];
 			while(parent) {
-				parent_account = me.data_by_name[parent];
+				parent_account = me.accounts_by_name[parent];
 				parent_account.opening_debit += account.opening_debit;
 				parent_account.opening_credit += account.opening_credit;
 				parent_account.debit += account.debit;
@@ -217,7 +258,7 @@
 	},
 	format_balances: function() {
 		// format amount
-		$.each(this.data, function(i, v) {
+		$.each(this.accounts, function(i, v) {
 			v.opening_debit = fmt_money(v.opening_debit);
 			v.opening_credit = fmt_money(v.opening_credit);
 			v.debit = fmt_money(v.debit);
@@ -259,38 +300,12 @@
 			d.indent = indent;
 		});
 	},
-	render: function() {
-		var me = this;
-		erpnext.coa.waiting.toggle(false);
-		this.setup_dataview();
-
-		var columns = [
-			{id: "name", name: "Account", field: "name", width: 300, cssClass: "cell-title", 
-				formatter: this.account_formatter},
-			{id: "opening_debit", name: "Opening (Dr)", field: "opening_debit", width: 100},
-			{id: "opening_credit", name: "Opening (Cr)", field: "opening_credit", width: 100},
-			{id: "debit", name: "Debit", field: "debit", width: 100},
-			{id: "credit", name: "Credit", field: "credit", width: 100},
-			{id: "closing_debit", name: "Closing (Dr)", field: "closing_debit", width: 100},
-			{id: "closing_credit", name: "Closing (Cr)", field: "closing_credit", width: 100}
-		];
-		
-		var options = {
-			editable: false,
-			enableColumnReorder: false
-		};
-
-		// initialize the grid
-		var grid = new Slick.Grid("#chart-of-accounts", this.dataView, columns, options);
-		this.add_events(grid);
-		this.grid = grid;
-	},
 	setup_dataview: function() {
 		var me = this;
 		// initialize the model
 		this.dataView = new Slick.Data.DataView({ inlineFilters: true });
 		this.dataView.beginUpdate();
-		this.dataView.setItems(this.data);
+		this.dataView.setItems(this.accounts);
 		this.dataView.setFilter(this.dataview_filter);
 		this.dataView.endUpdate();
 	},
@@ -298,7 +313,7 @@
 		if (item.parent) {
 			var parent = item.parent;
 			while (parent) {
-				if (erpnext.coa.chart.data_by_name[parent]._collapsed) {
+				if (erpnext.coa.chart.accounts_by_name[parent]._collapsed) {
 					return false;
 				}
 				parent = erpnext.coa.chart.parent_map[parent];
@@ -337,7 +352,7 @@
 	},
 	account_formatter: function (row, cell, value, columnDef, dataContext) {
 		value = value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
-		var data = erpnext.coa.chart.data;
+		var data = erpnext.coa.chart.accounts;
 		var spacer = "<span style='display:inline-block;height:1px;width:" + 
 			(15 * dataContext["indent"]) + "px'></span>";
 		var idx = erpnext.coa.chart.dataView.getIdxById(dataContext.id);
diff --git a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py
index 9979163..59cd460 100644
--- a/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py
+++ b/erpnext/accounts/page/chart_of_accounts/chart_of_accounts.py
@@ -41,6 +41,7 @@
 	else:
 		res["companies"] = [r[0] for r in webnotes.conn.sql("""select name from tabCompany
 			where docstatus!=2""")]
+	
 	res["fiscal_years"] = webnotes.conn.sql("""select name, year_start_date, 
 		adddate(year_start_date, interval 1 year)
 		from `tabFiscal Year` where docstatus!=2 
diff --git a/erpnext/accounts/page/general_ledger/__init__.py b/erpnext/accounts/page/general_ledger/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/page/general_ledger/__init__.py
diff --git a/erpnext/accounts/page/general_ledger/general_ledger.css b/erpnext/accounts/page/general_ledger/general_ledger.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/page/general_ledger/general_ledger.css
diff --git a/erpnext/accounts/page/general_ledger/general_ledger.html b/erpnext/accounts/page/general_ledger/general_ledger.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/page/general_ledger/general_ledger.html
diff --git a/erpnext/accounts/page/general_ledger/general_ledger.js b/erpnext/accounts/page/general_ledger/general_ledger.js
new file mode 100644
index 0000000..d395612
--- /dev/null
+++ b/erpnext/accounts/page/general_ledger/general_ledger.js
@@ -0,0 +1,65 @@
+wn.pages['general-ledger'].onload = function(wrapper) { 
+	wn.ui.make_app_page({
+		parent: wrapper,
+		title: 'General Ledger',
+		single_column: true
+	});
+	
+	erpnext.general_ledger = new wn.views.GridReport({
+		parent: $(wrapper).find('.layout-main'),
+		appframe: wrapper.appframe,
+		doctypes: ["Company", "Account", "GL Entry"],
+		filters: [
+			{fieldtype:"Select", label: "Company", options:"Company",
+				filter: function(val, item) {
+					return item.company == val || val == "Select Company";
+				}},
+			{fieldtype:"Select", label: "Account", options:"Account",
+				filter: function(val, item) {
+					return item.account == val || val == "Select Account";
+				}},
+			{fieldtype:"Date", label: "From Date"},
+			{fieldtype:"Label", label: "To"},
+			{fieldtype:"Date", label: "To Date"},
+			{fieldtype:"Button", label: "Refresh"},
+		],
+		setup: function() {
+			this.setup_filters();
+			this.setup_columns();
+		},
+		setup_filters: function() {
+			var me = this;
+			// default filters
+			this.filter_inputs.company.val(sys_defaults.company);
+			this.filter_inputs.from_date.val(dateutil.str_to_user(sys_defaults.year_start_date));
+			this.filter_inputs.to_date.val(dateutil.str_to_user(sys_defaults.year_end_date));
+			this.filter_inputs.refresh.click(function() { me.refresh(); })
+		},
+		setup_columns: function() {
+			this.columns = [
+				{id: "posting_date", name: "Posting Date", field: "posting_date", width: 100,
+					formatter: this.date_formatter},
+				{id: "account", name: "Account", field: "account", width: 240},
+				{id: "debit", name: "Debit", field: "debit", width: 100,
+					formatter: this.currency_formatter},
+				{id: "credit", name: "Credit", field: "credit", width: 100,
+					formatter: this.currency_formatter},
+			];
+		},
+		prepare_data: function() {
+			this.prepare_data_view(wn.report_dump.data["GL Entry"]);
+		},
+		dataview_filter: function(item) {
+			var filters = wn.cur_grid_report.filter_inputs;
+			for (i in filters) {
+				var filter = filters[i].get(0);
+				if(filter.opts.filter && !filter.opts.filter($(filter).val(), item)) {
+					return false;
+				}
+			}
+			return true;
+		},
+	});
+	
+}
+
diff --git a/erpnext/accounts/page/general_ledger/general_ledger.py b/erpnext/accounts/page/general_ledger/general_ledger.py
new file mode 100644
index 0000000..f351978
--- /dev/null
+++ b/erpnext/accounts/page/general_ledger/general_ledger.py
@@ -0,0 +1,10 @@
+import webnotes
+
+@webnotes.whitelist()
+def get_chart():
+	company = webnotes.form_dict.get('company')
+	res = {}
+	res["chart"] = webnotes.conn.sql("""select name, parent_account, 
+		if(debit_or_credit="Debit", "D", ""), 
+		if(is_pl_account="Yes", "Y", "") from 
+		tabAccount where company=%s and docstatus < 2 order by lft""", (company, ))
\ No newline at end of file
diff --git a/erpnext/accounts/page/general_ledger/general_ledger.txt b/erpnext/accounts/page/general_ledger/general_ledger.txt
new file mode 100644
index 0000000..c57ff0f
--- /dev/null
+++ b/erpnext/accounts/page/general_ledger/general_ledger.txt
@@ -0,0 +1,28 @@
+# Page, general-ledger
+[
+
+	# These values are common in all dictionaries
+	{
+		'creation': '2012-09-13 13:50:13',
+		'docstatus': 0,
+		'modified': '2012-09-13 13:50:13',
+		'modified_by': u'Administrator',
+		'owner': u'Administrator'
+	},
+
+	# These values are common for all Page
+	{
+		'doctype': 'Page',
+		'module': u'Accounts',
+		'name': '__common__',
+		'page_name': u'general-ledger',
+		'standard': u'Yes',
+		'title': u'General Ledger'
+	},
+
+	# Page, general-ledger
+	{
+		'doctype': 'Page',
+		'name': u'general-ledger'
+	}
+]
\ No newline at end of file
diff --git a/erpnext/patches/august_2012/reload_stock_ledger.py b/erpnext/patches/august_2012/reload_stock_ledger.py
deleted file mode 100644
index d0ec9ee..0000000
--- a/erpnext/patches/august_2012/reload_stock_ledger.py
+++ /dev/null
@@ -1,4 +0,0 @@
-def execute():
-	import webnotes
-	from webnotes.modules import reload_doc
-	reload_doc('stock', 'Report', 'Stock Ledger')
\ No newline at end of file
diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py
index be7cca2..9109b8e 100644
--- a/erpnext/patches/patch_list.py
+++ b/erpnext/patches/patch_list.py
@@ -566,10 +566,6 @@
 		'patch_file': 'remove_cash_flow_statement',
 	},
 	{
-		'patch_module': 'patches.august_2012',
-		'patch_file': 'reload_stock_ledger',
-	},
-	{
 		'patch_module': 'patches.september_2012',
 		'patch_file': 'stock_report_permissions_for_accounts',
 	},
@@ -577,4 +573,8 @@
 		'patch_module': 'patches.september_2012',
 		'patch_file': 'communication_delete_permission',
 	},
+	{
+		'patch_module': 'patches.september_2012',
+		'patch_file': 'reload_criteria_stock_ledger',
+	},
 ]
diff --git a/erpnext/patches/september_2012/reload_criteria_stock_ledger.py b/erpnext/patches/september_2012/reload_criteria_stock_ledger.py
new file mode 100644
index 0000000..4e2e71a
--- /dev/null
+++ b/erpnext/patches/september_2012/reload_criteria_stock_ledger.py
@@ -0,0 +1,7 @@
+def execute():
+	import webnotes
+	from webnotes.modules import reload_doc
+	reload_doc('stock', 'Search Criteria', 'Stock Ledger')
+
+	from webnotes.model import delete_doc
+	delete_doc("Report", "Stock Ledger")
\ No newline at end of file
diff --git a/erpnext/startup/report_data_map.py b/erpnext/startup/report_data_map.py
new file mode 100644
index 0000000..aa23ade
--- /dev/null
+++ b/erpnext/startup/report_data_map.py
@@ -0,0 +1,37 @@
+# ERPNext - web based ERP (http://erpnext.com)
+# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+data_map = {
+	"Account": {
+		"columns": ["name", "parent_account", "lft", "rgt", "debit_or_credit", "is_pl_account",
+			"company"],
+		"order_by": "lft"
+	},
+	"GL Entry": {
+		"columns": ["account", "posting_date", "cost_center", "debit", "credit", "is_opening",
+			"company"],
+		"conditions": ["ifnull(is_cancelled, 'No')='No'"],
+		"order_by": "posting_date"
+	},
+	"Company": {
+		"columns": ["name"],
+		"conditions": ["docstatus < 2"]
+	},
+	"Fiscal Year": {
+		"columns": ["name", "year_start_date", 
+			"adddate(year_start_date, interval 1 year) as year_end_date"]
+	}
+}
diff --git a/erpnext/startup/startup.py b/erpnext/startup/startup.py
index 0ae3114..3d30492 100644
--- a/erpnext/startup/startup.py
+++ b/erpnext/startup/startup.py
@@ -1,4 +1,19 @@
-from __future__ import unicode_literals
+# ERPNext - web based ERP (http://erpnext.com)
+# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
 import webnotes
 
 def get_unread_messages():
diff --git a/erpnext/stock/search_criteria/stock_ledger/__init__.py b/erpnext/stock/search_criteria/stock_ledger/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/erpnext/stock/search_criteria/stock_ledger/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/erpnext/stock/search_criteria/stock_ledger/stock_ledger.js b/erpnext/stock/search_criteria/stock_ledger/stock_ledger.js
deleted file mode 100644
index a47806f..0000000
--- a/erpnext/stock/search_criteria/stock_ledger/stock_ledger.js
+++ /dev/null
@@ -1,20 +0,0 @@
-// ERPNext - web based ERP (http://erpnext.com)
-// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
-// 
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-// 
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-report.customize_filters = function() {
-  this.add_filter({fieldname:'item_name', label:'Item Name', fieldtype:'Data', options:'', parent:'Item'});
-  this.add_filter({fieldname:'description', label:'Description', fieldtype:'Small Text', options: '', parent:'Item'});
-}
\ No newline at end of file
diff --git a/erpnext/stock/search_criteria/stock_ledger/stock_ledger.txt b/erpnext/stock/search_criteria/stock_ledger/stock_ledger.txt
deleted file mode 100644
index cee810b..0000000
--- a/erpnext/stock/search_criteria/stock_ledger/stock_ledger.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Search Criteria, stock_ledger
-[
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-04-16 11:42:44',
-		'docstatus': 0,
-		'modified': '2012-04-16 16:00:35',
-		'modified_by': u'Administrator',
-		'owner': u'Administrator'
-	},
-
-	# These values are common for all Search Criteria
-	{
-		'add_col': u'`tabItem`.`item_name`\n`tabItem`.`description`',
-		'add_cond': u'`tabItem`.`name` = `tabStock Ledger Entry`.`item_code`',
-		'add_tab': u'`tabItem`',
-		'columns': u'Stock Ledger Entry\x01Item Code,Stock Ledger Entry\x01Warehouse,Stock Ledger Entry\x01Posting Date,Stock Ledger Entry\x01Posting Time,Stock Ledger Entry\x01Actual Quantity,Stock Ledger Entry\x01Bin Actual Qty After Transaction,Stock Ledger Entry\x01Voucher Type,Stock Ledger Entry\x01Voucher No',
-		'criteria_name': u'Stock Ledger',
-		'doc_type': u'Stock Ledger Entry',
-		'doctype': 'Search Criteria',
-		'filters': u'{"Stock Ledger Entry\\u0001Warehouse Type":[""],"Stock Ledger Entry\\u0001Company":[""],"Stock Ledger Entry\\u0001Is Cancelled":[""],"Stock Ledger Entry\\u0001Is Stock Entry":[""]}',
-		'module': u'Stock',
-		'name': '__common__',
-		'page_len': 50,
-		'sort_by': u'`tabStock Ledger Entry`.`item_code`',
-		'sort_order': u'DESC',
-		'standard': u'Yes'
-	},
-
-	# Search Criteria, stock_ledger
-	{
-		'doctype': 'Search Criteria',
-		'name': u'stock_ledger'
-	}
-]
\ No newline at end of file
diff --git a/public/css/all-app.css b/public/css/all-app.css
index 8044e51..957a875 100644
--- a/public/css/all-app.css
+++ b/public/css/all-app.css
@@ -163,7 +163,7 @@
   margin-top: 1px;
 }
 .btn-small {
-  padding: 5px 9px;
+  padding: 4px 9px;
   font-size: 11px;
   line-height: 16px;
 }
diff --git a/public/css/all-web.css b/public/css/all-web.css
index fca3485..fd46111 100644
--- a/public/css/all-web.css
+++ b/public/css/all-web.css
@@ -163,7 +163,7 @@
   margin-top: 1px;
 }
 .btn-small {
-  padding: 5px 9px;
+  padding: 4px 9px;
   font-size: 11px;
   line-height: 16px;
 }
diff --git a/public/js/all-app.js b/public/js/all-app.js
index d76e1d1..6d19c4c 100644
--- a/public/js/all-app.js
+++ b/public/js/all-app.js
@@ -176,7 +176,7 @@
 wn.dom.set_box_shadow=function(ele,spread){$(ele).css('-moz-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')
 $(ele).css('-webkit-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')
 $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){$.fn.add_options=function(options_list){for(var i=0;i<options_list.length;i++){var v=options_list[i];value=v.value||v;label=v.label||v;$('<option>').html(label).attr('value',value).appendTo(this);}
-return $(this).val(options_list[0].value||options_list[0]);}
+this.selectedIndex=0;return $(this);}
 $.fn.set_working=function(){var ele=this.get(0);$(ele).attr('disabled','disabled');if(ele.loading_img){$(ele.loading_img).toggle(true);}else{ele.loading_img=$('<img src="images/lib/ui/button-load.gif" \
     style="margin-left: 4px; margin-bottom: -2px; display: inline;" />').insertAfter(ele);}}
 $.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery);
@@ -392,8 +392,10 @@
 msgprint(r.server_messages);}
 if(r.exc){r.exc=JSON.parse(r.exc);if(r.exc instanceof Array){$.each(r.exc,function(i,v){if(v)console.log(v);})}else{console.log(r.exc);}};if(r['403']){wn.container.change_to('403');}
 if(r.docs){LocalDB.sync(r.docs);}}
-wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
-opts.error&&opts.error(xhr)}})}
+wn.request.call=function(opts){wn.request.prepare(opts);var args={url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
+opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(args,{xhr:function(){var xhr=jquery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Content-length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2)
+opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);},complete:function(){clearInterval(interval);}})}
+$.ajax(args)}
 wn.call=function(opts){var args=$.extend({},opts.args)
 if(opts.module&&opts.page){args.cmd=opts.module+'.page.'+opts.page+'.'+opts.page+'.'+opts.method}else if(opts.method){args.cmd=opts.method;}
 for(key in args){if(args[key]&&typeof args[key]!='string'){args[key]=JSON.stringify(args[key]);}}
@@ -402,7 +404,7 @@
  *	lib/js/core.js
  */
 if(!console){var console={log:function(txt){}}}
-window._version_number="031a31bad930de7f9e8157242afbcba4729d91ff9f957c0c897cafd6";$(document).ready(function(){wn.assets.check();wn.provide('wn.app');$.extend(wn.app,new wn.Application());});
+window._version_number="d0dad4fa131b16b4b3226ab63ad2594c6c18a48d6e193ab73c57faa5";$(document).ready(function(){wn.assets.check();wn.provide('wn.app');$.extend(wn.app,new wn.Application());});
 
 /*
  *	lib/js/legacy/globals.js
@@ -852,7 +854,7 @@
 this.$breadcrumbs=$('</span>\
     <span class="breadcrumb-area"></span>').appendTo(this.$titlebar);var crumb=$('<span>').html(html);if(!this.$breadcrumbs.find('span').length){crumb.addClass('appframe-title');}
 crumb.appendTo(this.$breadcrumbs);},clear_breadcrumbs:function(){this.$breadcrumbs&&this.$breadcrumbs.empty();},add_toolbar:function(){if(!this.toolbar)
-this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 160px;'>").add_options(options).appendTo(this.add_label(label));},add_label:function(label){return $("<span style='margin-right: 12px;'>"+label+" </span>").appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
+this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_label:function(label){return $("<span style='margin: 2px 4px;'>"+label+" </span>").appendTo(this.toolbar);},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 160px; margin: 2px 4px;'>").add_options(options).appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px; margin: 2px 4px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.toolbar);},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
    <div class="layout-appframe"></div>\
    <div class="layout-main"></div>\
   </div>');}else{$(opts.parent).html('<div class="layout-wrapper layout-wrapper-background">\
@@ -1067,6 +1069,16 @@
    <a class="close" style="margin-top: 5px;">&times</a>\
    </div>').appendTo($(this.dialog.body).find('.column-list'));var fieldselect=new wn.ui.FieldSelect(w,this.doctype);fieldselect.$select.css('width','90%').val((c[1]||this.doctype)+"."+c[0]);w.find('.close').click(function(){$(this).parent().remove();});}});
 /*
+ *	lib/js/wn/views/grid_report.js
+ */
+wn.provide("wn.report_dump");$.extend(wn.report_dump,{data:{},with_data:function(doctypes,callback,progress_bar){var missing=[];$.each(doctypes,function(i,v){if(!wn.report_dump.data[v])missing.push(v);})
+if(missing.length){wn.call({method:"webnotes.widgets.report_dump.get_data",args:{doctypes:missing},callback:function(r){$.each(r.message,function(doctype,doctype_data){var data=[];$.each(doctype_data.data,function(i,d){var row={};$.each(doctype_data.columns,function(idx,col){row[col]=d[idx];});row.id=doctype+"-"+i;data.push(row);});wn.report_dump.data[doctype]=data;});callback();},progress_bar:progress_bar})}else{callback();}}});wn.provide("wn.views");wn.views.GridReport=Class.extend({init:function(opts){this.filter_inputs={};$.extend(this,opts);this.wrapper=$('<div>').appendTo(this.parent);if(this.filters){this.make_filters();}
+this.make_waiting();this.import_slickgrid();var me=this;this.get_data();wn.cur_grid_report=this;},get_data:function(){var me=this;wn.report_dump.with_data(this.doctypes,function(){$.each(me.filter_inputs,function(i,v){var opts=v.get(0).opts;if(opts.fieldtype=="Select"&&inList(me.doctypes,opts.options)){$(v).add_options($.map(wn.report_dump.data[opts.options],function(d){return d.name;}));}});me.setup();me.refresh();},this.wrapper.find(".progress .bar"));},make_waiting:function(){this.waiting=$('<div class="well" style="width: 63%; margin: 30px auto;">\
+   <p style="text-align: center;">Loading Report...</p>\
+   <div class="progress progress-striped active">\
+    <div class="bar" style="width: 10%"></div></div>').appendTo(this.wrapper);},load_filters:function(callback){callback();},make_filters:function(){var me=this;$.each(this.filters,function(i,v){v.fieldname=v.fieldname||v.label.replace(/ /g,'_').toLowerCase();var input=null;if(v.fieldtype=='Select'){input=me.appframe.add_select(v.label,["Select "+v.options]);}else if(v.fieldtype=='Button'){input=me.appframe.add_button(v.label);}else if(v.fieldtype=='Date'){input=me.appframe.add_date(v.label);}else if(v.fieldtype=='Label'){input=me.appframe.add_label(v.label);}
+input&&(input.get(0).opts=v);me.filter_inputs[v.fieldname]=input;});},import_slickgrid:function(){wn.require('js/lib/slickgrid/slick.grid.css');wn.require('js/lib/slickgrid/slick-default-theme.css');wn.require('js/lib/slickgrid/jquery.event.drag.min.js');wn.require('js/lib/slickgrid/slick.core.js');wn.require('js/lib/slickgrid/slick.grid.js');wn.require('js/lib/slickgrid/slick.dataview.js');wn.dom.set_style('.slick-cell { font-size: 12px; }');},refresh:function(){this.prepare_data();this.render();},render:function(){this.waiting.toggle(false);this.grid_wrapper=$("<div style='height: 500px; border: 1px solid #aaa;'>").appendTo(this.wrapper);this.id=wn.dom.set_unique_id(this.grid_wrapper.get(0));this.grid=new Slick.Grid("#"+this.id,this.dataView,this.columns,this.options);this.dataView.onRowsChanged.subscribe(function(e,args){grid.invalidateRows(args.rows);grid.render();});this.dataView.onRowCountChanged.subscribe(function(e,args){grid.updateRowCount();grid.render();});},prepare_data_view:function(items){this.dataView=new Slick.Data.DataView({inlineFilters:true});this.dataView.beginUpdate();this.dataView.setItems(items);this.dataView.setFilter(this.dataview_filter);this.dataView.endUpdate();},options:{editable:false,enableColumnReorder:false},dataview_filter:function(item){return true;},date_formatter:function(row,cell,value,columnDef,dataContext){return dateutil.str_to_user(value);},currency_formatter:function(row,cell,value,columnDef,dataContext){return"<div style='text-align: right;'>"+fmt_money(value)+"</div>";}})
+/*
  *	lib/js/legacy/widgets/dialog.js
  */
 var cur_dialog;var top_index=91;function Dialog(w,h,title,content){this.make({width:w,title:title});if(content)this.make_body(content);this.onshow='';this.oncancel='';this.no_cancel_flag=0;this.display=false;this.first_button=false;}
diff --git a/public/js/all-web.js b/public/js/all-web.js
index 1588b4e..c082672 100644
--- a/public/js/all-web.js
+++ b/public/js/all-web.js
@@ -63,7 +63,7 @@
 wn.dom.set_box_shadow=function(ele,spread){$(ele).css('-moz-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')
 $(ele).css('-webkit-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')
 $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){$.fn.add_options=function(options_list){for(var i=0;i<options_list.length;i++){var v=options_list[i];value=v.value||v;label=v.label||v;$('<option>').html(label).attr('value',value).appendTo(this);}
-return $(this).val(options_list[0].value||options_list[0]);}
+this.selectedIndex=0;return $(this);}
 $.fn.set_working=function(){var ele=this.get(0);$(ele).attr('disabled','disabled');if(ele.loading_img){$(ele.loading_img).toggle(true);}else{ele.loading_img=$('<img src="images/lib/ui/button-load.gif" \
     style="margin-left: 4px; margin-bottom: -2px; display: inline;" />').insertAfter(ele);}}
 $.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery);
@@ -279,8 +279,10 @@
 msgprint(r.server_messages);}
 if(r.exc){r.exc=JSON.parse(r.exc);if(r.exc instanceof Array){$.each(r.exc,function(i,v){if(v)console.log(v);})}else{console.log(r.exc);}};if(r['403']){wn.container.change_to('403');}
 if(r.docs){LocalDB.sync(r.docs);}}
-wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
-opts.error&&opts.error(xhr)}})}
+wn.request.call=function(opts){wn.request.prepare(opts);var args={url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
+opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(args,{xhr:function(){var xhr=jquery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Content-length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2)
+opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);},complete:function(){clearInterval(interval);}})}
+$.ajax(args)}
 wn.call=function(opts){var args=$.extend({},opts.args)
 if(opts.module&&opts.page){args.cmd=opts.module+'.page.'+opts.page+'.'+opts.page+'.'+opts.method}else if(opts.method){args.cmd=opts.method;}
 for(key in args){if(args[key]&&typeof args[key]!='string'){args[key]=JSON.stringify(args[key]);}}
@@ -289,7 +291,7 @@
  *	lib/js/core.js
  */
 if(!console){var console={log:function(txt){}}}
-window._version_number="031a31bad930de7f9e8157242afbcba4729d91ff9f957c0c897cafd6";$(document).ready(function(){wn.assets.check();wn.provide('wn.app');$.extend(wn.app,new wn.Application());});
+window._version_number="d0dad4fa131b16b4b3226ab63ad2594c6c18a48d6e193ab73c57faa5";$(document).ready(function(){wn.assets.check();wn.provide('wn.app');$.extend(wn.app,new wn.Application());});
 
 /*
  *	lib/js/legacy/globals.js
@@ -513,7 +515,7 @@
 this.$breadcrumbs=$('</span>\
     <span class="breadcrumb-area"></span>').appendTo(this.$titlebar);var crumb=$('<span>').html(html);if(!this.$breadcrumbs.find('span').length){crumb.addClass('appframe-title');}
 crumb.appendTo(this.$breadcrumbs);},clear_breadcrumbs:function(){this.$breadcrumbs&&this.$breadcrumbs.empty();},add_toolbar:function(){if(!this.toolbar)
-this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 160px;'>").add_options(options).appendTo(this.add_label(label));},add_label:function(label){return $("<span style='margin-right: 12px;'>"+label+" </span>").appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
+this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_label:function(label){return $("<span style='margin: 2px 4px;'>"+label+" </span>").appendTo(this.toolbar);},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 160px; margin: 2px 4px;'>").add_options(options).appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px; margin: 2px 4px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.toolbar);},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
    <div class="layout-appframe"></div>\
    <div class="layout-main"></div>\
   </div>');}else{$(opts.parent).html('<div class="layout-wrapper layout-wrapper-background">\
diff --git a/public/js/report-legacy.js b/public/js/report-legacy.js
index efdb2a0..431823b 100644
--- a/public/js/report-legacy.js
+++ b/public/js/report-legacy.js
@@ -170,10 +170,10 @@
 _r.DataTable.prototype.set_sort_option_disabled=function(label,disabled){var s=this.sort_sel;if(disabled){for(var i=0;i<s.options.length;i++){if(s.options[i]&&s.options[i].text==label){this.disabled_options[label]=s.options[i];s.remove(i);}}}else{if(this.disabled_options[label]){try{s.add(this.disabled_options[label],s.options[s.options.length-1]);}catch(e){try{s.add(this.disabled_options[label],s.options.length-1);}catch(e){}}
 this.disabled_options[label]=null;}}}
 _r.DataTable.prototype.add_sort_option=function(label,val){var s=this.sort_sel;s.options[s.options.length]=new Option(label,val,false,s.options.length==0?true:false);}
-_r.DataTable.prototype.update_query=function(no_limit){if((_r.rb_con.cur_rb&&_r.rb_con.cur_rb.get_query)||(this.search_criteria&&this.search_criteria.custom_query)){}else{if(!sel_val(this.sort_sel)){this.sort_sel.selectedIndex=0;}
+_r.DataTable.prototype.update_query=function(no_limit){if((_r.rb_con.cur_rb&&_r.rb_con.cur_rb.get_query)||(this.search_criteria&&this.search_criteria.custom_query)){}else{var me=this;var sort_by=null,sort_order="";if(sel_val(this.sort_sel)){sort_by=sel_val(this.sort_sel);sort_order=this.sort_order;}else if(_r.rb_con.cur_rb.sc.sort_by){sort_by=(_r.rb_con.cur_rb.sc.sort_by||"").split(",");sort_by=$.map(sort_by,function(v){return v.trim()+" "+(me.sort_order||"");}).join(", ");sort_order="";}else{this.sort_sel.selectedIndex=0;sort_by=sel_val(this.sort_sel);sort_order=this.sort_order;}
 this.query+=NEWLINE
-+' ORDER BY '+sel_val(this.sort_sel)
-+' '+this.sort_order;}
++' ORDER BY '+sort_by
++' '+sort_order;}
 if(no_limit||this.no_limit){if(this.show_query)alert(this.query);return;}
 this.query+=' LIMIT '+(this.start_rec-1)+','+this.page_len;if(this.show_query)
 alert(this.query);}