/*================================================================================================================\ + + 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({ dataTextField: "StateAlias", dataValueField: "StateId", filter: "contains", dataSource: data, change: function () { // loading cities according to state id loadCityChoices($("#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) { } }); } //================== 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 = $("#fromDatePicker").val(), state = $("#stateCombobox").data("kendoComboBox").text(), city = $("#cityCombobox").data("kendoComboBox").text(), dealerId = $("#dealerCombobox").val(); // 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/ShowEosCallCount/", data: { fromDate: startDate, toDate: endDate, state: state, city: city, dealerId: dealerId }, success: function (data) { // populating HTML on page $('#divGrid').html(data); // 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(); loadCityChoices($("#stateCombobox").val()) loadDealerChoices($("#stateCombobox").val(), $("#cityCombobox").val()); });