New methods.

This commit is contained in:
James Cole 2014-11-26 17:20:18 +01:00
parent 9f926394a6
commit 69b36ddd1d
2 changed files with 32 additions and 0 deletions

View File

@ -467,5 +467,23 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
}
/**
* @param \Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Pagination\Paginator
*/
public function getTransactionJournalsInRange(\Account $account, Carbon $start, Carbon $end)
{
$set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->leftJoin(
'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
)->where('transactions.account_id', $account->id)->before($end)->after($start)->orderBy('date', 'DESC')->get(
['transaction_journals.*']
);
return $set;
}
}

View File

@ -250,4 +250,18 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
return $sum;
}
/**
* @param \Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return float
*/
public function spentInPeriod(\Budget $budget, Carbon $start, Carbon $end)
{
$sum = floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
return $sum;
}
}