diff --git a/app/controllers/ReminderController.php b/app/controllers/ReminderController.php index e6bdef5ea0..15f226954d 100644 --- a/app/controllers/ReminderController.php +++ b/app/controllers/ReminderController.php @@ -57,5 +57,12 @@ class ReminderController extends BaseController Session::flash('success','Reminder dismissed'); return Redirect::route('index'); } + public function notnow(Reminder $reminder) { + $reminder->active = 0; + $reminder->notnow = 1; + $reminder->save(); + Session::flash('success','Reminder dismissed'); + return Redirect::route('index'); + } } \ No newline at end of file diff --git a/app/database/migrations/2014_11_17_194734_event_table_additions_1.php b/app/database/migrations/2014_11_17_194734_event_table_additions_1.php index a164da50ad..e5e419bb7f 100644 --- a/app/database/migrations/2014_11_17_194734_event_table_additions_1.php +++ b/app/database/migrations/2014_11_17_194734_event_table_additions_1.php @@ -26,6 +26,7 @@ class EventTableAdditions1 extends Migration // remove some fields: Schema::table( 'reminders', function (Blueprint $table) { + $table->boolean('notnow'); $table->integer('remindersable_id')->unsigned()->nullable(); $table->string('remindersable_type')->nullable(); } diff --git a/app/lib/FireflyIII/Collection/PiggybankPart.php b/app/lib/FireflyIII/Collection/PiggybankPart.php index bf5fb94d86..faf28173b2 100644 --- a/app/lib/FireflyIII/Collection/PiggybankPart.php +++ b/app/lib/FireflyIII/Collection/PiggybankPart.php @@ -7,17 +7,24 @@ use Carbon\Carbon; class PiggybankPart { - /** @var int */ - public $amount; + /** @var float */ public $amountPerBar; - /** @var int */ + + /** @var float */ public $currentamount; + + /** @var float */ + public $cumulativeAmount; + /** @var \Reminder */ public $reminder; + /** @var \PiggybankRepetition */ public $repetition; + /** @var Carbon */ public $startdate; + /** @var Carbon */ public $targetdate; @@ -92,10 +99,10 @@ class PiggybankPart public function percentage() { - if ($this->getCurrentamount() < $this->getAmount()) { + if ($this->getCurrentamount() < $this->getCumulativeAmount()) { $pct = 0; // calculate halway point? - if ($this->getAmount() - $this->getCurrentamount() < $this->getAmountPerBar()) { + if ($this->getCumulativeAmount() - $this->getCurrentamount() < $this->getAmountPerBar()) { $left = $this->getCurrentamount() % $this->getAmountPerBar(); $pct = round($left / $this->getAmountPerBar() * 100); } @@ -107,7 +114,7 @@ class PiggybankPart } /** - * @return int + * @return float */ public function getCurrentamount() { @@ -115,7 +122,7 @@ class PiggybankPart } /** - * @param int $currentamount + * @param float $currentamount */ public function setCurrentamount($currentamount) { @@ -123,23 +130,7 @@ class PiggybankPart } /** - * @return int - */ - public function getAmount() - { - return $this->amount; - } - - /** - * @param int $amount - */ - public function setAmount($amount) - { - $this->amount = $amount; - } - - /** - * @return mixed + * @return float */ public function getAmountPerBar() { @@ -147,10 +138,30 @@ class PiggybankPart } /** - * @param mixed $amountPerBar + * @param float $amountPerBar */ public function setAmountPerBar($amountPerBar) { $this->amountPerBar = $amountPerBar; } + + /** + * @return float + */ + public function getCumulativeAmount() + { + return $this->cumulativeAmount; + } + + /** + * @param float $cumulativeAmount + */ + public function setCumulativeAmount($cumulativeAmount) + { + $this->cumulativeAmount = $cumulativeAmount; + } + + + + } \ No newline at end of file diff --git a/app/lib/FireflyIII/Database/RepeatedExpense.php b/app/lib/FireflyIII/Database/RepeatedExpense.php index 9eda8edb9a..89c019bacd 100644 --- a/app/lib/FireflyIII/Database/RepeatedExpense.php +++ b/app/lib/FireflyIII/Database/RepeatedExpense.php @@ -8,7 +8,6 @@ use FireflyIII\Collection\PiggybankPart; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Database\Ifaces\PiggybankInterface; -use FireflyIII\Exception\FireflyException; use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; @@ -39,228 +38,234 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface \Log::debug('Repetition id is ' . $repetition->id); /** @var \Piggybank $piggyBank */ $piggyBank = $repetition->piggybank()->first(); + $bars = new Collection; \Log::debug('connected piggy bank is: ' . $piggyBank->name . ' (#' . $piggyBank->id . ')'); /* * If no reminders are set, the repetition is split in exactly one part: */ if (is_null($piggyBank->reminder)) { - $parts = 1; - } else { - /* - * Number of parts is the number of [reminder period]s between - * the start date and the target date - */ - /** @var Carbon $start */ - $start = clone $repetition->startdate; - /** @var Carbon $target */ - $target = clone $repetition->targetdate; - - switch ($piggyBank->reminder) { - default: - throw new FireflyException('Cannot handle "' . $piggyBank->reminder . '" reminders for repeated expenses (calculateParts)'); - break; - case 'week': - $parts = $start->diffInWeeks($target); - break; - case 'month': - $parts = $start->diffInMonths($target); - break; - case 'quarter': - $parts = ceil($start->diffInMonths($target) / 3); - break; - case 'year': - $parts = $start->diffInYears($target); - break; - } - $parts = $parts < 1 ? 1 : $parts; - unset($start, $target); - - - // /* - // * Otherwise, FF3 splits by the difference in time and the amount - // * of reminders the user wants. - // */ - // switch ($piggyBank->reminder) { - // default: - // throw new FireflyException('Cannot handle "' . $piggyBank->reminder . '" reminders for repeated expenses (calculateParts)'); - // break; - // case 'week': - // $start = clone $repetition->startdate; - // $start->startOfWeek(); - // $end = clone $repetition->targetdate; - // $end->endOfWeek(); - // $parts = $start->diffInWeeks($end); - // unset($start, $end); - // break; - // case 'month': - // $start = clone $repetition->startdate; - // $start->startOfMonth(); - // $end = clone $repetition->targetdate; - // $end->endOfMonth(); - // $parts = $start->diffInMonths($end); - // unset($start, $end); - // break; - // } - } - $amountPerBar = floatval($piggyBank->targetamount) / $parts; - $currentAmount = floatval($amountPerBar); - $currentStart = clone $repetition->startdate; - $currentTarget = clone $repetition->targetdate; - $bars = new Collection; - - // if($parts > 12) { - // $parts = 12; - // $currentStart = \DateKit::startOfPeriod(Carbon::now(), $piggyBank->reminder); - // $currentEnd = \DateKit::endOfPeriod($currentEnd, $piggyBank->reminder); - // } - - for ($i = 0; $i < $parts; $i++) { - /* - * If it's not the first repetition, jump the start date a [period] - * and jump the target date a [period] - */ - if($i > 0) { - $currentStart = clone $currentTarget; - $currentStart->addDay(); - $currentTarget = \DateKit::addPeriod($currentStart, $piggyBank->reminder,0); - } - /* - * If it's the first one, and has reminders, jump to the end of the [period] - */ - if($i == 0 && !is_null($piggyBank->reminder)) { - $currentTarget = \DateKit::endOfX($currentStart, $piggyBank->reminder); - } - if($currentStart > $repetition->targetdate) { - break; - } - - - /* - * Jump one month ahead after the first instance: - */ - // if ($i > 0) { - // $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); - // /* - // * Jump to the start of the period too: - // */ - // $currentStart = \DateKit::startOfPeriod($currentStart, $piggyBank->reminder); - // - // } - - - /* - * Move the current start to the actual start of - * the [period] once the first iteration has passed. - */ - // if ($i != 0) { - // $currentStart = \DateKit::startOfPeriod($currentStart, $piggyBank->reminder); - // } - // if($i == 0 && !is_null($piggyBank->reminder)) { - // $currentEnd = \DateKit::startOfPeriod($currentStart, $piggyBank->reminder); - // $currentEnd = \DateKit::endOfPeriod($currentEnd, $piggyBank->reminder); - // } - $part = new PiggybankPart; $part->setRepetition($repetition); - $part->setAmount($currentAmount); - $part->setAmountPerBar($amountPerBar); + $part->setAmountPerBar(floatval($piggyBank->targetamount)); + $part->setCurrentamount($repetition->currentamount); + $part->setCumulativeAmount($piggyBank->targetamount); + $part->setStartdate(clone $repetition->startdate); + $part->setTargetdate(clone $repetition->targetdate); + $bars->push($part); + $repetition->bars = $bars; + + return $repetition; + } + $currentStart = clone $repetition->startdate; + /* + * Loop between start and target instead of counting manually. + */ + $index = 0; + //echo 'Looping!
'; + //echo $repetition->startdate . ' until ' . $repetition->targetdate . '
'; + while ($currentStart < $repetition->targetdate) { + $currentTarget = \DateKit::endOfX($currentStart, $piggyBank->reminder); + if ($currentTarget > $repetition->targetdate) { + $currentTarget = clone $repetition->targetdate; + } + + // create a part: + $part = new PiggybankPart; + $part->setRepetition($repetition); $part->setCurrentamount($repetition->currentamount); $part->setStartdate($currentStart); $part->setTargetdate($currentTarget); - if (!is_null($piggyBank->reminder)) { - // might be a reminder for this range? - $reminder = $piggyBank->reminders() - ->where('startdate',$currentStart->format('Y-m-d')) - ->where('enddate',$currentTarget->format('Y-m-d')) - ->first(); - if($reminder) { - $part->setReminder($reminder); - } + $bars->push($part); + //echo 'Loop #' . $index . ', from ' . $currentStart . ' until ' . $currentTarget . '
'; + + /* + * Jump to the next period by adding a day. + */ + $currentStart = clone $currentTarget; + $currentStart->addDay();//\DateKit::addPeriod($currentTarget, $piggyBank->reminder, 0); + $index++; + + } + /* + * Loop parts again to add some + */ + $parts = $bars->count(); + $amountPerBar = floatval($piggyBank->targetamount) / $parts; + $cumulative = $amountPerBar; + /** @var PiggybankPart $bar */ + foreach ($bars as $bar) { + $bar->setAmountPerBar($amountPerBar); + $bar->setCumulativeAmount($cumulative); + + $reminder = $piggyBank->reminders() + ->where('startdate', $bar->getStartdate()->format('Y-m-d')) + ->where('enddate', $bar->getTargetdate()->format('Y-m-d')) + ->first(); + if ($reminder) { + $bar->setReminder($reminder); } - // if (!is_null($piggyBank->reminder)) { - // $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); - // $currentEnd = \DateKit::endOfPeriod($currentStart, $piggyBank->reminder); - // } - - - $bars->push($part); - $currentAmount += $amountPerBar; + $cumulative += $amountPerBar; } + $repetition->bars = $bars; return $repetition; - exit; - - - $repetition->hello = 'World!'; - - return $repetition; - - $return = new Collection; - $repetitions = $piggyBank->piggybankrepetitions()->get(); - /** @var \PiggybankRepetition $repetition */ - foreach ($repetitions as $repetition) { - - - if (is_null($piggyBank->reminder)) { - // simple, one part "repetition". - $part = new PiggybankPart; - $part->setRepetition($repetition); - } else { - $part = new PiggybankPart; - } - - - // end! - $return->push($part); - } - - exit; - - return $return; - $piggyBank->currentRelevantRep(); // get the current relevant repetition. - if (!is_null($piggyBank->reminder)) { - switch ($piggyBank->reminder) { - default: - throw new FireflyException('Cannot handle "' . $piggyBank->reminder . '" reminders for repeated expenses'); - break; - case 'month': - $start = clone $piggyBank->currentRep->startdate; - $start->startOfMonth(); - $end = clone $piggyBank->currentRep->targetdate; - $end->endOfMonth(); - $piggyBank->parts = $start->diffInMonths($end); - unset($start, $end); - break; - } - - } else { - $piggyBank->parts = 1; - } - - // number of bars: - $piggyBank->barCount = floor(12 / $piggyBank->parts) == 0 ? 1 : floor(12 / $piggyBank->parts); - $amountPerBar = floatval($piggyBank->targetamount) / $piggyBank->parts; - $currentAmount = floatval($amountPerBar); - $bars = []; - $currentStart = clone $piggyBank->currentRep->startdate; - for ($i = 0; $i < $piggyBank->parts; $i++) { - // niet elke keer een andere dinges pakken? om target te redden? - if (!is_null($piggyBank->reminder)) { - $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); - } - $bars[] = [ - 'amount' => $currentAmount, - 'date' => $currentStart - ]; - - - $currentAmount += $amountPerBar; - } - $piggyBank->bars = $bars; + // + // // if($parts > 12) { + // // $parts = 12; + // // $currentStart = \DateKit::startOfPeriod(Carbon::now(), $piggyBank->reminder); + // // $currentEnd = \DateKit::endOfPeriod($currentEnd, $piggyBank->reminder); + // // } + // + // for ($i = 0; $i < $parts; $i++) { + // /* + // * If it's not the first repetition, jump the start date a [period] + // * and jump the target date a [period] + // */ + // if ($i > 0) { + // $currentStart = clone $currentTarget; + // $currentStart->addDay(); + // $currentTarget = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); + // } + // /* + // * If it's the first one, and has reminders, jump to the end of the [period] + // */ + // if ($i == 0 && !is_null($piggyBank->reminder)) { + // $currentTarget = \DateKit::endOfX($currentStart, $piggyBank->reminder); + // } + // if ($currentStart > $repetition->targetdate) { + // break; + // } + // + // + // /* + // * Jump one month ahead after the first instance: + // */ + // // if ($i > 0) { + // // $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); + // // /* + // // * Jump to the start of the period too: + // // */ + // // $currentStart = \DateKit::startOfPeriod($currentStart, $piggyBank->reminder); + // // + // // } + // + // + // /* + // * Move the current start to the actual start of + // * the [period] once the first iteration has passed. + // */ + // // if ($i != 0) { + // // $currentStart = \DateKit::startOfPeriod($currentStart, $piggyBank->reminder); + // // } + // // if($i == 0 && !is_null($piggyBank->reminder)) { + // // $currentEnd = \DateKit::startOfPeriod($currentStart, $piggyBank->reminder); + // // $currentEnd = \DateKit::endOfPeriod($currentEnd, $piggyBank->reminder); + // // } + // + // $part = new PiggybankPart; + // $part->setRepetition($repetition); + // $part->setAmount($currentAmount); + // $part->setAmountPerBar($amountPerBar); + // $part->setCurrentamount($repetition->currentamount); + // $part->setStartdate($currentStart); + // $part->setTargetdate($currentTarget); + // if (!is_null($piggyBank->reminder)) { + // // might be a reminder for this range? + // $reminder = $piggyBank->reminders() + // ->where('startdate', $currentStart->format('Y-m-d')) + // ->where('enddate', $currentTarget->format('Y-m-d')) + // ->first(); + // if ($reminder) { + // $part->setReminder($reminder); + // } + // + // } + // + // // if (!is_null($piggyBank->reminder)) { + // // $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); + // // $currentEnd = \DateKit::endOfPeriod($currentStart, $piggyBank->reminder); + // // } + // + // + // $bars->push($part); + // $currentAmount += $amountPerBar; + // } + // $repetition->bars = $bars; + // + // return $repetition; + // exit; + // + // + // $repetition->hello = 'World!'; + // + // return $repetition; + // + // $return = new Collection; + // $repetitions = $piggyBank->piggybankrepetitions()->get(); + // /** @var \PiggybankRepetition $repetition */ + // foreach ($repetitions as $repetition) { + // + // + // if (is_null($piggyBank->reminder)) { + // // simple, one part "repetition". + // $part = new PiggybankPart; + // $part->setRepetition($repetition); + // } else { + // $part = new PiggybankPart; + // } + // + // + // // end! + // $return->push($part); + // } + // + // exit; + // + // return $return; + // $piggyBank->currentRelevantRep(); // get the current relevant repetition. + // if (!is_null($piggyBank->reminder)) { + // switch ($piggyBank->reminder) { + // default: + // throw new FireflyException('Cannot handle "' . $piggyBank->reminder . '" reminders for repeated expenses'); + // break; + // case 'month': + // $start = clone $piggyBank->currentRep->startdate; + // $start->startOfMonth(); + // $end = clone $piggyBank->currentRep->targetdate; + // $end->endOfMonth(); + // $piggyBank->parts = $start->diffInMonths($end); + // unset($start, $end); + // break; + // } + // + // } else { + // $piggyBank->parts = 1; + // } + // + // // number of bars: + // $piggyBank->barCount = floor(12 / $piggyBank->parts) == 0 ? 1 : floor(12 / $piggyBank->parts); + // $amountPerBar = floatval($piggyBank->targetamount) / $piggyBank->parts; + // $currentAmount = floatval($amountPerBar); + // $bars = []; + // $currentStart = clone $piggyBank->currentRep->startdate; + // for ($i = 0; $i < $piggyBank->parts; $i++) { + // // niet elke keer een andere dinges pakken? om target te redden? + // if (!is_null($piggyBank->reminder)) { + // $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0); + // } + // $bars[] = [ + // 'amount' => $currentAmount, + // 'date' => $currentStart + // ]; + // + // + // $currentAmount += $amountPerBar; + // } + // $piggyBank->bars = $bars; } /** diff --git a/app/lib/FireflyIII/Shared/Toolkit/Reminders.php b/app/lib/FireflyIII/Shared/Toolkit/Reminders.php index 10197cf05b..52998712f5 100644 --- a/app/lib/FireflyIII/Shared/Toolkit/Reminders.php +++ b/app/lib/FireflyIII/Shared/Toolkit/Reminders.php @@ -86,7 +86,7 @@ class Reminders } ); $today = Carbon::now(); - //$today = new Carbon('15-12-2014'); + //$today = new Carbon('14-12-2014'); /** @var \Piggybank $piggybank */ foreach ($set as $piggybank) { diff --git a/app/models/Reminder.php b/app/models/Reminder.php index 199c5b66e8..0a28b43165 100644 --- a/app/models/Reminder.php +++ b/app/models/Reminder.php @@ -13,6 +13,7 @@ use LaravelBook\Ardent\Ardent; * @property \Carbon\Carbon $startdate * @property \Carbon\Carbon $enddate * @property boolean $active + * @property boolean $notnow * @property integer $remembersable_id * @property string $remembersable_type * @property-read \Piggybank $remindersable diff --git a/app/routes.php b/app/routes.php index d11b2b3e4a..7c39fb1ae1 100644 --- a/app/routes.php +++ b/app/routes.php @@ -223,6 +223,7 @@ Route::group( // reminder controller Route::get('/reminders/{reminder}',['uses' => 'ReminderController@show','as' => 'reminders.show']); Route::get('/reminders/{reminder}/dismiss',['uses' => 'ReminderController@dismiss','as' => 'reminders.dismiss']); + Route::get('/reminders/{reminder}/notnow',['uses' => 'ReminderController@notnow','as' => 'reminders.notnow']); Route::get('/reminders/{reminder}/act',['uses' => 'ReminderController@act','as' => 'reminders.act']); // search controller: diff --git a/app/views/reminders/show.blade.php b/app/views/reminders/show.blade.php index 0b12c927c5..8eb7068fb4 100644 --- a/app/views/reminders/show.blade.php +++ b/app/views/reminders/show.blade.php @@ -21,7 +21,7 @@

