use journal repository instead of direct calls.

This commit is contained in:
James Cole
2018-02-25 19:09:05 +01:00
parent 99983a5c8f
commit 1b304bf85e
18 changed files with 175 additions and 222 deletions

View File

@@ -356,6 +356,30 @@ class JournalRepository implements JournalRepositoryInterface
return $list;
}
/**
* Return total amount of journal. Is always positive.
*
* @param TransactionJournal $journal
*
* @return string
*/
public function getJournalTotal(TransactionJournal $journal): string
{
$cache = new CacheProperties;
$cache->addProperty($journal->id);
$cache->addProperty('amount-positive');
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
// saves on queries:
$amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount');
$amount = strval($amount);
$cache->store($amount);
return $amount;
}
/**
* Return value of a meta field (or NULL) as a string.
*
@@ -475,6 +499,24 @@ class JournalRepository implements JournalRepositoryInterface
return $set;
}
/**
* Will tell you if journal is reconciled or not.
*
* @param TransactionJournal $journal
*
* @return bool
*/
public function isJournalReconciled(TransactionJournal $journal): bool
{
foreach ($journal->transactions as $transaction) {
if ($transaction->reconciled) {
return true;
}
}
return false;
}
/**
* @param Transaction $transaction
*