From c4818334e78d086480838fb67cae6be430e05092 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 20 May 2016 18:29:51 +0200 Subject: [PATCH] Sharper spent in period. [skip ci] --- app/Http/Controllers/Chart/ReportController.php | 4 ++-- app/Repositories/Account/AccountRepository.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php index 88651bda80..3824bfccea 100644 --- a/app/Http/Controllers/Chart/ReportController.php +++ b/app/Http/Controllers/Chart/ReportController.php @@ -118,8 +118,8 @@ class ReportController extends Controller while ($currentStart <= $end) { $currentEnd = Navigation::endOfPeriod($currentStart, '1M'); $date = $currentStart->format('Y-m'); - $spent = $repository->expensesInPeriod($accounts, $currentStart, $currentEnd); - $earned = $repository->incomesInPeriod($accounts, $currentStart, $currentEnd); + $spent = $repository->spentInPeriod($accounts, $currentStart, $currentEnd); + $earned = $repository->earnedInPeriod($accounts, $currentStart, $currentEnd); $spentArray[$date] = bcmul($spent, '-1'); $earnedArray[$date] = $earned; $currentStart = Navigation::addPeriod($currentStart, '1M', 0); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 170e97086a..ca55db6d94 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -127,6 +127,8 @@ class AccountRepository implements AccountRepositoryInterface $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0); } ); + + // should this not be a XOR query? $query->whereIn('destination.account_id', $accountIds); } @@ -559,7 +561,13 @@ class AccountRepository implements AccountRepositoryInterface $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0); } ); + $query->leftJoin( + 'transactions as destination', function (JoinClause $join) { + $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0); + } + ); $query->whereIn('source.account_id', $accountIds); + $query->whereNotIn('destination.account_id', $accountIds); } // remove group by