mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-23 09:26:29 -06:00
New budget charts for year report.
This commit is contained in:
parent
f231263085
commit
83f5b5e293
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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']);
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user