Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/hr/doctype/appraisal/appraisal.js b/hr/doctype/appraisal/appraisal.js
index 3601da9..11fa328 100644
--- a/hr/doctype/appraisal/appraisal.js
+++ b/hr/doctype/appraisal/appraisal.js
@@ -92,3 +92,5 @@
 	doc.total_score = flt(total);
 	refresh_field('total_score');
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/attendance/attendance.js b/hr/doctype/attendance/attendance.js
index 120a50e..3ba9868 100644
--- a/hr/doctype/attendance/attendance.js
+++ b/hr/doctype/attendance/attendance.js
@@ -22,9 +22,4 @@
 	refresh_field('employee_name'); 
 }
 
-
-//Employee
-//-----------------------------
-cur_frm.fields_dict['employee'].get_query = function(doc,cdt,cdn) {
-	return 'SELECT `tabEmployee`.`name`, `tabEmployee`.`employee_name` FROM `tabEmployee` WHERE `tabEmployee`.status = "Active" AND `tabEmployee`.`docstatus`!= 2 AND (`tabEmployee`.`employee_name` LIKE "%s" OR `tabEmployee`.`%(key)s` LIKE "%s") ORDER BY `tabEmployee`.`name` ASC LIMIT 50';
-}
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/employee/employee.js b/hr/doctype/employee/employee.js
index 75866c5..eab90cb 100644
--- a/hr/doctype/employee/employee.js
+++ b/hr/doctype/employee/employee.js
@@ -65,4 +65,6 @@
 	loaddoc('Salary Structure', st.name);
 }
 
-cur_frm.fields_dict.user_id.get_query = erpnext.utils.profile_query;
\ No newline at end of file
+cur_frm.fields_dict.user_id.get_query = erpnext.utils.profile_query;
+
+cur_frm.fields_dict.reports_to.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/expense_claim/expense_claim.js b/hr/doctype/expense_claim/expense_claim.js
index d8bee8b..5ed0d37 100644
--- a/hr/doctype/expense_claim/expense_claim.js
+++ b/hr/doctype/expense_claim/expense_claim.js
@@ -255,3 +255,5 @@
 	}
 	cur_frm.cscript.notify(doc, args);
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/leave_allocation/leave_allocation.js b/hr/doctype/leave_allocation/leave_allocation.js
index bce7af3..a26d211 100755
--- a/hr/doctype/leave_allocation/leave_allocation.js
+++ b/hr/doctype/leave_allocation/leave_allocation.js
@@ -78,3 +78,5 @@
     set_multiple(dt,dn,{carry_forwarded_leaves : 0,total_leaves_allocated : flt(doc.new_leaves_allocated)});
   }
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/leave_application/leave_application.js b/hr/doctype/leave_application/leave_application.js
index b7524c8..e8952ca 100755
--- a/hr/doctype/leave_application/leave_application.js
+++ b/hr/doctype/leave_application/leave_application.js
@@ -99,3 +99,5 @@
     }
   }
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/salary_slip/salary_slip.js b/hr/doctype/salary_slip/salary_slip.js
index 3e61665..fc58271 100644
--- a/hr/doctype/salary_slip/salary_slip.js
+++ b/hr/doctype/salary_slip/salary_slip.js
@@ -138,3 +138,5 @@
 cur_frm.cscript.validate = function(doc, dt, dn) {
 	calculate_all(doc, dt, dn);
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/salary_structure/salary_structure.js b/hr/doctype/salary_structure/salary_structure.js
index 27ed19e..3692fe8 100644
--- a/hr/doctype/salary_structure/salary_structure.js
+++ b/hr/doctype/salary_structure/salary_structure.js
@@ -107,3 +107,5 @@
 cur_frm.cscript.validate = function(doc, cdt, cdn) {
   calculate_totals(doc, cdt, cdn);
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/public/js/utils.js b/public/js/utils.js
index 76a443a..b84e293 100644
--- a/public/js/utils.js
+++ b/public/js/utils.js
@@ -22,5 +22,13 @@
 		from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
 		name not in ('Administrator', 'Guest') and (%(key)s like \"%s\" or \
 		concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
-		limit 50";
+		order by name asc limit 50";
+};
+
+// employee related get query
+erpnext.utils.employee_query = function() {
+	return "select name, employee_name from `tabEmployee` \
+		where status = 'Active' and docstatus < 2 and \
+		(employee_name like \"%%%s\" or %(key)s like \"%s\") \
+		order by name asc limit 50";
 };
\ No newline at end of file
diff --git a/setup/doctype/authorization_rule/authorization_rule.js b/setup/doctype/authorization_rule/authorization_rule.js
index 8bec206..b29d889 100644
--- a/setup/doctype/authorization_rule/authorization_rule.js
+++ b/setup/doctype/authorization_rule/authorization_rule.js
@@ -85,9 +85,9 @@
 }
 
 
-cur_frm.fields_dict.system_user.get_query = erpnext.profile_query;
+cur_frm.fields_dict.system_user.get_query = erpnext.utils.profile_query;
 
-cur_frm.fields_dict.approving_user.get_query = erpnext.profile_query;
+cur_frm.fields_dict.approving_user.get_query = erpnext.utils.profile_query;
 
 // System Role Trigger
 // -----------------------
@@ -112,3 +112,5 @@
   else
     return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE `tabItem`.`name` = "cheating done to avoid null" ORDER BY `tabItem`.`name` DESC LIMIT 50';
 }
+
+cur_frm.fields_dict.to_emp.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/setup/doctype/sales_person/sales_person.js b/setup/doctype/sales_person/sales_person.js
index 008d30d..ba1a339 100644
--- a/setup/doctype/sales_person/sales_person.js
+++ b/setup/doctype/sales_person/sales_person.js
@@ -38,12 +38,8 @@
   return 'SELECT `tabSales Person`.`name`,`tabSales Person`.`parent_sales_person` FROM `tabSales Person` WHERE `tabSales Person`.`is_group` = "Yes" AND `tabSales Person`.`docstatus`!= 2 AND `tabSales Person`.`name` !="'+doc.sales_person_name+'" AND `tabSales Person`.%(key)s LIKE "%s" ORDER BY  `tabSales Person`.`name` ASC LIMIT 50';
 }
 
-//get query select Territory
-cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
-  return 'SELECT `tabTerritory`.`name` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY  `tabTerritory`.`name` ASC LIMIT 50';
-}
-
-// ******************** ITEM Group ******************************** 
 cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) {
   return 'SELECT `tabItem Group`.name FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50'
 }
+
+cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file