Chart for piggy banks

This commit is contained in:
James Cole 2014-11-16 20:03:53 +01:00
parent 8c254554eb
commit fb0d463040
3 changed files with 41 additions and 5 deletions

View File

@ -473,6 +473,29 @@ class GoogleChartController extends BaseController
} }
public function piggyBankHistory(\Piggybank $piggybank)
{
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
$chart->addColumn('Date', 'date');
$chart->addColumn('Balance', 'number');
$sum = 0;
$set = \DB::table('piggybank_events')
->where('piggybank_id',$piggybank->id)
->groupBy('date')
->get(['date',DB::Raw('SUM(`amount`) AS `sum`')]);
foreach($set as $entry) {
$chart->addRow(new Carbon($entry->date), floatval($entry->sum));
}
$chart->generate();
return Response::json($chart->getData());
}
/** /**
* @param RecurringTransaction $recurring * @param RecurringTransaction $recurring
*/ */

View File

@ -113,4 +113,13 @@
@stop @stop
@section('scripts') @section('scripts')
<script type="text/javascript">
var piggyBankID = {{{$piggybank->id}}};
</script>
<!-- load the libraries and scripts necessary for Google Charts: -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}
{{HTML::script('assets/javascript/firefly/gcharts.js')}}
{{HTML::script('assets/javascript/firefly/piggybanks.js')}}
@stop @stop

View File

@ -1,6 +1,10 @@
$(function () { $(function () {
$('.addMoney').on('click', addMoney); $('.addMoney').on('click', addMoney);
$('.removeMoney').on('click', removeMoney); $('.removeMoney').on('click', removeMoney);
if (typeof(googleLineChart) == 'function' && typeof(piggyBankID) != 'undefined') {
googleLineChart('chart/piggyhistory/' + piggyBankID, 'piggybank-history');
}
}); });
function addMoney(e) { function addMoney(e) {