Merge pull request #594 from Zsub/show-suggested-monthly-savings

Show suggested monthly savings for a piggybank
This commit is contained in:
James Cole 2017-02-25 05:24:05 +01:00 committed by GitHub
commit 444439fdab
3 changed files with 25 additions and 0 deletions

View File

@ -129,6 +129,17 @@ class PiggyBank extends Model
}
public function getSuggestedMonthlyAmount()
{
if ($this->targetdate && $this->currentRelevantRep()->currentamount < $this->targetamount) {
$thisMonth = Carbon::now()->month;
$targetMonth = $this->targetdate->month;
$remainingAmount = $this->targetamount - $this->currentRelevantRep()->currentamount;
return $thisMonth < $targetMonth ? $remainingAmount / ($targetMonth - $thisMonth) : $remainingAmount ;
}
return 0;
}
/**
* Get all of the piggy bank's notes.
*/

View File

@ -39,6 +39,12 @@ class PiggyBank extends Twig_Extension
}
);
$functions[] = new Twig_SimpleFunction(
'suggestedMonthlyAmount', function (PB $piggyBank) {
return $piggyBank->getSuggestedMonthlyAmount();
}
);
return $functions;
}

View File

@ -70,6 +70,14 @@
{% endif %}
</td>
</tr>
{% if piggyBank.targetdate %}
<tr>
<td>Suggested monthly amount to save</td>
<td>
{{ suggestedMonthlyAmount(piggyBank)|formatAmount }}
</td>
</tr>
{% endif %}
</table>
</div>
</div>