Some fixes for budgets

This commit is contained in:
Sander Dorigo
2014-11-04 20:37:00 +01:00
parent 09e1f68c69
commit aaab7f8e0e
13 changed files with 676 additions and 274 deletions

View File

@@ -106,7 +106,22 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
*/
public function get()
{
return $this->getUser()->budgets()->get();
$budgets = $this->getUser()->budgets()->get();
return $budgets;
}
/**
* @param \Budget $budget
* @param Carbon $date
* @return float
*/
public function spentInMonth(\Budget $budget, Carbon $date) {
$end = clone $date;
$date->startOfMonth();
$end->endOfMonth();
$sum = floatval($budget->transactionjournals()->before($end)->after($date)->lessThan(0)->sum('amount')) * -1;
return $sum;
}
/**