forked from Wavyzz/dolibarr
Merge pull request #33091 from francoisPE/isInSEPA
FIX #33090 Is in sepa
This commit is contained in:
@@ -824,7 +824,7 @@ function getFormeJuridiqueLabel($code)
|
||||
* Return list of countries that are inside the EEC (European Economic Community)
|
||||
* Note: Try to keep this function as a "memory only" function for performance reasons.
|
||||
*
|
||||
* @return string[] Array of countries code in EEC
|
||||
* @return string[] Array of country codes in EEC
|
||||
*/
|
||||
function getCountriesInEEC()
|
||||
{
|
||||
@@ -875,6 +875,61 @@ function isInEEC($object)
|
||||
return in_array($object->country_code, $country_code_in_EEC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of countries that are inside the SEPA zone (Single Euro Payment Area)
|
||||
* Note: Try to keep this function as a "memory only" function for performance reasons.
|
||||
*
|
||||
* @return string[] Array of country codes in SEPA
|
||||
*/
|
||||
function getCountriesInSEPA()
|
||||
{
|
||||
// List of all country codes that are in Europe agreement for bank transferts
|
||||
// List found on https://www.ecb.europa.eu/paym/integration/retail/sepa/html/index.en.html
|
||||
global $conf, $db;
|
||||
$country_code_in_SEPA = array();
|
||||
|
||||
if (!empty($conf->cache['country_code_in_SEPA'])) {
|
||||
// Use of cache to reduce number of database requests
|
||||
$country_code_in_SEPA = $conf->cache['country_code_in_SEPA'];
|
||||
} else {
|
||||
$sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
|
||||
$sql .= " WHERE cc.sepa = 1";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$objp = $db->fetch_object($resql);
|
||||
$country_code_in_SEPA[] = $objp->code;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
$conf->cache['country_code_in_SEPA'] = $country_code_in_SEPA;
|
||||
}
|
||||
return $country_code_in_SEPA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a country of an object is inside the SEPA zone (Single Euro Payment Area)
|
||||
*
|
||||
* @param Object $object Object
|
||||
* @return boolean true = ccountry inside SEPA, false = country outside SEPA
|
||||
*/
|
||||
function isInSEPA($object)
|
||||
{
|
||||
if (empty($object->country_code)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$country_code_in_SEPA = getCountriesInSEPA(); // This make a database call but there is a cache done into $conf->cache['country_code_in_SEPA']
|
||||
|
||||
//print "dd".$object->country_code;
|
||||
return in_array($object->country_code, $country_code_in_SEPA);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show html area for list of projects
|
||||
|
||||
Reference in New Issue
Block a user