From 480e70dfac19ca3b90e840dfb90490be2210c9a9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 20 May 2016 18:30:48 +0200 Subject: [PATCH] Sharper spent in period. [skip ci] --- app/Repositories/Account/AccountRepository.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index ca55db6d94..ef95442a73 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -127,9 +127,14 @@ class AccountRepository implements AccountRepositoryInterface $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0); } ); + $query->leftJoin( + 'transactions as source', function (JoinClause $join) { + $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0); + } + ); - // should this not be a XOR query? $query->whereIn('destination.account_id', $accountIds); + $query->whereNotIn('source.account_id', $accountIds); } // remove group by