diff --git a/app/Helpers/Filter/TransferFilter.php b/app/Helpers/Filter/TransferFilter.php index 159096792b..ab606ca1f2 100644 --- a/app/Helpers/Filter/TransferFilter.php +++ b/app/Helpers/Filter/TransferFilter.php @@ -63,10 +63,14 @@ class TransferFilter implements FilterInterface $key = $journalId . '-' . implode(',', $transactionIds) . '-' . implode(',', $accountIds) . '-' . $amount; Log::debug(sprintf('Current transaction key is "%s"', $key)); if (!isset($count[$key])) { + Log::debug(sprintf('First instance of transaction #%d, add it.', $transaction->id)); // not yet counted? add to new set and count it: $new->push($transaction); $count[$key] = 1; } + if (isset($count[$key])) { + Log::debug(sprintf('Second instance of transaction #%d, do NOT add it.', $transaction->id)); + } } return $new; diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index 1b1309e0bd..3296e922a3 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -111,9 +111,11 @@ class ReconcileController extends Controller $cleared = $this->repository->getTransactionsById($clearedIds); $countCleared = 0; + Log::debug('Start transaction loop'); /** @var Transaction $transaction */ foreach ($transactions as $transaction) { // find the account and opposing account for this transaction + Log::debug(sprintf('Now at transaction #%d: %s', $transaction->journal_id, $transaction->description)); $srcAccount = $this->accountRepos->findNull((int)$transaction->account_id); $dstAccount = $this->accountRepos->findNull((int)$transaction->opposing_account_id); $srcCurrency = (int)$this->accountRepos->getMetaValue($srcAccount, 'currency_id'); @@ -123,10 +125,12 @@ class ReconcileController extends Controller if ($account->id === $srcAccount->id) { // source, and it matches the currency id or is 0 if ($srcCurrency === $transaction->transaction_currency_id || 0 === $srcCurrency) { + Log::debug(sprintf('Source matches currency: %s', $transaction->transaction_amount)); $amount = bcadd($amount, $transaction->transaction_amount); } // destination, and it matches the foreign currency ID. if ($srcCurrency === $transaction->foreign_currency_id) { + Log::debug(sprintf('Source matches foreign currency: %s', $transaction->transaction_foreign_amount)); $amount = bcadd($amount, $transaction->transaction_foreign_amount); } } @@ -134,14 +138,17 @@ class ReconcileController extends Controller if ($account->id === $dstAccount->id) { // destination, and it matches the currency id or is 0 if ($dstCurrency === $transaction->transaction_currency_id || 0 === $dstCurrency) { - $amount = bcadd($amount, $transaction->transaction_amount); + Log::debug(sprintf('Destination matches currency: %s', $transaction->transaction_amount)); + $amount = bcadd($amount, app('steam')->negative($transaction->transaction_amount)); } // destination, and it matches the foreign currency ID. if ($dstCurrency === $transaction->foreign_currency_id) { + Log::debug(sprintf('Destination matches foreign currency: %s', $transaction->transaction_foreign_amount)); $amount = bcadd($amount, $transaction->transaction_foreign_amount); } } } + Log::debug('End transaction loop'); // make sure amount is positive. $amount = app('steam')->positive($amount); /** @var Transaction $transaction */ diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 4f432c322e..0b42bdfb3d 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -28,6 +28,7 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TransactionJournalFactory; use FireflyIII\Factory\TransactionJournalMetaFactory; use FireflyIII\Helpers\Collector\TransactionCollectorInterface; +use FireflyIII\Helpers\Filter\InternalTransferFilter; use FireflyIII\Helpers\Filter\TransferFilter; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; @@ -594,7 +595,9 @@ class JournalRepository implements JournalRepositoryInterface /** @var TransactionCollectorInterface $collector */ $collector = app(TransactionCollectorInterface::class); $collector->setUser($this->user); - $collector->addFilter(TransferFilter::class); + $collector->setAllAssetAccounts(); + $collector->removeFilter(InternalTransferFilter::class); + //$collector->addFilter(TransferFilter::class); $collector->setJournals($journals)->withOpposingAccount(); return $collector->getTransactions();