Skip to content

Instantly share code, notes, and snippets.

@jmccaffrey
Created October 5, 2011 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmccaffrey/1264854 to your computer and use it in GitHub Desktop.
Save jmccaffrey/1264854 to your computer and use it in GitHub Desktop.
jquery script to calculate total number of billable and non-billable hours for Freshbooks invoices
//take this script and place it in your firebug or javascript console (when you are on the invoice edit page)
//it will segment billable and non-billable (0.00) and total them up (could be improved to group by rate)
var total=0;
function add_them(index, e){
var num = parseFloat($(e).val());
if (!isNaN(num)) {
total += num;
}
}
//find trs with td and a non-zero or empty hourly rate
var billable = $('tr').has('td.editable').has('input[name="unit_cost[]"][value!="0.00"][value!=""]');
var total=0; //zero out reusable variable
//within that group, go find the hours and total them up
billable.find('input[name="qty[]"]').each(add_them);
var bill_total = total; //copy value before running the next calc
//find trs with td and a zero value hourly rate
var non_billable = $('tr').has('td.editable').has('input[name="unit_cost[]"][value="0.00"]');
var total=0; //zero out reusable variable
non_billable.find('input[name="qty[]"]').each(add_them);
var nonbill_total = total;
//print it out if console is available
if(this.console){
console.log('Billable hours total: ' + bill_total);
console.log('Non-Billable hours total: ' + nonbill_total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment