Skip to content

Commit

Permalink
Some extra debugging and a fix for #1825
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Oct 28, 2018
1 parent f90b7be commit bb39781
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/Helpers/Filter/TransferFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ public function filter(Collection $set): Collection
$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;
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/Json/ReconcileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ public function overview(Request $request, Account $account, Carbon $start, Carb
$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');
Expand All @@ -123,25 +125,30 @@ public function overview(Request $request, Account $account, Carbon $start, Carb
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);
}
}

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 */
Expand Down
5 changes: 4 additions & 1 deletion app/Repositories/Journal/JournalRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -594,7 +595,9 @@ public function getTransactionsById(array $transactionIds): Collection
/** @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();
Expand Down

0 comments on commit bb39781

Please sign in to comment.