Make sure that accounts and their opening balance values are the same currency.

This commit is contained in:
James Cole
2017-04-14 07:11:30 +02:00
parent 89ee9c058a
commit 953c38563b
10 changed files with 180 additions and 21 deletions

View File

@@ -211,6 +211,26 @@ class Account extends Model
return $value;
}
/**
* Returns the opening balance
*
* @return TransactionJournal
* @throws FireflyException
*/
public function getOpeningBalance(): TransactionJournal
{
$journal = TransactionJournal::sortCorrectly()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $this->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
return new TransactionJournal;
}
return $journal;
}
/**
* Returns the amount of the opening balance for this account.
*