New Create isInSEPA function

This commit is contained in:
Amael-PE
2025-02-14 20:54:03 +01:00
parent 5261b2fe92
commit 757aec629f
2 changed files with 66 additions and 0 deletions

View File

@@ -812,6 +812,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 array Array of countries code 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

View File

@@ -4185,6 +4185,17 @@ class Societe extends CommonObject
return isInEEC($this);
}
/**
* Return if a company is inside the SEPA zone (Single Euro Payment Area)
*
* @return boolean true = country inside SEPA, false = country outside SEPA
*/
public function isInSEPA()
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
return isInSEPA($this);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load the list of provider categories