sql = " SELECT ROUND(COALESCE(SUM(invoiceamount), 0),0) AS invoiced, YEAR(invoicedate) AS invoiceyear FROM invoices WHERE project_id = {$projectID} GROUP BY YEAR(invoicedate) ORDER BY YEAR(invoicedate) "; $invoiced = $this->get_query_result(); return $invoiced; } public function getOutstandingPerProject( $projectID ) { $this->sql = " SELECT (own_revenue + other_revenue) - SUM(INV.invoiceamount) AS outstanding FROM invoices INV JOIN projects PRJ ON PRJ.id = INV.project_id JOIN offers OFF ON PRJ.id = OFF.project_id WHERE PRJ.id = {$projectID} "; $invoiced = $this->get_query_row( 'outstanding' ); return $invoiced; } }