mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Merge pull request #594 from Zsub/show-suggested-monthly-savings
Show suggested monthly savings for a piggybank
This commit is contained in:
@@ -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>
|
||||||
|
Reference in New Issue
Block a user