Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/page/accounts_home/accounts_home.js b/accounts/page/accounts_home/accounts_home.js
index 6a9f91a..99d92b5 100644
--- a/accounts/page/accounts_home/accounts_home.js
+++ b/accounts/page/accounts_home/accounts_home.js
@@ -188,6 +188,11 @@
 		icon: "icon-list",
 		items: [
 			{
+				"label":wn._("Bank Reconciliation Statement"),
+				route: "query-report/Bank Reconciliation Statement",
+				doctype: "Journal Voucher"
+			},
+			{
 				"label":wn._("Delivered Items To Be Billed"),
 				route: "query-report/Delivered Items To Be Billed",
 				doctype: "Sales Invoice"
@@ -197,6 +202,11 @@
 				route: "query-report/Ordered Items To Be Billed",
 				doctype: "Sales Invoice"
 			},
+			{
+				"label":wn._("Bank Clearance Summary"),
+				route: "query-report/Bank Clearance Summary",
+				doctype: "Journal Voucher"
+			},
 		]
 	}
 ]
diff --git a/accounts/report/accounts_payable/accounts_payable.py b/accounts/report/accounts_payable/accounts_payable.py
index a10dc7e..4e9b2c8 100644
--- a/accounts/report/accounts_payable/accounts_payable.py
+++ b/accounts/report/accounts_payable/accounts_payable.py
@@ -1,6 +1,7 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import getdate, nowdate, flt, cstr
+from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
 
 def execute(filters=None):
 	if not filters: filters = {}
@@ -67,8 +68,7 @@
 	gl_entries = []
 	gl_entries = webnotes.conn.sql("""select * from `tabGL Entry` 
 		where ifnull(is_cancelled, 'No') = 'No' %s order by posting_date, account""" % 
-		(conditions) % (", ".join(['%s']*len(supplier_accounts))), 
-		tuple(supplier_accounts), as_dict=1)
+		(conditions), tuple(supplier_accounts), as_dict=1)
 	return gl_entries
 	
 def get_conditions(filters, before_report_date=True):
@@ -85,7 +85,7 @@
 			conditions, filters)
 	
 	if supplier_accounts:
-		conditions += " and account in (%s)"
+		conditions += " and account in (%s)" % (", ".join(['%s']*len(supplier_accounts)))
 		
 	if filters.get("report_date"):
 		if before_report_date:
