Remove spaces from account numbers.

This commit is contained in:
James Cole
2025-05-29 22:04:42 +02:00
parent 08e2c1684f
commit 7e9c5a668f
2 changed files with 19 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ class CorrectsIbans extends Command
*/ */
public function handle(): int public function handle(): int
{ {
$accounts = Account::whereNotNull('iban')->get(); $accounts = Account::with('accountMeta')->get();
$this->filterIbans($accounts); $this->filterIbans($accounts);
$this->countAndCorrectIbans($accounts); $this->countAndCorrectIbans($accounts);
@@ -62,6 +62,18 @@ class CorrectsIbans extends Command
$this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id)); $this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id));
++$this->count; ++$this->count;
} }
// same for account number:
$accountNumber = $account->accountMeta->where('name', 'account_number')->first();
if(null !== $accountNumber) {
$number = (string) $accountNumber->value;
$newNumber = app('steam')->filterSpaces($number);
if ('' !== $number && $number !== $newNumber) {
$accountNumber->value = $newNumber;
$accountNumber->save();
$this->friendlyInfo(sprintf('Removed spaces from account number of account #%d', $account->id));
++$this->count;
}
}
} }
} }

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use FireflyIII\Support\Facades\Steam;
/** /**
* Class AccountMetaFactory * Class AccountMetaFactory
@@ -41,11 +42,16 @@ class AccountMetaFactory
$entry = $account->accountMeta()->where('name', $field)->first(); $entry = $account->accountMeta()->where('name', $field)->first();
// must not be an empty string: // must not be an empty string:
if ('' !== $value) { if ('' !== $value) {
if('account_number' === $field) {
$value = Steam::filterSpaces($value);
$value = trim(str_replace([' ',"\t", "\n", "\r"], '', $value));
}
// if $data has field and $entry is null, create new one: // if $data has field and $entry is null, create new one:
if (null === $entry) { if (null === $entry) {
return $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]); return $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]);
} }
// if $data has field and $entry is not null, update $entry: // if $data has field and $entry is not null, update $entry:
$entry->data = $value; $entry->data = $value;
$entry->save(); $entry->save();