Service/Account/Balance/Calc/A/Z/CollectTransactions.php
public function exec($balances, $trans)
    {
        $result = [];
        foreach ($trans as $one) {
            $accDebit = $one->getDebitAccId();
            $accCredit = $one->getCreditAccId();
            $timestamp = $one->getDateApplied();
            $value = $one->getValue();
            /* date_applied is in UTC format */
            $date = $this->hlpPeriod->getPeriodCurrent($timestamp);
            /**
             * Process debit account:
             */
            /** @var EBalance $entry Get balance on the transaction date (calculated or new) */
            $entry = $this->getBalanceEntry($balances, $result, $accDebit, $date);
            /* change total debit for the entry */
            $totalDebit = $entry->getTotalDebit() + $value;
            $entry->setTotalDebit($totalDebit);
            /* change close balance for the entry */
            $balanceClose = $entry->getBalanceClose() - $value;
            $entry->setBalanceClose($balanceClose);
            /* update calculated entries for result balances */
            $result[$accDebit][$date] = $entry;
            /* update current balances in the working var */
            if (isset($balances[$accDebit])) {
                $balances[$accDebit] -= $value;
            } else {
                $balances[$accDebit] = -$value;
            }
            /**
             * Process credit account:
             */
            /* get balance on the transaction date (calculated or new) */
            $entry = $this->getBalanceEntry($balances, $result, $accCredit, $date);
            /* change total credit for the entry */
            $totalCredit = $entry->getTotalCredit() + $value;
            $entry->setTotalCredit($totalCredit);
            /* change close balance for the entry */
            $balanceClose = $entry->getBalanceClose() + $value;
            $entry->setBalanceClose($balanceClose);
            /* update calculated entries for result balances */
            $result[$accCredit][$date] = $entry;
            /* update current balances in the working var */
            if (isset($balances[$accCredit])) {
                $balances[$accCredit] += $value;
            } else {
                $balances[$accCredit] = $value;
            }
        }
        return $result;
    }
public function exec($balances, $trans)
    {
        $result = [];
        foreach ($trans as $one) {
            $accDebit = $one->getDebitAccId();
            $accCredit = $one->getCreditAccId();
            $timestamp = $one->getDateApplied();
            $value = $one->getValue();
            /* date_applied is in UTC format */
            $date = $this->hlpPeriod->getPeriodCurrent($timestamp);
            /**
             * Process debit account:
             */
            /** @var EBalance $entry Get balance on the transaction date (calculated or new) */
            $entry = $this->getBalanceEntry($balances, $result, $accDebit, $date);
            /* change total debit for the entry */
            $totalDebit = $entry->getTotalDebit() + $value;
            $entry->setTotalDebit($totalDebit);
            /* change close balance for the entry */
            $balanceClose = $entry->getBalanceClose() - $value;
            $entry->setBalanceClose($balanceClose);
            /* update calculated entries for result balances */
            $result[$accDebit][$date] = $entry;
            /* update current balances in the working var */
            if (isset($balances[$accDebit])) {
                $balances[$accDebit] -= $value;
            } else {
                $balances[$accDebit] = -$value;
            }
            /**
             * Process credit account:
             */
            /* get balance on the transaction date (calculated or new) */
            $entry = $this->getBalanceEntry($balances, $result, $accCredit, $date);
            /* change total credit for the entry */
            $totalCredit = $entry->getTotalCredit() + $value;
            $entry->setTotalCredit($totalCredit);
            /* change close balance for the entry */
            $balanceClose = $entry->getBalanceClose() + $value;
            $entry->setBalanceClose($balanceClose);
            /* update calculated entries for result balances */
            $result[$accCredit][$date] = $entry;
            /* update current balances in the working var */
            if (isset($balances[$accCredit])) {
                $balances[$accCredit] += $value;
            } else {
                $balances[$accCredit] = $value;
            }
        }
        return $result;
    }
Collect transactions and compose daily balances updates.

@param array $balances [accId => balance]
@param ETrans[] $trans
@return array [accId => EBalance[]]
@throws \Exception