From 83f5b5e29397c72ffa73b1630bf58eead759606b Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 Jan 2015 08:54:33 +0100 Subject: [PATCH] New budget charts for year report. --- app/controllers/GoogleChartController.php | 33 ++++++++++++--------- app/controllers/ReportController.php | 4 ++- app/routes.php | 2 +- app/views/reports/year.blade.php | 8 +++-- public/assets/javascript/firefly/reports.js | 6 ++++ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index 7179fdf914..fb21a0b203 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -281,7 +281,7 @@ class GoogleChartController extends BaseController * * @return \Illuminate\Http\JsonResponse */ - public function budgetsAndSpending(Budget $budget) + public function budgetsAndSpending(Budget $budget, $year = 0) { /** @var \FireflyIII\Database\Budget\Budget $budgetRepository */ $budgetRepository = App::make('FireflyIII\Database\Budget\Budget'); @@ -289,21 +289,26 @@ class GoogleChartController extends BaseController $this->_chart->addColumn('Month', 'date'); $this->_chart->addColumn('Budgeted', 'number'); $this->_chart->addColumn('Spent', 'number'); + if ($year == 0) { + // grab the first budgetlimit ever: + $firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first(); + if ($firstLimit) { + $start = new Carbon($firstLimit->startdate); + } else { + $start = Carbon::now()->startOfYear(); + } - // grab the first budgetlimit ever: - $firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first(); - if ($firstLimit) { - $start = new Carbon($firstLimit->startdate); + // grab the last budget limit ever: + $lastLimit = $budget->budgetlimits()->orderBy('startdate', 'DESC')->first(); + if ($lastLimit) { + $end = new Carbon($lastLimit->startdate); + } else { + $end = Carbon::now()->endOfYear(); + } } else { - $start = Carbon::now()->startOfYear(); - } - - // grab the last budget limit ever: - $lastLimit = $budget->budgetlimits()->orderBy('startdate', 'DESC')->first(); - if ($lastLimit) { - $end = new Carbon($lastLimit->startdate); - } else { - $end = Carbon::now()->endOfYear(); + $start = Carbon::createFromDate(intval($year), 1, 1); + $end = clone $start; + $end->endOfYear(); } diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index 9d2f730003..efec329d56 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -126,9 +126,11 @@ class ReportController extends BaseController $balances = $this->_repository->yearBalanceReport($date); $groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end, 15); $groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15); + $budgets = \Auth::user()->budgets()->get(); return View::make( - 'reports.year', compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') + 'reports.year', + compact('date', 'groupedIncomes', 'budgets', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon') ); } diff --git a/app/routes.php b/app/routes.php index 24b2f3a926..765370890b 100644 --- a/app/routes.php +++ b/app/routes.php @@ -226,7 +226,7 @@ Route::group( Route::get('/chart/piggy_history/{piggyBank}', ['uses' => 'GoogleChartController@piggyBankHistory']); // google chart for components (categories + budgets combined) - Route::get('/chart/budget/{budget}/spending', ['uses' => 'GoogleChartController@budgetsAndSpending']); + Route::get('/chart/budget/{budget}/spending/{year?}', ['uses' => 'GoogleChartController@budgetsAndSpending']); Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']); Route::get('/chart/category/{category}/spending/{year}', ['uses' => 'GoogleChartController@categoriesAndSpending']); diff --git a/app/views/reports/year.blade.php b/app/views/reports/year.blade.php index 130f29ec55..d4b30af4a0 100644 --- a/app/views/reports/year.blade.php +++ b/app/views/reports/year.blade.php @@ -133,19 +133,21 @@ - +@foreach($budgets as $budget)
- Budgets + {{{$budget->name}}}
- +
+@endforeach + @stop @section('scripts') diff --git a/public/assets/javascript/firefly/reports.js b/public/assets/javascript/firefly/reports.js index 3ef9f9326d..fe54980daa 100644 --- a/public/assets/javascript/firefly/reports.js +++ b/public/assets/javascript/firefly/reports.js @@ -3,5 +3,11 @@ if (typeof(google) != 'undefined') { function drawChart() { googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart'); googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart') + + $.each($('.budgets'), function (i, v) { + var holder = $(v); + var id = holder.data('id'); + googleColumnChart('chart/budget/' + id + '/spending/' + year, 'budgets-' + id); + }); } } \ No newline at end of file