Renewal URL Generator Beta

Adds a button to service autopilot to automatically generate renewal URLs

  1. // ==UserScript==
  2. // @name Renewal URL Generator Beta
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.5
  5. // @description Adds a button to service autopilot to automatically generate renewal URLs
  6. // @author Tyler
  7. // @match https://my.serviceautopilot.com/ClientView.aspx?*
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. var $ = window.jQuery;
  14. 'use strict';
  15. $(document).arrive("#edSaveBtn", function() {
  16. function dateConvert(inputdate) {
  17. if (inputdate) {
  18. var dateParts = inputdate.toDateString().split(" ");
  19. if (dateParts[2] == "15") {
  20. dateParts[2] = "Late ";
  21. } else {
  22. dateParts[2] = "";
  23. }
  24. return dateParts[2] + dateParts[1] + " " + dateParts[3]
  25. } else {
  26. return ""
  27. }
  28. }
  29. function addMonths(date, months) {
  30. var d = date.getDate();
  31. date.setMonth(date.getMonth() + +months);
  32. if (date.getDate() != d) {
  33. date.setDate(0);
  34. }
  35. return date;
  36. }
  37. $("#editorOverlayDomId").append("Enter New Price: <input id='priceInput' type='text' width='5' /><br><button id='URLGeneration' type='button'>Generate Renewal URL</button><br><button id='genericGeneration' type='button'>Generate Quarterly Generic URL</button>");
  38. $("#priceInput").click(function(){$("#priceInput").focus()})
  39.  
  40. $('#URLGeneration').click(function() {
  41. $("#edSaveBtn").remove();
  42. var input = $("#priceInput").val();
  43. var URL = [];
  44. var dates = [];
  45. var i=0
  46. while ($("#edDetailDate"+i).text()) {
  47. dates.push(new Date($("#edDetailDate"+i).text()))
  48. i++
  49. }
  50. dates.sort((a, b) => a - b)
  51. var urlString;
  52. var Wadd1 = encodeURIComponent($("#lblPropertyAddress").text());
  53. var Wcity = encodeURIComponent($("#lblPropertyCityStateZip").text().split(',')[0]);
  54. var Wstate = encodeURIComponent($("#lblPropertyCityStateZip").text().split(',')[1].substring(0,3));
  55. var Wzip = encodeURIComponent($("#lblPropertyCityStateZip").text().split(',')[1].substring(3));
  56. var Badd1 = encodeURIComponent($("#lblBillingAddress").text());
  57. var Bcity, Bstate, Bzip
  58. if ($("#lblBillingCityStateZip").text()) {
  59. Bcity = encodeURIComponent($("#lblBillingCityStateZip").text().split(',')[0]);
  60. Bstate = encodeURIComponent($("#lblBillingCityStateZip").text().split(',')[1].substring(0,3));
  61. Bzip = encodeURIComponent($("#lblBillingCityStateZip").text().split(',')[1].substring(3));
  62. } else {
  63. Bcity = encodeURIComponent($("#lblBillingAddress2").text().split(',')[0]);
  64. Bstate = encodeURIComponent($("#lblBillingAddress2").text().split(',')[1].substring(0,3));
  65. Bzip = encodeURIComponent($("#lblBillingAddress2").text().split(',')[1].substring(3));
  66. }
  67. var Pphone = encodeURIComponent($("#lblPhone1").text().slice(0, -3));
  68. var Pcell = encodeURIComponent($("#lblPhone2").text().slice(0, -3));
  69. var Phome = encodeURIComponent($("#lblPhone3").text().slice(0, -3));
  70. var Pother = encodeURIComponent($("#lblPhone4").text().slice(0, -3));
  71. var Pemail = encodeURIComponent($("#contactEmailLink").text());
  72. var cd1 = dateConvert(dates[0]);
  73. var cd2 = dateConvert(dates[1]);
  74. var cd3 = dateConvert(dates[2]);
  75. var cd4 = dateConvert(dates[3]);
  76. var cd5 = dateConvert(dates[4]);
  77. var cd6 = dateConvert(dates[5]);
  78. var cd7 = dateConvert(dates[6]);
  79. var cd8 = dateConvert(dates[7]);
  80. var cd9 = dateConvert(dates[8]);
  81. var cd10 = dateConvert(dates[9]);
  82. var cd11 = dateConvert(dates[10]);
  83. var cd12 = dateConvert(dates[11]);
  84. var freq = $("[id^=edDetailDate]").length-2;
  85. var pptcp = parseFloat((input-10)*freq).toFixed(2);
  86. var ppsave = parseFloat(10*freq).toFixed(2);
  87. var nppfpr = parseFloat(input-5).toFixed(2);
  88. var nppmip = parseFloat(input).toFixed(2);
  89.  
  90. if ($("#lblCompany").text() == "AEROTECH ST. LOUIS") {
  91. urlString = "https://thegutterexperts.com/renewal/stl/?"
  92. }
  93. else if ($("#lblCompany").text() == "AEROTECH METRO DC") {
  94. urlString = "https://thegutterexperts.com/renewal/mdc/?"
  95. }
  96. else alert("error, unable to determine area")
  97.  
  98. URL.push(
  99. urlString,
  100. "Wadd1=",Wadd1,"&",
  101. "Wcity=",Wcity,"&",
  102. "Wstate=",Wstate,"&",
  103. "Wzip=",Wzip,"&",
  104. "BAdd1=",Badd1,"&",
  105. "Bcity=",Bcity,"&",
  106. "Bstate=",Bstate,"&",
  107. "Bzip=",Bzip,"&",
  108. "Pphone=",Pphone,"&",
  109. "Pcell=",Pcell,"&",
  110. "Phome=",Phome,"&",
  111. "Pother=",Pother,"&",
  112. "Pemail=",Pemail,"&",
  113. "cd1=",cd1,"&",
  114. "cd2=",cd2,"&",
  115. "cd3=",cd3,"&",
  116. "cd4=",cd4,"&",
  117. "cd5=",cd5,"&",
  118. "cd6=",cd6,"&",
  119. "cd7=",cd7,"&",
  120. "cd8=",cd8,"&",
  121. "cd9=",cd9,"&",
  122. "cd10=",cd10,"&",
  123. "cd12=",cd12,"&",
  124. "pptcp=",pptcp,"&",
  125. "ppsave=",ppsave,"&",
  126. "nppfpr=",nppfpr,"&",
  127. "nppmip=",nppmip,"&",
  128. );
  129. navigator.clipboard.writeText(URL.join(""))
  130. alert("Renewal URL Copied to Clipboard MAKE SURE YOU HAVE SELECTED CORRECT DATES!");
  131. });
  132.  
  133. $('#genericGeneration').click(function() {
  134. var input = $("#priceInput").val();
  135. var Bcity, Bstate, Bzip
  136. if ($("#lblBillingCityStateZip").text()) {
  137. Bcity = encodeURIComponent($("#lblBillingCityStateZip").text().split(',')[0]);
  138. Bstate = encodeURIComponent($("#lblBillingCityStateZip").text().split(',')[1].substring(0,3));
  139. Bzip = encodeURIComponent($("#lblBillingCityStateZip").text().split(',')[1].substring(3));
  140. } else {
  141. Bcity = encodeURIComponent($("#lblBillingAddress2").text().split(',')[0]);
  142. Bstate = encodeURIComponent($("#lblBillingAddress2").text().split(',')[1].substring(0,3));
  143. Bzip = encodeURIComponent($("#lblBillingAddress2").text().split(',')[1].substring(3));
  144. }
  145. var today = new Date();
  146. var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);
  147. var cd1 = addMonths(new Date(), 0)
  148. var cd2 = addMonths(new Date(), 3)
  149. var cd3 = addMonths(new Date(), 6)
  150. var cd4 = addMonths(new Date(), 9)
  151. var freq = 4
  152. var pptcp = parseFloat((input-10)*4).toFixed(2);
  153. var ppsave = parseFloat(10*4).toFixed(2);
  154. var nppfpr = parseFloat(input-5).toFixed(2);
  155. var nppmip = parseFloat(input).toFixed(2);
  156. var urlString
  157. //if five days from today is past the end of the month, add 1 to each month
  158. if (today.getDate()+5 > lastDayOfMonth.getDate()) {
  159. cd1 = addMonths(cd1, 1)
  160. cd2 = addMonths(cd2, 1)
  161. cd3 = addMonths(cd3, 1)
  162. cd4 = addMonths(cd4, 1)
  163. }
  164. if ($("#lblCompany").text() == "AEROTECH ST. LOUIS") {
  165. urlString = "https://thegutterexperts.com/renewal/stl/?"
  166. }
  167. else if ($("#lblCompany").text() == "AEROTECH METRO DC") {
  168. urlString = "https://thegutterexperts.com/renewal/mdc/?"
  169. }
  170. else alert("error, unable to determine area")
  171. var URL = [];
  172. URL.push(
  173. urlString,
  174. "Wadd1=",encodeURIComponent($("#lblPropertyAddress").text()),"&",
  175. "Wcity=",encodeURIComponent($("#lblPropertyCityStateZip").text().split(',')[0]),"&",
  176. "Wstate=",encodeURIComponent($("#lblPropertyCityStateZip").text().split(',')[1].substring(0,3)),"&",
  177. "Wzip=",encodeURIComponent($("#lblPropertyCityStateZip").text().split(',')[1].substring(3)),"&",
  178. "BAdd1=",encodeURIComponent($("#lblBillingAddress").text()),"&",
  179. "Bcity=",Bcity,"&",
  180. "Bstate=",Bstate,"&",
  181. "Bzip=",Bzip,"&",
  182. "Pphone=",encodeURIComponent($("#lblPhone1").text().slice(0, -3)),"&",
  183. "Pcell=",encodeURIComponent($("#lblPhone2").text().slice(0, -3)),"&",
  184. "Phome=",encodeURIComponent($("#lblPhone3").text().slice(0, -3)),"&",
  185. "Pother=",encodeURIComponent($("#lblPhone4").text().slice(0, -3)),"&",
  186. "Pemail=",encodeURIComponent($("#contactEmailLink").text()),"&",
  187. "cd1=",cd1.toLocaleString('en-US', { year: 'numeric', month: 'long'}),"&",
  188. "cd2=",cd2.toLocaleString('en-US', { year: 'numeric', month: 'long'}),"&",
  189. "cd3=",cd3.toLocaleString('en-US', { year: 'numeric', month: 'long'}),"&",
  190. "cd4=",cd4.toLocaleString('en-US', { year: 'numeric', month: 'long'}),"&",
  191. "pptcp=",pptcp,"&",
  192. "ppsave=",ppsave,"&",
  193. "nppfpr=",nppfpr,"&",
  194. "nppmip=",nppmip,"&",
  195. );
  196. navigator.clipboard.writeText(URL.join(""))
  197. alert("Renewal URL Copied to Clipboard.");
  198. })
  199. $('#MailJetInfo').click(function() {
  200. var i=1
  201. while ($('#lblCustomField'+i).text().length) {
  202. switch($('#lblCustomField'+i).text().trim()) {
  203. case "MailJet Renewal Information":
  204. var mjRI = $('#lblCustomData'+i).text();
  205. break;
  206. case "MailJet Renewal Date Changes":
  207. var mjDC = $('#lblCustomData'+i).text();
  208. break;
  209. case "MailJet Renewal Prepayment Amount":
  210. var mjPP = $('#lblCustomData'+i).text();
  211. break;
  212. case "MailJet Renewal Autocharge Amount":
  213. var mjAC = $('#lblCustomData'+i).text();
  214. break;
  215. case "MailJet Renewal Payment Method":
  216. var mjPM = $('#lblCustomData'+i).text();
  217. break;
  218. case "MailJet Renewal Extra Information":
  219. var mjEI = $('#lblCustomData'+i).text();
  220. break;
  221. }
  222. i++
  223. }
  224. $('#editorOverlayDomId').append("<div id='MJInfoDiv' style='margin-top: 10%;'></div>")
  225. $('#MJInfoDiv').append("<p>"+mjRI.substring(mjRI.lastIndexOf("Recommended Service Months"),mjRI.lastIndexOf("PREPAY")).replace(/undefined/g,"")+"</p>")
  226. $('#MJInfoDiv').append("<p>"+mjRI.substring(mjRI.lastIndexOf("PREPAY"),mjRI.lastIndexOf("AUTOCHARGE"))+"<br>"+mjRI.substring(mjRI.lastIndexOf("AUTOCHARGE"),mjRI.lastIndexOf("INVOICE"))+"<br>"+mjRI.substring(mjRI.lastIndexOf("INVOICE"),mjRI.length)+"</p>")
  227. $('#MJInfoDiv').append("<p>Requested Date Changes: "+mjDC+"</p>");
  228. $('#MJInfoDiv').append("<p>Selected Payment Method: "+mjPM.split(" ")[0]+"</p>");
  229. if (mjPM.split(" ")[0] == "PREPAY") {
  230. $('#MJInfoDiv').append("<p>Prepay Amount: "+mjPP+"</p>");
  231. }
  232. else if (mjPM.split(" ")[0]=="AUTOCHARGE")
  233. {
  234. $('#MJInfoDiv').append("<p>Autocharge Amount: "+mjAC+"</p>");
  235. }
  236. $('#MJInfoDiv').append("<p>Other Information: "+mjEI+"</p>");
  237. })
  238. });
  239. }
  240. )
  241. ()