2018-05-26 03:56:03 +00:00
|
|
|
# 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 = {}
|
2019-11-06 09:11:16 +00:00
|
|
|
|
|
|
|
if not filters["company"]:
|
|
|
|
frappe.throw(_('{0} is mandatory').format(_('Company')))
|
|
|
|
|
2018-05-26 03:56:03 +00:00
|
|
|
columns = get_columns()
|
|
|
|
employees = get_employees(filters)
|
2020-05-13 05:17:36 +00:00
|
|
|
parameters_result = get_parameters(filters)
|
|
|
|
parameters = []
|
|
|
|
if parameters_result:
|
|
|
|
for department in parameters_result:
|
|
|
|
parameters.append(department)
|
|
|
|
|
|
|
|
chart = get_chart_data(parameters,employees, filters)
|
2018-05-26 03:56:03 +00:00
|
|
|
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",
|
2020-05-27 06:56:54 +00:00
|
|
|
_("Designation") + ":Link/Designation:120", _("Gender") + "::100", _("Company") + ":Link/Company:120"
|
2018-05-26 03:56:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
def get_conditions(filters):
|
2020-05-13 05:17:36 +00:00
|
|
|
conditions = " and "+filters.get("parameter").lower().replace(" ","_")+" IS NOT NULL "
|
|
|
|
|
2019-11-06 09:11:16 +00:00
|
|
|
if filters.get("company"): conditions += " and company = '%s'" % \
|
|
|
|
filters["company"].replace("'", "\\'")
|
2018-05-26 03:56:03 +00:00
|
|
|
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)
|
|
|
|
|
2020-05-13 05:17:36 +00:00
|
|
|
def get_parameters(filters):
|
2020-05-27 06:56:54 +00:00
|
|
|
if filters.get("parameter") == "Grade":
|
|
|
|
parameter = "Employee Grade"
|
|
|
|
else:
|
|
|
|
parameter = filters.get("parameter")
|
|
|
|
|
|
|
|
return frappe.db.sql("""select name from `tab"""+ parameter +"""` """, as_list=1)
|
2020-05-13 05:17:36 +00:00
|
|
|
|
|
|
|
def get_chart_data(parameters,employees, filters):
|
|
|
|
if not parameters:
|
|
|
|
parameters = []
|
2018-05-26 03:56:03 +00:00
|
|
|
datasets = []
|
2020-05-13 05:17:36 +00:00
|
|
|
parameter_field_name = filters.get("parameter").lower().replace(" ","_")
|
|
|
|
label = []
|
|
|
|
for parameter in parameters:
|
|
|
|
if parameter:
|
|
|
|
total_employee = frappe.db.sql("""select count(*) from
|
|
|
|
`tabEmployee` where """+
|
|
|
|
parameter_field_name + """ = %s and company = %s""" ,( parameter[0], filters.get("company")), as_list=1)
|
|
|
|
if total_employee[0][0]:
|
|
|
|
label.append(parameter)
|
2018-05-26 03:56:03 +00:00
|
|
|
datasets.append(total_employee[0][0])
|
2020-05-13 05:17:36 +00:00
|
|
|
|
|
|
|
values = [ value for value in datasets if value !=0]
|
|
|
|
|
|
|
|
total_employee = frappe.db.count('Employee', {'status':'Active'})
|
|
|
|
others = total_employee - sum(values)
|
|
|
|
|
2020-05-13 16:17:52 +00:00
|
|
|
label.append(["Not Set"])
|
2020-05-13 05:17:36 +00:00
|
|
|
values.append(others)
|
|
|
|
|
2018-05-26 03:56:03 +00:00
|
|
|
chart = {
|
|
|
|
"data": {
|
2020-05-13 05:17:36 +00:00
|
|
|
'labels': label,
|
|
|
|
'datasets': [{'name': 'Employees','values': values}]
|
2018-05-26 03:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-13 05:17:36 +00:00
|
|
|
chart["type"] = "donut"
|
2018-05-26 03:56:03 +00:00
|
|
|
return chart
|
|
|
|
|