Add budget warnings #1202

This commit is contained in:
James Cole
2018-03-24 06:46:37 +01:00
parent dafddfa39a
commit 310ed9f504
6 changed files with 630 additions and 543 deletions

View File

@@ -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
*