NEW Add function isValidVATID()

This commit is contained in:
Laurent Destailleur 2019-04-23 22:49:33 +02:00
parent 742de5c777
commit 684e09fdcd
2 changed files with 33 additions and 3 deletions

View File

@ -564,6 +564,28 @@ function isValidUrl($url, $http = 0, $pass = 0, $port = 0, $path = 0, $query = 0
return $ValidUrl;
}
/**
* Check if VAT numero is valid (check done on syntax only, no database or remote access)
*
* @param Societe $company VAT number
* @return int 1=Check is OK, 0=Check is KO
*/
function isValidVATID($company)
{
if ($company->isInEEC()) // Syntax check rules for EEC countries
{
$vatprefix = $company->country_code;
if ($vatprefix == 'GR') $vatprefix = '(EL|GR)';
else $vatprefix = preg_quote($vatprefix, '/');
if (! preg_match('/^'.$vatprefix.'[a-zA-Z0-9\-\.]{5,10}$/', $company->tva_intra))
{
return 0;
}
}
return 1;
}
/**
* Clean an url string
*

View File

@ -41,6 +41,13 @@ $product = new Product($db);
$product->fetch($id);
$error = 0;
/*
* Actions
*/
if (!$product->isProduct()) {
header('Location: '.dol_buildpath('/product/card.php?id='.$product->id, 2));
exit();
@ -59,8 +66,8 @@ $combinations = GETPOST('combinations', 'array');
$price_var_percent = (bool) GETPOST('price_var_percent');
$donotremove = true;
if ($_POST) {
if ($_POST)
{
$donotremove = (bool) GETPOST('donotremove');
//We must check if all those given combinations actually exist
@ -102,7 +109,8 @@ if ($_POST) {
$res = 1;
foreach (cartesianArray($adapted_values) as $currcomb)
$cartesianarray = cartesianArray($adapted_values);
foreach ($cartesianarray as $currcomb)
{
$res = $combination->createProductCombination($product, $currcomb, $sanitized_values, $price_var_percent);
if ($res < 0) {