I want to do this I already did this - Not this time + Not this time

diff --git a/app/views/repeatedexpense/index.blade.php b/app/views/repeatedexpense/index.blade.php index eb8765a4ee..00b8115387 100644 --- a/app/views/repeatedexpense/index.blade.php +++ b/app/views/repeatedexpense/index.blade.php @@ -36,7 +36,7 @@ $barSize = floor(12 / $entry->currentRep->bars->count()) == 0 ? 1 : floor(12 / $ @foreach($entry->currentRep->bars as $bar)
- +
diff --git a/app/views/repeatedexpense/show.blade.php b/app/views/repeatedexpense/show.blade.php index ed22a28dd4..1e29b380dc 100644 --- a/app/views/repeatedexpense/show.blade.php +++ b/app/views/repeatedexpense/show.blade.php @@ -26,38 +26,33 @@ @foreach($rep->bars as $bar)
- -
-
+ +
+ @if($bar->percentage() > 50 && $bar->percentage() == 100) + @if($bar->hasReminder() && $bar->getReminder()->active == 1) + + @endif + @if($bar->hasReminder() && $bar->getReminder()->active == 0 && $bar->getReminder()->notnow == 0) + + @endif + @if($bar->hasReminder() && $bar->getReminder()->active == 0 && $bar->getReminder()->notnow == 1) + + @endif + @endif + @if($bar->percentage() > 50 && $bar->percentage() < 100) + {{mf($rep->currentamount,false)}} + @endif +
+
+
-

- - {{-- - @if($bar->hasReminder()) - - {{DateKit::periodShow($bar->getStartDate(),$piggyBank->reminder)}} - - @else - @if(!is_null($piggyBank->reminder)) - {{DateKit::periodShow($bar->getStartDate(),$piggyBank->reminder)}} - @endif - @endif - --}} - {{$bar->getStartDate()->format('d/m/y')}} → {{$bar->getTargetDate()->format('d/m/y')}} - @if($bar->hasReminder()) - ! - @endif -

@endforeach
@endforeach - @foreach($piggyBank->reminders()->get() as $reminder) - Reminder: #{{$reminder->id}} [from: {{$reminder->startdate->format('d/m/y')}}, to: {{$reminder->enddate->format('d/m/y')}}]
- @endforeach @stop \ No newline at end of file