Skip to content

Instantly share code, notes, and snippets.

@ryanmasondavies
Created May 3, 2017 17:15
Show Gist options
  • Save ryanmasondavies/72c8ace496f27f64da6835e412023539 to your computer and use it in GitHub Desktop.
Save ryanmasondavies/72c8ace496f27f64da6835e412023539 to your computer and use it in GitHub Desktop.
On the 'new invoice' page, run this JS to round hours.
var nodes = document.getElementsByName("qty[]");
var index;
for (index = 0; index < nodes.length; ++index) {
var node = nodes[index];
if (node.getAttribute("title") == "Task hours") {
var nonRoundedValueAsString = node.getAttribute("value");
var nonRoundedValue = Number(nonRoundedValueAsString);
var roundedValue = (Math.round(nonRoundedValue * 4) / 4).toFixed(2);
console.log(nonRoundedValue + " => " + roundedValue);
node.value = roundedValue.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment