[ADD] Department Analytics Bar Chart Feature (#14217)

diff --git a/erpnext/config/hr.py b/erpnext/config/hr.py
index 9e893c0..cd2ddd9 100644
--- a/erpnext/config/hr.py
+++ b/erpnext/config/hr.py
@@ -397,5 +397,16 @@
 					"youtube_id": "5SZHJF--ZFY"
 				}
 			]
+		},
+		{
+			"label": _("Analytics"),
+			"items": [
+				{
+					"type": "report",
+					"is_query_report": True,
+					"name": "Department Analytics",
+					"doctype": "Employee"
+				},
+			]
 		}
 	]
diff --git a/erpnext/hr/report/department_analytics/__init__.py b/erpnext/hr/report/department_analytics/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/report/department_analytics/__init__.py
diff --git a/erpnext/hr/report/department_analytics/department_analytics.js b/erpnext/hr/report/department_analytics/department_analytics.js
new file mode 100644
index 0000000..a0b6fc7
--- /dev/null
+++ b/erpnext/hr/report/department_analytics/department_analytics.js
@@ -0,0 +1,5 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Department Analytics"] = {
+};
\ No newline at end of file
diff --git a/erpnext/hr/report/department_analytics/department_analytics.json b/erpnext/hr/report/department_analytics/department_analytics.json
new file mode 100644
index 0000000..1e26b33
--- /dev/null
+++ b/erpnext/hr/report/department_analytics/department_analytics.json
@@ -0,0 +1,28 @@
+{
+ "add_total_row": 0, 
+ "creation": "2018-05-15 15:37:20.883263", 
+ "disabled": 0, 
+ "docstatus": 0, 
+ "doctype": "Report", 
+ "idx": 0, 
+ "is_standard": "Yes", 
+ "modified": "2018-05-15 17:19:32.934321", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "Department Analytics", 
+ "owner": "Administrator", 
+ "ref_doctype": "Employee", 
+ "report_name": "Department Analytics", 
+ "report_type": "Script Report", 
+ "roles": [
+  {
+   "role": "Employee"
+  }, 
+  {
+   "role": "HR User"
+  }, 
+  {
+   "role": "HR Manager"
+  }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/hr/report/department_analytics/department_analytics.py b/erpnext/hr/report/department_analytics/department_analytics.py
new file mode 100644
index 0000000..c4a9030
--- /dev/null
+++ b/erpnext/hr/report/department_analytics/department_analytics.py
@@ -0,0 +1,60 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+
+def execute(filters=None):
+	if not filters: filters = {}
+	columns = get_columns()
+	employees = get_employees(filters)
+	departments_result = get_department(filters)
+	departments = []
+	if departments_result:
+		for department in departments_result:
+			departments.append(department)
+	chart = get_chart_data(departments,employees)
+	return columns, employees, None, chart
+
+def get_columns():
+	return [
+		_("Employee") + ":Link/Employee:120", _("Name") + ":Data:200", _("Date of Birth")+ ":Date:100",
+		_("Branch") + ":Link/Branch:120", _("Department") + ":Link/Department:120",
+		_("Designation") + ":Link/Designation:120", _("Gender") + "::60", _("Company") + ":Link/Company:120"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	if filters.get("department"): conditions += " and department = '%s'" % \
+		filters["department"].replace("'", "\\'")
+	return conditions
+
+def get_employees(filters):
+	conditions = get_conditions(filters)
+	return frappe.db.sql("""select name, employee_name, date_of_birth,
+	branch, department, designation,
+	gender, company from `tabEmployee` where status = 'Active' %s""" % conditions, as_list=1)
+
+def get_department(filters):
+	return frappe.db.sql("""select name from `tabDepartment`""" , as_list=1)
+	
+def get_chart_data(departments,employees):
+	if not departments:
+		departments = []
+	datasets = []
+	for department in departments:
+		if department:
+			total_employee = frappe.db.sql("""select count(*) from \
+				`tabEmployee` where \
+				department = %s""" ,(department[0]), as_list=1)
+			datasets.append(total_employee[0][0])
+	chart = {
+		"data": {
+			'labels': departments,
+			'datasets': [{'name': 'Employees','values': datasets}]
+		}
+	}
+	chart["type"] = "bar"
+	return chart
+