getProjects(); $currentFinancialYear = 0; $totalRevenues = 0; $totalOwp = 0; $ownRevenue = 0; $available = 0; foreach ( $projects as $project ) { $revenues = 0; foreach ( $project['employees'] as $employee ) { $revenues += $employee['revenues']; } $currentFinancialYear += $project['current_financial_year']; $owp = $project['own_revenue'] - $revenues; $owp = $owp > 0 ? $owp : 0; $totalOwp += $owp; $ownRevenue += $project['own_revenue']; $totalRevenues += $revenues; $available += $project['budgetAvailable']; } $outstandings = $this->Invoices_model-> getTotalsOutstandingPerProject(); $this->json( [ 'totalOwp' => round( $totalOwp, 0 ), 'currentFinancialYear' => round( $currentFinancialYear ), 'owpNextyear' => round( $totalOwp - $currentFinancialYear ), 'revenuesNextyear' => round( $totalOwp / 0.4 ), 'totalRevenues' => round( $totalRevenues ), 'outstandings' => $outstandings ] ); } }