mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Show suggested monthly savings for a piggybank
If a piggybank has both a target date and a target amount, show how much money needs to be added to the piggybank each month to achieve both targets. Strings are currently hard-coded because I want to gauge the reaction to this :)
This commit is contained in:
parent
e737683efb
commit
a0e66b913b
@ -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.
|
* Get all of the piggy bank's notes.
|
||||||
*/
|
*/
|
||||||
|
@ -39,6 +39,12 @@ class PiggyBank extends Twig_Extension
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$functions[] = new Twig_SimpleFunction(
|
||||||
|
'suggestedMonthlyAmount', function (PB $piggyBank) {
|
||||||
|
return $piggyBank->getSuggestedMonthlyAmount();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return $functions;
|
return $functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,14 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if piggyBank.targetdate %}
|
||||||
|
<tr>
|
||||||
|
<td>Suggested monthly amount to save</td>
|
||||||
|
<td>
|
||||||
|
{{ suggestedMonthlyAmount(piggyBank)|formatAmount }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user