@@ -125,20 +125,4 @@
 			and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""", 
 			(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0]
 	
-	return flt(paid_amount)
-
-def get_ageing_data(ageing_based_on_date, age_on, outstanding_amount):
-	val1 = val2 = val3 = val4 = diff = 0
-	diff = age_on and ageing_based_on_date \
-		and (getdate(age_on) - getdate(ageing_based_on_date)).days or 0
-
-	if diff <= 30:
-		val1 = outstanding_amount
-	elif 30 < diff <= 60:
-		val2 = outstanding_amount
-	elif 60 < diff <= 90:
-		val3 = outstanding_amount
-	elif diff > 90:
-		val4 = outstanding_amount
-		
-	return [diff, val1, val2, val3, val4]
\ No newline at end of file
+	return flt(paid_amount)
\ No newline at end of file
diff --git a/accounts/report/accounts_receivable/accounts_receivable.py b/accounts/report/accounts_receivable/accounts_receivable.py
index a8c6d23..47908c3 100644
--- a/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/accounts/report/accounts_receivable/accounts_receivable.py
@@ -58,8 +58,7 @@
 	conditions, customer_accounts = get_conditions(filters, upto_report_date)
 	return webnotes.conn.sql("""select * from `tabGL Entry` 
 		where ifnull(is_cancelled, 'No') = 'No' %s order by posting_date, account""" % 
-		(conditions) % (", ".join(['%s']*len(customer_accounts))), 
-		tuple(customer_accounts), as_dict=1)
+		(conditions), tuple(customer_accounts), as_dict=1)
 	
 def get_conditions(filters, upto_report_date=True):
 	conditions = ""
@@ -75,7 +74,7 @@
 			conditions, filters)
 	
 	if customer_accounts:
-		conditions += " and account in (%s)"
+		conditions += " and account in (%s)" % (", ".join(['%s']*len(customer_accounts)))
 		
 	if filters.get("report_date"):
 		if upto_report_date:
@@ -96,7 +95,7 @@
 def get_si_due_date_map():
 	""" get due_date from sales invoice """
 	si_due_date_map = {}
-	for t in webnotes.conn.sql("""select name, due_date from `tabSales Invoice` group by name"""):
+	for t in webnotes.conn.sql("""select name, due_date from `tabSales Invoice`"""):
 		si_due_date_map[t[0]] = t[1]
 		
 	return si_due_date_map
diff --git a/accounts/report/bank_clearance_summary/__init__.py b/accounts/report/bank_clearance_summary/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/__init__.py
diff --git a/accounts/report/bank_clearance_summary/bank_clearance_summary.js b/accounts/report/bank_clearance_summary/bank_clearance_summary.js
new file mode 100644
index 0000000..76adfd3
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/bank_clearance_summary.js
@@ -0,0 +1,32 @@
+wn.query_reports["Bank Clearance Summary"] = {
+	"filters": [
+		{
+			"fieldname":"from_date",
+			"label": "From Date",
+			"fieldtype": "Date",
+			"default": wn.defaults.get_user_default("year_start_date"),
+			"width": "80"
+		},
+		{
+			"fieldname":"to_date",
+			"label": "To Date",
+			"fieldtype": "Date",
+			"default": get_today()
+		},
+		{
+			"fieldname":"account",
+			"label": "Bank Account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				return {
+					"query": "accounts.utils.get_account_list", 
+					"filters": {
+						"is_pl_account": "No",
+						"account_type": "Bank or Cash"
+					}
+				}
+			}
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/bank_clearance_summary/bank_clearance_summary.py b/accounts/report/bank_clearance_summary/bank_clearance_summary.py
new file mode 100644
index 0000000..49ac1a4
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/bank_clearance_summary.py
@@ -0,0 +1,54 @@
+# 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/>.
+
+from __future__ import unicode_literals
+import webnotes
+from webnotes import _, msgprint
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	columns = get_columns()
+	data = get_entries(filters)
+	
+	return columns, data
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140", 
+		"Posting Date:Date:100", "Clearance Date:Date:110", "Against Account:Link/Account:200", 
+		"Debit:Currency:120", "Credit:Currency:120"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	if not filters.get("account"):
+		msgprint(_("Please select Bank Account"), raise_exception=1)
+	else:
+		conditions += " and jvd.account = %(account)s"
+		
+	if filters.get("from_date"): conditions += " and jv.posting_date>=%(from_date)s"
+	if filters.get("to_date"): conditions += " and jv.posting_date<=%(to_date)s"
+	
+	return conditions
+	
+def get_entries(filters):
+	conditions = get_conditions(filters)
+	entries =  webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date, 
+		jv.clearance_date, jvd.against_account, jvd.debit, jvd.credit
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 %s
+		order by jv.name DESC""" % conditions, filters, as_list=1)
+	return entries
\ No newline at end of file
diff --git a/accounts/report/bank_clearance_summary/bank_clearance_summary.txt b/accounts/report/bank_clearance_summary/bank_clearance_summary.txt
new file mode 100644
index 0000000..3dd2079
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/bank_clearance_summary.txt
@@ -0,0 +1,21 @@
+[
+ {
+  "creation": "2013-05-01 12:13:25", 
+  "docstatus": 0, 
+  "modified": "2013-05-01 12:13:25", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Bank Clearance Summary", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Bank Clearance Summary"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/bank_reconciliation_statement/__init__.py b/accounts/report/bank_reconciliation_statement/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/__init__.py
diff --git a/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js
new file mode 100644
index 0000000..28ac920
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js
@@ -0,0 +1,25 @@
+wn.query_reports["Bank Reconciliation Statement"] = {
+	"filters": [
+		{
+			"fieldname":"account",
+			"label": "Bank Account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				return {
+					"query": "accounts.utils.get_account_list", 
+					"filters": {
+						"is_pl_account": "No",
+						"account_type": "Bank or Cash"
+					}
+				}
+			}
+		},
+		{
+			"fieldname":"report_date",
+			"label": "Date",
+			"fieldtype": "Date",
+			"default": get_today()
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
new file mode 100644
index 0000000..1345cd8
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
@@ -0,0 +1,79 @@
+# 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/>.
+
+from __future__ import unicode_literals
+import webnotes
+from webnotes import _, msgprint
+from webnotes.utils import flt
+
+def execute(filters=None):
+	if not filters: filters = {}
+		
+	columns = get_columns()	
+	data = get_entries(filters)
+	
+	from accounts.utils import get_balance_on
+	balance_as_per_company = get_balance_on(filters["account"], filters["report_date"])
+
+	total_debit, total_credit = 0,0
+	for d in data:
+		total_debit += flt(d[4])
+		total_credit += flt(d[5])
+
+	if webnotes.conn.get_value("Account", filters["account"], "debit_or_credit") == 'Debit':
+		bank_bal = flt(balance_as_per_company) - flt(total_debit) + flt(total_credit)
+	else:
+		bank_bal = flt(balance_as_per_company) + flt(total_debit) - flt(total_credit)
+		
+	data += [
+		["", "", "", "Balance as per company books", balance_as_per_company, ""], 
+		["", "", "", "Amounts not reflected in bank", total_debit, total_credit], 
+		["", "", "", "Balance as per bank", bank_bal, ""]
+	]
+			
+	return columns, data
+	
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Posting Date:Date:100", 
+		"Clearance Date:Date:110", "Against Account:Link/Account:200", 
+		"Debit:Currency:120", "Credit:Currency:120"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	if not filters.get("account"):
+		msgprint(_("Please select Bank Account"), raise_exception=1)
+	else:
+		conditions += " and jvd.account = %(account)s"
+		
+	if not filters.get("report_date"):
+		msgprint(_("Please select Date on which you want to run the report"), raise_exception=1)
+	else:
+		conditions += """ and jv.posting_date <= %(report_date)s 
+			and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s"""
+
+	return conditions
+	
+def get_entries(filters):
+	conditions = get_conditions(filters)
+	entries = webnotes.conn.sql("""select jv.name, jv.posting_date, jv.clearance_date, 
+		jvd.against_account, jvd.debit, jvd.credit
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 and ifnull(jv.cheque_no, '')!= '' %s
+		order by jv.name DESC""" % conditions, filters, as_list=1)
+		
+	return entries
\ No newline at end of file
diff --git a/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.txt b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.txt
new file mode 100644
index 0000000..9867c5d
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-04-30 18:30:21", 
+  "docstatus": 0, 
+  "modified": "2013-05-01 10:53:12", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 0, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Bank Reconciliation Statement", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Bank Reconciliation Statement"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/collection_report/__init__.py b/accounts/report/collection_report/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/collection_report/__init__.py
diff --git a/accounts/report/collection_report/collection_report.js b/accounts/report/collection_report/collection_report.js
new file mode 100644
index 0000000..b370453
--- /dev/null
+++ b/accounts/report/collection_report/collection_report.js
@@ -0,0 +1,42 @@
+wn.query_reports["Collection Report"] = {
+	"filters": [
+		{
+			"fieldname": "from_date",
+			"label": "From Date",
+			"fieldtype": "Date",
+			"default": wn.defaults.get_user_default("year_start_date"),
+			"width": "80"
+		},
+		{
+			"fieldname":"to_date",
+			"label": "To Date",
+			"fieldtype": "Date",
+			"default": get_today()
+		},
+		{
+			"fieldname":"account",
+			"label": "Customer Account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				var company = wn.query_report.filters_by_name.company.get_value();
+				return {
+					"query": "accounts.utils.get_account_list", 
+					"filters": {
+						"is_pl_account": "No",
+						"debit_or_credit": "Debit",
+						"company": company,
+						"master_type": "Customer"
+					}
+				}
+			}
+		},
+		{
+			"fieldname":"company",
+			"label": "Company",
+			"fieldtype": "Link",
+			"options": "Company",
+			"default": sys_defaults.company
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/collection_report/collection_report.py b/accounts/report/collection_report/collection_report.py
new file mode 100644
index 0000000..50f74e0
--- /dev/null
+++ b/accounts/report/collection_report/collection_report.py
@@ -0,0 +1,86 @@
+# 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/>.
+
+from __future__ import unicode_literals
+import webnotes
+from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	columns = get_columns()
+	entries = get_entries(filters)
+	si_posting_date_map = get_si_posting_date_map()
+	
+	data = []
+	for d in entries:
+		against_invoice_date = d.against_invoice and si_posting_date_map[d.against_invoice] or ""
+		
+		row = [d.name, d.account, d.posting_date, d.against_invoice, against_invoice_date, 
+			d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
+			
+		if d.against_invoice:
+			row += get_ageing_data(against_invoice_date, d.posting_date, d.credit or -1*d.debit)
+		else:
+			row += ["", "", "", "", ""]
+			
+		data.append(row)
+	
+	return columns, data
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140", 
+		"Posting Date:Date:100", "Against Invoice:Link/Sales Invoice:130", 
+		"Against Invoice Posting Date:Date:130", "Debit:Currency:120", "Credit:Currency:120", 
+		"Reference No::100", "Reference Date:Date:100", "Remarks::150", "Age:Int:40", 
+		"0-30:Currency:100", "30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	
+	customer_accounts = []
+	if filters.get("account"):
+		customer_accounts = [filters["account"]]
+	elif filters.get("company"):
+		customer_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
+			where ifnull(master_type, '') = 'Customer' and docstatus < 2 
+			and company = %s""", filters["company"])
+	
+	if customer_accounts:
+		conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(customer_accounts)))
+		
+	if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
+	if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
+	
+	return conditions, customer_accounts
+	
+def get_entries(filters):
+	conditions, customer_accounts = get_conditions(filters)
+	entries =  webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date, 
+		jvd.against_invoice, jvd.debit, jvd.credit, jv.cheque_no, jv.cheque_date, jv.remark
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" % 
+		(conditions), tuple(customer_accounts), as_dict=1)
+		
+	return entries
+	
+def get_si_posting_date_map():
+	si_posting_date_map = {}
+	for t in webnotes.conn.sql("""select name, posting_date from `tabSales Invoice`"""):
+		si_posting_date_map[t[0]] = t[1]
+		
+	return si_posting_date_map
\ No newline at end of file
diff --git a/accounts/report/collection_report/collection_report.txt b/accounts/report/collection_report/collection_report.txt
new file mode 100644
index 0000000..3933dee
--- /dev/null
+++ b/accounts/report/collection_report/collection_report.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-05-01 12:29:12", 
+  "docstatus": 0, 
+  "modified": "2013-05-01 12:29:12", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 1, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Collection Report", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Collection Report"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt b/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt
index c84854f..e84c597 100644
--- a/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt
+++ b/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 17:55:23", 
+  "creation": "2013-02-25 10:38:57", 
   "docstatus": 0, 
-  "modified": "2013-02-23 14:35:28", 
+  "modified": "2013-05-01 11:56:43", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
diff --git a/accounts/report/purchase_register/purchase_register.py b/accounts/report/purchase_register/purchase_register.py
index 01dc937..c131c17 100644
--- a/accounts/report/purchase_register/purchase_register.py
+++ b/accounts/report/purchase_register/purchase_register.py
@@ -141,7 +141,6 @@
 	accounts = list(set([inv.credit_to for inv in invoice_list]))
 	for acc in webnotes.conn.sql("""select name, parent_account from tabAccount 
 		where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
-			account_map.setdefault(acc.name, "")
 			account_map[acc.name] = acc.parent_account
 						
 	return account_map	
\ No newline at end of file
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index a0020c4..23d2227 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -145,7 +145,6 @@
 	customers = list(set([inv.customer for inv in invoice_list]))
 	for cust in webnotes.conn.sql("""select name, territory from `tabCustomer` 
 		where name in (%s)""" % ", ".join(["%s"]*len(customers)), tuple(customers), as_dict=1):
-			customer_map.setdefault(cust.name, "")
 			customer_map[cust.name] = cust.territory
 	
 	return customer_map
@@ -155,7 +154,6 @@
 	accounts = list(set([inv.debit_to for inv in invoice_list]))
 	for acc in webnotes.conn.sql("""select name, parent_account from tabAccount 
 		where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
-			account_map.setdefault(acc.name, "")
 			account_map[acc.name] = acc.parent_account
 						
 	return account_map
\ No newline at end of file
diff --git a/hr/doctype/deduction_type/deduction_type.txt b/hr/doctype/deduction_type/deduction_type.txt
index 4c9ad7a..f346793 100644
--- a/hr/doctype/deduction_type/deduction_type.txt
+++ b/hr/doctype/deduction_type/deduction_type.txt
@@ -1,12 +1,13 @@
 [
  {
-  "creation": "2013-01-10 16:34:13", 
+  "creation": "2013-01-22 16:50:30", 
   "docstatus": 0, 
-  "modified": "2013-01-22 14:25:38", 
+  "modified": "2013-05-02 11:22:59", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
+  "allow_rename": 1, 
   "autoname": "field:deduction_name", 
   "doctype": "DocType", 
   "document_type": "Master", 
diff --git a/hr/doctype/earning_type/earning_type.txt b/hr/doctype/earning_type/earning_type.txt
index 18cac68..d69f486 100644
--- a/hr/doctype/earning_type/earning_type.txt
+++ b/hr/doctype/earning_type/earning_type.txt
@@ -1,12 +1,13 @@
 [
  {
-  "creation": "2013-01-10 16:34:13", 
+  "creation": "2013-01-24 11:03:32", 
   "docstatus": 0, 
-  "modified": "2013-01-23 16:32:07", 
+  "modified": "2013-05-02 11:22:48", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
+  "allow_rename": 1, 
   "autoname": "field:earning_name", 
   "doctype": "DocType", 
   "document_type": "Master", 
diff --git a/stock/doctype/batch/batch.txt b/stock/doctype/batch/batch.txt
index 4722996..c6ed3c3 100644
--- a/stock/doctype/batch/batch.txt
+++ b/stock/doctype/batch/batch.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-01 19:09:43", 
+  "creation": "2013-03-05 14:50:38", 
   "docstatus": 0, 
-  "modified": "2013-03-01 08:22:16", 
+  "modified": "2013-05-01 15:49:47", 
   "modified_by": "Administrator", 
   "owner": "harshada@webnotestech.com"
  }, 
@@ -24,14 +24,19 @@
   "permlevel": 0
  }, 
  {
+  "cancel": 1, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Batch", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
+  "permlevel": 0, 
   "read": 1, 
+  "report": 1, 
   "role": "Material Master Manager", 
-  "submit": 0
+  "submit": 0, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -94,28 +99,6 @@
   "oldfieldtype": "Date"
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "trash_reason", 
-  "fieldtype": "Small Text", 
-  "label": "Trash Reason", 
-  "oldfieldname": "trash_reason", 
-  "oldfieldtype": "Small Text", 
-  "read_only": 1
- }, 
- {
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "report": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "match": "", 
-  "permlevel": 1
+  "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py
index 3c83de3..8fdb50e 100644
--- a/stock/doctype/stock_ledger/stock_ledger.py
+++ b/stock/doctype/stock_ledger/stock_ledger.py
@@ -114,7 +114,8 @@
 	def update_serial_purchase_details(self, obj, d, serial_no, is_submit, purpose = '', rejected=None):
 		exists = webnotes.conn.sql("select name, status, docstatus from `tabSerial No` where name = '%s'" % (serial_no))
 		if is_submit:
-			if exists and exists[0][2] != 2 and purpose not in ['Material Transfer', 'Sales Return']:
+			if exists and exists[0][2] != 2 and \
+					purpose not in ['Material Transfer', "Material Receipt", 'Sales Return']:
 				msgprint("Serial No: %s already %s" % (serial_no, exists and exists[0][1]), raise_exception = 1)
 			elif exists:
 				s = Document('Serial No', exists and exists[0][0])