// ***** Variables used by the main script and linked to the sub scripts.
// Full file name/path, file name, file path.
var src_fl, src_fl_t, src_fl_p;
// Brand
var brand, brand_b, brand_t;
// Operating system slash variable.
var os_t;
// Length of spreadsheet.
var i, l;
// ***** Define the URL's to use based upon the input brand.
brand = prompt("Which brand is this for: ASO, CTX, H9, SEOH, SEOW, ARVX");
switch (brand) {
case 'ASO':
brand_b = "https://c...content-available-to-author-only...e.com/admin/index.php";
brand_t = "%2";
break;
case 'CTX':
throw new Error("The script is not configured for this brand yet.");
break;
case 'H9':
throw new Error("The script is not configured for this brand yet.");
break;
case 'SEOH':
throw new Error("The script is not configured for this brand yet.");
break;
case 'SEOW':
throw new Error("The script is not configured for this brand yet.");
break;
case 'ARVX':
throw new Error("The script is not configured for this brand yet.");
break;
default:
throw new Error("You must specify a brand.");
break;
}
// ***** Define the file to use and number of lines in the file.
// ***** Checks for slash direction to ensure properly set going forward for windows or mac/linux.
src_fl = prompt("Please specify the file name and file path to run on.", "/home/user/doc/myfile.csv");
if (src_fl.lastIndexOf('/') >= 1) {
src_fl_t = src_fl.split('/').pop();
src_fl_p = src_fl.split('/');
src_fl_p = src_fl_p.slice(0, src_fl_p.length - 1).join("/") + "/";
src_fl_o = "out_" + src_fl_t;
os_t = "/";
} else {
src_fl_t = src_fl.split("\\").pop();
src_fl_p = src_fl.split('/');
src_fl_p = src_fl_p.slice(0, src_fl_p.length - 1).join("\\") + "\\";
src_fl_o = "out_" + src_fl_t;
os_t = "\\";
}
i = prompt("How many lines are in the file including the header?");
// ***** Master loop based on the number of lines input.
// ***** Pull the invoice ID from the spreadsheet.
for (l = 2; l <= i; l++) {
// ***** Reset these variables on every iteration to prevent corrupted data.
// Invoice id, client id, invoice status.
var inv_id, cli_id, inv_st
// Message variable for results output.
var msg;
// Item description array.
var desc_itm = [];
var itm_txt;
// Client ticket.
var cli_tkt;
iimSet("i", String(l));
iimSet("src_fl", String(src_fl));
iimPlay("ASO/cb_1.iim");
inv_id = iimGetLastExtract();
// ***** Search for the client in WHMCS based on the invoice ID.
iimSet("inv_id", String(inv_id));
iimSet("brand_b", String(brand_b));
iimPlay("ASO/cb_2.iim");
cli_id = iimGetLastExtract();
// ***** If no valid client ID identified, output an error to the file and proceed to next invoice entry.
if (cli_id === parseInt(cli_id, 10)) {
iimSet("src_fl_p", String(src_fl_p));
iimSet("src_fl_o", String(src_fl_o));
iimSet("inv_id", String(inv_id));
iimSet("msg", "Client could not be found from invoice ID.");
iimPlay("ASO/cb_3.iim");
// ***** If a valid client ID is identified, proceed with processing.
} else {
// ***** Extract the invoice status.
iimPlay("ASO/cb_4.iim");
inv_st = iimGetLastExtract();
if (inv_st != "Paid") {
// ***** If invoice status is not paid, may have already been processed. No further action taken to prevent over refunds and duplicate tickets.
iimSet("src_fl_p", String(src_fl_p));
iimSet("src_fl_o", String(src_fl_o));
iimSet("inv_id", String(inv_id));
iimSet("msg", "Invoice not marked as paid. Manual review required.");
iimPlay("ASO/cb_5.iim");
} else {
// ***** If invoice status is paid, we will process a refund, ticket the customer, suspend the services and billing.
// ***** Count the number of line items on the invoice.
iimPlay("CODE:TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTM");
var w_pge = iimGetLastExtract();
var l_itm = w_pge.split('description[').length - 1;
// ***** While the count of line items > 0 we will pull the data for each line item and store it in an array.
for ( l_itm_m = 1; l_itm_m <= l_itm; l_itm_m ++) {
iimSet("l_itm_m",l_itm_m);
var desc_get;
desc_get = "CODE:";
desc_get = desc_get+"TAG POS={{l_itm_m}} TYPE=TEXTAREA ATTR=NAME:description[*] EXTRACT=TXT";
iimPlay(desc_get);
desc_itm.push(iimGetLastExtract());
}
// ***** Mark the refund on the invoice from the chargeback.
// ***** Close the account and remove credit cards.
// ***** Invoice the $25 chargeback fee.
// ***** Move to the account page and get the customers email.
iimSet("cli_id", String(cli_id));
iimSet("inv_id", String(inv_id));
iimPlay("ASO/cb_6.iim");
cli_eml = iimGetLastExtract()
// ***** Suspend the services on the account.
for ( l_itm_m = 1; l_itm_m <= l_itm; l_itm_m ++) {
itm_txt = desc_itm[l_itm_m-1];
var lastIndex = itm_txt.lastIndexOf(" (");
itm_txt = itm_txt.substring(0, lastIndex);
if ( desc_itm[l_itm_m-1].startsWith("Addon") ) {
itm_txt = itm_txt.split(" - ").slice(1).join(" - ");
// ***** Cancelling addons.
iimSet("itm_txt", itm_txt);
iimSet("cli_id", String(cli_id));
iimPlay("ASO/cb_7.iim");
} else if ( desc_itm[l_itm_m-1].startsWith("Domain") ) {
//Do nothing.
} else {
// ***** Suspending services.
iimSet("itm_txt", itm_txt);
iimSet("cli_id", String(cli_id));
iimPlay("ASO/cb_8.iim");
}
}
// ***** Generate customer ticket.
iimSet("cli_eml", String(cli_eml));
var g_gen_tkt;
iimPlay("ASO/cb_9.iim");
cli_tkt = iimGetLastExtract();
cli_tkt = cli_tkt.split('/').pop();
// ***** Add admin note to ticket and output results to output file.
iimSet("cli_id", String(cli_id));
iimSet("cli_tkt", String(cli_tkt));
iimSet("inv_id", String(inv_id));
iimSet("msg", "Client processed for chargeback/suspension.");
iimSet("cli_tkt", String(cli_tkt));
iimSet("desc_itm", String(desc_itm));
iimSet("src_fl_p", String(src_fl_p));
iimSet("src_fl_o", String(src_fl_o));
iimPlay("ASO/cb_10.iim");
// ***** End master loop.
}
// ***** Script has finished, notify user.
alert ( "Processing complete. See results file. "+src_fl_p+src_fl_o );