blob: 6d8091be647bca87872e408c2210cda318ff67d4 [file] [log] [blame]
Anurag Mishra36aea712020-05-13 10:47:36 +05301# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4import frappe
5import erpnext
6import json
Nabin Hait9d04c062020-05-20 12:05:03 +05307from frappe import _
Anurag Mishra36aea712020-05-13 10:47:36 +05308
9def get_data():
10 return frappe._dict({
11 "dashboards": get_dashboards(),
12 "charts": get_charts(),
13 "number_cards": get_number_cards(),
14 })
15
16def get_dashboards():
17 dashboards = []
18 dashboards.append(get_human_resource_dashboard())
19 return dashboards
20
21def get_human_resource_dashboard():
22 return {
23 "name": "Human Resource",
24 "dashboard_name": "Human Resource",
25 "is_default": 1,
26 "charts": [
Anurag Mishra289c8222020-06-19 19:17:57 +053027 { "chart": "Attendance Count", "width": "Full"},
Anurag Mishra36aea712020-05-13 10:47:36 +053028 { "chart": "Gender Diversity Ratio", "width": "Half"},
Anurag Mishra57bfee82020-05-13 21:47:52 +053029 { "chart": "Job Application Status", "width": "Half"},
30 { "chart": 'Designation Wise Employee Count', "width": "Half"},
31 { "chart": 'Department Wise Employee Count', "width": "Half"},
32 { "chart": 'Designation Wise Openings', "width": "Half"},
Anurag Mishra289c8222020-06-19 19:17:57 +053033 { "chart": 'Department Wise Openings', "width": "Half"}
Anurag Mishra36aea712020-05-13 10:47:36 +053034 ],
35 "cards": [
36 {"card": "Total Employees"},
Nabin Hait9d04c062020-05-20 12:05:03 +053037 {"card": "New Joinees (Last year)"},
38 {'card': "Employees Left (Last year)"},
Nabin Hait9d04c062020-05-20 12:05:03 +053039 {'card': "Total Applicants (Last month)"},
Anurag Mishra36aea712020-05-13 10:47:36 +053040 ]
41 }
42
43def get_recruitment_dashboard():
44 pass
Anurag Mishra36aea712020-05-13 10:47:36 +053045
46
47def get_charts():
48 company = erpnext.get_default_company()
Anurag Mishra57bfee82020-05-13 21:47:52 +053049 date = frappe.utils.get_datetime()
50
51 month_map = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"]
52
Anurag Mishra36aea712020-05-13 10:47:36 +053053
54 if not company:
55 company = frappe.db.get_value("Company", {"is_group": 0}, "name")
56
57 dashboard_charts = [
Nabin Hait9d04c062020-05-20 12:05:03 +053058 get_dashboards_chart_doc('Gender Diversity Ratio', "Group By", "Pie",
59 document_type = "Employee", group_by_type="Count", group_by_based_on="gender",
60 filters_json = json.dumps([["Employee", "status", "=", "Active"]]))
Anurag Mishra36aea712020-05-13 10:47:36 +053061 ]
62
63 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053064 get_dashboards_chart_doc('Job Application Status', "Group By", "Pie",
65 document_type = "Job Applicant", group_by_type="Count", group_by_based_on="status",
66 filters_json = json.dumps([["Job Applicant", "creation", "Previous", "1 month"]]))
Anurag Mishra36aea712020-05-13 10:47:36 +053067 )
68
Nabin Hait9d04c062020-05-20 12:05:03 +053069 custom_options = '''{
70 "type": "line",
71 "axisOptions": {
72 "shortenYAxisNumbers": 1
73 },
74 "tooltipOptions": {}
75 }'''
76
77 filters_json = json.dumps({
78 "month": month_map[date.month - 1],
79 "year": str(date.year),
80 "company":company
81 })
Anurag Mishra36aea712020-05-13 10:47:36 +053082
83 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053084 get_dashboards_chart_doc('Attendance Count', "Report", "Line",
85 report_name = "Monthly Attendance Sheet", is_custom =1, group_by_type="Count",
86 filters_json = filters_json, custom_options=custom_options)
Anurag Mishra36aea712020-05-13 10:47:36 +053087 )
88
Anurag Mishra57bfee82020-05-13 21:47:52 +053089 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053090 get_dashboards_chart_doc('Department Wise Employee Count', "Group By", "Donut",
91 document_type = "Employee", group_by_type="Count", group_by_based_on="department",
92 filters_json = json.dumps([["Employee", "status", "=", "Active"]]))
Anurag Mishra57bfee82020-05-13 21:47:52 +053093 )
Anurag Mishra36aea712020-05-13 10:47:36 +053094
Anurag Mishra57bfee82020-05-13 21:47:52 +053095 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053096 get_dashboards_chart_doc('Designation Wise Employee Count', "Group By", "Donut",
97 document_type = "Employee", group_by_type="Count", group_by_based_on="designation",
98 filters_json = json.dumps([["Employee", "status", "=", "Active"]]))
Anurag Mishra57bfee82020-05-13 21:47:52 +053099 )
100
101 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530102 get_dashboards_chart_doc('Designation Wise Openings', "Group By", "Bar",
103 document_type = "Job Opening", group_by_type="Sum", group_by_based_on="designation",
104 time_interval = "Monthly", aggregate_function_based_on = "planned_vacancies")
Anurag Mishra57bfee82020-05-13 21:47:52 +0530105 )
106 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530107 get_dashboards_chart_doc('Department Wise Openings', "Group By", "Bar",
108 document_type = "Job Opening", group_by_type="Sum", group_by_based_on="department",
109 time_interval = "Monthly", aggregate_function_based_on = "planned_vacancies")
Anurag Mishra57bfee82020-05-13 21:47:52 +0530110 )
111 return dashboard_charts
Anurag Mishra36aea712020-05-13 10:47:36 +0530112
113
114def get_number_cards():
115 number_cards = []
116
117 number_cards = [
118 get_number_cards_doc("Employee", "Total Employees", filters_json = json.dumps([
119 ["Employee","status","=","Active"]
120 ])
121 )
122 ]
Anurag Mishra57bfee82020-05-13 21:47:52 +0530123
Anurag Mishra36aea712020-05-13 10:47:36 +0530124 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530125 get_number_cards_doc("Employee", "New Joinees (Last year)", filters_json = json.dumps([
Anurag Mishra57bfee82020-05-13 21:47:52 +0530126 ["Employee","date_of_joining","Previous","1 year"],
Anurag Mishra36aea712020-05-13 10:47:36 +0530127 ["Employee","status","=","Active"]
Anurag Mishra57bfee82020-05-13 21:47:52 +0530128 ])
Anurag Mishra36aea712020-05-13 10:47:36 +0530129 )
Anurag Mishra57bfee82020-05-13 21:47:52 +0530130 )
131
Anurag Mishra36aea712020-05-13 10:47:36 +0530132 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530133 get_number_cards_doc("Employee", "Employees Left (Last year)", filters_json = json.dumps([
Anurag Mishracf016862020-05-29 10:19:33 +0530134 ["Employee", "relieving_date", "Previous", "1 year"],
Nabin Hait9d04c062020-05-20 12:05:03 +0530135 ["Employee", "status", "=", "Left"]
Anurag Mishra36aea712020-05-13 10:47:36 +0530136 ])
137 )
138 )
Anurag Mishra57bfee82020-05-13 21:47:52 +0530139
Anurag Mishra36aea712020-05-13 10:47:36 +0530140 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530141 get_number_cards_doc("Job Applicant", "Total Applicants (Last month)", filters_json = json.dumps([
142 ["Job Applicant", "creation", "Previous", "1 month"]
Anurag Mishra36aea712020-05-13 10:47:36 +0530143 ])
144 )
145 )
146
147 return number_cards
148
149
150def get_number_cards_doc(document_type, label, **args):
151 args = frappe._dict(args)
152
153 return {
154 "doctype": "Number Card",
155 "document_type": document_type,
156 "function": args.func or "Count",
157 "is_public": args.is_public or 1,
Nabin Hait9d04c062020-05-20 12:05:03 +0530158 "label": _(label),
Anurag Mishra36aea712020-05-13 10:47:36 +0530159 "name": args.name or label,
160 "show_percentage_stats": args.show_percentage_stats or 1,
161 "stats_time_interval": args.stats_time_interval or 'Monthly',
162 "filters_json": args.filters_json or '[]',
Anurag Mishra57bfee82020-05-13 21:47:52 +0530163 "aggregate_function_based_on": args.aggregate_function_based_on or None
Anurag Mishra36aea712020-05-13 10:47:36 +0530164 }
165
166def get_dashboards_chart_doc(name, chart_type, graph_type, **args):
Anurag Mishra36aea712020-05-13 10:47:36 +0530167 args = frappe._dict(args)
168
169 return {
170 "name": name,
Nabin Hait9d04c062020-05-20 12:05:03 +0530171 "chart_name": _(args.chart_name or name),
Anurag Mishra36aea712020-05-13 10:47:36 +0530172 "chart_type": chart_type,
173 "document_type": args.document_type or None,
174 "report_name": args.report_name or None,
175 "is_custom": args.is_custom or 0,
176 "group_by_type": args.group_by_type or None,
177 "group_by_based_on": args.group_by_based_on or None,
178 "based_on": args.based_on or None,
179 "value_based_on": args.value_based_on or None,
180 "number_of_groups": args.number_of_groups or 0,
181 "is_public": args.is_public or 1,
182 "timespan": args.timespan or "Last Year",
183 "time_interval": args.time_interval or "Yearly",
184 "timeseries": args.timeseries or 0,
185 "filters_json": args.filters_json or '[]',
186 "type": graph_type,
187 "custom_options": args.custom_options or '',
188 "doctype": "Dashboard Chart",
Anurag Mishra57bfee82020-05-13 21:47:52 +0530189 "aggregate_function_based_on": args.aggregate_function_based_on or None
Anurag Mishra36aea712020-05-13 10:47:36 +0530190 }