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

@@ -530,12 +530,10 @@ class AccountRepository implements AccountRepositoryInterface
}
// opening balance data? update it!
if (!is_null($openingBalance->id)) {
$date = $data['openingBalanceDate'];
$amount = $data['openingBalance'];
Log::debug('Opening balance journal found, update journal.');
$this->updateOpeningBalanceJournal($account, $openingBalance, $date, $amount);
$this->updateOpeningBalanceJournal($account, $openingBalance, $data);
return true;
}
@@ -589,15 +587,19 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param Account $account
* @param TransactionJournal $journal
* @param Carbon $date
* @param float $amount
* @param array $data
*
* @return bool
*/
protected function updateOpeningBalanceJournal(Account $account, TransactionJournal $journal, Carbon $date, float $amount): bool
protected function updateOpeningBalanceJournal(Account $account, TransactionJournal $journal, array $data): bool
{
$date = $data['openingBalanceDate'];
$amount = $data['openingBalance'];
$currencyId = intval($data['currency_id']);
// update date:
$journal->date = $date;
$journal->date = $date;
$journal->transaction_currency_id = $currencyId;
$journal->save();
// update transactions:
/** @var Transaction $transaction */