2013-11-20 07:29:58 +00:00
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
2013-01-04 11:12:33 +00:00
|
|
|
wn.pages['support-analytics'].onload = function(wrapper) {
|
|
|
|
wn.ui.make_app_page({
|
|
|
|
parent: wrapper,
|
2013-10-04 18:51:17 +00:00
|
|
|
title: wn._('Support Analytics'),
|
2013-01-04 11:12:33 +00:00
|
|
|
single_column: true
|
|
|
|
});
|
|
|
|
|
|
|
|
new erpnext.SupportAnalytics(wrapper);
|
|
|
|
|
2013-11-13 11:25:38 +00:00
|
|
|
|
2013-04-19 07:31:32 +00:00
|
|
|
wrapper.appframe.add_module_icon("Support")
|
2013-11-13 11:25:38 +00:00
|
|
|
|
2013-01-04 11:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.SupportAnalytics = wn.views.GridReportWithPlot.extend({
|
|
|
|
init: function(wrapper) {
|
|
|
|
this._super({
|
2013-10-04 18:51:17 +00:00
|
|
|
title: wn._("Support Analtyics"),
|
2013-01-04 11:12:33 +00:00
|
|
|
page: wrapper,
|
|
|
|
parent: $(wrapper).find('.layout-main'),
|
|
|
|
appframe: wrapper.appframe,
|
|
|
|
doctypes: ["Support Ticket", "Fiscal Year"],
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
filters: [
|
2013-10-04 18:51:17 +00:00
|
|
|
{fieldtype:"Select", label: wn._("Fiscal Year"), link:"Fiscal Year",
|
2013-01-04 11:12:33 +00:00
|
|
|
default_value: "Select Fiscal Year..."},
|
2013-10-04 18:51:17 +00:00
|
|
|
{fieldtype:"Date", label: wn._("From Date")},
|
|
|
|
{fieldtype:"Label", label: wn._("To")},
|
|
|
|
{fieldtype:"Date", label: wn._("To Date")},
|
|
|
|
{fieldtype:"Select", label: wn._("Range"),
|
2013-01-04 11:12:33 +00:00
|
|
|
options:["Daily", "Weekly", "Monthly", "Quarterly", "Yearly"]},
|
2013-11-13 11:25:38 +00:00
|
|
|
{fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"},
|
2013-10-04 18:51:17 +00:00
|
|
|
{fieldtype:"Button", label: wn._("Reset Filters")}
|
2013-01-04 11:12:33 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
setup_columns: function() {
|
|
|
|
var std_columns = [
|
2013-10-04 18:51:17 +00:00
|
|
|
{id: "check", name: wn._("Plot"), field: "check", width: 30,
|
2013-01-04 11:12:33 +00:00
|
|
|
formatter: this.check_formatter},
|
2013-10-04 18:51:17 +00:00
|
|
|
{id: "status", name: wn._("Status"), field: "status", width: 100},
|
2013-01-04 11:12:33 +00:00
|
|
|
];
|
|
|
|
this.make_date_range_columns();
|
|
|
|
this.columns = std_columns.concat(this.columns);
|
|
|
|
},
|
|
|
|
|
|
|
|
prepare_data: function() {
|
|
|
|
// add Opening, Closing, Totals rows
|
|
|
|
// if filtered by account and / or voucher
|
|
|
|
var me = this;
|
|
|
|
var total_tickets = {status:"All Tickets", "id": "all-tickets",
|
|
|
|
checked:true};
|
|
|
|
var days_to_close = {status:"Days to Close", "id":"days-to-close",
|
|
|
|
checked:false};
|
2013-01-14 10:18:00 +00:00
|
|
|
var total_closed = {};
|
2013-01-04 11:12:33 +00:00
|
|
|
var hours_to_close = {status:"Hours to Close", "id":"hours-to-close",
|
|
|
|
checked:false};
|
2013-01-14 10:18:00 +00:00
|
|
|
var hours_to_respond = {status:"Hours to Respond", "id":"hours-to-respond",
|
|
|
|
checked:false};
|
|
|
|
var total_responded = {};
|
2013-01-04 11:12:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
$.each(wn.report_dump.data["Support Ticket"], function(i, d) {
|
|
|
|
var dateobj = dateutil.str_to_obj(d.creation);
|
|
|
|
var date = d.creation.split(" ")[0];
|
|
|
|
var col = me.column_map[date];
|
|
|
|
if(col) {
|
|
|
|
total_tickets[col.field] = flt(total_tickets[col.field]) + 1;
|
2013-01-14 10:18:00 +00:00
|
|
|
if(d.status=="Closed") {
|
|
|
|
// just count
|
|
|
|
total_closed[col.field] = flt(total_closed[col.field]) + 1;
|
|
|
|
|
|
|
|
days_to_close[col.field] = flt(days_to_close[col.field])
|
|
|
|
+ dateutil.get_diff(d.resolution_date, d.creation);
|
|
|
|
|
|
|
|
hours_to_close[col.field] = flt(hours_to_close[col.field])
|
|
|
|
+ dateutil.get_hour_diff(d.resolution_date, d.creation);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (d.first_responded_on) {
|
|
|
|
total_responded[col.field] = flt(total_responded[col.field]) + 1;
|
|
|
|
|
|
|
|
hours_to_respond[col.field] = flt(hours_to_respond[col.field])
|
|
|
|
+ dateutil.get_hour_diff(d.first_responded_on, d.creation);
|
|
|
|
}
|
2013-01-04 11:12:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// make averages
|
|
|
|
$.each(this.columns, function(i, col) {
|
|
|
|
if(col.formatter==me.currency_formatter && total_tickets[col.field]) {
|
2013-01-14 10:18:00 +00:00
|
|
|
days_to_close[col.field] = flt(days_to_close[col.field]) /
|
|
|
|
flt(total_closed[col.field]);
|
|
|
|
hours_to_close[col.field] = flt(hours_to_close[col.field]) /
|
|
|
|
flt(total_closed[col.field]);
|
|
|
|
hours_to_respond[col.field] = flt(hours_to_respond[col.field]) /
|
|
|
|
flt(total_responded[col.field]);
|
2013-01-04 11:12:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2013-01-14 10:18:00 +00:00
|
|
|
this.data = [total_tickets, days_to_close, hours_to_close, hours_to_respond];
|
2013-01-04 11:12:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get_plot_points: function(item, col, idx) {
|
|
|
|
return [[dateutil.str_to_obj(col.id).getTime(), item[col.field]],
|
|
|
|
[dateutil.user_to_obj(col.name).getTime(), item[col.field]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|