diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index f126d66605..9e320e3034 100644 --- a/app/Services/Internal/Support/AccountServiceTrait.php +++ b/app/Services/Internal/Support/AccountServiceTrait.php @@ -329,18 +329,22 @@ trait AccountServiceTrait /** @var AccountMeta $entry */ $entry = $account->accountMeta()->where('name', $field)->first(); - // if $data has field and $entry is null, create new one: - if (isset($data[$field]) && null === $entry) { - Log::debug(sprintf('Created meta-field "%s":"%s" for account #%d ("%s") ', $field, $data[$field], $account->id, $account->name)); - $factory->create(['account_id' => $account->id, 'name' => $field, 'data' => $data[$field],]); - } + // must not be an empty string: + if (isset($data[$field]) && strlen((string)$data[$field]) > 0) { - // if $data has field and $entry is not null, update $entry: - // let's not bother with a service. - if (isset($data[$field]) && null !== $entry) { - $entry->data = $data[$field]; - $entry->save(); - Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $data[$field], $account->id, $account->name)); + // if $data has field and $entry is null, create new one: + if (null === $entry) { + Log::debug(sprintf('Created meta-field "%s":"%s" for account #%d ("%s") ', $field, $data[$field], $account->id, $account->name)); + $factory->create(['account_id' => $account->id, 'name' => $field, 'data' => $data[$field],]); + } + + // if $data has field and $entry is not null, update $entry: + // let's not bother with a service. + if (null !== $entry) { + $entry->data = $data[$field]; + $entry->save(); + Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $data[$field], $account->id, $account->name)); + } } } } diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.php index c9711c0b46..e286d702d1 100644 --- a/app/Services/Internal/Update/AccountUpdateService.php +++ b/app/Services/Internal/Update/AccountUpdateService.php @@ -51,6 +51,10 @@ class AccountUpdateService $account->iban = $data['iban']; $account->save(); + if($data['currency_id'] === 0) { + unset($data['currency_id']); + } + // update all meta data: $this->updateMetaData($account, $data);