diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php index 5c54acc7b8..b754e133f2 100644 --- a/app/models/Piggybank.php +++ b/app/models/Piggybank.php @@ -104,68 +104,6 @@ class Piggybank extends Ardent return ['created_at', 'updated_at', 'targetdate', 'startdate']; } - /** - * Firefly shouldn't create piggybank repetions that completely - * lie in the future, so we should be able to safely grab the "latest" - * one and use that to calculate when the user will be reminded. - */ - public function nextReminderDate() - { - if (is_null($this->reminder)) { - return null; - } - /** @var \PiggybankRepetition $rep */ - $rep = $this->currentRelevantRep(); - $today = new Carbon; - if ($rep && is_null($rep->startdate)) { - switch ($this->reminder) { - case 'day': - return $today; - break; - case 'week': - return $today->endOfWeek(); - break; - case 'month': - return $today->endOfMonth(); - break; - case 'year': - return $today->endOfYear(); - break; - - } - return null; - } - if ($rep && !is_null($rep->startdate)) { - // start with the start date - // when its bigger than today, return it: - $start = clone $rep->startdate; - while ($start <= $today) { - switch ($this->reminder) { - default: - return null; - break; - case 'day': - $start->addDay(); - break; - case 'week': - $start->addWeek(); - break; - case 'month': - $start->addMonth(); - break; - case 'year': - $start->addYear(); - break; - - } - } - - return $start; - } - - return new Carbon; - } - /** * Grabs the PiggyBankRepetition that's currently relevant / active * @@ -222,14 +160,6 @@ class Piggybank extends Ardent return $this->hasMany('PiggybankEvent'); } - /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function piggybankreminders() - { - return $this->hasMany('PiggybankReminder'); - } - /** * Same but for specific date. * diff --git a/app/models/PiggybankReminder.php b/app/models/PiggybankReminder.php index 58ab497e6d..1910ad964c 100644 --- a/app/models/PiggybankReminder.php +++ b/app/models/PiggybankReminder.php @@ -1,105 +1,8 @@ piggybank; - - - $fullText - = 'In order to save enough money for "' . e( - $piggyBank->name - ) . '" you'; - - $fullText .= ' should save at least ' . mf($this->amountToSave(), false) . ' this ' . $piggyBank->reminder - . ', before ' . $this->enddate->format('M jS, Y'); - - return $fullText; - } - - - /** - * @return float - * @throws Firefly\Exception\FireflyException - */ - public function amountToSave() - { - /** @var \Piggybank $piggyBank */ - $piggyBank = $this->piggybank; - /** @var \PiggybankRepetition $repetition */ - $repetition = $piggyBank->currentRelevantRep(); - - // if the target date of the repetition is zero, we use the created_at date of the repetition - // and add two years; it's the same routine used elsewhere. - if (is_null($repetition->targetdate)) { - $targetdate = clone $repetition->created_at; - $targetdate->addYears(2); - } else { - $targetdate = $repetition->targetdate; - } - - - $today = new Carbon; - $diff = $today->diff($targetdate); - $left = $piggyBank->targetamount - $repetition->currentamount; - // to prevent devide by zero: - $piggyBank->reminder_skip = $piggyBank->reminder_skip < 1 ? 1 : $piggyBank->reminder_skip; - $toSave = 0; - switch ($piggyBank->reminder) { - case 'day': - $toSave = $left;// / ($diff->days / $piggyBank->reminder_skip); - break; - case 'week': - $weeks = ceil($diff->days / 7); - $toSave = $left / ($weeks / $piggyBank->reminder_skip); - break; - case 'month': - $toSave = $left / ($diff->m / $piggyBank->reminder_skip); - break; - case 'year': - throw new \Firefly\Exception\FireflyException('No impl year reminder/ PiggyBankReminder Render'); - break; - } - - return floatval($toSave); - } } \ No newline at end of file