Extended reports

This commit is contained in:
Sander Dorigo
2014-11-07 22:06:30 +01:00
parent 139d985904
commit ab4f34a96b
6 changed files with 134 additions and 5 deletions

View File

@@ -124,15 +124,19 @@ class GoogleChartController extends BaseController
$end->endOfYear(); $end->endOfYear();
$income = 0; $income = 0;
$expense = 0; $expense = 0;
$count = 0;
while ($start < $end) { while ($start < $end) {
// total income: // total income:
$income += $tj->getSumOfIncomesByMonth($start); $income += $tj->getSumOfIncomesByMonth($start);
$expense += $tj->getSumOfExpensesByMonth($start); $expense += $tj->getSumOfExpensesByMonth($start);
$count++;
$start->addMonth(); $start->addMonth();
} }
$chart->addRow('Sum', $income, $expense); $chart->addRow('Sum', $income, $expense);
$count = $count > 0 ? $count : 1;
$chart->addRow('Average', ($income / $count), ($expense / $count));
$chart->generate(); $chart->generate();
@@ -140,6 +144,53 @@ class GoogleChartController extends BaseController
} }
/**
* @return \Illuminate\Http\JsonResponse
*/
public function budgetsReportChart($year)
{
try {
$start = new Carbon('01-01-' . $year);
} catch (Exception $e) {
App::abort(500);
}
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
/** @var \FireflyIII\Database\Budget $bdt */
$bdt = App::make('FireflyIII\Database\Budget');
$budgets = $bdt->get();
$chart->addColumn('Month', 'date');
/** @var \Budget $budget */
foreach ($budgets as $budget) {
$chart->addColumn($budget->name, 'number');
}
/*
* Loop budgets this year.
*/
$end = clone $start;
$end->endOfYear();
while ($start <= $end) {
$row = [clone $start];
foreach($budgets as $budget) {
$row[] = $bdt->spentInMonth($budget, $start);
}
$chart->addRowArray($row);
$start->addMonth();
}
$chart->generate();
return Response::json($chart->getData());
}
/** /**
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */

View File

@@ -168,6 +168,7 @@ Route::group(
Route::get('/chart/sankey/{account}/in', ['uses' => 'GoogleChartController@accountSankeyInChart']); Route::get('/chart/sankey/{account}/in', ['uses' => 'GoogleChartController@accountSankeyInChart']);
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']); 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/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
Route::get('/chart/reports/budgets/{year}', ['uses' => 'GoogleChartController@budgetsReportChart']);
// google table controller // google table controller
Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']); Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']);

View File

@@ -67,6 +67,19 @@
</div> </div>
</div> </div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
Budgets
</div>
<div class="panel-body">
<div id="budgets"></div>
</div>
</div>
</div>
</div>
@stop @stop
@section('scripts') @section('scripts')
<!-- load the libraries and scripts necessary for Google Charts: --> <!-- load the libraries and scripts necessary for Google Charts: -->

View File

@@ -89,6 +89,35 @@ function googleColumnChart(URL, container) {
}); });
} }
function googleStackedColumnChart(URL, container) {
$.getJSON(URL).success(function (data) {
/*
Get the data from the JSON
*/
gdata = new google.visualization.DataTable(data);
/*
Format as money
*/
var money = new google.visualization.NumberFormat({decimalSymbol: ',', groupingSymbol: '.', prefix: '\u20AC '});
for (i = 1; i < gdata.getNumberOfColumns(); i++) {
money.format(gdata, i);
}
/*
Create a new google charts object.
*/
var chart = new google.visualization.ColumnChart(document.getElementById(container));
/*
Draw it:
*/
chart.draw(gdata, defaultStackedColumnChartOptions);
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
}
function googlePieChart(URL, container) { function googlePieChart(URL, container) {
$.getJSON(URL).success(function (data) { $.getJSON(URL).success(function (data) {
/* /*

View File

@@ -12,7 +12,6 @@ var defaultLineChartOptions = {
height: '80%' height: '80%'
}, },
height: 400, height: 400,
vAxis: {format: '\u20AC #'},
colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"], colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
hAxis: { hAxis: {
textStyle: { textStyle: {
@@ -29,7 +28,8 @@ var defaultLineChartOptions = {
color: '#838383', color: '#838383',
fontName: 'Roboto2', fontName: 'Roboto2',
fontSize: '12' fontSize: '12'
} },
format: '\u20AC #'
} }
@@ -65,6 +65,40 @@ var defaultColumnChartOptions = {
}, },
}; };
var defaultStackedColumnChartOptions = {
height: 400,
chartArea: {
left: 50,
top: 10,
width: '85%',
height: '80%'
},
vAxis: {format: '\u20AC #'},
legend: {
position: 'none'
},
isStacked: true,
colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
vAxis: {
textStyle: {
color: '#838383',
fontName: 'Roboto2',
fontSize: '12'
},
format: '\u20AC #'
},
hAxis: {
textStyle: {
color: '#838383',
fontName: 'Roboto2',
fontSize: '12'
},
gridlines: {
color: 'transparent'
}
},
};
var defaultPieChartOptions = { var defaultPieChartOptions = {
chartArea: { chartArea: {
left: 0, left: 0,

View File

@@ -4,4 +4,5 @@ google.setOnLoadCallback(drawChart);
function drawChart() { function drawChart() {
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart'); googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart') googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
googleStackedColumnChart('chart/reports/budgets/' + year, 'budgets');
} }