This commit is contained in:
James Cole
2018-05-26 07:48:49 +02:00
parent 4031057bc0
commit 664451d0c6
12 changed files with 88 additions and 50 deletions

View File

@@ -36,6 +36,11 @@ use FireflyIII\Models\Account;
/**
* Class PiggyBank.
*
* @property Carbon $targetdate
* @property Carbon $startdate
* @property string $targetamount
*
*/
class PiggyBank extends Model
{
@@ -132,32 +137,6 @@ class PiggyBank extends Model
return $value;
}
/**
* @deprecated
* @return string
*/
public function getSuggestedMonthlyAmount(): string
{
$savePerMonth = '0';
if ($this->targetdate && $this->currentRelevantRep()->currentamount < $this->targetamount) {
$now = Carbon::now();
$diffInMonths = $now->diffInMonths($this->targetdate, false);
$remainingAmount = bcsub($this->targetamount, $this->currentRelevantRep()->currentamount);
// more than 1 month to go and still need money to save:
if ($diffInMonths > 0 && 1 === bccomp($remainingAmount, '0')) {
$savePerMonth = bcdiv($remainingAmount, (string)$diffInMonths);
}
// less than 1 month to go but still need money to save:
if (0 === $diffInMonths && 1 === bccomp($remainingAmount, '0')) {
$savePerMonth = $remainingAmount;
}
}
return $savePerMonth;
}
/**
* @param Carbon $date
*

View File

@@ -29,6 +29,7 @@ use FireflyIII\Models\PiggyBank;
/**
* Class PiggyBankRepetition.
* @property string $currentamount
*/
class PiggyBankRepetition extends Model
{