Merge pull request #9467 from rohitwaghchaure/support_hours_report

[enhance] Report for analysis of support hours count
diff --git a/erpnext/config/support.py b/erpnext/config/support.py
index c1f56f0..b85c430 100644
--- a/erpnext/config/support.py
+++ b/erpnext/config/support.py
@@ -49,6 +49,12 @@
 					"doctype": "Issue",
 					"is_query_report": True
 				},
+				{
+					"type": "report",
+					"name": "Support Hours",
+					"doctype": "Issue",
+					"is_query_report": True
+				},
 			]
 		},
 	]
diff --git a/erpnext/docs/assets/img/support/support_hours.png b/erpnext/docs/assets/img/support/support_hours.png
new file mode 100644
index 0000000..44cfbbb
--- /dev/null
+++ b/erpnext/docs/assets/img/support/support_hours.png
Binary files differ
diff --git a/erpnext/docs/user/manual/en/support/support_reports.md b/erpnext/docs/user/manual/en/support/support_reports.md
new file mode 100644
index 0000000..2be72e1
--- /dev/null
+++ b/erpnext/docs/user/manual/en/support/support_reports.md
@@ -0,0 +1,8 @@
+
+
+### Support Hours
+This report provide the information about the time slot along with the count of issues has been reported during the slot daywise.
+
+> Support > Reports > Support Hours
+
+<img class="screenshot" alt="Maintenance Visit" src="{{docs_base_url}}/assets/img/support/support_hours.png">
diff --git a/erpnext/support/report/support_hours/__init__.py b/erpnext/support/report/support_hours/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/support/report/support_hours/__init__.py
diff --git a/erpnext/support/report/support_hours/support_hours.js b/erpnext/support/report/support_hours/support_hours.js
new file mode 100644
index 0000000..439b767
--- /dev/null
+++ b/erpnext/support/report/support_hours/support_hours.js
@@ -0,0 +1,39 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+/* eslint-disable */
+
+frappe.query_reports["Support Hours"] = {
+	"filters": [
+		{
+			'lable': __("From Date"),
+			'fieldname': 'from_date',
+			'fieldtype': 'Date',
+			'default': frappe.datetime.nowdate(),
+			'reqd': 1
+		},
+		{
+			'lable': __("To Date"),
+			'fieldname': 'to_date',
+			'fieldtype': 'Date',
+			'default': frappe.datetime.nowdate(),
+			'reqd': 1
+		}
+	],
+	get_chart_data: function(columns, result) {
+		return {
+			data: {
+				x: 'Date',
+				columns: [
+					['Date'].concat($.map(result, function(d) { return d.date; })),
+					[columns[3].label].concat($.map(result, function(d) { return d[columns[3].label]; })),
+					[columns[4].label].concat($.map(result, function(d) { return d[columns[4].label]; })),
+					[columns[5].label].concat($.map(result, function(d) { return d[columns[5].label]; })),
+					[columns[6].label].concat($.map(result, function(d) { return d[columns[6].label]; })),
+					[columns[7].label].concat($.map(result, function(d) { return d[columns[7].label]; }))
+				]
+			},
+			chart_type: 'bar',
+
+		}
+	}
+}
diff --git a/erpnext/support/report/support_hours/support_hours.json b/erpnext/support/report/support_hours/support_hours.json
new file mode 100644
index 0000000..01e4bb4
--- /dev/null
+++ b/erpnext/support/report/support_hours/support_hours.json
@@ -0,0 +1,27 @@
+{
+ "add_total_row": 0, 
+ "apply_user_permissions": 1, 
+ "creation": "2017-06-23 14:21:37.558691", 
+ "disabled": 0, 
+ "docstatus": 0, 
+ "doctype": "Report", 
+ "idx": 0, 
+ "is_standard": "Yes", 
+ "letter_head": "", 
+ "modified": "2017-06-23 16:33:31.211390", 
+ "modified_by": "Administrator", 
+ "module": "Support", 
+ "name": "Support Hours", 
+ "owner": "Administrator", 
+ "ref_doctype": "Issue", 
+ "report_name": "Support Hours", 
+ "report_type": "Script Report", 
+ "roles": [
+  {
+   "role": "Support Team"
+  }, 
+  {
+   "role": "System Manager"
+  }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/support/report/support_hours/support_hours.py b/erpnext/support/report/support_hours/support_hours.py
new file mode 100644
index 0000000..f1606cd
--- /dev/null
+++ b/erpnext/support/report/support_hours/support_hours.py
@@ -0,0 +1,73 @@
+# 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 import _
+from frappe.utils import add_to_date, getdate, get_datetime
+
+time_slots = {
+	'12AM - 3AM': '00:00:00-03:00:00',
+	'3AM - 6AM': '03:00:00-06:00:00',
+	'6AM - 9AM': '06:00:00-09:00:00',
+	'9AM - 12PM': '09:00:00-12:00:00',
+	'12PM - 3PM': '12:00:00-15:00:00',
+	'3PM - 6PM': '15:00:00-18:00:00',
+	'6PM - 9PM': '18:00:00-21:00:00',
+	'9PM - 12AM': '21:00:00-23:00:00'
+}
+
+def execute(filters=None):
+	columns, data = [], []
+	if not filters.get('periodicity'):
+		filters['periodicity'] = 'Daily'
+
+	columns = get_columns()
+	data = get_data(filters)
+	return columns, data
+
+def get_data(filters):
+	start_date = getdate(filters.from_date)
+	data = []
+	while(start_date <= getdate(filters.to_date)):
+		hours_count = {'date': start_date}
+		for key, value in time_slots.items():
+			start_time, end_time = value.split('-')
+			start_time = get_datetime("{0} {1}".format(start_date.strftime("%Y-%m-%d"), start_time))
+			end_time = get_datetime("{0} {1}".format(start_date.strftime("%Y-%m-%d"), end_time))
+			hours_count[key] = get_hours_count(start_time, end_time)
+
+		if hours_count:
+			data.append(hours_count)
+
+		start_date = add_to_date(start_date, days=1)
+
+	return data
+
+def get_hours_count(start_time, end_time):
+	data = frappe.db.sql(""" select count(*) from `tabIssue` where creation
+		between %(start_time)s and %(end_time)s""", {
+			'start_time': start_time,
+			'end_time': end_time
+		}, as_list=1) or []
+
+	return data[0][0] if len(data) > 0 else 0
+
+def get_columns():
+	columns = [{
+		"fieldname": "date",
+		"label": _("Date"),
+		"fieldtype": "Date",
+		"width": 100
+	}]
+
+	for label in ['12AM - 3AM', '3AM - 6AM', '6AM - 9AM',
+		'9AM - 12PM', '12PM - 3PM', '3PM - 6PM', '6PM - 9PM', '9PM - 12AM']:
+		columns.append({
+			"fieldname": label,
+			"label": _(label),
+			"fieldtype": "Data",
+			"width": 120
+		})
+
+	return columns
\ No newline at end of file