feature/RVRNEXT-7-calculate-balance-for-community-members #37
@ -1,6 +1,7 @@
 | 
				
			|||||||
<?php namespace RVR\Controller;
 | 
					<?php namespace RVR\Controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use DateTime;
 | 
					use DateTime;
 | 
				
			||||||
 | 
					use RVR\Finance\BalanceCalculator;
 | 
				
			||||||
use RVR\PersistentData\Model\Community;
 | 
					use RVR\PersistentData\Model\Community;
 | 
				
			||||||
use RVR\PersistentData\Model\CommunityMember;
 | 
					use RVR\PersistentData\Model\CommunityMember;
 | 
				
			||||||
use RVR\PersistentData\Model\Currency;
 | 
					use RVR\PersistentData\Model\Currency;
 | 
				
			||||||
@ -50,11 +51,34 @@ class CommunityController implements IAuthenticationRequired
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        \Container::$persistentDataManager->loadRelationsFromDb($community, false, ['main_currency']);
 | 
					        \Container::$persistentDataManager->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', [
 | 
					        return new HtmlContent('communities/community', [
 | 
				
			||||||
            'community' => $community,
 | 
					            'community' => $community,
 | 
				
			||||||
            'members' => $this->getMembers($community),
 | 
					            'members' => $this->getMembers($community),
 | 
				
			||||||
            'currencies' => $this->getCurrencies($community),
 | 
					            'currencies' => $this->getCurrencies($community),
 | 
				
			||||||
            'upcomingEvents' => [],
 | 
					            'upcomingEvents' => [],
 | 
				
			||||||
 | 
					            'debtUsers' => $debtUsers,
 | 
				
			||||||
 | 
					            'debtBalance' => $debtBalance,
 | 
				
			||||||
 | 
					            'outstandingUsers' => $outstandingUsers,
 | 
				
			||||||
 | 
					            'outstandingBalance' => $outstandingBalance,
 | 
				
			||||||
 | 
					            'balance' => $balance,
 | 
				
			||||||
            'editPermission' => $ownCommunityMember->getOwner()
 | 
					            'editPermission' => $ownCommunityMember->getOwner()
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user