Move common methods to traits

This commit is contained in:
James Cole
2018-02-23 15:12:47 +01:00
parent 38c1d332e2
commit dae3371c69
9 changed files with 478 additions and 611 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TransactionJournalFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@@ -300,14 +301,43 @@ class JournalRepository implements JournalRepositoryInterface
* @return TransactionJournal
*
* @throws \FireflyIII\Exceptions\FireflyException
* @throws Exception
*/
public function update(TransactionJournal $journal, array $data): TransactionJournal
{
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->setUser($this->user);
return $service->update($journal, $data);
try {
$journal = $service->update($journal, $data);
} catch (FireflyException | Exception $e) {
throw new FireflyException($e->getMessage());
}
return $journal;
}
/**
* Get account of transaction that is more than zero. Only works with unsplit journals.
*
* @param TransactionJournal $journal
*
* @return Account
*/
public function getDestinationAccount(TransactionJournal $journal): Account
{
return $journal->transactions()->where('amount','<',0)->first()->account;
}
/**
* Get account of transaction that is less than zero. Only works with unsplit journals.
*
* @param TransactionJournal $journal
*
* @return Account
*/
public function getSourceAccount(TransactionJournal $journal): Account
{
return $journal->transactions()->where('amount','>',0)->first()->account;
}
}