New budget charts for year report.

This commit is contained in:
James Cole 2015-01-24 08:54:33 +01:00
parent f231263085
commit 83f5b5e293
5 changed files with 34 additions and 19 deletions

View File

@ -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();
}

View File

@ -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')
);
}

View File

@ -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']);

View File

@ -133,19 +133,21 @@
</div>
</div>
</div>
@foreach($budgets as $budget)
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
Budgets
{{{$budget->name}}}
</div>
<div class="panel-body">
<!-- <div id="budgets"></div> -->
<div class="budgets" data-id="{{{$budget->id}}}" id="budgets-{{{$budget->id}}}"></div>
</div>
</div>
</div>
</div>
@endforeach
@stop
@section('scripts')

View File

@ -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);
});
}
}