feature/RVRNEXT-43-split-transactions #59

Merged
bence merged 9 commits from feature/RVRNEXT-43-split-transactions into master 2023-06-17 14:59:09 +02:00
Showing only changes of commit 1d0a2b09d5 - Show all commits

View File

@ -1,5 +1,6 @@
<?php namespace RVR\Finance;
use Container;
use RVR\PersistentData\Model\Community;
use RVR\Repository\CommunityMemberRepository;
use RVR\Repository\TransactionRepository;
@ -56,13 +57,18 @@ class BalanceCalculator
private function sumTransactions(): void
{
$membersCount = count($this->members);
$transactions = $this->transactionRepository->getAllByCommunity($this->community, true, ['currency']);
$transactions = iterator_to_array($this->transactionRepository->getAllByCommunity($this->community, true, ['currency']));
Container::$persistentDataManager->loadMultiRelationsFromDb($transactions, 'payees');
foreach ($transactions as $transaction) {
$sum = $this->exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate());
$payees = $transaction->getPayees();
$payeeCount = count($payees);
if ($transaction->getPayeeUserId()) {
$this->payments[$transaction->getPayerUserId()][$transaction->getPayeeUserId()] += $sum;
if ($payeeCount > 0) {
foreach ($payees as $payee) {
$this->payments[$transaction->getPayerUserId()][$payee->getUserId()] += $sum / $payeeCount;
}
} else {
foreach ($this->members as $payeeUserId => $member) {
$this->payments[$transaction->getPayerUserId()][$payeeUserId] += $sum / $membersCount;