fork download
  1. // ***** Variables used by the main script and linked to the sub scripts.
  2.  
  3. // Full file name/path, file name, file path.
  4. var src_fl, src_fl_t, src_fl_p;
  5. // Brand
  6. var brand, brand_b, brand_t;
  7. // Operating system slash variable.
  8. var os_t;
  9. // Length of spreadsheet.
  10. var i, l;
  11.  
  12. // ***** Define the URL's to use based upon the input brand.
  13. brand = prompt("Which brand is this for: ASO, CTX, H9, SEOH, SEOW, ARVX");
  14.  
  15. switch (brand) {
  16. case 'ASO':
  17. brand_b = "https://c...content-available-to-author-only...e.com/admin/index.php";
  18. brand_t = "%2";
  19. break;
  20. case 'CTX':
  21. throw new Error("The script is not configured for this brand yet.");
  22. break;
  23. case 'H9':
  24. throw new Error("The script is not configured for this brand yet.");
  25. break;
  26. case 'SEOH':
  27. throw new Error("The script is not configured for this brand yet.");
  28. break;
  29. case 'SEOW':
  30. throw new Error("The script is not configured for this brand yet.");
  31. break;
  32. case 'ARVX':
  33. throw new Error("The script is not configured for this brand yet.");
  34. break;
  35. default:
  36. throw new Error("You must specify a brand.");
  37. break;
  38. }
  39.  
  40. // ***** Define the file to use and number of lines in the file.
  41. // ***** Checks for slash direction to ensure properly set going forward for windows or mac/linux.
  42. src_fl = prompt("Please specify the file name and file path to run on.", "/home/user/doc/myfile.csv");
  43.  
  44. if (src_fl.lastIndexOf('/') >= 1) {
  45. src_fl_t = src_fl.split('/').pop();
  46. src_fl_p = src_fl.split('/');
  47. src_fl_p = src_fl_p.slice(0, src_fl_p.length - 1).join("/") + "/";
  48. src_fl_o = "out_" + src_fl_t;
  49. os_t = "/";
  50. } else {
  51. src_fl_t = src_fl.split("\\").pop();
  52. src_fl_p = src_fl.split('/');
  53. src_fl_p = src_fl_p.slice(0, src_fl_p.length - 1).join("\\") + "\\";
  54. src_fl_o = "out_" + src_fl_t;
  55. os_t = "\\";
  56. }
  57.  
  58. i = prompt("How many lines are in the file including the header?");
  59.  
  60. // ***** Master loop based on the number of lines input.
  61.  
  62. // ***** Pull the invoice ID from the spreadsheet.
  63.  
  64. for (l = 2; l <= i; l++) {
  65.  
  66. // ***** Reset these variables on every iteration to prevent corrupted data.
  67. // Invoice id, client id, invoice status.
  68. var inv_id, cli_id, inv_st
  69. // Message variable for results output.
  70. var msg;
  71. // Item description array.
  72. var desc_itm = [];
  73. var itm_txt;
  74. // Client ticket.
  75. var cli_tkt;
  76.  
  77. iimSet("i", String(l));
  78. iimSet("src_fl", String(src_fl));
  79. iimPlay("ASO/cb_1.iim");
  80. inv_id = iimGetLastExtract();
  81.  
  82. // ***** Search for the client in WHMCS based on the invoice ID.
  83.  
  84. iimSet("inv_id", String(inv_id));
  85. iimSet("brand_b", String(brand_b));
  86. iimPlay("ASO/cb_2.iim");
  87. cli_id = iimGetLastExtract();
  88.  
  89. // ***** If no valid client ID identified, output an error to the file and proceed to next invoice entry.
  90.  
  91. if (cli_id === parseInt(cli_id, 10)) {
  92.  
  93. iimSet("src_fl_p", String(src_fl_p));
  94. iimSet("src_fl_o", String(src_fl_o));
  95. iimSet("inv_id", String(inv_id));
  96. iimSet("msg", "Client could not be found from invoice ID.");
  97. iimPlay("ASO/cb_3.iim");
  98.  
  99. // ***** If a valid client ID is identified, proceed with processing.
  100.  
  101. } else {
  102.  
  103. // ***** Extract the invoice status.
  104.  
  105. iimPlay("ASO/cb_4.iim");
  106. inv_st = iimGetLastExtract();
  107.  
  108. if (inv_st != "Paid") {
  109.  
  110. // ***** If invoice status is not paid, may have already been processed. No further action taken to prevent over refunds and duplicate tickets.
  111.  
  112. iimSet("src_fl_p", String(src_fl_p));
  113. iimSet("src_fl_o", String(src_fl_o));
  114. iimSet("inv_id", String(inv_id));
  115. iimSet("msg", "Invoice not marked as paid. Manual review required.");
  116. iimPlay("ASO/cb_5.iim");
  117.  
  118. } else {
  119.  
  120. // ***** If invoice status is paid, we will process a refund, ticket the customer, suspend the services and billing.
  121.  
  122. // ***** Count the number of line items on the invoice.
  123.  
  124. iimPlay("CODE:TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTM");
  125. var w_pge = iimGetLastExtract();
  126. var l_itm = w_pge.split('description[').length - 1;
  127.  
  128. // ***** While the count of line items > 0 we will pull the data for each line item and store it in an array.
  129.  
  130. for ( l_itm_m = 1; l_itm_m <= l_itm; l_itm_m ++) {
  131. iimSet("l_itm_m",l_itm_m);
  132. var desc_get;
  133. desc_get = "CODE:";
  134. desc_get = desc_get+"TAG POS={{l_itm_m}} TYPE=TEXTAREA ATTR=NAME:description[*] EXTRACT=TXT";
  135. iimPlay(desc_get);
  136. desc_itm.push(iimGetLastExtract());
  137. }
  138.  
  139. // ***** Mark the refund on the invoice from the chargeback.
  140. // ***** Close the account and remove credit cards.
  141. // ***** Invoice the $25 chargeback fee.
  142. // ***** Move to the account page and get the customers email.
  143. iimSet("cli_id", String(cli_id));
  144. iimSet("inv_id", String(inv_id));
  145. iimPlay("ASO/cb_6.iim");
  146. cli_eml = iimGetLastExtract()
  147.  
  148. // ***** Suspend the services on the account.
  149.  
  150. for ( l_itm_m = 1; l_itm_m <= l_itm; l_itm_m ++) {
  151.  
  152. itm_txt = desc_itm[l_itm_m-1];
  153. var lastIndex = itm_txt.lastIndexOf(" (");
  154. itm_txt = itm_txt.substring(0, lastIndex);
  155.  
  156. if ( desc_itm[l_itm_m-1].startsWith("Addon") ) {
  157.  
  158. itm_txt = itm_txt.split(" - ").slice(1).join(" - ");
  159. // ***** Cancelling addons.
  160. iimSet("itm_txt", itm_txt);
  161. iimSet("cli_id", String(cli_id));
  162. iimPlay("ASO/cb_7.iim");
  163.  
  164. } else if ( desc_itm[l_itm_m-1].startsWith("Domain") ) {
  165.  
  166. //Do nothing.
  167.  
  168. } else {
  169.  
  170. // ***** Suspending services.
  171. iimSet("itm_txt", itm_txt);
  172. iimSet("cli_id", String(cli_id));
  173. iimPlay("ASO/cb_8.iim");
  174.  
  175. }
  176.  
  177. }
  178.  
  179. // ***** Generate customer ticket.
  180.  
  181. iimSet("cli_eml", String(cli_eml));
  182. var g_gen_tkt;
  183. iimPlay("ASO/cb_9.iim");
  184. cli_tkt = iimGetLastExtract();
  185. cli_tkt = cli_tkt.split('/').pop();
  186.  
  187. // ***** Add admin note to ticket and output results to output file.
  188. iimSet("cli_id", String(cli_id));
  189. iimSet("cli_tkt", String(cli_tkt));
  190. iimSet("inv_id", String(inv_id));
  191. iimSet("msg", "Client processed for chargeback/suspension.");
  192. iimSet("cli_tkt", String(cli_tkt));
  193. iimSet("desc_itm", String(desc_itm));
  194. iimSet("src_fl_p", String(src_fl_p));
  195. iimSet("src_fl_o", String(src_fl_o));
  196. iimPlay("ASO/cb_10.iim");
  197.  
  198. // ***** End master loop.
  199.  
  200. }
  201.  
  202. // ***** Script has finished, notify user.
  203.  
  204. alert ( "Processing complete. See results file. "+src_fl_p+src_fl_o );
Runtime error #stdin #stdout #stderr 0s 105856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:204:72 SyntaxError: missing } in compound statement:
prog.js:204:72 cessing complete.  See results file.  "+src_fl_p+src_fl_o );
prog.js:204:72 ............................................................^