mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Avoid using model methods and use repository instead
This commit is contained in:
@@ -125,6 +125,23 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $account->notes()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get note text or null.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getNoteText(Account $account): ?string
|
||||
{
|
||||
$note = $account->notes()->first();
|
||||
if (is_null($note)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of the opening balance for this account.
|
||||
*
|
||||
@@ -285,5 +302,4 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,6 +145,15 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getNote(Account $account): ?Note;
|
||||
|
||||
/**
|
||||
* Get note text or null.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getNoteText(Account $account): ?string;
|
||||
|
||||
/**
|
||||
* Returns the amount of the opening balance for this account.
|
||||
*
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Journal;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Factory\TransactionJournalFactory;
|
||||
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -384,7 +385,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return new Carbon($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
@@ -392,7 +393,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
$value = new Carbon($entry->data);
|
||||
$cache->store($value);
|
||||
$cache->store($entry->data);
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -597,6 +598,52 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set meta field for journal that contains a date.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $name
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMetaDate(TransactionJournal $journal, string $name, Carbon $date): void
|
||||
{
|
||||
/** @var TransactionJournalMetaFactory $factory */
|
||||
$factory = app(TransactionJournalMetaFactory::class);
|
||||
$factory->updateOrCreate(
|
||||
[
|
||||
'data' => $date,
|
||||
'journal' => $journal,
|
||||
'name' => $name,
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set meta field for journal that contains string.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function setMetaString(TransactionJournal $journal, string $name, string $value): void
|
||||
{
|
||||
/** @var TransactionJournalMetaFactory $factory */
|
||||
$factory = app(TransactionJournalMetaFactory::class);
|
||||
$factory->updateOrCreate(
|
||||
[
|
||||
'data' => $value,
|
||||
'journal' => $journal,
|
||||
'name' => $name,
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $order
|
||||
|
||||
@@ -262,6 +262,26 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function reconcileById(int $transactionId): bool;
|
||||
|
||||
/**
|
||||
* Set meta field for journal that contains a date.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $name
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMetaDate(TransactionJournal $journal, string $name, Carbon $date): void;
|
||||
|
||||
/**
|
||||
* Set meta field for journal that contains string.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function setMetaString(TransactionJournal $journal, string $name, string $value): void;
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $order
|
||||
|
||||
Reference in New Issue
Block a user