Merge pull request #5323 from KanchanChauhan/shoppingcart-changes

Shopping cart dropdown changes
diff --git a/erpnext/__version__.py b/erpnext/__version__.py
index 8559b8c..01b41d2 100644
--- a/erpnext/__version__.py
+++ b/erpnext/__version__.py
@@ -1,2 +1,2 @@
 from __future__ import unicode_literals
-__version__ = '6.27.15'
+__version__ = '6.27.16'
diff --git a/erpnext/accounts/doctype/payment_tool/payment_tool.js b/erpnext/accounts/doctype/payment_tool/payment_tool.js
index e15694c..8d8e0ce 100644
--- a/erpnext/accounts/doctype/payment_tool/payment_tool.js
+++ b/erpnext/accounts/doctype/payment_tool/payment_tool.js
@@ -146,6 +146,10 @@
 					c.total_amount = d.invoice_amount;
 					c.outstanding_amount = d.outstanding_amount;
 
+					if (in_list(['Sales Invoice', 'Purchase Invoice'], d.voucher_type)){
+						c.due_date = d.due_date
+					}
+
 					if (frm.doc.set_payment_amount) {
 						c.payment_amount = d.outstanding_amount;
 					}
@@ -202,7 +206,7 @@
 	}
 
 	frappe.call({
-		method: 'erpnext.accounts.doctype.payment_tool.payment_tool.get_against_voucher_amount',
+		method: 'erpnext.accounts.doctype.payment_tool.payment_tool.get_against_voucher_details',
 		args: {
 			"against_voucher_type": row.against_voucher_type,
 			"against_voucher_no": row.against_voucher_no,
diff --git a/erpnext/accounts/doctype/payment_tool/payment_tool.py b/erpnext/accounts/doctype/payment_tool/payment_tool.py
index ef8ffb1..5c5b393 100644
--- a/erpnext/accounts/doctype/payment_tool/payment_tool.py
+++ b/erpnext/accounts/doctype/payment_tool/payment_tool.py
@@ -20,15 +20,15 @@
 		jv.company = self.company
 		jv.cheque_no = self.reference_no
 		jv.cheque_date = self.reference_date
-		
-		party_account_currency, party_account_type = frappe.db.get_value("Account", self.party_account, 
+
+		party_account_currency, party_account_type = frappe.db.get_value("Account", self.party_account,
 			["account_currency", "account_type"])
-		
+
 		bank_account_currency, bank_account_type = None, None
 		if self.payment_account:
-			bank_account_currency, bank_account_type = frappe.db.get_value("Account", self.payment_account, 
+			bank_account_currency, bank_account_type = frappe.db.get_value("Account", self.payment_account,
 				["account_currency", "account_type"])
-		
+
 		if not self.total_payment_amount:
 			frappe.throw(_("Please enter Payment Amount in atleast one row"))
 
@@ -36,11 +36,11 @@
 			if not frappe.db.get_value(v.against_voucher_type, {"name": v.against_voucher_no}):
 				frappe.throw(_("Row {0}: {1} is not a valid {2}").format(v.idx, v.against_voucher_no,
 					v.against_voucher_type))
-			
+
 			if v.payment_amount:
 				exchange_rate = get_exchange_rate(self.party_account, party_account_currency,
 					self.company, v.against_voucher_type, v.against_voucher_no)
-				
+
 				d1 = jv.append("accounts")
 				d1.account = self.party_account
 				d1.party_type = self.party_type
@@ -56,7 +56,7 @@
 				d1.reference_name = v.against_voucher_no
 				d1.is_advance = 'Yes' \
 					if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No'
-					
+
 				amount = flt(d1.debit_in_account_currency) - flt(d1.credit_in_account_currency)
 				if bank_account_currency == party_account_currency:
 					total_payment_amount += amount
@@ -65,27 +65,27 @@
 
 		d2 = jv.append("accounts")
 		if self.payment_account:
-			bank_account_currency, bank_account_type = frappe.db.get_value("Account", self.payment_account, 
+			bank_account_currency, bank_account_type = frappe.db.get_value("Account", self.payment_account,
 				["account_currency", "account_type"])
-				
+
 			d2.account = self.payment_account
 			d2.account_currency = bank_account_currency
 			d2.account_type = bank_account_type
-			d2.exchange_rate = get_exchange_rate(self.payment_account, bank_account_currency, self.company, 
-				debit=(abs(total_payment_amount) if total_payment_amount < 0 else 0), 
+			d2.exchange_rate = get_exchange_rate(self.payment_account, bank_account_currency, self.company,
+				debit=(abs(total_payment_amount) if total_payment_amount < 0 else 0),
 				credit=(total_payment_amount if total_payment_amount > 0 else 0))
 			d2.account_balance = get_balance_on(self.payment_account)
-		
+
 		amount_field_bank = 'debit_in_account_currency' if total_payment_amount < 0 \
 			else 'credit_in_account_currency'
-		
+
 		d2.set(amount_field_bank, abs(total_payment_amount))
-		
+
 		company_currency = frappe.db.get_value("Company", self.company, "default_currency")
 		if party_account_currency != company_currency or \
 			(bank_account_currency and bank_account_currency != company_currency):
 				jv.multi_currency = 1
-			
+
 		jv.set_amounts_in_company_currency()
 		jv.set_total_debit_credit()
 
@@ -150,7 +150,7 @@
 	return order_list
 
 @frappe.whitelist()
-def get_against_voucher_amount(against_voucher_type, against_voucher_no, party_account, company):
+def get_against_voucher_details(against_voucher_type, against_voucher_no, party_account, company):
 	party_account_currency = get_account_currency(party_account)
 	company_currency = frappe.db.get_value("Company", company, "default_currency")
 	ref_field = "base_grand_total" if party_account_currency == company_currency else "grand_total"
diff --git a/erpnext/accounts/doctype/payment_tool_detail/payment_tool_detail.json b/erpnext/accounts/doctype/payment_tool_detail/payment_tool_detail.json
index 765aa93..66447b0 100644
--- a/erpnext/accounts/doctype/payment_tool_detail/payment_tool_detail.json
+++ b/erpnext/accounts/doctype/payment_tool_detail/payment_tool_detail.json
@@ -16,14 +16,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
+   "in_list_view": 0, 
    "label": "Against Voucher Type", 
    "length": 0, 
    "no_copy": 0, 
    "options": "DocType", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "print_width": "", 
    "read_only": 0, 
    "report_hide": 0, 
@@ -41,6 +43,7 @@
    "fieldtype": "Dynamic Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Against Voucher No", 
@@ -49,6 +52,7 @@
    "options": "against_voucher_type", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -60,10 +64,36 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "fieldname": "due_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Due Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
    "fieldname": "column_break_3", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "length": 0, 
@@ -71,6 +101,7 @@
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -86,6 +117,7 @@
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Total Amount", 
@@ -94,6 +126,7 @@
    "options": "party_account_currency", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 1, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -109,6 +142,7 @@
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Outstanding Amount", 
@@ -117,6 +151,7 @@
    "options": "party_account_currency", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 1, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -132,6 +167,7 @@
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Payment Amount", 
@@ -140,6 +176,7 @@
    "options": "party_account_currency", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -150,13 +187,14 @@
  ], 
  "hide_heading": 0, 
  "hide_toolbar": 0, 
+ "idx": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2015-11-16 06:29:51.626386", 
+ "modified": "2016-05-05 06:22:24.736160", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Tool Detail", 
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 06197eb..48668fa 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -473,7 +473,8 @@
 			'posting_date': d.posting_date,
 			'invoice_amount': flt(d.invoice_amount),
 			'payment_amount': flt(d.payment_amount),
-			'outstanding_amount': flt(d.invoice_amount - d.payment_amount, precision)
+			'outstanding_amount': flt(d.invoice_amount - d.payment_amount, precision),
+			'due_date': frappe.db.get_value(d.voucher_type, d.voucher_no, "due_date")
 		})
 
 	return outstanding_invoices
diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py
index 9187706..d5c677c 100644
--- a/erpnext/controllers/sales_and_purchase_return.py
+++ b/erpnext/controllers/sales_and_purchase_return.py
@@ -53,17 +53,18 @@
 
 	valid_items = frappe._dict()
 
-	select_fields = "item_code, sum(qty) as qty, rate" if doc.doctype=="Purchase Invoice" \
-		else "item_code, sum(qty) as qty, rate, serial_no, batch_no"
+	select_fields = "item_code, qty" if doc.doctype=="Purchase Invoice" \
+		else "item_code, qty, serial_no, batch_no"
 
-	for d in frappe.db.sql("""select {0} from `tab{1} Item` where parent = %s
-		group by item_code""".format(select_fields, doc.doctype), doc.return_against, as_dict=1):
-			valid_items.setdefault(d.item_code, d)
+	for d in frappe.db.sql("""select {0} from `tab{1} Item` where parent = %s"""
+		.format(select_fields, doc.doctype), doc.return_against, as_dict=1):
+			valid_items = get_ref_item_dict(valid_items, d)
+			
 
 	if doc.doctype in ("Delivery Note", "Sales Invoice"):
 		for d in frappe.db.sql("""select item_code, sum(qty) as qty, serial_no, batch_no from `tabPacked Item`
 			where parent = %s group by item_code""".format(doc.doctype), doc.return_against, as_dict=1):
-				valid_items.setdefault(d.item_code, d)
+				valid_items = get_ref_item_dict(valid_items, d)
 
 	already_returned_items = get_already_returned_items(doc)
 
@@ -86,7 +87,7 @@
 				elif abs(d.qty) > max_return_qty:
 					frappe.throw(_("Row # {0}: Cannot return more than {1} for Item {2}")
 						.format(d.idx, ref.qty, d.item_code), StockOverReturnError)
-				elif ref.batch_no and d.batch_no != ref.batch_no:
+				elif ref.batch_no and d.batch_no not in ref.batch_no:
 					frappe.throw(_("Row # {0}: Batch No must be same as {1} {2}")
 						.format(d.idx, doc.doctype, doc.return_against))
 				elif ref.serial_no:
@@ -94,9 +95,8 @@
 						frappe.throw(_("Row # {0}: Serial No is mandatory").format(d.idx))
 					else:
 						serial_nos = get_serial_nos(d.serial_no)
-						ref_serial_nos = get_serial_nos(ref.serial_no)
 						for s in serial_nos:
-							if s not in ref_serial_nos:
+							if s not in ref.serial_no:
 								frappe.throw(_("Row # {0}: Serial No {1} does not match with {2} {3}")
 									.format(d.idx, s, doc.doctype, doc.return_against))
 
@@ -107,6 +107,25 @@
 
 	if not items_returned:
 		frappe.throw(_("Atleast one item should be entered with negative quantity in return document"))
+		
+def get_ref_item_dict(valid_items, ref_item_row):
+	from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
+	
+	valid_items.setdefault(ref_item_row.item_code, frappe._dict({
+		"qty": 0,
+		"serial_no": [],
+		"batch_no": []
+	}))
+	item_dict = valid_items[ref_item_row.item_code]
+	item_dict["qty"] += ref_item_row.qty
+	
+	if ref_item_row.get("serial_no"):
+		item_dict["serial_no"] += get_serial_nos(ref_item_row.serial_no)
+		
+	if ref_item_row.get("batch_no"):
+		item_dict["batch_no"].append(ref_item_row.batch_no)
+		
+	return valid_items
 
 def get_already_returned_items(doc):
 	return frappe._dict(frappe.db.sql("""
diff --git a/erpnext/docs/assets/img/setup/email/email-alert-condition.png b/erpnext/docs/assets/img/setup/email/email-alert-condition.png
new file mode 100644
index 0000000..8ede011
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/email/email-alert-condition.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/email/email-alert-subject.png b/erpnext/docs/assets/img/setup/email/email-alert-subject.png
new file mode 100644
index 0000000..671de9b
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/email/email-alert-subject.png
Binary files differ
diff --git a/erpnext/docs/user/manual/en/customize-erpnext/customize-form.md b/erpnext/docs/user/manual/en/customize-erpnext/customize-form.md
index b93d76e..f52cee1 100644
--- a/erpnext/docs/user/manual/en/customize-erpnext/customize-form.md
+++ b/erpnext/docs/user/manual/en/customize-erpnext/customize-form.md
@@ -1,5 +1,5 @@
 <!--markdown-->
-Before we venture to learn form customization tool, click [here](https://frappe.github.io/frappe/user/tutorial/doctypes.html) to understand the architecture of forms in ERPNext. It shall help you in using Customize Form tool more efficiently.
+Before we venture to learn form customization tool, click [here](https://frappe.github.io/frappe/user/en/tutorial/doctypes.html) to understand the architecture of forms in ERPNext. It shall help you in using Customize Form tool more efficiently.
 
 Customize Form is the tool which allows user to customize property of the standard fields, and insert [custom fields]({{docs_base_url}}/user/manual/en/customize-erpnext/custom-field.html) as per the requirement. Let's assume we need to set Project Name field as a mandatory field in the Sales Order form. Following are the steps which shall be followed to achieve this.
 
diff --git a/erpnext/docs/user/manual/en/setting-up/email/email-alerts.md b/erpnext/docs/user/manual/en/setting-up/email/email-alerts.md
index f4cccd3..1a5d13a 100644
--- a/erpnext/docs/user/manual/en/setting-up/email/email-alerts.md
+++ b/erpnext/docs/user/manual/en/setting-up/email/email-alerts.md
@@ -28,6 +28,41 @@
 1. Set the recipients of this alert. The recipient could either be a field of the document or a list of fixed email ids.
 1. Compose the message
 
+
+### Setting a Subject
+You can retrieve the data for a particular field by using `doc.[field_name]`. To use it in your subject / message, you have to surround it with `{{ }}`. These are called [Jinja](http://jinja.pocoo.org/) tags. So, for example to get the name of a document, you use `{{ doc.name }}`. The below example sends an email on saving a Task with the Subject, "TASK##### has been created"
+
+<img class="screenshot" alt="Setting Subject" src="{{docs_base_url}}/assets/img/setup/email/email-alert-subject.png">
+
+### Setting Conditions
+
+Email alerts allow you to set conditions according to the field data in your documents. For example, if you want to recieve an Email if a Lead has been saved as "Interested" as it's status, you put `doc.status == "Interested"` in the conditions textbox. You can also set more complex conditions by combining them.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/email/email-alert-condition.png">
+
+The above example will send an Email Alert when a Task is saved with the status "Open" and the Expected End Date for the Task is the date on or before the date on which it was saved on. 
+
+### Setting a Message
+
+You can use both Jinja Tags (`{{ doc.[field_name] }}`) and HTML tags in the message textbox. 
+
+	<h3>Order Overdue</h3>
+
+	<p>Transaction {{ doc.name }} has exceeded Due Date. Please take necessary action.</p>
+
+	<!-- show last comment -->
+	{% if comments %}
+	Last comment: {{ comments[-1].comment }} by {{ comments[-1].by }}
+	{% endif %}
+
+	<h4>Details</h4>
+
+	<ul>
+	<li>Customer: {{ doc.customer }}
+	<li>Amount: {{ doc.total_amount }}
+	</ul>
+
+
 ---
 
 ### Example
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 2be21d6..1e16c89 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -7,7 +7,7 @@
 app_description = """ERP made simple"""
 app_icon = "icon-th"
 app_color = "#e74c3c"
-app_version = "6.27.15"
+app_version = "6.27.16"
 app_email = "info@erpnext.com"
 app_license = "GNU General Public License (v3)"
 source_link = "https://github.com/frappe/erpnext"
diff --git a/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py b/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
index 061f606..fb58d75 100755
--- a/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
+++ b/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
@@ -21,4 +21,4 @@
 		user_role.role = "Leave Approver"
 		and user_role.parent = user.name and
 		user.name != %s 
-		""", name)
\ No newline at end of file
+		""", name or "")
\ No newline at end of file
diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.js b/erpnext/hr/doctype/hr_settings/hr_settings.js
new file mode 100644
index 0000000..6ab523e
--- /dev/null
+++ b/erpnext/hr/doctype/hr_settings/hr_settings.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('HR Settings', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.json b/erpnext/hr/doctype/hr_settings/hr_settings.json
index 99625fd..561f013 100644
--- a/erpnext/hr/doctype/hr_settings/hr_settings.json
+++ b/erpnext/hr/doctype/hr_settings/hr_settings.json
@@ -16,12 +16,15 @@
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Employee Settings", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -39,13 +42,16 @@
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Employee Records to be created by", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Naming Series\nEmployee Number", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -62,12 +68,15 @@
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Stop Birthday Reminders", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -83,12 +92,15 @@
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Payroll Settings", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -105,12 +117,42 @@
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Include holidays in Total no. of Working Days", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "default": "1", 
+   "description": "Check if you want to send salary slip in mail to each employee while submitting salary slip", 
+   "fieldname": "email_salary_slip_to_employee", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Email Salary Slip to Employee", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -128,7 +170,8 @@
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
- "modified": "2015-02-05 05:11:39.153447", 
+ "max_attachments": 0, 
+ "modified": "2016-04-26 05:54:32.501880", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "HR Settings", 
@@ -156,5 +199,6 @@
   }
  ], 
  "read_only": 0, 
- "read_only_onload": 0
+ "read_only_onload": 0, 
+ "sort_order": "ASC"
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json
index c92fbb8..17e667e 100644
--- a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json
+++ b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json
@@ -15,11 +15,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -33,17 +36,20 @@
    "bold": 0, 
    "collapsible": 0, 
    "description": "Leave blank if considered for all employee types", 
-   "fieldname": "employee_type", 
+   "fieldname": "employment_type", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Employee Type", 
+   "label": "Employment Type", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Employment Type", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -60,13 +66,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Branch", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Branch", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -83,13 +92,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Department", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Department", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -106,13 +118,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Designation", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Designation", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -128,11 +143,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -149,13 +167,16 @@
    "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "From Date", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -171,13 +192,16 @@
    "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "To Date", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -193,13 +217,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Leave Type", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Leave Type", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -216,12 +243,15 @@
    "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Carry Forward", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -237,12 +267,15 @@
    "fieldtype": "Float", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "New Leaves Allocated (In Days)", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -258,13 +291,16 @@
    "fieldtype": "Button", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Allocate", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "allocate_leave", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -282,7 +318,8 @@
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
- "modified": "2015-10-28 16:23:57.733900", 
+ "max_attachments": 0, 
+ "modified": "2016-05-05 05:45:33.355366", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Leave Control Panel", 
diff --git a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py
index 77c7ad9..b4561f1 100644
--- a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py
+++ b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py
@@ -10,27 +10,24 @@
 
 class LeaveControlPanel(Document):
 	def get_employees(self):
-		lst1 = [[self.employee_type,"employment_type"],[self.branch,"branch"],[self.designation,"designation"],[self.department, "department"]]
-		condition = "where "
-		flag = 0
-		for l in lst1:
-			if(l[0]):
-				if flag == 0:
-					condition += l[1] + "= '" + l[0] +"'"
-				else:
-					condition += " and " + l[1]+ "= '" +l[0] +"'"
-				flag = 1
-		emp_query = "select name from `tabEmployee` "
-		if flag == 1:
-			emp_query += condition
-		e = frappe.db.sql(emp_query)
+		conditions, values = [], []
+		for field in ["employment_type", "branch", "designation", "department"]:
+			if self.get(field):
+				conditions.append("{0}=%s".format(field))
+				values.append(self.get(field))
+
+		condition_str = " and " + " and ".join(conditions) if len(conditions) else ""
+
+		e = frappe.db.sql("select name from tabEmployee where status='Active' {condition}"
+			.format(condition=condition_str), tuple(values))
+
 		return e
 
 	def validate_values(self):
 		for f in ["from_date", "to_date", "leave_type", "no_of_days"]:
 			if not self.get(f):
 				frappe.throw(_("{0} is required").format(self.meta.get_label(f)))
-	
+
 	def to_date_validation(self):
 		if date_diff(self.to_date, self.from_date) <= 0:
 			return "Invalid period"
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.json b/erpnext/hr/doctype/process_payroll/process_payroll.json
index 3bd298e..e3f16a5 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.json
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.json
@@ -16,12 +16,15 @@
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Select Employees", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -37,11 +40,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -58,13 +64,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Company", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Company", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -80,35 +89,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
    "label": "Branch", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Branch", 
    "permlevel": 0, 
    "print_hide": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "description": "Check if you want to send salary slip in mail to each employee while submitting salary slip", 
-   "fieldname": "send_email", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Send Email", 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -124,11 +114,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -145,13 +138,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Department", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Department", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -167,13 +163,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Designation", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Designation", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -189,13 +188,16 @@
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Select Payroll Year and Month", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -211,13 +213,16 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Fiscal Year", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "Fiscal Year", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -233,12 +238,15 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -254,13 +262,16 @@
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Month", 
+   "length": 0, 
    "no_copy": 0, 
    "options": "\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12", 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
@@ -276,13 +287,16 @@
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Process Payroll", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -298,11 +312,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -320,12 +337,15 @@
    "fieldtype": "Button", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Create Salary Slip", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -341,11 +361,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -363,12 +386,15 @@
    "fieldtype": "Button", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Submit Salary Slip", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -384,11 +410,14 @@
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -406,12 +435,15 @@
    "fieldtype": "Button", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Make Bank Entry", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -427,11 +459,14 @@
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -447,12 +482,15 @@
    "fieldtype": "HTML", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "label": "Activity Log", 
+   "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -470,7 +508,8 @@
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
- "modified": "2015-07-07 07:16:02.380839", 
+ "max_attachments": 0, 
+ "modified": "2016-04-26 07:22:41.792785", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Process Payroll", 
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py
index 51e3740..de41530 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.py
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.py
@@ -70,7 +70,6 @@
 					"fiscal_year": self.fiscal_year,
 					"employee": emp[0],
 					"month": self.month,
-					"email_check": self.send_email,
 					"company": self.company,
 				})
 				ss.insert()
@@ -109,7 +108,6 @@
 		for ss in ss_list:
 			ss_obj = frappe.get_doc("Salary Slip",ss[0])
 			try:
-				ss_obj.email_check = self.send_email
 				ss_obj.submit()
 			except Exception,e:
 				not_submitted_ss.append(ss[0])
@@ -128,11 +126,9 @@
 
 		submitted_ss = self.format_as_links(list(set(all_ss) - set(not_submitted_ss)))
 		if submitted_ss:
-			mail_sent_msg = self.send_email and " (Mail has been sent to the employee)" or ""
 			log = """
-			<b>Salary Slips Submitted %s:</b>\
-			<br><br> %s <br><br>
-			""" % (mail_sent_msg, '<br>'.join(submitted_ss))
+				<b>Salary Slips Submitted:</b> <br><br>%s
+				""" % ('<br>'.join(submitted_ss))
 
 		if not_submitted_ss:
 			log += """
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.json b/erpnext/hr/doctype/salary_slip/salary_slip.json
index 76ad96e..a31e7b0 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.json
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.json
@@ -431,32 +431,6 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "email_check", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Email", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "email_check", 
-   "oldfieldtype": "Check", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 1, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -880,8 +854,8 @@
  "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
- "max_attachments": 0, 
- "modified": "2016-04-06 03:10:12.181480", 
+ "max_attachments": 0,
+ "modified": "2016-04-26 06:02:06.940543", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Slip", 
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index 63147d5..0c1f8c8 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -204,15 +204,17 @@
 			self.precision("net_pay") if disable_rounded_total else 0)
 
 	def on_submit(self):
-		if(self.email_check == 1):
-			self.send_mail_funct()
+		if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")):
+			self.email_salary_slip()
 
 
-	def send_mail_funct(self):
-		receiver = frappe.db.get_value("Employee", self.employee, "company_email")
+	def email_salary_slip(self):
+		receiver = frappe.db.get_value("Employee", self.employee, "company_email") or \
+			frappe.db.get_value("Employee", self.employee, "personal_email")
 		if receiver:
 			subj = 'Salary Slip - ' + cstr(self.month) +'/'+cstr(self.fiscal_year)
 			frappe.sendmail([receiver], subject=subj, message = _("Please see attachment"),
-				attachments=[frappe.attach_print(self.doctype, self.name, file_name=self.name)])
+				attachments=[frappe.attach_print(self.doctype, self.name, file_name=self.name)], 
+				bulk=True, reference_doctype= self.doctype, reference_name= self.name)
 		else:
-			msgprint(_("Company Email ID not found, hence mail not sent"))
+			msgprint(_("{0}: Employee email not found, hence email not sent").format(self.employee_name))
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 2383aff..106b8a2 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -96,6 +96,19 @@
 
 		frappe.set_user("test_employee@example.com")
 		self.assertTrue(salary_slip_test_employee.has_permission("read"))
+		
+	def test_email_salary_slip(self):
+		frappe.db.sql("delete from `tabBulk Email`")
+
+		hr_settings = frappe.get_doc("HR Settings", "HR Settings")
+		hr_settings.email_salary_slip_to_employee = 1
+		hr_settings.save()
+		
+		self.make_employee("test_employee@example.com")
+		self.make_employee_salary_slip("test_employee@example.com")
+		bulk_mails = frappe.db.sql("""select name from `tabBulk Email`""")
+		self.assertTrue(bulk_mails)
+		
 
 	def make_employee(self, user):
 		if not frappe.db.get_value("User", user):
@@ -118,6 +131,7 @@
 				"date_of_joining": "2013-01-01",
 				"department": "_Test Department 1",
 				"gender": "Female",
+				"company_email": user,
 				"status": "Active"
 			}).insert()
 
diff --git a/erpnext/public/js/conf.js b/erpnext/public/js/conf.js
index 1191c47..d8133ce 100644
--- a/erpnext/public/js/conf.js
+++ b/erpnext/public/js/conf.js
@@ -15,6 +15,7 @@
 			frappe.urllib.get_base_url()+'/assets/erpnext/images/erp-icon.svg" />');
 
 	$('[data-link="docs"]').attr("href", "https://manual.erpnext.com")
+	$('[data-link="issues"]').attr("href", "https://github.com/frappe/erpnext/issues")
 });
 
 // doctypes created via tree
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index d3fa482..ed67322 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -215,6 +215,8 @@
 		stock_value_change = 0
 		if incoming_rate:
 			stock_value_change = actual_qty * incoming_rate
+		elif flt(sle.outgoing_rate):
+			stock_value_change = actual_qty * flt(sle.outgoing_rate)
 		elif actual_qty < 0:
 			# In case of delivery/stock issue, get average purchase rate
 			# of serial nos of current entry
diff --git a/setup.py b/setup.py
index fb914f8..ce447d5 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 from pip.req import parse_requirements
 
-version = "6.27.15"
+version = "6.27.16"
 requirements = parse_requirements("requirements.txt", session="")
 
 setup(