Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
This should fix reminders!
James Colef8ea0f971ddb
diff --git a/app/controllers/ReminderController.php b/app/controllers/ReminderController.phpindex ce59b5d256..f289497e6c 100644--- a/app/controllers/ReminderController.php+++ b/app/controllers/ReminderController.php@@ -1,5 +1,4 @@<?php-use FireflyIII\Exception\NotImplementedException;/*** Class ReminderController@@ -8,9 +7,10 @@ use FireflyIII\Exception\NotImplementedException;class ReminderController extends BaseController{- public function __construct() {- View::share('title','Reminders');- View::share('mainTitleIcon','fa-lightbulb-o');+ public function __construct()+ {+ View::share('title', 'Reminders');+ View::share('mainTitleIcon', 'fa-lightbulb-o');}/**@@ -18,24 +18,31 @@ class ReminderController extends BaseController*/public function show(Reminder $reminder){- throw new NotImplementedException;-// $subTitle = $reminder->title;-// $model = null; // related model.-//-// if(isset($reminder->data->model) && isset($reminder->data->type)) {-// switch($reminder->data->type) {-// case 'Test':-// break;-// case 'Piggybank':-// break;-// default:-// throw new FireflyException('Cannot handle model of type '.$reminder->data->model);-// break;-// }-// } else {-//-// }-//-// return View::make('reminders.show',compact('reminder','title','subTitle'));+ // $subTitle = $reminder->title;+ // $model = null; // related model.+ //+ // if(isset($reminder->data->model) && isset($reminder->data->type)) {+ // switch($reminder->data->type) {+ // case 'Test':+ // break;+ // case 'Piggybank':+ // break;+ // default:+ // throw new FireflyException('Cannot handle model of type '.$reminder->data->model);+ // break;+ // }+ // } else {+ //+ // }+ //+ $amount = null;+ if (get_class($reminder->remindersable) == 'Piggybank') {+ /** @var \FireflyIII\Shared\Toolkit\Reminders $toolkit */+ $reminderKit = App::make('FireflyIII\Shared\Toolkit\Reminders');++ $amount = $reminderKit->amountForReminder($reminder);+ }++ return View::make('reminders.show', compact('reminder', 'amount'));}}\ No newline at end of filediff --git a/app/filters.php b/app/filters.phpindex f1396ca5e1..3d119c2a3b 100644--- a/app/filters.php+++ b/app/filters.php@@ -14,7 +14,6 @@ App::before($reminderKit = App::make('FireflyIII\Shared\Toolkit\Reminders');$reminderKit->updateReminders();-View::share('reminders',$reminderKit->getReminders());}diff --git a/app/lib/FireflyIII/Shared/Toolkit/Reminders.php b/app/lib/FireflyIII/Shared/Toolkit/Reminders.phpindex 263108ee37..555663d9a0 100644--- a/app/lib/FireflyIII/Shared/Toolkit/Reminders.php+++ b/app/lib/FireflyIII/Shared/Toolkit/Reminders.php@@ -3,6 +3,7 @@namespace FireflyIII\Shared\Toolkit;use Carbon\Carbon;+use FireflyIII\Exception\FireflyException;use Illuminate\Support\Collection;/**@@ -13,13 +14,52 @@ use Illuminate\Support\Collection;class Reminders{+ /**+ * @param \Reminder $reminder+ *+ * @return int+ * @throws FireflyException+ */+ public function amountForReminder(\Reminder $reminder) {++ /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */+ $dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');++ switch(get_class($reminder->remindersable)) {++ case 'Piggybank':+ $start = new Carbon;+ $end = !is_null($reminder->remindersable->targetdate) ? clone $reminder->remindersable->targetdate : new Carbon;+ $reminders = 0;+ while ($start <= $end) {+ $reminders++;+ $start = $dateKit->addPeriod($start, $reminder->remindersable->reminder, $reminder->remindersable->reminder_skip);+ }+ /*+ * Now find amount yet to save.+ */+ $repetition = $reminder->remindersable->currentRelevantRep();+ $leftToSave = floatval($reminder->remindersable->targetamount) - floatval($repetition->currentamount);+ $reminders = $reminders == 0 ? 1 : $reminders;+ return $leftToSave / $reminders;+ break;+ default:+ throw new FireflyException('Cannot handle class '. get_class($reminder->remindersable).' in amountForReminder.');+ break;+ }++++ return 50;+ }/****/public function getReminders(){- return [];+ $reminders = \Auth::user()->reminders()->get();+ return $reminders;// $reminders = \Auth::user()->reminders()->where('active', true)->get();// $return = [];// /** @var \Reminder $reminder */diff --git a/app/models/User.php b/app/models/User.phpindex a4ec72a7fd..0ce9515e51 100644--- a/app/models/User.php+++ b/app/models/User.php@@ -9,21 +9,21 @@ use LaravelBook\Ardent\Ardent;/*** User*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property string $email- * @property string $password- * @property string $reset- * @property string $remember_token- * @property boolean $migrated- * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts- * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets- * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories- * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components- * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property string $email+ * @property string $password+ * @property string $reset+ * @property string $remember_token+ * @property boolean $migrated+ * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts+ * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets+ * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories+ * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components+ * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences* @property-read \Illuminate\Database\Eloquent\Collection|\RecurringTransaction[] $recurringtransactions- * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals+ * @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals* @method static \Illuminate\Database\Query\Builder|\User whereId($value)* @method static \Illuminate\Database\Query\Builder|\User whereCreatedAt($value)* @method static \Illuminate\Database\Query\Builder|\User whereUpdatedAt($value)@@ -108,6 +108,15 @@ class User extends Ardent implements UserInterface, RemindableInterfacereturn $this->hasMany('RecurringTransaction');}+ /**+ * @return \Illuminate\Database\Eloquent\Relations\HasMany+ */+ public function reminders()+ {+ return $this->hasMany('Reminder');+ }++/*** @param $value*/diff --git a/app/views/partials/menu.blade.php b/app/views/partials/menu.blade.phpindex 1b62a21451..53a8736903 100644--- a/app/views/partials/menu.blade.php+++ b/app/views/partials/menu.blade.php@@ -14,7 +14,6 @@<ul class="nav navbar-top-links navbar-right"><!-- reminders -->- {{--@if(count($reminders) > 0)<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">@@ -23,10 +22,17 @@<ul class="dropdown-menu dropdown-alerts">@foreach($reminders as $index => $reminder)<li>- <a href="{{route('reminders.show',$reminder['id'])}}">+ <a href="{{route('reminders.show',$reminder->id)}}"><div>- <i class="fa {{$reminder['icon']}} fa-fw"></i> {{{$reminder['title']}}}- <span class="pull-right text-muted small">{{$reminder['text']}}</span>+ <i class="fa fa-clock-o fa-fw"></i>+ <!-- may be a title, may be a name or a description -->+ @if($reminder->remindersable->title)+ {{{$reminder->remindersable->title}}}+ @endif+ @if($reminder->remindersable->name)+ {{{$reminder->remindersable->name}}}+ @endif+ <span class="pull-right text-muted small"></span></div></a></li>@@ -38,7 +44,6 @@<!-- /.dropdown-alerts --></li>@endif- --}}<!-- /.dropdown --><li class="dropdown">diff --git a/app/views/reminders/show.blade.php b/app/views/reminders/show.blade.phpindex 76a0531df8..156897a1e5 100644--- a/app/views/reminders/show.blade.php+++ b/app/views/reminders/show.blade.php@@ -1,13 +1,28 @@@extends('layouts.default')@section('content')<div class="row">- <div class="col-lg-6 col-md-6 col-sm-12">- <div class="panel panel-default">+ <div class="col-lg-8 col-md-8 col-sm-12">+ <div class="panel panel-primary"><div class="panel-heading">- Something+ A reminder about+ @if(get_class($reminder->remindersable) == 'Piggybank')+ your piggy bank labelled "{{{$reminder->remindersable->name}}}"+ @endif</div><div class="panel-body">- {{$reminder->data->text}}+ <p>+ @if(get_class($reminder->remindersable) == 'Piggybank')+ Somewhere between {{$reminder->startdate->format('j F Y')}} and {{$reminder->enddate->format('j F Y')}} you+ should deposit {{mf($amount)}} in piggy bank <a href="{{route('piggybanks.show',$reminder->remindersable_id)}}">{{{$reminder->remindersable->name}}}</a>+ in order to make your goal of saving {{mf($reminder->remindersable->targetamount)}} on {{$reminder->remindersable->targetdate->format('j F Y')}}+ @endif+ </p>+ <p>+ <a href="#" class="btn btn-primary"><i class="fa fa-fw fa-thumbs-o-up"></i> I want to do this</a>+ <a href="#" class="btn btn-success"><i class="fa fa-smile-o fa-fw"></i> I already did this</a>+ <a href="#" class="btn btn-danger"><i class="fa fa-fw fa-clock-o"></i> Not this time</a>++ </p></div></div></div>