EOS/Scripts/TicketAdministration_Dealer/ticketAdministrationDealer.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

1711 lines
62 KiB
JavaScript

/*================================================================================================================\
+
+ Project : GoData-VECV
+ Filename : ticketAdministrationDealer.js
+ Module Name : Ticket
+ Purpose : For ticketing
+ Coded By : Parul Gupta
+
+================================================================================================================*/
/**
* For ticketing
* @module Ticket
*/
/**
* This class contains functionality of Ticket administration for Dealer and his vans.
* @class TicketForDealer
* @constructor
*/
//Global Variables
var activeRequest, xhr_getTicketHistory, xhr_getTicketHistoryInterval, xhr_getCloseTickerDetails, xhr_getOpenTicketDetails, xhr_showActivity,
xhr_showOpenActivity, xhr_addCustomer, xhr_addCustomerForExisting, xhr_getAllVans, xhr_addNewTicket;
var interval_id;
var ccplMap = null, markerImagePath = "../../Scripts/map_api/icons/red_blank.png",
markerTransImgPath = "../../Scripts/map_api/icons/red_blink.gif",
defaultLat = 26.912285124827,
defaultLng = 75.7873203125,
sourceMarker = '../../Scripts/map_api/icons/red_s.png', destinationMarker = '../../Scripts/map_api/icons/red_d.png';
var availableVansMarkers = '../../Content/css/images/avil-van.png';
var unavailableVansMarkers = '../../Content/css/images/unavl-van.png';
var dealerMarker = '../../Content/css/images/dealer-icon.png';
var breakdownLocationLatLng = "";
//initialize markers
var nearestVansDealersMarks = []; //array of nearest vans and dealers markers
var detailsListOfVanDealer = []; //array of objects of details of nearest vans and dealers
var vanDealerLatLngArr = []; //array of nearest vans and dealers lat lng
var ticketDetailsMarkerArray = [];
var _securityToken;
var _userId;
var marker, geoCoder, directionService;
var routeDirectionDisplay = "";
var routeDirectionsService = "";
var routeDistanceService = "";
var displayDisplay = "";
var selectedTicket;
var assignedTo;
var tcktid;
var tstatus;
/**f
* Load google map on page.
* @method initMap
* @for TicketForDealer
*/
function initMap(id) {
var mapOptions = {
center: new google.maps.LatLng(defaultLat, defaultLng),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
ccplMap = new google.maps.Map(document.getElementById(id), mapOptions);
geoCoder = new google.maps.Geocoder();
}
var specialKeys = new Array();
specialKeys.push(8);//Backspace
specialKeys.push(13);//enter
/**
* function to validate if ticket id is numeric or not
*/
function IsNumeric(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
return ret;
}
/**
* Function call on click of Route label to show map
* @method onclickLabelRoute
* @for TicketForDealer
*/
function onclickLabelRoute() {
//on click of label route
$("#labelRoute").click(function () {
// add selected class
$('#labelActivity').removeClass("toolBtnActive");
$('#labelRoute').addClass("toolBtnActive");
$("#divMapContainer").show();
$("#divActivity").css('display', 'none');
$('#labelpayment').removeClass("toolBtnActive");
$('#divPaymentDeatils').hide();
$("#divAddPaymentDeatils").hide();
$("#divMapContainer").hide();
});
}
/**
* Function call on click of Activity label to show ticket activity
* @method onclickLabelActivity
* @for TicketForDealer
*/
function onclickLabelActivity() {
//on click of label Activitys
$("#labelActivity").click(function () {
// alert('aa');
// add selected class
$('#labelRoute').removeClass("toolBtnActive");
$('#labelActivity').addClass("toolBtnActive");
$("#divActivity").css('display', 'inline-block');
$("#divActivity").addClass("withtoolbar");
$('#labelpayment').removeClass("toolBtnActive");
$('#divPaymentDeatils').hide();
$("#divMapContainer").hide();
$("#divAddPaymentDeatils").hide();
// $('#divPaymentDeatils').hide();
var ticketId;
setTimeout(function () {
var ishistory = 1;
// console.log(tstatu
if (tstatus == "AssignDealer") {
ishistory = 2;
// getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "dealer", "divMyTickets");
//sessionStorage.removeItem("storedId");
//sessionStorage.removeItem("storedStatus");
}
if (tstatus == "AssignVan") {
ishistory = 2;
//getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "van", "divMyVansTickets");
// sessionStorage.removeItem("storedId");
// sessionStorage.removeItem("storedStatus");
}
if (tstatus == "Allocated") {
ishistory = 2;
}
if (ishistory == 2) {
allocatedclick = "";
//selectedTicket=tcktid;
// $("#tabMyVansTickets").click();
//getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "allocated", "divMyTickets");
//sessionStorage.removeItem("storedId");
//sessionStorage.removeItem("storedStatus");
ticketId = tcktid;
$.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_GetTicketDetails/",
data: { ticketId: ticketId, ticketStatus: 'open' },
success: function (data) {
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
//if (displayDisplay) {
// //Remove direction display
// displayDisplay.setMap(null);
//}
////Remove previous markers
//removeTicketDetailsMarkerArray();
$("#divDetail").html('');
$("#divDetail").html(data);
//if (ccplMap) {
if ($("#labelRoute").hasClass('toolBtnActive') == true) {
var vanLat = $("#AssignedVanDealerLat").val();
var vanLng = $("#AssignedVanDealerLng").val();
var breakdownLat = $("#BreakdownLat").val();
var breakdownLng = $("#BreakdownLng").val();
if ((vanLat != "" && vanLat != null) && (vanLng != "" && vanLng != null) && (breakdownLat != "" && breakdownLat != null) && (breakdownLng != "" && breakdownLng != null)) {
assignedVanDealerLatLng = vanLat + "," + vanLng;
_breakdownLocationLatLng = breakdownLat + "," + breakdownLng;
// drawStaticMap_MarkersPath("staticMapImgUrl", "700", "450", assignedVanDealerLatLng, _breakdownLocationLatLng)
//assignedVanDealerLatLng = new google.maps.LatLng(vanLat, vanLng);
//breakdownLocationLatLng = new google.maps.LatLng(breakdownLat, breakdownLng);
////Get address of the Lat Long click clicked
//getReverseGeoCode(assignedVanDealerLatLng, function (data) {
// //Here we got the address of the point clicked. Update this value to the form textbox.
// var title = data;
// //create marker at position
// createMarkerVanDealer(assignedVanDealerLatLng, sourceMarker, title);
// //Get address of the Lat Long click clicked
// getReverseGeoCode(breakdownLocationLatLng, function (data) {
// //Here we got the address of the point clicked. Update this value to the form textbox.
// var title = data;
// //create marker at position
// createMarkerVanDealer(breakdownLocationLatLng, destinationMarker, title);
// //calculate route
// calcRoute(assignedVanDealerLatLng, breakdownLocationLatLng);
// //get map bound
// var _bounds = new google.maps.LatLngBounds();
// for (var count = 0; count < ticketDetailsMarkerArray.length; count++) {
// _bounds.extend(ticketDetailsMarkerArray[count].position);
// }
// ccplMap.fitBounds(_bounds);
// });
//});
} else {
$("#div_loading").hide();
}
}
// }
},
complete: function () {
$("#div_loading").hide();
//$("#textBoxDescription").val("");
},
error: function (data) {
console.log(data);
}
});
//alert(ticketId);
getPaymentDetailscount(ticketId);
apiUrl = url + "Api/TicketDetails?ownerinfo=yes&ticketid=" + ticketId + "&Token=teramatrix&openclose=open";
//alert(apiUrl);
$.ajax({
type: "POST",
url: apiUrl,
success: function (data) {
// alert(data.VehicleModelNumber);
if (data.VehicleModelNumber == null) {
}
else {
var str = data.VehicleModelNumber;
if (str.toLowerCase().indexOf("titan") !== -1) {
$('#listpaymentdetais').hide();
}
}
}
});
//enable ticket status dropdown list and remarks text box and update button for open tickets list
$("#ddTicketStatus, #textBoxDescription").attr("disabled", false);
$("#button_submit").show();
if (xhr_showOpenActivity && xhr_showOpenActivity.readystate != 4) {
xhr_showOpenActivity.abort();
}
//get ticket activity details
xhr_showOpenActivity = $.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_ShowTicketActivityOpenClose/",
data: { ticketId: ticketId, ticketStatus: 'open' },
success: function (data) {
$("#divActivity").html(data);
if (allocatedclick == 'yes') {
//$("#ddTicketStatus").hide();
$('#ddTicketStatus').html('');
var html = "<option value=\"12\">Assigned To Dealer</option><option value=\"4\">Pre-Closure</option><option value=\"11\">Assigned To Tab</option>";
$('#ddTicketStatus').append(html);
}
else {
} $("#ddTicketStatus, #textBoxDescription").attr("disabled", false);
$("#button_submit").show();
},
error: function (data) { }
});
}
else {
if ((document.getElementById('tableTicketHistory')) || (document.getElementById('tableCloseTicketHistory')) || ((document.getElementById('tableTicketHistory')) && (document.getElementById('tableCloseTicketHistory')))) {
if (document.getElementById('tableTicketHistory')) {
if ($("#tableTicketHistory > tbody > tr").hasClass('select')) {
ticketId = $("#tableTicketHistory > tbody > tr.select")[0].id;
//alert(ticketId);
getPaymentDetailscount(ticketId);
apiUrl = url + "Api/TicketDetails?ownerinfo=yes&ticketid=" + ticketId + "&Token=teramatrix&openclose=open";
//alert(apiUrl);
$.ajax({
type: "POST",
url: apiUrl,
success: function (data) {
// alert(data.VehicleModelNumber);
if (data.VehicleModelNumber == null) {
}
else {
var str = data.VehicleModelNumber;
if (str.toLowerCase().indexOf("titan") !== -1) {
$('#listpaymentdetais').hide();
}
}
}
});
//enable ticket status dropdown list and remarks text box and update button for open tickets list
$("#ddTicketStatus, #textBoxDescription").attr("disabled", false);
$("#button_submit").show();
if (xhr_showOpenActivity && xhr_showOpenActivity.readystate != 4) {
xhr_showOpenActivity.abort();
}
//get ticket activity details
xhr_showOpenActivity = $.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_ShowTicketActivityOpenClose/",
data: { ticketId: ticketId, ticketStatus: 'open' },
success: function (data) {
setTimeout(function () {
// alert($('#ticketStatusId').val());
if($('#ticketStatusId').val() =='4'){
getpreclosureval();
setTimeout(function () { // alert(precloseval);
$('#ddPreclosureReason').val(precloseval);
$('#ddTicketStatus').val('4');
}, 500);
}
}, 500);
$("#divActivity").html(data);
if (allocatedclick == 'yes') {
//$("#ddTicketStatus").hide();
$('#ddTicketStatus').html('');
var html = "<option value=\"12\">Assigned To Dealer</option><option value=\"4\">Pre-Closure</option><option value=\"11\">Assigned To Tab</option>";
$('#ddTicketStatus').append(html);
}
else {
} $("#ddTicketStatus, #textBoxDescription").attr("disabled", false);
$("#button_submit").show();
},
error: function (data) { }
});
}
else {
ticketId = $("#tableCloseTicketHistory > tbody > tr.select")[0].id;
getPaymentDetailscount(ticketId);
//disable ticket status dropdown list and remarks text box and update button for close tickets list
$("#ddTicketStatus, #textBoxDescription").attr("disabled", true);
$("#button_submit").hide();
//get ticket activity details
if (xhr_showActivity && xhr_showActivity.readystate != 4) {
xhr_showActivity.abort();
}
xhr_showActivity = $.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_ShowTicketActivityOpenClose/",
data: { ticketId: ticketId, ticketStatus: 'close' },
success: function (data) {
$("#divActivity").html(data);
$("#ddTicketStatus, #textBoxDescription, #ddReasonForOpportunityLost").attr("disabled", true);
$("#button_submit").hide();
},
error: function (data) { }
});
}
} else {
ticketId = $("#tableCloseTicketHistory > tbody > tr.select")[0].id;
$("#ddTicketStatus, #textBoxDescription").attr("disabled", true);
$("#button_submit").hide();
//get ticket activity details
if (xhr_showActivity && xhr_showActivity.readystate != 4) {
xhr_showActivity.abort();
}
xhr_showActivity = $.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_ShowTicketActivityOpenClose/",
data: { ticketId: ticketId, ticketStatus: 'close' },
success: function (data) {
$("#divActivity").html(data);
$("#ddTicketStatus, #textBoxDescription, #ddReasonForOpportunityLost").attr("disabled", true);
$("#button_submit").hide();
},
error: function (data) { }
});
}
}
}
}, 1000);
});
}
function showvanreassign() {
//alert(dealerId)
var trString = "";
var _trString = "";
var html = "";
// var dealerscode = $this.value;
$.ajax({
type: "POST",
url: url + "Api/CogentAPI?getvans=ss",
// data: { StateName: state1, limit: prdvariant, StateName2: state2, DealerSCode: dealercode, Token: securityToken, UserId: userId },
data: { StateName: "", limit: 100, StateName2: "", DealerSCode: dealerId, Fuel_type: "electric", Token: securityToken, UserId: userId },
// data: { StateName: 'Madhya Pradesh', limit: 100, StateName2: '', DealerSCode: '1S3053', Fuel_type: "diesel,cng", Token: securityToken, UserId: userId },
success: function (data) {
var cnt = 1;
if (data.length > 0) {
console.log(data); // $("#div_loading").show();
$("#divCreateDealer").html('');
$("#divCreateDealer").html('');
var cnt = 1;
var html2="<table cellpadding=\"0\" cellspacing=\"0\" class=\"OpenTicketTbl\" id=\"tblallocated\" style=\"overflow: scroll;\">";
// html2 += "">";
html2 += "<tr><td class=\"tableCellinfo\" style=\"width: 30 % !important; background: none!important;\"><select id=\"ddlvandetails\" onchange=\"getvandetails();\"> <option>-- Select -- </option>";
var html = html2;//+"<table cellpadding=\"0\" cellspacing=\"0\" class=\"OpenTicketTbl\" id=\"tblallocated\" style=\"overflow: scroll;\">";
// html += "<thead> <tr class=\"\"><th style =\"text-align: left;\">van Name</th>";
// html += "<th style =\"text-align: left;display: none;\">Reg No</th><th style =\"text-align: left;display: none;\"> Conatct Number</th><th style =\"text-align: left;display: none;\">No of open ticket</th><th style =\"text-align: left;display: none;\">Status</th>";
// html += "<th style=\"text-align: left;display: none;\"> Edit</th>";
// html += "<tr><td class=\"tableCellinfo\" style=\"width: 30 % !important; background: none!important;\"><select id=\"ddlvandetails\" onchange=\"getvandetails();\"> <option>-- Select -- </option>";
var cnt = 1;
addKendoWindowToDiv("#divCreateDealer", "Technician Details", "833px", 385);
//open form in new dialog box
$("#divCreateDealer").parent().addClass("responsive_popup"); //addClass for respond the menu
$("#divCreateDealer").parent().addClass("k-window2");
// var trhtml = "<thead><tr><th style=\"display: none;\">Van/Dealer Id</th><th>Van/Dealer Name</th><th style=\"display: none;\">Reg no</th>< style=\"display: none;\">Contact No.</th></tr></thead><tbody></tbody>";
for (keyVar in data) {
if (data.hasOwnProperty(keyVar)) {
console.log(data);
var brdvandistance = "";
var type = data[keyVar].Type;
var backgroundColor = "";
var vanRemainingTime = data[keyVar].RemainingTime;
var deviceStatus = data[keyVar].DeviceStatus;
var dname = data[keyVar].DealerVanLattitude + ' / ' + data[keyVar].DealerOrVanContactNo;
var vid = data[keyVar].DealerVanId + ',' + data[keyVar].DeviceAlias;
if (vanRemainingTime == null || vanRemainingTime == "") {
vanRemainingTime = "0";
}
else {
if (vanRemainingTime.indexOf('-') === -1) {
vanRemainingTime = vanRemainingTime;
} else {
vanRemainingTime = "0";
}
}
//check if device is connected or not
if ((deviceStatus == "True") && (type == "van")) {
updatedDeviceStatus = "green-circle";
}
else if ((deviceStatus == "False") && (type == "van")) {
updatedDeviceStatus = "red-circle";
} else {
updatedDeviceStatus = "";
}
if (vanRemainingTime == "0") {
backgroundColor = "green";
}
else {
backgroundColor = "red";
}
var brklat = $("#BreakdownLat").val();
var brklng = $("#BreakdownLng").val();
var url = "https://router.hereapi.com/v8/routes?transportMode=car&routingMode=short&avoid[features]=ferry&"
url += "origin="+ data[keyVar].Limit + "," + data[keyVar].Status + "&destination=" + brklat + "," + brklng + "&return=polyline,summary&apikey=DW3-YCFFZtJzlAQpTfVPoXADcZpEeZe3t8h6ganVsqo";
// console.log(url);
var request = GetDataHerefromAPI("get", url);
if (request) {
request.onload = function (data) {
//var res = JSON.parse(data.target.response);
//var response = (res.response.route[0].summary);
var res = JSON.parse(data.target.response);
if (res.notices && res.notices.length > 0 && res.notices[0].code === "noRouteFound")
{
brdvandistance='0.0';
}
else{
var response = (res.routes[0].sections[0].summary);
brdvandistance = response.length;
if (brdvandistance > 1000) {
brdvandistance = (brdvandistance / 1000);
brdvandistance = Math.round(brdvandistance * 10) / 10;
} else {
brdvandistance = brdvandistance;
}
console.log(brdvandistance);
}
// alert(brdvandistance);
}
} request.send();
var hdnhtml = "";
//hdnhtml +="";
if(brdvandistance == undefined){
console.log('brdvandistance');
brdvandistance='0.0';
}
var nameid = "hdnName" + data[keyVar].DeviceAlias;
html += "<option data-name='" + data[keyVar].DealerVanLattitude + "' data-no=" + data[keyVar].DealerOrVanContactNo + " data-lat=" + data[keyVar].Limit + " data-lng=" + data[keyVar].Status + " data-distance=" + brdvandistance + " data-devicealias=" + data[keyVar].DeviceAlias + " data-dealervanId=" + data[keyVar].DealerVanId + " data-reg=" + data[keyVar].DealerVanLongitude + " data-devicestatus=" + updatedDeviceStatus + " data-ContactNo=" + data[keyVar].DealerOrVanContactNo + " data-assticket=" + data[keyVar].NoOfAssignedTicket + ">" + dname + "</option>";
cnt++;
}
}
html += "</select></td></tr></table>";
html += "<table id=\"tblvanedit\" style=\"display:none;\" cellpadding=\"0\" cellspacing=\"0\" class=\"OpenTicketTbl\" style=\"overflow: scroll;\">";
html += "<thead> <tr class=\"\"><th style =\"text-align: left;\">Technician Name</th>";
html += "<th style =\"text-align: left;\">Technician Mobile Number</th><th style =\"text-align: left;\">VAN Registration Number</th><th style =\"text-align: left;\">Number of Open Tickets</th><th style =\"text-align: left;\">VAN Online/Offline</th>";
html += "<th style=\"text-align: left;\"> Action</th>";
html += "<tr><td class=\"tableCellinfo\" style=\"width: 30% !important; background: none!important;\"><span id=\"spntdname\"></span></td><td class=\"tableCellinfo\" style=\"width: 20% !important; background: none!important;\"><span id=\"spntdno\"></td><td id=\"vanreg\" class=\"tableCellinfo\" style=\"width: 20% !important; background: none!important;\"></td><td id=\"vanticket\" class=\"tableCellinfo\" style=\"width: 14% !important; background: none!important;\"></td><td id=\"vanstatus\" class=\"tableCellinfo\" style=\"width: 20% !important; background: none!important;\"></td><td class=\"tableCellinfo\" id=\"tdbtn\" style=\"width: 2% !important; background: none!important;\" nowrap=\"true\"></td> </tr></thead >";
$("#divCreateDealer").html(html);
SetKendoWindowTitle("#divCreateDealer", "Technician Details");
//open form in new dialog box
$("#divCreateDealer").data("kendoWindow").open();
openKendoWindowInCenter("#divCreateDealer");
}
else {
alert("No Active Van");
}
setTimeout(function () {
// alert(_trString);
// _createVanDealerSortedListForVan(id);
//$('#tvansearh').html(_trString)
}, 1000);
},
complete: function () {
$("#div_loading").hide();
},
error: function (data) {
}
});
}
function editname() {
$('#txtname').show();
var relValue = $('#imgeditvan').attr('rel');
//alert(relValue);
// $('#txtname').removeAttr('disabled');
// $('#btnAllocate').show();
// $('#' + relValue).hide();
//$('#txtname').val('');
}
function getvandetails() {
$('#tblvanedit').show();
// tblvanedit
//alert('aa');
// $('#tblallocated th').show();
var selectedOption = $('#ddlvandetails option:selected');
// alert(selectedOption.val());
var reg = selectedOption.data('reg');
var devicestatus = selectedOption.data('devicestatus');
var contactno = selectedOption.data('contactno');
var assticket = selectedOption.data('assticket');
var devicealias = selectedOption.data('devicealias');
var DealerVanId = selectedOption.data('dealervanid');
var distance = selectedOption.data('distance');
var lat = selectedOption.data('lat');
var dname = selectedOption.data('name');
var lng = selectedOption.data('lng');
var no = selectedOption.data('no');
var reltxt = 'txt' + DealerVanId;
// alert('hii');
// $('#spntdname').html("<span id=\"spnidtxt\" style=\"display:none;\"><img rel="+reltxt+ " onclick=\"editname();\" id=\"imgeditvantxt\" style=\"width: 31px;height: 40px;margin-left: 173px;\" src=\"/Content/css/images/pencil-xxl.png\" alt=\"Edit\" title=\"Edit\"><input type=\"text\" style=\"margin-top:-43px;display:none;\" disabled onchange=\"validatename();\" id=\"txtname\" value=" + dname + "></span>");
// $('#spntdno').html("<span id=\"spnidno\" style=\"display:none;\"><img rel="+reltxt+ " onclick=\"editno();\" id=\"imgeditvantxt\" style=\"width: 31px;height: 40px;margin-left: 173px;\" src=\"/Content/css/images/pencil-xxl.png\" alt=\"Edit\" title=\"Edit\"><input type=\"text\" style=\"margin-top:-43px;display:none;\" disabled onchange=\"validatename();\" id=\"txtname\" value=" + no + "></span>");
$('#spntdname').html("<span><img rel=" + DealerVanId + " onclick=\"editname();\" id=\"imgeditvan\" style=\"width: 31px;height: 40px;margin-left: 173px;\" src=\"/Content/css/images/pencil-xxl.png\" alt=\"Edit\" title=\"Edit\"><input type=\"text\" style=\"margin-top:-43px;\" disabled id=\"txtname\" value=" + name + "></span>");
$('#spntdno').html("<span><img rel=" + DealerVanId + " onclick=\"editno();\" id=\"imgeditvan\" style=\"width: 31px;height: 40px;margin-left: 173px;\" src=\"/Content/css/images/pencil-xxl.png\" alt=\"Edit\" title=\"Edit\"><input type=\"text\" style=\"margin-top:-43px;\" disabled id=\"txtno\" value=" + no + "></span>");
$('#vanreg').html("<span><img rel=" + DealerVanId + " onclick=\"editreg();\" id=\"imgeditvan\" style=\"width: 31px;height: 40px;margin-left: 173px;\" src=\"/Content/css/images/pencil-xxl.png\" alt=\"Edit\" title=\"Edit\"><input type=\"text\" style=\"margin-top:-43px;\" disabled id=\"txtreg\" value=" + reg + "></span>");
$('#vancontact').html(contactno);
$('#vanticket').html(assticket);
$('#vanstatus').html("<span class=" + updatedDeviceStatus + "></span>");
// $('#tblallocated td').show();
//$('#spnidtxt').show();
// $('#txtname').show();
$('#txtname').val(dname);
var btnhtml = '<input style="display:none;" type="button" ' +
'class="button_blue"' +
'data-devicealias="' + devicealias + '" ' +
'data-lat="' + lat + '" ' +
'data-lng="' + lng + '" ' +
'data-vanid="' + DealerVanId + '" ' +
'value="Assign" ' +
'onclick="editDetails(this)" ' +
'id=btnAllocate />' +
'<input type="button" ' +
'class="button_blue" ' +
'data-devicealias="' + devicealias + '" ' +
'data-vanid="' + DealerVanId + '" ' +
'data-distance="' + distance + '" ' +
'data-lat="' + lat + '" ' +
'data-lng="' + lng + '" ' +
'value="Assign" ' +
'onclick="assignvan(this)" ' +
'id="' + DealerVanId + '" />';
$('#tdbtn').html(btnhtml);
// alert(reg);
}
var isvalidate = 1;
function validatename() {
var txtname = $('#txtname').val();
if (txtname == "") {
alert("enter name");
}
else {
}
//alert(splits.length());
// alert(no);
// if( no == ""){
// alert("enter no");
// }
// else{
// isvalidate =2;
// }
// }
// alert(isvalidate);
}
function editvanDetails() {
//alert(iserror);
iserror =1;
var vanno = $("#txtVanReg").val();
var drivername = $("#txtvanname").val();
var drivercontactno = $("#txtdriverno").val();
if (drivername == "") {
alert("Please enter Driver Name", 'Message');
iserror =2;
return false;
}else{
}
var mobno = $('#txtno').val();
if ($('#txtno').val() == "") { //check if warrenty is selected or not
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
else {
var filter = /^\d*(?:\.\d{1,2})?$/;
if (filter.test(mobno)) {
if (mobno.length == 10) {
iserror=1;
} else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
alert(iserror);
// chkDriverval();
// setTimeout(function () {
// alert(iserror);
// // IsRegistrationNoFormatEdit();
// }, 500);
// setTimeout(function () {
// alert(iserror);
// }, 1000);
/*var tid = $('#TicketId').val();
var vanid = $('#hdnVanid').val();
var vanalias = $('#hdnVanalias').val();
updateAssignEditVan(tid, vanno, drivername, drivercontactno, vanid, vanalias);*/
}
function editname() {
var relValue = $('#imgeditvan').attr('rel');
//alert(relValue);
$('#txtname').removeAttr('disabled');
$('#btnAllocate').show();
$('#' + relValue).hide();
$('#txtname').val('');
}
function editno() {
var relValue = $('#imgeditvan').attr('rel');
//alert(relValue);
$('#txtno').removeAttr('disabled');
$('#btnAllocate').show();
$('#' + relValue).hide();
$('#txtno').val('');
}
function editreg() {
var relValue = $('#imgeditvan').attr('rel');
//alert(relValue);
$('#txtreg').removeAttr('disabled');
$('#btnAllocate').show();
$('#' + relValue).hide();
$('#txtreg').val('');
}
function chkDriverval() {
var mobno = $('#txtno').val();
if ($('#txtno').val() == "") { //check if warrenty is selected or not
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
else {
var filter = /^\d*(?:\.\d{1,2})?$/;
if (filter.test(mobno)) {
if (mobno.length == 10) {
} else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
}
var iserror=1;
function IsRegistrationNoFormatEdit() {
if ($('#txtreg').val() == ""){
jAlert("Please Enter Registration No.!!", 'Message');
}
else{
var regex1 = /[a-zA-Z]{2}[-][a-zA-Z0-9]{2}[-][a-zA-Z]{2}[-][0-9]{4,5}/g;
var regex2 = /[a-zA-Z]{2}[-][0-9]{4,5}/g;
var regex3 = /[a-zA-Z]{2}[-][a-zA-Z0-9]{2}[-][-][0-9]{4,5}/g;
var lengthRegNo = $("#txtreg").val().replace(/-/g, "").length;
if (lengthRegNo == 11 || lengthRegNo == 10 || lengthRegNo == 6 || lengthRegNo == 7 || lengthRegNo == 8 || lengthRegNo == 9) {
//var match = ($("#RegistrationNo").val()).match(regex);
var match1 = regex1.test($("#txtreg").val());
var match2 = regex2.test($("#txtreg").val());
var match3 = regex3.test($("#txtreg").val());
if (match1 || match2 || match3) {
iserror=1;
//document.getElementById('button_search').click();
return true;
} else {
$("#txtreg").val("");
jAlert("Please insert correct Registration No.!!", 'Message');
// alert();
iserror=2;
return false;
}
} else {
$("#txtreg").val("");
jAlert("Please insert correct Registration No.!!", 'Message');
iserror=2;
return false;
}
}
}
function editDetails(button) {
iserror =1;
//$('#divCreateDealer').data("kendoWindow").close();
var vanno = $("#txtreg").val();
var name = $("#txtname").val();
var no= $("#txtno").val();
if (name == "") {
jAlert("Please Enter Name", 'Message');
// alert("Please enter name", 'Message');
iserror =2;
return false;
}
else{
if (!/^[a-zA-Z\s]+$/.test(name)) {
jAlert("Please Enter Correct Name", 'Message');
iserror =2;
return false;
}
// Optional: Check for minimum length
else if (name.length < 2) {
jAlert("Please Enter Correct Name", 'Message');
iserror =2;
return false;
}
}
var mobno = $('#txtno').val();
if ($('#txtno').val() == "") { //check if warrenty is selected or not
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
else {
var filter = /^\d*(?:\.\d{1,2})?$/;
if (filter.test(mobno)) {
if (mobno.length == 10) {
iserror=1;
} else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
if ($('#txtreg').val() == ""){
jAlert("Please Enter Registration No.!!", 'Message');
iserror=2;
}
else{
var regex1 = /[a-zA-Z]{2}[-][a-zA-Z0-9]{2}[-][a-zA-Z]{2}[-][0-9]{4,5}/g;
var regex2 = /[a-zA-Z]{2}[-][0-9]{4,5}/g;
var regex3 = /[a-zA-Z]{2}[-][a-zA-Z0-9]{2}[-][-][0-9]{4,5}/g;
var lengthRegNo = $("#txtreg").val().replace(/-/g, "").length;
if (lengthRegNo == 9 || lengthRegNo == 10 ) {
//var match = ($("#RegistrationNo").val()).match(regex);
var match1 = regex1.test($("#txtreg").val());
var match2 = regex2.test($("#txtreg").val());
var match3 = regex3.test($("#txtreg").val());
/* if (match1 || match2 || match3) {
iserror=1;
//document.getElementById('button_search').click();
// return true;
} else {
// $("#txtreg").val("");
jAlert("Please insert correct Registration No.!!", 'Message');
// alert();
iserror=2;
return false;
}*/
} else {
// $("#txtreg").val("");
jAlert("Please insert correct Registration No.!!", 'Message');
iserror=2;
return false;
}
}
if(iserror ==1){
// alert(iserror);
var tid = $('#TicketId').val();
// var vanid = $('#hdnVanid').val();updateAssignEditVan
//var vanalias = $('#hdnVanalias').val();
// var vanid = button.id;
var devicealias = button.dataset.devicealias;
var vanid = button.dataset.vanid;
var lat = button.dataset.lat;
var lng = button.dataset.lng;
updateAssignEditVan(tid, vanno, vanid, devicealias, lat, lng);
}
}
/*chkDriverval();
if (no == "") {
jAlert("Please Enter Mobile Number", 'Message');
// alert("Please enter Registration number", 'Message');
iserror =2;
return false;
}
else{
var mobno = $('#txtno').val();
if ($('#txtno').val() == "") { //check if warrenty is selected or not
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
else {
var filter = /^\d*(?:\.\d{1,2})?$/;
if (filter.test(mobno)) {
if (mobno.length == 10) {
} else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
else {
jAlert("Please enter 10 digit mobile number", 'Message');
iserror=2;
return false;
}
}
}
if (vanno == "") {
jAlert("Please Enter Registration Number", 'Message');
// alert("Please enter Registration number", 'Message');
iserror =2;
return false;
}
else{
if ($("#txtreg").val() != "") {
var regex1 = /[a-zA-Z]{2}[-][a-zA-Z0-9]{2}[-][a-zA-Z]{2}[-][0-9]{4,5}/g;
var regex2 = /[a-zA-Z]{2}[-][0-9]{4,5}/g;
var regex3 = /[a-zA-Z]{2}[-][a-zA-Z0-9]{2}[-][-][0-9]{4,5}/g;
var lengthRegNo = $("#txtreg").val().replace(/-/g, "").length;
if (lengthRegNo == 11 || lengthRegNo == 10 || lengthRegNo == 6 || lengthRegNo == 7 || lengthRegNo == 8 || lengthRegNo == 9) {
//var match = ($("#RegistrationNo").val()).match(regex);
var match1 = regex1.test($("#txtreg").val());
var match2 = regex2.test($("#txtreg").val());
var match3 = regex3.test($("#txtreg").val());
if (match1 || match2 || match3) {
//document.getElementById('button_search').click();
return true;
} else {
$("#txtreg").val("");
jAlert("Please insert correct Registration No.!!", 'Message');
// alert();
iserror=2;
return false;
}
} else {
$("#txtreg").val("");
jAlert("Please insert correct Registration No.!!", 'Message');
iserror=2;
return false;
}
}
}
// IsRegistrationNoFormatEdit();
setTimeout(function () {
// alert(iserror);
if(iserror ==1){
//return false;
var tid = $('#TicketId').val();
// var vanid = $('#hdnVanid').val();updateAssignEditVan
//var vanalias = $('#hdnVanalias').val();
// var vanid = button.id;
var devicealias = button.dataset.devicealias;
var vanid = button.dataset.vanid;
var lat = button.dataset.lat;
var lng = button.dataset.lng;
updateAssignEditVan(tid, vanno, vanid, devicealias, lat, lng);
}
}, 500);
}*/
function SetKendoWindowTitle(divId, titleText) {
var dialog = $(divId).data("kendoWindow");
dialog.title(titleText);
}
function closeWindow(divId) {
$(divId).data("kendoWindow").close();
}
function addKendoWindowToDiv(divId, titleText, width, left) {
$(divId).kendoWindow({
width: width,
title: titleText,
modal: true,
resizable: false,
draggable: true,
position: {
top: 95,
left: left
}
});
}
function onChangegetDealerInfo(vanid) {
// alert(vanid);
// var trlatid = "#" + vanid;
var selected = $("#ddDealerVan option:selected");
var splits = selected.text();
//alert(splits);
var sval = splits.split("/");
var name = sval[0];
var reg = sval[1];
var sid = vanid.split(",");
var output = selected.attr('rel');
// alert(output);
$('#trVanno').show();
$('#trVanReg').show();
$('#trvanname').show();
$('#txtVanReg').val(output);
$('#txtVanno').val(reg);
$('#txtvanname').val(name);
$('#hdnvanid').val(sid[0]);
$('#hdndevicealias').val(sid[1]);
}
function updateAssignVan(ticketid, vanid, devicealias, distance, lat, lng) {
// alert(distance);
var tidval = $('#TicketIdAlias').val();
// alert(tidval)
var apiUrl = url + "Api/TitanDealer?assignvan=yes&type=yes&dealerlist=yes";
$.ajax({
url: apiUrl,
type: 'POST',
dataType: 'json',
data: { ticketid: ticketid, token: securityToken,TicketIdAlias: tidval, LastModifiedBy: userName, AssignedToUserId: vanid, SenderId: devicealias, EstimateDistance: distance, VanLatitude: lat, VanLongitude: lng },
success: function (data) {
var tid = $('#TicketIdAlias').val();
updateAllocatedStatus(tid, "11");
$('#divCreateDealer').data("kendoWindow").close();
// $('#divEditRegno').data("kendoWindow").close();
},
error: function (xhr, textStatus, errorThrown) {
}
});
}
function assignvan(button) {
////console.log(button.id);
var vanid = button.id;
var tid = $('#TicketId').val();
var devicealias = button.dataset.devicealias;
var distance = button.dataset.distance;
var lat = button.dataset.lat;
var lng = button.dataset.lng;
//alert(lat);
//return false;
updateAssignVan(tid, vanid, devicealias, distance, lat, lng)
}
function updateAssignEditVan(ticketid, regno, vanid, devicealias,lat,lng) {
// var splits = $('#txtname').val().split("/");
regno=regno.replace(/-/g, "");
// alert(regno);
//return false;
var name =$('#txtname').val();
var no =$('#txtno').val();
// alert(no);
var apiUrl = url + "Api/TitanDealer?assignvan=yes&type=yes&dealerlist=yes";
$.ajax({
url: apiUrl,
type: 'POST',
dataType: 'json',
data: { ticketid: ticketid, token: securityToken, VehicleRegistrationNumber: regno, DriverName: name, DriverContactNo: no, LastModifiedBy: userName, AssignedToUserId: vanid, SenderId: devicealias, VanLatitude: lat, VanLongitude: lng },
success: function (data) {
var tid = $('#TicketIdAlias').val();
updateAllocatedStatus(tid, "11");
},
error: function (xhr, textStatus, errorThrown) {
}
});
}
function updateAllocatedStatus(ticketid, ticketstatus) {
var tidalias = $('#TicketIdAlias').val();
var tid = $('#TicketId').val();
//alert(tid);
var apiUrl = url + "Api/TitanDealer?updateallocatedstatus=yes";
$.ajax({
url: apiUrl,
type: 'POST',
dataType: 'json',
data: { ticketid_alias: tidalias, token: securityToken, "Status": "true" },
success: function (data) {
if (ticketstatus == "12") {
sessionStorage.setItem("storedId", tid);
sessionStorage.setItem("storedStatus", "AssignDealer");
jAlert("Ticket allocated successfully", 'Message');
// $('#divCreateDealer').data("kendoWindow").close();
}
if (ticketstatus == "11") {
sessionStorage.setItem("storedId", tid);
sessionStorage.setItem("storedStatus", "AssignVan");
//$('#divEditRegno').data("kendoWindow").close();
jAlert("Ticket allocated successfully", 'Message');
}
window.location.reload();
},
error: function (xhr, textStatus, errorThrown) {
}
});
}
/**
* Function to get open tickets history
* @method getOpenTicketsHistory
* @for TicketForDealer
*/
function getOpenTicketsHistory() {
$("#tableTicketHistory > tbody > tr").click(function (e) {
$("#div_loading").show();
$("#labelActivity").trigger('click');
$("#divActivity").html("");
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
//if (displayDisplay) {
// //Remove direction display
// displayDisplay.setMap(null);
//}
////Remove previous markers
//removeTicketDetailsMarkerArray();
var ticketId = e.currentTarget.id;
var assignedVanDealerLatLng, breakdownLocationLatLng;
//remove select class
$("#tableCloseTicketHistory > tbody > tr.select > td").removeClass("SelectRow");
$("#tableCloseTicketHistory > tbody > tr").removeClass("select");
$("#tableTicketHistory > tbody > tr.select > td").removeClass("SelectRow");
$("#tableTicketHistory > tbody > tr").removeClass("select");
$("#tableTicketHistory > tbody > tr[id=" + ticketId + "]").addClass('select');
$("#tableTicketHistory > tbody > tr[id=" + ticketId + "].select > td").addClass('SelectRow');
$("#divMap").css('width', '50%');
$("#divMapContainer").addClass("withtoolbar");
$("#divMapContainer").addClass("MapBox");
$("#divTicketDetailTitle").css('display', 'inline-block');
if (xhr_getOpenTicketDetails && xhr_getOpenTicketDetails.readystate != 4) {
xhr_getOpenTicketDetails.abort();
}
//get ticket details
xhr_getOpenTicketDetails = $.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_GetTicketDetails/",
data: { ticketId: ticketId, ticketStatus: 'open' },
success: function (data) {
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
//if (displayDisplay) {
// //Remove direction display
// displayDisplay.setMap(null);
//}
////Remove previous markers
//removeTicketDetailsMarkerArray();
$("#divDetail").html('');
$("#divDetail").html(data);
//if (ccplMap) {
if ($("#labelRoute").hasClass('toolBtnActive') == true) {
var vanLat = $("#AssignedVanDealerLat").val();
var vanLng = $("#AssignedVanDealerLng").val();
var breakdownLat = $("#BreakdownLat").val();
var breakdownLng = $("#BreakdownLng").val();
if ((vanLat != "" && vanLat != null) && (vanLng != "" && vanLng != null) && (breakdownLat != "" && breakdownLat != null) && (breakdownLng != "" && breakdownLng != null)) {
assignedVanDealerLatLng = vanLat + "," + vanLng;
_breakdownLocationLatLng = breakdownLat + "," + breakdownLng;
// drawStaticMap_MarkersPath("staticMapImgUrl", "700", "450", assignedVanDealerLatLng, _breakdownLocationLatLng)
//assignedVanDealerLatLng = new google.maps.LatLng(vanLat, vanLng);
//breakdownLocationLatLng = new google.maps.LatLng(breakdownLat, breakdownLng);
////Get address of the Lat Long click clicked
//getReverseGeoCode(assignedVanDealerLatLng, function (data) {
// //Here we got the address of the point clicked. Update this value to the form textbox.
// var title = data;
// //create marker at position
// createMarkerVanDealer(assignedVanDealerLatLng, sourceMarker, title);
// //Get address of the Lat Long click clicked
// getReverseGeoCode(breakdownLocationLatLng, function (data) {
// //Here we got the address of the point clicked. Update this value to the form textbox.
// var title = data;
// //create marker at position
// createMarkerVanDealer(breakdownLocationLatLng, destinationMarker, title);
// //calculate route
// calcRoute(assignedVanDealerLatLng, breakdownLocationLatLng);
// //get map bound
// var _bounds = new google.maps.LatLngBounds();
// for (var count = 0; count < ticketDetailsMarkerArray.length; count++) {
// _bounds.extend(ticketDetailsMarkerArray[count].position);
// }
// ccplMap.fitBounds(_bounds);
// });
//});
} else {
$("#div_loading").hide();
}
}
// }
},
complete: function () {
$("#div_loading").hide();
//$("#textBoxDescription").val("");
},
error: function (data) {
console.log(data);
}
});
});
}
/**
* Function to get close tickets history
* @method getCloseTicketsHistory
* @for TicketForDealer
*/
function getCloseTicketsHistory() {
$("#tableCloseTicketHistory > tbody > tr").click(function (e) {
$("#div_loading").show();
$("#labelActivity").trigger('click');
$("#divActivity").html("");
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
//Remove previous markers
removeTicketDetailsMarkerArray();
var ticketId = e.currentTarget.id;
var assignedVanDealerLatLng, breakdownLocationLatLng;
//remove select class
$("#tableTicketHistory > tbody > tr.select > td").removeClass("SelectRow");
$("#tableTicketHistory > tbody > tr").removeClass("select");
$("#tableCloseTicketHistory > tbody > tr.select > td").removeClass("SelectRow");
$("#tableCloseTicketHistory > tbody > tr").removeClass("select");
$("#tableCloseTicketHistory > tbody > tr[id=" + ticketId + "]").addClass('select');
$("#tableCloseTicketHistory > tbody > tr[id=" + ticketId + "].select > td").addClass('SelectRow');
$("#divMap").css('width', '50%');
$("#divTicketDetailTitle").css('display', 'inline-block');
if (xhr_getCloseTickerDetails && xhr_getCloseTickerDetails.readystate != 4) {
xhr_getCloseTickerDetails.abort();
}
xhr_getCloseTickerDetails = $.ajax({
type: "POST",
url: "/TicketAdministration_Dealer/TicketAdministrationDealer_GetTicketDetails/",
data: { ticketId: ticketId, ticketStatus: 'close' },
success: function (data) {
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
//if (displayDisplay) {
// //Remove direction display
// displayDisplay.setMap(null);
//}
////Remove previous markers
//removeTicketDetailsMarkerArray();
$("#divDetail").html('');
$("#divDetail").html(data);
// if (ccplMap) {
if ($("#labelRoute").hasClass('toolBtnActive') == true) {
var vanLat = $("#AssignedVanDealerLat").val();
var vanLng = $("#AssignedVanDealerLng").val();
var breakdownLat = $("#BreakdownLat").val();
var breakdownLng = $("#BreakdownLng").val();
if ((vanLat != "" && vanLat != null) && (vanLng != "" && vanLng != null) && (breakdownLat != "" && breakdownLat != null) && (breakdownLng != "" && breakdownLng != null)) {
assignedVanDealerLatLng = vanLat + "," + vanLng;
_breakdownLocationLatLng = breakdownLat + "," + breakdownLng;
// drawStaticMap_MarkersPath("staticMapImgUrl", "700", "450", assignedVanDealerLatLng, _breakdownLocationLatLng)
//assignedVanDealerLatLng = new google.maps.LatLng(vanLat, vanLng);
//breakdownLocationLatLng = new google.maps.LatLng(breakdownLat, breakdownLng);
////Get address of the Lat Long click clicked
//getReverseGeoCode(assignedVanDealerLatLng, function (data) {
// //Here we got the address of the point clicked. Update this value to the form textbox.
// var title = data;
// //create marker at position
// createMarkerVanDealer(assignedVanDealerLatLng, sourceMarker, title);
// //Get address of the Lat Long click clicked
// getReverseGeoCode(breakdownLocationLatLng, function (data) {
// //Here we got the address of the point clicked. Update this value to the form textbox.
// var title = data;
// //create marker at position
// createMarkerVanDealer(breakdownLocationLatLng, destinationMarker, title);
// var _bounds = new google.maps.LatLngBounds();
// // console.log(ticketDetailsMarkerArray);
// for (var count = 0; count < ticketDetailsMarkerArray.length; count++) {
// _bounds.extend(ticketDetailsMarkerArray[count].position);
// }
// ccplMap.fitBounds(_bounds);
// //calculate route
// calcRoute(assignedVanDealerLatLng, breakdownLocationLatLng);
// });
//});
} else {
$("#div_loading").hide();
}
}
// }
},
complete: function () {
$("#div_loading").hide();
},
error: function (data) {
console.log(data);
}
});
});
}
/**
* This fn return selected tab id.
* @method getSelectedTab
* @for TicketForDealer
*/
function getSelectedTab() {
'use strict';
var selectedTab;
selectedTab = $(".tabs").find('ul > li.ActiveTab')[0].id;
return selectedTab;
}
/**
* This fn get history of ticket
* @method getTicketsHistory
* @param {string} controller Controller name
* @param {string} assignedToType Type to which, Ticket is assigned
* @param {string} divId HTML id of div
* @for TicketForDealer
*/
function getAllocatedticket() {
var allocatehtml = "<div class=\"content overflow\" id=\"divDealerOpenCloseTickets\"> <div><h4>Open Ticket</h4></div>";
allocatehtml += "<table id=\"tableallocatedTicketHistory\" class=\"OpenTicketTbl\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
allocatehtml += "<thead> <tr> <th width=\"84px\">Id</th><th>Status </th> <th>Resolution SLA (in min)</th><th>Response SLA (in min) </th></tr> </thead> <tbody>";
var apiUrl = url + "Api/TitanDealer?type=allocated&dealerlist=yes";
$.ajax({
url: apiUrl,
type: 'POST',
dataType: 'json',
data: { DealerCode: dealerId, token: securityToken },
success: function (data) {
for (keyVar in data) {
if (data.hasOwnProperty(keyVar)) {
//console.log( data[keyVar]);
allocatehtml += "<tr id=" + data[keyVar].TicketId + " data-ticketstatus=\"open\" class=\"trData select\">";
allocatehtml += "<td width=\"84px\" class=\"SelectRow\">" + data[keyVar].TicketIdAlias + "</td>";
allocatehtml += "<td class=\"SelectRow\">To be allocated 12233</td>";
allocatehtml += "<td class=\"SelectRow\">" + data[keyVar].DefaultSlTtime + "</td>"
allocatehtml += " <td class=\"SelectRow\">" + data[keyVar].TotalTicketLifecycleTimeSla + " </td> </tr>";
}
$('#divMyTickets, #divMyVansTickets').html('');
$('#divMyTickets').html(allocatehtml);
$('#divMyTickets').show();
$("#divMyTickets > tbody > tr").first().trigger('click');
$("#li_Activity").show();
// $('#dvallocated').show();
// $('#tableAllocatedHistory').show();
}
}
});
}
function getTicketsHistory(controller, assignedToType, divId) {
// alert(divId);
//alert(tcktid);
//alert(tstatus);
'use strict';
//alert(assignedToType);
// check request already exist or not.
if (xhr_getTicketHistory && xhr_getTicketHistory.readystate != 4) {
xhr_getTicketHistory.abort();
}
xhr_getTicketHistory = $.post("/TicketAdministration_Dealer/" + controller + "/", { assignedToType: assignedToType }, function (data) {
$('#divMyTickets, #divMyVansTickets').html('');
$('#' + divId).html(data);
$('#' + divId).show();
if (!selectedTicket) {
//alert('storedid1');
//alert(storedid);
if(!storedid) {
//alert('storedid3');
if (document.getElementById('tableTicketHistory') != null) {
$("#tableTicketHistory > tbody > tr").first().trigger('click');
$("#li_Activity").show();
} else if (document.getElementById('tableCloseTicketHistory') != null) {
$("#tableCloseTicketHistory > tbody > tr").first().trigger('click');
$("#li_Activity").show();
} else {
$('#' + divId).html("<div class='no_data display_block no_dispalyTop'><span>No open / close tickets are available !!</span></div>")
$("#li_Activity").hide();
$("#divActivity").hide();
$("#labelActivity").trigger('click');
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
//Remove previous markers
removeTicketDetailsMarkerArray();
}
$("#divDetail").html('');
}
}
else{
// alert('storedid4');
$("#" + storedid).trigger("click");
$("#li_Activity").show();
}
}
else {
//alert('storedid2');
//alert(storedid);
var container = $('#divDealerOpenCloseTickets'), scrollTo = $('#' + selectedTicket);
console.log(container);
container.animate({
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()
});
$("#tableTicketHistory > tbody > tr[id='" + selectedTicket + "']").trigger('click');
setTimeout(function () { $("#labelActivity").trigger("click"); }, 500);
selectedTicket = "";
}
});
}
/**
* This fn show ticket history
* @method showTicketHistory
* @for TicketForDealer
*/
function showTicketHistory() {
//alert('storedId');
//alert(tcktid);
//alert(tstatus);
if (tstatus == "AssignDealer") {
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "dealer", "divMyTickets");
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
}
if (tstatus == "AssignVan") {
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "van", "divMyVansTickets");
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
}
if (tstatus == "EPS") {
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "eps", "divMyEPSTickets");
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
}
if (tstatus == "Allocated") {
//alert('aa');
allocatedclick = "yes";
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "allocated", "divMyTickets");
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
}
// get selected tab id.
var tabId;
tabId = getSelectedTab();
allocatedclick = "";
if (tabId == "tabMyTickets") {
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "dealer", "divMyTickets");
}
else if (tabId == "tabMyVansTickets") {
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "van", "divMyVansTickets");
}
else if (tabId == "tabMyAllocatedTickets") {
// alert(tabId)
allocatedclick = "yes";
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "allocated", "divMyTickets");
// getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "van", "divMyVansTickets");
}
else if (tabId == "tabMyEPSTickets") {
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
getTicketsHistory("TicketAdministrationDealer_GetTicketHistory", "eps", "divMyEPSTickets");
}
}
/**S
* Maintain tab functionality. show particular div based on the tab id.
* @method graphicalTabAction
* @for TicketForDealer
*/
function graphicalTabAction() {
'use strict';
$(".divContent").hide();
$("#tabGroup li").removeClass("ActiveTab");
$('#tabGroup li').click(function (e) {
e.stopPropagation();
var target = $(this).attr("rel");
$(".divContent").hide();
$("#tabGroup li").removeClass("ActiveTab");
$(".divContent[rel='" + target + "']").show();
$("#tabGroup li[rel='" + target + "']").addClass("ActiveTab");
showTicketHistory();
});
}
/**
* Function to create markers on van's / dealer's location for ticket details
* @method createMarkerVanDealer
* @param {String} position Position of van / dealer
* @param {String} icon Icon of placed marker
* @param {String} title Title of placed marker
* @for TicketForDealer
*/
function createMarkerVanDealer(position, icon, title) {
//create a google marker with the given param
var vanDealerMarker = new google.maps.Marker({
position: position,
map: ccplMap,
icon: icon,
title: title
});
//push marker to marksArray
ticketDetailsMarkerArray.push(vanDealerMarker);
}
//------------------------------------------ calculate route -------------------------------------//
/**
* This fn removes all markers stored in ticketDetailsMarkerArray.
* @method removeTicketDetailsMarkerArray
* @for TicketForDealer
*/
function removeTicketDetailsMarkerArray() {
//loop through arary
for (var i = 0; i < ticketDetailsMarkerArray.length; i++) {
//set marker map to null
ticketDetailsMarkerArray[i].setMap(null);
}
//empty array
ticketDetailsMarkerArray = [];
}
/**
* This fn calculates and draws the Route for the Ticket selected in the Ticket List using Google Direction API
* @method calcRoute
* @param {String} startLatLng Position of origin
* @param {String} endLatLng Position of destination
* @for TicketForDealer
*/
function calcRoute(startLatLng, endLatLng) {
var merkerIcon;
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
var rendererOptions = {
map: ccplMap,
suppressMarkers: true,
polylineOptions: { strokeColor: "#1b3f94" }
}
displayDisplay = new google.maps.DirectionsRenderer(rendererOptions);
//Make request obj to Direction Service API with starting and end LatLng
var request = {
origin: startLatLng,
destination: endLatLng,
travelMode: google.maps.TravelMode.DRIVING
};
//call Direction Service API with the reuqest obj
routeDirectionsService.route(request, function (response, status) {
//if status was a success
if (status == google.maps.DirectionsStatus.OK) {
displayDisplay.setOptions({ preserveViewport: true });
//set Direction to the response
displayDisplay.setDirections(response);
var leg = response.routes[0].legs[0];
$("#div_loading").hide();
}
});
}
//-------------------------------------------- end routing ---------------------------------------//
//======================================================================GeoCoding Functions=============================================================================//
/**
* This function reverses the Lat Lng to Get the Approxmiate Address using the Google GeoCoding. Callback the result
* @method getReverseGeoCode
* @param {String} latLng lat lng of marker
* @param {String} callback function callback
* @for TicketForDealer
*/
function getReverseGeoCode(latLng, callback) {
// Get google map LatLng object with the latLng in params
var latlng = new google.maps.LatLng(latLng.lat(), latLng.lng());
//Use google geocode library to get results
geoCoder.geocode({ 'latLng': latlng }, function (results, status) {
//If status is Ok
if (status == google.maps.GeocoderStatus.OK) {
//Find most intensive search result and callback it
if (results[0]) {
callback(results[0].formatted_address);
//Else callback no result found
} else {
callback('No results found');
}
}
else { callback('NA'); }
return 'NA';
});
}
//========================== document ready function =========================//
var tcktid = "";
var tstatus = "";
var storedid ="";
$(document).ready(function () {
storedid = sessionStorage.getItem("storedId");
var storedStatus = sessionStorage.getItem("storedStatus");
console.log("Retrieved Value:", storedid);
console.log("Retrieved Value:", storedStatus);
tcktid = storedid;
tstatus = storedStatus;
// alert('tstatus');
//alert(tstatus);
if(storedStatus == null){
}
else{
if(storedStatus == "AssignDealer"){
tcktid = storedid;
tstatus = "dealer";
selectedTicket =tcktid;
assignedTo = tstatus;
}
if(storedStatus == "AssignVan"){
tcktid = storedid;
tstatus = "van";
selectedTicket =tcktid;
assignedTo = tstatus;
}
if(storedStatus == "Allocated"){
tcktid = storedid;
tstatus="allocated";
selectedTicket =tcktid;
assignedTo = tstatus;
}
if (storedStatus == "EPS") {
tcktid = storedid;
tstatus = "EPS";
selectedTicket = tcktid;
assignedTo = tstatus;
}
}
sessionStorage.removeItem("storedId");
sessionStorage.removeItem("storedStatus");
graphicalTabAction();
if (!selectedTicket) {
$("#tabMyTickets").trigger('click');
}
else {
if (assignedTo == "dealer") {
//alert(storedid);
selectedTicket=storedid;
$("#tabMyTickets").trigger('click'); }
else if (assignedTo == "van")
{
//alert(storedid);
selectedTicket=storedid;
$("#tabMyVansTickets").trigger('click'); }
else if (assignedTo == "allocated"){
{
// alert(storedid);
tstatus="allocated";
selectedTicket=storedid;
$("#tabMyAllocatedTickets").trigger('click'); }
}
else if (assignedTo == "EPS") {
{
// alert(storedid);
tstatus = "EPS";
selectedTicket = storedid;
$("#tabMyEPSTickets").trigger('click');
}
}
}
});