Merge branch 'master' into edge
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index b150974..3946f00 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -36,7 +36,7 @@
 		# invoice details
 		sales_order = ", ".join(invoice_so_dn_map.get(inv.name, {}).get("sales_order", []))
 		delivery_note = ", ".join(invoice_so_dn_map.get(inv.name, {}).get("delivery_note", []))
-		# webnotes.errprint(customer_map.get(inv.customer, []))
+
 		row = [inv.name, inv.posting_date, inv.customer, inv.debit_to, 
 			account_map.get(inv.debit_to), customer_map.get(inv.customer), inv.project_name, 
 			inv.remarks, sales_order, delivery_note]
diff --git a/hr/page/hr_home/hr_home.js b/hr/page/hr_home/hr_home.js
index b2cce73..8a50184 100644
--- a/hr/page/hr_home/hr_home.js
+++ b/hr/page/hr_home/hr_home.js
@@ -177,6 +177,10 @@
 				"label":wn._("Employee Information"),
 				route: "Report2/Employee/Employee Information"
 			},
+			{
+				"label":wn._("Monthly Salary Register"),
+				route: "query-report/Monthly Salary Register"
+			},
 		]
 	}
 ];
diff --git a/hr/report/monthly_salary_register/__init__.py b/hr/report/monthly_salary_register/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/hr/report/monthly_salary_register/__init__.py
diff --git a/hr/report/monthly_salary_register/monthly_salary_register.js b/hr/report/monthly_salary_register/monthly_salary_register.js
new file mode 100644
index 0000000..da88137
--- /dev/null
+++ b/hr/report/monthly_salary_register/monthly_salary_register.js
@@ -0,0 +1,32 @@
+wn.query_reports["Monthly Salary Register"] = {
+	"filters": [
+		{
+			"fieldname":"month",
+			"label": "Month",
+			"fieldtype": "Select",
+			"options": "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec",
+			"default": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", 
+				"Dec"][wn.datetime.str_to_obj(wn.datetime.get_today()).getMonth()],
+		},
+		{
+			"fieldname":"fiscal_year",
+			"label": "Fiscal Year",
+			"fieldtype": "Link",
+			"options": "Fiscal Year",
+			"default": sys_defaults.fiscal_year,
+		},
+		{
+			"fieldname":"employee",
+			"label": "Employee",
+			"fieldtype": "Link",
+			"options": "Employee"
+		},
+		{
+			"fieldname":"company",
+			"label": "Company",
+			"fieldtype": "Link",
+			"options": "Company",
+			"default": sys_defaults.company
+		}
+	]
+}
\ No newline at end of file
diff --git a/hr/report/monthly_salary_register/monthly_salary_register.py b/hr/report/monthly_salary_register/monthly_salary_register.py
new file mode 100644
index 0000000..cc25dc3
--- /dev/null
+++ b/hr/report/monthly_salary_register/monthly_salary_register.py
@@ -0,0 +1,119 @@
+# 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.utils import flt, cstr
+from webnotes import msgprint, _
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	salary_slips = get_salary_slips(filters)
+	columns, earning_types, ded_types = get_columns(salary_slips)
+	ss_earning_map = get_ss_earning_map(salary_slips)
+	ss_ded_map = get_ss_ded_map(salary_slips)
+	
+	data = []
+	for ss in salary_slips:
+		row = [ss.employee, ss.employee_name, ss.branch, ss.department, ss.designation, 
+			ss.company, ss.month, ss.leave_withut_pay, ss.payment_days]
+			
+		for e in earning_types:
+			row.append(ss_earning_map.get(ss.name, {}).get(e))
+			
+		row += [ss.arrear_amount, ss.leave_encashment_amount, ss.gross_pay]
+		
+		for d in ded_types:
+			row.append(ss_ded_map.get(ss.name, {}).get(d))
+		
+		row += [ss.total_deduction, ss.net_pay]
+		
+		data.append(row)
+	
+	return columns, data
+	
+def get_columns(salary_slips):
+	columns = [
+		"Employee:Link/Employee:120", "Employee Name::140", "Branch:Link/Branch:120", 
+		"Department:Link/Department:120", "Designation:Link/Designation:120",
+		 "Company:Link/Company:120", "Month::80", "Leave Without pay:Float:130", 
+		"Payment Days:Float:120"
+	]
+	
+	earning_types = webnotes.conn.sql_list("""select distinct e_type from `tabSalary Slip Earning`
+		where ifnull(e_modified_amount, 0) != 0 and parent in (%s)""" % 
+		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]))
+		
+	ded_types = webnotes.conn.sql_list("""select distinct d_type from `tabSalary Slip Deduction`
+		where ifnull(d_modified_amount, 0) != 0 and parent in (%s)""" % 
+		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]))
+		
+	columns = columns + [(e + ":Link/Earning Type:120") for e in earning_types] + \
+		["Arrear Amount:Currency:120", "Leave Encashment Amount:Currency:150", 
+		"Gross Pay:Currency:120"] + [(d + ":Link/Deduction Type:120") for d in ded_types] + \
+		["Total Deduction:Currency:120", "Net Pay:Currency:120"]
+
+	return columns, earning_types, ded_types
+	
+def get_salary_slips(filters):
+	conditions, filters = get_conditions(filters)
+	salary_slips = webnotes.conn.sql("""select * from `tabSalary Slip` where docstatus = 1 %s""" % 
+		conditions, filters, as_dict=1)
+	
+	if not salary_slips:
+		msgprint(_("No salary slip found for month: ") + cstr(filters.get("month")) + 
+			_(" and year: ") + cstr(filters.get("fiscal_year")), raise_exception=1)
+	
+	return salary_slips
+	
+def get_conditions(filters):
+	conditions = ""
+	if filters.get("month"):
+		month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", 
+			"Dec"].index(filters["month"]) + 1
+		filters["month"] = month
+		conditions += " and month = %(month)s"
+	
+	if filters.get("fiscal_year"): conditions += " and fiscal_year = %(fiscal_year)s"
+	if filters.get("company"): conditions += " and company = %(company)s"
+	if filters.get("employee"): conditions += " and employee = %(employee)s"
+	
+	return conditions, filters
+	
+def get_ss_earning_map(salary_slips):
+	ss_earnings = webnotes.conn.sql("""select parent, e_type, e_modified_amount 
+		from `tabSalary Slip Earning` where parent in (%s)""" %
+		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]), as_dict=1)
+	
+	ss_earning_map = {}
+	for d in ss_earnings:
+		ss_earning_map.setdefault(d.parent, webnotes._dict()).setdefault(d.e_type, [])
+		ss_earning_map[d.parent][d.e_type] = flt(d.e_modified_amount)
+	
+	return ss_earning_map
+
+def get_ss_ded_map(salary_slips):
+	ss_deductions = webnotes.conn.sql("""select parent, d_type, d_modified_amount 
+		from `tabSalary Slip Deduction` where parent in (%s)""" %
+		(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]), as_dict=1)
+	
+	ss_ded_map = {}
+	for d in ss_deductions:
+		ss_ded_map.setdefault(d.parent, webnotes._dict()).setdefault(d.d_type, [])
+		ss_ded_map[d.parent][d.e_type] = flt(d.d_modified_amount)
+	
+	return ss_ded_map
\ No newline at end of file
diff --git a/hr/report/monthly_salary_register/monthly_salary_register.txt b/hr/report/monthly_salary_register/monthly_salary_register.txt
new file mode 100644
index 0000000..b0d5880
--- /dev/null
+++ b/hr/report/monthly_salary_register/monthly_salary_register.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-05-07 18:09:42", 
+  "docstatus": 0, 
+  "modified": "2013-05-07 18:09:42", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 1, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Salary Slip", 
+  "report_name": "Monthly Salary Register", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Monthly Salary Register"
+ }
+]
\ No newline at end of file
diff --git a/patches/may_2013/__init__.py b/patches/may_2013/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/patches/may_2013/__init__.py
diff --git a/patches/may_2013/repost_stock_for_no_posting_time.py b/patches/may_2013/repost_stock_for_no_posting_time.py
new file mode 100644
index 0000000..04ceae5
--- /dev/null
+++ b/patches/may_2013/repost_stock_for_no_posting_time.py
@@ -0,0 +1,34 @@
+# 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
+def execute():
+	import webnotes
+	from stock.stock_ledger import update_entries_after
+	
+	res = webnotes.conn.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry` 
+		where posting_time = '00:00'""")
+	
+	i=0
+	for d in res:
+	    try:
+	        update_entries_after({ "item_code": d[0], "warehouse": d[1]	})
+	    except:
+	        pass
+	    i += 1
+	    if i%100 == 0:
+	        webnotes.conn.sql("commit")
+	        webnotes.conn.sql("start transaction")
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index ed1c846..5475d0f 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -250,4 +250,5 @@
 	"patches.april_2013.p07_update_file_data_2",
 	"patches.april_2013.rebuild_sales_browser",
 	"patches.april_2013.p08_price_list_country",
+	"patches.may_2013.repost_stock_for_no_posting_time",
 ]
\ No newline at end of file