Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
This is a partial fix for issue #151. It does not filter on account selection.
James Coleecefcfabc0b3
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.phpindex ed5bd7dcb7..b767e3d355 100644--- a/app/Http/Controllers/BudgetController.php+++ b/app/Http/Controllers/BudgetController.php@@ -193,7 +193,7 @@ class BudgetController extends Controller/** @var Carbon $start */$start = session('start', Carbon::now()->startOfMonth());/** @var Carbon $end */- $end = session('end', Carbon::now()->endOfMonth());+ $end = session('end', Carbon::now()->endOfMonth());$list = $repository->getWithoutBudget($start, $end);$subTitle = trans(diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.phpindex e08a67bc72..8df13ec46a 100644--- a/app/Http/Controllers/Chart/BudgetController.php+++ b/app/Http/Controllers/Chart/BudgetController.php@@ -259,21 +259,24 @@ class BudgetController extends Controller$currentEnd = clone $currentStart;$currentEnd->endOfYear();- // save to array:+ // basic information:$year = $currentStart->year;- $entry['name'] = $budget->name;+ $entry['name'] = $budget->name ?? (string)trans('firefly.noBudget');$spent = 0;- $budgeted = 0;- if (isset($set[$id]['entries'][$year])) {- $spent = $set[$id]['entries'][$year] * -1;- }-- if (isset($budgetedArray[$id][$year])) {- $budgeted = round($budgetedArray[$id][$year], 2);+ // 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;+ } else {+ if (isset($set[$id]['entries'][$year])) {+ $spent = $set[$id]['entries'][$year] * -1;+ }}+ $budgeted = $budgetedArray[$id][$year] ?? '0';$entry['spent'][$year] = $spent;- $entry['budgeted'][$year] = $budgeted;+ $entry['budgeted'][$year] = round($budgeted, 2);+// jump to next year.$currentStart = clone $currentEnd;diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.phpindex 334bc6c6a7..90a7809637 100644--- a/app/Repositories/Budget/BudgetRepository.php+++ b/app/Repositories/Budget/BudgetRepository.php@@ -463,7 +463,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn** @return string*/- public function getWithoutBudgetSum(Carbon $start, Carbon $end)+ public function getWithoutBudgetSum(Carbon $start, Carbon $end): string{$entry = Auth::user()->transactionjournals()@@ -488,7 +488,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn->transactionTypes([TransactionType::WITHDRAWAL])->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]);if (is_null($entry->journalAmount)) {- return '';+ return '0';}return $entry->journalAmount;diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.phpindex d6ab73938e..99aa34e476 100644--- a/app/Repositories/Budget/BudgetRepositoryInterface.php+++ b/app/Repositories/Budget/BudgetRepositoryInterface.php@@ -171,9 +171,9 @@ interface BudgetRepositoryInterface* @param Carbon $start* @param Carbon $end*- * @return mixed+ * @return string*/- public function getWithoutBudgetSum(Carbon $start, Carbon $end);+ public function getWithoutBudgetSum(Carbon $start, Carbon $end): string;/*** Returns an array with the following key:value pairs: