From 684e09fdcd39afe92ac4755044fd01a5760bc998 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 23 Apr 2019 22:49:33 +0200 Subject: [PATCH] NEW Add function isValidVATID() --- htdocs/core/lib/functions2.lib.php | 22 ++++++++++++++++++++++ htdocs/variants/generator.php | 14 +++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 89c945d5ef4..16fb210ee4d 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -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 * diff --git a/htdocs/variants/generator.php b/htdocs/variants/generator.php index 3ab809028e9..b2b2b1bdfc6 100644 --- a/htdocs/variants/generator.php +++ b/htdocs/variants/generator.php @@ -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) {