From 69553b138b0032ba903b5e639b636ac043fe0b32 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 15 Dec 2015 12:52:42 +0100 Subject: [PATCH] First calculations for multi-year budget chart. --- app/Http/Controllers/Chart/BudgetController.php | 15 +++++++++++++-- app/Http/routes.php | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 864e910cc4..2cdba30b4e 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -47,14 +47,25 @@ class BudgetController extends Controller public function multiYear(BudgetRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets) { $currentStart = clone $start; + $collection = new Collection; while ($currentStart < $end) { $currentEnd = clone $currentStart; $currentEnd->endOfYear(); - //echo 'now for '.$currentStart->format('Ymd').' to '.$currentEnd->format('Ymd').'
'; - //epository->balanceInPeriod() + echo 'now for ' . $currentStart->format('Ymd') . ' to ' . $currentEnd->format('Ymd') . '
'; + /** @var Budget $budget */ + foreach ($budgets as $budget) { + if (is_null($budget->id)) { + $name = trans('firefly.noBudget'); + $sum = $repository->getWithoutBudgetSum($currentStart, $currentEnd); + } else { + $name = $budget->name; + $sum = $repository->balanceInPeriodForList($budget, $currentStart, $currentEnd, $accounts); + } + echo $name.': '.$sum.'
'; + } // do something for all budgets. // jump to next year. diff --git a/app/Http/routes.php b/app/Http/routes.php index 4599887047..1e3f4c109a 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -60,6 +60,12 @@ Route::bind( ->whereIn('budgets.id', $ids) ->where('budgets.user_id', Auth::user()->id) ->get(['budgets.*']); + + // add empty budget if applicable. + if(in_array('0', $ids)) { + $object->push(new Budget); + } + if ($object->count() > 0) { return $object; }