Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 1 | # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | import frappe |
| 5 | import erpnext |
| 6 | import json |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 7 | from frappe import _ |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 8 | |
| 9 | def get_data(): |
| 10 | return frappe._dict({ |
| 11 | "dashboards": get_dashboards(), |
| 12 | "charts": get_charts(), |
| 13 | "number_cards": get_number_cards(), |
| 14 | }) |
| 15 | |
| 16 | def get_dashboards(): |
| 17 | dashboards = [] |
| 18 | dashboards.append(get_human_resource_dashboard()) |
| 19 | return dashboards |
| 20 | |
| 21 | def get_human_resource_dashboard(): |
| 22 | return { |
| 23 | "name": "Human Resource", |
| 24 | "dashboard_name": "Human Resource", |
| 25 | "is_default": 1, |
| 26 | "charts": [ |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 27 | { "chart": "Outgoing Salary", "width": "Full"}, |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 28 | { "chart": "Gender Diversity Ratio", "width": "Half"}, |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 29 | { "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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 34 | { "chart": "Attendance Count", "width": "Full"} |
| 35 | ], |
| 36 | "cards": [ |
| 37 | {"card": "Total Employees"}, |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 38 | {"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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 45 | ] |
| 46 | } |
| 47 | |
| 48 | def get_recruitment_dashboard(): |
| 49 | pass |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def get_charts(): |
| 53 | company = erpnext.get_default_company() |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 54 | date = frappe.utils.get_datetime() |
| 55 | |
| 56 | month_map = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"] |
| 57 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 58 | |
| 59 | if not company: |
| 60 | company = frappe.db.get_value("Company", {"is_group": 0}, "name") |
| 61 | |
| 62 | dashboard_charts = [ |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 63 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 66 | ] |
| 67 | |
| 68 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 69 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 72 | ) |
| 73 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 74 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 75 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 79 | ) |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 80 | |
| 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 94 | |
| 95 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 96 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 99 | ) |
| 100 | |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 101 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 102 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 105 | ) |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 106 | |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 107 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 108 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 111 | ) |
| 112 | |
| 113 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 114 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 117 | ) |
| 118 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 119 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 122 | ) |
| 123 | return dashboard_charts |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 124 | |
| 125 | |
| 126 | def 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 135 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 136 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 137 | get_number_cards_doc("Employee", "New Joinees (Last year)", filters_json = json.dumps([ |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 138 | ["Employee","date_of_joining","Previous","1 year"], |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 139 | ["Employee","status","=","Active"] |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 140 | ]) |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 141 | ) |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 142 | ) |
| 143 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 144 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 145 | get_number_cards_doc("Employee", "Employees Left (Last year)", filters_json = json.dumps([ |
| 146 | ["Employee", "modified", "Previous", "1 year"], |
| 147 | ["Employee", "status", "=", "Left"] |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 148 | ]) |
| 149 | ) |
| 150 | ) |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 151 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 152 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 153 | get_number_cards_doc("Job Applicant", "Total Applicants (Last month)", filters_json = json.dumps([ |
| 154 | ["Job Applicant", "creation", "Previous", "1 month"] |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 155 | ]) |
| 156 | ) |
| 157 | ) |
| 158 | |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 159 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 160 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 163 | ) |
| 164 | ) |
| 165 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 166 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 169 | ]) |
| 170 | ) |
| 171 | ) |
| 172 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 173 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 176 | ]) |
| 177 | ) |
| 178 | ) |
| 179 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 180 | get_number_cards_doc("Job Offer", "Total Job Offered (Last month)", |
| 181 | filters_json = json.dumps([["Job Offer", "creation", "Previous", "1 month"]]) |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 182 | ) |
| 183 | ) |
| 184 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 185 | return number_cards |
| 186 | |
| 187 | |
| 188 | def 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 Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 196 | "label": _(label), |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 197 | "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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 201 | "aggregate_function_based_on": args.aggregate_function_based_on or None |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | def get_dashboards_chart_doc(name, chart_type, graph_type, **args): |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 205 | args = frappe._dict(args) |
| 206 | |
| 207 | return { |
| 208 | "name": name, |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 209 | "chart_name": _(args.chart_name or name), |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 210 | "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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 227 | "aggregate_function_based_on": args.aggregate_function_based_on or None |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 228 | } |