Guest User

Untitled

a guest
Apr 23rd, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 123.11 KB | None | 0 0
  1. invoice = new Object();
  2. purchase_order = new Object();
  3. var _geofence;
  4. var _places;
  5. var product_list;
  6. var prod_info;
  7. var map;
  8. var bounds;
  9. var directionsDisplay;
  10. var markerCluster;
  11. var object;
  12. var geocoder;
  13. var origMarker;
  14. var tmpMarker;
  15. var position;
  16. var watchId;
  17. var leg;
  18. var userMark;
  19. var drawingManager;
  20. var destName;
  21. var displayCircle;
  22. var fullAccess;
  23. var systemRole;
  24. var repSelect;
  25. var mapSize;
  26. var infoBubble;
  27. var directionsHandler;
  28. var request;
  29. var waypoints;
  30. var shapes = [];
  31. var geocodeID = [];
  32. var enhancedNavs = [];
  33. var markersCluster = [];
  34. var directionsOrderedNames = [];
  35. var visitPageArray = [];
  36. var directionsEnabled = 0;
  37. var distance = 0;
  38. var countPage = 0;
  39. var surveyCount = 0;
  40. var navbar = 0;
  41. var routeID = 0;
  42. var embarrassingFuckItBoolVar = true;
  43. var shouldLoadAll = true;
  44. var GEOFENCE_RADIUS = 150;
  45. var MILES_IN_METER = 0.000621371;
  46. var AVERAGE_TIME_AT_STOP = 1200;
  47. var LANGUAGE = "English";
  48. var directionsService = new google.maps.DirectionsService();
  49. var usahPos = new google.maps.LatLng(28.399909, -81.40094699999997);
  50. var distanceService = new google.maps.DistanceMatrixService();
  51. var customerInvoiceCutoff = {
  52. string: '-1 month',
  53. num: 30
  54. };
  55. var people = {
  56. customersSet: false,
  57. customersSummaryExists: false,
  58. customersArray: [],
  59. leadsSet: true,
  60. leadsSummaryExists: false,
  61. leadsArray: [],
  62. clustersSet: true
  63. };
  64. var Device = new ScannerDevice({
  65. barcodeData: function (data, bar_type){
  66. $.get('adminLeadsQuery.php?num=26&ref_num=*'+data+'*', function(res) {
  67. console.log(res);
  68. if(String(res) != "") {
  69. var obj = JSON.parse(res);
  70. console.log(obj);
  71. var $page = $('#invoicePage');
  72. $page.children(":jqmData(role=header)").find('h3').html(obj.customer);
  73. var str = "<a href='#' class='startPulling' data-role='button' data-icon='tags' data-json='" + res + "'>Start Pulling</a>";
  74. for(var j = 0; j < obj.items.length; j++) {
  75. str += '<li data-icon="tags"><a href="#"><h2>'+obj.items[j].name+'</h2><p>'+obj.items[j].description+'</p><span class="ui-li-count">Qty: <span id="leftToScan">'+obj.items[j].quantity+'</span></span></a></li>';
  76. }
  77. (embarrassingFuckItBoolVar) ? $('#invoiceList').html(str).trigger('create') : $('#invoiceList').html(str).listview('refresh').find('.startPulling').button();
  78. embarrassingFuckItBoolVar = false;
  79. $.mobile.changePage($page, {transition : 'slideup'});
  80. }
  81. else alert('Invoice not found.');
  82. });
  83. },
  84. magneticCardData: function (track1, track2, track3){
  85. alert('Card read with following data: '+track1+'\n'+track2+'\n'+track3);
  86. },
  87. magneticCardRawData: function (data){
  88. alert('Raw data read from card reader: '+data);
  89. },
  90. buttonPressed: function (button){
  91. // Currently device only registers 1 button.
  92. console.log('Button was pressed');
  93. },
  94. buttonReleased: function (button){
  95. // Currently device only registers 1 button.
  96. console.log('Button was released');
  97. },
  98. connectionState: function (state){
  99. console.log('Scanner is now in state: '+state);
  100. }
  101. });
  102.  
  103. ScannerDevice.registerListener(Device);
  104.  
  105. function showLogin(e) {
  106. $.ajaxSetup({
  107. error: function(xhr, status, error) {
  108. console.log("An AJAX error occured: " + status + "\nError: " + error);
  109. alert("Could not retrieve data from server. Check your internet connection and try again. If this problem persists you will need to restart the application. Status: " + status + " Error: " + error);
  110. }
  111. });
  112. $('.pagerefresh').live('click', function() {
  113. //scan();
  114. window.location="";
  115. });
  116. $.mobile.loading('show', {text: 'Please Wait...', textVisible: true});
  117. console.log(Device);
  118. //Device.enableBarcode(ScannerDevice.CONSTANTS.BAR_TYPES.BAR_ALL, true);
  119. $.noty.consumePopupFunction('alert', {layout: 'top', timeout: 2500, type: 'alert', dismissQueue: true});
  120. $.noty.consumePopupFunction('confirm', {
  121. layout: 'top',
  122. type: 'confirm',
  123. buttons: [
  124. {addClass: 'btn btn-primary confirm-ok', text: 'Yes'},
  125. {addClass: 'btn btn-danger confirm-cancel', text: 'No'}
  126. ],
  127. dismissQueue: true
  128. });
  129. initContent();
  130. init();
  131. $.mobile.changePage($('#leadsPage'), {transition: "flip"});
  132. }
  133.  
  134. function init() {
  135. $('#dirbutton').hide();
  136. setTimeout(initMapPageHandlers, 4000);
  137. $("#directions").css('display', 'none');
  138. //$.get('adminLeadsQuery.php?num=2', showContent);
  139. //$.mobile.loading( 'show', {text: 'Loading Map...', textVisible: true});
  140. }
  141.  
  142. function initMapPageHandlers() {
  143. document.getElementById("iframe").style.height = (document.body.offsetHeight - $('#mapheader').height()) + 'px';
  144. mapSize = new google.maps.Size(document.body.offsetWidth, document.body.offsetHeight - document.getElementById("mapheader").style.height);
  145. directionsDisplay = new google.maps.DirectionsRenderer();
  146.  
  147. GeoMarker = new GeolocationMarker();
  148. GeoMarker.setCircleOptions({fillColor: '#808080'});
  149. geocoder = new google.maps.Geocoder();
  150. console.log(navigator);
  151. console.log(window.plugins);
  152. console.log(window);
  153.  
  154. //Geocode current customers to find lat lng to display on the map
  155. $.get('adminLeadsQuery.php?num=9', function(res) {
  156. var obj = JSON.parse(res),
  157. length = obj.resultsFound.length;
  158.  
  159. if(length != 0) {
  160. var SAMPLE_POST = 'http://www.mapquestapi.com/geocoding/v1/batch?key=Fmjtd%7Cluub2l68nd%2C7a%3Do5-96tgh4&callback=renderGeocode';
  161.  
  162. //Max of 100 locations per request
  163. if(length > 100) length = 100;
  164.  
  165. for(var i = 0; i < length; i++) {
  166. SAMPLE_POST += '&location=' + obj.resultsFound[i].address;
  167. geocodeID.push(obj.resultsFound[i].id);
  168. }
  169. console.log(SAMPLE_POST);
  170. console.log(geocodeID);
  171. var script = document.createElement('script');
  172. script.type = 'text/javascript';
  173. script.src = SAMPLE_POST;
  174. document.body.appendChild(script);
  175. }
  176. });
  177.  
  178.  
  179. directionsHandler = {
  180. arrLocations : [],
  181. addLocation:function(obj){
  182. directionsHandler.arrLocations.push(obj);
  183. }
  184. };
  185.  
  186. map = new google.maps.Map(document.getElementById("iframe").contentDocument.getElementById('map_canvas'), {
  187. mapTypeId: google.maps.MapTypeId.ROADMAP,
  188. center: GeoMarker.getPosition()
  189. });
  190.  
  191. //Initialize the drawing manager
  192. initDrawer();
  193.  
  194. google.maps.Polygon.prototype.Contains = function(point) {
  195. // ray casting alogrithm http://rosettacode.org/wiki/Ray-casting_algorithm
  196. var crossings = 0,
  197. path = this.getPath();
  198.  
  199. // for each edge
  200. for (var i=0; i < path.getLength(); i++) {
  201. var a = path.getAt(i),
  202. j = i + 1;
  203. if (j >= path.getLength()) {
  204. j = 0;
  205. }
  206. var b = path.getAt(j);
  207. if (rayCrossesSegment(point, a, b)) {
  208. crossings++;
  209. }
  210. }
  211.  
  212. // odd number of crossings?
  213. return (crossings % 2 == 1);
  214.  
  215. function rayCrossesSegment(point, a, b) {
  216. var px = point.lng(),
  217. py = point.lat(),
  218. ax = a.lng(),
  219. ay = a.lat(),
  220. bx = b.lng(),
  221. by = b.lat();
  222. if (ay > by) {
  223. ax = b.lng();
  224. ay = b.lat();
  225. bx = a.lng();
  226. by = a.lat();
  227. }
  228. // alter longitude to cater for 180 degree crossings
  229. if (px < 0) { px += 360 };
  230. if (ax < 0) { ax += 360 };
  231. if (bx < 0) { bx += 360 };
  232.  
  233. if (py == ay || py == by) py += 0.00000001;
  234. if ((py > by || py < ay) || (px > Math.max(ax, bx))) return false;
  235. if (px < Math.min(ax, bx)) return true;
  236.  
  237. var red = (ax != bx) ? ((by - ay) / (bx - ax)) : Infinity;
  238. var blue = (ax != px) ? ((py - ay) / (px - ax)) : Infinity;
  239. return (blue >= red);
  240.  
  241. }
  242.  
  243. };
  244.  
  245. var input = document.getElementById('search_bar');
  246. var autocomplete = new google.maps.places.Autocomplete(input);
  247.  
  248. autocomplete.bindTo('bounds', map);
  249.  
  250.  
  251. $('#dirbutton').live('click', function () {$('#directions').css('display', 'block')});
  252.  
  253. //Make the browser go back to the map when an individual leg of the route is clicked
  254. $('.adp-directions').live('click', function() {parent.history.back();});
  255. $('div[jsselect="legs"]').live('click', function() {parent.history.back();});
  256.  
  257. //if(!navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
  258. if(fullAccess != 1) {
  259. initCustomers();
  260. }
  261. $('#leads_list').find('.location').each(function() {
  262. var $this = $(this);
  263. var loc = $this.val();
  264. var placeName = $this.siblings('h3:first').html();
  265. var id = $this.siblings('.leadid:first').val();
  266. var quality = $this.siblings('.quality:first').val();
  267. var imgString = getMarkerImage(quality, 0);
  268. var newMark = loc.substring(1,loc.length-2).split(",");
  269. var image = new google.maps.MarkerImage(imgString,
  270. new google.maps.Size(20, 34),
  271. new google.maps.Point(0, 0),
  272. new google.maps.Point(10, 34)
  273. );
  274. var pos = new google.maps.LatLng(newMark[0], newMark[1]);
  275. var mark = new google.maps.Marker({
  276. map: map,
  277. position: pos,
  278. icon: image,
  279. animation: google.maps.Animation.DROP,
  280. quality: quality,
  281. name: placeName
  282. });
  283. markersCluster.push(mark);
  284. people.leadsArray.push(mark);
  285. google.maps.event.addListener(mark, 'click', function() {
  286. if(typeof infoBubble === 'undefined' || infoBubble.name !== placeName) {
  287. if(typeof infoBubble !== 'undefined') infoBubble.close();
  288. infoBubble = new InfoBubble({
  289. content: '<div id="bubble'+id+'" style="background: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(112,112,112)),color-stop(0.51, rgb(94,94,94)),color-stop(0.52, rgb(57,57,57))); background: -moz-linear-gradient(center top,rgb(112,112,112) 0%,rgb(94,94,94) 51%,rgb(57,57,57) 52%);"><div id="placearrow" style="text-shadow: 0 -1px 0 #000; color: #fff; font-family: Helvetica Neue, Helvetica, arial; font-size: 18px; line-height: 25px; padding: 4px 15px 4px 15px; font-weight: bold;">' + placeName + '</div></div>',
  290. shadowStyle: 1,
  291. padding: 0,
  292. backgroundColor: 'rgb(57,57,57)',
  293. borderRadius: 4,
  294. arrowSize: 10,
  295. borderWidth: 1,
  296. borderColor: '#2c2c2c',
  297. disableAutoPan: true,
  298. hideCloseButton: true,
  299. arrowPosition: 30,
  300. arrowStyle: 2,
  301. enableEventPropagation: false,
  302. name: placeName
  303. });
  304. infoBubble.open(map, mark);
  305. $('#bubble'+id).bind('click', function() {
  306. infoBubble.close();
  307. infoBubble = undefined;
  308. singleLocationPageTransition(id, placeName);
  309. });
  310. }
  311. else {
  312. infoBubble.close();
  313. infoBubble = undefined;
  314. singleLocationPageTransition(id, placeName);
  315. }
  316. });
  317. });
  318.  
  319.  
  320. markerCluster = new MarkerClusterer(map, markersCluster, {averageCenter: true, maxZoom: 14});
  321.  
  322. var infowindow = new google.maps.InfoWindow();
  323.  
  324. google.maps.event.addListener(autocomplete, 'place_changed', function() {
  325. var marker = new google.maps.Marker({
  326. map: map
  327. });
  328. if(typeof infoBubble !== 'undefined') infoBubble.close();
  329. marker.setVisible(false);
  330. var place = autocomplete.getPlace();
  331. if (!place.geometry) {
  332. // Inform the user that the place was not found and return.
  333. input.className = 'notfound';
  334. return;
  335. }
  336.  
  337. // If the place has a geometry, then present it on a map.
  338. if (place.geometry.viewport) {
  339. map.fitBounds(place.geometry.viewport);
  340. } else {
  341. map.setCenter(place.geometry.location);
  342. map.setZoom(17); // Why 17? Because it looks good.
  343. }
  344. var image = new google.maps.MarkerImage(
  345. place.icon,
  346. new google.maps.Size(71, 71),
  347. new google.maps.Point(0, 0),
  348. new google.maps.Point(17, 34),
  349. new google.maps.Size(35, 35));
  350. marker.setIcon(image);
  351. marker.setPosition(place.geometry.location);
  352. marker.setVisible(true);
  353.  
  354. var address = '';
  355. if (place.address_components) {
  356. address = [
  357. (place.address_components[0] && place.address_components[0].short_name || ''),
  358. (place.address_components[1] && place.address_components[1].short_name || ''),
  359. (place.address_components[2] && place.address_components[2].short_name || '')
  360. ].join(' ');
  361. }
  362. if(typeof infoBubble != 'undefined') infoBubble.close();
  363. infoBubble = new InfoBubble({
  364. content: '<div style="background: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(112,112,112)),color-stop(0.51, rgb(94,94,94)),color-stop(0.52, rgb(57,57,57))); background: -moz-linear-gradient(center top,rgb(112,112,112) 0%,rgb(94,94,94) 51%,rgb(57,57,57) 52%);"><div id="placearrow" style="text-shadow: 0 -1px 0 #000; color: #fff; font-family: Helvetica Neue, Helvetica, arial; font-size: 18px; line-height: 25px; padding: 4px 15px 4px 15px; font-weight: bold;">' + place.name + '</div></div>',
  365. shadowStyle: 1,
  366. padding: 0,
  367. backgroundColor: 'rgb(57,57,57)',
  368. borderRadius: 4,
  369. arrowSize: 10,
  370. borderWidth: 1,
  371. borderColor: '#2c2c2c',
  372. disableAutoPan: true,
  373. hideCloseButton: true,
  374. arrowPosition: 30,
  375. arrowStyle: 2,
  376. enableEventPropagation: true
  377. });
  378.  
  379. infoBubble.open(map, marker);
  380. google.maps.event.addListener(marker, 'click', function() {
  381. var zipcode, assString;
  382. for(var k = 0; k<place.address_components.length;k++) {
  383. if(place.address_components[k].types == "postal_code") {
  384. zipcode = place.address_components[k].long_name;
  385. }
  386. }
  387. //Get rid of the everything past the comma to make searching more accurate
  388. var searchAddress = place.formatted_address.split(',')[0];
  389. $.get('adminLeadsQuery.php?num=4&string='+searchAddress+'&pnum='+place.formatted_phone_number+'&fnum='+place.formatted_phone_number.substring(1).replace(') ','-'), function(res) {
  390. var $page = $('#popupLead');
  391. var $content = $page.children( ":jqmData(role=content)" );
  392. var $header = $page.children( ":jqmData(role=header)" );
  393. $.mobile.changePage($page);
  394. //Unbind previously binded event handlers.
  395. $('#dirbutt').unbind('click');
  396. $('#newlead').unbind('click');
  397.  
  398. //Parse result into a JSON object
  399. console.log(res);
  400. var obj = JSON.parse(res);
  401. var element = obj.resultsFound[0];
  402. console.log(obj.resultsFound);
  403.  
  404. if(obj.resultsFound.length == 0) assString = 'Nobody yet.';
  405. else if(element.assigned == '') (element.lead == 1) ? assString = 'Has a lead, not assigned.' : assString = 'House Account';
  406. else assString = element.assigned;
  407.  
  408.  
  409. var str = '<li><h3>Address:</h3> <p>'+place.formatted_address+'</p></li>'+
  410. '<li><h3>Zip Code:</h3> <p>'+zipcode+'</li>'+
  411. '<li><h3>Phone Number:</h3> <p>'+place.formatted_phone_number+'</p></li>'+
  412. '<li><h3>Assigned to:</h3> <p>'+assString+'</p></li>';
  413. $header.find( "h3" ).html( place.name );
  414. $content.find('ul').html(str);
  415. // Enhance the elements we just injected.
  416. $content.find( ":jqmData(role=listview)" ).listview('refresh');
  417.  
  418.  
  419. $('#dirbutt').bind('click', function() {
  420. $.mobile.changePage($('#popupMap'), {reverse: true});
  421. setTimeout(function() {
  422. getDirections(place.geometry.location);
  423. directionsOrderedNames.push(place.name);
  424. }, 2000);
  425. });
  426. $('#newlead').bind('click', function() {
  427. console.log(place.name+' '+place.formatted_address+' '+place.formatted_phone_number+' '+zipcode+' '+place.geometry.location);
  428. $.get('adminLeadsQuery.php?num=5&name='+place.name+'&address='+place.formatted_address+'&phone_num='+place.formatted_phone_number+'&zip='+zipcode+'&location='+place.geometry.location, function(res) {
  429. //Parse JSON result into a javascript object
  430. console.log(res);
  431. var obj = JSON.parse(res);
  432. console.log(obj);
  433. if(obj.found == 0 || obj.found == 2) {
  434. $.get('adminLeadsQuery.php?num=2', showContent);
  435. } else {
  436. $( "#popupError" ).popup( "open" );
  437. }
  438. });
  439. });
  440. });
  441. });
  442. });
  443.  
  444. directionsDisplay.setMap(map);
  445. directionsDisplay.setPanel(document.getElementById("directions"));
  446.  
  447.  
  448. var polyOptions = {
  449. strokeColor: '#2861a4',
  450. strokeOpacity: 1.0,
  451. strokeWeight: 3
  452. }
  453. poly = new google.maps.Polyline(polyOptions);
  454. poly.setMap(map);
  455.  
  456. trackGeoMarker();
  457. if( /iPhone|iPod/i.test(navigator.userAgent) ) {
  458. //Device.enableBarcode(ScannerDevice.CONSTANTS.BAR_TYPES.BAR_ALL, true)
  459. }
  460.  
  461. $('.routePageClick').live('click', function() {
  462. $this = $(this);
  463. $this.addClass('ui-btn-active');
  464. setTimeout(function() {
  465. $this.removeClass('ui-btn-active');
  466. }, 500);
  467. $.get('adminLeadsQuery.php?num=1', function(res) {
  468. $('#routeContent').html(res);
  469. $('#routePage').page();
  470. $('#routePage').find( ":jqmData(role=listview)" ).listview();
  471. $('#routePage').find( ":jqmData(role=button)" ).button();
  472. $('#routeContent').collapsibleset('refresh');
  473. $('#routeContentCompleted').collapsibleset();
  474. $.mobile.changePage($('#routePage'));
  475. //if(jQuery.contains(document.documentElement, $('#routeContentCompleted')[0]))
  476. });
  477. });
  478.  
  479. $('.routeItemButton').live('click', function() {
  480. $this = $(this);
  481. var pending = $this.attr('pending');
  482. var id = $this.attr('route_id');
  483. console.log(id+' '+pending);
  484. $this.addClass('ui-btn-active');
  485. setTimeout(function() {
  486. $this.removeClass('ui-btn-active');
  487. }, 500);
  488. $.mobile.changePage('#popupMap', {reverse: true});
  489. $('#pendingListDiv').before('<ul data-role="listview">' +
  490. '<li data-role="list-divider" focus="false" data-theme="b">In Progress</li>' +
  491. '</ul>' +
  492. '<ul data-role="listview" data-theme="c" data-inset="true" id="routeContentInProgress">' +
  493. '</ul><br>');
  494. $('#c' + id).hide();
  495. $.get('adminLeadsQuery.php?num=22&id='+id, function(res) {
  496. waypoints = JSON.parse(res);
  497. waypoints = waypoints.results;
  498. console.log(waypoints);
  499. var pos = waypoints[0].destination.split(',');
  500. pos = new google.maps.LatLng(pos[0], pos[1]);
  501. startRouteRequest(GeoMarker.getPosition(), pos);
  502. for(var i = 0; i < waypoints.length; i++) {
  503. $('#routeContentInProgress').append('<li><p><strong>Start: ' + waypoints[i].origin_name + '</strong><br>' + waypoints[i].start_address + '<br><strong>End: ' + waypoints[i].destination_name + '</strong><br>' + waypoints[i].end_address + '</strong><br>' + waypoints[i].distance + ', ' + waypoints[i].duration + '</p></li>');
  504. }
  505. //$('#routeContentInProgress').find('li:first').attr('data-theme', 'b');
  506. $('#routeContentInProgress').append('<a href="#" class="routeNextStep" data-role="button" data-icon="map-marker" data-theme="c">Start Next Step</a>');
  507. $('.routeNextStep').live('click', function() {
  508. $this = $(this);
  509. $this.addClass('ui-btn-active');
  510. setTimeout(function() {
  511. $this.removeClass('ui-btn-active');
  512. }, 500);
  513. GeoMarker.setMap(null);
  514. GeoMarker = new GeolocationMarker(map);
  515. GeoMarker.setCircleOptions({fillColor: '#808080'});
  516. trackGeoMarker();
  517. nextRouteStep();
  518. });
  519. _geofence = new GeoFence(0, pos, waypoints[0].destination_name);
  520. });
  521. });
  522.  
  523. $('.popupMenu').live('click', function() {$('#popupMenu').popup('close');});
  524.  
  525. $('.optionMenu').live('click', function() {
  526. $( "#popupMenu" ).popup( "open" );
  527. setTimeout(function() {
  528. $(".optionMenu").removeClass('ui-btn-active');
  529. }, 500);
  530.  
  531. });
  532.  
  533. $('.leadsPageTurn').bind('click', function() {
  534. $.mobile.changePage($('#leadsPage'));
  535. });
  536.  
  537. $('#distance').live('click', function() {
  538. $this = $(this);
  539. $this.addClass('ui-btn-active');
  540. setTimeout(function() {
  541. $this.removeClass('ui-btn-active');
  542. }, 500);
  543. alert("You've traveled "+distance+" miles.");
  544. });
  545.  
  546. $('#current').bind('click', function() {
  547. setTimeout(function() {
  548. $("#current").removeClass('ui-btn-active');
  549. }, 500);
  550. map.setCenter(GeoMarker.getPosition());
  551. map.setZoom(16);
  552. });
  553.  
  554. $('#displaycust').bind('click', function() {
  555. $this = $(this);
  556. $this.addClass('ui-btn-active');
  557. setTimeout(function() {
  558. $this.removeClass('ui-btn-active');
  559. }, 500);
  560. initCustomers();
  561. });
  562.  
  563. $('#displayleads').bind('click', function() {
  564. $this = $(this);
  565. $this.addClass('ui-btn-active');
  566. setTimeout(function() {
  567. $this.removeClass('ui-btn-active');
  568. }, 500);
  569. initLeads();
  570. });
  571.  
  572. $('#displayclusters').bind('click', function() {
  573. if(people.clustersSet == true) {
  574. confirm("This may cause serious lag and has the possiblity of crashing the application. Would you like to continue?", function(r) {
  575. if(r == true) {
  576. $('#displayclusters').html('Show Clusters');
  577. markerCluster.clearMarkers();
  578. for(var i = 0; i < people.leadsArray.length; i++) {
  579. people.leadsArray[i].setMap(map);
  580. }
  581. for(var i = 0; i < people.customersArray.length; i++) {
  582. people.customersArray[i].setMap(map);
  583. }
  584. people.clustersSet = false;
  585. }
  586. });
  587. }
  588. else {
  589. $('#displayclusters').html('Hide Clusters');
  590. if(people.customersSet == true) {
  591. markerCluster.addMarkers(people.customersArray);
  592. }
  593. if(people.leadsSet == true) {
  594. markerCluster.addMarkers(people.leadsArray);
  595. }
  596. people.clustersSet = true;
  597. }
  598. });
  599.  
  600. $('.custsummary').bind('click', function() {
  601.  
  602. if(people.customersSummaryExists == false) {
  603. if(people.customersSet == false) {
  604. $.mobile.loading( 'show', {text: 'Generating Report', textVisible: true});
  605. $.get('adminLeadsQuery.php?num=13', function(res) {
  606. object = JSON.parse(res);
  607. var length = object.resultsFound.length;
  608. addCustomers(object, length);
  609. });
  610. //Wait a second to make sure all customers have been added to the array (asynchronous)
  611. setTimeout(function() {
  612. people.customersArray.forEach(appendCustomer);
  613. console.log(people.customersArray);
  614. $.mobile.changePage($('#summaryPage'), {transition: 'flip'});
  615. $.mobile.loading( 'hide');
  616. people.customersSummaryExists = true
  617. }, 20000);
  618. }
  619. else {
  620. people.customersArray.forEach(appendCustomer);
  621. console.log(people.customersArray);
  622. $.mobile.changePage($('#summaryPage'), {transition: 'flip'});
  623. people.customersSummaryExists = true;
  624. }
  625. }
  626. else {
  627. $.mobile.changePage($('#summaryPage'), {transition: 'flip'});
  628. }
  629. $('#uncollapse').removeClass('ui-collapsible-collapsed');
  630. });
  631.  
  632. $('#custOptions').bind('click', function() {
  633. $('#popupCustOptions').popup('open');
  634. });
  635.  
  636. $('.weekly').bind('click', function() {
  637. var $this = $(this);
  638. $this.addClass('ui-btn-active');
  639. setTimeout(function() {
  640. $this.removeClass('ui-btn-active');
  641. }, 2000);
  642. classificationChange('-1 week', '7', 'Weekly');
  643. });
  644.  
  645. $('.monthly').bind('click', function() {
  646. var $this = $(this);
  647. $this.addClass('ui-btn-active');
  648. setTimeout(function() {
  649. $this.removeClass('ui-btn-active');
  650. }, 2000);
  651. classificationChange('-1 month', '30', 'Monthly');
  652. });
  653.  
  654. $('.quarterly').bind('click', function() {
  655. var $this = $(this);
  656. $this.addClass('ui-btn-active');
  657. setTimeout(function() {
  658. $this.removeClass('ui-btn-active');
  659. }, 2000);
  660. classificationChange('-3 month', '90', 'Quarterly');
  661. });
  662.  
  663. $('.leadsummary').bind('click', function() {
  664. $this = $(this);
  665. $this.addClass('ui-btn-active');
  666. setTimeout(function() {
  667. $this.removeClass('ui-btn-active');
  668. }, 500);
  669. if(people.leadsSummaryExists == false) {
  670. people.leadsArray.forEach(appendLead);
  671. console.log(people.leadsArray);
  672. people.leadsSummaryExists = true;
  673. }
  674. $.mobile.changePage($('#leadSummaryPage'), {transition: 'flip'});
  675. });
  676.  
  677. $('#aButton, #bButton, #cButton, #dButton, #eButton, #fButton, #inactiveButton').bind('click', function() {
  678. if($(this).hasClass('ui-btn-active')) {
  679. $(this).removeClass('ui-btn-active');
  680. var c = $(this).attr('id').substring(0,1).toUpperCase() + $(this).attr('id').substring(1);
  681. c = c.split('Button')[0];
  682. for(var i = 0; i < people.customersArray.length; i++) {
  683. if(people.customersArray[i].classification.localeCompare(c) == 0) {
  684. people.customersArray[i].setVisible(false);
  685. if(people.clustersSet == true) markerCluster.removeMarker(people.customersArray[i]);
  686. }
  687. }
  688. }
  689. else {
  690. var time = 0;
  691.  
  692. var c = $(this).attr('id').substring(0,1).toUpperCase() + $(this).attr('id').substring(1);
  693. c = c.split('Button')[0];
  694. if(people.customersArray.length == 0) {
  695. initCustomers();
  696. setTimeout(function() {
  697. for(var i = 0; i < people.customersArray.length; i++) {
  698. if(people.customersArray[i].classification.localeCompare(c) != 0) {
  699. people.customersArray[i].setVisible(false);
  700. if(people.clustersSet == true) markerCluster.removeMarker(people.customersArray[i]);
  701. }
  702. }
  703. }, 8000);
  704. $('#aButton, #bButton, #cButton, #dButton, #eButton, #fButton, #inactiveButton').removeClass('ui-btn-active');
  705. }
  706. else {
  707. for(var i = 0; i < people.customersArray.length; i++) {
  708. if(people.customersArray[i].classification.localeCompare(c) == 0) {
  709. people.customersArray[i].setVisible(true);
  710. if(people.clustersSet == true) markerCluster.addMarker(people.customersArray[i]);
  711. }
  712. }
  713. }
  714. $(this).addClass('ui-btn-active');
  715. }
  716. });
  717.  
  718. /* $('#printPB').bind('click', function() {
  719. $.get('barcode.php?str=391324502', function(res) {
  720. window.plugin.print(res);
  721. });
  722. }); */
  723.  
  724. /* $('#selLanguage').live('click', function() {
  725. $this = $(this);
  726. $this.addClass('ui-btn-active');
  727. setTimeout(function() {
  728. $this.removeClass('ui-btn-active');
  729. }, 500);
  730. $.mobile.changePage( "#pageTranslator", { role: "dialog" } );
  731.  
  732. $('.goog-te-combo').
  733. }); */
  734.  
  735. geocoder = new google.maps.Geocoder();
  736.  
  737. var showMenu = 0;
  738.  
  739. GeoMarker.setMap(map);
  740. $('input').textinput();
  741. setTimeout(function() {
  742. $.mobile.loading( 'hide' );
  743. }, 15000);
  744. $('.leadsPageTurn').live('click', function() {
  745. var prev = {
  746. distance: 0,
  747. element: 0
  748. };
  749. $('#leads_list').find('.location').each(function() {
  750. var $this = $(this);
  751. var loc = $this.val();
  752. var newMark = loc.substring(1,loc.length-2).split(",");
  753. var pos = new google.maps.LatLng(newMark[0], newMark[1]);
  754. var distance = (google.maps.geometry.spherical.computeDistanceBetween(pos, GeoMarker.getPosition()) * MILES_IN_METER).toFixed(2);
  755. $this.siblings('p:first').find('.realDistance').html(distance);
  756. });
  757. $("#leads_list>li[focus='true']").tsort('.realDistance');
  758. $("#leads_list>li[focus='false']").tsort('.realDistance');
  759. });
  760. }
  761.  
  762. function initContent() {
  763. $.mobile.loading( 'show', {text: 'Loading...', textVisible: true});
  764. //$('.leadsPageTurn').live('click', function() {
  765. $.get('adminLeadsQuery.php?num=2', showContent);
  766.  
  767. }
  768.  
  769. function showContent(res) {
  770. $('.editable').unbind('change');
  771. $('.marker').unbind('click');
  772. var $page = $('#leadsPage'),
  773.  
  774. // Get the header for the page.
  775. $header = $page.children( ":jqmData(role=header)" ),
  776.  
  777. // Get the content area element for the page.
  778. $content = $page.children( ":jqmData(role=content)" );
  779. $content.html(res);
  780.  
  781.  
  782. // Pages are lazily enhanced. We call page() on the page
  783. // element to make sure it is always enhanced before we
  784. // attempt to enhance the listview markup we just injected.
  785. // Subsequent calls to page() are ignored since a page/widget
  786. // can only be enhanced once.
  787. $page.page();
  788.  
  789. // Enhance the listview we just injected.
  790. $content.find( ":jqmData(role=listview)" ).listview();
  791.  
  792. //Event handlers for the search bar.
  793. $('input[placeholder="Search..."]').live('change', function() {
  794. if(this.value.length > 1 && $('#search_all').hasClass('ui-btn-active')) {
  795. $.mobile.loading('show');
  796. $.get('adminLeadsQuery.php?num=4&string='+this.value, searchComplete);
  797. $('#leads_list').children().addClass('ui-screen-hidden');
  798. }
  799. });
  800.  
  801. $('#search_all').live('click', function() {
  802. $('#leads_list').children().addClass('ui-screen-hidden');
  803. });
  804.  
  805. $('#search_spec').live('click', function() {
  806. $('.deletable_list').remove();
  807. $('#leads_list').children('.ui-screen-hidden').removeClass('ui-screen-hidden');
  808. $('a[title="clear text"]').trigger('click');
  809. });
  810.  
  811. $('a[title="clear text"]').live('click', function() {
  812. $('.deletable_list').remove();
  813. $('#search_spec').addClass('ui-btn-active');
  814. $('#search_all').removeClass('ui-btn-active');
  815. });
  816.  
  817. //Event handlers for the page buttons.
  818. $('.ls-lead').live('click', function() {
  819. $this = $(this);
  820. setTimeout(function() {
  821. $this.removeClass('ui-btn-active');
  822. }, 500);
  823. var $this = $(this);
  824. console.log($this);
  825. var id = $this.find('.leadid:first').val();
  826. console.log(id);
  827. var visit_num = $this.find('.visit_num:first').val();
  828. console.log(visit_num);
  829. var name = $this.find('h3:first').html();
  830. console.log(name);
  831. $this.addClass('ui-btn-active');
  832. singleLocationPageTransition(id,name);
  833. });
  834.  
  835. $('.editable').live('change',function() {
  836. var name = $(this).attr('name');
  837. var value = $(this).val();
  838. $.get('../../admin/updateLeads.php?id='+$('.ui-page-active').find('.id').val()+'&name='+name+'&val='+value, function () {
  839. if(name == "name") $('.ui-page-active').children( ":jqmData(role=header)" ).find( "h3" ).html( value );
  840. $('#singleLead').find('.check').html('<img id="checkmark" style="position: fixed; right: 50%; top: 50%; margin-right:-32px; margin-top:-32px; height:75px; width:75px; z-index:1;" src="http://www.usahospitality.com/old/admin/imagen/accept.png"></img>');
  841. $('#checkmark').hide().fadeIn(800);
  842. $('#checkmark').fadeOut(800);
  843. alert('Edit Successful!');
  844. });
  845. });
  846.  
  847. $('.marker').live('click', function() {
  848. var loc = $('#singleLead').find('.location').val();;
  849. var placeName = $('#singleLead').children( ":jqmData(role=header)" ).find('h3').html();
  850. $.mobile.changePage($('#popupMap'), {transition:'flow', reverse: true});
  851. if(loc.charAt(0) == '(') loc = loc.substring(1,loc.length-2);
  852. var newMark = loc.split(",");
  853. var pos = new google.maps.LatLng(newMark[0], newMark[1]);
  854.  
  855. google.maps.event.trigger(map, 'resize');
  856. map.setZoom(15);
  857. map.setCenter(pos);
  858. });
  859.  
  860. $('.getdir').live('click', function() {
  861. var loc = $('#singleLead').find('.location').val();
  862. $.mobile.changePage($('#popupMap'), {transition:'flow', reverse: true});
  863. if(loc.charAt(0) == '(') loc = loc.substring(1,loc.length-2);
  864. var newMark = loc.split(",");
  865. var position = new google.maps.LatLng(newMark[0], newMark[1]);
  866. setTimeout(function() {
  867. getDirections(position);
  868. directionsOrderedNames.push($('#singleLead').children( ":jqmData(role=header)" ).find('h3').html());
  869. }, 1000);
  870. });
  871.  
  872. $('.lead-enhance').live('click', function() {
  873. appendNavBar();
  874. });
  875.  
  876. $('.newvisit').live('click', function() {
  877. var leadsId = $('.ui-page-active').find('.id').val();
  878. $.get('adminLeadsQuery.php?num=8&id=' + leadsId, function (res) {
  879. var visitNumber = Number(res) + 1;
  880. $page = $('#newVisit');
  881. $content = $page.children(":jqmData(role=content)");
  882. $page.children(":jqmData(role=header)").find('h3').html(getNumberSuffix(visitNumber) + ' Visit');
  883. var newHTML = '<h3>Visit Goal:</h3>' +
  884. '<p>' + getVisitGoal(visitNumber) + '</p>' +
  885.  
  886. '<form id="visitForm">' +
  887.  
  888. '<input name="num" type="hidden" value="7">' +
  889. '<input name="visit_num" type="hidden" value="' + visitNumber + '">' +
  890. '<input name="leads_id" type="hidden" value="' + leadsId + '">' +
  891.  
  892. '<label for="date">Date:</label>' +
  893. '<input type="date" name="date" id="date" />' +
  894.  
  895. '<div class="ui-grid-a">' +
  896.  
  897. '<div class="ui-block-a">' +
  898. '<label for="time_in">Time In:</label>' +
  899. '<input type="time" name="time_in" id="time_in" />' +
  900. '</div>' +
  901.  
  902. '<div class="ui-block-b">' +
  903. '<label for="time_out">Time Out:</label>' +
  904. '<input type="time" name="time_out" id="time_out" />' +
  905. '</div>' +
  906.  
  907. '</div>' +
  908.  
  909. '<fieldset data-role="controlgroup">' +
  910. '<legend>Contact with decision maker:</legend>' +
  911. '<input type="radio" name="boss_contact" id="dec-yes" value="yes" />' +
  912. '<label for="dec-yes">Yes</label>' +
  913. '<input type="radio" name="boss_contact" id="dec-no" value="no" />' +
  914. '<label for="dec-no">No</label>' +
  915. '<input type="radio" name="boss_contact" id="dec-reschedule" value="reschedule" />' +
  916. '<label for="dec-reschedule">Reschedule</label>' +
  917. '</fieldset>' +
  918.  
  919. '<label for="employees">Other people that you saw:</label>' +
  920. '<input type="text" name="employees" id="employees" />';
  921. if(visitNumber == 1) {
  922. newHTML += '<label for="current_suppliers">Current Suppliers:</label>' +
  923. '<input type="text" name="current_suppliers" id="current_suppliers" />' +
  924.  
  925. '<label for="supplier_time">How long have they been buying from them? (in months)</label>' +
  926. '<input type="range" min="0" max="60" value="" data-track-theme="b" name="supplier_time" id="supplier_time" />' +
  927.  
  928. '<label for="supplier_rep">Supplier\'s Rep Name:</label>' +
  929. '<input type="text" name="supplier_rep" id="supplier_rep" />';
  930. }
  931. else {
  932. newHTML += '<legend>Product Research Area:</legend>' +
  933. '<div class="fieldcontain">' +
  934. '<ul id="product_area" data-role="listview" data-inset="true">' +
  935. '<li data-icon="plus"><a href="#addProduct" data-rel="dialog" data-transition="pop">Add product</a></li>' +
  936. '</ul>' +
  937. '</div>';
  938. }
  939. if(visitNumber == 2) {
  940. newHTML += '<br><strong>Find a demo product to be scheduled at the 4th appointment.</strong><br><br>' +
  941. '<label for="demo_product">Demo Product:</label>' +
  942. '<input type="text" name="demo_product" id="demo_product" />';
  943. }
  944. else if(visitNumber == 3 || visitNumber == 5 || visitNumber == 6) newHTML += '<br><strong>Talk about the demo product.</strong><br><br>';
  945. else if(visitNumber == 4) newHTML += '<br><strong>Schedule Demo Installation.</strong><br><br>';
  946.  
  947. if(visitNumber == 2) {
  948. newHTML += '<label for="weekly_volume">Weekly Purchasing Volume:</label>' +
  949. '<input type="text" name="weekly_volume" id="weekly_volume" />';
  950. }
  951. if(visitNumber == 1 || visitNumber == 5 || visitNumber == 6) {
  952. newHTML += '<label for="ice_breaker">Ice Breaking Product:</label>' +
  953. '<input type="text" name="ice_breaker" id="ice_breaker" />' +
  954.  
  955. '<label for="conv_piece">Conversation Piece:</label>' +
  956. '<input type="text" name="conv_piece" id="conv_piece" />';
  957. }
  958. if(visitNumber >= 4) {
  959. newHTML += '<fieldset data-role="controlgroup">' +
  960. '<legend>Order:</legend>' +
  961. '<input type="radio" name="ordered" id="order-yes" value="yes" />' +
  962. '<label for="order-yes">Yes</label>' +
  963. '<input type="radio" name="ordered" id="order-no" value="no" />' +
  964. '<label for="order-no">No</label>' +
  965. '</fieldset>' +
  966.  
  967. '<fieldset data-role="controlgroup">' +
  968. '<legend>Application:</legend>' +
  969. '<input type="radio" name="application" id="application-yes" value="yes" />' +
  970. '<label for="application-yes">Yes</label>' +
  971. '<input type="radio" name="application" id="application-no" value="no" />' +
  972. '<label for="application-no">No</label>' +
  973. '</fieldset>';
  974. }
  975. if(visitNumber == 2 || visitNumber == 3) {
  976. newHTML += '<fieldset data-role="controlgroup">' +
  977. '<legend>Got Samples:</legend>' +
  978. '<input type="radio" name="got_samples" id="got_samples-yes" value="yes" />' +
  979. '<label for="got_samples-yes">Yes</label>' +
  980. '<input type="radio" name="got_samples" id="got_samples-no" value="no" />' +
  981. '<label for="got_samples-no">No</label>' +
  982. '</fieldset>';
  983. }
  984. //All visits receive these
  985. newHTML += '<div class="ui-grid-a">' +
  986.  
  987. '<div class="ui-block-a">' +
  988. '<label for="appointment_date">Next Appointment Date:</label>' +
  989. '<input type="date" name="appointment_date" id="appointment_date" />' +
  990. '</div>' +
  991.  
  992. '<div class="ui-block-b">' +
  993. '<label for="appointment_time">Next Appointment Time:</label>' +
  994. '<input type="time" name="appointment_time" id="appointment_time" />' +
  995. '</div>' +
  996.  
  997. '</div>' +
  998.  
  999. '<fieldset data-role="controlgroup">' +
  1000. '<legend>Visit Shape:</legend>' +
  1001. '<input type="radio" name="visit_shape" id="sphere" value="Sphere" />' +
  1002. '<label for="sphere">Sphere</label>' +
  1003. '<input type="radio" name="visit_shape" id="cube" value="Cube" />' +
  1004. '<label for="cube">Cube</label>' +
  1005. '<input type="radio" name="visit_shape" id="pyramid" value="Pyramid" />' +
  1006. '<label for="pyramid">Pyramid</label>' +
  1007. '</fieldset>' +
  1008.  
  1009. '<fieldset data-role="controlgroup">' +
  1010. '<legend>Appointment Classification:</legend>' +
  1011. '<input type="radio" name="app_class" id="radio-hot" value="hot" />' +
  1012. '<label for="radio-hot">Hot</label>' +
  1013. '<input type="radio" name="app_class" id="radio-warm" value="warm" />' +
  1014. '<label for="radio-warm">Warm</label>' +
  1015. '<input type="radio" name="app_class" id="radio-cold" value="cold" />' +
  1016. '<label for="radio-cold">Cold</label>' +
  1017. '<input type="radio" name="app_class" id="radio-har" value="hit and run" />' +
  1018. '<label for="radio-har">Hit and Run</label>' +
  1019. '</fieldset>';
  1020.  
  1021. if(visitNumber >= 5) {
  1022. newHTML += '<fieldset data-role="controlgroup">' +
  1023. '<legend>Back Burner:</legend>' +
  1024. '<input type="radio" name="back_burner" id="bb-yes" value="yes" />' +
  1025. '<label for="bb-yes">Yes</label>' +
  1026. '<input type="radio" name="back_burner" id="bb-no" value="no" />' +
  1027. '<label for="bb-no">No</label>' +
  1028. '</fieldset>' +
  1029.  
  1030. '<fieldset data-role="controlgroup">' +
  1031. '<legend>Long Term Follow-Up:</legend>' +
  1032. '<input type="radio" name="follow_up" id="fu-three" value="3 Months" />' +
  1033. '<label for="fu-three">3 Months</label>' +
  1034. '<input type="radio" name="follow_up" id="fu-six" value="6 Months" />' +
  1035. '<label for="fu-six">6 Months</label>' +
  1036. '<input type="radio" name="follow_up" id="fu-nine" value="9 Months" />' +
  1037. '<label for="fu-nine">9 Months</label>' +
  1038. '</fieldset>';
  1039. }
  1040.  
  1041. newHTML += '<fieldset data-role="controlgroup">' +
  1042. '<label for="comments">Comments:</label>' +
  1043. '<textarea name="comments" id="comments"></textarea>' +
  1044. '</fieldset>' +
  1045. '<button type="submit" id="visitSubmit" data-theme="b" name="submit">Submit</button>'+
  1046. '</form>';
  1047. var $newcontent = $content.html(newHTML);
  1048. surveyCount++;
  1049.  
  1050. //If a new visit was already initialized we need to recreate the page for proper element enhancements
  1051. if(surveyCount > 1) $newcontent.trigger('create');
  1052.  
  1053. $.mobile.changePage($page, {transition: 'flip'});
  1054. visitSubmitController();
  1055. });
  1056. });
  1057.  
  1058. $('.visits').live('click', function() {
  1059. var leadsId = $('.ui-page-active').find('.id').val();
  1060. $.get('adminLeadsQuery.php?num=39&id='+leadsId, function(res) {
  1061. $page = $('#newVisit');
  1062. $content = $page.children(":jqmData(role=content)");
  1063. visitPageArray = res.split('|');
  1064. var $newcontent = $content.html(visitPageArray[0]+''+visitPageArray[1]);
  1065. surveyCount++;
  1066. visitPageRadioButtonController();
  1067. if(surveyCount > 1) $newcontent.trigger('create');
  1068.  
  1069. $.mobile.changePage($page, {transition: 'flip'});
  1070. $('.visitDiv:not([data-visit=1])').hide();
  1071. visitSubmitController();
  1072. visitTabController();
  1073.  
  1074. });
  1075. });
  1076.  
  1077. $('.new_leaf').live('click', function() {
  1078. var id = $('.ui-page-active').find('.id').val();
  1079. $.get('initialSurvey.php?id='+id, function(res) {
  1080. $page = $('#newVisit');
  1081. $content = $page.children(":jqmData(role=content)");
  1082. $page.children(":jqmData(role=header)").find('h3').html('Business Information Survey');
  1083. var $newcontent = $content.html(res);
  1084. surveyCount++;
  1085. if(surveyCount > 1) $newcontent.trigger('create');
  1086. $.mobile.changePage($page, {transition: 'flip'});
  1087.  
  1088. $('#surveySubmit').one('click', function() {
  1089. var $formData = $('#surveyForm').serialize();
  1090. $.mobile.loading('show');
  1091. $.post('adminLeadsQuery.php', $formData, function(res) {
  1092. console.log(res);
  1093. history.back();
  1094. $.mobile.loading('hide');
  1095. });
  1096. return false;
  1097. });
  1098. $('.buy_group_yes').live('change', function() {
  1099. $('#bg_form').css('display', 'block');
  1100. });
  1101. $('.buy_group_no').live('change', function() {
  1102. $('#bg_form').css('display', 'none');
  1103. });
  1104. });
  1105. });
  1106.  
  1107. $('.new_leaf_edit').live('click', function() {
  1108. var id = $('#singleLead').find('.id').val();
  1109. var name = $('#singleLead').find('.name').val();
  1110. $.get('adminLeadsQuery.php?num=15&id='+id, function(res) {
  1111. $page = $('#newVisit');
  1112. $content = $page.children(":jqmData(role=content)");
  1113. $page.children(":jqmData(role=header)").find('h3').html('Business Information Survey');
  1114. var $newcontent = $content.html(res);
  1115. surveyCount++;
  1116. if(surveyCount > 1) $newcontent.trigger('create');
  1117. $.mobile.changePage($page, {transition: 'flip'});
  1118. $('#editableSurvey>*').bind('change', function() {
  1119. $.get('adminLeadsQuery.php?num=16&id='+id+'&name='+$(this).attr('name')+'&val='+$(this).val(), function(res) {
  1120. alert('Edit Successful!');
  1121. });
  1122. });
  1123. });
  1124. });
  1125.  
  1126. $('.focusClick').live('click', function() {
  1127. var id = $(this).attr('id-to-add');
  1128. console.log(id);
  1129. $('#focusId').val(id);
  1130. console.log($('#focusId').val());
  1131. });
  1132.  
  1133. $('#addToFocusGroup').live('click', function() {
  1134. var id = $('#popupFocus').find('#focusId').val();
  1135. console.log('Registered, ID:'+id);
  1136. $.get('adminLeadsQuery.php?num=19&lead_id='+id, function(res) {
  1137. $.get('adminLeadsQuery.php?num=2', showContent);
  1138. });
  1139. });
  1140.  
  1141. $('.focusClickRemove').live('click', function() {
  1142. var id = $(this).attr('id-to-remove');
  1143. console.log(id);
  1144. $('#focusIdRem').val(id);
  1145. console.log($('#focusIdRem').val());
  1146. });
  1147.  
  1148. $('#remFromFocusGroup').live('click', function() {
  1149. var id = $('#popupFocusRemove').find('#focusIdRem').val();
  1150. console.log('Registered, ID:'+id);
  1151. $.get('adminLeadsQuery.php?num=21&lead_id='+id, function(res) {
  1152. $.get('adminLeadsQuery.php?num=2', showContent);
  1153. });
  1154. });
  1155. $('#remFromLeads').live('click', function() {
  1156. var id = $('#popupFocus').find('#focusId').val();
  1157. console.log('Registered, ID:'+id);
  1158. confirm("Are you sure you want to delete this lead?", function(r) {
  1159. if(r == true) {
  1160. $.get('adminLeadsQuery.php?num=38&lead_id='+id, function(res) {
  1161. $.get('adminLeadsQuery.php?num=2', showContent);
  1162. });
  1163. }
  1164. });
  1165. });
  1166. //$.mobile.changePage($('#leadsPage'), {transition: "flow"});
  1167. // setTimeout(function() {
  1168. // $.mobile.loading('hide');
  1169. // }, 8000);
  1170. }
  1171.  
  1172. function visitPageRadioButtonController() {
  1173. switch($('#bossContactRadio').data('val')) {
  1174. case 'yes':
  1175. $('#dec-yes').prop('checked', true);
  1176. break;
  1177. case 'no':
  1178. $('#dec-no').prop('checked', true);
  1179. break;
  1180. case 'reschedule':
  1181. $('#dec-reschedule').prop('checked', true);
  1182. }
  1183. switch($('#orderedRadio').data('val')) {
  1184. case 'yes':
  1185. $('#application-yes').prop('checked', true);
  1186. break;
  1187. case 'no':
  1188. $('#application-no').prop('checked', true);
  1189. }
  1190. switch($('#gotSamplesRadio').data('val')) {
  1191. case 'yes':
  1192. $('#got_samples-yes').prop('checked', true);
  1193. break;
  1194. case 'no':
  1195. $('#got_samples-no').prop('checked', true);
  1196. }
  1197. switch($('#visitShapeRadio').data('val')) {
  1198. case 'Sphere':
  1199. $('#sphere').prop('checked', true);
  1200. break;
  1201. case 'Cube':
  1202. $('#cube').prop('checked', true);
  1203. break;
  1204. case 'Pyramid':
  1205. $('#pyramid').prop('checked', true);
  1206. }
  1207. switch($('#appClassRadio').data('val')) {
  1208. case 'hot':
  1209. $('#radio-hot').prop('checked', true);
  1210. break;
  1211. case 'warm':
  1212. $('#radio-warm').prop('checked', true);
  1213. break;
  1214. case 'cold':
  1215. $('#radio-cold').prop('checked', true);
  1216. }
  1217. switch($('#backBurnerRadio').data('val')) {
  1218. case 'yes':
  1219. $('bb-yes').prop('checked', true);
  1220. break;
  1221. case 'no':
  1222. $('#bb-no').prop('checked', true);
  1223. }
  1224. switch($('#followUpRadio').data('val')) {
  1225. case '3 Months':
  1226. $('#fu-three').prop('checked', true);
  1227. break;
  1228. case '6 Months':
  1229. $('#fu-six').prop('checked', true);
  1230. break;
  1231. case '9 Months':
  1232. $('#fu-nine').prop('checked', true);
  1233. }
  1234. }
  1235.  
  1236. function visitTabController() {
  1237. $('.visit-tab').unbind('click');
  1238. $('.visit-tab').one('click', function() {
  1239. $this = $(this);
  1240. $('.visit-tab').removeClass('ui-btn-active');
  1241. $this.addClass('ui-btn-active');
  1242. // $('.visitDiv:not([data-visit='+$this.data('visit')+'])').hide();
  1243. // $('.visitDiv[data-visit='+$this.data('visit')+']').show();
  1244. var content = $('#visitPageAppendDiv').html(visitPageArray[$this.data('visit')]);
  1245. visitPageRadioButtonController();
  1246. content.trigger('create');
  1247. visitTabController();
  1248. });
  1249. }
  1250.  
  1251. function visitSubmitController() {
  1252. $('.visitSubmit').unbind('click');
  1253. $('#visitSubmit').one('click', function() {
  1254. var $formData = $('#visitForm').serialize();
  1255. $.mobile.loading('show');
  1256. $.post('adminLeadsQuery.php', $formData, function(res) {
  1257. console.log(res);
  1258. history.back();
  1259. $.mobile.loading('hide');
  1260. });
  1261. return false;
  1262. visitSubmitController();
  1263. });
  1264. }
  1265.  
  1266. function searchComplete(res) {
  1267. $.mobile.loading('hide');
  1268.  
  1269. //Parse result into a JSON object
  1270. var obj = JSON.parse(res);
  1271. var element = obj.resultsFound[0];
  1272.  
  1273. console.log(obj.resultsFound);
  1274. if(obj.resultsFound.length == 1) {
  1275. if(element.assigned == "") (element.lead==1) ? element.assigned = "noone yet, get in there!" : element.assigned = "House Account";
  1276. $('#leads_list').append('<li class="deletable_list"><h3>'+element.name+'</h3><p> Assigned to '+element.assigned+'</p></li>');
  1277. $('#leads_list').listview('refresh');
  1278. }
  1279. else if(obj.resultsFound.length == 0) {
  1280. $('#leads_list').append('<li class="deletable_list"><center><strong>No results... Please check your spelling.</strong></center></li>');
  1281. $('#leads_list').listview('refresh');
  1282. }
  1283. else {
  1284. $('#leads_list').append('<li class="deletable_list"><center><strong>You have more than one result. Please be more specific.</strong></center></li>');
  1285. //obj.resultsFound.forEach(displayArrayElements);
  1286. }
  1287. }
  1288.  
  1289. function appendNavBar() {
  1290. $(document).bind('pagebeforechange', function(e, data) {
  1291. if(typeof data.toPage != 'string') {
  1292. if($.inArray(data.toPage.selector, enhancedNavs) == -1) {
  1293. var str = '<div data-role="footer" data-theme="b" data-position="fixed">' +
  1294. '<div data-role="navbar">' +
  1295. '<ul>' +
  1296. '<li><a href="" data-role="button" data-theme="b" data-transition="flow" data-icon="map-marker" class="marker">View on Map</a></li>' +
  1297. '<li><a href="" data-role="button" data-theme="b" data-transition="flow" data-icon="road" class="getdir">Get Directions</a></li>' +
  1298. '<li><a href="" data-role="button" data-theme="b" data-transition="flow" data-icon="faplus" class="newvisit">New Visit</a></li>' +
  1299. '<li><a href="" data-role="button" data-theme="b" data-transition="flow" data-icon="calendar" class="visits">Visits</a></li>' +
  1300. '</ul>' +
  1301. '</div>' +
  1302. '</div>';
  1303. data.toPage.append(str);
  1304. data.toPage.find(':jqmData(role=navbar)').navbar();
  1305. enhancedNavs.push(data.toPage.selector);
  1306. }
  1307. $(document).unbind('pagebeforechange');
  1308. }
  1309. });
  1310. }
  1311.  
  1312. function routeLogged(res) {
  1313. res = res.split(',');
  1314. console.log(res);
  1315. if(res[2] == "true") routeID = res[1];
  1316. console.log(routeID);
  1317. $('#dirres').html('<br>'+res[0]+'<br>');
  1318. }
  1319.  
  1320. function getDirections(place) {
  1321. if(typeof request == 'undefined'){
  1322. basicRequest(place);
  1323. }
  1324. else {
  1325. request.optimizeWaypoints = true;
  1326. $('.newRoute').one('click', function() {
  1327. console.log(place);
  1328. basicRequest(place);
  1329. $( "#popupDialog" ).popup( "close" );
  1330. });
  1331. $('.addCurrent').one('click', function() {
  1332. if(request.destination == usahPos && request.waypoints.length > 0) {
  1333. request.destination = request.waypoints[request.waypoints.length-1].location;
  1334. directionsOrderedNames.pop()
  1335. }
  1336. if(!request.waypoints) request.waypoints = [];
  1337. request.waypoints.push({
  1338. location:request.destination,
  1339. stopover:true
  1340. });
  1341. request.destination = place;
  1342. directionsService.route(request, function(result, status) {
  1343. directionsCallback(result, status);
  1344. });
  1345. $( "#popupDialog" ).popup( "close" );
  1346. });
  1347. $( "#popupDialog" ).popup( "open" );
  1348. }
  1349. }
  1350.  
  1351. function basicRequest(dest, wps) {
  1352. request = {
  1353. origin: GeoMarker.getPosition(),
  1354. destination: dest,
  1355. travelMode: google.maps.TravelMode.DRIVING
  1356. };
  1357. if(wps) {
  1358. request.waypoints = wps;
  1359. request.optimizeWaypoints = true;
  1360. }
  1361. console.log(request);
  1362. directionsService.route(request, function(result, status) {
  1363. directionsCallback(result, status);
  1364. });
  1365. }
  1366.  
  1367. function startRouteRequest(origin, dest) {
  1368. request = {
  1369. origin: origin,
  1370. destination: dest,
  1371. travelMode: google.maps.TravelMode.DRIVING
  1372. }
  1373. console.log(request);
  1374. directionsService.route(request, function(result, status) {
  1375. startDirectionsCallback(result, status);
  1376. });
  1377. }
  1378.  
  1379. function startDirectionsCallback(result, status) {
  1380. if (status == google.maps.DirectionsStatus.OK) {
  1381. directionsDisplay.setDirections(result);
  1382. $('#dirbutton').show();
  1383. }
  1384. }
  1385.  
  1386. function directionsCallback(result, status) {
  1387. if (status == google.maps.DirectionsStatus.OK) {
  1388.  
  1389. var totalDistance = 0;
  1390. var totalDuration = 0;
  1391. document.getElementById("dirres").innerHTML = '<br><input id="add-route" type="button" value="Add to Routes"><br>';
  1392. directionsDisplay.setDirections(result);
  1393. console.log(result)
  1394. console.log(directionsOrderedNames);
  1395. var legs = result.routes[0].legs;
  1396. leg = result.routes[0].legs[0];
  1397. directionsOrderedNames = nameCompare(result.routes[0].waypoint_order);
  1398. console.log(directionsOrderedNames);
  1399. for(var i = 0; i < legs.length; i++) {
  1400. totalDistance += legs[i].distance.value;
  1401. totalDuration += legs[i].duration.value + AVERAGE_TIME_AT_STOP;
  1402. }
  1403. totalDistance = Number(totalDistance * MILES_IN_METER).toFixed(1) + " mi";
  1404. totalDuration = parseInt( totalDuration / 3600 ) % 24 + " hours, " + parseInt( totalDuration / 60 ) % 60 + " mins";
  1405. console.log(totalDistance);
  1406. console.log(totalDuration);
  1407. $('#add-route').unbind('click')
  1408. $('#add-route').bind('click', function() {
  1409. $.get('updateDistance.php?num=2&pending=true&distance='+totalDistance+'&duration='+totalDuration+'&start_address='+legs[0].start_address+'&end_address='+legs[legs.length-1].end_address+'&start_location='+legs[0].start_location.lat()+','+legs[0].start_location.lng()+'&end_location='+legs[legs.length-1].end_location.lat()+','+legs[legs.length-1].end_location.lng(), routeLogged);
  1410. //Wait to make sure routeID is set in routeLogged function
  1411. setTimeout(function() {
  1412. if(legs.length > 1) {
  1413. var i = 0;
  1414. for(var c = 0; c < legs.length; c++) {
  1415. setTimeout(function() {
  1416. console.log(legs)
  1417. console.log(i);
  1418. $.get('updateDistance.php?num=3&routeId='+routeID+'&distance='+legs[i].distance.text+'&duration='+legs[i].duration.text+'&start_address='+legs[i].start_address+'&end_address='+legs[i].end_address+'&origin_name='+directionsOrderedNames[i]+'&destination_name='+directionsOrderedNames[i+1]+'&start_location='+legs[i].start_location.lat()+','+legs[i].start_location.lng()+'&end_location='+legs[i].end_location.lat()+','+legs[i].end_location.lng());
  1419. i++;
  1420. }, c*100);
  1421. }
  1422. }
  1423. else {
  1424. $.get('updateDistance.php?num=3&routeId='+routeID+'&distance='+legs[0].distance.text+'&duration='+legs[0].duration.text+'&start_address='+legs[0].start_address+'&end_address='+legs[0].end_address+'&origin_name='+directionsOrderedNames[0]+'&destination_name='+directionsOrderedNames[1]+'&start_location='+legs[0].start_location.lat()+','+legs[0].start_location.lng()+'&end_location='+legs[0].end_location.lat()+','+legs[0].end_location.lng());
  1425. }
  1426. }, 2000);
  1427. });
  1428. $('#dirbutton').show();
  1429. initCustomers();
  1430. initLeads();
  1431. }
  1432. }
  1433.  
  1434. function singleLocationPageTransition(id, placeName) {
  1435. $.get('adminLeadsQuery.php?num=10&lead_id='+id, function(res) {
  1436. var $page = $('#singleLead');
  1437. $page.children( ":jqmData(role=header)" ).find('h3').html(placeName);
  1438.  
  1439. // Get the content area element for the page.
  1440. var $content = $page.children( ":jqmData(role=content)" );
  1441.  
  1442. var $newcontent = $content.html(res);
  1443. //$page.find('input').addClass('ui-input-text ui-body-c ui-corner-all ui-shadow-inset');
  1444. //$page.find('textarea').addClass('ui-input-text ui-body-c ui-corner-all ui-shadow-inset');
  1445. //$page.find('fieldset').addClass('ui-corner-all ui-controlgroup ui-controlgroup-vertical');
  1446.  
  1447.  
  1448. var quality = $('#qualityRadio').data('selected');
  1449. var confirmed = $('#numberConfirmedRadio').data('selected');
  1450. var assigned = $('#assignedToRadio').data('selected');
  1451. console.log('Quality: '+quality+' Confirmed: '+confirmed+' Assigned To: '+assigned);
  1452. switch(quality) {
  1453. case 'Hot':
  1454. $('#qual-hot').prop('checked', true);
  1455. break;
  1456. case 'Warm':
  1457. $('#qual-warm').prop('checked', true);
  1458. break;
  1459. case 'Cold':
  1460. $('#qual-cold').prop('checked', true);
  1461. break;
  1462. case 'Back-Burner':
  1463. $('#qual-bb').prop('checked', true);
  1464. }
  1465. switch(confirmed) {
  1466. case 'Yes':
  1467. $('#num-yes').prop('checked', true);
  1468. break;
  1469. case 'No':
  1470. $('#num-no').prop('checked', true);
  1471. break;
  1472. case 'pending':
  1473. $('#num-pending').prop('checked', true);
  1474. }
  1475.  
  1476. $('#at-'+assigned).prop('checked', true);
  1477.  
  1478.  
  1479. $newcontent.trigger('create');
  1480. $.mobile.changePage($('#singleLead'), {transition : 'slideup'});
  1481. });
  1482. }
  1483.  
  1484. //Rearranges the company names after waypoints are optimized.
  1485. function nameCompare(correct) {
  1486. var tmp = [];
  1487. for(var i = 0; i < correct.length; i++) {
  1488. tmp[correct[i]] = directionsOrderedNames[i];
  1489. }
  1490. tmp[correct.length] = directionsOrderedNames[correct.length]; //destination
  1491. tmp.unshift('USA Hospitality');
  1492. return tmp;
  1493. }
  1494.  
  1495. function getVisitGoal(visit_num) {
  1496. var str = "";
  1497. switch(visit_num) {
  1498. case 1:
  1499. str = "To find out the names of the decision maker and current suppliers. Possibility of seeing the decision maker to schedule an appointment. Look for their personality shape and an ice-breaking product or conversation piece.";
  1500. break;
  1501. case 2:
  1502. str = "Use your knowledge of the personality shapes to start talking with the decision maker about his current products including packing information and weights. Also, try to get their product volumes and samples. Schedule an official quotation appointment.";
  1503. break;
  1504. case 3:
  1505. str = "Make a higher price quotation mixed with some below price products to attract customer to open current prices. Show them that if they compare apples to apples giving you a target price they will benefit from it. Blame on not getting samples. Explain about our company matching policy plus 2% off. Get prices and samples! Drop credit application.";
  1506. break;
  1507. case 4:
  1508. str = "Go over final quotation. Get first order commitment. Define Customer Shape.";
  1509. break;
  1510. case 5:
  1511. str = "Follow-up and first renegotiation - Customer had shared quote with current supplier and we need to make ourselves look more attractive. Talk about prices and services. Show differences using HB2B and collect new targets. Schedule next appointment or work new prices face-to-face.";
  1512. break;
  1513. case 6:
  1514. str = "Follow-up and second renegotiation - Use ice breaker, conversation piece and free demo. Try to keep the relationship warm by talking about savings using the right products.";
  1515. break;
  1516. }
  1517. return str;
  1518. }
  1519.  
  1520. function getNumberSuffix(num) {
  1521. switch(num) {
  1522. case 1:
  1523. return '1st';
  1524. case 2:
  1525. return '2nd';
  1526. case 3:
  1527. return '3rd';
  1528. default:
  1529. return String(num)+'th';
  1530. }
  1531. }
  1532.  
  1533. function renderGeocode(response) {
  1534. var length = response.results.length;
  1535. console.log(response);
  1536. //var str = '{\'locations[]\': [';
  1537. for (var i = 0; i < length; i++) {
  1538. var location = response.results[i].locations[0];
  1539. $.get('adminLeadsQuery.php?num=12&id=' + geocodeID[i] + '&location=' + location.latLng.lat + ',' + location.latLng.lng);
  1540. //str += '{id: "'+geocodeID[i]
  1541. console.log(geocodeID[i]);
  1542. //geocodeID.shift();
  1543. }
  1544. }
  1545.  
  1546. function getMarkerImage(string) {
  1547. switch(string) {
  1548. //Customer check
  1549. case '($1001 and up)':
  1550. return 'http://maps.google.com/mapfiles/marker_orangeA.png';
  1551. case '($1000 - $501)':
  1552. return 'http://maps.google.com/mapfiles/marker_yellowB.png';
  1553. case '($500 -$251)':
  1554. return 'http://maps.google.com/mapfiles/marker_brownC.png';
  1555. case '($250 - $176)':
  1556. return 'http://maps.google.com/mapfiles/marker_purpleD.png';
  1557. case '($175 - $126)':
  1558. return 'http://maps.google.com/mapfiles/marker_purpleE.png';
  1559. case '(less than $125)':
  1560. return 'http://maps.google.com/mapfiles/markerF.png';
  1561. case 'none':
  1562. return 'http://maps.google.com/mapfiles/marker_black.png';
  1563. //Lead check
  1564. case 'Pending':
  1565. case 'pending':
  1566. return 'http://maps.google.com/mapfiles/marker_blackL.png';
  1567. case 'Hot':
  1568. return 'http://maps.google.com/mapfiles/marker_yellowL.png';
  1569. case 'Warm':
  1570. return 'http://maps.google.com/mapfiles/markerL.png';
  1571. case 'Cold':
  1572. return 'http://maps.google.com/mapfiles/marker_purpleL.png';
  1573. case 'Back-Burner':
  1574. return 'http://maps.google.com/mapfiles/marker_brownL.png';
  1575. default:
  1576. return 'http://maps.google.com/mapfiles/marker_black.png';
  1577. }
  1578. }
  1579.  
  1580. function addMarkerClass(string, mark, days) {
  1581. switch(string) {
  1582. case '($1001 and up)':
  1583. mark.classification = 'A';
  1584. break;
  1585. case '($1000 - $501)':
  1586. mark.classification = 'B';
  1587. break;
  1588. case '($500 -$251)':
  1589. mark.classification = 'C';
  1590. break;
  1591. case '($250 - $176)':
  1592. mark.classification = 'D';
  1593. break;
  1594. case '($175 - $126)':
  1595. mark.classification = 'E';
  1596. break;
  1597. case '(less than $125)':
  1598. mark.classification = 'F';
  1599. break;
  1600. default:
  1601. mark.classification = 'Inactive';
  1602. break;
  1603. }
  1604. if(days > 7) mark.classification = 'Inactive';
  1605. }
  1606.  
  1607. function uploadPicture(returnPageString, callback) {
  1608. $.ajax({
  1609. type: "POST",
  1610. url: "http://www.usahospitality.com/old/maps/mobile/adminLeadsQuery.php?num=23",
  1611. data: {img: $('.myImage').attr('src').replace(/^data:image\/(png|jpg);base64,/, "")},
  1612. contentType: "application/x-www-form-urlencoded;charset=UTF-8",
  1613. success: function(data, textStatus, jqXHR){
  1614. callback(data);
  1615. $.mobile.loading('hide');
  1616. $.mobile.changePage($(returnPageString), {transition : 'slideup'});
  1617. },
  1618. error: function(jqXHR, textStatus, errorThrown) {
  1619. console.log(jqXHR);
  1620. console.log(textStatus);
  1621. console.log(errorThrown);
  1622. $.mobile.loading('hide');
  1623. alert('Upload failed. ' + errorThrown);
  1624. }
  1625. });
  1626. }
  1627.  
  1628. function appendCustomer(element, index, array) {
  1629. if(typeof element.total === 'undefined') element.total = 0;
  1630. $('#class'+element.classification).append('<li><a href="#" id="cust'+index+'">'+element.name+'<p class="ui-li-aside"><strong>Invoice Avg: $'+element.average+'<br>Total Sold: $'+element.total+'</strong></p></a></li>');
  1631. $('#cust'+index).bind('click', function() {
  1632. var $this = $(this);
  1633. $this.addClass('ui-btn-active');
  1634. google.maps.event.trigger(map, 'resize');
  1635. map.setZoom(15);
  1636. map.setCenter(element.position);
  1637. $.mobile.changePage($('#popupMap'), {reverse: true, transition: 'flip'});
  1638. setTimeout(function() {
  1639. $this.removeClass('ui-btn-active');
  1640. }, 2000);
  1641. var name = element.name;
  1642. if(typeof infoBubble === 'undefined' || infoBubble.name !== name) {
  1643. if(typeof infoBubble !== 'undefined') infoBubble.close();
  1644. infoBubble = new InfoBubble({
  1645. content: '<div style="background: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(112,112,112)),color-stop(0.51, rgb(94,94,94)),color-stop(0.52, rgb(57,57,57))); background: -moz-linear-gradient(center top,rgb(112,112,112) 0%,rgb(94,94,94) 51%,rgb(57,57,57) 52%);"><div id="placearrow" style="text-shadow: 0 -1px 0 #000; color: #fff; font-family: Helvetica Neue, Helvetica, arial; font-size: 18px; line-height: 25px; padding: 4px 15px 4px 15px; font-weight: bold;">' + name + '</div></div>',
  1646. shadowStyle: 1,
  1647. padding: 0,
  1648. backgroundColor: 'rgb(57,57,57)',
  1649. borderRadius: 4,
  1650. arrowSize: 10,
  1651. borderWidth: 1,
  1652. borderColor: '#2c2c2c',
  1653. disableAutoPan: true,
  1654. hideCloseButton: true,
  1655. arrowPosition: 30,
  1656. arrowStyle: 2,
  1657. enableEventPropagation: true,
  1658. name: name
  1659. });
  1660. infoBubble.open(map, element);
  1661. }
  1662. });
  1663.  
  1664. }
  1665.  
  1666. function classificationChange(string, num, classification) {
  1667. $.mobile.loading( 'show', {text: 'Generating Report', textVisible: true});
  1668. $('#popupCustOptions').popup('close');
  1669. customerInvoiceCutoff.string = string;
  1670. customerInvoiceCutoff.num = num;
  1671. $('#classTime').html(classification);
  1672. removeCustomers();
  1673. initCustomers();
  1674. setTimeout(function() {
  1675. console.log(people.customersArray);
  1676. people.customersArray.forEach(appendCustomer);
  1677. $('#classA, #classB, #classC, #classD, #classE, #classF, #classInactive').listview('refresh');
  1678. $.mobile.loading('hide');
  1679. }, 8000);
  1680. }
  1681.  
  1682. function appendLead(element, index, array) {
  1683. $('#class'+element.quality).append('<li><a href="#" id="lead'+index+'">'+element.name+'</a></li>');
  1684. $('#lead'+index).bind('click', function() {
  1685. var $this = $(this);
  1686. $this.addClass('ui-btn-active');
  1687. google.maps.event.trigger(map, 'resize');
  1688. map.setZoom(15);
  1689. map.setCenter(element.position);
  1690. $.mobile.changePage($('#popupMap'), {reverse: true, transition: 'flip'});
  1691. setTimeout(function() {
  1692. $this.removeClass('ui-btn-active');
  1693. }, 2000);
  1694. var name = element.name;
  1695. if(typeof infoBubble === 'undefined' || infoBubble.name !== name) {
  1696. if(typeof infoBubble !== 'undefined') infoBubble.close();
  1697. infoBubble = new InfoBubble({
  1698. content: '<div style="background: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(112,112,112)),color-stop(0.51, rgb(94,94,94)),color-stop(0.52, rgb(57,57,57))); background: -moz-linear-gradient(center top,rgb(112,112,112) 0%,rgb(94,94,94) 51%,rgb(57,57,57) 52%);"><div id="placearrow" style="text-shadow: 0 -1px 0 #000; color: #fff; font-family: Helvetica Neue, Helvetica, arial; font-size: 18px; line-height: 25px; padding: 4px 15px 4px 15px; font-weight: bold;">' + name + '</div></div>',
  1699. shadowStyle: 1,
  1700. padding: 0,
  1701. backgroundColor: 'rgb(57,57,57)',
  1702. borderRadius: 4,
  1703. arrowSize: 10,
  1704. borderWidth: 1,
  1705. borderColor: '#2c2c2c',
  1706. disableAutoPan: true,
  1707. hideCloseButton: true,
  1708. arrowPosition: 30,
  1709. arrowStyle: 2,
  1710. enableEventPropagation: true,
  1711. name: name
  1712. });
  1713. infoBubble.open(map, element);
  1714. }
  1715. });
  1716. }
  1717.  
  1718. function initLeads() {
  1719. console.log(people);
  1720. if(people.leadsSet == true) {
  1721. $('#displayleads').html('Show Leads');
  1722. if(people.clustersSet == true) markerCluster.removeMarkers(people.leadsArray);
  1723. for(var i = 0; i < people.leadsArray.length; i++) {
  1724. people.leadsArray[i].setVisible(false);
  1725. }
  1726. people.leadsSet = false;
  1727. }
  1728. else {
  1729. $('#displayleads').html('Hide Leads');
  1730. if(people.clustersSet == true) markerCluster.addMarkers(people.leadsArray);
  1731. for(var i = 0; i < people.leadsArray.length; i++) {
  1732. people.leadsArray[i].setVisible(true);
  1733. }
  1734. people.leadsSet = true;
  1735. }
  1736. }
  1737.  
  1738. function initCustomers() {
  1739. $.get('adminLeadsQuery.php?num=13', function(res) {
  1740. object = JSON.parse(res);
  1741. object = object.resultsFound;
  1742. if(people.customersSet == false) {
  1743. addCustomers(object);
  1744. $('#aButton, #bButton, #cButton, #dButton, #eButton, #fButton, #inactiveButton').addClass('ui-btn-active');
  1745. }
  1746. else {
  1747. removeCustomers();
  1748. }
  1749. });
  1750. }
  1751.  
  1752. function addCustomers(customers) {
  1753. $('#displaycust').html('Hide Customers');
  1754. for(var i = 0; i < customers.length; i++) {
  1755. $.get('adminLeadsQuery.php?num=14&customer_id='+customers[i].cust_id+'&pos='+customers[i].location+'&name='+customers[i].name+'&cutoff='+customerInvoiceCutoff.string+'&cnum='+customerInvoiceCutoff.num, function(result) {
  1756. var c = JSON.parse(result);
  1757. var str = getMarkerImage(c.classification);
  1758. var newMark = c.pos.split(",");
  1759. var image = new google.maps.MarkerImage(str,
  1760. new google.maps.Size(20, 34),
  1761. new google.maps.Point(0, 0),
  1762. new google.maps.Point(10, 34)
  1763. );
  1764. var mark = new google.maps.Marker({
  1765. map: map,
  1766. position: new google.maps.LatLng(newMark[0], newMark[1]),
  1767. icon: image,
  1768. animation: google.maps.Animation.DROP,
  1769. name: c.placeName,
  1770. cust_id: c.cust_id,
  1771. total: c.total,
  1772. average: Number(c.average).toFixed(2)
  1773. //shadow: ' http://maps.google.com/intl/en_us/mapfiles/ms/micons/msmarker.shadow.png'
  1774. });
  1775. addMarkerClass(c.classification, mark, c.diff);
  1776. people.customersArray.push(mark);
  1777. if(people.clustersSet == true) markerCluster.addMarker(mark);
  1778. google.maps.event.addListener(mark, 'click', function() {
  1779. var name = this.name;
  1780. if(typeof infoBubble === 'undefined' || infoBubble.name !== name) {
  1781. if(typeof infoBubble !== 'undefined') infoBubble.close();
  1782. infoBubble = new InfoBubble({
  1783. content: '<div style="background: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgb(112,112,112)),color-stop(0.51, rgb(94,94,94)),color-stop(0.52, rgb(57,57,57))); background: -moz-linear-gradient(center top,rgb(112,112,112) 0%,rgb(94,94,94) 51%,rgb(57,57,57) 52%);"><div id="placearrow" style="text-shadow: 0 -1px 0 #000; color: #fff; font-family: Helvetica Neue, Helvetica, arial; font-size: 18px; line-height: 25px; padding: 4px 15px 4px 15px; font-weight: bold;">' + name + '</div></div>',
  1784. shadowStyle: 1,
  1785. padding: 0,
  1786. backgroundColor: 'rgb(57,57,57)',
  1787. borderRadius: 4,
  1788. arrowSize: 10,
  1789. borderWidth: 1,
  1790. borderColor: '#2c2c2c',
  1791. disableAutoPan: true,
  1792. hideCloseButton: true,
  1793. arrowPosition: 30,
  1794. arrowStyle: 2,
  1795. enableEventPropagation: true,
  1796. name: name
  1797. });
  1798. infoBubble.open(map, mark);
  1799. }
  1800. else {
  1801. infoBubble.close();
  1802. infoBubble = undefined;
  1803. console.log(this.cust_id);
  1804. var cust_id = this.cust_id;
  1805. $.get('adminLeadsQuery.php?num=17&cust_id='+cust_id, function(res) {
  1806. console.log(res);
  1807. var $page = $('#singleCustomer');
  1808. $page.children( ":jqmData(role=header)" ).find('h3').html(name);
  1809.  
  1810. // Get the content area element for the page.
  1811. var $content = $page.children( ":jqmData(role=content)" );
  1812.  
  1813. var $newcontent = $content.html(res);
  1814.  
  1815. $newcontent.trigger('create');
  1816. $.mobile.changePage($('#singleCustomer'), {transition : 'slideup'});
  1817. $('#newShippingAddress').bind('click', function() {
  1818. $.mobile.changePage($('#popupMap'), {transition : 'slideup', reverse: 'true'});
  1819. alert('Click on the map to add a mark.');
  1820. var clickListener = google.maps.event.addListener(map, 'click', function(event) {
  1821. console.log(event);
  1822. var addressMark = new google.maps.Marker({
  1823. position: event.latLng,
  1824. map: map
  1825. });
  1826. $('#popupAddress').popup('open');
  1827. $('.cancel').bind('click', function() {
  1828. $('#popupAddress').popup('close');
  1829. });
  1830. $('.confirm').bind('click', function() {
  1831. $('#popupAddress').popup('close');
  1832.  
  1833. google.maps.event.removeListener(clickListener);
  1834. geocoder.geocode({'latLng': addressMark.position}, function(results, status) {
  1835. if(status == google.maps.GeocoderStatus.OK) {
  1836. if (results[1]) {
  1837. console.log(results[0].formatted_address);
  1838. console.log(results);
  1839. }
  1840. }
  1841. else {
  1842. alert("Geocoder failed due to: " + status);
  1843. }
  1844. });
  1845. $.mobile.loading( 'show', {text: 'Uploading Image...', textVisible: true});
  1846. uploadPicture('#singleCustomer', function(data) {
  1847. console.log(data);
  1848. });
  1849. });
  1850. });
  1851. });
  1852. });
  1853. }
  1854. });
  1855. });
  1856. }
  1857. people.customersSet = true;
  1858. }
  1859.  
  1860. function removeCustomers() {
  1861. $('#displaycust').html('Show Customers');
  1862. if(people.clustersSet == true) markerCluster.removeMarkers(people.customersArray);
  1863. for(var i = 0; i < people.customersArray.length; i++) {
  1864. people.customersArray[i].setVisible(false);
  1865. }
  1866. people.customersArray = [];
  1867. people.customersSet = false;
  1868. $('#classA, #classB, #classC, #classD, #classE, #classF, #classInactive').html('');
  1869. $('#aButton, #bButton, #cButton, #dButton, #eButton, #fButton, #inactiveButton').removeClass('ui-btn-active');
  1870. }
  1871.  
  1872. function initDrawer() {
  1873. //Google Drawing Manager
  1874. drawingManager = new google.maps.drawing.DrawingManager({
  1875. drawingMode: null,
  1876. drawingControl: true,
  1877. drawingControlOptions: {
  1878. position: google.maps.ControlPosition.TOP_CENTER,
  1879. drawingModes: [
  1880. google.maps.drawing.OverlayType.POLYGON
  1881. ]
  1882. },
  1883. polygonOptions: {
  1884. fillColor: '#2861a4',
  1885. fillOpacity: 0.2,
  1886. strokeWeight: 3,
  1887. clickable: true,
  1888. zIndex: 1
  1889. }
  1890. });
  1891. drawingManager.setMap(map);
  1892.  
  1893. google.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
  1894. // Switch back to non-drawing mode after drawing a shape.
  1895. drawingManager.setDrawingMode(null);
  1896.  
  1897. var newPolygon = event.overlay;
  1898. newPolygon.type = event.type;
  1899. newPolygon.setVisible(false);
  1900.  
  1901. _places = new PolygonContainedPlaces(newPolygon);
  1902.  
  1903. if(people.leadsSet == true) {
  1904. people.leadsArray.forEach(polygonCompare);
  1905. }
  1906. if(people.customersSet == true) {
  1907. people.customersArray.forEach(polygonCompare);
  1908. }
  1909. _places.displayList();
  1910. //Need to call this instead of directly calling _places.add to get the correct 'this' object
  1911. function polygonCompare(element, index, array) {
  1912. _places.add(element);
  1913. }
  1914. $('.newRouteAlt').one('click', function() {
  1915. var $formData = $('#placesList').val();
  1916. console.log($formData);
  1917. for(var i = 0; i < $formData.length; i++) {
  1918. $formData[i] = $formData[i].split('|');
  1919. var newMark = $formData[i][1].substring(1,$formData[i][1].length-2).split(",");
  1920. $formData[i][1] = new google.maps.LatLng(newMark[0], newMark[1]);
  1921. }
  1922. if($formData.length > 10) {
  1923. alert('You can\'t have more than 10 places in a route.');
  1924. }
  1925. else {
  1926. $( "#popupPlaces" ).popup( "close" );
  1927. _places.getDirections($formData, true);
  1928. }
  1929. });
  1930. $('.addCurrentAlt').one('click', function() {
  1931. if(typeof request != 'undefined') {
  1932. var $formData = $('#placesList').val();
  1933. console.log($formData);
  1934. for(var i = 0; i < $formData.length; i++) {
  1935. $formData[i] = $formData[i].split('|');
  1936. var newMark = $formData[i][1].substring(1,$formData[i][1].length-2).split(",");
  1937. $formData[i][1] = new google.maps.LatLng(newMark[0], newMark[1]);
  1938. }
  1939. console.log($formData);
  1940. if($formData.length > 10) {
  1941. alert('You can\'t have more than 10 places in a route.');
  1942. }
  1943. else {
  1944. $( "#popupPlaces" ).popup( "close" );
  1945. _places.getDirections($formData);
  1946. }
  1947. }
  1948. else alert('There is no existing route!');
  1949. });
  1950. $('#popupPlaces').bind('popupafterclose', function(event, ui) { _places.clearList(); });
  1951. });
  1952. }
  1953.  
  1954. function trackGeoMarker() {
  1955. google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
  1956. map.setCenter(this.getPosition());
  1957. map.setZoom(10);
  1958. });
  1959.  
  1960. var minimumDistanceTraveled = 30;
  1961. var maxOffset = 300;
  1962. if( /Android|webOS|BlackBerry/i.test(navigator.userAgent) ) {
  1963. minimumDistanceTraveled = 70;
  1964. maxOffset = 15;
  1965. }
  1966. google.maps.event.addListener(GeoMarker, 'position_changed', function() {
  1967. var path = poly.getPath();
  1968. if(path.length <= 1) path.push(this.getPosition());
  1969. if(path.length > 1 && this.accuracy < maxOffset) {
  1970. if(typeof(_geofence) != 'undefined') {
  1971. _geofence.perimeterCrossed(function(crossed) {
  1972. if(crossed == true) {
  1973. if(_geofence.withinRadius == true) {
  1974. if(_geofence.nearbyLocations.length == 0) {
  1975. window.plugins.localNotification.addNotification({
  1976. fireDate : Math.round(new Date().getTime()/1000 + 1),
  1977. alertBody : "You have reached your destination.",
  1978. soundName: "beep.caf",
  1979. badge: 1,
  1980. hasAction: true,
  1981. notificationId: 123
  1982. });
  1983. if(_geofence.id != waypoints.length-1) {
  1984. setTimeout(function() {
  1985. navigator.notification.confirm('You have reached your destination. Would you like to submit a visit?', function(buttonIndex) {
  1986. alert(buttonIndex);
  1987. }, 'USAHLS', 'Yes,No');
  1988. }, 5000);
  1989. setTimeout(function() {
  1990. alert('Now tracking.');
  1991. GeoMarker.setMap(null);
  1992. GeoMarker = new GeolocationMarker(map);
  1993. GeoMarker.setCircleOptions({fillColor: '#808080'});
  1994. trackGeoMarker();
  1995. }, AVERAGE_TIME_AT_STOP * 0.75);
  1996. }
  1997. else {
  1998. //Submit arrival time. Move route to completed. Clear directionsResult object.
  1999. }
  2000. }
  2001. else {
  2002. window.plugins.localNotification.addNotification({
  2003. fireDate : Math.round(new Date().getTime()/1000 + 1),
  2004. alertBody : "You have reached your destination. There are several locations nearby.",
  2005. soundName: "beep.caf",
  2006. badge: 1,
  2007. hasAction: true,
  2008. notificationId: 123
  2009. });
  2010. }
  2011. }
  2012. else if(_geofence.id != waypoints.length-1){
  2013. window.plugins.localNotification.addNotification({
  2014. fireDate : Math.round(new Date().getTime()/1000 + 1),
  2015. alertBody : "You are leaving your previous destination, now starting next step of route. Launch the application to cancel.",
  2016. soundName: "beep.caf",
  2017. badge: 1,
  2018. hasAction: true,
  2019. notificationId: 123
  2020. });
  2021. var oldGeofence = nextRouteStep();
  2022. setTimeout(function() {
  2023. navigator.notification.confirm('Would you like to cancel starting the next step of your route? You can always start it manually from the route page.', function(buttonIndex) {
  2024. if(buttonIndex == 1) _geofence = oldGeofence;
  2025. }, 'USAHLS', 'Yes,No');
  2026. }, 5000);
  2027. }
  2028. }
  2029. });
  2030. }
  2031. var tmpdistance = google.maps.geometry.spherical.computeDistanceBetween(path.getAt(path.length-1), this.getPosition()); //in meters
  2032. if(tmpdistance > minimumDistanceTraveled) {
  2033. path.push(this.getPosition());
  2034. distance = Number(distance) + Number((tmpdistance*MILES_IN_METER).toFixed(2));
  2035. $.get('updateDistance.php?num=1&route_id='+routeID+'&location='+this.getPosition());
  2036. }
  2037. }
  2038. });
  2039.  
  2040. google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
  2041. console.log('There was an error obtaining your position. Message: ' + e.message);
  2042. if(e.code == 3) {
  2043. window.plugins.localNotification.addNotification({
  2044. fireDate : Math.round(new Date().getTime()/1000 + 1),
  2045. alertBody : "Location tracking has timed out.",
  2046. soundName: "beep.caf",
  2047. badge: 1,
  2048. hasAction: true,
  2049. notificationId: 123,
  2050. callback : function() {
  2051. navigator.notification.confirm('Would you like to submit a visit?', confirmCallback, 'USAHLS', 'Yes,No');
  2052. }
  2053. });
  2054. alert('Timeout');
  2055. }
  2056. else if(e.code == 2) {
  2057. window.plugins.localNotification.addNotification({
  2058. fireDate : Math.round(new Date().getTime()/1000 + 1),
  2059. alertBody : "You seem to have lost your internet connection. Please push the refresh button after restoring your connection.",
  2060. soundName: "beep.caf",
  2061. badge: 1,
  2062. hasAction: true,
  2063. notificationId: 123,
  2064. callback : function() {
  2065. navigator.notification.confirm('Would you like to submit a visit?', confirmCallback, 'USAHLS', 'Yes,No');
  2066. }
  2067. });
  2068. alert('Connection lost.');
  2069. }
  2070. else if(e.code == 1) {
  2071. alert('You need to enable location services for this application. Please go to Settings -> Privacy -> Location Services');
  2072. }
  2073. });
  2074.  
  2075. }
  2076.  
  2077. function success(resultArray) {
  2078. $('#sku').val(resultArray[0]);
  2079. $.mobile.changePage('#popupScanner', {transition: "flip"});
  2080. //alert("Scanned " + resultArray[0] + " code: " + resultArray[1]);
  2081. // NOTE: Scandit SDK Phonegap Plugin Versions 1.* for iOS report
  2082. // the scanning result as a concatenated string.
  2083. // Starting with version 2.0.0, the Scandit SDK Phonegap
  2084. // Plugin for iOS reports the result as an array
  2085. // identical to the way the Scandit SDK plugin for Android reports results.
  2086.  
  2087. // If you are running the Scandit SDK Phonegap Plugin Version 1.* for iOS,
  2088. // use the following approach to generate a result array from the string result returned:
  2089. // resultArray = result.split("|");
  2090. }
  2091.  
  2092. function failure(error) {
  2093. alert("Failed: " + error);
  2094. }
  2095.  
  2096. function scan() {
  2097. // See below for all available options.
  2098. cordova.exec(success, failure, "ScanditSDK", "scan",
  2099. ["NpxxYMStEeKE4rWWVSgp67A/sPxP65D8wyqTRP2Wpq0",
  2100. {"beep": true,
  2101. "1DScanning" : true,
  2102. "2DScanning" : true,
  2103. "toolBarButtonCaption" : "Done",
  2104. "textForMostLikelyBarcodeUIElement": "Tap to use"}]);
  2105. }
  2106.  
  2107. function nextRouteStep() {
  2108. $.mobile.changePage('#popupMap', {reverse: true});
  2109. var tmp = _geofence;
  2110. var id = _geofence.id+1;
  2111. $('#routeContentInProgress').find('li:first').remove();
  2112. $('#routeContentInProgress').find("li:first").attr('data-theme', 'b');
  2113. $('#routeContentInProgress').listview('refresh');
  2114. var origin = waypoints[id].origin.split(',');
  2115. origin = new google.maps.LatLng(origin[0], origin[1]);
  2116. var dest = waypoints[id].destination.split(',');
  2117. dest = new google.maps.LatLng(dest[0], dest[1]);
  2118. startRouteRequest(origin, dest);
  2119. _geofence = new GeoFence(id, dest, waypoints[id].destination_name);
  2120. console.log(_geofence);
  2121. return tmp;
  2122. }
  2123.  
  2124. function identifyItem(invoice, itemNum, shouldContinue, appendType, shouldPrint) {
  2125. $('.itemPageContent').fadeOut(1000, function() {
  2126. $('.itemPageContent').html('<span class="redFont">Use the search bar to identify item.<br>Ex: "GEN800"</span>').fadeIn(1000);
  2127. var c = $('#itemPageProductList, form[role="search"]').show();
  2128. console.log(c);
  2129. });
  2130. $('input[data-type="search"]').change(function() {
  2131. console.log($(this).val());
  2132. if ($(this).val() === '' || $(this).val().length <= 3) {
  2133. $('#itemPageProductList li').remove();
  2134. } else {
  2135. $.get('adminLeadsQuery.php?num=34&string='+$(this).val(), function(res) {
  2136. $('#itemPageProductList').append(res).listview('refresh');
  2137. $('#itemPageProductList li').bind('click', function() {
  2138. invoice.items[itemNum].pid = $(this).data('productId');
  2139. invoice.items[itemNum].name = $(this).data('name');
  2140. invoice.items[itemNum].barcode = $(this).data('barcode');
  2141. $('.itemPageContent').before('<strong>'+invoice.items[itemNum].name+'</strong>');
  2142. $('#itemPageProductList').remove();
  2143. appendItemPageContent(invoice, itemNum, invoice.items[itemNum].barcode, location, shouldContinue, appendType);
  2144. if(shouldPrint) {
  2145. $.get('barcode.php?str='+invoice.items[itemNum].pid, function(res) {
  2146. window.plugin.print(res);
  2147. });
  2148. }
  2149. });
  2150. });
  2151. }
  2152. });
  2153. $.mobile.loading('hide');
  2154. }
  2155.  
  2156. function addNewInventory(invoice, itemNum, shouldContinue, appendType) {
  2157. var $content = $('#itemPage').children( ":jqmData(role=content)" );
  2158. Device.barcodeData = function (data, bar_type){
  2159. if(typeof invoice.location == 'undefined') {
  2160. confirm("Location: "+data+". Is this correct?", function(r) {
  2161. if(r == true) {
  2162. scanInventoryAddItem(invoice, itemNum, shouldContinue, appendType, data);
  2163. }
  2164. });
  2165. }
  2166. else {
  2167. if(invoice.location == data) {
  2168. scanInventoryAddItem(invoice, itemNum, shouldContinue, appendType, data);
  2169. }
  2170. else {
  2171. $('.errorSpan').html("Wrong location. <br>Expected:"+invoice.location+" <br>Scanned:"+data);
  2172. $('#popupCloseLeft').popup('open');
  2173. }
  2174. }
  2175. }
  2176. }
  2177.  
  2178. function scanInventoryAddItem(invoice, itemNum, shouldContinue, appendType, data) {
  2179. var location = data;
  2180. $('.itemPageContent').fadeOut(1000, function() {
  2181. $('.itemPageContent').html('<span class="redFont">Please now scan the item.</span><br><br><br><a href="#" class="printBC" data-pid="'+invoice.items[itemNum].pid+'" data-theme="c" data-icon="tags" data-role="button">No Barcode!</a>').fadeIn(1000);
  2182. $('.printBC').button();
  2183. $('.printBC').one('click', function() {
  2184. $this = $(this);
  2185. $this.addClass('ui-btn-active');
  2186. setTimeout(function() {
  2187. $this.removeClass('ui-btn-active');
  2188. }, 500);
  2189. identifyItem(invoice, itemNum, shouldContinue, appendType, true);
  2190. });
  2191. });
  2192. Device.barcodeData = function (data, bar_type){
  2193. var b = false;
  2194. if(invoice.items[itemNum].barcode == "") b = true;
  2195. if(b == true || invoice.items[itemNum].barcode == data) {
  2196. invoice.items[itemNum].barcode = data;
  2197. if(invoice.items[itemNum].pid == "") {
  2198. $.get('adminLeadsQuery.php?num=33&barcode='+invoice.items[itemNum].barcode, function(res) {
  2199. if(res.trim().charAt(0) != '{') {
  2200. $.mobile.loading('show');
  2201. identifyItem(invoice, itemNum, shouldContinue, appendType, false);
  2202. }
  2203. else {
  2204. obj = JSON.parse(res);
  2205. invoice.items[itemNum].pid = obj.pid;
  2206. invoice.items[itemNum].name = obj.name;
  2207. appendItemPageContent(invoice, itemNum, data, location, shouldContinue, appendType);
  2208. }
  2209. });
  2210. }
  2211. else appendItemPageContent(invoice, itemNum, data, location, shouldContinue, appendType);
  2212. }
  2213. else {
  2214. $('.errorSpan').html("Wrong Item. <br>Expected:"+invoice.items[itemNum].barcode+" <br>Scanned:"+data);
  2215. $('#popupCloseLeft').popup('open');
  2216. }
  2217. }
  2218. }
  2219.  
  2220. function appendItemPageContent(invoice, itemNum, data, location, shouldContinue, appendType) {
  2221. $('.itemPageContent').html('<form action="#" method="post">' +
  2222. '<label for="flip-1">Primary Location:</label>'+
  2223. '<select name="flip-1" id="primary_loc" data-role="slider">'+
  2224. '<option value="no">No</option>'+
  2225. '<option value="yes">Yes</option>'+
  2226. '</select><br><br>'+
  2227. '<label for="newInvQty" class="select">Quantity:</label>' +
  2228. '<br><br><div class="ui-grid-b"><div class="ui-block-a">' +
  2229. '<input id="newInvQty" data-width="180" data-thickness=".5" data-fgColor="#417CB7" data-bgColor="#FFFFFF" data-displayInput="false" data-cursor=true></div>' +
  2230. '<div class="ui-block-b"></div><div class="ui-block-c">' +
  2231. '<br><div class="ival" style="width:80px;text-align:center;font-size:50px;color:#AAA">0</div><div class="idir" style="width:80px;text-align:center;font-size:50px;"></div></div></div>' +
  2232. '<button type="submit" id="itemSubmit" data-theme="b" name="submit">Submit</button>');
  2233. //$('#newInvQty').knob({'min': 1, 'max': 50, 'fgColor': '#417CB7', 'inputColor': '#5e87b0'});
  2234. // Example of infinite knob, iPod click wheel
  2235. var v, up=0,down=0,i=0
  2236. ,$idir = $("div.idir")
  2237. ,$ival = $("div.ival")
  2238. ,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
  2239. ,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
  2240. $("#newInvQty").knob({
  2241. min : 0
  2242. , max : 20
  2243. , stopper : false
  2244. , change : function () {
  2245. if(v > this.cv){
  2246. if(up){
  2247. decr();
  2248. up=0;
  2249. }else{up=1;down=0;}
  2250. } else {
  2251. if(v < this.cv){
  2252. if(down){
  2253. incr();
  2254. down=0;
  2255. }else{down=1;up=0;}
  2256. }
  2257. }
  2258. v = this.cv;
  2259. }
  2260. });
  2261. $('#itemSubmit').button();
  2262. $('#primary_loc').slider();
  2263. $('#itemSubmit').one('click', function() {
  2264. $this = $(this);
  2265. $this.addClass('ui-btn-active');
  2266. console.log('adminLeadsQuery.php?num=27&update_pull=false&pid='+invoice.items[itemNum].pid+'&name='+invoice.items[itemNum].name+'&barcode='+data+'&location='+location+'&qty='+Number($ival.html())+'&ploc='+$('#primary_loc').val());
  2267. $.get('adminLeadsQuery.php?num=27&update_pull=false&pid='+invoice.items[itemNum].pid+'&name='+invoice.items[itemNum].name+'&barcode='+data+'&location='+location+'&qty='+Number($ival.html())+'&ploc='+$('#primary_loc').val(), function(res) {
  2268. $this.removeClass('ui-btn-active');
  2269.  
  2270. confirm("Quantity on hand shows "+res+". Is this correct?", function(r) {
  2271. if(r == false) {
  2272. setTimeout(function() {
  2273. (LANGUAGE == "Spanish") ? alert('Inventario agregó. Por favor, encontrar un administrador. La cantidad es incorrecta.') : alert('Inventory added. Please contact an administrator.');
  2274. }, 1000);
  2275. }
  2276. else {
  2277. setTimeout(function() {
  2278. (LANGUAGE == "Spanish") ? alert('Inventario agregó.') : alert('Inventory added successfully.');
  2279. }, 1000);
  2280. }
  2281. if(shouldContinue) {
  2282. invoice.items[itemNum].locations.push({loc: location, qty: Number($ival.html())});
  2283. console.log(invoice);
  2284. if(invoice.items.length != itemNum){
  2285. startPullingItem(invoice, itemNum);
  2286. }
  2287. }
  2288. else {
  2289. var strToAppend;
  2290. if(appendType == 'location') {
  2291. var $object = $('.'+location);
  2292. if($('#itemManagePage ul li').html() == 'None in inventory!') $('#itemManagePage ul li').remove();
  2293. if($object.length) {
  2294. $object.find('span').html($object.find('span').html().substring(0, 5) + String(Number($object.find('span').html().substring(5))+Number($ival.html())));
  2295. }
  2296. else {
  2297. $('#itemManagePage ul').append('<li class="'+location+'">'+location+'<span class="ui-li-count">Qty: '+Number($ival.html())+'</span></li>');
  2298. $('#itemManagePage ul').listview('refresh');
  2299. }
  2300. if($('#barcodeInput').val().length == 0) {
  2301. $('#barcodeInput').val(invoice.items[itemNum].barcode);
  2302. }
  2303. }
  2304. else if(appendType == 'product') {
  2305. var $object = $('.'+invoice.items[itemNum].name);
  2306. if($('#itemManagePage ul li').html() == 'Nothing in inventory!') $('#itemManagePage ul li').remove();
  2307. if($object.length) {
  2308. $object.find('span').html($object.find('span').html().substring(0, 5) + String(Number($object.find('span').html().substring(5))+Number($ival.html())));
  2309. }
  2310. else {
  2311. $('#itemManagePage ul').append('<li class="'+invoice.items[itemNum].name+'">'+invoice.items[itemNum].name+'<span class="ui-li-count">Qty: '+Number($ival.html())+'</span></li>');
  2312. $('#itemManagePage ul').listview('refresh');
  2313. }
  2314. }
  2315. $ival.html('');
  2316. history.back();
  2317. }
  2318. Device.barcodeData = function (data, bar_type) {
  2319. $.get('adminLeadsQuery.php?num=26&ref_num=*'+data+'*', function(res) {
  2320. console.log(res);
  2321. if(String(res) != "") {
  2322. var obj = JSON.parse(res);
  2323. console.log(obj);
  2324. var $page = $('#invoicePage');
  2325. $page.children(":jqmData(role=header)").find('h3').html(obj.customer);
  2326. var str = "<a href='#' class='startPulling' data-role='button' data-icon='tags' data-json='" + res + "'>Start Pulling</a>";
  2327. for(var j = 0; j < obj.items.length; j++) {
  2328. str += '<li data-icon="tags"><a href="#"><h2>'+obj.items[j].name+'</h2><p>'+obj.items[j].description+'</p><span class="ui-li-count">Qty: <span id="leftToScan">'+obj.items[j].quantity+'</span></span></a></li>';
  2329. }
  2330. (embarrassingFuckItBoolVar) ? $('#invoiceList').html(str).trigger('create') : $('#invoiceList').html(str).listview('refresh').find('.startPulling').button();
  2331. embarrassingFuckItBoolVar = false;
  2332. $.mobile.changePage($page, {transition : 'slideup'});
  2333. }
  2334. else alert('Invoice not found.');
  2335. });
  2336. }
  2337. });
  2338. });
  2339. return false;
  2340. });
  2341. }
  2342.  
  2343. function loadPurchaseOrderPage() {
  2344. $.mobile.loading('show', {text: 'Loading...', textVisible: true});
  2345. $.get('adminLeadsQuery.php?num=28', function(res) {
  2346. var obj = JSON.parse(res);
  2347. var arr = obj.resultsFound;
  2348. console.log(arr);
  2349. $('#purchaseOrderList').html('');
  2350. for(var i = 0; i < arr.length; i++) {
  2351. var str = '';
  2352. str += '<li lid="'+i+'" ><a href="#"><h2>'+arr[i].vendor+' </h2><p>Expected: '+arr[i].expected_date+' Order: <span class="refNums">'+arr[i].ref_number+'</span></p></a><span class="ui-li-count">'+arr[i].items.length+'</span><ul>';
  2353. str += "<a href='#' data-rel='back' data-role='button' data-icon='arrow-l'>Back</a><a href='#' class='startPushing' data-role='button' data-icon='tags' data-json='" + JSON.stringify(arr[i]) + "'>Receive Order</a>";
  2354. for(var j = 0; j < arr[i].items.length; j++) {
  2355. str += '<li data-icon="tags"><a href="#"><h2>'+arr[i].items[j].name+'</h2><p>'+arr[i].items[j].sales_info+'</p><span class="ui-li-count">Qty: <span id="leftToScan">'+arr[i].items[j].quantity+'</span></span></a></li>';
  2356. }
  2357. str += '</ul></li>';
  2358. $('#purchaseOrderList').append(str);
  2359. }
  2360.  
  2361. $.mobile.changePage($('#purchaseOrderPage'), {transition: "flip"});
  2362. $('#purchaseOrderList').listview('refresh');
  2363. $.mobile.loading('hide');
  2364. });
  2365. }
  2366.  
  2367. function loadInvoicePage() {
  2368. $.mobile.loading('show', {text: 'Loading...', textVisible: true});
  2369. $.get('adminLeadsQuery.php?num=25', function(res) {
  2370. var obj = JSON.parse(res);
  2371. var arr = obj.resultsFound;
  2372. console.log(arr);
  2373. var tmp = [];
  2374. $('#invoiceList').html('');
  2375. for(var i = 0; i < arr.length; i++) {
  2376. var str = '';
  2377. if($.inArray(arr[i].customer, tmp) == -1) {
  2378. tmp.push(arr[i].customer);
  2379. str += '<li lid="'+i+'" location="'+arr[i].location+'"><a href="#"><h2>'+arr[i].customer+' </h2><p>Ship Date: '+arr[i].ship_date+' Pref Dev: '+arr[i].pref_delivery_time+' Sales Rep: '+arr[i].sales_rep+' Order #: <span class="refNums">'+arr[i].ref_number+'</span></p></a><span class="ui-li-count">'+arr[i].items.length+'</span><ul>';
  2380. str += "<a href='#' data-rel='back' data-role='button' data-icon='arrow-l'>Back</a><a href='#' class='startPulling' data-role='button' data-icon='tags' data-json='" + JSON.stringify(arr[i]) + "'>Start Pulling</a>";
  2381. for(var j = 0; j < arr[i].items.length; j++) {
  2382. str += '<li data-icon="tags"><a href="#"><h2>'+arr[i].items[j].name+'</h2><p>'+arr[i].items[j].description+'</p><span class="ui-li-count">Qty: <span id="leftToScan">'+arr[i].items[j].quantity+'</span></span></a></li>';
  2383. }
  2384. str += '</ul><a class="invoiceMoveButton" href="#popupInvoiceMove" iid="'+i+'" data-rel="popup" data-position-to="parent" data-transition="pop">Move</a></li>';
  2385. $('#invoiceList').append(str);
  2386. }
  2387. else {
  2388. var $count = $('#invoiceList h2:contains("'+arr[i].customer+'")').parents('li').find('.ui-li-count:not(:contains("Qty"))');
  2389. $count.html(Number($count.html())+arr[i].items.length);
  2390. $('#invoiceList h2:contains("'+arr[i].customer+'") ~ p').find('.refNums').append(', '+arr[i].ref_number);
  2391. for(var j = 0; j < arr[i].items.length; j++) {
  2392. str += '<li data-icon="tags"><a href="#"><h2>'+arr[i].items[j].name+' - Qty: '+arr[i].items[j].quantity+'</h2><p>'+arr[i].items[j].description+'</p><span class="ui-li-count">Qty: <span id="leftToScan">'+arr[i].items[j].quantity+'</span></span></a></li>';
  2393. }
  2394. $('#invoiceList h2:contains("'+arr[i].customer+'")').parents('li').find('ul').append(str);
  2395. }
  2396. }
  2397. var lid;
  2398. $('.invoiceMoveButton').bind('click', function() {
  2399. lid = $(this).attr('iid');
  2400. console.log(lid);
  2401. });
  2402. $('#moveUp').live('click', function(event) {
  2403. event.preventDefault();
  2404. $('#popupInvoiceMove').popup('close');
  2405. var $curLi = $("[lid='"+lid+"']");
  2406. var $prevLi = $curLi.prev();
  2407. if($prevLi.attr('lid') > -1) {
  2408. $prevLi.fadeOut();
  2409. $curLi.fadeOut(function() {
  2410. $prevLi.before($curLi);
  2411. $curLi.find('.startPulling').attr('json', JSON.stringify(arr[lid-1]));
  2412. $prevLi.find('.startPulling').attr('json', JSON.stringify(arr[lid]));
  2413. var tmp = arr[lid];
  2414. arr[lid] = arr[lid-1];
  2415. arr[lid-1] = tmp;
  2416. $prevLi.fadeIn();
  2417. $curLi.fadeIn();
  2418. });
  2419. }
  2420. });
  2421. $('#moveDown').live('click', function(event) {
  2422. event.preventDefault();
  2423. $('#popupInvoiceMove').popup('close');
  2424. var $curLi = $("[lid='"+lid+"']");
  2425. var $nextLi = $curLi.next();
  2426. if($nextLi.attr('lid') > -1) {
  2427. $nextLi.fadeOut();
  2428. $curLi.fadeOut(function() {
  2429. $nextLi.after($curLi);
  2430. $curLi.find('.startPulling').attr('json', JSON.stringify(arr[lid+1]));
  2431. $nextLi.find('.startPulling').attr('json', JSON.stringify(arr[lid]));
  2432. var tmp = arr[lid];
  2433. arr[lid] = arr[lid+1];
  2434. arr[lid+1] = tmp;
  2435. $nextLi.fadeIn();
  2436. $curLi.fadeIn();
  2437. });
  2438. }
  2439. });
  2440.  
  2441. $.mobile.changePage($('#invoicePage'), {transition: "flip"});
  2442. $.mobile.loading('hide');
  2443. $('#invoiceList').listview('refresh');
  2444. });
  2445. }
  2446.  
  2447. function startPullingItem(invoice, itemNum) {
  2448. var $page = $('#itemPage'),
  2449. $header = $page.children( ":jqmData(role=header)" ),
  2450. $content = $page.children( ":jqmData(role=content)" );
  2451. $header.find('h3').html(invoice.items[itemNum].name);
  2452. if(itemNum === 0) {
  2453. $.get('adminLeadsQuery?num=37&ref_number='+invoice.ref_number+'&field=start_time');
  2454. }
  2455. if(invoice.items[itemNum].barcode == "") {
  2456. //alert("This item's barcode is unknown. Please find and scan the location it is located now.")
  2457. $content.html('<h3>'+invoice.items[itemNum].name+' <br>Units: '+invoice.items[itemNum].quantity+'</h3><h4>'+invoice.items[itemNum].description+'</h4><p class="itemPageContent">This item has not yet been scanned. Please go to a location where this product is located and scan the location tag, then the actual item.</p>');
  2458. addNewInventory(invoice, itemNum, true);
  2459. }
  2460. else {
  2461. //alert("Please go to and scan one of the following locations:\n"+invoice.items[itemNum].locations);
  2462. var locString = "";
  2463. var locsToExpect = [];
  2464. for(var i = 0; i < invoice.items[itemNum].locations.length; i++) {
  2465. locString += '<li>' + invoice.items[itemNum].locations[i].loc + ' Qty: ' + invoice.items[itemNum].locations[i].qty + '</li>';
  2466. locsToExpect.push(invoice.items[itemNum].locations[i].loc);
  2467. }
  2468. if(invoice.items[itemNum].locations.length == 0) {
  2469. locString = "None found!";
  2470. }
  2471. $content.html('<h4>'+invoice.items[itemNum].name+' <br>Units: '+invoice.items[itemNum].quantity+'</h4>'+invoice.items[itemNum].description+'<p class="itemPageContent">Please go to one of the following locations and scan the location tag:<br><ul data-role="listview" data-inset="true">'+locString+'</ul></p>');
  2472. Device.barcodeData = function (data, bar_type){
  2473. if($.inArray(data, locsToExpect) > -1) {
  2474. var location = data;
  2475. var qty = invoice.items[itemNum].locations[$.inArray(location, locsToExpect)].qty;
  2476. $('.itemPageContent').html('<br><span class="redFont">Now scan the item.</span>');
  2477. Device.barcodeData = function (data, bar_type){
  2478. if(data == invoice.items[itemNum].barcode) {
  2479. var strToAppend = '<form action="#" method="post"><br>' +
  2480. '<label for="pullInvQty" class="select">How many units? (Do not pull from other locations in the warehouse)</label>' +
  2481. '<br><br><div class="ui-grid-b"><div class="ui-block-a">' +
  2482. '<input id="pullInvQty" data-width="180" data-thickness=".5" data-fgColor="#417CB7" data-bgColor="#FFFFFF" data-displayInput="false" data-cursor=true></div>' +
  2483. '<div class="ui-block-b"></div><div class="ui-block-c">' +
  2484. '<br><div class="ival" style="width:80px;text-align:center;font-size:50px;color:#AAA">0</div><div class="idir" style="width:80px;text-align:center;font-size:50px;"></div></div></div>';
  2485. strToAppend += '<button type="submit" id="itemSubmit" data-theme="b" name="submit">Submit</button>';
  2486. $('.itemPageContent').html(strToAppend);
  2487. //$('#pullInvQtyKnob').knob({'min': 1, 'max': qty, 'fgColor': '#417CB7', 'inputColor': '#5e87b0'});
  2488. var v, up=0,down=0,i=0
  2489. ,$idir = $("div.idir")
  2490. ,$ival = $("div.ival")
  2491. ,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
  2492. ,decr = function() {
  2493. if(i != 0) {
  2494. i--;
  2495. $idir.show().html("-").fadeOut();
  2496. $ival.html(i);
  2497. }
  2498. };
  2499. $("#pullInvQty").knob({
  2500. min : 0
  2501. , max : 20
  2502. , stopper : false
  2503. , change : function () {
  2504. if(v > this.cv){
  2505. if(up){
  2506. decr();
  2507. up=0;
  2508. }else{up=1;down=0;}
  2509. } else {
  2510. if(v < this.cv){
  2511. if(down){
  2512. incr();
  2513. down=0;
  2514. }else{down=1;up=0;}
  2515. }
  2516. }
  2517. v = this.cv;
  2518. }
  2519. /* function () {
  2520. if(v > this.cv){
  2521. decr();
  2522. } else if(v < this.cv){
  2523. incr();
  2524. }
  2525. v = this.cv;
  2526. } */
  2527. });
  2528. $('#itemSubmit').button();
  2529. $('#itemSubmit').on('click', function() {
  2530. $(this).addClass('ui-btn-active');
  2531. setTimeout(function() {
  2532. $(this).removeClass('ui-btn-active');
  2533. }, 500);
  2534. if(Number($ival.html()) <= qty) {
  2535. if(Number($ival.html()) == invoice.items[itemNum].quantity) {
  2536. $('#itemSubmit').off('click');
  2537. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+invoice.items[itemNum].name+'&pid='+invoice.items[itemNum].pid+'&ref_num='+invoice.ref_number.substring(1,invoice.ref_number.length-1)+'&location='+location+'&qty=-'+Number($ival.html()), function(res) {
  2538. if(itemNum != invoice.items.length-1) {
  2539. startPullingItem(invoice, itemNum+1);
  2540. }
  2541. else {
  2542. $('#invoicePage').children(':jqmData(role=header)').find('h3').html('Invoices');
  2543. delete invoice;
  2544. invoice = {};
  2545. loadInvoicePage();
  2546. if(itemNum === invoice.items.length-1) {
  2547. $.get('adminLeadsQuery?num=37&ref_number='+invoice.ref_number+'&field=end_time');
  2548. }
  2549. }
  2550. });
  2551. }
  2552. else if(Number($ival.html()) < invoice.items[itemNum].quantity) {
  2553. // $('.errorSpan').html('You still need to scan '+(invoice.items[itemNum].quantity - $ival.html())+' more units.');
  2554. // $('#popupCloseLeft').popup('open');
  2555. invoice.items[itemNum].quantity = invoice.items[itemNum].quantity - Number($ival.html());
  2556. invoice.items[itemNum].locations[$.inArray(location, locsToExpect)].qty = invoice.items[itemNum].locations[$.inArray(location, locsToExpect)].qty - Number($ival.html());
  2557. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+invoice.items[itemNum].name+'&pid='+invoice.items[itemNum].pid+'&ref_num='+invoice.ref_number.substring(1,invoice.ref_number.length-1)+'&location='+location+'&qty=-'+Number($ival.html()), function(res) {
  2558. startPullingItem(invoice, itemNum);
  2559. });
  2560. if($('#invPullQty').val() == qty) invoice.items[itemNum].locations.splice($.inArray(location, locsToExpect), 1);
  2561. }
  2562. else if(Number($ival.html()) > invoice.items[itemNum].quantity) {
  2563. /* alert('You are trying to pull too many units. You only need '+invoice.items[itemNum].quantity+' units for this invoice. Make sure this is all you pull.');
  2564. $('#itemSubmit').off('click');
  2565. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+invoice.items[itemNum].name+'&pid='+invoice.items[itemNum].pid+'&ref_num='+invoice.ref_number.substring(1,invoice.ref_number.length-1)+'&location='+location+'&qty=-'+invoice.items[itemNum].quantity, function(res) {
  2566. startPullingItem(invoice, itemNum+1);
  2567. }); */
  2568. $('.errorSpan').html('Too many units. Try again!<br>Expected: '+invoice.items[itemNum].quantity);
  2569. $('#popupCloseLeft').popup('open');
  2570. }
  2571. }
  2572. else if(Number($ival.html()) > Number(qty) ) {
  2573. invoice.items[itemNum].locations.splice($.inArray(location, locsToExpect), 1);
  2574. console.log(invoice.items[itemNum].locations);
  2575. locString = "";
  2576. for(var i = 0; i < invoice.items[itemNum].locations.length; i++) {
  2577. locString += '<li>' + invoice.items[itemNum].locations[i].loc + '<span class="ui-li-count">Qty: ' + invoice.items[itemNum].locations[i].qty + '</span></li>';
  2578. }
  2579. invoice.items[itemNum].quantity = invoice.items[itemNum].quantity - qty;
  2580. //$('.errorSpan').html('There aren\'t enough units in this location. Pull all '+qty+' units from here now.');
  2581. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+invoice.items[itemNum].name+'&pid='+invoice.items[itemNum].pid+'&ref_num='+invoice.ref_number.substring(1,invoice.ref_number.length-1)+'&location='+location+'&qty=-'+qty, function(res) {
  2582. startPullingItem(invoice, itemNum);
  2583. });
  2584. }
  2585. return false;
  2586. });
  2587. }
  2588. else {
  2589. $('.errorSpan').html("Wrong Item. <br>Expected:"+invoice.items[itemNum].barcode+" <br>Scanned:"+data);
  2590. $('#popupCloseLeft').popup('open');
  2591. }
  2592. }
  2593. }
  2594. else {
  2595. /* var r = confirm("The system reads no inventory in this location, is this correct? Click OK if yes, cancel if no.");
  2596. if(r == true) alert('Go to one of the listed locations and scan the tag.');
  2597. else addNewInventory(invoice, itemNum, true); */
  2598. $('.errorSpan').html("No inventory here!");
  2599. $('#popupCloseLeft').popup('open');
  2600. }
  2601. }
  2602. }
  2603. $page.page();
  2604. $.mobile.changePage($page, {transition: 'flip'});
  2605. }
  2606.  
  2607. function startPushingItem(purchase_order, itemNum) {
  2608. var $page = $('#itemPage'),
  2609. $header = $page.children( ":jqmData(role=header)" ),
  2610. $content = $page.children( ":jqmData(role=content)" );
  2611. $header.find('h3').html(purchase_order.items[itemNum].name);
  2612. if(purchase_order.items[itemNum].barcode == "") {
  2613. $content.html('<h3>'+purchase_order.items[itemNum].name+' <br>Units: '+purchase_order.items[itemNum].quantity+'</h3><h4>'+purchase_order.items[itemNum].description+'</h4><p class="itemPageContent">This item has not yet been scanned. Please go to a location where this product is located and scan the location tag, then the actual item.</p>');
  2614. addNewInventory(purchase_order, itemNum, true);
  2615. }
  2616. else {
  2617. var locString = "";
  2618. var locsToExpect = [];
  2619. for(var i = 0; i < purchase_order.items[itemNum].locations.length; i++) {
  2620. locString += '<li>' + purchase_order.items[itemNum].locations[i].loc + ' Qty: ' + purchase_order.items[itemNum].locations[i].qty + '</li>';
  2621. locsToExpect.push(purchase_order.items[itemNum].locations[i].loc);
  2622. }
  2623. if(purchase_order.items[itemNum].locations.length == 0) {
  2624. locString = "None in inventory!";
  2625. }
  2626. $content.html('<h4>'+purchase_order.items[itemNum].name+' <br>Units: '+purchase_order.items[itemNum].quantity+'</h4>'+purchase_order.items[itemNum].description+'<p class="itemPageContent"><span class="redFont">Scan the location of where to place the item.</span><br><br>Other locations for '+purchase_order.items[itemNum].name+':<br><ul data-role="listview" data-inset="true">'+locString+'</ul></p>');
  2627. Device.barcodeData = function (data, bar_type){
  2628. var location = data;
  2629. var qty = purchase_order.items[itemNum].quantity;
  2630. if($.inArray(data, locsToExpect) == -1) {
  2631. locsToExpect.push(location);
  2632. }
  2633. $('.itemPageContent').html('<br><span class="redFont">Now scan the item.</span><br><br><br><a href="#" class="printBC" data-pid="'+purchase_order.items[itemNum].pid+'" data-theme="c" data-icon="tags" data-role="button">Print Barcode</a>');
  2634. $('.printBC').button();
  2635. $('.printBC').one('click', function() {
  2636. $this = $(this);
  2637. $this.addClass('ui-btn-active');
  2638. setTimeout(function() {
  2639. $this.removeClass('ui-btn-active');
  2640. }, 500);
  2641. $.get('barcode.php?str='+purchase_order.items[itemNum].pid, function(res) {
  2642. window.plugin.print(res);
  2643. });
  2644. });
  2645. Device.barcodeData = function (data, bar_type){
  2646. if(data == purchase_order.items[itemNum].barcode) {
  2647. var strToAppend = '<form action="#" method="post"><br>' +
  2648. '<label for="pullInvQty" class="select">How many units are you placing here?</label>' +
  2649. '<br><br><div class="ui-grid-b"><div class="ui-block-a">' +
  2650. '<input id="pullInvQty" data-width="180" data-thickness=".5" data-fgColor="#417CB7" data-bgColor="#FFFFFF" data-displayInput="false" data-cursor=true></div>' +
  2651. '<div class="ui-block-b"></div><div class="ui-block-c">' +
  2652. '<br><div class="ival" style="width:80px;text-align:center;font-size:50px;color:#AAA">0</div><div class="idir" style="width:80px;text-align:center;font-size:50px;"></div></div></div>';
  2653. strToAppend += '<button type="submit" id="itemSubmit" data-theme="b" name="submit">Submit</button>';
  2654. $('.itemPageContent').html(strToAppend);
  2655. var v, up=0,down=0,i=0
  2656. ,$idir = $("div.idir")
  2657. ,$ival = $("div.ival")
  2658. ,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
  2659. ,decr = function() {
  2660. if(i != 0) {
  2661. i--;
  2662. $idir.show().html("-").fadeOut();
  2663. $ival.html(i);
  2664. }
  2665. };
  2666. $("#pullInvQty").knob({
  2667. min : 0
  2668. , max : 20
  2669. , stopper : false
  2670. , change : function () {
  2671. if(v > this.cv){
  2672. if(up){
  2673. decr();
  2674. up=0;
  2675. }else{up=1;down=0;}
  2676. } else {
  2677. if(v < this.cv){
  2678. if(down){
  2679. incr();
  2680. down=0;
  2681. }else{down=1;up=0;}
  2682. }
  2683. }
  2684. v = this.cv;
  2685. }
  2686. });
  2687. $('#itemSubmit').button();
  2688. $('#itemSubmit').on('click', function() {
  2689. $(this).addClass('ui-btn-active');
  2690. setTimeout(function() {
  2691. $(this).removeClass('ui-btn-active');
  2692. }, 500);
  2693. if(Number($ival.html()) <= qty) {
  2694. if(Number($ival.html()) == purchase_order.items[itemNum].quantity) {
  2695. $('#itemSubmit').off('click');
  2696. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+purchase_order.items[itemNum].name+'&pid='+purchase_order.items[itemNum].pid+'&ref_num='+purchase_order.ref_number.substring(1,purchase_order.ref_number.length-1)+'&location='+location+'&qty='+Number($ival.html()), function(res) {
  2697. if(itemNum != purchase_order.items.length-1) {
  2698. startPushingItem(purchase_order, itemNum+1);
  2699. }
  2700. else {
  2701. //$('#invoicePage').children(':jqmData(role=header)').find('h3').html('Invoices');
  2702. delete purchase_order;
  2703. purchase_order = {};
  2704. loadPurchaseOrderPage();
  2705. }
  2706. });
  2707. }
  2708. else if(Number($ival.html()) < purchase_order.items[itemNum].quantity) {
  2709. $('.errorSpan').html('You still need to scan '+(purchase_order.items[itemNum].quantity - $ival.html())+' more units.');
  2710. $('#popupCloseLeft').popup('open');
  2711. purchase_order.items[itemNum].quantity = purchase_order.items[itemNum].quantity - Number($ival.html());
  2712. purchase_order.items[itemNum].locations[$.inArray(location, locsToExpect)].qty = purchase_order.items[itemNum].locations[$.inArray(location, locsToExpect)].qty - Number($ival.html());
  2713. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+purchase_order.items[itemNum].name+'&pid='+purchase_order.items[itemNum].pid+'&ref_num='+purchase_order.ref_number.substring(1,purchase_order.ref_number.length-1)+'&location='+location+'&qty='+Number($ival.html()), function(res) {
  2714. startPushingItem(purchase_order, itemNum);
  2715. });
  2716. if($('#invPullQty').val() == qty) purchase_order.items[itemNum].locations.splice($.inArray(location, locsToExpect), 1);
  2717. }
  2718. else if(Number($ival.html()) > purchase_order.items[itemNum].quantity) {
  2719. $('.errorSpan').html('Too many units.<br>Try again!<br>Expected: '+purchase_order.items[itemNum].quantity);
  2720. $('#popupCloseLeft').popup('open');
  2721. }
  2722. }
  2723. else if(Number($ival.html()) > Number(qty) ) {
  2724. purchase_order.items[itemNum].locations.splice($.inArray(location, locsToExpect), 1);
  2725. console.log(purchase_order.items[itemNum].locations);
  2726. locString = "";
  2727. for(var i = 0; i < purchase_order.items[itemNum].locations.length; i++) {
  2728. locString += '<li>' + purchase_order.items[itemNum].locations[i].loc + '<span class="ui-li-count">Qty: ' + purchase_order.items[itemNum].locations[i].qty + '</span></li>';
  2729. }
  2730. purchase_order.items[itemNum].quantity = purchase_order.items[itemNum].quantity - qty;
  2731. $.get('adminLeadsQuery.php?num=27&update_pull=true&name='+purchase_order.items[itemNum].name+'&pid='+purchase_order.items[itemNum].pid+'&ref_num='+purchase_order.ref_number.substring(1,purchase_order.ref_number.length-1)+'&location='+location+'&qty='+qty, function(res) {
  2732. startPullingItem(purchase_order, itemNum);
  2733. });
  2734. }
  2735. return false;
  2736. });
  2737. }
  2738. else {
  2739. $('.errorSpan').html("Wrong Item. <br>Expected:"+purchase_order.items[itemNum].barcode+" <br>Scanned:"+data);
  2740. $('#popupCloseLeft').popup('open');
  2741. }
  2742. }
  2743. }
  2744. }
  2745. $page.page();
  2746. $.mobile.changePage($page, {transition: 'flip'});
  2747. }
  2748.  
  2749. function initInvManagementPage() {
  2750. $.get('adminLeadsQuery.php?num=31', function(res) {
  2751. $.mobile.loading('show', {text: 'Loading...', textVisible: true});
  2752. setTimeout(function() {
  2753. $.mobile.loading('hide');
  2754. }, 3000);
  2755. $('#invManagementPage').find(':jqmData(role=content)').append(res).trigger('create');
  2756. $('.locationListview li').on('click', function() {
  2757. $this = $(this);
  2758. $this.removeClass('ui-btn-up-c').addClass('ui-btn-up-b');
  2759. setTimeout(function() {
  2760. $this.removeClass('ui-btn-up-b').addClass('ui-btn-up-c');
  2761. }, 500);
  2762. console.log($this.data('loc'));
  2763. $.get('adminLeadsQuery.php?num=32&loc='+$this.data('loc'), function(res) {
  2764. $page = $('#itemManagePage');
  2765. $content = $page.children(":jqmData(role=content)");
  2766. if($page.children(":jqmData(role=header)").find('h3').html() != "Current Product") {
  2767. $content.html(res).trigger('create');
  2768. }
  2769. else $content.html(res);
  2770. $page.children(":jqmData(role=header)").find('h3').html($this.data('loc'));
  2771. $.mobile.changePage($page);
  2772. $('.newInventory').on('click', function() {
  2773. console.log(invoice);
  2774. $(this).data('json').invoice.items[0].barcode = "";
  2775. $(this).data('json').invoice.items[0].pid = "";
  2776. $(this).data('json').invoice.items[0].name = "";
  2777. delete invoice;
  2778. invoice = $(this).data('json').invoice;
  2779. console.log(invoice);
  2780. if (navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
  2781. if($('#itemPage').children(":jqmData(role=header)").find('h3').html() != "Current Product") {
  2782. $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.location+'</h3><p class="itemPageContent"><span class="redFont">Scan the location now.</span></p><ul data-role="listview" id="itemPageProductList" data-filter="true" data-filter-placeholder="Search Products"></ul>');
  2783. $('#itemPage').find('ul').listview();
  2784. }
  2785. else $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.location+'</h3><p class="itemPageContent"><span class="redFont">Scan the location now.</span></p><ul data-role="listview" id="itemPageProductList" data-filter="true" data-filter-placeholder="Search Products"></ul>');
  2786. $('#itemPage').children(":jqmData(role=header)").find('h3').html('Add Inventory');
  2787. $.mobile.changePage('#itemPage');
  2788. setTimeout(function() {
  2789. $('#itemPageProductList, form[role="search"]').hide();
  2790. }, 1000);
  2791. addNewInventory(invoice, 0, false, 'product');
  2792. }
  2793. else {
  2794. if(invoice.items[0].barcode == "") {
  2795. $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.items[0].name+'</h3><p class="itemPageContent">This item has not yet been scanned. Please input the barcode now: <br><input id="bcInput" type="text"></p>').trigger('create');
  2796. $.mobile.changePage('#itemPage', {transition: "flip"});
  2797. $('#bcInput').bind('change', function() {
  2798. alert($('#bcInput').val());
  2799. });
  2800. }
  2801. else {
  2802. $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.items[0].name+'</h3><p class="itemPageContent">Please input the location for the new inventory: <br><input id="locInput" type="text"></p>').trigger('create');
  2803. $.mobile.changePage('#itemPage', {transition: "flip"});
  2804. $('#locInput').bind('change', function() {
  2805. if(isValidLocation($('#locInput').val())) {
  2806. alert('Inventory added successfully.');
  2807. }
  2808. else alert('Invalid location. Check your spelling.');
  2809. });
  2810. }
  2811. }
  2812. });
  2813. $.mobile.loading('hide');
  2814. });
  2815. });
  2816. });
  2817. setTimeout(function() {
  2818. $('input[data-type="search"]').change(function() {
  2819. console.log($(this).val());
  2820. if ($(this).val() === '' || $(this).val().length <= 3) {
  2821. $('#invManagementList li').remove();
  2822. } else {
  2823. $.get('adminLeadsQuery.php?num=34&string='+$(this).val(), function(res) {
  2824. $('#invManagementList').append(res).listview('refresh');
  2825. $('#invManagementList li').bind('click', invManagementListHandler);
  2826. });
  2827. }
  2828. });
  2829. }, 1000);
  2830. }
  2831.  
  2832. function invManagementListHandler() {
  2833. var product_name = $(this).data('name');
  2834. var barcode = $(this).data('barcode');
  2835. var pid = $(this).data('productId');
  2836. $.get('adminLeadsQuery.php?num=30&pid='+pid+'&name='+product_name+'&barcode='+barcode, function(res) {
  2837. console.log(res);
  2838. $page = $('#itemManagePage');
  2839. $content = $page.children(":jqmData(role=content)");
  2840. if($page.children(":jqmData(role=header)").find('h3').html() != "Current Product") {
  2841. $content.html(res).trigger('create');
  2842. }
  2843. else $content.html(res);
  2844. $page.children(":jqmData(role=header)").find('h3').html(product_name);
  2845. $.mobile.changePage($page, {transition: "flip"});
  2846. $('.newInventory').bind('click', function() {
  2847. $this = $(this);
  2848. $this.addClass('ui-btn-active');
  2849. setTimeout(function() {
  2850. $this.removeClass('ui-btn-active');
  2851. }, 500);
  2852. if(typeof invoice != 'undefined') invoice = null;
  2853. console.log($(this).data('json').invoice);
  2854. var invoice = $(this).data('json').invoice;
  2855. console.log(invoice);
  2856. console.log(navigator.userAgent);
  2857. console.log('This is bullshit');
  2858.  
  2859. if (navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
  2860. $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.items[0].name+'</h3><p class="itemPageContent">Scan the location tag first. Then scan the item\'s barcode.</p>');
  2861. $.mobile.changePage('#itemPage', {transition: "flip"});
  2862. addNewInventory(invoice, 0, false, 'location');
  2863. } else {
  2864. if(invoice.items[itemNum].barcode == "") {
  2865. $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.items[0].name+'</h3><p class="itemPageContent">This item has not yet been scanned. Please input the barcode now: <br><input id="bcInput" type="text"></p>').trigger('create');
  2866. $.mobile.changePage('#itemPage', {transition: "flip"});
  2867. $('#bcInput').bind('change', function() {
  2868. alert($('#bcInput').val());
  2869. });
  2870. }
  2871. else {
  2872. $('#itemPage').find(':jqmData(role=content)').html('<h3>'+invoice.items[0].name+'</h3><p class="itemPageContent">Please input the location for the new inventory: <br><input id="locInput" type="text"></p>').trigger('create');
  2873. $.mobile.changePage('#itemPage', {transition: "flip"});
  2874. $('#locInput').bind('change', function() {
  2875. if(isValidLocation($('#locInput').val())) {
  2876. alert('Inventory added successfully.');
  2877. }
  2878. else alert('Invalid location. Check your spelling.');
  2879. });
  2880. }
  2881. }
  2882. });
  2883. });
  2884. }
  2885.  
  2886. function isValidLocation(locationString) {
  2887. if(str.charAt(0) == 'R' && str.charAt(3) == 'S' && str.charAt(6) == 'L') {
  2888. return true;
  2889. }
  2890. else return false;
  2891. }
  2892.  
  2893. //Javascript classes
  2894. function PolygonContainedPlaces(polygon) {
  2895. this.polygon = polygon;
  2896. this.array = [];
  2897.  
  2898. this.add = function(element) {
  2899. var r = this.polygon.Contains(element.position);
  2900. if(r == true) this.array.push(element);
  2901. }
  2902.  
  2903. this.clearList = function() {
  2904. $('#placesList').html('');
  2905. $('#placesList').selectmenu('refresh');
  2906. }
  2907.  
  2908. this.displayList = function() {
  2909. for(var i = 0; i < this.array.length; i++) {
  2910. $('#placesList').append('<option value="'+this.array[i].name+'|'+this.array[i].position+'">'+this.array[i].name+'</option>');
  2911. }
  2912. $('#popupPlaces').popup('open');
  2913. }
  2914.  
  2915. this.positionToWaypoint = function(array) {
  2916. for(var i = 0; i < array.length; i++) {
  2917. directionsOrderedNames.push(array[i][0]);
  2918. array[i] = {
  2919. location: array[i][1],
  2920. stopover: true
  2921. }
  2922. }
  2923. return array;
  2924. }
  2925.  
  2926. this.getDirections = function(array, newRoute) {
  2927. if(newRoute) {
  2928. var $this = this;
  2929. setTimeout(function() {
  2930. var destination;
  2931. var wp;
  2932. confirm('Would you like to make USAH your final destination?', function(c) {
  2933. if(c) {
  2934. destination = usahPos;
  2935. wp = $this.positionToWaypoint(array);
  2936. directionsOrderedNames.push('USA Hospitality');
  2937. }
  2938. else {
  2939. var lastValue = array.pop();
  2940. destination = lastValue[1];
  2941. wp = $this.positionToWaypoint(array);
  2942. directionsOrderedNames.push(lastValue[0]);
  2943. }
  2944. basicRequest(destination, wp);
  2945. });
  2946. }, 500);
  2947. }
  2948. else {
  2949. if(request.destination == usahPos && request.waypoints.length > 0) request.destination = request.waypoints[request.waypoints.length-1].position;
  2950. if(!request.waypoints) request.waypoints = [];
  2951. request.waypoints.push({
  2952. location:request.destination,
  2953. stopover:true
  2954. });
  2955. confirm('Would you like to make USAH your final destination?', function(c) {
  2956. if(c) {
  2957. request.destination = usahPos;
  2958. directionsOrderedNames.push('USA Hospitality');
  2959. }
  2960. else {
  2961. var lastValue = array.pop();
  2962. request.destination = lastValue[1];
  2963. directionsOrderedNames.push(lastValue[0]);
  2964. }
  2965. array = this.positionToWaypoint(array);
  2966. for(var i = 0; i < array.length; i++) {
  2967. request.waypoints.push(array[i]);
  2968. }
  2969. directionsService.route(request, function(result, status) {
  2970. directionsCallback(result, status);
  2971. });
  2972. });
  2973. }
  2974. }
  2975. }
  2976.  
  2977. function GeoFence(id, location, name) {
  2978. this.id = id;
  2979. this.location = location;
  2980. this.name = name;
  2981. this.withinRadius = false;
  2982. this.perimeterCrossed = function(callbackFunction) {
  2983. console.log(this.location);
  2984. console.log(this.withinRadius);
  2985. var distanceFromGeofence = google.maps.geometry.spherical.computeDistanceBetween(this.location, GeoMarker.getPosition());
  2986. console.log(distanceFromGeofence);
  2987. if(this.withinRadius == false) {
  2988. if(distanceFromGeofence < GEOFENCE_RADIUS) {
  2989. this.withinRadius = true;
  2990. callbackFunction(true)
  2991. }
  2992. else callbackFunction(false);
  2993. }
  2994. else {
  2995. if(distanceFromGeofence > GEOFENCE_RADIUS) {
  2996. this.withinRadius = false;
  2997. callbackFunction(true);
  2998. }
  2999. else callbackFunction(false);
  3000. }
  3001. }
  3002. }
  3003.  
  3004. //Methods used between different login types (inventory, sales rep, driver, etc.)
  3005. $(window).load(function() {
  3006. if ( !Array.prototype.forEach ) {
  3007. Array.prototype.forEach = function(fn, scope) {
  3008. for(var i = 0, len = this.length; i < len; ++i) {
  3009. fn.call(scope, this[i], i, this);
  3010. }
  3011. }
  3012. }
  3013. $('.pullingSlips').live('click', function() {
  3014. $(this).addClass('ui-btn-active');
  3015. setTimeout(function() {
  3016. $(this).removeClass('ui-btn-active');
  3017. }, 500);
  3018. loadInvoicePage();
  3019. });
  3020.  
  3021. $('.startPulling').live('click', function() {
  3022. $(this).addClass('ui-btn-active');
  3023. setTimeout(function() {
  3024. $(this).removeClass('ui-btn-active');
  3025. }, 500);
  3026. console.log($(this).data('json'));
  3027. delete invoice;
  3028. invoice = $(this).data('json');
  3029. console.log(invoice);
  3030. startPullingItem(invoice, 0);
  3031. });
  3032.  
  3033. $('.purchaseOrders').live('click', function() {
  3034. $(this).addClass('ui-btn-active');
  3035. setTimeout(function() {
  3036. $(this).removeClass('ui-btn-active');
  3037. }, 500);
  3038. loadPurchaseOrderPage();
  3039. });
  3040.  
  3041. $('.startPushing').bind('click', function() {
  3042. $(this).addClass('ui-btn-active');
  3043. setTimeout(function() {
  3044. $(this).removeClass('ui-btn-active');
  3045. }, 500);
  3046. console.log($(this).data('json'));
  3047. delete purchase_order;
  3048. purchase_order = $(this).data('json');
  3049. console.log(purchase_order);
  3050. startPushingItem(purchase_order, 0);
  3051. });
  3052.  
  3053. $('.manageInventory').bind('click', function() {
  3054. $(this).addClass('ui-btn-active');
  3055. setTimeout(function() {
  3056. $(this).removeClass('ui-btn-active');
  3057. }, 500);
  3058. $.mobile.changePage($('#invManagementPage'), {transition: "flip"});
  3059. });
  3060. $('.scanner').bind('click', function() {
  3061. $(".scanner").addClass('ui-btn-active');
  3062. setTimeout(function() {
  3063. $(".scanner").removeClass('ui-btn-active');
  3064. }, 500);
  3065. //scan();
  3066. Device.enableBarcode(ScannerDevice.CONSTANTS.BAR_TYPES.BAR_ALL, true)
  3067. //Device.playSound([100,100,0,100,100,100,0,100,100,100]);
  3068. /* Device.startScan();
  3069. Device = new ScannerDevice({
  3070. barcodeData: function (data, bar_type){
  3071. $.get('adminLeadsQuery.php?num=26&ref_num=*'+data+'*', function(res) {
  3072. console.log(res);
  3073. if(String(res) != "") {
  3074. var obj = JSON.parse(res);
  3075. console.log(obj);
  3076. var $page = $('#invoicePage');
  3077. $page.children(":jqmData(role=header)").find('h3').html(obj.customer);
  3078. var str = "<a href='#' class='startPulling' data-role='button' data-icon='tags' data-json='" + res + "'>Start Pulling</a>";
  3079. for(var j = 0; j < obj.items.length; j++) {
  3080. str += '<li data-icon="tags"><a href="#"><h2>'+obj.items[j].name+'</h2><p>'+obj.items[j].description+'</p><span class="ui-li-count">Qty: <span id="leftToScan">'+obj.items[j].quantity+'</span></span></a></li>';
  3081. }
  3082. (embarrassingFuckItBoolVar) ? $('#invoiceList').html(str).trigger('create') : $('#invoiceList').html(str).listview('refresh').find('.startPulling').button();
  3083. embarrassingFuckItBoolVar = false;
  3084. $.mobile.changePage($page, {transition : 'slideup'});
  3085. }
  3086. else alert('Invoice not found.');
  3087. });
  3088. },
  3089. magneticCardData: function (track1, track2, track3){
  3090. alert('Card read with following data: '+track1+'\n'+track2+'\n'+track3);
  3091. },
  3092. magneticCardRawData: function (data){
  3093. alert('Raw data read from card reader: '+data);
  3094. },
  3095. buttonPressed: function (button){
  3096. // Currently device only registers 1 button.
  3097. console.log('Button was pressed');
  3098. },
  3099. buttonReleased: function (button){
  3100. // Currently device only registers 1 button.
  3101. console.log('Button was released');
  3102. },
  3103. connectionState: function (state){
  3104. console.log('Scanner is now in state: '+state);
  3105. }
  3106. }); */
  3107. });
  3108.  
  3109.  
  3110. $('#reportBug').live('click', function() {
  3111. $this = $(this);
  3112. $this.addClass('ui-btn-active');
  3113. setTimeout(function() {
  3114. $this.removeClass('ui-btn-active');
  3115. }, 500);
  3116. $.mobile.changePage( "#addBugReport", { role: "dialog" } );
  3117. });
  3118.  
  3119. $('#logout').live('click', function() {
  3120. $this = $(this);
  3121. $this.addClass('ui-btn-active');
  3122. setTimeout(function() {
  3123. $this.removeClass('ui-btn-active');
  3124. }, 500);
  3125. $.get('adminLeadsQuery.php?num=18', function(res) {
  3126. window.location = "";
  3127. });
  3128. });
  3129.  
  3130. $('.addPicture').live('click', function() {
  3131. navigator.camera.getPicture(onSuccess, onFail, { quality: 20, destinationType: navigator.camera.DestinationType.DATA_URL, sourceType: navigator.camera.PictureSourceType.Camera, encodingType: navigator.camera.EncodingType.PNG });
  3132. });
  3133.  
  3134. $('.addPictureFromLibrary').live('click', function() {
  3135. navigator.camera.getPicture(onSuccess, onFail, { quality: 20, destinationType: navigator.camera.DestinationType.DATA_URL, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, encodingType: navigator.camera.EncodingType.PNG });
  3136. });
  3137.  
  3138. $('#bugSubmit').live('click', function() {
  3139. $.mobile.loading( 'show', {text: 'Uploading Image...', textVisible: true});
  3140. uploadPicture('#popupMap', function(data) {
  3141. $.get("adminLeadsQuery.php?num=24&description="+$('#bug_desc').val()+"&imageURL="+data)
  3142. setTimeout(function() {
  3143. alert('Thank you!');
  3144. }, 1000);
  3145. });
  3146. });
  3147.  
  3148. /* setTimeout(function() {
  3149. $.get('barcode.php?str=80000031-1324499173', function(res) {
  3150. window.plugin.print(res);
  3151. });
  3152. }, 4000); */
  3153.  
  3154. function onSuccess(imageData) {
  3155. $('.myImage').attr('src', 'data:image/png;base64,' + imageData);
  3156. $('.myImage').show();
  3157. }
  3158. function onFail(message) {
  3159. alert('Failed because: ' + message);
  3160. }
  3161. });
  3162.  
  3163. //Page Handler for Inventory Management Page
  3164. $(document).bind('pagebeforecreate', function(e) {
  3165. //console.log(e.currentTarget.URL.substring(e.currentTarget.URL.length-18, e.currentTarget.URL.length));
  3166. console.log(e);
  3167. setTimeout(function() {
  3168. $('#popupLogin a').hide();
  3169. }, 200);
  3170. if(e.target.id == 'invManagementPage') {
  3171. shouldLoadAll = false;
  3172. initInvManagementPage();
  3173. }
  3174. });
  3175. //$(document).bind('deviceready', showLogin);
  3176. $(window).load(showLogin);
  3177. //$('#popupMap').live('pageinit', init);
Add Comment
Please, Sign In to add comment