198 lines
6.1 KiB
JavaScript
198 lines
6.1 KiB
JavaScript
/*================================================================================================================\
|
|
+
|
|
+ Project : GoData-VECV
|
|
+ Filename : customerReport.js
|
|
+ Module Name : Report
|
|
+ Purpose : To load customer list(with server side filtering and paging) and showing report for a particular customer.
|
|
+ Coded By : Pankaj Khandal
|
|
+
|
|
+================================================================================================================*/
|
|
|
|
/**
|
|
* To show and export reports.
|
|
* @module ReportModule
|
|
*/
|
|
|
|
/**
|
|
* To load customer list(with server side filtering and paging) and showing report for a particular customer.
|
|
* @class CustomerReport
|
|
* @constructor
|
|
*/
|
|
|
|
|
|
/**
|
|
* Global References: To store Ajax Request's XHR objecta and some other global references.
|
|
* @for CustomerReport
|
|
*/
|
|
var activeRequest, activeRequest_OwnerDetails, xhr_exportExport;
|
|
var customerId = '';
|
|
|
|
|
|
/**
|
|
* Function to show customer report for a particular owner according to filter parameters.
|
|
* @method showReport
|
|
* @for CustomerReport
|
|
*/
|
|
function showReport() {
|
|
// hiding the excel icon
|
|
$('.excelIcon').hide();
|
|
// Making the target Div Container empty
|
|
$('#divGrid').empty();
|
|
|
|
grid = $("#gridOwnerList").data("kendoGrid");
|
|
|
|
/// click event on rows of grid.
|
|
$(grid.tbody).on("click", "tr", function () {
|
|
// clicked row instance
|
|
row = $(this).closest("tr");
|
|
var custId;
|
|
custId = row[0].childNodes[0].innerHTML;
|
|
customerId = custId;
|
|
OwnerName = row[0].childNodes[2].innerHTML;
|
|
|
|
var year = $("#fromDatePicker").val();
|
|
var state = $("#stateCombobox").data("kendoComboBox").text();
|
|
|
|
// ajax request to get Owner detail
|
|
if (activeRequest_OwnerDetails && activeRequest_OwnerDetails.readystate != 4) {
|
|
activeRequest_OwnerDetails.abort();
|
|
}
|
|
$("#div_load").show();
|
|
activeRequest_OwnerDetails = $.ajax({
|
|
type: "POST",
|
|
url: "/Report/ShowCustomerReport/",
|
|
data: {Year:year,State:state, CustomerId: custId },
|
|
success: function (data) {
|
|
console.log(data.length);
|
|
// Showing/Hiding the excel-icon according to data received
|
|
if (data.length > 500) {
|
|
$('.excelIcon').show();
|
|
}
|
|
else {
|
|
$('.excelIcon').hide();
|
|
}
|
|
// populating the HTML on page
|
|
$('#divGrid').html(data);
|
|
},
|
|
complete: function () {
|
|
$("#div_load").hide();
|
|
},
|
|
error: function (data) {
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* To get filter parameters and export report.
|
|
* @method exportReport
|
|
* @for CustomerReport
|
|
*/
|
|
function exportReport() {
|
|
var year = $("#fromDatePicker").val(); // getting selected year
|
|
var state = $("#stateCombobox").data("kendoComboBox").text(); // getting selected state
|
|
var custId = customerId; // storing customer Id
|
|
|
|
// 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/ExportCustomerReport/",
|
|
data: { Year: year, State: state, CustomerId: custId },
|
|
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");
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to get Owner list.
|
|
* @method getOwnerList
|
|
* @for CustomerReport
|
|
*/
|
|
function getOwnerList() {
|
|
$("#spanState").hide(); // hiding state validation span
|
|
stateVal = $("#stateCombobox").data("kendoComboBox").text(); // getting selected state
|
|
var FilterVal = $("#srchText").val(); // getting Search filter value
|
|
|
|
if (stateVal != "") {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Report/CustomerReport_GetOwnerList/",
|
|
data: { state: stateVal, FilterVal: FilterVal },
|
|
success: function (data) {
|
|
//Bind html
|
|
$("#divOwnerList").html(data);
|
|
vPrePageSize = 0;
|
|
},
|
|
error: function (data) {
|
|
}
|
|
});
|
|
} else {
|
|
$("#spanState").show(); // showing state validation span
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* This Function is used to Get The Load State
|
|
* @method loadStateChoices
|
|
* @for CustomerReport
|
|
*/
|
|
function loadStateChoices() {
|
|
SecurityToken = securityToken; // getting security token
|
|
utcMinutes = parseInt(UtcMinutes, 10); // getting utc minutes
|
|
UserId = userId; // getting user id
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: WCFRESTURL.GetStateListIdWise,
|
|
data: { Token: SecurityToken, UtcMinutes: utcMinutes, UserId: UserId },
|
|
dataType: "json",
|
|
success: function (data) {
|
|
data.sort(function SortState(a, b) { // non-anonymous as you ordered...
|
|
return b.StateAlias < a.StateAlias ? 1 // if b should come earlier, push a to end
|
|
: b.StateAlias > a.StateAlias ? -1 // if b should come later, push a to begin
|
|
: 0; // a and b are equal
|
|
});
|
|
// binding state combo-box
|
|
$("#stateCombobox").kendoComboBox({
|
|
dataTextField: "StateAlias",
|
|
dataValueField: "StateId",
|
|
filter: "contains",
|
|
dataSource: data
|
|
});
|
|
},
|
|
complete: function () {
|
|
//$("#stateCombobox").data('kendoComboBox').select(0);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
}
|
|
});
|
|
}
|
|
|
|
//------------------------------------ document ready function --------------------------------------//
|
|
/**
|
|
* Fired when Html-DOM is ready.
|
|
* @event $(document).ready
|
|
* @for CustomerReport
|
|
*/
|
|
$(document).ready(function () {
|
|
//populating state combobox
|
|
loadStateChoices();
|
|
// making the search box empty
|
|
$('#srchText').html('');
|
|
});
|
|
|