More stuffs. Too lazy to explain.

This commit is contained in:
James Cole
2014-11-15 11:36:27 +01:00
parent 8c949e6190
commit 61aba29df7
12 changed files with 162 additions and 36 deletions

View File

@@ -336,6 +336,34 @@ class GoogleChartController extends BaseController
} }
public function budgetLimitSpending(\Budget $budget, \LimitRepetition $repetition)
{
$start = clone $repetition->startdate;
$end = $repetition->enddate;
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
$chart->addColumn('Day', 'date');
$chart->addColumn('Left', 'number');
$amount = $repetition->amount;
while ($start <= $end) {
/*
* Sum of expenses on this day:
*/
$sum = floatval($budget->transactionjournals()->lessThan(0)->transactionTypes(['Withdrawal'])->onDate($start)->sum('amount'));
$amount += $sum;
$chart->addRow(clone $start, $amount);
$start->addDay();
}
$chart->generate();
return Response::json($chart->getData());
}
/** /**
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
@@ -445,28 +473,44 @@ class GoogleChartController extends BaseController
} }
public function budgetLimitSpending(\Budget $budget, \LimitRepetition $repetition) { /**
$start = clone $repetition->startdate; * @param RecurringTransaction $recurring
$end = $repetition->enddate; */
public function recurringOverview(RecurringTransaction $recurring)
{
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = App::make('FireflyIII\Shared\Toolkit\Date');
/** @var \Grumpydictator\Gchart\GChart $chart */ /** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart'); $chart = App::make('gchart');
$chart->addColumn('Day', 'date'); $chart->addColumn('Date', 'date');
$chart->addColumn('Left', 'number'); $chart->addColumn('Max amount', 'number');
$chart->addColumn('Min amount', 'number');
$chart->addColumn('Current entry', 'number');
// get first transaction or today for start:
$amount = $repetition->amount; $first = $recurring->transactionjournals()->orderBy('date', 'ASC')->first();
if ($first) {
while($start <= $end) { $start = $first->date;
/* } else {
* Sum of expenses on this day: $start = new Carbon;
*/
$sum = floatval($budget->transactionjournals()->lessThan(0)->transactionTypes(['Withdrawal'])->onDate($start)->sum('amount'));
$amount += $sum;
$chart->addRow(clone $start, $amount);
$start->addDay();
} }
$end = new Carbon;
while ($start <= $end) {
$result = $recurring->transactionjournals()->before($end)->after($start)->first();
if($result) {
$amount = $result->getAmount();
} else {
$amount = 0;
}
unset($result);
$chart->addRow(clone $start, $recurring->amount_max, $recurring->amount_min, $amount);
$start = $dateKit->addPeriod($start, $recurring->repeat_freq, 0);
}
$chart->generate(); $chart->generate();
return Response::json($chart->getData()); return Response::json($chart->getData());
} }
@@ -551,6 +595,7 @@ class GoogleChartController extends BaseController
$chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']); $chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
$chart->generate(); $chart->generate();
return Response::json($chart->getData()); return Response::json($chart->getData());
} }

View File

