diff --git a/app/controllers/ReminderController.php b/app/controllers/ReminderController.php index ce59b5d256..f289497e6c 100644 --- a/app/controllers/ReminderController.php +++ b/app/controllers/ReminderController.php @@ -1,5 +1,4 @@ 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 file diff --git a/app/filters.php b/app/filters.php index 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.php index 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.php index 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, RemindableInterface return $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.php index 1b62a21451..53a8736903 100644 --- a/app/views/partials/menu.blade.php +++ b/app/views/partials/menu.blade.php @@ -14,7 +14,6 @@