- Added new phrase for the validation

- Better check for the SWIFT/BIC code
- Checks if the IBAN and the SWIFT/BIC codes are for the same country
This commit is contained in:
Paolo
2024-12-17 11:12:41 +01:00
parent b3f0d2d679
commit f809a4e5ee
2 changed files with 45 additions and 4 deletions
@@ -99,7 +99,7 @@ class Bank extends FHCAPI_Controller
$this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel');
// Checks if the logged user is an amployee, in case stop the execution
if ($this->MitarbeiterModel->isMitarbeiter($loggedUID)) $this->terminateWithValidationErrors(array('' => $this->p->t('person', 'notForEmployees')));
if (!$this->MitarbeiterModel->isMitarbeiter($loggedUID)) $this->terminateWithValidationErrors(array('' => $this->p->t('person', 'notForEmployees')));
// Loads the CI validation library
$this->load->library('form_validation');
@@ -120,6 +120,9 @@ class Bank extends FHCAPI_Controller
$iban = preg_replace("/[^A-Za-z0-9 ]/", '', $this->input->post(self::IBAN_PARAM));
if (!verify_iban($iban)) $this->terminateWithValidationErrors(array('iban' => $this->p->t('person', 'notValidaIBAN')));
// If the IBAN and the BIC code are for different countries
if (substr($iban, 0, 2) != substr($bic, 4, 2)) $this->terminateWithValidationErrors(array('' => $this->p->t('person', 'ibanBicCountryNotMatch')));
// Check if there is at least a record in the bank data table
$bankDataResult = $this->BankverbindungModel->execReadOnlyQuery(
'SELECT
@@ -181,12 +184,30 @@ class Bank extends FHCAPI_Controller
}
/**
* Generic BIC check
* Generic SWIFT/BIC check
* Given the fake SWIFT/BIC: TBIC AT 12 ABC
* - 4 letters: Institution Code or bank code.
* - 2 letters: ISO 3166-1 alpha-2 country code
* - 2 letters or digits: location code
* (8 chars BIC)
* - 3 letters or digits: branch code, optional
* (11 chars BIC)
*/
private function _checkBic($bic)
{
// Check if the provided BIC is fine
return preg_match("^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$^", $bic) == 1;
// If the provided BIC is made up of 11 chars
if (strlen($bic) == 11)
{
// Check if the provided BIC is fine
return preg_match("^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$^", $bic) == 1;
}
elseif (strlen($bic) == 8) // otherwise if it is made up of 8 chars
{
// Check if the provided BIC is fine
return preg_match("^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}?$^", $bic) == 1;
}
return false;
}
}
+20
View File
@@ -37277,6 +37277,26 @@ array(
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'person',
'phrase' => 'ibanBicCountryNotMatch',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'IBAN and BIC codes are not for the same country DE',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'IBAN and BIC codes are not for the same country',
'description' => '',
'insertvon' => 'system'
)
)
)
);