Skip to content

Firefly III: a personal finances manager

Fixes #151

James Cole1aea4045a3a5
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: