From 438f189a7422b7ffc2af78b86d9b68eb2dd9ef7e Mon Sep 17 00:00:00 2001
From: Antony Le Courtes <antony.lecourtes@unicaen.fr>
Date: Tue, 14 Sep 2021 10:38:03 +0200
Subject: [PATCH] =?UTF-8?q?Correction=20sur=20la=20v=C3=A9rification=20du?=
 =?UTF-8?q?=20code=20INSEE=20pour=20les=20d=C3=A9partements=20de=20naissan?=
 =?UTF-8?q?ce=20en=20outre=20mer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Validator/NumeroINSEEValidator.php        | 20 ++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/module/Application/src/Application/Validator/NumeroINSEEValidator.php b/module/Application/src/Application/Validator/NumeroINSEEValidator.php
index 0d59fb61e1..e4c823d604 100755
--- a/module/Application/src/Application/Validator/NumeroINSEEValidator.php
+++ b/module/Application/src/Application/Validator/NumeroINSEEValidator.php
@@ -202,7 +202,10 @@ class NumeroINSEEValidator extends NumeroINSEE
     private function isValidDepartementFrance()
     {
         /* Département du numéro INSEE */
-        $iDepartement = strtoupper(str_pad((string)$this->getDepartement(), 3, '0', STR_PAD_LEFT));
+        $iDepartement = (string)$this->getDepartement();
+        if ($iDepartement != '97' && $iDepartement != '98') {
+            $iDepartement = strtoupper(str_pad($iDepartement, 3, '0', STR_PAD_LEFT));
+        }
 
         /* Code du département issu du dossier */
         $dDepartement = strtoupper(str_pad((string)$this->departement->getCode(), 3, '0', STR_PAD_LEFT));
@@ -220,6 +223,12 @@ class NumeroINSEEValidator extends NumeroINSEE
             return false; // département étranger
         }
 
+        //On traite les départements d'outre mer (peuvent etre sur deux ou trois chiffres, donc on teste que les deux premiers...)
+        if ($iDepartement == '97' || $iDepartement == '98') {
+            $dDepartement = substr($dDepartement, 0, 2);
+            if ($dDepartement == $iDepartement) return true;
+        }
+
         if ($dDepartement == $iDepartement) return true; // Impec
 
         if ($iDepartement == '020') {
@@ -310,11 +319,12 @@ class NumeroINSEEValidator extends NumeroINSEE
         if ($iDepartement == '99') {
             return 99; // étranger
         }
-        if ($iDepartement == '97' || $iDepartement == '98') {
-            $iDepartement = substr(strtoupper($this->value), 5, 3);
 
-            return (int)$iDepartement;
-        }
+        /* if ($iDepartement == '97' || $iDepartement == '98') {
+             $iDepartement = substr(strtoupper($this->value), 5, 3);
+
+             return (int)$iDepartement;
+         }*/
 
         return (int)$iDepartement;
     }
-- 
GitLab