Merge pull request #18958 from surajshetty3416/employee-leave-balance-summary

feat: Employee Leave Balance Summary report
diff --git a/erpnext/hr/report/employee_leave_balance_summary/__init__.py b/erpnext/hr/report/employee_leave_balance_summary/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/report/employee_leave_balance_summary/__init__.py
diff --git a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js
new file mode 100644
index 0000000..838f4ad
--- /dev/null
+++ b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js
@@ -0,0 +1,36 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+/* eslint-disable */
+
+frappe.query_reports['Employee Leave Balance Summary'] = {
+	filters: [
+		{
+			fieldname:'company',
+			label: __('Company'),
+			fieldtype: 'Link',
+			options: 'Company',
+			reqd: 1,
+			default: frappe.defaults.get_user_default('Company')
+		},
+		{
+			fieldname:'employee',
+			label: __('Employee'),
+			fieldtype: 'Link',
+			options: 'Employee',
+		},
+		{
+			fieldname:'from_date',
+			label: __('From Date'),
+			fieldtype: 'Date',
+			reqd: 1,
+			default: frappe.defaults.get_default('year_start_date')
+		},
+		{
+			fieldname:'to_date',
+			label: __('To Date'),
+			fieldtype: 'Date',
+			reqd: 1,
+			default: frappe.defaults.get_default('year_end_date')
+		}
+	]
+};
diff --git a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.json b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.json
new file mode 100644
index 0000000..60fe1ae
--- /dev/null
+++ b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.json
@@ -0,0 +1,34 @@
+{
+ "add_total_row": 0,
+ "creation": "2019-09-05 11:18:06.209397",
+ "disable_prepared_report": 0,
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "idx": 0,
+ "is_standard": "Yes",
+ "letter_head": "sapcon-old",
+ "modified": "2019-09-05 11:18:06.209397",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Employee Leave Balance Summary",
+ "owner": "Administrator",
+ "prepared_report": 0,
+ "ref_doctype": "Employee",
+ "report_name": "Employee Leave Balance Summary",
+ "report_type": "Script Report",
+ "roles": [
+  {
+   "role": "Employee"
+  },
+  {
+   "role": "HR Manager"
+  },
+  {
+   "role": "HR User"
+  },
+  {
+   "role": "Leave Approver"
+  }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py
new file mode 100644
index 0000000..64a5c1c
--- /dev/null
+++ b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py
@@ -0,0 +1,96 @@
+# 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.utils import flt
+from frappe import _
+from erpnext.hr.doctype.leave_application.leave_application import get_leaves_for_period
+
+from erpnext.hr.report.employee_leave_balance.employee_leave_balance import get_total_allocated_leaves
+
+def execute(filters=None):
+	if filters.to_date <= filters.from_date:
+		frappe.throw(_('From date can not be greater than than To date'))
+
+	columns = get_columns()
+	data = get_data(filters)
+
+	return columns, data
+
+def get_columns():
+	columns = [{
+		'label': _('Leave Type'),
+		'fieldtype': 'Link',
+		'fieldname': 'leave_type',
+		'width': 300,
+		'options': 'Leave Type'
+	}, {
+		'label': _('Employee'),
+		'fieldtype': 'Link',
+		'fieldname': 'employee',
+		'width': 100,
+		'options': 'Employee'
+	}, {
+		'label': _('Employee Name'),
+		'fieldtype': 'Data',
+		'fieldname': 'employee_name',
+		'width': 100,
+	}, {
+		'label': _('Opening Balance'),
+		'fieldtype': 'float',
+		'fieldname': 'opening_balance',
+		'width': 160,
+	}, {
+		'label': _('Leaves Taken'),
+		'fieldtype': 'float',
+		'fieldname': 'leaves_taken',
+		'width': 160,
+	}, {
+		'label': _('Closing Balance'),
+		'fieldtype': 'float',
+		'fieldname': 'closing_balance',
+		'width': 160,
+	}]
+
+	return columns
+
+def get_data(filters):
+	leave_types = frappe.db.sql_list("SELECT `name` FROM `tabLeave Type` ORDER BY `name` ASC")
+
+	conditions = {
+		'status': 'Active',
+	}
+
+	if filters.get('employee'):
+		conditions['name'] = filters.get('employee')
+
+	active_employees = frappe.get_all('Employee',
+		filters=conditions,
+		fields=['name', 'employee_name', 'department', 'user_id'])
+
+	data = []
+
+	for leave_type in leave_types:
+		data.append({
+			'leave_type': leave_type
+		})
+		for employee in active_employees:
+			row = frappe._dict({
+				'employee': employee.name,
+				'employee_name': employee.employee_name
+			})
+
+			leaves_taken = get_leaves_for_period(employee.name, leave_type,
+				filters.from_date, filters.to_date) * -1
+
+			opening = get_total_allocated_leaves(employee.name, leave_type, filters.from_date, filters.to_date)
+			closing = flt(opening) - flt(leaves_taken)
+
+			row.opening_balance = opening
+			row.leaves_taken = leaves_taken
+			row.closing_balance = closing
+			row.indent = 1
+			data.append(row)
+
+	return data