102 lines
2.8 KiB
PHP
102 lines
2.8 KiB
PHP
|
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
|
||
|
<?php
|
||
|
|
||
|
error_reporting(E_ALL);
|
||
|
|
||
|
include_once(FWK_PATH.'common/chiffres.php');
|
||
|
include_once(FWK_PATH.'common/dates.php');
|
||
|
include_once(INCLUDE_PATH.'insee/classMInsee.php');
|
||
|
include_once(INCLUDE_PATH.'partenaires/classMGreffes.php');
|
||
|
include_once(FWK_PATH.'mail/sendMail.php');
|
||
|
|
||
|
$strInfoScript='Usage : '.basename($argv[0]). " [OPTIONS] tranche1 tranche2 ...
|
||
|
Traitement des plages ou tranches de siren attribués par l'INSEE.
|
||
|
|
||
|
Options:
|
||
|
-v Mode verbose ou debug
|
||
|
-n Liste des tranches par % d'occupation
|
||
|
|
||
|
(*): Valeur par défaut !
|
||
|
";
|
||
|
$tabTranches=array();
|
||
|
$modeDebug=false;
|
||
|
|
||
|
$argv=$_SERVER['argv'];
|
||
|
if ($_SERVER['argc']>1)
|
||
|
{
|
||
|
for ($i=1; isset($argv[$i]); $i++) {
|
||
|
if (substr($argv[$i],0,1)=='-') {
|
||
|
switch (substr($argv[$i],1,1)) {
|
||
|
case 'v': $modeDebug=true;
|
||
|
define('TMIN',1);
|
||
|
define('TMAX',2);
|
||
|
break;
|
||
|
case 'n': $force=true; break;
|
||
|
case 'm': $max=true;
|
||
|
$annee=substr($argv[$i],3); break;
|
||
|
case '-':
|
||
|
case '?': die($strInfoScript); break;
|
||
|
default: die('Option '. $argv[$i] . " inconnue !\n");
|
||
|
break;
|
||
|
}
|
||
|
} else {
|
||
|
$tabTranches[]=$argv[$i];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!defined('TMIN')) define('TMIN',10);
|
||
|
if (!defined('TMAX')) define('TMAX',20);
|
||
|
|
||
|
$iDb=new WDB('tmp');
|
||
|
//$iDb2=new WDB('jo');
|
||
|
$iInsee=new MInsee();
|
||
|
$iGreffe=new MGreffes();
|
||
|
|
||
|
foreach ($tabTranches as $tranche) {
|
||
|
echo date ('Y/m/d - H:i:s')." - Début du traitement de la tranche '$tranche'...".EOL;
|
||
|
|
||
|
$tmp=$iDb->select('siretDcren2', 'SIREN', "SIR3=$tranche ORDER BY SIREN ASC", false, MYSQL_ASSOC);
|
||
|
$iCalc=0;
|
||
|
$tabSirenConnus=$tabSirenManquants=array();
|
||
|
|
||
|
foreach ($tmp as $i=>$tabTmp) {
|
||
|
//echo $tabTmp['SIREN']."\t";
|
||
|
$tabSirenConnus[]=$tabTmp['SIREN'];
|
||
|
$iLu=substr($tabTmp['SIREN'],3,5)*1;
|
||
|
while ($iLu>$iCalc++) {
|
||
|
for($i2=0; $i2<10; $i2++) {
|
||
|
$sirenTest=$tranche.sprintf('%05s', $iCalc-1).$i2;
|
||
|
if ($iInsee->valideSiren($sirenTest)) {
|
||
|
// echo $sirenTest;
|
||
|
$tabSirenManquants[]=$sirenTest;
|
||
|
}
|
||
|
}
|
||
|
$iCalc++;
|
||
|
}
|
||
|
//echo EOL;
|
||
|
}
|
||
|
$nbC=count($tabSirenConnus);
|
||
|
$nbM=count($tabSirenManquants);
|
||
|
echo date ('Y/m/d - H:i:s')." - Siren en base ....... $nbC siren / 99999 dont ";
|
||
|
$tmp=$iDb->select('siretDcren', 'DCREN4, count(*) AS nb', "SIR3=$tranche GROUP BY DCREN4 ORDER BY nb DESC", true, MYSQL_ASSOC);
|
||
|
$nbTot=0;
|
||
|
$tabAnnees=array();
|
||
|
foreach ($tmp as $i=>$tabTmp) {
|
||
|
$nbTot+=$tabAnnees[$tabTmp['DCREN4']]=$tabTmp['nb'];
|
||
|
}
|
||
|
foreach ($tabAnnees as $annee=>$nb) {
|
||
|
echo round($nb/$nbTot*100,1)."% en $annee.".EOL;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
echo date ('Y/m/d - H:i:s')." - Siren manquants ..... $nbM siren.".EOL;
|
||
|
|
||
|
shuffle($tabSirenManquants);
|
||
|
foreach ($tabSirenManquants as $i=>$siren) {
|
||
|
echo "$i:$siren".EOL;
|
||
|
print_r($iGreffe->getIdentite($siren));
|
||
|
randsleep(TMIN,TMAX);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|