Skip to content

Instantly share code, notes, and snippets.

@Zoramite
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zoramite/52a19050a6753b5fb492 to your computer and use it in GitHub Desktop.
Save Zoramite/52a19050a6753b5fb492 to your computer and use it in GitHub Desktop.
doTerra Volume History

dōTERRA Wellness Advocate historical volume.

This script is intended to make it easier to retrieve the historical PV, TV, and OV for a wellness advocate. The current system makes it almost impossible to get the historical values past the latest couple of months.

To download a CSV of your historical volumes paste the following into the chrome console when you are logged into the Teams page of the back office.

$('<script src="https://rawgit.com/Zoramite/52a19050a6753b5fb492/raw/volume.js" type="text/javascript"></script>').appendTo($("head"));

Then run the following to download your volume history:

doTerraDownloadVolumes();

You can also download a csv for one of your downline by providing their advocate id to the doTerraDownloadVolumes():

doTerraDownloadVolumes(123456);
(function($) {
var hostname = window.location.hostname;
function getEnrollmentDate(distributorID) {
var deferEnrollment = $.Deferred();
distributorID = distributorID || getDistributorID();
var requests = [];
// Get the enrollment date for distributorID
$.post(
'https://' + hostname + '/index.cfm',
{
Fuseaction: 'evo_Modules.DetailedGenealogy',
TargetID: distributorID,
DETAIL_FOCUSID: distributorID,
DETAIL_START_LEVEL: 0,
DETAIL_END_LEVEL: 0
}
).done(function(data) {
var doc = $(data);
var row = $('#DetailGen' + distributorID, doc);
var enrollDate = $('td', row).slice(3, 4).text().replace(/[^0-9]/g, '');
var year = parseInt(enrollDate.slice(-4));
var month = parseInt(enrollDate.slice(0,2));
deferEnrollment.resolve(year, month);
});
return deferEnrollment;
}
function getVolumes(distributorID) {
var deferVolumes = $.Deferred();
distributorID = distributorID || getDistributorID();
var requests = [];
// Get the enrollment date for distributorID.
getEnrollmentDate(distributorID).done(function(enrollYear, enrollMonth) {
// Get the volume from the enrollment date until last month.
var now = new Date();
// Use the last day of the month.
var previousMonth = new Date(now.getFullYear(), now.getMonth(), -1);
var currentMonth = new Date(enrollYear, enrollMonth, -1);
while(currentMonth <= previousMonth) {
console.log('Retrieving volume for ' + currentMonth);
requests.push(getVolume(distributorID, currentMonth));
// Use the last day of the month.
currentMonth = new Date(
currentMonth.getFullYear(),
currentMonth.getMonth() + 2,
-1);
}
$.when.apply(this, requests).then(function() {
var args = Array.prototype.slice.call(arguments);
deferVolumes.resolve(args);
});
});
return deferVolumes;
}
function getVolume(distributorID, period) {
var deferVolume = $.Deferred();
var year = period.getFullYear();
var month = ('0' + (period.getMonth() + 1)).slice(-2);
var jqxhr = $.post(
'https://' + hostname + '/index.cfm',
{
Fuseaction: 'evo_Modules.Qualifications',
TargetID: distributorID,
viewpvdate: year + month
}
);
jqxhr.done(function(data, textStatus, jqXHR) {
var doc = $(data);
var stat = {};
stat.period = year + month;
stat.lastDay = month + '/' + period.getDate() + '/' + year;
stat.pv = parseFloat($('.PVClick table table', doc)
.attr('title')
.replace(/[^0-9\.]/g, '')
.match(/([0-9]*[\.,][0-9]*)$/)[1]);
$("font[color]", doc).each(function() {
var ele = $(this);
var onclick = ele.parents("[onclick]");
var action = onclick.attr('onclick');
if (action) {
var text = ele.text().replace(/[^0-9\.]/g, '');
if (action.search(/currentfieldlist\=WRK31/) >= 0) {
stat.tv = parseFloat(text);
} else if (action.search(/currentfieldlist\=VOL3/) >= 0) {
stat.ov = parseFloat(text);
}
}
});
deferVolume.resolve(stat);
});
return deferVolume;
}
function downloadVolumes(distributorID) {
distributorID = distributorID || getDistributorID();
getVolumes(distributorID).done(function(volumes) {
volumes.sort(function(a, b){
if(a.period < b.period) return -1;
if(a.period > b.period) return 1;
return 0;
});
var data = [['Month', 'PV', 'TV', 'OV']];
volumes.forEach(function(stat) {
data.push([stat.lastDay, stat.pv, stat.tv, stat.ov]);
});
downloadCSV(distributorID, data);
});
}
function downloadCSV(distributorID, data) {
var csvContent = "data:text/csv;charset=utf-8,";
var rows = [];
data.forEach(function(infoArray, index){
rows.push(infoArray.join(","));
});
csvContent += rows.join('\n');
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", 'volume-' + distributorID + '.csv');
console.log('CSV file downloading...');
link.click();
console.log('CSV file downloaded');
}
// Use the navigation links to return the distributorID
function getDistributorID() {
return $('#nav a')
.attr('onclick')
.match(/DistributorID\=([0-9]*)/i)[1];
}
// Allow for calling externally.
window.doTerraDownloadVolumes = downloadVolumes;
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment