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": [ |
Anurag Mishra | 289c822 | 2020-06-19 19:17:57 +0530 | [diff] [blame] | 27 | { "chart": "Attendance Count", "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"}, |
Anurag Mishra | 289c822 | 2020-06-19 19:17:57 +0530 | [diff] [blame] | 33 | { "chart": 'Department Wise Openings', "width": "Half"} |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 34 | ], |
| 35 | "cards": [ |
| 36 | {"card": "Total Employees"}, |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 37 | {"card": "New Joinees (Last year)"}, |
| 38 | {'card': "Employees Left (Last year)"}, |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 39 | {'card': "Total Applicants (Last month)"}, |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 40 | ] |
| 41 | } |
| 42 | |
| 43 | def get_recruitment_dashboard(): |
| 44 | pass |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 45 | |
| 46 | |
| 47 | def get_charts(): |
| 48 | company = erpnext.get_default_company() |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 49 | date = frappe.utils.get_datetime() |
| 50 | |
| 51 | month_map = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"] |
| 52 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 53 | |
| 54 | if not company: |
| 55 | company = frappe.db.get_value("Company", {"is_group": 0}, "name") |
| 56 | |
| 57 | dashboard_charts = [ |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 58 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 61 | ] |
| 62 | |
| 63 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 64 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 67 | ) |
| 68 | |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 69 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 82 | |
| 83 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 84 | 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 Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 87 | ) |
| 88 | |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 89 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 90 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 93 | ) |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 94 | |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 95 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 96 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 99 | ) |
| 100 | |
| 101 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 102 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 105 | ) |
| 106 | dashboard_charts.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 107 | 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 110 | ) |
| 111 | return dashboard_charts |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 112 | |
| 113 | |
| 114 | def 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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 123 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 124 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 125 | 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] | 126 | ["Employee","date_of_joining","Previous","1 year"], |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 127 | ["Employee","status","=","Active"] |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 128 | ]) |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 129 | ) |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 130 | ) |
| 131 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 132 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 133 | get_number_cards_doc("Employee", "Employees Left (Last year)", filters_json = json.dumps([ |
Anurag Mishra | cf01686 | 2020-05-29 10:19:33 +0530 | [diff] [blame] | 134 | ["Employee", "relieving_date", "Previous", "1 year"], |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 135 | ["Employee", "status", "=", "Left"] |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 136 | ]) |
| 137 | ) |
| 138 | ) |
Anurag Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 139 | |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 140 | number_cards.append( |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 141 | get_number_cards_doc("Job Applicant", "Total Applicants (Last month)", filters_json = json.dumps([ |
| 142 | ["Job Applicant", "creation", "Previous", "1 month"] |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 143 | ]) |
| 144 | ) |
| 145 | ) |
| 146 | |
| 147 | return number_cards |
| 148 | |
| 149 | |
| 150 | def 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 Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 158 | "label": _(label), |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 159 | "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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 163 | "aggregate_function_based_on": args.aggregate_function_based_on or None |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | def get_dashboards_chart_doc(name, chart_type, graph_type, **args): |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 167 | args = frappe._dict(args) |
| 168 | |
| 169 | return { |
| 170 | "name": name, |
Nabin Hait | 9d04c06 | 2020-05-20 12:05:03 +0530 | [diff] [blame] | 171 | "chart_name": _(args.chart_name or name), |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 172 | "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 Mishra | 57bfee8 | 2020-05-13 21:47:52 +0530 | [diff] [blame] | 189 | "aggregate_function_based_on": args.aggregate_function_based_on or None |
Anurag Mishra | 36aea71 | 2020-05-13 10:47:36 +0530 | [diff] [blame] | 190 | } |