EOS/Scripts/out/files/Ticket_TicketAdministration.js.html
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

2545 lines
113 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ticket\TicketAdministration.js</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title=""></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: </em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/CallFeedbackRating.html">CallFeedbackRating</a></li>
<li><a href="../classes/CloseTicketReport.html">CloseTicketReport</a></li>
<li><a href="../classes/ConsolidatedReport.html">ConsolidatedReport</a></li>
<li><a href="../classes/CustomerReport.html">CustomerReport</a></li>
<li><a href="../classes/DealerWiseCallDetails.html">DealerWiseCallDetails</a></li>
<li><a href="../classes/DeclinedCalls.html">DeclinedCalls</a></li>
<li><a href="../classes/DropDownData.html">DropDownData</a></li>
<li><a href="../classes/EicherPromise.html">EicherPromise</a></li>
<li><a href="../classes/EosCallCount.html">EosCallCount</a></li>
<li><a href="../classes/GeoAnalysis.html">GeoAnalysis</a></li>
<li><a href="../classes/HdBusLmdContrCallFeedbackRatingibution.html">HdBusLmdContrCallFeedbackRatingibution</a></li>
<li><a href="../classes/HdBusLmdContribution.html">HdBusLmdContribution</a></li>
<li><a href="../classes/HistoryTracking.html">HistoryTracking</a></li>
<li><a href="../classes/LiveTracking.html">LiveTracking</a></li>
<li><a href="../classes/ManageEscalation.html">ManageEscalation</a></li>
<li><a href="../classes/ManageFleet.html">ManageFleet</a></li>
<li><a href="../classes/ManageFleet_Detail.html">ManageFleet_Detail</a></li>
<li><a href="../classes/ManageFleet_details.html">ManageFleet_details</a></li>
<li><a href="../classes/ManageOwner.html">ManageOwner</a></li>
<li><a href="../classes/ManageReason.html">ManageReason</a></li>
<li><a href="../classes/ManageVechile.html">ManageVechile</a></li>
<li><a href="../classes/ManageVehicle.html">ManageVehicle</a></li>
<li><a href="../classes/NonVecvUserManagement.html">NonVecvUserManagement</a></li>
<li><a href="../classes/Notifications.html">Notifications</a></li>
<li><a href="../classes/OpenTicketReport.html">OpenTicketReport</a></li>
<li><a href="../classes/OrganizationChart.html">OrganizationChart</a></li>
<li><a href="../classes/PositioningTool.html">PositioningTool</a></li>
<li><a href="../classes/PositioningTool_Report.html">PositioningTool_Report</a></li>
<li><a href="../classes/ReasonForClosure.html">ReasonForClosure</a></li>
<li><a href="../classes/Report.html">Report</a></li>
<li><a href="../classes/ShowDealerMap.html">ShowDealerMap</a></li>
<li><a href="../classes/TicketAdministration.html">TicketAdministration</a></li>
<li><a href="../classes/TicketAdministration_FullDetail.html">TicketAdministration_FullDetail</a></li>
<li><a href="../classes/TicketFeedback.html">TicketFeedback</a></li>
<li><a href="../classes/TicketForDealer.html">TicketForDealer</a></li>
<li><a href="../classes/TicketForDealer_FullDetails.html">TicketForDealer_FullDetails</a></li>
<li><a href="../classes/TicketReassign.html">TicketReassign</a></li>
<li><a href="../classes/TileDashboard.html">TileDashboard</a></li>
<li><a href="../classes/TimeSlotClosure.html">TimeSlotClosure</a></li>
<li><a href="../classes/TollFreeAndOpportunityLoss.html">TollFreeAndOpportunityLoss</a></li>
<li><a href="../classes/VanCoverageDesigner.html">VanCoverageDesigner</a></li>
<li><a href="../classes/VecvUserManagement.html">VecvUserManagement</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/Dashboard.html">Dashboard</a></li>
<li><a href="../modules/DropDownData.html">DropDownData</a></li>
<li><a href="../modules/Geo.html">Geo</a></li>
<li><a href="../modules/Inventory.html">Inventory</a></li>
<li><a href="../modules/Notifications.html">Notifications</a></li>
<li><a href="../modules/ReportModule.html">ReportModule</a></li>
<li><a href="../modules/Ticket.html">Ticket</a></li>
<li><a href="../modules/TrackingModule.html">TrackingModule</a></li>
<li><a href="../modules/UserManagement.html">UserManagement</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: Ticket\TicketAdministration.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
/*================================================================================================================\
+
+ Project : GoData-VECV
+ Filename : TicketAdministration.js
+ Module Name : Ticket
+ Purpose : For ticketing
+ Coded By : Parul Gupta
+
+================================================================================================================*/
/**
* For ticketing
* @module Ticket
*/
/**
* This class contains functionality of Ticket administration for CCE.
* @class TicketAdministration
* @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, xhr_CheckHistory;
var searchBox = null;
var ccplMap = null,
markerImagePath = &quot;../../Scripts/map_api/icons/red_blank.png&quot;,
markerTransImgPath = &quot;../../Scripts/map_api/icons/red_blink.gif&quot;,
defaultLat = 26.912285124827,
defaultLng = 75.7873203125
//initialize markers
var sourceMarker = &#x27;../../Scripts/map_api/icons/red_s.png&#x27;; //marker for source
var destinationMarker = &#x27;../../Scripts/map_api/icons/red_d.png&#x27;; //marker for destination
var availableVansMarkers = &#x27;../../Content/css/images/avil-van.png&#x27;; //marker for available vans
var unavailableVansMarkers = &#x27;../../Content/css/images/unavl-van.png&#x27;; //marker for unavailable vans
var dealerMarker = &#x27;../../Content/css/images/dealer-icon.png&#x27;; //marker for dealers
//initialize markers arrays
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 placeLocationMarkerArray = []; //array of placed location markers
var ticketDetailsMarkerArray = []; //array of source and destination markers
var copyResulEls = []; //replica array of result vans and dealers array
var _securityToken;
var _userId;
var marker, geoCoder, directionService;
var breakdownLocationLatLng = &quot;&quot;;
var routeDirectionDisplay = &quot;&quot;;
var routeDirectionsService = new google.maps.DirectionsService(); //direction google map api
var routeDistanceService = new google.maps.DistanceMatrixService(); //distance google map api
var displayDisplay = &quot;&quot;; //route direction display
var displayHighway = &quot;&quot;; //highway display
//Google Distance MAtrix Service API
var service = new google.maps.DistanceMatrixService();
var selectedTicket;
/**
* Load google map on page.
* @method initMap
* @param {String} id HTML element id where map is loaded.
* @for TicketAdministration
*/
function initMap(id) {
var mapOptions = {
center: new google.maps.LatLng(defaultLat, defaultLng),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//initialize map
ccplMap = new google.maps.Map(document.getElementById(id), mapOptions);
//initialize geo coder to get address from lat lng
geoCoder = new google.maps.Geocoder();
// Create the search box and link it to the UI element.
var input = /** @type {HTMLInputElement} */(
document.getElementById(&#x27;searchLocationTool&#x27;));
ccplMap.controls[google.maps.ControlPosition.TOP_CENTER].push(input);
searchBox = new google.maps.places.SearchBox(
/** @type {HTMLInputElement} */(input));
//initialize search places
placeLocationOnMap();
}
//initialize infowindow
var infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(50, 50)
});
//=================================== search places text box ================================//
/**
* function to remove place location markers.
* @method removePlaceLocationMarkerArray
* @for TicketAdministration
*/
function removePlaceLocationMarkerArray() {
for (var i = 0, placeMarker; placeMarker = placeLocationMarkerArray[i]; i++) {
placeMarker.setMap(null);
}
// For each place, get the icon, place name, and location.
placeLocationMarkerArray = [];
}
/**
* Function to search location using search places text box google map api.
* @method placeLocationOnMap
* @for TicketAdministration
*/
function placeLocationOnMap() {
//search location on map
// Listen for the event fired when the user selects an item from the
// pick list. Retrieve the matching places for that item.
google.maps.event.addListener(searchBox, &#x27;places_changed&#x27;, function () {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
removePlaceLocationMarkerArray();
//remove direction path amd markers
if (displayDisplay) {
//Remove previous markers
removeTicketDetailsMarkerArray();
//Remove direction display
displayDisplay.setMap(null);
}
//remove breakdown location marker
if (marker) {
marker.setMap(null);
marker = &quot;&quot;;
}
var bounds = new google.maps.LatLngBounds();
// Create a marker for each place.
var markerLocation = new google.maps.Marker({
map: ccplMap,
title: places[0].name,
position: places[0].geometry.location
});
// console.log(markerLocation);
breakdownLocationLatLng = markerLocation.position;
placeLocationMarkerArray.push(markerLocation);
bounds.extend(places[0].geometry.location);
$(&quot;#eos_exact_location&quot;).val(&quot;&quot;);
$(&quot;#eos_exact_location&quot;).val($(&quot;#searchLocationTool&quot;).val());
ccplMap.fitBounds(bounds);
});
// Bias the SearchBox results towards places that are within the bounds of the
// current map&#x27;s viewport.
google.maps.event.addListener(ccplMap, &#x27;bounds_changed&#x27;, function () {
var bounds = ccplMap.getBounds();
searchBox.setBounds(bounds);
});
}
//================================== end of search place locations =================================//
/**
* Get Check History Form view
* @method viewCheckHistory
* @for TicketAdministration
*/
function viewCheckHistory() {
//Remove Source Destination Direction Display if visible
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
//stopIntervalRefreshTicketList();
if (selectedTicket != &quot;&quot;) {
selectedTicket = &quot;&quot;;
}
//Remove previous markers if any present
removeTicketDetailsMarkerArray();
//add active class to selected tab
$(&quot;#tabCheckHistory&quot;).addClass(&#x27;ActiveTab&#x27;);
$(&quot;#divMap&quot;).css(&#x27;width&#x27;, &#x27;75%&#x27;);
$(&quot;#divTicketDetailTitle&quot;).hide();
$(&quot;#divActivity&quot;).hide();
$(&quot;#divFeedback&quot;).hide();
$(&quot;#divMapContainer&quot;).show();
$(&quot;#searchLocationTool&quot;).hide();
$(&#x27;#labelActivity&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelFeedback&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelRoute&#x27;).removeClass(&quot;toolBtnActive&quot;);
//send ajax request
if (xhr_CheckHistory &amp;&amp; xhr_CheckHistory.readystate != 4) {
xhr_CheckHistory.abort();
}
xhr_CheckHistory = $.ajax({
type: &quot;GET&quot;,
url: &quot;/Ticket/TicketAdministration_CheckHistory/&quot;,
success: function (data) {
$(&quot;#divCheckHistory&quot;).html(data);
$(&quot;#divMapDetail&quot;).addClass(&quot;display_none&quot;);
$(&quot;#divMapContainer&quot;).removeClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).removeClass(&quot;MapBox&quot;);
},
error: function (data) {
console.log(data);
}
});
}
/**
* Function call on click of Route label to show map
* @method onclickLabelRoute
* @for TicketAdministration
*/
function onclickLabelRoute() {
//on click of label route
$(&quot;#labelRoute&quot;).click(function () {
// add selected class
$(&#x27;#labelActivity&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelFeedback&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelRoute&#x27;).addClass(&quot;toolBtnActive&quot;);
$(&quot;#divMapContainer&quot;).show();
$(&quot;#divFeedback&quot;).hide();
$(&quot;#divActivity&quot;).css(&#x27;display&#x27;, &#x27;none&#x27;);
});
}
/**
* Function call on click of Activity label to show ticket activity
* @method onclickLabelActivity
* @for TicketAdministration
*/
function onclickLabelActivity() {
//on click of label Activities
$(&quot;#labelActivity&quot;).click(function () {
$(&quot;#divActivity&quot;).html(&#x27;&#x27;);
// add selected class
$(&#x27;#labelRoute&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelFeedback&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelActivity&#x27;).addClass(&quot;toolBtnActive&quot;);
$(&quot;#divActivity&quot;).css(&#x27;display&#x27;, &#x27;inline-block&#x27;);
$(&quot;#divActivity&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).hide();
$(&quot;#divFeedback&quot;).hide();
var ticketId;
if ((document.getElementById(&#x27;tableTicketHistory&#x27;)) || (document.getElementById(&#x27;tableCloseTicketHistory&#x27;)) || ((document.getElementById(&#x27;tableTicketHistory&#x27;)) &amp;&amp; (document.getElementById(&#x27;tableCloseTicketHistory&#x27;)))) {
if (document.getElementById(&#x27;tableTicketHistory&#x27;)) {
if ($(&quot;#tableTicketHistory &gt; tbody &gt; tr&quot;).hasClass(&#x27;select&#x27;)) {
ticketId = $(&quot;#tableTicketHistory &gt; tbody &gt; tr.select&quot;)[0].id;
//get ticket activity details
if (xhr_showActivity &amp;&amp; xhr_showActivity.readystate != 4) {
xhr_showActivity.abort();
}
xhr_showActivity = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_ShowTicketActivityOpenClose/&quot;,
data: { ticketId: ticketId, ticketStatus: &#x27;open&#x27; },
success: function (data) {
//console.log(data);
$(&quot;#divActivity&quot;).html(data);
$(&quot;#ddTicketStatus, #textBoxDescription, #ddReasonForOpportunityLost&quot;).attr(&quot;disabled&quot;, false);
$(&quot;#button_submit&quot;).show();
},
error: function (data) { }
});
}
else {
ticketId = $(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select&quot;)[0].id;
//get ticket activity details
if (xhr_showActivity &amp;&amp; xhr_showActivity.readystate != 4) {
xhr_showActivity.abort();
}
xhr_showActivity = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_ShowTicketActivityOpenClose/&quot;,
data: { ticketId: ticketId, ticketStatus: &#x27;close&#x27; },
success: function (data) {
//console.log(data);
$(&quot;#divActivity&quot;).html(data);
$(&quot;#ddTicketStatus, #textBoxDescription, #ddReasonForOpportunityLost&quot;).attr(&quot;disabled&quot;, true);
$(&quot;#button_submit&quot;).hide();
},
error: function (data) { }
});
}
} else {
ticketId = $(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select&quot;)[0].id;
//get ticket activity details
if (xhr_showActivity &amp;&amp; xhr_showActivity.readystate != 4) {
xhr_showActivity.abort();
}
xhr_showActivity = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_ShowTicketActivityOpenClose/&quot;,
data: { ticketId: ticketId, ticketStatus: &#x27;close&#x27; },
success: function (data) {
//console.log(data);
$(&quot;#divActivity&quot;).html(data);
$(&quot;#ddTicketStatus, #textBoxDescription, #ddReasonForOpportunityLost&quot;).attr(&quot;disabled&quot;, true);
$(&quot;#button_submit&quot;).hide();
},
error: function (data) { }
});
}
}
});
}
/**
* Function call on click of Route label to show map
* @method onclickLabelRoute
* @for TicketAdministration
*/
function onclickLabelFeedback() {
//on click of label route
$(&quot;#labelFeedback&quot;).click(function () {
var selectTicketId;
var ticketCreationTime, isMoreThan24Hrs, isFeedBackDetails;
// add selected class
$(&#x27;#labelActivity&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelRoute&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelFeedback&#x27;).addClass(&quot;toolBtnActive&quot;);
$(&quot;#divFeedback&quot;).show();
$(&quot;#divFeedback&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).hide();
$(&quot;#divActivity&quot;).css(&#x27;display&#x27;, &#x27;none&#x27;);
showFeedback();
});
}
/**
* Function call on click of feedback label to show feedback form
* @method showFeedback
* @for TicketAdministration
*/
function showFeedback() {
var selectTicketId;
var ticketCreationTime, isMoreThan24Hrs, isFeedBackDetails;
if ($(&quot;#tableTicketHistory &gt; tbody &gt; tr.select&quot;)[0] != undefined) {
selectTicketId = $(&quot;#tableTicketHistory &gt; tbody &gt; tr.select&quot;)[0].id;
ticketCreationTime = document.getElementById(selectTicketId).getAttribute(&#x27;data-ticketCreationTime&#x27;);
isMoreThan24Hrs = document.getElementById(selectTicketId).getAttribute(&#x27;data-reason24Hrs&#x27;);
isFeedBackDetails = document.getElementById(selectTicketId).getAttribute(&#x27;data-isFeedback&#x27;);
}
else {
selectTicketId = $(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select&quot;)[0].id;
ticketCreationTime = document.getElementById(selectTicketId).getAttribute(&#x27;data-ticketCreationTime&#x27;);
isMoreThan24Hrs = document.getElementById(selectTicketId).getAttribute(&#x27;data-reason24Hrs&#x27;);
isFeedBackDetails = document.getElementById(selectTicketId).getAttribute(&#x27;data-isFeedback&#x27;);
}
//console.log(selectTicketId);
$.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_Feedback/&quot;,
data: { selectTicketId: selectTicketId, ticketCreationTime: ticketCreationTime, isMoreThan24Hrs: isMoreThan24Hrs },
success: function (data) {
if (data) {
$(&quot;#divFeedback&quot;).html(data);
}
},
error: function (data) {
console.log(data);
}
});
}
/**
* Function call on click of back button
* @method onBackButtonClick
* @for TicketAdministration
*/
function onBackButtonClick() {
viewCheckHistory();
}
/**
* Function to get ticket history based on vehicle registration no., customer/owner mobile no. or ticket id/complaint no.
* @method getTicketHistory
* @for TicketAdministration
*/
function getTicketHistory() {
var registrationNo, mobileNo, complaintNo;
registrationNo = $(&quot;#RegistrationNo&quot;).val();
mobileNo = $(&quot;#MobileNo&quot;).val();
if (selectedTicket) {
complaintNo = selectedTicket;
$(&quot;#tabCheckHistory&quot;).addClass(&#x27;ActiveTab&#x27;);
}
else {
complaintNo = $(&quot;#ComplaintNo&quot;).val();
}
if (xhr_getTicketHistory &amp;&amp; xhr_getTicketHistory.readystate != 4) {
xhr_getTicketHistory.abort();
}
xhr_getTicketHistory = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_GetTicketHistory/&quot;,
data: { registrationNo: registrationNo, mobileNo: mobileNo, complaintNo: complaintNo },
success: function (data) {
if (data.fillFieldMesseage) {
jAlert(data.fillFieldMesseage, &#x27;Message&#x27;);
}
else {
$(&quot;#divCheckHistory&quot;).html(&quot;&quot;);
$(&quot;#divCheckHistory&quot;).html(data);
var searchedTicketId = $(&quot;#VComplaintNo&quot;).val();
// console.log(searchedTicketId);
$(&#x27;#labelRoute&#x27;).addClass(&quot;toolBtnActive&quot;);
if (document.getElementById(&#x27;tableTicketHistory&#x27;)) {
$(&quot;#divMap&quot;).css({ &#x27;width&#x27;: &#x27;50%&#x27;, &#x27;left&#x27;: &#x27;25%&#x27;, &#x27;right&#x27;: &#x27;25%&#x27; });
$(&quot;#divMapDetail&quot;).removeClass(&quot;display_none&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;MapBox&quot;);
if (searchedTicketId != null &amp;&amp; searchedTicketId != &quot;&quot;) {
$(&quot;#&quot; + searchedTicketId).trigger(&quot;click&quot;);
} else {
$(&quot;#tableTicketHistory &gt; tbody &gt; tr:first&quot;).trigger(&quot;click&quot;);
}
} else if (document.getElementById(&#x27;tableCloseTicketHistory&#x27;)) {
$(&quot;#divMapDetail&quot;).removeClass(&quot;display_none&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;MapBox&quot;);
$(&quot;#divMap&quot;).css({ &#x27;width&#x27;: &#x27;50%&#x27;, &#x27;left&#x27;: &#x27;25%&#x27;, &#x27;right&#x27;: &#x27;25%&#x27; });
if (searchedTicketId != null &amp;&amp; searchedTicketId != &quot;&quot;) {
$(&quot;#&quot; + searchedTicketId).trigger(&quot;click&quot;);
} else {
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr:first&quot;).trigger(&quot;click&quot;);
}
}
}
selectedTicket = &quot;&quot;;
},
error: function (data) {
console.log(data);
}
});
}
/**
* Function to get close ticket details
* @method getCloseTicketDetails
* @for TicketAdministration
*/
function getCloseTicketDetails() {
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr&quot;).click(function (e) {
$(&quot;#div_loading&quot;).show();
$(&quot;#labelRoute&quot;).trigger(&#x27;click&#x27;);
$(&quot;#listFeedback&quot;).show();
$(&quot;#divDetail&quot;).html(&#x27;&#x27;);
$(&quot;#divFeedback&quot;).html(&quot;&quot;);
$(&quot;#divActivity&quot;).html(&quot;&quot;);
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
if (displayDisplay) {
//Remove previous markers
removeTicketDetailsMarkerArray();
//Remove direction display
displayDisplay.setMap(null);
}
var assignedVanDealerLatLng, _breakdownLocationLatLng;
var ticketId = e.currentTarget.id;
var ticketStatus = document.getElementById(ticketId).getAttribute(&#x27;data-ticketStatus&#x27;);
var vRegistrationNo = $(&quot;#VRegistrationNo&quot;).val();
//remove select class
$(&quot;#tableTicketHistory &gt; tbody &gt; tr.select &gt; td&quot;).removeClass(&quot;SelectRow&quot;);
$(&quot;#tableTicketHistory &gt; tbody &gt; tr&quot;).removeClass(&quot;select&quot;);
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select &gt; td&quot;).removeClass(&quot;SelectRow&quot;);
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr&quot;).removeClass(&quot;select&quot;);
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr[id=&quot; + ticketId + &quot;]&quot;).addClass(&#x27;select&#x27;);
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr[id=&quot; + ticketId + &quot;].select &gt; td&quot;).addClass(&#x27;SelectRow&#x27;);
$(&quot;#divMap&quot;).css(&#x27;width&#x27;, &#x27;50%&#x27;);
$(&quot;#divTicketDetailTitle&quot;).css(&#x27;display&#x27;, &#x27;inline-block&#x27;);
//call rest api
if (xhr_getCloseTickerDetails &amp;&amp; xhr_getCloseTickerDetails.readystate != 4) {
xhr_getCloseTickerDetails.abort();
}
xhr_getCloseTickerDetails = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_GetTicketDetails/&quot;,
data: { ticketId: ticketId, ticketStatus: &#x27;close&#x27; },
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();
$(&quot;#divDetail&quot;).html(data);
if ($(&quot;#labelRoute&quot;).hasClass(&#x27;toolBtnActive&#x27;) == true) {
var vanLat = $(&quot;#AssignedVanDealerLat&quot;).val();
var vanLng = $(&quot;#AssignedVanDealerLng&quot;).val();
var breakdownLat = $(&quot;#BreakdownLat&quot;).val();
var breakdownLng = $(&quot;#BreakdownLng&quot;).val();
if ((vanLat != &quot;&quot; &amp;&amp; vanLat != null) &amp;&amp; (vanLng != &quot;&quot; &amp;&amp; vanLng != null) &amp;&amp; (breakdownLat != &quot;&quot; &amp;&amp; breakdownLat != null) &amp;&amp; (breakdownLng != &quot;&quot; &amp;&amp; breakdownLng != null)) {
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, &quot;&quot;, ccplMap, []);
var _bounds = new google.maps.LatLngBounds();
for (var count = 0; count &lt; ticketDetailsMarkerArray.length; count++) {
_bounds.extend(ticketDetailsMarkerArray[count].position);
}
ccplMap.fitBounds(_bounds);
});
});
} else {
$(&quot;#div_loading&quot;).hide();
}
}
},
error: function (data) {
console.log(data);
}
});
});
}
/**
* Function to get open ticket details
* @method getTicketDetails
* @for TicketAdministration
*/
function getTicketDetails(tableId) {
$(&quot;#tableTicketHistory &gt; tbody &gt; tr&quot;).click(function (e) {
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
$(&quot;#div_loading&quot;).show();
$(&quot;#labelRoute&quot;).trigger(&#x27;click&#x27;);
$(&quot;#listFeedback&quot;).hide();
$(&quot;#divDetail&quot;).html(&#x27;&#x27;);
$(&quot;#divFeedback&quot;).html(&quot;&quot;);
$(&quot;#divActivity&quot;).html(&quot;&quot;);
if (displayDisplay) {
//Remove previous markers
removeTicketDetailsMarkerArray();
//Remove direction display
displayDisplay.setMap(null);
}
var assignedVanDealerLatLng, _breakdownLocationLatLng;
var ticketId = e.currentTarget.id;
var ticketStatus = document.getElementById(ticketId).getAttribute(&#x27;data-ticketStatus&#x27;);
var vRegistrationNo = $(&quot;#VRegistrationNo&quot;).val();
//remove select class
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select &gt; td&quot;).removeClass(&quot;SelectRow&quot;);
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr&quot;).removeClass(&quot;select&quot;);
$(&quot;#tableTicketHistory &gt; tbody &gt; tr.select &gt; td&quot;).removeClass(&quot;SelectRow&quot;);
$(&quot;#tableTicketHistory &gt; tbody &gt; tr&quot;).removeClass(&quot;select&quot;);
$(&quot;#tableTicketHistory &gt; tbody &gt; tr[id=&quot; + ticketId + &quot;]&quot;).addClass(&#x27;select&#x27;);
$(&quot;#tableTicketHistory &gt; tbody &gt; tr[id=&quot; + ticketId + &quot;].select &gt; td&quot;).addClass(&#x27;SelectRow&#x27;);
$(&quot;#divMap&quot;).css(&#x27;width&#x27;, &#x27;50%&#x27;);
$(&quot;#divMapContainer&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;MapBox&quot;);
$(&quot;#divTicketDetailTitle&quot;).css(&#x27;display&#x27;, &#x27;inline-block&#x27;);
if (xhr_getOpenTicketDetails &amp;&amp; xhr_getOpenTicketDetails.readystate != 4) {
xhr_getOpenTicketDetails.abort();
}
//get ticket details
xhr_getOpenTicketDetails = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_GetTicketDetails/&quot;,
data: { ticketId: ticketId, ticketStatus: &#x27;open&#x27; },
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();
$(&quot;#divDetail&quot;).html(data);
if (ccplMap) {
if ($(&quot;#labelRoute&quot;).hasClass(&#x27;toolBtnActive&#x27;) == true) {
var vanLat = $(&quot;#AssignedVanDealerLat&quot;).val();
var vanLng = $(&quot;#AssignedVanDealerLng&quot;).val();
var breakdownLat = $(&quot;#BreakdownLat&quot;).val();
var breakdownLng = $(&quot;#BreakdownLng&quot;).val();
if ((vanLat != &quot;&quot; &amp;&amp; vanLat != null) &amp;&amp; (vanLng != &quot;&quot; &amp;&amp; vanLng != null) &amp;&amp; (breakdownLat != &quot;&quot; &amp;&amp; breakdownLat != null) &amp;&amp; (breakdownLng != &quot;&quot; &amp;&amp; breakdownLng != null)) {
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, &quot;&quot;, ccplMap, []);
var _bounds = new google.maps.LatLngBounds();
for (var count = 0; count &lt; ticketDetailsMarkerArray.length; count++) {
_bounds.extend(ticketDetailsMarkerArray[count].position);
}
ccplMap.fitBounds(_bounds);
});
});
} else {
$(&quot;#div_loading&quot;).hide();
}
}
}
},
error: function (data) {
console.log(data);
}
});
});
}
/**
* Function to add new ticket
* @method addNewTicket
* @for TicketAdministration
*/
function addNewTicket() {
breakdownLocationLatLng = &quot;&quot;;
var VRegistrationNo = $(&quot;#VRegistrationNo&quot;).val();
$(&quot;#searchLocationTool&quot;).attr(&#x27;readonly&#x27;, false);
$(&quot;#eos_exact_location, #nature_of_problem, #vehicle_direction, #vehicle_type_of_load, #breakdown_landmark, #searchLocationTool&quot;).val(&#x27;&#x27;);
$(&quot;#driver_name&quot;).val(&#x27;-Select-&#x27;);
getMobileNoCustomerWise();
getLanguageList(&quot;vehicle_owner_language&quot;); //get languages list in drop down
getTollFreeSourceList(&quot;tollFreeNoSource&quot;); //get sources list of toll free no. in drop down
getWarrentyAmcList(&quot;isVehicleInWarrentyOrAmc&quot;); //get warrenty list in drop down
getStateList(); //get all states list in drop down
//LoadCityListOnStateChange();
getRoutesList(); // get all routes list in drop down
GetChassisNo();// get the chasis number
//get owner detailsLoadCityList(id)
$.getJSON(&quot;/Ticket_CustomerInventory/GetOwnerDetailsBasedOnMobilenNo/&quot;, { RegistrationNo: VRegistrationNo, OwnerMobileNo: &quot;&quot; }, function (result) {
console.log(result);
if (result.CustomerOwnerDetails) {
var Details = result.CustomerOwnerDetails;
for (var count = 0; count &lt; Details.length; count++) {
if (Details[count].CustomerVehicleIsOwner == true) {
$(&quot;#vehicle_owner_name&quot;).val(Details[count].CustomerCustomerName);
$(&quot;#vehicle_owner_contact_no&quot;).val(Details[count].CustomerMobileNumber1);
$(&quot;#vehicle_owner_location&quot;).val(Details[count].CustomerState);
$(&quot;#vehicle_owner_emailID&quot;).val(Details[count].CustomerEmailId);
$(&quot;#vehicle_owner_Address&quot;).val(Details[count].CustomerAddress);
$(&quot;#vehicle_owner_City&quot;).val(Details[count].CustomerCity);
}
}
}
});
//get vehicle details
$.getJSON(&quot;/Ticket_CustomerInventory/GetVehicleDetailsBasedOnRegistrationNo/&quot;, { RegistrationNo: VRegistrationNo }, function (result) {
if (result.VehicleDetails) {
var Details = result.VehicleDetails;
for (var count = 0; count &lt; Details.length; count++) {
$(&quot;#vehicle_registration&quot;).val(Details[count].RegistrationNo);
$(&quot;#vehicle_numberPlate&quot;).val(Details[count].VehicleNumberPlate);
$(&quot;#vehicle_model&quot;).val(Details[count].ModelNumber);
$(&quot;#vehicle_model&quot;).prop(&#x27;title&#x27;, Details[count].ModelNumber);
$(&quot;#eos_VehicleType&quot;).val(Details[count].VehicleType);
$(&quot;#eos_VehicleInstallationDate&quot;).val(Details[count].VehicleInstallationDate);
var VModel = $(&quot;#vehicle_model&quot;).val();
//get model tagging
$.getJSON(&quot;/Ticket_CustomerInventory/GetVehicleModelTaggingBasedOnModelNo/&quot;, { ModelTypeId: VModel }, function (result) {
if (result) {
var ModelType = result.VehicleModelTagging;
for (var count = 0; count &lt; ModelType.length; count++) {
$(&quot;#vehicle_product_varient&quot;).val(ModelType[0].VehicleTypeTagging);
}
}
});
}
}
});
$(&quot;#Ticket_List&quot;).hide();
$(&quot;#divActivity&quot;).hide();
$(&quot;#divFeedback&quot;).hide();
$(&quot;#divMapContainer&quot;).show();
$(&quot;#searchLocationTool&quot;).show();
$(&quot;#divCheckHistory, #divMapContainer&quot;).removeClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).removeClass(&quot;MapBox&quot;);
$(&quot;#divMapDetail&quot;).addClass(&quot;display_none&quot;);
$(&quot;#Tracker_form, #Tracker_from_BtnWrp&quot;).removeClass(&quot;display_none&quot;);
$(&quot;#divInnerWindow&quot;).css(&#x27;width&#x27;, &#x27;25%&#x27;);
$(&quot;#divMap&quot;).removeClass(&quot;size50&quot;);
$(&quot;#divMap&quot;).css({ &quot;width&quot;: &quot;75%&quot;, &quot;left&quot;: &quot;25%&quot;, &quot;right&quot;: &quot;0%&quot; });
$(&quot;#divTicketDetailTitle&quot;).css(&#x27;display&#x27;, &#x27;none&#x27;);
bindClickEventToMap(); // bind click event on map to select breakdown location
placeLocationOnMap();
if (displayDisplay) {
//Remove previous markers
removeTicketDetailsMarkerArray();
//Remove direction display
displayDisplay.setMap(null);
}
}
function hidetelematic() {
debugger;
var drpval = $("#tollFreeNoSource").val();
if ($("#tollFreeNoSource").val() != "Telematic") {
//document.getElementById("tr_telelat").style.display = "none";
//document.getElementById("tr_telelastlog").style.display = "none";
$("#tr_telelat").hide();
$("#tr_telelastlog").hide();
}
else {
$("#tr_telelat").show();
$("#tr_telelastlog").show();
}
}
function GetChassisNo() {
var vehicleRegistrationNo = $("#VRegistrationNo").val().replace(/-/g, "");
// var vehicleRegistrationNo = $("#VehicleRegistrationNumber").val().replace(getNearestVansDealers/-/g, "");
$.getJSON("/Ticket_CustomerInventory/GetChassisNo/", { RegistrationNo: vehicleRegistrationNo }, function (result) {
if (result.Status != "0") {
var Details = result.Chassis_Details[0];
var latlong = Details.latitude + "," + Details.longitude;
$("#Tele_latlong").val(latlong);
$("#Tele_date").val(result.lastdate);
// $("#age").css('background-color', 'green');
$("#Tele_latlong").css('border-color', 'blue');
$("#Tele_date").css('border-color', 'blue');
//new Date("2011-07-14 11:23:00")
}
else
$("#thirdPartyInfoupdatedornot").prop("disabled", true);
});
}
/**
* Function to bind all states in drop down
* @method getStateList
* @for TicketAdministration
*/
function getStateList() {
$.ajax({
type: &quot;GET&quot;,
url: &quot;/Ticket/GetAllStateList/&quot;,
success: function (data) {
// empty City dropdown
$(&quot;#eos_state&quot;).text(&quot;&quot;);
// by default add select text.
$(&quot;#eos_state&quot;).append($(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(&quot;&quot;).html(&quot;-Select-&quot;));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter &lt; data.list.length; counter++) {
$(&quot;#eos_state&quot;).append(
$(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(data.list[counter].Value).html(data.list[counter].Text));
}
}
},
error: function (data) {
console.log(data);
}
});
}
/**
* Function to add new customer
* @method LoadCityList
* @param {string} ddlId HTML id of drop down list of city
* @param {string} cityValue HTML value of drop down list selected item of city
* @for TicketAdministration
*/
function LoadCityList(ddlId, cityValue) {
var DdlId = ddlId;
var ddCityId;
if (DdlId == &quot;ddOwnerState&quot;) {
ddCityId = &quot;#ddOwnerCity&quot;;
$(&quot;#customerOwnerStateName&quot;).val($(&#x27;#ddOwnerState&#x27;).find(&#x27;option:selected&#x27;).text());
}
else {
ddCityId = &quot;#ddCustomerCity&quot;;
$(&quot;#customerStateName&quot;).val($(&#x27;#ddCustomerState&#x27;).find(&#x27;option:selected&#x27;).text());
}
var stateVal;
stateVal = $(&quot;#&quot; + DdlId).val();
if (stateVal != &quot;-Select-&quot;) {
stateVal = $(&quot;#&quot; + DdlId).val();
}
else {
stateVal = 0;
}
if (stateVal != &quot;&quot;) {
$.ajax({
type: &quot;GET&quot;,
url: &quot;/Ticket_CustomerInventory/showCityStateWise/&quot;,
data: { stateVal: stateVal },
success: function (data) {
// empty City dropdown
$(ddCityId).text(&quot;&quot;);
// by default add select text.
$(ddCityId).append($(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(&quot;&quot;).html(&quot;-Select-&quot;));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter &lt; data.list.length; counter++) {
$(ddCityId).append(
$(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(data.list[counter].Value).html(data.list[counter].Text));
}
}
},
complete: function () {
if (cityValue) {
$(ddCityId).val(cityValue);
}
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* Function to bind all routes in drop down
* @method getRoutesList
* @for TicketAdministration
*/
function getRoutesList() {
$.ajax({
type: &quot;GET&quot;,
url: &quot;/Ticket/GetAllRoutesList/&quot;,
success: function (data) {
// empty routes dropdown
$(&quot;#routes&quot;).text(&quot;&quot;);
// by default add select text.
$(&quot;#routes&quot;).append($(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(&quot;&quot;).html(&quot;-Select-&quot;));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter &lt; data.list.length; counter++) {
$(&quot;#routes&quot;).append(
$(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(data.list[counter].Value).html(data.list[counter].Text));
}
}
},
error: function (data) {
console.log(data);
}
});
}
/**
* Function call onclick cancel button
* @method btnCancel
* @for TicketAdministration
*/
function btnCancel() {
onClickAssignTicketOrCancel();
if ($(&quot;#tableTicketHistory &gt; tbody &gt; tr.select&quot;)[0] != undefined) {
$(&quot;#tableTicketHistory &gt; tbody &gt; tr.select&quot;).trigger(&quot;click&quot;);
} else if ($(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select&quot;)[0] != undefined) {
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr.select&quot;).trigger(&quot;click&quot;);
} else {
$(&quot;#divMapContainer&quot;).removeClass(&quot;MapBox&quot;);
$(&quot;#divMapContainer&quot;).removeClass(&quot;withtoolbar&quot;);
$(&quot;#divTicketDetailTitle&quot;).hide();
$(&quot;#divMap&quot;).addClass(&quot;size50&quot;);
$(&quot;#divMap&quot;).css({ &#x27;width&#x27;: &#x27;75%&#x27;, &#x27;left&#x27;: &#x27;25%&#x27; });
}
}
/**
* Function call onclick of cancel or assign ticket
* @method onClickAssignTicketOrCancel
* @for TicketAdministration
*/
function onClickAssignTicketOrCancel() {
$(&#x27;#labelRoute&#x27;).addClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelFeedback&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&#x27;#labelActivity&#x27;).removeClass(&quot;toolBtnActive&quot;);
$(&quot;#Ticket_List&quot;).show();
$(&quot;#searchLocationTool&quot;).hide();
$(&quot;#divFeedback&quot;).hide();
$(&quot;#divActivity&quot;).css(&#x27;display&#x27;, &#x27;none&#x27;);
$(&quot;#divCheckHistory&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapDetail&quot;).removeClass(&quot;display_none&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;MapBox&quot;);
$(&quot;#Tracker_form, #Tracker_from_BtnWrp&quot;).addClass(&quot;display_none&quot;);
$(&quot;#divInnerWindow&quot;).css(&#x27;width&#x27;, &#x27;25%&#x27;);
$(&quot;#divMap&quot;).addClass(&quot;size50&quot;);
$(&quot;#divMap&quot;).css({ &#x27;width&#x27;: &#x27;50%&#x27;, &#x27;left&#x27;: &#x27;25%&#x27;, &#x27;right&#x27;: &#x27;25%&#x27;, &#x27;height&#x27;: &#x27;&#x27; });
$(&quot;#divVanDealerList&quot;).hide();
$(&quot;#divTicketDetailTitle&quot;).css(&#x27;display&#x27;, &#x27;inline-block&#x27;);
//Remove Source Destination Direction Display if visible
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
//Remove highway Display if visible
if (displayHighway) {
//Remove direction display
displayHighway.setMap(null);
}
if (nearestVansDealersMarks.length &gt; 0) {
//loop through arary
for (var i = 0; i &lt; nearestVansDealersMarks.length; i++) {
//set marker map to null
nearestVansDealersMarks[i].setMap(null);
}
//empty array
nearestVansDealersMarks = [];
}
removeClickEventToMap();
removePlaceLocationMarkerArray();
}
/**
* Function to add new customer
* @method addNewCustomer
* @for TicketAdministration
*/
function addNewCustomer() {
var vRegNo = $(&quot;#VRegistrationNo&quot;).val();
createAjaxRequest(&quot;Ticket_CustomerInventory&quot;, &quot;Create&quot;, &quot;#divAddCustomer&quot;, vRegNo);
}
//Global variable for Customer(owner) Mobile No.
var customerMobileNo1;
/**
* Function to check owner mobile no. on focus
* @method checkIfContactNoIsSame
* @for TicketAdministration
*/
function checkIfContactNoIsSame() {
$(&quot;#CustomerOwnerMobileNo1&quot;).focus(function () {
customerMobileNo1 = $(&quot;#CustomerOwnerMobileNo1&quot;).val();
});
}
/**
* Function to check is owner exist already
* @method checkIsOwnerExist
* @for TicketAdministration
*/
function checkIsOwnerExist() {
$(&quot;#CustomerOwnerMobileNo1&quot;).blur(function () {
var vehicleRegistrationNo = $(&quot;#VehicleRegistrationNumber&quot;).val();
var ownerMobileNo = $(&quot;#CustomerOwnerMobileNo1&quot;).val();
if (ownerMobileNo != customerMobileNo1) {
//call web api to check is owner exist true, if yes autofill other fields of vehicle
$.getJSON(&quot;/Ticket_CustomerInventory/GetOwnerDetailsBasedOnMobilenNo/&quot;, { RegistrationNo: vehicleRegistrationNo, OwnerMobileNo: ownerMobileNo }, function (result) {
if (result.CustomerOwnerDetails) {
var Details = result.CustomerOwnerDetails;
for (var count = 0; count &lt; Details.length; count++) {
if (Details[count].CustomerId != null) {
if (Details[count].CustomerVehicleIsOwner == true) {
if (ownerMobileNo == &quot;&quot;) {
$(&quot;#CustomerOwnerMobileNo1&quot;).val(Details[count].CustomerMobileNumber1);
}
$(&quot;#CustomerOwnerName&quot;).val(Details[count].CustomerCustomerName);
$(&quot;#CustomerOwnerEmailId&quot;).val(Details[count].CustomerEmailId);
//set selected state
var stateName = Details[count].CustomerState;
var dd = document.getElementById(&#x27;ddOwnerState&#x27;);
for (var i = 0; i &lt; dd.options.length; i++) {
if (dd.options[i].text === stateName) {
dd.selectedIndex = i;
break;
}
}
LoadCityList(&quot;ddOwnerState&quot;, Details[count].CustomerCity);
$(&quot;#CustomerOwnerAddress&quot;).val(Details[count].CustomerAddress);
}
}
else {
if (ownerMobileNo == &quot;&quot;) {
$(&quot;#CustomerOwnerMobileNo1&quot;).val(&#x27;&#x27;);
}
$(&quot;#CustomerOwnerName&quot;).val(&#x27;&#x27;);
$(&quot;#CustomerOwnerEmailId&quot;).val(&#x27;&#x27;);
$(&quot;#CustomerOwnerAddress&quot;).val(&#x27;&#x27;);
$(&quot;#ddOwnerState&quot;).val(&#x27;&#x27;);
$(&quot;#ddOwnerCity&quot;).val(&#x27;&#x27;);
}
}
}
});
}
});
}
//Global variable for Customer(owner) Vehicle Registration No.
var customerVehicleRegistrationNo;
/**
* Function to check owner vehicle registration no. on focus
* @method checkIfVRegistrationNoIsSame
* @for TicketAdministration
*/
function checkIfVRegistrationNoIsSame() {
$(&quot;#VehicleRegistrationNumber&quot;).focus(function () {
customerVehicleRegistrationNo = $(&quot;#VehicleRegistrationNumber&quot;).val().replace(/-/g, &quot;&quot;);
});
}
/**
* Function to check is vehicle exist already
* @method checkIsVehicleExist
* @for TicketAdministration
*/
function checkIsVehicleExist() {
$(&quot;#VehicleRegistrationNumber&quot;).blur(function () {
var vehicleRegistrationNo = $(&quot;#VehicleRegistrationNumber&quot;).val().replace(/-/g, &quot;&quot;);
if (vehicleRegistrationNo != customerVehicleRegistrationNo) {
//call web api to check is vehicle exist true, if yes autofill other fields of vehicle
$.getJSON(&quot;/Ticket_CustomerInventory/GetVehicleDetailsBasedOnRegistrationNo/&quot;, { RegistrationNo: vehicleRegistrationNo }, function (result) {
if (result.VehicleDetails) {
var Details = result.VehicleDetails;
for (var count = 0; count &lt; Details.length; count++) {
if (Details[count].Id != null) {
$(&quot;#VehicleNumberPlate&quot;).val(Details[count].VehicleNumberPlate);
$(&quot;#ddVehicleModleNo&quot;).val(Details[count].ModelNumber);
$(&quot;#ddVehicleType&quot;).val(Details[count].VehicleType);
$(&quot;#CustomerVehicleModelTagging&quot;).val(&#x27;&#x27;);
getVehicleModelTagging();
$(&quot;#InstallationDate&quot;).val(Details[count].VehicleInstallationDate);
} else {
$(&quot;#VehicleNumberPlate&quot;).val(&#x27;&#x27;);
$(&quot;#ddVehicleModleNo&quot;).val(&#x27;&#x27;);
$(&quot;#ddVehicleType&quot;).val(&#x27;&#x27;);
$(&quot;#CustomerVehicleModelTagging&quot;).val(&#x27;&#x27;);
$(&quot;#InstallationDate&quot;).val(&#x27;&#x27;);
}
}
}
});
}
});
}
/**
* Function to get vehicle model tagging based on vehicle model no
* @method getVehicleModelTagging
* @for TicketAdministration
*/
function getVehicleModelTagging() {
var VehicleModelTypeId = $(&quot;#ddVehicleModleNo&quot;).val();
$.getJSON(&quot;/Ticket_CustomerInventory/GetVehicleModelTaggingBasedOnModelNo/&quot;, { ModelTypeId: VehicleModelTypeId }, function (result) {
if (result) {
var ModelType = result.VehicleModelTagging;
for (var count = 0; count &lt; ModelType.length; count++) {
$(&quot;#CustomerVehicleModelTagging&quot;).val(ModelType[count].VehicleTypeTagging);
}
}
});
}
/**
* Function call on success of add customer
* @method onSuccessAddCustomer
* @for TicketAdministration
*/
function onSuccessAddCustomer(data) {
var registrationNo, mobileNo, complaintNo;
if (data.success == true) {
registrationNo = data.vRegistrationNo;
mobileNo = &quot;&quot;;
complaintNo = &quot;&quot;;
if (xhr_addCustomer &amp;&amp; xhr_addCustomer.readystate != 4) {
xhr_addCustomer.abort();
}
xhr_addCustomer = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_GetTicketHistory/&quot;,
data: { registrationNo: registrationNo, mobileNo: mobileNo, complaintNo: complaintNo },
success: function (data) {
if (data.fillFieldMesseage) {
jAlert(data.fillFieldMesseage, &#x27;Message&#x27;);
}
else {
$(&quot;#divCheckHistory&quot;).html(&quot;&quot;);
$(&quot;#divCheckHistory&quot;).html(data);
$(&quot;#divMapDetail&quot;).removeClass(&quot;display_none&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).addClass(&quot;MapBox&quot;);
if (document.getElementById(&#x27;tableTicketHistory&#x27;)) {
$(&quot;#tableTicketHistory &gt; tbody &gt; tr:first&quot;).trigger(&quot;click&quot;);
} else if (document.getElementById(&#x27;tableCloseTicketHistory&#x27;)) {
$(&quot;#tableCloseTicketHistory &gt; tbody &gt; tr:first&quot;).trigger(&quot;click&quot;);
} else {
$(&quot;#divMapDetail&quot;).addClass(&quot;display_none&quot;);
$(&quot;#divMapContainer&quot;).removeClass(&quot;withtoolbar&quot;);
$(&quot;#divMapContainer&quot;).removeClass(&quot;MapBox&quot;);
}
}
},
complete: function () {
closeWindow(&quot;#divAddCustomer&quot;);
},
error: function (data) {
console.log(data);
}
});
}
else {
jAlert(data.message, &#x27;Message&#x27;, function () {
});
}
}
/**
* Function to create ajax request
* @method createAjaxRequest
* @param {string} controller Name of controller
* @param {string} actionName Name of action on controller
* @param {string} divId HTML id of div
* @param {string} VRegNo Registration no. of vehicle
* @for TicketAdministration
*/
function createAjaxRequest(controller, actionName, divId, VRegNo) {
var divIdToBeRemoveData;
if (divId == &quot;#divAddCustomerForExistingVehicle&quot;) {
divIdToBeRemoveData = &quot;#divAddCustomer&quot;;
}
else {
divIdToBeRemoveData = &quot;#divAddCustomerForExistingVehicle&quot;;
}
// Ajax request
if (activeRequest &amp;&amp; activeRequest.readystate != 4) {
activeRequest.abort();
}
activeRequest = $.ajax({
type: &quot;GET&quot;,
url: &quot;/&quot; + controller + &quot;/&quot; + actionName + &quot;/&quot;,
data: { VRegistrationNo: VRegNo },
success: function (data) {
$(divIdToBeRemoveData).html(&quot;&quot;);
$(divId).html(&quot;&quot;);
$(divId).html(data);
//open form in new dialog box
$(divId).data(&quot;kendoWindow&quot;).open();
if (divId == &quot;#divAddCustomerForExistingVehicle&quot;) {
$(&quot;#customerOwnerMobileNo1&quot;).val($(&quot;#vehicle_owner_contact_no&quot;).val());
$(&quot;#CustomerOwnerEmailId&quot;).val($(&quot;#vehicle_owner_emailID&quot;).val());
$(&quot;#ddOwnerState&quot;).val($(&quot;#vehicle_owner_location&quot;).val());
$(&quot;#ddOwnerCity&quot;).val($(&quot;#vehicle_owner_City&quot;).val());
$(&quot;#CustomerOwnerAddress&quot;).val($(&quot;#vehicle_owner_Address&quot;).val());
$(&quot;#CustomerOwnerName&quot;).val($(&quot;#vehicle_owner_name&quot;).val());
$(&quot;#VehicleRegistrationNumber&quot;).val($(&quot;#vehicle_registration&quot;).val());
$(&quot;#VehicleNumberPlate&quot;).val($(&quot;#vehicle_numberPlate&quot;).val());
//$(&quot;#ddVehicleModleNo&quot;).val($(&quot;#vehicle_model&quot;).val());
$(&quot;#VehicleModelNumber&quot;).val(stringToDecode($(&quot;#vehicle_model&quot;).val(), &quot;hiddenModelNo&quot;));
$(&quot;#VehicleModelNumber&quot;).prop(&#x27;title&#x27;, stringToDecode($(&quot;#vehicle_model&quot;).val(), &quot;hiddenModelNo&quot;));
$(&quot;#CustomerVehicleModelTagging&quot;).val($(&quot;#vehicle_product_varient&quot;).val());
$(&quot;#VehicleType&quot;).val($(&quot;#eos_VehicleType&quot;).val());
$(&quot;#VehicleInstallationDate&quot;).val($(&quot;#eos_VehicleInstallationDate&quot;).val());
}
},
error: function (data) {
console.log(data);
}
});
}
/**
* Function to close kendo window
* @method closeWindow
* @param {String} divId The id of div
* @for TicketAdministration
*/
function closeWindow(divId) {
$(divId).data(&quot;kendoWindow&quot;).close();
}
/**
* Function call on click of cancel button of add customer window
* @method btnCancelAddCustomer
* @param {String} divId The id of div
* @for TicketAdministration
*/
function btnCancelAddCustomer(divId) {
closeWindow(divId);
}
/**
* Function to add new customer for already existing vehicle
* @method addCustomerForExistingVehicle
* @param {String} vRegNo Registration no of vehicle
* @for TicketAdministration
*/
function addCustomerForExistingVehicle(vRegNo) {
var VRegistrationNo = vRegNo;
createAjaxRequest(&quot;Ticket_CustomerInventory&quot;, &quot;CreateNewCustomerForExistingVehicle&quot;, &quot;#divAddCustomerForExistingVehicle&quot;, VRegistrationNo);
}
/**
* Function call on success of add customer for already existing vehicle
* @method onSuccessAddCustomerForExistingVehicle
* @for TicketAdministration
*/
function onSuccessAddCustomerForExistingVehicle(data) {
if (data.success == true) {
var VRegistrationNo = data.vRegistationNo;
if (xhr_addCustomerForExisting &amp;&amp; xhr_addCustomerForExisting.readystate != 4) {
xhr_addCustomerForExisting.abort();
}
xhr_addCustomerForExisting = $.ajax({
type: &quot;GET&quot;,
url: &quot;/Ticket_CustomerInventory/ShowCustomerList/&quot;,
data: { VRegistrationNo: VRegistrationNo },
success: function (data) {
$(&quot;#driver_name&quot;).text(&quot;&quot;);
// add by default select text
$(&quot;#driver_name&quot;).append(
$(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(&quot;&quot;).html(&quot;-Select-&quot;));
for (var counter = 0; counter &lt; data.list.length; counter++) {
$(&quot;#driver_name&quot;).append(
$(&#x27;&lt;option&gt;&lt;/option&gt;&#x27;).val(data.list[counter].Value).html(data.list[counter].Text));
}
},
complete: function () {
closeWindow(&quot;#divAddCustomerForExistingVehicle&quot;);
},
error: function (data) {
console.log(data);
}
});
}
}
//======================= get all nearest vans and dealers ==========================//
/**
* Function call on begin of get all nearest vans list
* @method onBeginGetAllVansDealers
* @for TicketAdministration
*/
function onBeginGetAllVansDealers() {
if ($(&#x27;#vehicle_owner_language&#x27;).find(&#x27;option:selected&#x27;).text() == &quot;-Select-&quot;) { //check if owner language is selected or not
$(&quot;#spanLanguageRequired&quot;).show();
return false;
} else if ($(&#x27;#tollFreeNoSource&#x27;).find(&#x27;option:selected&#x27;).text() == &quot;-Select-&quot;) { //check if toll free no source is selected or not
$(&quot;#spanSourceTollFreeRequired&quot;).show();
return false;
} else if ($(&#x27;#driver_name&#x27;).find(&#x27;option:selected&#x27;).text() == &quot;-Select-&quot;) { //check if driver/customer name is selected or not
$(&quot;#spanCustomerRequired&quot;).show();
return false;
} else if ($(&#x27;#eos_state&#x27;).find(&#x27;option:selected&#x27;).text() == &quot;-Select-&quot;) { //check if state is selected or not
$(&quot;#spanState&quot;).show();
return false;
} else if ($(&#x27;#eos_city&#x27;).val() == &quot;&quot;) { //check if city is selected or not
$(&quot;#spanCity&quot;).show();
return false;
} else if ($(&#x27;#routes&#x27;).find(&#x27;option:selected&#x27;).text() == &quot;-Select-&quot;) { //check if route is selected or not
$(&quot;#spanRoutes&quot;).show();
return false;
} else if ($(&#x27;#nature_of_problem&#x27;).val() == &quot;&quot;) { //check if nature of problem is selected or not
$(&quot;#spanDescription&quot;).show();
return false;
} else if ($(&#x27;#isVehicleInWarrentyOrAmc&#x27;).find(&#x27;option:selected&#x27;).text() == &quot;-Select-&quot;) { //check if warrenty is selected or not
$(&quot;#spanWarrenty&quot;).show();
return false;
}
//else if ($(&#x27;#totalKmCovered&#x27;).val() == &quot;&quot;) { //check if warrenty is selected or not
// $(&quot;#spanKmCovered&quot;).show();
// return false;
//}
return true;
}
//Global variables to get more than 25 vans/dealers
var arrOf25VanDealerLatLng = [];
var arrOf25VanDealerDetails = [];
var _LIMIT = 100;
/**
* Function to get all nearest vans / dealers list
* @method getNearestVansDealers
* @for TicketAdministration
*/
function getNearestVansDealers() {
if (onBeginGetAllVansDealers() == true) {
$(&quot;#spanEosLocation&quot;).hide();
$(&quot;#spanRoutes&quot;).hide();
$(&quot;#spanState&quot;).hide();
$(&quot;#spanDescription&quot;).hide();
$(&quot;#spanLanguageRequired&quot;).hide();
$(&quot;#spanSourceTollFreeRequired&quot;).hide();
$(&quot;#spanCity&quot;).hide();
$(&quot;#spanWarrenty&quot;).hide();
$(&quot;#spanKmCovered&quot;).hide();
//empty van dealer lat lng array
if (vanDealerLatLngArr.length &gt; 0) {
vanDealerLatLngArr = [];
}
//empty details list of van dealer array
if (detailsListOfVanDealer.length &gt; 0) {
detailsListOfVanDealer = [];
}
//remove path between 2 markers
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
//empty array to get next 25 vans/dealers details.
copyResulEls = [];
//loop through arary
for (var i = 0; i &lt; nearestVansDealersMarks.length; i++) {
//set marker map to null
nearestVansDealersMarks[i].setMap(null);
}
//empty array
nearestVansDealersMarks = [];
var stateName, stateId, vanDealerLatlng, type, VDId, vanDealerLat, vanDealerLng, vanDealerCity, vanDealerName, vanDealerState,
deviceAlias, vanRemainingTime, deviceStatus, noOfAssignedTickets, description;
stateName = $(&#x27;#eos_state&#x27;).find(&#x27;option:selected&#x27;).text();
stateId = $(&#x27;#eos_state&#x27;).find(&#x27;option:selected&#x27;).val();
if (xhr_getAllVans &amp;&amp; xhr_getAllVans.readystate != 4) {
xhr_getAllVans.abort();
}
xhr_getAllVans = $.ajax({
type: &quot;GET&quot;,
url: &quot;/Ticket/GetAllNearestVansDealers/&quot;,
data: { StateName: stateName, limit: _LIMIT },
success: function (data) {
if (data.NearestVansDealers.length &gt; 0) {
if (breakdownLocationLatLng != &quot;&quot;) {
//remove bind click
google.maps.event.clearListeners(ccplMap, &#x27;click&#x27;);
$(&quot;#searchLocationTool&quot;).attr(&#x27;readonly&#x27;, &#x27;readonly&#x27;);
google.maps.event.clearListeners(searchBox, &#x27;places_changed&#x27;);
}
vanDealerLatLngArr.length = 0;
for (var counter = 0; counter &lt; data.NearestVansDealers.length; counter++) {
var title, markerIcon, backgroundColor;
var updatedDeviceStatus = &quot;&quot;;
var vanDealerObj = {};
vanDealerLatlng = new google.maps.LatLng(data.NearestVansDealers[counter].DealerVanLattitude, data.NearestVansDealers[counter].DealerVanLongitude);
type = data.NearestVansDealers[counter].Type;
VDId = data.NearestVansDealers[counter].DealerVanId;
vanDealerLat = data.NearestVansDealers[counter].DealerVanLattitude;
vanDealerLng = data.NearestVansDealers[counter].DealerVanLongitude;
vanDealerCity = data.NearestVansDealers[counter].DealerVanCity;
noOfAssignedTickets = data.NearestVansDealers[counter].NoOfAssignedTicket;
vanDealerName = data.NearestVansDealers[counter].DealerVanName;
vanDealerState = data.NearestVansDealers[counter].DealerVanState;
deviceAlias = data.NearestVansDealers[counter].DeviceAlias;
vanRemainingTime = data.NearestVansDealers[counter].RemainingTime;
deviceStatus = data.NearestVansDealers[counter].DeviceStatus;
//check if remaining time is negative
if (vanRemainingTime == null || vanRemainingTime == &quot;&quot;) {
vanRemainingTime = &quot;0&quot;;
}
else {
if (vanRemainingTime.indexOf(&#x27;-&#x27;) === -1) {
vanRemainingTime = vanRemainingTime;
} else {
vanRemainingTime = &quot;0&quot;;
}
}
//check if device is connected or not
if ((deviceStatus == &quot;True&quot;) &amp;&amp; (type == &quot;van&quot;)) {
//console.log(deviceStatus);
updatedDeviceStatus = &quot;green-circle&quot;;
}
else if ((deviceStatus == &quot;False&quot;) &amp;&amp; (type == &quot;van&quot;)) {
updatedDeviceStatus = &quot;red-circle&quot;;
} else {
updatedDeviceStatus = &quot;&quot;;
}
if (vanRemainingTime == &quot;0&quot;) {
backgroundColor = &quot;green&quot;;
}
else {
backgroundColor = &quot;red&quot;;
}
//push van dealer lat lng in array
vanDealerLatLngArr.push(vanDealerLatlng);
//bind van / dealer details in object
vanDealerObj.type = type;
vanDealerObj.id = VDId;
vanDealerObj.lat = vanDealerLat;
vanDealerObj.lng = vanDealerLng;
vanDealerObj.city = vanDealerCity;
vanDealerObj.assignedTickets = noOfAssignedTickets;
vanDealerObj.name = vanDealerName;
vanDealerObj.state = vanDealerState;
vanDealerObj.alias = deviceAlias;
vanDealerObj.remainingTime = vanRemainingTime;
vanDealerObj.deviceStatus = updatedDeviceStatus;
vanDealerObj.backGroundColor = backgroundColor;
//push van dealer details in array
detailsListOfVanDealer.push(vanDealerObj);
//Get address of the Lat Long click clicked
getReverseGeoCode(vanDealerLatlng, function (data) {
//Here we got the address of the point clicked. Update this value to the form textbox.
title = data;
});
}
var forLoopLength, multiplier = 100, waitIndex = 0, setTimeOutSeconds = 0;
var vanDealerLatLngArrLength = vanDealerLatLngArr.length;
//check if breakdown location is marked or not
if (breakdownLocationLatLng != &quot;&quot;) {
if (vanDealerLatLngArr.length &lt; 25 &amp;&amp; vanDealerLatLngArr.length &gt; 0) {
forLoopLength = 1;
} else {
if ((vanDealerLatLngArr.length % 25) &gt; 0) {
forLoopLength = parseInt((vanDealerLatLngArr.length / 25), 10) + 1;
} else if ((vanDealerLatLngArr.length % 25) == 0) {
forLoopLength = parseInt((vanDealerLatLngArr.length / 25), 10);
}
}
var z;
if (forLoopLength == 1) {
arrOf25VanDealerLatLng = [];
arrOf25VanDealerDetails = [];
for (var i = 0; i &lt; vanDealerLatLngArr.length; i++) {
arrOf25VanDealerLatLng.push(vanDealerLatLngArr[i]);
arrOf25VanDealerDetails.push(detailsListOfVanDealer[i]);
}
calcRouteDistance(breakdownLocationLatLng, arrOf25VanDealerLatLng, arrOf25VanDealerDetails);
setTimeout(function () {// console.log(copyResulEls);
createVanDealerSortedList();
}, 1000);
} else {
for (var i = 0; i &lt; forLoopLength; i++) {
// setTimeout(function () {
console.log(setTimeOutSeconds, waitIndex, i);
setTimeOutSeconds = waitIndex * multiplier;
//console.log(i);
if (vanDealerLatLngArrLength &lt; 25) { z = 0; } else { z = vanDealerLatLngArrLength - 25; }
arrOf25VanDealerLatLng = [];
arrOf25VanDealerDetails = [];
for (var j = vanDealerLatLngArrLength; j &gt; z; j--) {
arrOf25VanDealerLatLng.push(vanDealerLatLngArr[j - 1]);
arrOf25VanDealerDetails.push(detailsListOfVanDealer[j - 1]);
}
vanDealerLatLngArrLength = vanDealerLatLngArrLength - 25;
calculateDistanceInSetTimeOut(breakdownLocationLatLng, arrOf25VanDealerLatLng, arrOf25VanDealerDetails, setTimeOutSeconds);
waitIndex++;
}
createVanDealerList();
}
} else {
jAlert(CREATE_TICKET_MESSAGES.requiredBreakdownLocation);
}
}
else {
jAlert(CREATE_TICKET_MESSAGES.vanDealerUnavailable, &#x27;Message&#x27;, function () {
$(&quot;#divVanDealerList&quot;).css(&#x27;display&#x27;, &#x27;none&#x27;);
$(&quot;#divMap&quot;).css(&#x27;height&#x27;, &#x27;&#x27;);
});
}
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* SetTimeOut function to calculate distance between van and dealer using google distance matrix api
* @method calculateDistanceInSetTimeOut
* @param {String} breakDownLatLng LatLng of breakdown vehicle
* @param {array} arrVanDealerLatLng LatLng of vans / dealers
* @param {array} arrVanDealerDetails details of vans/dealers
* @param {String} timeOutSeconds time in seconds for setTimeout function
* @for TicketAdministration
*/
function calculateDistanceInSetTimeOut(breakDownLatLng, arrVanDealerLatLng, arrVanDealerDetails, timeOutSeconds) {
setTimeout(function () {
calcRouteDistance(breakDownLatLng, arrVanDealerLatLng, arrVanDealerDetails);
}, timeOutSeconds);
}
/**
* setTimeOut function to create sorted van dealer list
* @method createVanDealerList
* @for TicketAdministration
*/
function createVanDealerList() {
setTimeout(function () {
createVanDealerSortedList();
}, 1000);
}
/**
* Function to create markers on van&#x27;s / dealer&#x27;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 TicketAdministration
*/
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);
}
/**
* Function to create markers on van&#x27;s / dealer&#x27;s locations
* @method createMarker
* @param {String} position Position of van / dealer
* @param {String} icon Icon of placed marker
* @param {String} vanDealerId Van / Dealer&#x27;s id
* @param {String} content Content of mesage to show in infowindow
* @param {String} mapId map id
* @for TicketAdministration
*/
function createMarker(position, icon, vanDealerId, content, mapId) {
//create a google marker with the given param
var vanDealerMarker = new google.maps.Marker({
position: position,
map: mapId,
icon: icon,
customInfo: String(vanDealerId)
});
vanDealerMarker.infoCheck = false;
//push marker to marksArray
nearestVansDealersMarks.push(vanDealerMarker);
//update infowindow
updateInfoWindow(vanDealerMarker, content, mapId);
//on mouse over of marker
google.maps.event.addListener(vanDealerMarker, &#x27;mouseover&#x27;, function () {
//remove animation on marker
if (vanDealerMarker.getAnimation() != null) {
vanDealerMarker.setAnimation(null);
}
});
}
/**
* Function to update data of info window on markers of van&#x27;s / dealer&#x27;s locations
* @method updateInfoWindow
* @param {String} unitMarker Position of van / dealer
* @param {String} message Data of info window on placed marker
* @param {String} map map id
* @for TicketAdministration
*/
function updateInfoWindow(unitMarker, message, map) {
// Add click listener to open info window
google.maps.event.addListener(unitMarker, &#x27;click&#x27;, function () {
infowindow.setContent(message);
infowindow.open(map, unitMarker);
});
}
//=============================== end ==============================================//
//------------------------------------------ calculate route -------------------------------------//
/**
* This fn removes all markers stored in ticketDetailsMarkerArray.
* @method removeTicketDetailsMarkerArray
* @for TicketAdministration
*/
function removeTicketDetailsMarkerArray() {
//loop through arary
for (var i = 0; i &lt; 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
* @param {String} vanDealerType Type is Van or Dealer
* @param {String} mapID map id
* @for TicketAdministration
*/
function calcRoute(startLatLng, endLatLng, vanDealerType, mapID, wayPointArr) {
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
var rendererOptions = {
map: mapID,
suppressMarkers: true,
polylineOptions: { strokeColor: &quot;#1b3f94&quot; }
}
var request = &quot;&quot;;
displayDisplay = new google.maps.DirectionsRenderer(rendererOptions);
//Make request obj to Direction Service API with starting and end LatLng
request = {
origin: startLatLng,
destination: endLatLng,
avoidHighways: false,
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];
$(&quot;#div_loading&quot;).hide();
} else {
$(&quot;#div_loading&quot;).hide();
}
});
}
/**
* This fn calculates and draws the Route for selected national highway using Google Direction API
* @method drawHighway
* @param {String} startLatLng Position of origin
* @param {String} endLatLng Position of destination
* @param {String} vanDealerType Type is Van or Dealer
* @param {String} mapID map id
* @for TicketAdministration
*/
function drawHighway(startLatLng, endLatLng, vanDealerType, mapID, wayPointArr, routeColor) {
if (displayHighway) {
//Remove direction display
displayHighway.setMap(null);
}
var rendererOptionsForHighway = {
map: mapID,
suppressMarkers: true,
polylineOptions: { strokeColor: routeColor }
}
var request = &quot;&quot;;
displayHighway = new google.maps.DirectionsRenderer(rendererOptionsForHighway);
if (wayPointArr.length &gt; 0) {
//Make request obj to Direction Service API with starting and end LatLng
request = {
origin: startLatLng,
destination: endLatLng,
waypoints: wayPointArr,
avoidHighways: false,
optimizeWaypoints: true,
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) {
displayHighway.setOptions({ preserveViewport: true });
//set Direction to the response
displayHighway.setDirections(response);
var leg = response.routes[0].legs[0];
} else {
}
});
}
}
//-------------------------------------------- end routing ---------------------------------------//
//===================================== calculate distance =========================================//
/**
* This fn removes and add class to show which Van is assigned.
* @method assignVan
* @param {String} index Index of selected row of van / dealer list
* @for TicketAdministration
*/
function assignVan(index) {
//remove previous assignede class
$(&quot;#displayVansDealersTable&quot;).find(&#x27;tr&#x27;).removeClass(&#x27;showMarked&#x27;);
$(&quot;#displayVansDealersTable&quot;).find(&#x27;tr:nth-child(&#x27; + (index + 2) + &#x27;)&#x27;).addClass(&#x27;showMarked&#x27;);
var vehicleRegNo = $(&quot;#vehicle_registration&quot;).val();
//create object of ticket model
var TicketModel = {};
TicketModel.TicketId = &quot;&quot;;
TicketModel.Description = $(&quot;#nature_of_problem&quot;).val();
TicketModel.listDescription = {};
TicketModel.AssignedTo = $(&#x27;#displayVansDealersTable tr:eq(&#x27; + (index + 1) + &#x27;) &gt; td:eq(1)&#x27;).text();
TicketModel.ReportedVia = &quot;&quot;;
if (TicketModel.AssignedTo == &quot;van&quot;) {
TicketModel.TicketStatus = 1;
}
else {
TicketModel.TicketStatus = 2;
}
TicketModel.Priority = 1;
TicketModel.CustomerScore = &quot;&quot;;
TicketModel.CreatedBy = &quot;&quot;;
TicketModel.CreationTime = &quot;&quot;;
TicketModel.LastModifiedBy = &quot;&quot;;
TicketModel.LastModifiedTime = &quot;&quot;;
TicketModel.BreakdownLocation = $(&quot;#eos_exact_location&quot;).val();
TicketModel.BreakdownLongitude = breakdownLocationLatLng.lng();
TicketModel.BreakdownLattitude = breakdownLocationLatLng.lat();
TicketModel.AssignedToUserId = $(&#x27;#displayVansDealersTable tr:eq(&#x27; + (index + 1) + &#x27;) &gt; td:eq(2)&#x27;).text();
TicketModel.AssignedToUserLattitude = copyResulEls[index].lat;
TicketModel.AssignedToUserLongitude = copyResulEls[index].lng;
TicketModel.Isdeclined = false;
TicketModel.EstimatedTimeForJobCompletion = &quot;&quot;;
TicketModel.TotalTicketLifecycleTimeSla = &quot;&quot;;
TicketModel.EstimatedTimeForJobCompletionSubmitTime = &quot;&quot;;
TicketModel.VehicleRegisterNumber = $(&quot;#vehicle_registration&quot;).val();
TicketModel.BreakdownLocationLandmark = $(&quot;#breakdown_landmark&quot;).val();
TicketModel.RouteId = parseInt($(&quot;#routes&quot;).val(), 10);
TicketModel.CustomerContactNo = $(&quot;#driver_contact_no&quot;).val();
TicketModel.TicketStatusAlias = &quot;&quot;;
TicketModel.Token = &quot;&quot;;
TicketModel.Status = &quot;&quot;;
TicketModel.Message = &quot;&quot;;
TicketModel.UtcMinute = 0;
TicketModel.RepairCost = &quot;&quot;;
TicketModel.SlaMissedReason = &quot;&quot;;
TicketModel.SuggestionComment = &quot;&quot;;
TicketModel.JobCompleteResponseTime = &quot;&quot;;
TicketModel.DefaultCol2 = $(&quot;#vehicle_type_of_load&quot;).val();
TicketModel.DefaultCol3 = $(&quot;#vehicle_direction&quot;).val();
TicketModel.StateName = $(&#x27;#eos_state&#x27;).find(&#x27;option:selected&#x27;).text();
TicketModel.CityName = $(&quot;#eos_city&quot;).data(&quot;kendoComboBox&quot;).text();
TicketModel.CallerLanguage = $(&#x27;#vehicle_owner_language&#x27;).find(&#x27;option:selected&#x27;).text();
TicketModel.KmCovered = $(&#x27;#totalKmCovered&#x27;).val();
TicketModel.Warranty = $(&#x27;#isVehicleInWarrentyOrAmc&#x27;).find(&#x27;option:selected&#x27;).text();
TicketModel.TollFreeeNoSource = $(&#x27;#tollFreeNoSource&#x27;).find(&#x27;option:selected&#x27;).text();
TicketModel.VehicleTagging = $(&quot;#vehicle_product_varient&quot;).val();
distanceInKm = $(&#x27;#displayVansDealersTable tr:eq(&#x27; + (index + 1) + &#x27;) &gt; td:eq(5)&#x27;).text();
var lastIndex = distanceInKm.lastIndexOf(&quot; km&quot;);
var distance = distanceInKm.substring(0, lastIndex);
TicketModel.EstimateDistance = distance;
//get route id
routeId = parseInt($(&quot;#routes&quot;).val(), 10);
$.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/GetRouteWiseSlaTime/&quot;,
data: { RouteId: routeId },
success: function (result) {
if (result) {
for (var count = 0; count &lt; result.RouteWiseSlaTime.length; count++) {
routeWiseSlaTime = parseInt(result.RouteWiseSlaTime[count].SlaTime, 10);
}
}
},
complete: function () {
TicketModel.DefaultSlaTime = routeWiseSlaTime;
//Send POST request with the ticket data
if (xhr_addNewTicket &amp;&amp; xhr_addNewTicket.readystate != 4) {
xhr_addNewTicket.abort();
}
xhr_addNewTicket = $.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_CreateTicket/&quot;,
data: TicketModel,
success: function (data) {
var createdTicketId = data.ticketId;
if (displayDisplay) {
displayDisplay.setMap(null);
}
//remove marker
if (marker) {
marker.setMap(null);
//set address text field empty here
marker = &quot;&quot;;
}
//empty van dealers marker array
if (nearestVansDealersMarks.length &gt; 0) {
for (var counter = 0; counter &lt; nearestVansDealersMarks.length; counter++) {
nearestVansDealersMarks[counter].setMap(null);
//set address text field empty here
nearestVansDealersMarks[counter] = &quot;&quot;;
}
nearestVansDealersMarks = [];
}
//loop through arary
for (var i = 0; i &lt; ticketDetailsMarkerArray.length; i++) {
//set marker map to null
ticketDetailsMarkerArray[i].setMap(null);
}
//remove highway path
if (displayHighway) {
displayHighway.setMap(null);
}
//empty array
ticketDetailsMarkerArray = [];
//empty city
$(&quot;#eos_city&quot;).data(&quot;kendoComboBox&quot;).text(&#x27;&#x27;);
//remove place location markers
removePlaceLocationMarkerArray();
//remove click event
removeClickEventToMap();
//ajax request to show new ticket in ticket table
$.ajax({
type: &quot;POST&quot;,
url: &quot;/Ticket/TicketAdministration_GetTicketHistory/&quot;,
data: { registrationNo: &quot;&quot;, mobileNo: &quot;&quot;, complaintNo: createdTicketId },
success: function (data) {
if (data.fillFieldMesseage) {
jAlert(data.fillFieldMesseage, &#x27;Message&#x27;);
}
else {
onClickAssignTicketOrCancel();
$(&quot;#divCheckHistory&quot;).html(&quot;&quot;);
$(&quot;#divCheckHistory&quot;).html(data);
$(&quot;#divVanDealerList&quot;).css(&#x27;display&#x27;, &#x27;none&#x27;);
$(&quot;#searchLocationTool&quot;).hide();
$(&quot;#divMap&quot;).css(&#x27;height&#x27;, &#x27;&#x27;);
if (document.getElementById(&#x27;tableTicketHistory&#x27;)) {
$(&quot;#tableTicketHistory &gt; tbody &gt; tr[id=&quot; + createdTicketId + &quot;]&quot;).trigger(&quot;click&quot;);
}
}
},
error: function (data) {
console.log(data);
}
});
//Remove any click listener if any present
google.maps.event.clearListeners(ccplMap, &#x27;click&#x27;);
//set marker to null
marker = &quot;&quot;;
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
}
});
}
/**
* This fn calculate route distance and show sorted vans and dealers list in table
* @method calcRouteDistance
* @param {String} origin Location of origin
* @param {String} destinationArr array Locations of destination
* @for TicketAdministration
*/
function calcRouteDistance(origin, destinationArr, vanDealerDetailsArr) {
console.log(vanDealerDetailsArr);
service.getDistanceMatrix({
origins: [origin],
destinations: destinationArr,
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
}, distanceMatrixCallback);
//Callback for Distance Matrix API
function distanceMatrixCallback(response, status) {
//If Status was an error, throw alert
console.log(status, response);
if (status != google.maps.DistanceMatrixStatus.OK) {
alert(&#x27;Error was: &#x27; + status);
} else {
//Result ELements response from Distance Matrinx
var resultEls = response.rows[0].elements;
//Add vanId and vanAddress to the response
for (var i = 0; i &lt; resultEls.length; i++) {
if (resultEls[i].status == &quot;OK&quot;) {
resultEls[i].vanDealerAddress = response.destinationAddresses[i];
resultEls[i].vanDealerID = vanDealerDetailsArr[i].id;
resultEls[i].type = vanDealerDetailsArr[i].type;
resultEls[i].lat = vanDealerDetailsArr[i].lat;
resultEls[i].lng = vanDealerDetailsArr[i].lng;
resultEls[i].city = vanDealerDetailsArr[i].city;
resultEls[i].assignedTicketsToVanDealer = vanDealerDetailsArr[i].assignedTickets;
resultEls[i].name = vanDealerDetailsArr[i].name;
resultEls[i].state = vanDealerDetailsArr[i].state;
resultEls[i].alias = vanDealerDetailsArr[i].alias;
resultEls[i].remainingTime = vanDealerDetailsArr[i].remainingTime;
resultEls[i].deviceStatus = vanDealerDetailsArr[i].deviceStatus;
resultEls[i].backgroundColor = vanDealerDetailsArr[i].backGroundColor;
}
}
for (var counter = 0; counter &lt; resultEls.length; counter++) {
if (resultEls[counter].status == &quot;OK&quot;) {
copyResulEls.push(resultEls[counter]);
}
}
}
}
}
/**
* This fn create sorted van dealer list
* @method createVanDealerSortedList
* @for TicketAdministration
*/
function createVanDealerSortedList() {
//Sort our Array according to the duration values in ascending order. [See: https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort for more reference]
copyResulEls.sort(function (a, b) {
var reg = new RegExp(&#x27;^[0-9]+$&#x27;);
if (a.status == &quot;OK&quot; &amp;&amp; b.status == &quot;OK&quot;) {
var k1 = a.duration.value;
var k2 = b.duration.value;
if (reg.test(k1) == true &amp;&amp; reg.test(k2) == true) {
if (k1 &gt; k2) {
return 1;
} else {
return -1;
}
}
}
else {
return -1;
}
return 0;
});
$(&quot;#tableVansDealers&quot;).html(&#x27;&#x27;);
//var to hold table String to show in dialog-form
var trString = &#x27;&#x27;;
//Loop through of array length of copyResulEls
for (var i = 0; i &lt; copyResulEls.length; i++) {
//if i===0, add html for table.
if (copyResulEls[i].status == &quot;OK&quot;) {
var markerIcon;
if (i === 0) {
trString += &#x27;&lt;table id=&quot;displayVansDealersTable&quot; class=&quot;modalTable&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;S. No.&lt;/th&gt;&lt;th&gt;Van/Dealer&lt;/th&gt;&lt;th style=&quot;display:none;&quot;&gt;Van/Dealer Id&lt;/th&gt;&lt;th&gt;Van/Dealer Name&lt;/th&gt;&lt;th style=&quot;width:25%;&quot;&gt;Van/Dealer Location&lt;/th&gt;&lt;th&gt;Distance&lt;/th&gt;&lt;th&gt;Duration&lt;/th&gt;&lt;th&gt;No. of Open Tickets&lt;/th&gt;&lt;th&gt;Remaining Time(in mins)&lt;/th&gt;&lt;th&gt;Is Connected&lt;/th&gt;&lt;th &gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&#x27;;
}
//add each row
trString += &#x27;&lt;tr id=&quot;&#x27; + copyResulEls[i].vanDealerID + &#x27;&quot;&gt;&lt;td style=&quot;box-shadow: 4px 0px 0px &#x27; + copyResulEls[i].backgroundColor + &#x27; inset;&quot; &gt;&#x27; + (i + 1) + &#x27;&lt;/td&gt;&lt;td &gt;&#x27; + copyResulEls[i].type + &#x27;&lt;/td&gt;&lt;td style=&quot;display:none;&quot;&gt;&#x27; + copyResulEls[i].vanDealerID + &#x27;&lt;/td&gt;&lt;td&gt;&#x27; + copyResulEls[i].name + &#x27;&lt;/td&gt;&lt;td&gt;&#x27; + copyResulEls[i].vanDealerAddress + &#x27;&lt;/td&gt;&lt;td&gt;&#x27; + copyResulEls[i].distance.text + &#x27;&lt;/td&gt;&lt;td&gt;&#x27; + copyResulEls[i].duration.text + &#x27;&lt;/td&gt;&lt;td&gt;&#x27; + copyResulEls[i].assignedTicketsToVanDealer + &#x27;&lt;/td&gt;&lt;td&gt;&#x27; + copyResulEls[i].remainingTime + &#x27;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;&#x27; + copyResulEls[i].deviceStatus + &#x27;&quot;&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;button class=&quot;button_blue&quot;, style=&quot;width:auto;&quot; onclick=&quot;assignVan(&#x27; + i + &#x27;);&quot;&gt;Assign&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;&#x27;;
//if i===2, end table tag.
if (i === copyResulEls.length) {
$(&quot;#tableVansDealers&quot;).append(&#x27;&lt;/tbody&gt;&lt;/table&gt;&#x27;);
}
//add content to info window
var description = &#x27;&lt;div id=&quot;divInfoWindow&quot;&gt;&#x27; +
&#x27;&lt;div class=&quot;&quot;&gt;&#x27; +
&#x27; &lt;div class=&quot;&quot;&gt;&#x27; +
&#x27;&lt;h2 class=&quot;EngName_heading&quot;&gt;&lt;span id=&quot;spanVanDealerName&quot;&gt;&#x27; + copyResulEls[i].name + &#x27;&lt;/span&gt;&lt;/h2&gt;&#x27; +
&#x27;&lt;table width=&quot;100%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;InfoWindowTbl&quot;&gt;&#x27; +
&#x27;&lt;tbody&gt;&#x27; +
&#x27;&lt;tr&gt;&#x27; +
&#x27;&lt;td class=&quot;&quot;&gt;&lt;span&gt;Van/Dealer Location&lt;/span&gt;&lt;/td&gt;&lt;td colspan=&quot;5&quot;&gt;&lt;span id=&quot;spanVanDealerLocation&quot;&gt;&#x27; + copyResulEls[i].vanDealerAddress + &#x27;&lt;/span&gt;&#x27; +
&#x27;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;span&gt;Distance&lt;/span&gt;&lt;/td&gt; &lt;td&gt; &lt;span id=&quot;spanVanDealerDistance&quot;&gt;&#x27; + copyResulEls[i].distance.text + &#x27;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span&gt;Duration&lt;/span&gt; &lt;/td&gt;&lt;td&gt;&lt;span id=&quot;spanVanDealerDuration&quot;&gt;&#x27; + copyResulEls[i].duration.text + &#x27;&lt;/span&gt;&#x27; +
&#x27;&lt;/td&gt;&lt;td class=&quot;&quot;&gt; &lt;span&gt;No. of Open Tickets&lt;/span&gt; &lt;/td&gt; &lt;td&gt; &lt;span id=&quot;spanNoOfAssignedTickets&quot;&gt;&#x27; + copyResulEls[i].assignedTicketsToVanDealer + &#x27;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&#x27;;
if (copyResulEls[i].type == &quot;dealer&quot;) {
markerIcon = dealerMarker;
}
else {
if (copyResulEls[i].backgroundColor == &#x27;green&#x27;) {
markerIcon = availableVansMarkers;
} else {
markerIcon = unavailableVansMarkers;
}
}
var vanDealerLatlng = new google.maps.LatLng(copyResulEls[i].lat, copyResulEls[i].lng);
//create marker at position
createMarker(vanDealerLatlng, markerIcon, copyResulEls[i].vanDealerID, description, ccplMap);
}
}
var _bounds = new google.maps.LatLngBounds();
for (var count = 0; count &lt; nearestVansDealersMarks.length; count++) {
_bounds.extend(nearestVansDealersMarks[count].position);
}
ccplMap.fitBounds(_bounds);
//Append the trString created in the dialog-form
$(&quot;#tableVansDealers&quot;).append(trString);
$(&quot;#divVanDealerList&quot;).css(&#x27;display&#x27;, &#x27;inline-block&#x27;);
$(&quot;#divMap&quot;).css(&#x27;height&#x27;, &#x27;60%&#x27;);
$(&quot;#displayVansDealersTable &gt; tbody &gt; tr&quot;).click(function (e) {
var rowId = e.currentTarget.id;
if (infowindow) {
infowindow.close();
}
$(&quot;#displayVansDealersTable&quot;).find(&#x27;tr&#x27;).removeClass(&#x27;showMarked&#x27;);
$(&quot;#displayVansDealersTable&quot;).find(&#x27;tr[id=&#x27; + rowId + &#x27;]&#x27;).addClass(&#x27;showMarked&#x27;);
var selectedVanDealerLat, selectedVanDealerLng, vehicleLatLng, selectedVanDealerLatLng, selectedVanDealerType;
var selectedVanDealerId = e.currentTarget.id;
for (var counter = 0; counter &lt; nearestVansDealersMarks.length; counter++) {
if (nearestVansDealersMarks[counter].customInfo == selectedVanDealerId) {
stopMarkerBounce();
getMarkerBounce(nearestVansDealersMarks[counter]);
}
}
for (var count = 0; count &lt; copyResulEls.length; count++) {
if (copyResulEls[count].vanDealerID == selectedVanDealerId) {
selectedVanDealerLat = copyResulEls[count].lat;
selectedVanDealerLng = copyResulEls[count].lng;
selectedVanDealerType = copyResulEls[count].type;
}
}
vehicleLatLng = breakdownLocationLatLng;
selectedVanDealerLatLng = new google.maps.LatLng(selectedVanDealerLat, selectedVanDealerLng);
calcRoute(vehicleLatLng, selectedVanDealerLatLng, selectedVanDealerType, ccplMap, []);
});
//start marker bounce
function getMarkerBounce(vanDealerMarker) {
if (vanDealerMarker.getAnimation() != null) {
vanDealerMarker.setAnimation(null);
} else {
vanDealerMarker.setAnimation(google.maps.Animation.BOUNCE);
}
}
//stop marker bounce
function stopMarkerBounce() {
for (var count = 0; count &lt; nearestVansDealersMarks.length; count++) {
if (nearestVansDealersMarks[count].getAnimation() != null) {
nearestVansDealersMarks[count].setAnimation(null);
}
}
}
}
//=================================== end calculate distance =======================================//
//===========================================Click Events =========================================//
/**
* This fn binds Click Event to the Map when adding New Vehicle to location Vehicle Location.
* @method bindClickEventToMap
* @for TicketAdministration
*/
function bindClickEventToMap() {
//Remove Source Destination Direction Display if visible as well as Remove Previous Markers if any Present
if (displayDisplay) {
//Remove previous markers
removeTicketDetailsMarkerArray();
//Remove direction display
displayDisplay.setMap(null);
}
//Remove any previous Click Listener on Map if any present.
removeClickEventToMap();
//Bind click listener on Map
google.maps.event.addListener(ccplMap, &#x27;click&#x27;, function (e) {
//Remove previous marker if present
if (marker) {
marker.setMap(null);
//set address text field empty here
marker = &quot;&quot;;
}
if (displayDisplay) {
//Remove direction display
displayDisplay.setMap(null);
}
if (nearestVansDealersMarks.length &gt; 0) {
for (var counter = 0; counter &lt; nearestVansDealersMarks.length; counter++) {
nearestVansDealersMarks[counter].setMap(null);
//set address text field empty here
nearestVansDealersMarks[counter] = &quot;&quot;;
}
nearestVansDealersMarks = [];
}
//remove place location marker array
removePlaceLocationMarkerArray();
//Create a new Marker on the position click on the map
marker = new google.maps.Marker({
position: e.latLng,
map: ccplMap
});
breakdownLocationLatLng = e.latLng;
//Get address of the Lat Long click clicked
var latLngAddress = getReverseGeoCode(e.latLng, function (data) {
//Here we got the address of the point clicked. Update this value to the form textbox.
$(&quot;#eos_exact_location&quot;).val(&quot;&quot;);
$(&quot;#eos_exact_location&quot;).val(data);
$(&quot;#searchLocationTool&quot;).val(data);
});
});
}
/**
* This fn removes Click Event Listener from the map
* @method removeClickEventToMap
* @for TicketAdministration
*/
function removeClickEventToMap() {
google.maps.event.clearListeners(ccplMap, &#x27;click&#x27;);
if (marker) {
marker.setMap(null);
marker = &quot;&quot;;
}
}
//===================================================== end ==========================================//
//======================================================================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 TicketAdministration
*/
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({ &#x27;latLng&#x27;: 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(&#x27;No results found&#x27;);
}
}
return false;
});
}
/**
* This function set center and zoom of map when state or city change
* @method setMapCenterToAddress
* @param {String} address address to show on map
* @for TicketAdministration
*/
function setMapCenterToAddress(address) {
geoCoder = new google.maps.Geocoder();
geoCoder.geocode({ &#x27;address&#x27;: address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
ccplMap.setCenter(results[0].geometry.location);
if (typeof results[0].geometry.bounds !== &#x27;undefined&#x27;) {
ccplMap.fitBounds(results[0].geometry.bounds);
}
}
});
}
/**
* This function call on change of city ame
* @method onBlurCity
* @param {String} $this id of input text box
* @for TicketAdministration
*/
function onBlurCity($this) {
var id = $this;
var cityName = $(&quot;#eos_city&quot;).data(&quot;kendoComboBox&quot;).text();
setMapCenterToAddress($(&#x27;#eos_state&#x27;).find(&#x27;option:selected&#x27;).text() + &quot;, &quot; + cityName);
}
//Global array to allow some special keys
var specialKeys = new Array();
specialKeys.push(8);//Backspace
specialKeys.push(13);//enter
//specialKeys.push(46);//dot
/**
* function to validate if ticket id is numeric or not
*/
function IsNumeric(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode &gt;= 48 &amp;&amp; keyCode &lt;= 57) || specialKeys.indexOf(keyCode) != -1);
document.getElementById(&quot;error&quot;).style.display = ret ? &quot;none&quot; : &quot;inline&quot;;
return ret;
}
/**
* function to validate if reg no is alphanumeric or not
*/
function IsAlphaNumeric(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode &gt;= 48 &amp;&amp; keyCode &lt;= 57) || (keyCode &gt;= 65 &amp;&amp; keyCode &lt;= 90) || (keyCode &gt;= 97 &amp;&amp; keyCode &lt;= 122) || specialKeys.indexOf(keyCode) != -1);
document.getElementById(&quot;errorRegNo&quot;).style.display = ret ? &quot;none&quot; : &quot;inline&quot;;
return ret;
}
/**
* function to validate if ticket id is float or not
*/
function IsFloat(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode &gt;= 48 &amp;&amp; keyCode &lt;= 57) || (keyCode == 46) || specialKeys.indexOf(keyCode) != -1);
document.getElementById(&quot;error&quot;).style.display = ret ? &quot;none&quot; : &quot;inline&quot;;
return ret;
}
/**
* This function call on change of route name
* @method onChangeRoute
* @for TicketAdministration
*/
function onChangeRoute() {
var NH_ID = $(&quot;#routes&quot;).val();
var NH_PATH = HIGHWAY_PATH[NH_ID];
console.log(NH_PATH);
drawHighway(NH_PATH.source, NH_PATH.destination, &quot;&quot;, ccplMap, NH_PATH.wayPoints, NH_PATH.color);
}
//============================================ document ready function ======================================== //
$(document).ready(function () {
////Importing google map api
//document.write(&quot;&lt;script type=&#x27;text/javascript&#x27; src=&#x27;~/Scripts/Shared/HighwayPath.js&#x27;&gt;&lt;/script&gt;&quot;);
selectedTicket = getParameterByName(&quot;complaintNo&quot;);
if (selectedTicket != &quot;&quot;) {
getTicketHistory();
} else {
//viewCheckHistory();
//$(&quot;#tabCheckHistory&quot;).trigger(&#x27;click&#x27;);
}
$(&quot;#tabCheckHistory&quot;).addClass(&#x27;ActiveTab&#x27;);
$(&quot;#div_loading&quot;).hide();
setTimeout(function () {
initMap(&quot;divMapContainer&quot;);
}, 1);
addKendoWindow(&quot;#divAddCustomer&quot;, &quot;Add Customer&quot;, &quot;1000px&quot;, 340, 120);
addKendoWindow(&quot;#divAddCustomerForExistingVehicle&quot;, &quot;Add Customer&quot;, &quot;1000px&quot;, 340, 120);
addKendoWindow(&quot;#divReassignTicket&quot;, &quot;Reassign Ticket&quot;, &quot;1000px&quot;, 150, 120);
$(&quot;#divAddCustomer&quot;).parent().addClass(&quot;Cust_Window&quot;);
$(&quot;#divAddCustomerForExistingVehicle&quot;).parent().addClass(&quot;Cust_Window&quot;);
$(&quot;#divReassignTicket&quot;).parent().addClass(&quot;ReAssign_Window&quot;);
});
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>