mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Chart for piggy banks
This commit is contained in:
parent
8c254554eb
commit
fb0d463040
@ -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
|
||||||
*/
|
*/
|
||||||
@ -499,7 +522,7 @@ class GoogleChartController extends BaseController
|
|||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
while ($start <= $end) {
|
while ($start <= $end) {
|
||||||
$result = $recurring->transactionjournals()->before($end)->after($start)->first();
|
$result = $recurring->transactionjournals()->before($end)->after($start)->first();
|
||||||
if($result) {
|
if ($result) {
|
||||||
$amount = $result->getAmount();
|
$amount = $result->getAmount();
|
||||||
} else {
|
} else {
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
|
@ -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
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
$(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) {
|
||||||
var pigID = parseInt($(e.target).data('id'));
|
var pigID = parseInt($(e.target).data('id'));
|
||||||
$('#moneyManagementModal').empty().load('piggybanks/add/' + pigID).modal('show');
|
$('#moneyManagementModal').empty().load('piggybanks/add/' + pigID).modal('show');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeMoney(e) {
|
function removeMoney(e) {
|
||||||
var pigID = parseInt($(e.target).data('id'));
|
var pigID = parseInt($(e.target).data('id'));
|
||||||
$('#moneyManagementModal').empty().load('piggybanks/remove/' + pigID).modal('show');
|
$('#moneyManagementModal').empty().load('piggybanks/remove/' + pigID).modal('show');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user