Some small fixes.

This commit is contained in:
James Cole
2015-07-07 10:05:11 +02:00
parent 76a1b2cd51
commit 3172bc90da
3 changed files with 22 additions and 27 deletions

View File

@@ -26,9 +26,7 @@ class ComponentRepository
*/
protected function spentInPeriod($object, Carbon $start, Carbon $end, $shared = false)
{
// we must cache this.
$cache = new CacheProperties;
$cache = new CacheProperties; // we must cache this.
$cache->addProperty($object->id);
$cache->addProperty(get_class($object));
$cache->addProperty($start);
@@ -40,21 +38,13 @@ class ComponentRepository
return $cache->get(); // @codeCoverageIgnore
}
if ($shared === true) {
// shared is true.
// always ignore transfers between accounts!
$sum
= $object->transactionjournals()
->transactionTypes(['Withdrawal'])
->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount');
if ($shared === true) { // shared is true: always ignore transfers between accounts!
$sum = $object->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start)
->get(['transaction_journals.*'])->sum('amount');
} else {
// do something else, SEE budgets.
// get all journals in this month where the asset account is NOT shared.
$sum = $object->transactionjournals()
->before($end)
->after($start)
$sum = $object->transactionjournals()->before($end)->after($start)
->transactionTypes(['Withdrawal'])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
@@ -62,9 +52,7 @@ class ComponentRepository
'account_meta', function (JoinClause $join) {
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
}
)
->where('account_meta.data', '!=', '"sharedAsset"')
->get(['transaction_journals.*'])->sum('amount');
)->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('amount');
}
$cache->store($sum);