From 8f5289b7dc5db89961805f4abd3f22107c9a7108 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 15 Feb 2017 21:55:50 +0100 Subject: [PATCH] Fixed some transaction list filter issues. --- app/Helpers/Collector/JournalCollector.php | 14 +++++---- .../Controllers/TransactionController.php | 31 ++++++------------- app/Support/Twig/General.php | 15 +++++++++ resources/views/list/journals-tasker.twig | 21 ++++++++++--- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/app/Helpers/Collector/JournalCollector.php b/app/Helpers/Collector/JournalCollector.php index f1de985b9e..945f604f6c 100644 --- a/app/Helpers/Collector/JournalCollector.php +++ b/app/Helpers/Collector/JournalCollector.php @@ -506,6 +506,7 @@ class JournalCollector implements JournalCollectorInterface { $this->joinOpposingTables(); + /** $accountIds = $this->accountIds; $this->query->where( function (EloquentBuilder $q1) use ($accountIds) { @@ -535,6 +536,7 @@ class JournalCollector implements JournalCollectorInterface ); } ); + * **/ return $this; } @@ -637,12 +639,12 @@ class JournalCollector implements JournalCollectorInterface continue; } // make property string: - $journalId = $transaction->transaction_journal_id; - $amount = Steam::positive($transaction->transaction_amount); - $source = $transaction->account_id; - $dest = $transaction->opposing_account_id; - $key = $journalId . $source . $dest . $amount; - + $journalId = $transaction->transaction_journal_id; + $amount = Steam::positive($transaction->transaction_amount); + $accountIds = [intval($transaction->account_id), intval($transaction->opposing_account_id)]; + sort($accountIds); + $key = $journalId . '-' . join(',', $accountIds) . '-' . $amount; + Log::debug(sprintf('Key is %s', $key)); if (!isset($count[$key])) { // not yet counted? add to new set and count it: $new->push($transaction); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 3557144c94..b0ef6013ab 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -73,15 +73,10 @@ class TransactionController extends Controller /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); - $collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts(); - $collector->setRange($start, $end)->withBudgetInformation()->withCategoryInformation(); - - // do not filter transfers if $what = transfer. - if (!in_array($what, ['transfer', 'transfers'])) { - Log::debug('Also get opposing account info.'); - $collector->withOpposingAccount(); - } - + $collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->withBudgetInformation() + ->withCategoryInformation(); + $collector->withOpposingAccount(); + $collector->disableInternalFilter(); $journals = $collector->getPaginatedJournals(); $journals->setPath('transactions/' . $what); @@ -122,14 +117,11 @@ class TransactionController extends Controller $subTitle = sprintf('%s (%s)', trans('firefly.title_' . $what), strtolower(trans('firefly.everything'))); $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page')); + /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->withBudgetInformation()->withCategoryInformation(); - - // do not filter transfers if $what = transfer. - if (!in_array($what, ['transfer', 'transfers'])) { - Log::debug('Also get opposing account info.'); - $collector->withOpposingAccount(); - } + $collector->withOpposingAccount(); + $collector->disableInternalFilter(); $journals = $collector->getPaginatedJournals(); $journals->setPath('transactions/' . $what . '/all'); @@ -165,13 +157,8 @@ class TransactionController extends Controller $collector->setUser(auth()->user()); $collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts(); $collector->setRange($start, $end)->withBudgetInformation()->withCategoryInformation(); - - // do not filter transfers if $what = transfer. - if (!in_array($what, ['transfer', 'transfers'])) { - Log::debug('Also get opposing account info.'); - $collector->withOpposingAccount(); - } - + $collector->withOpposingAccount(); + $collector->disableInternalFilter(); $journals = $collector->getPaginatedJournals(); $journals->setPath('transactions/' . $what . '/' . $date); diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index cfd98fcafc..5d339960fa 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -17,6 +17,7 @@ use Carbon\Carbon; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; use Route; +use Steam; use Twig_Extension; use Twig_SimpleFilter; use Twig_SimpleFunction; @@ -43,6 +44,7 @@ class General extends Twig_Extension $this->balance(), $this->formatFilesize(), $this->mimeIcon(), + ]; } @@ -59,6 +61,7 @@ class General extends Twig_Extension $this->env(), $this->getAmountFromJournal(), $this->activeRouteStrict(), + $this->steamPositive(), $this->activeRoutePartial(), $this->activeRoutePartialWhat(), ]; @@ -288,6 +291,18 @@ class General extends Twig_Extension ); } + /** + * @return Twig_SimpleFunction + */ + protected function steamPositive() + { + return new Twig_SimpleFunction( + 'steam_positive', function (string $str): string { + return Steam::positive($str); + } + ); + } + /** * @return Twig_SimpleFunction */ diff --git a/resources/views/list/journals-tasker.twig b/resources/views/list/journals-tasker.twig index 184ab9431f..7502719e27 100644 --- a/resources/views/list/journals-tasker.twig +++ b/resources/views/list/journals-tasker.twig @@ -33,7 +33,11 @@ -
{% if sorting %}{% endif %}
+
{% if sorting %}{% endif %}
@@ -58,10 +62,17 @@ - - {{ formatByCode(transaction.transaction_currency_code, transaction.transaction_amount) }} - - {{ optionalJournalAmount(transaction.journal_id, transaction.transaction_amount, transaction.transaction_currency_code, transaction.transaction_type_type) }} + {% if transaction.transaction_type_type == 'Transfer' %} + + {{ formatByCode(transaction.transaction_currency_code, steam_positive(transaction.transaction_amount)) }} + + {{ optionalJournalAmount(transaction.journal_id, transaction.transaction_amount, transaction.transaction_currency_code, transaction.transaction_type_type) }} + {% else %} + + {{ formatByCode(transaction.transaction_currency_code, transaction.transaction_amount) }} + + {{ optionalJournalAmount(transaction.journal_id, transaction.transaction_amount, transaction.transaction_currency_code, transaction.transaction_type_type) }} + {% endif %}