From 5ef00d200fe83f98e57b7fd9fb990c7af75878fc Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 28 Feb 2018 12:26:05 +0000 Subject: [PATCH] Added idprof1 check to country PT --- htdocs/societe/class/societe.class.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f5c0f004794..9cf14b4bc9d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2876,6 +2876,29 @@ class Societe extends CommonObject return -4; } + //Verify NIF if country is PT + //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad + if ($idprof == 1 && $soc->country_code == 'PT') + { + $string=trim($this->idprof1); + $string=preg_replace('/(\s)/','',$string); + + for ($i = 0; $i < 9; $i ++) { + $num[$i] = substr($string, $i, 1); + } + + //Check NIF + if (preg_match('/(^[0-9]{9}$)/', $string)) { + return 1; + } + else { + return -1; + } + + //Wrong format + return 0; + } + return $ok; }