diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d0992f9627..e16a91807b 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -42,6 +42,7 @@ class AccountController extends Controller $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what); $subTitle = trans('firefly.make_new_' . $what . '_account'); + Session::flash('preFilled', []); // put previous url in session if not redirect from store (not "create another"). if (session('accounts.create.fromStore') !== true) { diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 6e98cf72f3..20fcfdc67b 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -34,6 +34,9 @@ class AccountRepository implements AccountRepositoryInterface /** @var User */ private $user; + /** @var array */ + private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber']; + /** * AttachmentRepository constructor. * @@ -448,7 +451,7 @@ class AccountRepository implements AccountRepositoryInterface $this->updateMetadata($account, $data); $openingBalance = $this->openingBalanceTransaction($account); if ($data['openingBalance'] != 0) { - if ($openingBalance) { + if (!is_null($openingBalance->id)) { $this->updateInitialBalance($account, $openingBalance, $data); } else { $type = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; @@ -570,8 +573,7 @@ class AccountRepository implements AccountRepositoryInterface */ protected function storeMetadata(Account $account, array $data) { - $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType']; - foreach ($validFields as $field) { + foreach ($this->validFields as $field) { if (isset($data[$field])) { $metaData = new AccountMeta( [ @@ -621,9 +623,7 @@ class AccountRepository implements AccountRepositoryInterface */ protected function updateMetadata(Account $account, array $data) { - $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType']; - - foreach ($validFields as $field) { + foreach ($this->validFields as $field) { $entry = $account->accountMeta()->where('name', $field)->first(); if (isset($data[$field])) {