EOS/Views/Report/tollFreeAndOpportunityLoss.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

238 lines
7.5 KiB
JavaScript

/*================================================================================================================\
+
+ Project : GODATA-VECV
+ Filename : tollFreeAndOpportunityLoss.js
+ Module Name : ReportModule
+ Purpose : To show and export Toll Free And Opportunity Loss report.
+ Coded By : Pankaj Khandal
+
+================================================================================================================*/
/**
* To show and export reports.
* @module ReportModule
*/
/**
* To show and export Toll Free And Opportunity Loss report.
* @class TollFreeAndOpportunityLoss
* @constructor
*/
/**
* Global References: To store ajax request's XHR objects.
* @for TollFreeAndOpportunityLoss
*/
var xhr_report = null;
var xhr_exportExport = null;
//================== FILTERS Section Start =========================
/**
* To populate state combobox.
* @method loadStateChoices
* @for TollFreeAndOpportunityLoss
*/
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 TollFreeAndOpportunityLoss
*/
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 TollFreeAndOpportunityLoss
*/
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 TollFreeAndOpportunityLoss
*/
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/ShowTollFreeAndOpportunityLoss/",
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 () {
$("#tab_OppotunityLoss").trigger("click");
},
error: function (data) {
// hiding the excel icon
$('.excelIcon').hide();
console.log("Error");
}
});
}
/**
* To get filter parameters and export report.
* @method exportReport
* @for TollFreeAndOpportunityLoss
*/
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/ExportTollFreeAndOpportunityLoss/",
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 TollFreeAndOpportunityLoss
*/
$(document).ready(function () {
// populating state, city & dealer comboboxes
loadStateChoices();
loadCityChoices($("#stateCombobox").val())
loadDealerChoices($("#stateCombobox").val(), $("#cityCombobox").val());
//Tab functionality
$("#tab_TollFreeNo").click(function () {
$(this).addClass('selected');
$('#tab_OppotunityLoss').removeClass('selected');
$('#TollFreeNoDiv').show();
$('#OppotunityLossDiv').hide();
});
$("#tab_OppotunityLoss").click(function () {
$(this).addClass('selected');
$('#tab_TollFreeNo').removeClass('selected');
$('#TollFreeNoDiv').hide();
$('#OppotunityLossDiv').show();
});
// First tab is triggered
$("#tab_OppotunityLoss").trigger("click");
});