This commit is contained in:
James Cole
2019-08-02 05:44:51 +02:00
parent ac903b88ba
commit 3dbde59787
4 changed files with 97 additions and 5 deletions

View File

@@ -867,4 +867,33 @@ class JournalRepository implements JournalRepositoryInterface
->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account'])
->get(['transaction_journals.*']);
}
/**
* Return Carbon value of a meta field (or NULL).
*
* @param int $journalId
* @param string $field
*
* @return null|Carbon
*/
public function getMetaDateById(int $journalId, string $field): ?Carbon
{
$cache = new CacheProperties;
$cache->addProperty('journal-meta-updated');
$cache->addProperty($journalId);
$cache->addProperty($field);
if ($cache->has()) {
return new Carbon($cache->get()); // @codeCoverageIgnore
}
$entry = TransactionJournalMeta::where('transaction_journal_id', $journalId)
->where('name', $field)->first();
if (null === $entry) {
return null;
}
$value = new Carbon($entry->data);
$cache->store($entry->data);
return $value;
}
}

View File

@@ -238,6 +238,16 @@ interface JournalRepositoryInterface
*/
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon;
/**
* Return Carbon value of a meta field (or NULL).
*
* @param int $journalId
* @param string $field
*
* @return null|Carbon
*/
public function getMetaDateById(int $journalId, string $field): ?Carbon;
/**
* Return string value of a meta date (or NULL).
*