mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
Add budget warnings #1202
This commit is contained in:
@@ -48,6 +48,33 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* A method that returns the amount of money budgeted per day for this budget,
|
||||
* on average.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function budgetedPerDay(Budget $budget): string
|
||||
{
|
||||
$total = '0';
|
||||
$count = 0;
|
||||
foreach ($budget->budgetlimits as $limit) {
|
||||
$diff = strval($limit->start_date->diffInDays($limit->end_date));
|
||||
$amount = strval($limit->amount);
|
||||
$perDay = bcdiv($amount, $diff);
|
||||
$total = bcadd($total, $perDay);
|
||||
$count++;
|
||||
}
|
||||
$avg = $total;
|
||||
if ($count > 0) {
|
||||
$avg = bcdiv($total, strval($count));
|
||||
}
|
||||
|
||||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
|
Reference in New Issue
Block a user