Last active
March 5, 2019 05:20
-
-
Save PaulStovell/ce1dd5d214116681dabe47076c2166c7 to your computer and use it in GitHub Desktop.
A TamperMonkey script that lets you easily find and match multiple transactions in Xero to reconcile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Xero Bank Rec Helper | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://go.xero.com/Bank/BankRec.aspx* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
function main(){ | |
function load() { | |
var $em = jQ("<div class='paulsearch' style='clear: both;'><textarea class='codes' style='width: 200px; height: 150px'></textarea><a class='xbtn blue startbutton'>Start</a></div>"); | |
jQ(".bankrec-search-form").not(".paulified").each(function () { | |
var $form = jQ(this); | |
console.log($form); | |
$form.before($em); | |
var $inserted = jQ(".paulsearch", $form.parent()); | |
console.log($inserted); | |
var codesTextBox = jQ(".codes", $inserted); | |
jQ(".clear", $form).css("display", "none"); | |
var codes = []; | |
var currentCode = null; | |
function nextCode() { | |
if (!currentCode) { | |
currentCode = codes.shift(); | |
if (!currentCode) { | |
return; | |
} | |
codesTextBox.val(codes.join("\n")); | |
console.log("Searching", currentCode); | |
jQ("#searchNameText", $form).val(currentCode); | |
var goButton = jQ(".newsearchcol a.xbtn.blue").filter(function() { return jQ(this).text() == "Go"; }); | |
goButton.click(); | |
} | |
} | |
function awaitResults() { | |
var $resultsTable = jQ("#availableTransactionList", $form.parent()); | |
jQ("div.ref.newpayref", $resultsTable).each(function () { | |
var $ref = jQ(this); | |
var ref = $ref.text(); | |
var isMatch = ref.startsWith(currentCode); | |
if (isMatch) { | |
console.log("found it!"); | |
var parentRow = $ref.parent(".transaction-row"); | |
parentRow.css("background", "lightyellow"); | |
var checkbox = jQ("input.checkbox", parentRow); | |
if (!checkbox.prop("checked")){ | |
checkbox.click(); | |
currentCode = null; | |
} | |
} | |
}); | |
} | |
function autoCheckTimer() { | |
awaitResults(); | |
nextCode(); | |
setTimeout(autoCheckTimer, 500); | |
}; | |
autoCheckTimer(); | |
jQ(".startbutton", $inserted).click(function() { | |
var text = codesTextBox.val(); | |
codes = text.split(/\r?\n/); | |
currentCode = null; | |
}); | |
$form.addClass("paulified"); | |
}); | |
}; | |
function loadOnTimer() { | |
load(); | |
setTimeout(loadOnTimer, 500); | |
} | |
loadOnTimer(); | |
//Jquery Here | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment