From 1aea4045a3a5e6de683c2811b0c392e9ce361437 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Mar 2016 07:44:20 +0100 Subject: [PATCH] Fixes #151 --- app/Helpers/Report/BudgetReportHelper.php | 2 +- app/Http/Controllers/Chart/BudgetController.php | 4 ++-- app/Repositories/Budget/BudgetRepository.php | 9 ++++++--- app/Repositories/Budget/BudgetRepositoryInterface.php | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/Helpers/Report/BudgetReportHelper.php b/app/Helpers/Report/BudgetReportHelper.php index 57cd56d0c3..338d6b6d2b 100644 --- a/app/Helpers/Report/BudgetReportHelper.php +++ b/app/Helpers/Report/BudgetReportHelper.php @@ -97,7 +97,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface } // stuff outside of budgets: - $noBudget = $repository->getWithoutBudgetSum($start, $end); + $noBudget = $repository->getWithoutBudgetSum($accounts, $start, $end); $budgetLine = new BudgetLine; $budgetLine->setOverspent($noBudget); $budgetLine->setSpent($noBudget); diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 8df13ec46a..5752890878 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -200,7 +200,7 @@ class BudgetController extends Controller $allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]); } - $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); + $noBudgetExpenses = $repository->getWithoutBudgetSum($accounts, $start, $end); $allEntries->push([trans('firefly.noBudget'), '0', '0', $noBudgetExpenses, '0', '0']); $data = $this->generator->frontpage($allEntries); $cache->store($data); @@ -266,7 +266,7 @@ class BudgetController extends Controller // this might be a good moment to collect no budget stuff. if (is_null($budget->id)) { // get without budget sum in range: - $spent = $repository->getWithoutBudgetSum($currentStart, $currentEnd) * -1; + $spent = $repository->getWithoutBudgetSum($accounts, $currentStart, $currentEnd) * -1; } else { if (isset($set[$id]['entries'][$year])) { $spent = $set[$id]['entries'][$year] * -1; diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 21072a82df..3def0840c6 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -472,13 +472,15 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn } /** - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return string */ - public function getWithoutBudgetSum(Carbon $start, Carbon $end): string + public function getWithoutBudgetSum(Collection $accounts, Carbon $start, Carbon $end): string { + $ids = $accounts->pluck('id')->toArray(); $entry = $this->user ->transactionjournals() ->whereNotIn( @@ -499,6 +501,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); } ) + ->whereIn('transactions.account_id', $ids) ->transactionTypes([TransactionType::WITHDRAWAL]) ->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]); if (is_null($entry->journalAmount)) { diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 36c60ccabc..3765508d6f 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -168,12 +168,13 @@ interface BudgetRepositoryInterface public function getWithoutBudget(Carbon $start, Carbon $end); /** + * @param Collection $accounts * @param Carbon $start * @param Carbon $end * * @return string */ - public function getWithoutBudgetSum(Carbon $start, Carbon $end): string; + public function getWithoutBudgetSum(Collection $accounts, Carbon $start, Carbon $end): string; /** * Returns an array with the following key:value pairs: