/*================================================================================================================\
+
+ Project : GODATA-VECV
+ Filename : eosCallCount.js
+ Module Name : ReportModule
+ Purpose : To show and export EOS Call Count report.
+ Coded By : Pankaj Khandal
+
+================================================================================================================*/
/**
* To show and export reports.
* @module ReportModule
*/
/**
* To show and export EOS Call Count report.
* @class EosCallCount
* @constructor
*/
/**
* Global References: To store ajax request's XHR objects.
* @for EosCallCount
*/
var xhr_report = null;
var xhr_exportExport = null;
//================== FILTERS Section Start =========================
/**
* To populate state combobox.
* @method loadStateChoices
* @for EosCallCount
*/
function loadStateChoices() {
utcMinutes = parseInt(UtcMinutes, 10);
UserId = userId;
$.ajax({
type: "POST",
url: WCFRESTURL.GetStateListIdWise,
data: { Token: securityToken, UtcMinutes: utcMinutes, UserId: UserId },
dataType: "json",
success: function (data) {
$("#stateCombobox").kendoComboBox({
placeholder: "Select State",
dataTextField: "StateAlias",
dataValueField: "StateAlias",
filter: "contains",
dataSource: data,
suggest: true,
dataBound: function() {
var dataSource = this.dataSource;
var data = dataSource.data();
if (!this._adding) {
this._adding = true;
data.splice(0, 0, {
"StateAlias": "All",
"StateAlias": "All"
});
//this._adding = false;
}
var $cbx = $("#stateCombobox").data("kendoComboBox");
$cbx.select(0);
$cbx.trigger("change");
},
change: function () {
// loading cities according to state id
loadCustomerChoices($("#stateCombobox").val());
//loadDealerChoices($("#stateCombobox").data("kendoComboBox").text(), $("#cityCombobox").data("kendoComboBox").text());
}
});
},
complete: function () {
//$("#stateCombobox").data('kendoComboBox').select(0);
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
/**
* To populate city combobox.
* @method loadCityChoices
* @param {String} stateId id of state
* @for EosCallCount
*/
function loadCityChoices(stateId) {
utcMinutes = parseInt(UtcMinutes, 10);
UserId = userId;
$.ajax({
type: "POST",
url: WCFRESTURL.GetCityListStateIdWise,
data: { Token: securityToken, UtcMinutes: utcMinutes, UserId: UserId, StateId: stateId },
dataType: "json",
success: function (data) {
$("#cityCombobox").kendoComboBox({
dataTextField: "CityName",
dataValueField: "CityId",
filter: "contains",
dataSource: data,
change: function () {
loadDealerChoices($("#stateCombobox").data("kendoComboBox").text(), $("#cityCombobox").data("kendoComboBox").text());
}
});
},
complete: function () {
$("#cityCombobox").data("kendoComboBox").text('');
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
/**
* To populate dealer combobox.
* @method loadDealerChoices
* @param {String} state state-name
* @param {String} city city-name
* @for EosCallCount
*/
function loadDealerChoices(state, city) {
utcMinutes = parseInt(UtcMinutes, 10);
UserId = userId;
$.ajax({
type: "POST",
url: WCFRESTURL.GetDealerStateCityWise,
data: { Token: securityToken, UtcMinutes: utcMinutes, UserId: UserId, DealerStateParam: state, DealerCityParam: city },
dataType: "json",
success: function (data) {
$("#dealerCombobox").kendoComboBox({
dataTextField: "DealerDealerName",
dataValueField: "DealerId",
filter: "contains",
dataSource: data,
});
},
complete: function () {
$("#dealerCombobox").data("kendoComboBox").text('');
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
/**
* To populate city combobox.
* @method loadCityChoices
* @param {String} stateId id of state
* @for EosCallCount
*/
function loadCustomerChoices(stateId) {
utcMinutes = parseInt(UtcMinutes, 10);
UserId = userId;
$.ajax({
type: "POST",
url: WCFRESTURL.GetCustomerList,
data: { Token: securityToken, CustomerState: stateId, limit: 10000 },
dataType: "json",
success: function (data) {
$("#customerCombobox").kendoComboBox({
dataTextField: "CustomerCustomerName",
dataValueField: "CustomerId",
filter: "contains",
dataSource: data,
//change: function () {
// loadDealerChoices($("#stateCombobox").data("kendoComboBox").text(), $("#cityCombobox").data("kendoComboBox").text());
//}
});
},
complete: function () {
$("#customerCombobox").data("kendoComboBox").text('');
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
//================== FILTERS Section End =========================
/**
* To get filter parameters and show report and showing/hiding export functionality accordingly.
* @method showReport
* @for EosCallCount
*/
function showReport() {
// hiding the excel icon
$('.excelIcon').hide();
// Making the target Div Container empty
$('#divGrid').empty();
var startDate = $("#fromDatePicker").val(),
endDate = $("#toDatePicker").val(),
state = $("#stateCombobox").data("kendoComboBox").text(),
//city = $("#cityCombobox").data("kendoComboBox").text(),
customerId = $("#customerCombobox").data("kendoComboBox").value();
// 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: "/FuelManagementReport/FuelManagement_ShowReport/",
data: { startDate: startDate, endDate: endDate, state: state, customerId: customerId },
success: function (data) {
// populating HTML on page
//$('#divGrid').html(data);
console.log(data.list);
if (data.list.length > 0) {
$("#divNoData").hide();
$("#divGrid").show();
$("#divGrid").kendoGrid({
dataSource: {
data: data.list,
pageSize: 20,
error: function (e) {
//console.log(e);
$("#divGrid").empty();
}
},
//height: 600,
groupable: false,
sortable: true,
resizable: true,
reorderable: true,
filterable: true,
pageable: {
buttonCount: 2
},
columnMenu: true,
columns: [{
field: "customerId",
title: "Customer Id",
width: 200
}, {
field: "customerName",
title: "Customer Name",
width: 200
}, {
field: "state",
title: "State",
width: 200
}, {
field: "displayDate",
title: "Date",
width: 200
}, {
field: "driverName",
title: "Driver Name",
width: 200
}, {
field: "vehicleModel",
title: "Vehicle Model",
width: 200
}, {
field: "vehicleChassisNumber",
title: "Vehicle Chassis Number",
width: 200
}, {
command: [{
text: "driverScore",
title: "Driver Score"
}],
title: "Driver Score",
width: 150
}, {
field: "fuelMileage",
title: "Fuel Mileage (km/l)",
width: 200
}, {
field: "totalRunning",
title: "Total Running (km)",
width: 200
}, {
field: "engineHours",
title: "Total Engine Hours",
width: 200
}, {
field: "vehicleAvgSpeed",
title: "Vehicle Average Speed (km/h)",
width: 200
}, {
command: [{
text: "currentRunning",
title: "Current Running"
}],
title: "Current Running",
width: 150
}, {
field: "fuelUtilisationTotal",
title: "Fuel Utilisation Total (litre)",
width: 200
},
{
title: "Fuel Utilisation",
columns: [{
field: "fuelUtilisationIdle",
title: "Idle (%)",
width: 200
}, {
field: "fuelUtilisationDrive",
title: "Drive (%)",
width: 200
}]
},
{
title: "Fuel Utilisation Drive Mode",
columns: [{
field: "fuelUtilisationInCruiseMode",
title: "Cruise Mode (%)",
width: 200
}, {
field: "fuelUtilisationInSweetspotMode",
title: "Sweet Spot Mode (%)",
width: 200
}]
}],
dataBound: function (e) {
var grid = e.sender;
var gridData = e.sender._data;
grid.items().each(function (idx, row) {
var dataItem = grid.dataItem(row);
if (((parseInt(dataItem.driverScore, 10) == 4) || (parseInt(dataItem.driverScore, 10) == 5)) && (parseInt(dataItem.fuelUtilisationInSweetspotMode, 10) > 90)) {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').removeClass("k-button k-button-icontext").html('' + dataItem.driverScore + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').parent().css("background-color", "#00a54f")
} else if ((parseInt(dataItem.driverScore, 10) == 3) && ((parseInt(dataItem.fuelUtilisationInSweetspotMode, 10) > 85) && (parseInt(dataItem.fuelUtilisationInSweetspotMode, 10) < 90))) {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').removeClass("k-button k-button-icontext").html('' + dataItem.driverScore + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').parent().css("background-color", "yellow");
} else if (((parseInt(dataItem.driverScore, 10) == 1) || (parseInt(dataItem.driverScore, 10) == 2)) && ((parseInt(dataItem.fuelUtilisationInSweetspotMode, 10) > 80) && (parseInt(dataItem.fuelUtilisationInSweetspotMode, 10) < 85))) {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').removeClass("k-button k-button-icontext").html('' + dataItem.driverScore + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').parent().css("background-color", "#ee1d23");
} else {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').removeClass("k-button k-button-icontext").html('' + dataItem.driverScore + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-driverScore').parent().css("background-color", "white");
}
if (((parseInt(dataItem.currentRunning, 10) == 4) || (parseInt(dataItem.currentRunning, 10) == 5))) {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').removeClass("k-button k-button-icontext").html('' + dataItem.currentRunning + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').parent().css("background-color", "#00a54f");
} else if ((parseInt(dataItem.currentRunning, 10) == 3)) {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').removeClass("k-button k-button-icontext").html('' + dataItem.currentRunning + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').parent().css("background-color", "yellow");
} else if (((parseInt(dataItem.currentRunning, 10) == 1) || (parseInt(dataItem.currentRunning, 10) == 2))) {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').removeClass("k-button k-button-icontext").html('' + dataItem.currentRunning + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').parent().css("background-color", "#ee1d23");
} else {
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').removeClass("k-button k-button-icontext").html('' + dataItem.currentRunning + '');
$('tr[data-uid="' + dataItem.uid + '"] > td > a.k-grid-currentRunning').parent().css("background-color", "white");
}
});
$('.k-grid-driverScore, .k-grid-currentRunning').removeAttr("href");
},
dataBinding: ''
});
}
else {
$("#divNoData").show();
$("#divGrid").hide();
}
//// Showing/Hising the Excel Icon according to received data.
//if (data.length < 300) { $('.excelIcon').hide(); }
//else { $('.excelIcon').show(); }
},
complete: function () {
},
error: function (data) {
//// hiding the excel icon
//$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and export report.
* @method exportReport
* @for EosCallCount
*/
function exportReport() {
var startDate = $("#fromDatePicker").val(),
endDate = $("#fromDatePicker").val(),
state = $("#stateCombobox").data("kendoComboBox").text(),
city = $("#cityCombobox").data("kendoComboBox").text(),
dealerId = $("#dealerCombobox").val();
// sending ajax request to export ICR Unique Users and Data Usage to Excel, and hadling its completion
if (xhr_exportExport && xhr_exportExport.readystate != 4) {
xhr_exportExport.abort();
}
xhr_exportExport = $.ajax({
type: "POST",
url: "/Report/ExportEosCallCount/",
data: { fromDate: startDate, toDate: endDate, state: state, city: city, dealerId: dealerId },
success: function (data) {
// making the generated Excel available for downloading.
window.location.href = data;
},
complete: function () {
},
error: function (data) {
console.log("Error in Export to Excel");
}
});
}
/**
* Fired when Html-DOM is ready.
* @event $(document).ready
* @for EosCallCount
*/
$(document).ready(function () {
// populating state, city & dealer comboboxes
loadStateChoices();
loadCustomerChoices($("#stateCombobox").val())
setTimeout(function () { showReport() }, 1000);
//loadDealerChoices($("#stateCombobox").val(), $("#cityCombobox").val());
});