diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 0f0ea55043e..c1110a22938 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -831,7 +831,26 @@ class Form } } - + + + /** + * \brief Retourne le formulaire de saisie d'un identifiant professionnel (siren, siret, etc...) + * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) + * \param soc Objet societe + * \param htmlname Nom de la zone input + */ + function id_prof($idprof,$soc,$htmlname,$selected='') + { + global $langs; + $formlength=16; + if ($idprof==1 && $soc->pays_code == 'FR') $formlength=9; + if ($idprof==2 && $soc->pays_code == 'FR') $formlength=14; + if ($idprof==3 && $soc->pays_code == 'FR') $formlength=4; + if ($idprof==4 && $soc->pays_code == 'FR') $formlength=4; + print ''; + } + + /** * \brief Retourne le nom traduit ou code+nom d'un pays * \param id id du pays diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 7c151eb3993..2f2d027bc51 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -20,6 +20,7 @@ ErrorNoRequestRan=No request ran ErrorWrongHostParameter=Wrong host parameter ErrorYourCountryIsNotDefined=Your country is not defined. Go to Home-Setup-Edit and post again the form. ErrorRecordIsUsedByChild=Failed to delete this record. This record is used by at least on child records. +ErrorWrongValue=Wrong value HomeArea=Home area LastAccess=Last access RequestedUrl=Requested Url @@ -275,6 +276,7 @@ TotalQuantity=Total quantity DateFromTo=From %s to %s DateFrom=From %s DateUntil=Until %s +Check=Check # Countries CountryFR=France CountryBE=Belgium diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 54ee0de4d55..8624c0ba3db 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -20,6 +20,7 @@ ErrorNoRequestRan=Aucune requ ErrorWrongHostParameter=Mauvais paramètre Serveur ErrorYourCountryIsNotDefined=Votre pays n'est pas défini. Aller dans Configuration-Général-Editer et resoumettez le formulaire. ErrorRecordIsUsedByChild=Impossible de supprimer cet enregistrement. Ce dernier est utilisé en tant que père par au moins un enregistrement fils. +ErrorWrongValue=Valeur incorrecte HomeArea=Espace accueil LastAccess=Dernière connexion RequestedUrl=Url sollicitée @@ -275,6 +276,7 @@ TotalQuantity=Quantit DateFromTo=Du %s au %s DateFrom=A partir du %s DateUntil=Jusqu'au %s +Check=Vérifier # Countries CountryFR=France CountryBE=Belgique diff --git a/htdocs/soc.php b/htdocs/soc.php index 36a1905899e..1fb379f9d64 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -413,9 +413,47 @@ elseif ($_GET["action"] == 'edit') print ''.$langs->trans('Web').''; - print ''.$langs->transcountry('ProfId1',$soc->pays_code).''; - print ''.$langs->transcountry('ProfId2',$soc->pays_code).''; - print ''.$langs->transcountry('ProfId3',$soc->pays_code).' '; + print ''; + // IdProf1 + $idprof=$langs->transcountry('ProfId1',$soc->pays_code); + if ($idprof!='-') + { + print ''.$idprof.''; + $form->id_prof(1,$soc,'siren',$soc->siren); + print ''; + } + else print '  '; + // IdProf2 + $idprof=$langs->transcountry('ProfId2',$soc->pays_code); + if ($idprof!='-') + { + print ''.$idprof.''; + $form->id_prof(2,$soc,'siret',$soc->siret); + print ''; + } + else print '  '; + print ''; + print ''; + // IdProf3 + $idprof=$langs->transcountry('ProfId3',$soc->pays_code); + if ($idprof!='-') + { + print ''.$idprof.''; + $form->id_prof(3,$soc,'ape',$soc->ape); + print ''; + } + else print '  '; + // IdProf4 + // $idprof=$langs->transcountry('ProfId4',$soc->pays_code); + $idprof='-'; // L'identifiant 4 n'est pas encore géré + if ($idprof!='-') + { + print ''.$idprof.''; + $form->id_prof(4,$soc,'rcs',$soc->rcs); + print ''; + } + else print '  '; + print ''; print ''.$langs->trans('VATIntraShort').''; print ''; @@ -556,28 +594,66 @@ else if ($soc->url) { print 'http://'.$soc->url.''; } print ''; - print ''.$langs->transcountry('ProfId1',$soc->pays_code).''; - // Si société FR et siren fourni, on le vérifie - if ($soc->pays_code == "FR" && $soc->siren) { - if ($soc->check_siren() == 0) - { - print ''.$soc->siren.' '; - } - else - { - print ''.$soc->siren; - // Siren invalide - print " Code Siren Invalide !"; - } - } - else { + // ProfId1 + $profid=$langs->transcountry('ProfId1',$soc->pays_code); + if ($profid!='-') + { + print ''.$profid.''; print $soc->siren; + if ($soc->siren) + { + if ($soc->id_prof_check(1,$soc) > 0) print '   '.$soc->id_prof_url(1,$soc); + else print ' ('.$langs->trans("ErrorWrongValue").')'; + } + print ''; } - print ''; - print ''.$langs->transcountry('ProfId2',$soc->pays_code).''.$soc->siret.''; + else print '  '; + // ProfId2 + $profid=$langs->transcountry('ProfId2',$soc->pays_code); + if ($profid!='-') + { + print ''.$profid.''; + print $soc->siret; + if ($soc->siret) + { + if ($soc->id_prof_check(2,$soc) > 0) print '   '.$soc->id_prof_url(2,$soc); + else print ' ('.$langs->trans("ErrorWrongValue").')'; + } + print ''; + } + else print '  '; - print ''.$langs->transcountry('ProfId3',$soc->pays_code).''.$soc->ape.' '; + // ProfId3 + $profid=$langs->transcountry('ProfId3',$soc->pays_code); + if ($profid!='-') + { + print ''.$profid.''; + print $soc->ape; + if ($soc->ape) + { + if ($soc->id_prof_check(3,$soc) > 0) print '   '.$soc->id_prof_url(3,$soc); + else print ' ('.$langs->trans("ErrorWrongValue").')'; + } + print ''; + } + else print '  '; + // ProfId4 + // $profid=$langs->transcountry('ProfId4',$soc->pays_code); + $profid='-'; // L'identifiant 4 n'est pas encore géré + if ($profid!='-') + { + print ''.$profid.''; + print $soc->rcs; + if ($soc->rcs) + { + if ($soc->id_prof_check(4,$soc) > 0) print '   '.$soc->id_prof_url(4,$soc); + else print ' ('.$langs->trans("ErrorWrongValue").')'; + } + print ''; + } + else print '  '; + // TVA print ''.$langs->trans('VATIntraShort').''; print $soc->tva_intra; print ''; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index c8268e43b89..495842b9465 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -1356,83 +1356,113 @@ class Societe { } } - /** - * \brief Verifie la validite du siren - */ - function check_siren() - { - if (strlen($this->siren) == 9) - { - $sum = 0; + /** + * \brief Verifie la validite d'un identifiant professionnel en + * fonction du pays de la societe (siren, siret, ...) + * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) + * \param soc Objet societe + * \return int <0 si ko, >0 si ok + */ + function id_prof_check($idprof,$soc) + { + $ok=1; + + // Verifie SIREN si pays FR + if ($idprof == 1 && $soc->pays_code == 'FR') + { + $chaine=trim($this->siren); + $chaine=eregi_replace(' ','',$chaine); + + if (strlen($chaine) != 9) return -1; - for ($i = 0 ; $i < 10 ; $i = $i+2) - { - $sum = $sum + substr($this->siren, (8 - $i), 1); - } + $sum = 0; + + for ($i = 0 ; $i < 10 ; $i = $i+2) + { + $sum = $sum + substr($this->siren, (8 - $i), 1); + } + + for ($i = 1 ; $i < 9 ; $i = $i+2) + { + $ps = 2 * substr($this->siren, (8 - $i), 1); + + if ($ps > 9) + { + $ps = substr($ps, 0,1) + substr($ps, 1 ,1); + } + $sum = $sum + $ps; + } + + if (substr($sum, -1) != 0) return -1; + } - for ($i = 1 ; $i < 9 ; $i = $i+2) - { - $ps = 2 * substr($this->siren, (8 - $i), 1); + // Verifie SIRET si pays FR + if ($idprof == 2 && $soc->pays_code == 'FR') + { + $chaine=trim($this->siret); + $chaine=eregi_replace(' ','',$chaine); + + if (strlen($chaine) != 14) return -1; + } - if ($ps > 9) - { - $ps = substr($ps, 0,1) + substr($ps, 1 ,1); - } - $sum = $sum + $ps; - } + return $ok; + } - if (substr($sum, -1) == 0) - { - return 0; - } - else - { - return -1; - } - } - else - { - return -2; - } - } + /** + * \brief Renvoi url de vérification d'un identifiant professionnal + * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) + * \param soc Objet societe + * \return string url ou chaine vide si aucune url connue + */ + function id_prof_url($idprof,$soc) + { + global $langs; - /** - * \brief Indique si la société a des projets - * \return bool true si la société a des projets, false sinon - */ - function has_projects() - { - $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id; - $resql = $this->db->query($sql); - if ($resql) - { - $nump = $this->db->num_rows($resql); - $obj = $this->db->fetch_object(); - $count = $obj->numproj; - } - else - { - $count = 0; - print $this->db->error(); - } - $this->db->free($resql); - return ($count > 0); - } + $url=''; + if ($idprof == 1 && $soc->pays_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->siren; + if ($idprof == 1 && $soc->pays_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/'; + + if ($url) return '['.$langs->trans("Check").']'; + return ''; + } + + /** + * \brief Indique si la société a des projets + * \return bool true si la société a des projets, false sinon + */ + function has_projects() + { + $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id; + $resql = $this->db->query($sql); + if ($resql) + { + $nump = $this->db->num_rows($resql); + $obj = $this->db->fetch_object(); + $count = $obj->numproj; + } + else + { + $count = 0; + print $this->db->error(); + } + $this->db->free($resql); + return ($count > 0); + } - function AddPerms($user_id, $read, $write, $perms) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms"; - $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) "; - $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");"; - - $resql=$this->db->query($sql); - - if ($resql) - { - - } - } + function AddPerms($user_id, $read, $write, $perms) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms"; + $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) "; + $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");"; + + $resql=$this->db->query($sql); + if ($resql) + { + + } + } + } ?>