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