Internationnalisation de la fonction de vrification de l'identifiant de socit (siret, siren pour FR, registration number pour GB, etc...)
This commit is contained in:
parent
bac7ca55ab
commit
e74b2fddc0
@ -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 '<input type="text" name="'.$htmlname.'" size="'.($formlength+1).'" maxlength="'.$formlength.'" value="'.$selected.'">';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retourne le nom traduit ou code+nom d'un pays
|
||||
* \param id id du pays
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
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->transcountry('ProfId1',$soc->pays_code).'</td><td><input type="text" name="siren" size="10" maxlength="9" value="'.$soc->siren.'"></td>';
|
||||
print '<td>'.$langs->transcountry('ProfId2',$soc->pays_code).'</td><td><input type="text" name="siret" size="15" maxlength="14" value="'.$soc->siret.'"></td></tr>';
|
||||
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>';
|
||||
print '<tr>';
|
||||
// IdProf1
|
||||
$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 '<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>'; }
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->transcountry('ProfId1',$soc->pays_code).'</td><td>';
|
||||
// Si société FR et siren fourni, on le vérifie
|
||||
if ($soc->pays_code == "FR" && $soc->siren) {
|
||||
if ($soc->check_siren() == 0)
|
||||
{
|
||||
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 {
|
||||
// ProfId1
|
||||
$profid=$langs->transcountry('ProfId1',$soc->pays_code);
|
||||
if ($profid!='-')
|
||||
{
|
||||
print '<tr><td>'.$profid.'</td><td>';
|
||||
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>';
|
||||
print '<td>'.$langs->transcountry('ProfId2',$soc->pays_code).'</td><td>'.$soc->siret.'</td></tr>';
|
||||
else print '<tr><td> </td><td> </td>';
|
||||
// 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 $soc->tva_intra;
|
||||
print '</td></tr>';
|
||||
|
||||
@ -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 '<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)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user