Updated getTotals to work with JOINS