/*================================================================================================================\
+
+ Project : GODATA-VECV
+ Filename : driverScoreReport.js
+ Module Name : ReportModule
+ Purpose : To show and export Driver Score report.
+ Coded By : Parul Gupta
+
+================================================================================================================*/
/**
* To show and export reports.
* @module ReportModule
*/
/**
* To show and export Call Feedback Rating report.
* @class DriverScoreReport
* @constructor
*/
/**
* Global References: To store ajax request's XHR objects.
* @for DriverScoreReport
*/
var xhr_report = null, xhr_vanCompareReport = null, xhr_vanHistoryReport = null, xhr_dealerCompareReport = null,
xhr_dealerScorereport = null, xhr_dealerHistoryReport = null,
xhr_ticketScorereport = null, xhr_ticketScorereportData = null,
xhr_report_downloadexcelvan;
var xhr_exportExport = null, countSubmitBtnClickEvent = 0;
var compareImagePath = "../../Content/css/images/icons/compare-icon.png";
var compareGreenImagePath = "../../Content/css/images/icons/compare-green-icon.png";
var historyImagePath = "../../Content/css/images/icons/reload-icon.png";
var infoImagePath = "../../Content/css/images/icons/info-icon.png";
var selectedVans = [];
var selectedDealers = [];
Array.prototype.remove = function () {
var what, a = arguments, L = a.length, ax;
while (L && this.length) {
what = a[--L];
while ((ax = this.indexOf(what)) !== -1) {
this.splice(ax, 1);
}
}
return this;
};
//======================== Tab Selection =============================//
/**
* Return selected tab id.
* @method getSelectedTab
* @for DriverScoreReport
*/
function getSelectedTab() {
'use strict';
var selectedTab;
selectedTab = $(".tabs").find('ul > li.selected')[0].id;
return selectedTab;
}
/**
* Maintain tab functionality. show particular div based on the tab id.
* @method graphicalTabAction
* @for DriverScoreReport
*/
function graphicalTabAction() {
'use strict';
$(".divContent").hide();
$("#tabGroup li").removeClass("selected");
$('#tabGroup li').click(function (e) {
e.stopPropagation();
var target = $(this).attr("rel");
$(".divContent").hide();
$("#tabGroup li").removeClass("selected");
$(".divContent[rel='" + target + "']").show();
$("#tabGroup li[rel='" + target + "']").addClass("selected");
var id = getSelectedTab();
// here counter shows submit button is pressed once or more.
// if submit button is not pressed then don't send any request.
if (countSubmitBtnClickEvent > 0) {
showReport();
}
});
}
//======================== End Tab Selection =============================//
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function showReport() {
// increase counter , when submit button pressed.
countSubmitBtnClickEvent++;
// hiding the excel icon
//$('.excelIcon').hide();
var selectedTab = getSelectedTab();
if (selectedTab == "tabVan")
showVanScoreReport();
else if (selectedTab == "tabDealer")
showDealerScoreReport();
else if (selectedTab == "tabTicket")
showTicketScoreReport();
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function showVanScoreReport() {
// increase counter , when submit button pressed.
countSubmitBtnClickEvent++;
// hiding the excel icon
//$('.excelIcon').hide();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_report && xhr_report.readystate != 4) {
xhr_report.abort();
}
xhr_report = $.ajax({
type: "POST",
url: "/Report/Report_GetAllVansScore/",
success: function (data) {
// populating HTML on page
$('#divVanDetails').html(data);
// Showing/Hising the Excel Icon according to received data.
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function showDealerScoreReport() {
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_dealerScorereport && xhr_dealerScorereport.readystate != 4) {
xhr_dealerScorereport.abort();
}
xhr_dealerScorereport = $.ajax({
type: "POST",
url: "/Report/Report_GetAllDealersScore/",
success: function (data) {
// populating HTML on page
$('#divDealerDetails').html(data);
// Showing/Hising the Excel Icon according to received data.
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function showTicketScoreReport() {
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_ticketScorereport && xhr_ticketScorereport.readystate != 4) {
xhr_ticketScorereport.abort();
}
xhr_ticketScorereport = $.ajax({
type: "POST",
url: "/Report/Report_GetAllTicketScore/",
success: function (data) {
// populating HTML on page
$('#divTicketDetails').html(data);
// Showing/Hising the Excel Icon according to received data.
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function showTicketScoreReportData() {
var userID = userId;
var fromDate = $("#startDate").val();
var endDate = $("#endtDate").val();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_ticketScorereportData && xhr_ticketScorereportData.readystate != 4) {
xhr_ticketScorereportData.abort();
}
xhr_ticketScorereportData = $.ajax({
type: "POST",
url: "/Report/Report_GetAllTicketScoreGrid/",
data: { userId: userID, startDate: fromDate, endDate: endDate, ticketStatus: "close" },
success: function (data) {
// populating HTML on page
$('#divGridTicketScore').html(data);
// Showing/Hising the Excel Icon according to received data.
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
//========================================================== van score functionality start ===================================================//
/**
* Function call on row bound of close tickets table
* @method onRowBound
* @for OpenTicketReport
*/
function onRowBound(e) {
$('.k-grid-VanHistory').text("").removeClass("k-button k-button-icontext").html("
");
$('.k-grid-VanInfo').text("").removeClass("k-button k-button-icontext").html("
");
// called common file function to show title on mouse hover.
addTitleAttribute();
// sla met or not met functionality
var data = this.dataSource.view();
for (var i = 0; i < data.length; i++) {
//get uid of row
var uid = data[i].uid;
// get default sla time of row
var dealerName = data[i].DealerName;
// get total ticket life cycle sla value
var vanId = data[i].VanId;
////get gps status of van
//var gps_status = data[i].gps_status;
var row = this.table.find("tr[data-uid='" + uid + "']");
$('.k-grid-Compare').text("").removeClass("k-button k-button-icontext").html("
");
}
}
function onCompareClick(e) {
console.log(($(e.srcElement)[0].id));
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
$(e.srcElement).siblings().removeClass("hide");
$(e.srcElement).addClass("hide");
if (($(e.srcElement)[0].id).indexOf("imgCompare") > -1) {
selectedVans.push(dataItem.VanId);
} else if (($(e.srcElement)[0].id).indexOf("imgNotCompare_") > -1) {
selectedVans.remove(dataItem.VanId);
}
console.log(selectedVans);
}
function compareVanScores() {
var fromDate = new Date(new Date().setMonth(new Date().getMonth() - 1));
var toDate = new Date();
if (selectedVans != null && selectedVans.length > 1 && selectedVans.length <= 10) {
var vans = selectedVans.toString();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_vanCompareReport && xhr_vanCompareReport.readystate != 4) {
xhr_vanCompareReport.abort();
}
xhr_vanCompareReport = $.ajax({
type: "POST",
url: "/Report/Report_CompareVansScore/",
data: { vans: selectedVans.toString(), fromDate: null, toDate: null },
success: function (data) {
console.log(data);
$("#divVansScoreComparePopUp").html("");
//open window in new dialog box
$("#divVansScoreComparePopUp").data("kendoWindow").open();
openKendoWindowInCenter("#divVansScoreComparePopUp");
$("#divVansScoreComparePopUp").html(data);
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
} else {
if (selectedVans.length < 2) {
jAlert("Please select atleast 2 vans.", 'Alert');
} else if (selectedVans.length > 10) {
jAlert("Please select upto 10 vans only.", 'Alert');
}
}
}
function onVanHistoryClick(e) {
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var vans = dataItem.VanId;
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_vanHistoryReport && xhr_vanHistoryReport.readystate != 4) {
xhr_vanHistoryReport.abort();
}
xhr_vanHistoryReport = $.ajax({
type: "POST",
url: "/Report/Report_CompareVansScore/",
data: { vans: vans, fromDate: null, toDate: null },
success: function (data) {
console.log(data);
//open window in new dialog box
$("#divVansScoreComparePopUp").data("kendoWindow").open();
openKendoWindowInCenter("#divVansScoreComparePopUp");
$("#divVansScoreComparePopUp").html("");
$("#divVansScoreComparePopUp").html(data);
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
function onVanInfoClick(e) {
var startDate = $("#scoreStartDate").val();
var endDate = $("#scoreEndtDate").val();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var assignToUser = dataItem.RegistrationNumber.trim();
window.open('/Report/Ticket_Close?startDate=01-Jan-2013'+ '&endDate=' + endDate + '&isTicketScore=true&assignedToUser=' + assignToUser + '&assignedTo=van');
}
//========================================================== van score functionality end ===================================================//
//========================================================== dealer score functionality start ===================================================//
/**
* Function call on row bound of close tickets table
* @method onRowBound
* @for OpenTicketReport
*/
function onRowBoundDealer(e) {
$('.k-grid-DealerHistory').text("").removeClass("k-button k-button-icontext").html("
");
$('.k-grid-DealerInfo').text("").removeClass("k-button k-button-icontext").html("
");
// called common file function to show title on mouse hover.
addTitleAttribute();
// sla met or not met functionality
var data = this.dataSource.view();
for (var i = 0; i < data.length; i++) {
//get uid of row
var uid = data[i].uid;
// get default sla time of row
var dealerName = data[i].DealerName;
// get total ticket life cycle sla value
var vanId = data[i].DealerId;
////get gps status of van
//var gps_status = data[i].gps_status;
var row = this.table.find("tr[data-uid='" + uid + "']");
$('.k-grid-DealerCompare').text("").removeClass("k-button k-button-icontext").html("
");
}
}
function onDealerCompareClick(e) {
console.log(($(e.srcElement)[0].id));
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
$(e.srcElement).siblings().removeClass("hide");
$(e.srcElement).addClass("hide");
if (($(e.srcElement)[0].id).indexOf("imgDealerCompare_") > -1) {
selectedDealers.push(dataItem.DealerId);
} else if (($(e.srcElement)[0].id).indexOf("imgDealerNotCompare_") > -1) {
selectedDealers.remove(dataItem.DealerId);
}
console.log(selectedDealers);
}
function onDealerHistoryClick(e) {
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var dealers = dataItem.DealerId;
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_dealerHistoryReport && xhr_dealerHistoryReport.readystate != 4) {
xhr_dealerHistoryReport.abort();
}
xhr_dealerHistoryReport = $.ajax({
type: "POST",
url: "/Report/Report_CompareDealersScore/",
data: { dealers: dealers, fromDate: null, toDate: null },
success: function (data) {
console.log(data);
//open window in new dialog box
$("#divDealersScoreComparePopUp").data("kendoWindow").open();
openKendoWindowInCenter("#divDealersScoreComparePopUp");
$("#divDealersScoreComparePopUp").html("");
$("#divDealersScoreComparePopUp").html(data);
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
function onDealerInfoClick(e) {
var startDate = $("#scoreStartDate").val();
var endDate = $("#scoreEndtDate").val();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var assignToUser = dataItem.DealerName.trim();
window.open('/Report/Ticket_Close?startDate=01-Jan-2013' + '&endDate=' + endDate + '&isTicketScore=true&assignedToUser=' + assignToUser + '&assignedTo=dealer');
}
function compareDealerScores() {
var fromDate = new Date(new Date().setMonth(new Date().getMonth() - 1));
var toDate = new Date();
if (selectedDealers != null && selectedDealers.length > 1 && selectedDealers.length <= 10) {
var dealers = selectedDealers.toString();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_dealerCompareReport && xhr_dealerCompareReport.readystate != 4) {
xhr_dealerCompareReport.abort();
}
xhr_dealerCompareReport = $.ajax({
type: "POST",
url: "/Report/Report_CompareDealersScore/",
data: { dealers: dealers, fromDate: null, toDate: null },
success: function (data) {
console.log(data);
//open window in new dialog box
$("#divDealersScoreComparePopUp").data("kendoWindow").open();
openKendoWindowInCenter("#divDealersScoreComparePopUp");
$("#divDealersScoreComparePopUp").html("");
$("#divDealersScoreComparePopUp").html(data);
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
} else {
if (selectedDealers.length < 2) {
jAlert("Please select atleast 2 dealers.", 'Alert');
} else if (selectedDealers.length > 10) {
jAlert("Please select upto 10 dealers only.", 'Alert');
}
}
}
//========================================================== dealer score functionality end ===================================================//
function onRowBoundTicketScoreGrid() {
$('.k-grid-TicketDetails').text("").removeClass("k-button k-button-icontext").html("").show();
}
/**
* Function to display close ticket details
* @method showCloseTicketDetails
* @for CloseTicketReport
*/
function showCloseTicketDetails(e) {
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
// console.log(dataItem.Id);
$.ajax({
type: "POST",
url: "/Report/Ticket_GetOpencloseTicketFullDetails/",
data: { ticketId: dataItem.Id, ticketStatus: "close" },
success: function (data) {
$("#divTicketScoreDetails").html(data);
//open window in new dialog box
$("#divTicketScoreDetails").data("kendoWindow").open();
openKendoWindowInCenter("#divTicketScoreDetails");
},
error: function (data) {
console.log(data);
}
});
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function exportReport() {
var selectedTab = getSelectedTab();
if (selectedTab == "tabVan")
downloadVanScoreReport();
else if (selectedTab == "tabDealer")
downloadealerScoreReport();
else if (selectedTab == "tabTicket")
downloadticketScoreReport();
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function downloadVanScoreReport() {
var fromDate = $("#startDate").val();
var endDate = $("#endtDate").val();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_report_downloadexcelvan && xhr_report_downloadexcelvan.readystate != 4) {
xhr_report_downloadexcelvan.abort();
}
xhr_report_downloadexcelvan = $.ajax({
type: "POST",
url: "/Report/DriverScoreCard_downloadExcel/",
data: { type: "van" },
success: function (data) { window.location.href = data;},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function downloadealerScoreReport() {
var fromDate = $("#startDate").val();
var endDate = $("#endtDate").val();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_report_downloadexcelvan && xhr_report_downloadexcelvan.readystate != 4) {
xhr_report_downloadexcelvan.abort();
}
xhr_report_downloadexcelvan = $.ajax({
type: "POST",
url: "/Report/DriverScoreCard_downloadExcel/",
data: { type: "dealer" },
success: function (data) { window.location.href = data; },
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for DriverScoreReport
*/
function downloadticketScoreReport() {
var userID = userId;
var fromDate = $("#startDate").val();
var endDate = $("#endtDate").val();
// sending the Ajax request to show the outage report and hadling its completion
if (xhr_report_downloadexcelvan && xhr_report_downloadexcelvan.readystate != 4) {
xhr_report_downloadexcelvan.abort();
}
xhr_report_downloadexcelvan = $.ajax({
type: "POST",
url: "/Report/DriverScoreCard_downloadExcel/",
data: { type: "ticket", userId: userID, startDate: fromDate, endDate: endDate, ticketStatus: "close" },
success: function (data) { window.location.href = data; },
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* Fired when Html-DOM is ready.
* @event $(document).ready
* @for DriverScoreReport
*/
$(document).ready(function () {
'use strict';
$("#tabVan").addClass('selected');
countSubmitBtnClickEvent++;
graphicalTabAction();
// First tab is triggered
$("#tabVan").addClass('selected').trigger("click");
addKendoWindow("#divVansScoreComparePopUp", "Compare VAN Scores", "1000px", 150, 120);
$("#divVansScoreComparePopUp").parent().addClass("TicketReportDetails_Window");
addKendoWindow("#divTicketScoreDetails", "Ticket Details", "1000px", 150, 120);
$("#divTicketScoreDetails").parent().addClass("TicketReportDetails_Window");
addKendoWindow("#divDealersScoreComparePopUp", "Dealer Score History", "1000px", 150, 120);
$("#divDealersScoreComparePopUp").parent().addClass("TicketReportDetails_Window");
});