mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-29 02:11:12 -06:00
New chart for budget-overview.
This commit is contained in:
parent
7750b06476
commit
f69b6f9b4e
@ -200,6 +200,47 @@ class GoogleChartController extends BaseController
|
||||
return Response::json($chart->getData());
|
||||
}
|
||||
|
||||
public function budgetsAndSpending(Budget $budget, $year) {
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
|
||||
/** @var \FireflyIII\Database\Budget $bdt */
|
||||
$bdt = App::make('FireflyIII\Database\Budget');
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Month', 'date');
|
||||
$chart->addColumn('Budgeted', 'number');
|
||||
$chart->addColumn('Spent', 'number');
|
||||
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
while($start <= $end) {
|
||||
|
||||
$spent = $bdt->spentInMonth($budget, $start);
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, $start);
|
||||
if($repetition) {
|
||||
$budgeted = floatval($repetition->amount);
|
||||
} else {
|
||||
$budgeted = 0;
|
||||
}
|
||||
|
||||
$chart->addRow(clone $start, $budgeted, $spent);
|
||||
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
|
@ -169,6 +169,7 @@ Route::group(
|
||||
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
|
||||
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
|
||||
Route::get('/chart/reports/budgets/{year}', ['uses' => 'GoogleChartController@budgetsReportChart']);
|
||||
Route::get('/chart/budgets/{budget}/spending/{year}', ['uses' => 'GoogleChartController@budgetsAndSpending']);
|
||||
|
||||
// google table controller
|
||||
Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']);
|
||||
|
@ -8,7 +8,7 @@
|
||||
Some stuff?
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
Some stuff?
|
||||
<div id="budgetOverview"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -76,7 +76,11 @@
|
||||
var budgetID = {{$budget->id}};
|
||||
@if(!is_null($repetition))
|
||||
var repetitionID = {{$repetition->id}};
|
||||
var year = {{$repetition->startdate->format('Y')}};
|
||||
@else
|
||||
var year = {{Session::get('start')->format('Y')}};
|
||||
@endif
|
||||
|
||||
</script>
|
||||
|
||||
<!-- load the libraries and scripts necessary for Google Charts: -->
|
||||
|
@ -10,6 +10,8 @@ $(function () {
|
||||
if (typeof(googleTable) == 'function') {
|
||||
if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') {
|
||||
googleTable('table/budget/' + budgetID + '/0/transactions', 'transactions');
|
||||
googleColumnChart('chart/budgets/'+budgetID+'/spending/2014','budgetOverview');
|
||||
|
||||
} else if (typeof budgetID != 'undefined' && typeof repetitionID != 'undefined') {
|
||||
googleTable('table/budget/' + budgetID + '/' + repetitionID + '/transactions', 'transactions');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user