diff --git a/src/Controller/CommunityController.php b/src/Controller/CommunityController.php index 1a853e9..30b90be 100644 --- a/src/Controller/CommunityController.php +++ b/src/Controller/CommunityController.php @@ -1,6 +1,7 @@ loadRelationsFromDb($community, false, ['main_currency']); + $balanceCalculator = new BalanceCalculator($community); + $debts = $balanceCalculator->calculate(); + $debtUsers = []; + $debtBalance = 0.0; + $outstandingUsers = []; + $outstandingBalance = 0.0; + foreach ($debts as $debt) { + if ($debt['payer']->getId() === \Container::$request->user()->getUniqueId()) { + $debtBalance += $debt['amount']; + $debtUsers[] = $debt; + } + if ($debt['payee']->getId() === \Container::$request->user()->getUniqueId()) { + $outstandingBalance += $debt['amount']; + $outstandingUsers[] = $debt; + } + } + $balance = $outstandingBalance - $debtBalance; + return new HtmlContent('communities/community', [ 'community' => $community, 'members' => $this->getMembers($community), 'currencies' => $this->getCurrencies($community), 'upcomingEvents' => [], + 'debtUsers' => $debtUsers, + 'debtBalance' => $debtBalance, + 'outstandingUsers' => $outstandingUsers, + 'outstandingBalance' => $outstandingBalance, + 'balance' => $balance, 'editPermission' => $ownCommunityMember->getOwner() ]); }