mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
First code for #2723
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
@@ -377,4 +378,26 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSourceAccount(TransactionJournal $journal): Account
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->with('account')->where('amount', '<', 0)->first();
|
||||
|
||||
return $transaction->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->with('account')->where('amount', '>', 0)->first();
|
||||
|
||||
return $transaction->account;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
@@ -109,6 +110,22 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getJournalSourceAccounts(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* Returns the source account of the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @return Account
|
||||
*/
|
||||
public function getSourceAccount(TransactionJournal $journal): Account;
|
||||
|
||||
/**
|
||||
* Returns the destination account of the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @return Account
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account;
|
||||
|
||||
/**
|
||||
* Return total amount of journal. Is always positive.
|
||||
*
|
||||
|
Reference in New Issue
Block a user