Internationnalisation de la fonction de vérification de l'identifiant de société (siret, siren pour FR, registration number pour GB, etc...)
This commit is contained in:
parent
bac7ca55ab
commit
e74b2fddc0
@ -832,6 +832,25 @@ 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 '<input type="text" name="'.$htmlname.'" size="'.($formlength+1).'" maxlength="'.$formlength.'" value="'.$selected.'">';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Retourne le nom traduit ou code+nom d'un pays
|
* \brief Retourne le nom traduit ou code+nom d'un pays
|
||||||
* \param id id du pays
|
* \param id id du pays
|
||||||
|
|||||||
@ -20,6 +20,7 @@ ErrorNoRequestRan=No request ran
|
|||||||
ErrorWrongHostParameter=Wrong host parameter
|
ErrorWrongHostParameter=Wrong host parameter
|
||||||
ErrorYourCountryIsNotDefined=Your country is not defined. Go to Home-Setup-Edit and post again the form.
|
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.
|
ErrorRecordIsUsedByChild=Failed to delete this record. This record is used by at least on child records.
|
||||||
|
ErrorWrongValue=Wrong value
|
||||||
HomeArea=Home area
|
HomeArea=Home area
|
||||||
LastAccess=Last access
|
LastAccess=Last access
|
||||||
RequestedUrl=Requested Url
|
RequestedUrl=Requested Url
|
||||||
@ -275,6 +276,7 @@ TotalQuantity=Total quantity
|
|||||||
DateFromTo=From %s to %s
|
DateFromTo=From %s to %s
|
||||||
DateFrom=From %s
|
DateFrom=From %s
|
||||||
DateUntil=Until %s
|
DateUntil=Until %s
|
||||||
|
Check=Check
|
||||||
# Countries
|
# Countries
|
||||||
CountryFR=France
|
CountryFR=France
|
||||||
CountryBE=Belgium
|
CountryBE=Belgium
|
||||||
|
|||||||
@ -20,6 +20,7 @@ ErrorNoRequestRan=Aucune requ
|
|||||||
ErrorWrongHostParameter=Mauvais paramètre Serveur
|
ErrorWrongHostParameter=Mauvais paramètre Serveur
|
||||||
ErrorYourCountryIsNotDefined=Votre pays n'est pas défini. Aller dans Configuration-Général-Editer et resoumettez le formulaire.
|
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.
|
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
|
HomeArea=Espace accueil
|
||||||
LastAccess=Dernière connexion
|
LastAccess=Dernière connexion
|
||||||
RequestedUrl=Url sollicitée
|
RequestedUrl=Url sollicitée
|
||||||
@ -275,6 +276,7 @@ TotalQuantity=Quantit
|
|||||||
DateFromTo=Du %s au %s
|
DateFromTo=Du %s au %s
|
||||||
DateFrom=A partir du %s
|
DateFrom=A partir du %s
|
||||||
DateUntil=Jusqu'au %s
|
DateUntil=Jusqu'au %s
|
||||||
|
Check=Vérifier
|
||||||
# Countries
|
# Countries
|
||||||
CountryFR=France
|
CountryFR=France
|
||||||
CountryBE=Belgique
|
CountryBE=Belgique
|
||||||
|
|||||||
118
htdocs/soc.php
118
htdocs/soc.php
@ -413,9 +413,47 @@ elseif ($_GET["action"] == 'edit')
|
|||||||
|
|
||||||
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3"><input type="text" name="url" size="40" value="'.$soc->url.'"></td></tr>';
|
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3"><input type="text" name="url" size="40" value="'.$soc->url.'"></td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->transcountry('ProfId1',$soc->pays_code).'</td><td><input type="text" name="siren" size="10" maxlength="9" value="'.$soc->siren.'"></td>';
|
print '<tr>';
|
||||||
print '<td>'.$langs->transcountry('ProfId2',$soc->pays_code).'</td><td><input type="text" name="siret" size="15" maxlength="14" value="'.$soc->siret.'"></td></tr>';
|
// IdProf1
|
||||||
print '<tr><td>'.$langs->transcountry('ProfId3',$soc->pays_code).'</td><td><input type="text" name="ape" size="5" maxlength="4" value="'.$soc->ape.'"></td><td colspan="2"> </td></tr>';
|
$idprof=$langs->transcountry('ProfId1',$soc->pays_code);
|
||||||
|
if ($idprof!='-')
|
||||||
|
{
|
||||||
|
print '<td>'.$idprof.'</td><td>';
|
||||||
|
$form->id_prof(1,$soc,'siren',$soc->siren);
|
||||||
|
print '</td>';
|
||||||
|
}
|
||||||
|
else print '<td> </td><td> </td>';
|
||||||
|
// IdProf2
|
||||||
|
$idprof=$langs->transcountry('ProfId2',$soc->pays_code);
|
||||||
|
if ($idprof!='-')
|
||||||
|
{
|
||||||
|
print '<td>'.$idprof.'</td><td>';
|
||||||
|
$form->id_prof(2,$soc,'siret',$soc->siret);
|
||||||
|
print '</td>';
|
||||||
|
}
|
||||||
|
else print '<td> </td><td> </td>';
|
||||||
|
print '</tr>';
|
||||||
|
print '<tr>';
|
||||||
|
// IdProf3
|
||||||
|
$idprof=$langs->transcountry('ProfId3',$soc->pays_code);
|
||||||
|
if ($idprof!='-')
|
||||||
|
{
|
||||||
|
print '<td>'.$idprof.'</td><td>';
|
||||||
|
$form->id_prof(3,$soc,'ape',$soc->ape);
|
||||||
|
print '</td>';
|
||||||
|
}
|
||||||
|
else print '<td> </td><td> </td>';
|
||||||
|
// IdProf4
|
||||||
|
// $idprof=$langs->transcountry('ProfId4',$soc->pays_code);
|
||||||
|
$idprof='-'; // L'identifiant 4 n'est pas encore géré
|
||||||
|
if ($idprof!='-')
|
||||||
|
{
|
||||||
|
print '<td>'.$idprof.'</td><td>';
|
||||||
|
$form->id_prof(4,$soc,'rcs',$soc->rcs);
|
||||||
|
print '</td>';
|
||||||
|
}
|
||||||
|
else print '<td> </td><td> </td>';
|
||||||
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr><td nowrap>'.$langs->trans('VATIntraShort').'</td><td colspan="3">';
|
print '<tr><td nowrap>'.$langs->trans('VATIntraShort').'</td><td colspan="3">';
|
||||||
print '<input type="text" name="tva_intra_code" size="3" maxlength="2" value="'.$soc->tva_intra_code.'">';
|
print '<input type="text" name="tva_intra_code" size="3" maxlength="2" value="'.$soc->tva_intra_code.'">';
|
||||||
@ -556,28 +594,66 @@ else
|
|||||||
if ($soc->url) { print '<a href="http://'.$soc->url.'">http://'.$soc->url.'</a>'; }
|
if ($soc->url) { print '<a href="http://'.$soc->url.'">http://'.$soc->url.'</a>'; }
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->transcountry('ProfId1',$soc->pays_code).'</td><td>';
|
// ProfId1
|
||||||
// Si société FR et siren fourni, on le vérifie
|
$profid=$langs->transcountry('ProfId1',$soc->pays_code);
|
||||||
if ($soc->pays_code == "FR" && $soc->siren) {
|
if ($profid!='-')
|
||||||
if ($soc->check_siren() == 0)
|
{
|
||||||
{
|
print '<tr><td>'.$profid.'</td><td>';
|
||||||
print '<a target="_blank" href="http://www.societe.com/cgi-bin/recherche?rncs='.$soc->siren.'">'.$soc->siren.'</a> ';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '<a class="error">'.$soc->siren;
|
|
||||||
// Siren invalide
|
|
||||||
print " Code Siren Invalide !</a>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print $soc->siren;
|
print $soc->siren;
|
||||||
|
if ($soc->siren)
|
||||||
|
{
|
||||||
|
if ($soc->id_prof_check(1,$soc) > 0) print ' '.$soc->id_prof_url(1,$soc);
|
||||||
|
else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
|
||||||
|
}
|
||||||
|
print '</td>';
|
||||||
}
|
}
|
||||||
print '</td>';
|
else print '<tr><td> </td><td> </td>';
|
||||||
print '<td>'.$langs->transcountry('ProfId2',$soc->pays_code).'</td><td>'.$soc->siret.'</td></tr>';
|
// ProfId2
|
||||||
|
$profid=$langs->transcountry('ProfId2',$soc->pays_code);
|
||||||
|
if ($profid!='-')
|
||||||
|
{
|
||||||
|
print '<td>'.$profid.'</td><td>';
|
||||||
|
print $soc->siret;
|
||||||
|
if ($soc->siret)
|
||||||
|
{
|
||||||
|
if ($soc->id_prof_check(2,$soc) > 0) print ' '.$soc->id_prof_url(2,$soc);
|
||||||
|
else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
|
||||||
|
}
|
||||||
|
print '</td></tr>';
|
||||||
|
}
|
||||||
|
else print '<td> </td><td> </td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->transcountry('ProfId3',$soc->pays_code).'</td><td>'.$soc->ape.'</td><td colspan="2"> </td></tr>';
|
// ProfId3
|
||||||
|
$profid=$langs->transcountry('ProfId3',$soc->pays_code);
|
||||||
|
if ($profid!='-')
|
||||||
|
{
|
||||||
|
print '<tr><td>'.$profid.'</td><td>';
|
||||||
|
print $soc->ape;
|
||||||
|
if ($soc->ape)
|
||||||
|
{
|
||||||
|
if ($soc->id_prof_check(3,$soc) > 0) print ' '.$soc->id_prof_url(3,$soc);
|
||||||
|
else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
|
||||||
|
}
|
||||||
|
print '</td>';
|
||||||
|
}
|
||||||
|
else print '<tr><td> </td><td> </td>';
|
||||||
|
// ProfId4
|
||||||
|
// $profid=$langs->transcountry('ProfId4',$soc->pays_code);
|
||||||
|
$profid='-'; // L'identifiant 4 n'est pas encore géré
|
||||||
|
if ($profid!='-')
|
||||||
|
{
|
||||||
|
print '<td>'.$profid.'</td><td>';
|
||||||
|
print $soc->rcs;
|
||||||
|
if ($soc->rcs)
|
||||||
|
{
|
||||||
|
if ($soc->id_prof_check(4,$soc) > 0) print ' '.$soc->id_prof_url(4,$soc);
|
||||||
|
else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
|
||||||
|
}
|
||||||
|
print '</td></tr>';
|
||||||
|
}
|
||||||
|
else print '<td> </td><td> </td></tr>';
|
||||||
|
|
||||||
|
// TVA
|
||||||
print '<tr><td nowrap>'.$langs->trans('VATIntraShort').'</td><td colspan="3">';
|
print '<tr><td nowrap>'.$langs->trans('VATIntraShort').'</td><td colspan="3">';
|
||||||
print $soc->tva_intra;
|
print $soc->tva_intra;
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|||||||
@ -1356,83 +1356,113 @@ class Societe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Verifie la validite du siren
|
* \brief Verifie la validite d'un identifiant professionnel en
|
||||||
*/
|
* fonction du pays de la societe (siren, siret, ...)
|
||||||
function check_siren()
|
* \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
|
||||||
{
|
* \param soc Objet societe
|
||||||
if (strlen($this->siren) == 9)
|
* \return int <0 si ko, >0 si ok
|
||||||
{
|
*/
|
||||||
$sum = 0;
|
function id_prof_check($idprof,$soc)
|
||||||
|
{
|
||||||
|
$ok=1;
|
||||||
|
|
||||||
for ($i = 0 ; $i < 10 ; $i = $i+2)
|
// Verifie SIREN si pays FR
|
||||||
{
|
if ($idprof == 1 && $soc->pays_code == 'FR')
|
||||||
$sum = $sum + substr($this->siren, (8 - $i), 1);
|
{
|
||||||
}
|
$chaine=trim($this->siren);
|
||||||
|
$chaine=eregi_replace(' ','',$chaine);
|
||||||
|
|
||||||
for ($i = 1 ; $i < 9 ; $i = $i+2)
|
if (strlen($chaine) != 9) return -1;
|
||||||
{
|
|
||||||
$ps = 2 * substr($this->siren, (8 - $i), 1);
|
|
||||||
|
|
||||||
if ($ps > 9)
|
$sum = 0;
|
||||||
{
|
|
||||||
$ps = substr($ps, 0,1) + substr($ps, 1 ,1);
|
|
||||||
}
|
|
||||||
$sum = $sum + $ps;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($sum, -1) == 0)
|
for ($i = 0 ; $i < 10 ; $i = $i+2)
|
||||||
{
|
{
|
||||||
return 0;
|
$sum = $sum + substr($this->siren, (8 - $i), 1);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
for ($i = 1 ; $i < 9 ; $i = $i+2)
|
||||||
* \brief Indique si la société a des projets
|
{
|
||||||
* \return bool true si la société a des projets, false sinon
|
$ps = 2 * substr($this->siren, (8 - $i), 1);
|
||||||
*/
|
|
||||||
function has_projects()
|
if ($ps > 9)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
|
$ps = substr($ps, 0,1) + substr($ps, 1 ,1);
|
||||||
$resql = $this->db->query($sql);
|
}
|
||||||
if ($resql)
|
$sum = $sum + $ps;
|
||||||
{
|
}
|
||||||
$nump = $this->db->num_rows($resql);
|
|
||||||
$obj = $this->db->fetch_object();
|
if (substr($sum, -1) != 0) return -1;
|
||||||
$count = $obj->numproj;
|
}
|
||||||
}
|
|
||||||
else
|
// Verifie SIRET si pays FR
|
||||||
{
|
if ($idprof == 2 && $soc->pays_code == 'FR')
|
||||||
$count = 0;
|
{
|
||||||
print $this->db->error();
|
$chaine=trim($this->siret);
|
||||||
}
|
$chaine=eregi_replace(' ','',$chaine);
|
||||||
$this->db->free($resql);
|
|
||||||
return ($count > 0);
|
if (strlen($chaine) != 14) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \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;
|
||||||
|
|
||||||
|
$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 '<a target="_blank" href="'.$url.'">['.$langs->trans("Check").']</a>';
|
||||||
|
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)
|
function AddPerms($user_id, $read, $write, $perms)
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms";
|
||||||
$sql .= " (fk_soc, fk_user, pread, pwrite, pperms) ";
|
$sql .= " (fk_soc, fk_user, pread, pwrite, pperms) ";
|
||||||
$sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");";
|
$sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");";
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
|
||||||
if ($resql)
|
}
|
||||||
{
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user