@@ -20,6 +20,7 @@ class PiggybankController extends BaseController
/** /**
* Add money to piggy bank * Add money to piggy bank
*
* @param Piggybank $piggybank * @param Piggybank $piggybank
* *
* @return $this * @return $this
@@ -109,7 +110,7 @@ class PiggybankController extends BaseController
* Flash some data to fill the form. * Flash some data to fill the form.
*/ */
$prefilled = ['name' => $piggybank->name, 'account_id' => $piggybank->account_id, 'targetamount' => $piggybank->targetamount, $prefilled = ['name' => $piggybank->name, 'account_id' => $piggybank->account_id, 'targetamount' => $piggybank->targetamount,
'targetdate' => $piggybank->targetdate, 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false]; 'targetdate' => !is_null($piggybank->targetdate) ? $piggybank->targetdate->format('Y-m-d') : null,'reminder' => $piggybank->reminder, 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false];
Session::flash('prefilled', $prefilled); Session::flash('prefilled', $prefilled);
return View::make('piggybanks.edit', compact('piggybank', 'accounts', 'periods', 'prefilled'))->with('title', 'Piggybanks')->with( return View::make('piggybanks.edit', compact('piggybank', 'accounts', 'periods', 'prefilled'))->with('title', 'Piggybanks')->with(
@@ -152,6 +153,7 @@ class PiggybankController extends BaseController
/** /**
* POST add money to piggy bank * POST add money to piggy bank
*
* @param Piggybank $piggybank * @param Piggybank $piggybank
* *
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
@@ -176,7 +178,7 @@ class PiggybankController extends BaseController
/* /*
* Create event! * Create event!
*/ */
Event::fire('piggybank.addMoney',[$piggybank, $amount]); Event::fire('piggybank.addMoney', [$piggybank, $amount]);
Session::flash('success', 'Added ' . mf($amount, false) . ' to "' . e($piggybank->name) . '".'); Session::flash('success', 'Added ' . mf($amount, false) . ' to "' . e($piggybank->name) . '".');
} else { } else {
@@ -205,7 +207,7 @@ class PiggybankController extends BaseController
/* /*
* Create event! * Create event!
*/ */
Event::fire('piggybank.removeMoney',[$piggybank, $amount]); Event::fire('piggybank.removeMoney', [$piggybank, $amount]);
Session::flash('success', 'Removed ' . mf($amount, false) . ' from "' . e($piggybank->name) . '".'); Session::flash('success', 'Removed ' . mf($amount, false) . ' from "' . e($piggybank->name) . '".');
} else { } else {
@@ -228,7 +230,21 @@ class PiggybankController extends BaseController
public function show(Piggybank $piggybank) public function show(Piggybank $piggybank)
{ {
return View::make('piggybanks.show', compact('piggybank'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc')->with( $events = $piggybank->piggybankevents()->orderBy('date', 'DESC')->get();
/*
* Number of reminders:
*/
$remindersCount = $piggybank->countFutureReminders();
if ($remindersCount > 0) {
$amountPerReminder = ($piggybank->targetamount - $piggybank->currentRelevantRep()->currentamount) / $remindersCount;
} else {
$amountPerReminder = ($piggybank->targetamount - $piggybank->currentRelevantRep()->currentamount);
}
return View::make('piggybanks.show', compact('amountPerReminder', 'remindersCount', 'piggybank', 'events'))->with('title', 'Piggy banks')->with(
'mainTitleIcon', 'fa-sort-amount-asc'
)->with(
'subTitle', $piggybank->name 'subTitle', $piggybank->name
); );
@@ -296,7 +312,7 @@ class PiggybankController extends BaseController
default: default:
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"'); throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
break; break;
case 'create_another': case 'return_to_edit':
case 'update': case 'update':
$messages = $repos->validate($data); $messages = $repos->validate($data);
/** @var MessageBag $messages ['errors'] */ /** @var MessageBag $messages ['errors'] */
@@ -311,7 +327,7 @@ class PiggybankController extends BaseController
$repos->update($piggyBank, $data); $repos->update($piggyBank, $data);
Session::flash('success', 'Piggy bank updated!'); Session::flash('success', 'Piggy bank updated!');
if ($data['post_submit_action'] == 'create_another') { if ($data['post_submit_action'] == 'return_to_edit') {
return Redirect::route('piggybanks.edit', $piggyBank->id); return Redirect::route('piggybanks.edit', $piggyBank->id);
} else { } else {
return Redirect::route('piggybanks.index'); return Redirect::route('piggybanks.index');

View File

@@ -79,10 +79,12 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
$model->reminder_skip = isset($data['reminder_skip']) ? $data['reminder_skip'] : 0; $model->reminder_skip = isset($data['reminder_skip']) ? $data['reminder_skip'] : 0;
$model->order = isset($data['order']) ? $data['order'] : 0; $model->order = isset($data['order']) ? $data['order'] : 0;
$model->remind_me = isset($data['remind_me']) ? intval($data['remind_me']) : 0; $model->remind_me = isset($data['remind_me']) ? intval($data['remind_me']) : 0;
$model->reminder = isset($data['reminder']) ? $data['reminder'] : 'month';
if (!$model->validate()) { if (!$model->validate()) {
var_dump($model->errors()); var_dump($model->errors());
exit(); exit();
} }
$model->save(); $model->save();
return true; return true;

View File

@@ -111,6 +111,9 @@ class Form
$options['id'] = 'ffInput_' . $name; $options['id'] = 'ffInput_' . $name;
$options['autocomplete'] = 'off'; $options['autocomplete'] = 'off';
$label = self::label($name, $options); $label = self::label($name, $options);
/* /*
* Make label and placeholder look nice. * Make label and placeholder look nice.
*/ */

View File

@@ -30,9 +30,11 @@ class Date
case 'daily': case 'daily':
$date->addDays($add); $date->addDays($add);
break; break;
case 'week':
case 'weekly': case 'weekly':
$date->addWeeks($add); $date->addWeeks($add);
break; break;
case 'month':
case 'monthly': case 'monthly':
$date->addMonths($add); $date->addMonths($add);
break; break;

View File

@@ -70,6 +70,20 @@ class Piggybank extends Ardent
return $this->belongsTo('Account'); return $this->belongsTo('Account');
} }
public function countFutureReminders() {
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = App::make('FireflyIII\Shared\Toolkit\Date');
$start = new Carbon;
$end = !is_null($this->targetdate) ? clone $this->targetdate : new Carbon;
$reminders = 0;
while($start <= $end) {
$reminders++;
$start = $dateKit->addPeriod($start, $this->reminder, $this->reminder_skip);
}
return $reminders;
}
public function createRepetition(Carbon $start = null, Carbon $target = null) public function createRepetition(Carbon $start = null, Carbon $target = null)
{ {
$rep = new \PiggybankRepetition; $rep = new \PiggybankRepetition;
@@ -90,15 +104,16 @@ class Piggybank extends Ardent
*/ */
public function currentRelevantRep() public function currentRelevantRep()
{ {
if($this->currentRep) { if ($this->currentRep) {
return $this->currentRep; return $this->currentRep;
} }
if ($this->repeats == 0) { if ($this->repeats == 0) {
$rep = $this->piggybankrepetitions()->first(); $rep = $this->piggybankrepetitions()->first();
$this->currentRep = $rep; $this->currentRep = $rep;
return $rep; return $rep;
} else { } else {
$query = $this->piggybankrepetitions()->where( $query = $this->piggybankrepetitions()->where(
function ($q) { function ($q) {
$q->where( $q->where(
@@ -122,7 +137,7 @@ class Piggybank extends Ardent
$q->where('targetdate', '>=', $today->format('Y-m-d')); $q->where('targetdate', '>=', $today->format('Y-m-d'));
} }
)->orderBy('startdate', 'ASC'); )->orderBy('startdate', 'ASC');
$result = $query->first(); $result = $query->first();
$this->currentRep = $result; $this->currentRep = $result;
return $result; return $result;

View File

@@ -0,0 +1,18 @@
<table class="table table-bordered table-striped">
<tr>
<th>Date</th>
<th>Amount</th>
</tr>
@foreach($events as $event)
<tr>
<td>{{$event->date->format('j F Y')}}</td>
<td>
@if($event->amount < 0)
<span class="text-danger">Removed {{mf($event->amount*-1,false)}}</span>
@else
<span class="text-success">Added {{mf($event->amount,false)}}</span>
@endif
</td>
</tr>
@endforeach
</table>

View File

@@ -1,6 +1,6 @@
@extends('layouts.default') @extends('layouts.default')
@section('content') @section('content')
{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.update',$piggybank->id)])}} {{Form::model($piggybank, ['class' => 'form-horizontal','url' => route('piggybanks.update',$piggybank->id)])}}
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-12 col-sm-6"> <div class="col-lg-6 col-md-12 col-sm-6">
@@ -30,7 +30,7 @@
<div class="panel-body"> <div class="panel-body">
{{Form::ffDate('targetdate')}} {{Form::ffDate('targetdate')}}
{{Form::ffCheckbox('remind_me','1',$prefilled['remind_me'],['label' => 'Remind me'])}} {{Form::ffCheckbox('remind_me','1',$prefilled['remind_me'],['label' => 'Remind me'])}}
{{Form::ffSelect('reminder',$periods,'month',['label' => 'Remind every'])}} {{Form::ffSelect('reminder',$periods,$prefilled['reminder'],['label' => 'Remind every'])}}
</div> </div>
</div> </div>

View File

@@ -8,15 +8,29 @@
<i class="fa fa-fw fa-clock-o"></i> Events <i class="fa fa-fw fa-clock-o"></i> Events
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div id="piggybank-history"></div> <!-- TODO piggy bank events --> <div id="piggybank-history"></div>
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-4 col-md-4 col-sm-6"> <div class="col-lg-4 col-md-4 col-sm-6">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<i class="fa fa-fw fa-info-circle"></i> Details <i class="fa fa-fw fa-info-circle"></i> Details
<!-- ACTIONS MENU -->
<div class="pull-right">
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="{{route('piggybanks.edit',$piggybank->id)}}"><i class="fa fa-pencil fa-fw"></i> Edit</a></li>
<li><a href="{{route('piggybanks.delete',$piggybank->id)}}"><i class="fa fa-trash fa-fw"></i> Delete</a></li>
</ul>
</div>
</div>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">
@@ -72,15 +86,23 @@
</tr> </tr>
<tr> <tr>
<td>Reminders left</td> <td>Reminders left</td>
<td>12</td> <!-- TODO piggy bank reminders--> <td>{{$remindersCount}}</td>
</tr> </tr>
<tr> <tr>
<td>Expected amount per reminder</td> <td>Expected amount per reminder</td>
<td>{{mf(0)}}</td> <!-- TODO piggy bank reminder --> <td>{{mf($amountPerReminder)}}</td>
</tr> </tr>
</table> </table>
</div> </div>
</div> </div>
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-fw fa-clock-o"></i> Table
</div>
<div class="panel-body">
@include('list.piggybank-events')
</div>
</div>
</div> </div>
</div> </div>

View File

@@ -81,6 +81,7 @@
Chart Chart
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div id="recurring-overview"></div>
<!-- TODO chart with hits, grouped by repeat_freq and two lines with max/min amount --> <!-- TODO chart with hits, grouped by repeat_freq and two lines with max/min amount -->
</div> </div>
</div> </div>

View File

@@ -100,8 +100,6 @@ Event::subscribe('FireflyIII\Event\Piggybank');
// TODO event for when a transfer gets created and set an associated piggy bank; save as Piggy bank event. // TODO event for when a transfer gets created and set an associated piggy bank; save as Piggy bank event.
// TODO when this transfer gets edited, retro-actively edit the event and THUS also the piggy bank. // TODO when this transfer gets edited, retro-actively edit the event and THUS also the piggy bank.
// TODO event for when a transfer gets deleted; also delete related piggy bank event. // TODO event for when a transfer gets deleted; also delete related piggy bank event.
// TODO event for when money is added to a piggy bank.
// TODO event for when money is removed from a piggy bank.
// TODO event to create the first repetition (for non-repeating piggy banks) when the piggy bank is created. // TODO event to create the first repetition (for non-repeating piggy banks) when the piggy bank is created.
// TODO event for when the non-repeating piggy bank is updated because the single repetition must also be changed. // TODO event for when the non-repeating piggy bank is updated because the single repetition must also be changed.
// (also make piggy bank events "invalid" when they start falling outside of the date-scope of the piggy bank, // (also make piggy bank events "invalid" when they start falling outside of the date-scope of the piggy bank,

View File

@@ -2,9 +2,13 @@ $(document).ready(function () {
if (typeof(googleTable) == 'function') { if (typeof(googleTable) == 'function') {
googleTable('table/recurring', 'recurring-table'); googleTable('table/recurring', 'recurring-table');
if (typeof(recurringID) != 'undefined') {
googleTable('table/recurring/' + recurringID + '/transactions', 'transaction-table');
}
} }
if (typeof(googleTable) == 'function') { if (typeof(googleLineChart) == 'function' && typeof(recurringID) != 'undefined') {
googleTable('table/recurring/' + recurringID + '/transactions', 'transaction-table'); googleLineChart('chart/recurring/' + recurringID, 'recurring-overview');
} }
} }
); );