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

This commit is contained in:
Solufyin 2018-05-26 09:26:03 +05:30 committed by Nabin Hait
parent 089a41c679
commit 64d02f917a
5 changed files with 104 additions and 0 deletions

View File

@ -397,5 +397,16 @@ def get_data():
"youtube_id": "5SZHJF--ZFY"
}
]
},
{
"label": _("Analytics"),
"items": [
{
"type": "report",
"is_query_report": True,
"name": "Department Analytics",
"doctype": "Employee"
},
]
}
]

View File

@ -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"] = {
};

View File

@ -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"
}
]
}

View File

@ -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