Skip to content

Firefly III: a personal finances manager

Extended IBAN validation

Sander Dorigo0cab974048be
diff --git a/app/Validation/Account/WithdrawalValidation.php b/app/Validation/Account/WithdrawalValidation.php
index 21e5522e41..6414d40556 100644
--- a/app/Validation/Account/WithdrawalValidation.php
+++ b/app/Validation/Account/WithdrawalValidation.php
@@ -92,10 +92,11 @@ trait WithdrawalValidation
{
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
+ $accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
Log::debug('Now in validateWithdrawalDestination()', $array);
// source can be any of the following types.
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
- if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
+ if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
// if both values are NULL return false,
// because the destination of a withdrawal can never be created automatically.
$this->destError = (string)trans('validation.withdrawal_dest_need_data');
@@ -117,6 +118,15 @@ trait WithdrawalValidation
return false;
}
}
+ // if there is an iban, it can only be in use by a revenue account or we will fail.
+ if(null !== $accountIban && '' !== $accountIban) {
+ app('log')->debug('Check if there is not already an account with this IBAN');
+ $existing = $this->findExistingAccount([AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], ['iban' => $accountIban]);
+ if(null !== $existing) {
+ $this->destError = (string)trans('validation.withdrawal_dest_iban_exists');
+ return false;
+ }
+ }
// if the account can be created anyway don't need to search.
return true === $this->canCreateTypes($validTypes);
diff --git a/config/firefly.php b/config/firefly.php
index 59568808cc..33b2957e63 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -107,7 +107,7 @@ return [
'webhooks' => true,
'handle_debts' => true,
],
- 'version' => '6.0.15',
+ 'version' => '6.0.16',
'api_version' => '2.0.4',
'db_version' => 19,
diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php
index b113b9352a..242b83aa0e 100644
--- a/resources/lang/en_US/validation.php
+++ b/resources/lang/en_US/validation.php
@@ -208,6 +208,9 @@ return [
'withdrawal_dest_need_data' => '[a] Need to get a valid destination account ID and/or valid destination account name to continue.',
'withdrawal_dest_bad_data' => 'Could not find a valid destination account when searching for ID ":id" or name ":name".',
+ 'withdrawal_dest_iban_exists' => 'This destination account IBAN is already in use by an asset account or a liability and cannot be used as a withdrawal destination.',
+ 'deposit_src_iban_exists' => 'This source account IBAN is already in use by an asset account or a liability and cannot be used as a deposit source.',
+
'reconciliation_source_bad_data' => 'Could not find a valid reconciliation account when searching for ID ":id" or name ":name".',
'generic_source_bad_data' => '[e] Could not find a valid source account when searching for ID ":id" or name ":name".',