feature/RVRNEXT-43-split-transactions #59
@ -1,5 +1,6 @@
|
|||||||
<?php namespace RVR\Finance;
|
<?php namespace RVR\Finance;
|
||||||
|
|
||||||
|
use Container;
|
||||||
use RVR\PersistentData\Model\Community;
|
use RVR\PersistentData\Model\Community;
|
||||||
use RVR\Repository\CommunityMemberRepository;
|
use RVR\Repository\CommunityMemberRepository;
|
||||||
use RVR\Repository\TransactionRepository;
|
use RVR\Repository\TransactionRepository;
|
||||||
@ -56,13 +57,18 @@ class BalanceCalculator
|
|||||||
private function sumTransactions(): void
|
private function sumTransactions(): void
|
||||||
{
|
{
|
||||||
$membersCount = count($this->members);
|
$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) {
|
foreach ($transactions as $transaction) {
|
||||||
$sum = $this->exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate());
|
$sum = $this->exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate());
|
||||||
|
$payees = $transaction->getPayees();
|
||||||
|
$payeeCount = count($payees);
|
||||||
|
|
||||||
if ($transaction->getPayeeUserId()) {
|
if ($payeeCount > 0) {
|
||||||
$this->payments[$transaction->getPayerUserId()][$transaction->getPayeeUserId()] += $sum;
|
foreach ($payees as $payee) {
|
||||||
|
$this->payments[$transaction->getPayerUserId()][$payee->getUserId()] += $sum / $payeeCount;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->members as $payeeUserId => $member) {
|
foreach ($this->members as $payeeUserId => $member) {
|
||||||
$this->payments[$transaction->getPayerUserId()][$payeeUserId] += $sum / $membersCount;
|
$this->payments[$transaction->getPayerUserId()][$payeeUserId] += $sum / $membersCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user