Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Was not able to remove opening balance.
James Cole74664afa682b
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 423efcd23e..122e8f7d5c 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -466,7 +466,12 @@ class AccountRepository implements AccountRepositoryInterface*/protected function storeInitialBalance(Account $account, array $data): TransactionJournal{- $amount = $data['openingBalance'];+ $amount = strval($data['openingBalance']);++ if (bccomp($amount, '0') === 0) {+ return new TransactionJournal;+ }+$name = $data['name'];$currencyId = $data['currency_id'];$opposing = $this->storeOpposingAccount($name);@@ -487,12 +492,12 @@ class AccountRepository implements AccountRepositoryInterface$firstAccount = $account;$secondAccount = $opposing;$firstAmount = $amount;- $secondAmount = $amount * -1;+ $secondAmount = bcmul($amount, '-1');if ($data['openingBalance'] < 0) {$firstAccount = $opposing;$secondAccount = $account;- $firstAmount = $amount * -1;+ $firstAmount = bcmul($amount, '-1');$secondAmount = $amount;}@@ -606,9 +611,15 @@ class AccountRepository implements AccountRepositoryInterfaceprotected function updateOpeningBalanceJournal(Account $account, TransactionJournal $journal, array $data): bool{$date = $data['openingBalanceDate'];- $amount = $data['openingBalance'];+ $amount = strval($data['openingBalance']);$currencyId = intval($data['currency_id']);+ if (bccomp($amount, '0') === 0) {+ $journal->delete();++ return true;+ }+// update date:$journal->date = $date;$journal->transaction_currency_id = $currencyId;@@ -621,7 +632,7 @@ class AccountRepository implements AccountRepositoryInterface$transaction->save();}if ($account->id != $transaction->account_id) {- $transaction->amount = $amount * -1;+ $transaction->amount = bcmul($amount, '-1');$transaction->save();}}@@ -631,6 +642,7 @@ class AccountRepository implements AccountRepositoryInterface}+/*** @param array $data*@@ -638,9 +650,7 @@ class AccountRepository implements AccountRepositoryInterface*/protected function validOpeningBalanceData(array $data): bool{- if (isset($data['openingBalance']) && isset($data['openingBalanceDate'])- && bccomp(strval($data['openingBalance']), '0') !== 0- ) {+ if (isset($data['openingBalance']) && isset($data['openingBalanceDate'])) {Log::debug('Array has valid opening balance data.');return true;