2012-07-28 14:21:05 +02:00
|
|
|
|
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
include_once(INCLUDE_PATH.'insee/classMInsee.php');
|
|
|
|
|
include_once(INCLUDE_PATH.'bodacc/classMBodacc.php');
|
|
|
|
|
include_once(FWK_PATH.'mail/sendMail.php');
|
|
|
|
|
|
|
|
|
|
error_reporting(E_ALL ^ E_NOTICE);
|
|
|
|
|
|
|
|
|
|
$strInfoScript='Usage : '.basename($argv[0]). " [OPTION]
|
2013-06-19 10:24:49 +02:00
|
|
|
|
Sirenage automatique des annonces Bodacc pas encore siren<EFBFBD>es.
|
2012-07-28 14:21:05 +02:00
|
|
|
|
|
|
|
|
|
Options :
|
2013-06-19 10:24:49 +02:00
|
|
|
|
-s Sirenage semi-automatique (Ligne de prompt pour les entreprises non siren<EFBFBD>es)
|
2012-07-28 14:21:05 +02:00
|
|
|
|
-p Sirenage de toutes les annonces sans propositions (en vu du traitement manuel)
|
2013-06-19 10:24:49 +02:00
|
|
|
|
-a Re-sirenage de toutes les annonces Bodacc non siren<EFBFBD>es !
|
|
|
|
|
-i:XXX Reprise <EFBFBD> partir du num<EFBFBD>ro d'annonce XXX
|
|
|
|
|
-m Ne pas envoyer l'email d'Information <EFBFBD> l'<EFBFBD>quipe de production
|
|
|
|
|
-n Ne pas limiter le nombre d'entit<EFBFBD>s <EFBFBD> sirener.
|
2012-07-28 14:21:05 +02:00
|
|
|
|
";
|
|
|
|
|
$semiManuel=$sansPropo=$toutes=$index=$noLimit=false;
|
|
|
|
|
$envoyerMail=true;
|
|
|
|
|
|
|
|
|
|
$iInsee=new MInsee();
|
|
|
|
|
$iBodacc=new MBodacc();
|
|
|
|
|
$iDb2=new WDB('jo');
|
|
|
|
|
|
|
|
|
|
$argv=$_SERVER['argv'];
|
2013-06-19 10:24:49 +02:00
|
|
|
|
if ($_SERVER['argc']==1) $semiManuel=false; // Fonctionnement normal du script, c<>d : on sirene que en auto
|
2012-07-28 14:21:05 +02:00
|
|
|
|
else {
|
|
|
|
|
for ($i=1; isset($argv[$i]); $i++) {
|
|
|
|
|
if (substr($argv[$i],0,1)=='-') {
|
|
|
|
|
switch (substr($argv[$i],1,1)) {
|
|
|
|
|
case 's':
|
|
|
|
|
$semiManuel=true;
|
|
|
|
|
break;
|
|
|
|
|
case 'm':
|
|
|
|
|
$envoyerMail=false;
|
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
|
|
|
|
$sansPropo=true;
|
|
|
|
|
break;
|
|
|
|
|
case 'a':
|
|
|
|
|
$toutes=true;
|
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
$noLimit=true;
|
|
|
|
|
break;
|
|
|
|
|
case 'i':
|
|
|
|
|
$index=trim(substr($argv[$i],3));
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
|
|
|
|
case '?':
|
|
|
|
|
die($strInfoScript);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
die('Option '. $argv[$i] . " inconnue !\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo date('Y/m/d - H:i:s') ." - DEBUT du programme de SIRENAGE...".EOL;
|
|
|
|
|
|
|
|
|
|
$pertinence=false;
|
|
|
|
|
$nbRep=30;
|
|
|
|
|
$siege=0;
|
|
|
|
|
|
|
|
|
|
$iDb=new WDB('tmp');
|
|
|
|
|
$iDb2=new WDB('tmp');
|
|
|
|
|
$nbNonSirene=$iDb->select( 'maxiprospect',
|
|
|
|
|
'id,siren,sirenValide,nic,nicValide,NOM,ADRESSE,CP,VILLE,TEL,FAX,EMAIL,web',
|
|
|
|
|
"siren=0 AND sirenValide=0 AND TEL>0 AND (FAX>0 OR EMAIL LIKE '%@%') AND id>=3568968 ORDER BY id ASC", true, MYSQL_ASSOC, true);
|
|
|
|
|
|
2013-06-19 10:24:49 +02:00
|
|
|
|
echo date('Y/m/d - H:i:s') ." - Nombre d'entit<69>es non SIRENEES : ".$nbNonSirene . EOL;
|
2012-07-28 14:21:05 +02:00
|
|
|
|
$k=0;
|
|
|
|
|
|
|
|
|
|
while($entrep=$iDb->fetch(MYSQL_ASSOC)) {
|
|
|
|
|
$k++;
|
|
|
|
|
|
|
|
|
|
$lastId=$entrep['id'];
|
|
|
|
|
$nomIn=$entrep['NOM'];
|
|
|
|
|
$adrIn=$entrep['ADRESSE'];
|
|
|
|
|
$cpIn =$entrep['CP'];
|
|
|
|
|
$comIn=$entrep['VILLE'];
|
|
|
|
|
$telIn=$entrep['TEL'];
|
|
|
|
|
$faxIn=$entrep['FAX'];
|
|
|
|
|
$tabInsert=false;
|
|
|
|
|
//print_r($entrep);
|
|
|
|
|
|
|
|
|
|
// Recherche par TEL
|
|
|
|
|
$res=$iInsee->getEtablissementsParId('TEL', $telIn);
|
|
|
|
|
if ($res['nbReponses']>0) {
|
|
|
|
|
$levMin=1;
|
|
|
|
|
$tabInsert=false;
|
|
|
|
|
foreach ($res['reponses'] as $i=>$etab) {
|
|
|
|
|
$size=strlen($nomIn.$etab['Nom'].$adrIn.$etab['Adresse'].$cpIn.$etab['CP'].$comIn.$etab['Ville']);
|
|
|
|
|
$levNom=levenshtein($nomIn,$etab['Nom']);
|
|
|
|
|
$levAdr=levenshtein($adrIn,$etab['Adresse']);
|
|
|
|
|
$levCP =levenshtein($cpIn ,$etab['CP']);
|
|
|
|
|
$levCom=levenshtein($comIn,$etab['Ville']);
|
|
|
|
|
$levTot=$levNom+$levAdr+$levCP+$levCom;
|
|
|
|
|
$levPct=$levTot/$size;
|
|
|
|
|
if ($levPct<0.3 && $levPct<$levMin) {
|
|
|
|
|
$tabInsert= array( 'siren'=>$etab['Siren'],
|
|
|
|
|
'sirenValide'=>1,
|
|
|
|
|
'nic'=>$etab['Nic'],
|
|
|
|
|
'nicValide'=>1);
|
|
|
|
|
$levMin=$levPct;
|
|
|
|
|
}
|
|
|
|
|
if ($tabInsert) {
|
|
|
|
|
$iDb2->update( 'maxiprospect', $tabInsert, "id=$lastId",false);
|
|
|
|
|
echo "$k/$nbNonSirene TEL $lastId : $nomIn <>".$etab['Nom']."\tlevenshtein=$levTot ($i: $levPct %)".EOL;
|
|
|
|
|
echo "\t$adrIn $cpIn $comIn <>".$etab['Adresse'].' '.$etab['CP'].' '.$etab['Ville'].EOL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($tabInsert) continue;
|
|
|
|
|
|
|
|
|
|
// Recherche par FAX
|
|
|
|
|
if ($faxIn*1>0) {
|
|
|
|
|
$res=$iInsee->getEtablissementsParId('TEL', $faxIn);
|
|
|
|
|
if ($res['nbReponses']>0) {
|
|
|
|
|
$levMin=1;
|
|
|
|
|
$tabInsert=false;
|
|
|
|
|
foreach ($res['reponses'] as $i=>$etab) {
|
|
|
|
|
$size=strlen($nomIn.$etab['Nom'].$adrIn.$etab['Adresse'].$cpIn.$etab['CP'].$comIn.$etab['Ville']);
|
|
|
|
|
$levNom=levenshtein($nomIn,$etab['Nom']);
|
|
|
|
|
$levAdr=levenshtein($adrIn,$etab['Adresse']);
|
|
|
|
|
$levCP =levenshtein($cpIn ,$etab['CP']);
|
|
|
|
|
$levCom=levenshtein($comIn,$etab['Ville']);
|
|
|
|
|
$levTot=$levNom+$levAdr+$levCP+$levCom;
|
|
|
|
|
$levPct=$levTot/$size;
|
|
|
|
|
if ($levPct<0.2 && $levPct<$levMin) {
|
|
|
|
|
$tabInsert= array( 'siren'=>$etab['Siren'],
|
|
|
|
|
'sirenValide'=>2,
|
|
|
|
|
'nic'=>$etab['Nic'],
|
|
|
|
|
'nicValide'=>2);
|
|
|
|
|
$levMin=$levPct;
|
|
|
|
|
}
|
|
|
|
|
if ($tabInsert) {
|
|
|
|
|
$iDb2->update( 'maxiprospect', $tabInsert, "id=$lastId",false);
|
|
|
|
|
echo "$k/$nbNonSirene FAX $lastId : $nomIn <>".$etab['Nom']."\tlevenshtein=$levTot ($i: $levPct %)".EOL;
|
|
|
|
|
echo "\t$adrIn $cpIn $comIn <>".$etab['Adresse'].' '.$etab['CP'].' '.$etab['Ville'].EOL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($tabInsert) continue;
|
|
|
|
|
|
|
|
|
|
// Recherche par IDENTITE
|
|
|
|
|
$deb=0;$nbRep=20;$maxRep=20;$siege=$actif='';
|
|
|
|
|
$res=@$iInsee->rechercheEtab($nomIn, $adrIn, $cpIn, $comIn, $siege, $actif, $deb, $nbRep, $maxRep, false, true);
|
|
|
|
|
if ($res['nbReponses']>0) {
|
|
|
|
|
$levMin=1;
|
|
|
|
|
$tabInsert=false;
|
|
|
|
|
foreach ($res['reponses'] as $i=>$etab) {
|
|
|
|
|
$size=strlen($nomIn.$etab['Nom'].$adrIn.$etab['Adresse'].$cpIn.$etab['CP'].$comIn.$etab['Ville']);
|
|
|
|
|
$levNom=levenshtein($nomIn,$etab['Nom']);
|
|
|
|
|
$levAdr=levenshtein($adrIn,$etab['Adresse']);
|
|
|
|
|
$levCP =levenshtein($cpIn ,$etab['CP']);
|
|
|
|
|
$levCom=levenshtein($comIn,$etab['Ville']);
|
|
|
|
|
$levTot=$levNom+$levAdr+$levCP+$levCom;
|
|
|
|
|
$levPct=$levTot/$size;
|
|
|
|
|
if ($levPct<0.15 && $levPct<$levMin) {
|
|
|
|
|
$tabInsert= array( 'siren'=>$etab['Siren'],
|
|
|
|
|
'sirenValide'=>3,
|
|
|
|
|
'nic'=>$etab['Nic'],
|
|
|
|
|
'nicValide'=>3);
|
|
|
|
|
$levMin=$levPct;
|
|
|
|
|
}
|
|
|
|
|
if ($tabInsert) {
|
|
|
|
|
$iDb2->update( 'maxiprospect', $tabInsert, "id=$lastId",false);
|
|
|
|
|
echo "$k/$nbNonSirene IDEN $lastId : $nomIn <>".$etab['Nom']."\tlevenshtein=$levTot ($i: $levPct %)".EOL;
|
|
|
|
|
echo "\t$adrIn $cpIn $comIn <>".$etab['Adresse'].' '.$etab['CP'].' '.$etab['Ville'].EOL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 10:24:49 +02:00
|
|
|
|
echo date('Y/m/d - H:i:s') ." - FIN du programme de SIRENAGE des annonces mal siren<65>s du BODACC.".EOL;
|
2012-07-28 14:21:05 +02:00
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
?>
|