This should fix reminders!

This commit is contained in:
James Cole
2014-11-17 23:08:36 +01:00
parent 9918410954
commit f8ea0f971d
6 changed files with 123 additions and 48 deletions

View File

@@ -1,5 +1,4 @@
<?php <?php
use FireflyIII\Exception\NotImplementedException;
/** /**
* Class ReminderController * Class ReminderController
@@ -8,9 +7,10 @@ use FireflyIII\Exception\NotImplementedException;
class ReminderController extends BaseController class ReminderController extends BaseController
{ {
public function __construct() { public function __construct()
View::share('title','Reminders'); {
View::share('mainTitleIcon','fa-lightbulb-o'); View::share('title', 'Reminders');
View::share('mainTitleIcon', 'fa-lightbulb-o');
} }
/** /**
@@ -18,24 +18,31 @@ class ReminderController extends BaseController
*/ */
public function show(Reminder $reminder) public function show(Reminder $reminder)
{ {
throw new NotImplementedException; // $subTitle = $reminder->title;
// $subTitle = $reminder->title; // $model = null; // related model.
// $model = null; // related model. //
// // if(isset($reminder->data->model) && isset($reminder->data->type)) {
// if(isset($reminder->data->model) && isset($reminder->data->type)) { // switch($reminder->data->type) {
// switch($reminder->data->type) { // case 'Test':
// case 'Test': // break;
// break; // case 'Piggybank':
// case 'Piggybank': // break;
// break; // default:
// default: // throw new FireflyException('Cannot handle model of type '.$reminder->data->model);
// throw new FireflyException('Cannot handle model of type '.$reminder->data->model); // break;
// break; // }
// } // } else {
// } else { //
// // }
// } //
// $amount = null;
// return View::make('reminders.show',compact('reminder','title','subTitle')); 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'));
} }
} }

View File

@@ -14,7 +14,6 @@ App::before(
$reminderKit = App::make('FireflyIII\Shared\Toolkit\Reminders'); $reminderKit = App::make('FireflyIII\Shared\Toolkit\Reminders');
$reminderKit->updateReminders(); $reminderKit->updateReminders();
View::share('reminders',$reminderKit->getReminders()); View::share('reminders',$reminderKit->getReminders());
} }

View File

@@ -3,6 +3,7 @@
namespace FireflyIII\Shared\Toolkit; namespace FireflyIII\Shared\Toolkit;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exception\FireflyException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
@@ -13,13 +14,52 @@ use Illuminate\Support\Collection;
class Reminders 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() public function getReminders()
{ {
return []; $reminders = \Auth::user()->reminders()->get();
return $reminders;
// $reminders = \Auth::user()->reminders()->where('active', true)->get(); // $reminders = \Auth::user()->reminders()->where('active', true)->get();
// $return = []; // $return = [];
// /** @var \Reminder $reminder */ // /** @var \Reminder $reminder */

View File

@@ -9,21 +9,21 @@ use LaravelBook\Ardent\Ardent;
/** /**
* User * User
* *
* @property integer $id * @property integer $id
* @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at * @property \Carbon\Carbon $updated_at
* @property string $email * @property string $email
* @property string $password * @property string $password
* @property string $reset * @property string $reset
* @property string $remember_token * @property string $remember_token
* @property boolean $migrated * @property boolean $migrated
* @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts
* @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets
* @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories
* @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components
* @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences
* @property-read \Illuminate\Database\Eloquent\Collection|\RecurringTransaction[] $recurringtransactions * @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 whereId($value)
* @method static \Illuminate\Database\Query\Builder|\User whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\User whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\User whereUpdatedAt($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 $this->hasMany('RecurringTransaction');
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function reminders()
{
return $this->hasMany('Reminder');
}
/** /**
* @param $value * @param $value
*/ */

View File

@@ -14,7 +14,6 @@
<ul class="nav navbar-top-links navbar-right"> <ul class="nav navbar-top-links navbar-right">
<!-- reminders --> <!-- reminders -->
{{--
@if(count($reminders) > 0) @if(count($reminders) > 0)
<li class="dropdown"> <li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">
@@ -23,10 +22,17 @@
<ul class="dropdown-menu dropdown-alerts"> <ul class="dropdown-menu dropdown-alerts">
@foreach($reminders as $index => $reminder) @foreach($reminders as $index => $reminder)
<li> <li>
<a href="{{route('reminders.show',$reminder['id'])}}"> <a href="{{route('reminders.show',$reminder->id)}}">
<div> <div>
<i class="fa {{$reminder['icon']}} fa-fw"></i> {{{$reminder['title']}}} <i class="fa fa-clock-o fa-fw"></i>
<span class="pull-right text-muted small">{{$reminder['text']}}</span> <!-- 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> </div>
</a> </a>
</li> </li>
@@ -38,7 +44,6 @@
<!-- /.dropdown-alerts --> <!-- /.dropdown-alerts -->
</li> </li>
@endif @endif
--}}
<!-- /.dropdown --> <!-- /.dropdown -->
<li class="dropdown"> <li class="dropdown">

View File

@@ -1,13 +1,28 @@
@extends('layouts.default') @extends('layouts.default')
@section('content') @section('content')
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-12"> <div class="col-lg-8 col-md-8 col-sm-12">
<div class="panel panel-default"> <div class="panel panel-primary">
<div class="panel-heading"> <div class="panel-heading">
Something A reminder about
@if(get_class($reminder->remindersable) == 'Piggybank')
your piggy bank labelled "{{{$reminder->remindersable->name}}}"
@endif
</div> </div>
<div class="panel-body"> <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> </div>
</div> </div>