blob: 004477c26cc4e4bae16e0d3fd71710b3ef16831a [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": [
Nabin Hait9d04c062020-05-20 12:05:03 +053027 { "chart": "Outgoing Salary", "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"},
33 { "chart": 'Department Wise Openings', "width": "Half"},
Anurag Mishra36aea712020-05-13 10:47:36 +053034 { "chart": "Attendance Count", "width": "Full"}
35 ],
36 "cards": [
37 {"card": "Total Employees"},
Nabin Hait9d04c062020-05-20 12:05:03 +053038 {"card": "New Joinees (Last year)"},
39 {'card': "Employees Left (Last year)"},
40 {'card': "Total Job Openings (Last month)"},
41 {'card': "Total Applicants (Last month)"},
42 {'card': "Shortlisted Candidates (Last month)"},
43 {'card': "Rejected Candidates (Last month)"},
44 {'card': "Total Job Offered (Last month)"},
Anurag Mishra36aea712020-05-13 10:47:36 +053045 ]
46 }
47
48def get_recruitment_dashboard():
49 pass
Anurag Mishra36aea712020-05-13 10:47:36 +053050
51
52def get_charts():
53 company = erpnext.get_default_company()
Anurag Mishra57bfee82020-05-13 21:47:52 +053054 date = frappe.utils.get_datetime()
55
56 month_map = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"]
57
Anurag Mishra36aea712020-05-13 10:47:36 +053058
59 if not company:
60 company = frappe.db.get_value("Company", {"is_group": 0}, "name")
61
62 dashboard_charts = [
Nabin Hait9d04c062020-05-20 12:05:03 +053063 get_dashboards_chart_doc('Gender Diversity Ratio', "Group By", "Pie",
64 document_type = "Employee", group_by_type="Count", group_by_based_on="gender",
65 filters_json = json.dumps([["Employee", "status", "=", "Active"]]))
Anurag Mishra36aea712020-05-13 10:47:36 +053066 ]
67
68 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053069 get_dashboards_chart_doc('Job Application Status', "Group By", "Pie",
70 document_type = "Job Applicant", group_by_type="Count", group_by_based_on="status",
71 filters_json = json.dumps([["Job Applicant", "creation", "Previous", "1 month"]]))
Anurag Mishra36aea712020-05-13 10:47:36 +053072 )
73
Anurag Mishra36aea712020-05-13 10:47:36 +053074 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053075 get_dashboards_chart_doc('Outgoing Salary', "Sum", "Line",
76 document_type = "Salary Slip", based_on="end_date",
77 value_based_on = "rounded_total", time_interval = "Monthly", timeseries = 1,
78 filters_json = json.dumps([["Salary Slip", "docstatus", "=", 1]]))
Anurag Mishra36aea712020-05-13 10:47:36 +053079 )
Nabin Hait9d04c062020-05-20 12:05:03 +053080
81 custom_options = '''{
82 "type": "line",
83 "axisOptions": {
84 "shortenYAxisNumbers": 1
85 },
86 "tooltipOptions": {}
87 }'''
88
89 filters_json = json.dumps({
90 "month": month_map[date.month - 1],
91 "year": str(date.year),
92 "company":company
93 })
Anurag Mishra36aea712020-05-13 10:47:36 +053094
95 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +053096 get_dashboards_chart_doc('Attendance Count', "Report", "Line",
97 report_name = "Monthly Attendance Sheet", is_custom =1, group_by_type="Count",
98 filters_json = filters_json, custom_options=custom_options)
Anurag Mishra36aea712020-05-13 10:47:36 +053099 )
100
Anurag Mishra57bfee82020-05-13 21:47:52 +0530101 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530102 get_dashboards_chart_doc('Department Wise Employee Count', "Group By", "Donut",
103 document_type = "Employee", group_by_type="Count", group_by_based_on="department",
104 filters_json = json.dumps([["Employee", "status", "=", "Active"]]))
Anurag Mishra57bfee82020-05-13 21:47:52 +0530105 )
Anurag Mishra36aea712020-05-13 10:47:36 +0530106
Anurag Mishra57bfee82020-05-13 21:47:52 +0530107 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530108 get_dashboards_chart_doc('Designation Wise Employee Count', "Group By", "Donut",
109 document_type = "Employee", group_by_type="Count", group_by_based_on="designation",
110 filters_json = json.dumps([["Employee", "status", "=", "Active"]]))
Anurag Mishra57bfee82020-05-13 21:47:52 +0530111 )
112
113 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530114 get_dashboards_chart_doc('Designation Wise Openings', "Group By", "Bar",
115 document_type = "Job Opening", group_by_type="Sum", group_by_based_on="designation",
116 time_interval = "Monthly", aggregate_function_based_on = "planned_vacancies")
Anurag Mishra57bfee82020-05-13 21:47:52 +0530117 )
118 dashboard_charts.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530119 get_dashboards_chart_doc('Department Wise Openings', "Group By", "Bar",
120 document_type = "Job Opening", group_by_type="Sum", group_by_based_on="department",
121 time_interval = "Monthly", aggregate_function_based_on = "planned_vacancies")
Anurag Mishra57bfee82020-05-13 21:47:52 +0530122 )
123 return dashboard_charts
Anurag Mishra36aea712020-05-13 10:47:36 +0530124
125
126def get_number_cards():
127 number_cards = []
128
129 number_cards = [
130 get_number_cards_doc("Employee", "Total Employees", filters_json = json.dumps([
131 ["Employee","status","=","Active"]
132 ])
133 )
134 ]
Anurag Mishra57bfee82020-05-13 21:47:52 +0530135
Anurag Mishra36aea712020-05-13 10:47:36 +0530136 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530137 get_number_cards_doc("Employee", "New Joinees (Last year)", filters_json = json.dumps([
Anurag Mishra57bfee82020-05-13 21:47:52 +0530138 ["Employee","date_of_joining","Previous","1 year"],
Anurag Mishra36aea712020-05-13 10:47:36 +0530139 ["Employee","status","=","Active"]
Anurag Mishra57bfee82020-05-13 21:47:52 +0530140 ])
Anurag Mishra36aea712020-05-13 10:47:36 +0530141 )
Anurag Mishra57bfee82020-05-13 21:47:52 +0530142 )
143
Anurag Mishra36aea712020-05-13 10:47:36 +0530144 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530145 get_number_cards_doc("Employee", "Employees Left (Last year)", filters_json = json.dumps([
146 ["Employee", "modified", "Previous", "1 year"],
147 ["Employee", "status", "=", "Left"]
Anurag Mishra36aea712020-05-13 10:47:36 +0530148 ])
149 )
150 )
Anurag Mishra57bfee82020-05-13 21:47:52 +0530151
Anurag Mishra36aea712020-05-13 10:47:36 +0530152 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530153 get_number_cards_doc("Job Applicant", "Total Applicants (Last month)", filters_json = json.dumps([
154 ["Job Applicant", "creation", "Previous", "1 month"]
Anurag Mishra36aea712020-05-13 10:47:36 +0530155 ])
156 )
157 )
158
Anurag Mishra57bfee82020-05-13 21:47:52 +0530159 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530160 get_number_cards_doc("Job Opening", "Total Job Openings (Last month)", func = "Sum",
161 aggregate_function_based_on = "planned_vacancies",
162 filters_json = json.dumps([["Job Opening", "creation", "Previous", "1 month"]])
Anurag Mishra57bfee82020-05-13 21:47:52 +0530163 )
164 )
165 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530166 get_number_cards_doc("Job Applicant", "Shortlisted Candidates (Last month)", filters_json = json.dumps([
167 ["Job Applicant", "status", "=", "Accepted"],
168 ["Job Applicant", "creation", "Previous", "1 month"]
Anurag Mishra57bfee82020-05-13 21:47:52 +0530169 ])
170 )
171 )
172 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530173 get_number_cards_doc("Job Applicant", "Rejected Candidates (Last month)", filters_json = json.dumps([
174 ["Job Applicant", "status", "=", "Rejected"],
175 ["Job Applicant", "creation", "Previous", "1 month"]
Anurag Mishra57bfee82020-05-13 21:47:52 +0530176 ])
177 )
178 )
179 number_cards.append(
Nabin Hait9d04c062020-05-20 12:05:03 +0530180 get_number_cards_doc("Job Offer", "Total Job Offered (Last month)",
181 filters_json = json.dumps([["Job Offer", "creation", "Previous", "1 month"]])
Anurag Mishra57bfee82020-05-13 21:47:52 +0530182 )
183 )
184
Anurag Mishra36aea712020-05-13 10:47:36 +0530185 return number_cards
186
187
188def get_number_cards_doc(document_type, label, **args):
189 args = frappe._dict(args)
190
191 return {
192 "doctype": "Number Card",
193 "document_type": document_type,
194 "function": args.func or "Count",
195 "is_public": args.is_public or 1,
Nabin Hait9d04c062020-05-20 12:05:03 +0530196 "label": _(label),
Anurag Mishra36aea712020-05-13 10:47:36 +0530197 "name": args.name or label,
198 "show_percentage_stats": args.show_percentage_stats or 1,
199 "stats_time_interval": args.stats_time_interval or 'Monthly',
200 "filters_json": args.filters_json or '[]',
Anurag Mishra57bfee82020-05-13 21:47:52 +0530201 "aggregate_function_based_on": args.aggregate_function_based_on or None
Anurag Mishra36aea712020-05-13 10:47:36 +0530202 }
203
204def get_dashboards_chart_doc(name, chart_type, graph_type, **args):
Anurag Mishra36aea712020-05-13 10:47:36 +0530205 args = frappe._dict(args)
206
207 return {
208 "name": name,
Nabin Hait9d04c062020-05-20 12:05:03 +0530209 "chart_name": _(args.chart_name or name),
Anurag Mishra36aea712020-05-13 10:47:36 +0530210 "chart_type": chart_type,
211 "document_type": args.document_type or None,
212 "report_name": args.report_name or None,
213 "is_custom": args.is_custom or 0,
214 "group_by_type": args.group_by_type or None,
215 "group_by_based_on": args.group_by_based_on or None,
216 "based_on": args.based_on or None,
217 "value_based_on": args.value_based_on or None,
218 "number_of_groups": args.number_of_groups or 0,
219 "is_public": args.is_public or 1,
220 "timespan": args.timespan or "Last Year",
221 "time_interval": args.time_interval or "Yearly",
222 "timeseries": args.timeseries or 0,
223 "filters_json": args.filters_json or '[]',
224 "type": graph_type,
225 "custom_options": args.custom_options or '',
226 "doctype": "Dashboard Chart",
Anurag Mishra57bfee82020-05-13 21:47:52 +0530227 "aggregate_function_based_on": args.aggregate_function_based_on or None
Anurag Mishra36aea712020-05-13 10:47:36 +0530228 }