2012-10-16 07:44:31 +00:00
|
|
|
|
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
include_once(FWK_PATH.'common/chiffres.php');
|
|
|
|
|
include_once(FWK_PATH.'common/dates.php');
|
|
|
|
|
include_once(INCLUDE_PATH.'insee/classMInsee.php');
|
|
|
|
|
|
|
|
|
|
$iDbR=new WDB('tmp');
|
|
|
|
|
$iDbW=new WDB('insee');
|
|
|
|
|
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo date ('Y/m/d - H:i:s')." - D<>but du traitement...".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
|
|
|
|
|
$nbLongs=$nbCourt=$nbUpdates=$nbIdentiques=$nbNonRemplaces=0;
|
|
|
|
|
|
|
|
|
|
$fieldsR='SIREN, NIC, TEL';
|
2013-06-19 08:24:49 +00:00
|
|
|
|
// on lit R pour mettre <20> jour W
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$fieldsW='SIREN, NIC, APE_ENT, APE_ETAB, SIEGE, ACTIF, ADR_DEP, ADR_COM, TEL';
|
|
|
|
|
$ret=$iDbR->select('mederic', $fieldsR, "SIREN<>'' AND NIC<>'' AND TEL<>''", true, MYSQL_ASSOC, true);
|
|
|
|
|
$k=$nbInsert=$nbUpdate=$nbDBl=0;
|
|
|
|
|
while($ligne=$iDbR->fetch(MYSQL_ASSOC)) {
|
|
|
|
|
$k++;
|
|
|
|
|
$sirenR=$ligne['SIREN']*1;
|
|
|
|
|
$nicR =$ligne['NIC']*1;
|
|
|
|
|
$telR =''.trim(preg_replace('/[^0-9]/', '', $ligne['TEL']));
|
|
|
|
|
if (strlen($telR)>10) { $nbLongs++; continue; }
|
|
|
|
|
elseif (strlen($telR)==9) $telR = '0'.$telR;
|
|
|
|
|
elseif (strlen($telR)<9) { $nbCourt++; continue; }
|
|
|
|
|
|
|
|
|
|
$ret2=$iDbW->select('identite', $fieldsW, "SIREN=$sirenR AND NIC=$nicR", false, MYSQL_ASSOC);
|
|
|
|
|
$cpt=count($ret2);
|
|
|
|
|
if ($cpt==1) {
|
|
|
|
|
/**
|
2013-06-19 08:24:49 +00:00
|
|
|
|
** On V<EFBFBD>rifie si le t<EFBFBD>l<EFBFBD>phone est absent dans la table identit<EFBFBD>
|
2012-10-16 07:44:31 +00:00
|
|
|
|
**/
|
|
|
|
|
$tabIden=$ret2[0];
|
|
|
|
|
if (trim($tabIden['TEL'])=='') {
|
|
|
|
|
//
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo "Ligne $k, $sirenR $nicR, T<>l <20> mettre <20> jour = $telR\n";
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$retUpdate=$iDbW->update('identite', array('TEL'=>$telR), "SIREN=$sirenR AND NIC=$nicR");
|
|
|
|
|
if (!$retUpdate) die('Erreur lors de MAJ Mysqlsur SIREN=$sirenR AND NIC=$nicR : '. mysql_errno() .' : '.mysql_error());
|
|
|
|
|
$nbUpdates++;
|
|
|
|
|
} elseif ($tabIden['TEL']==$telR) {
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo "Ligne $k, $sirenR $nicR, T<>l identiques = $telR\n";
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$nbIdentiques++;
|
|
|
|
|
} else {
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo "Ligne $k, $sirenR $nicR, T<>l <20> mettre <20> jour = $telR... Mais t<>l<EFBFBD>phone d<>j<EFBFBD> en base = ". $tabIden['TEL'] . EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$nbNonRemplaces++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Trop Longs = $nbLongs".EOL;
|
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Trop Courts = $nbCourt".EOL;
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Mis <20> jours = $nbUpdates".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Identiques = $nbIdentiques".EOL;
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Non remplac<61>s = $nbNonRemplaces".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Mise <20> jour depuis le flux bascule...".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
|
|
|
|
|
$fieldsR='siren, nic, apen5, apen4, depCom, siege, apet5, apet4';
|
2013-06-19 08:24:49 +00:00
|
|
|
|
// on lit R pour mettre <20> jour W
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$fieldsW='SIREN, NIC, APE_ENT, APE_ETAB, SIEGE, ACTIF, ADR_DEP, ADR_COM';
|
|
|
|
|
$ret=$iDbR->select('bascule', $fieldsR, '1', true, MYSQL_ASSOC, true);
|
|
|
|
|
$k=$nbInsert=$nbUpdate=$nbDBl=0;
|
|
|
|
|
while($ligne=$iDbR->fetch(MYSQL_ASSOC)) {
|
|
|
|
|
$k++;
|
|
|
|
|
$siren=$ligne['siren'];
|
|
|
|
|
$nic =$ligne['nic'];
|
|
|
|
|
$ret2=$iDbW->select('identite', $fieldsW, "SIREN=$siren AND NIC=$nic", false, MYSQL_ASSOC);
|
|
|
|
|
$cpt=count($ret2);
|
|
|
|
|
|
|
|
|
|
$arrBase=array( 'ACTIF'=> 1, // PROVISOIRE
|
2013-06-19 08:24:49 +00:00
|
|
|
|
'SIEGE'=> $ligne['siege'], // Si<53>ge
|
2012-10-16 07:44:31 +00:00
|
|
|
|
'APE_ENT'=> trim($ligne['apen5']), // Code NAF de l'entreprise (cf. table APE)
|
2013-06-19 08:24:49 +00:00
|
|
|
|
'APE_ETAB'=> trim($ligne['apet5']), // Code NAF de l'<27>tablissement (cf. table APE)
|
2012-10-16 07:44:31 +00:00
|
|
|
|
'ADR_DEP'=> trim(substr($ligne['depCom'],0,2))*1,
|
|
|
|
|
'ADR_COM'=> trim(substr($ligne['depCom'],2,3))*1,
|
|
|
|
|
'DATE_MAJ'=> '20080111'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($cpt==0) {
|
|
|
|
|
/**
|
2013-06-19 08:24:49 +00:00
|
|
|
|
** On ajoute la fiche de l'<EFBFBD>tablissement
|
2012-10-16 07:44:31 +00:00
|
|
|
|
**/
|
|
|
|
|
$tabInsert=array( 'SIREN'=> $siren,
|
|
|
|
|
'NIC'=> $nic,
|
|
|
|
|
);
|
|
|
|
|
$tabInsert=array_merge($tabInsert, $arrBase);
|
|
|
|
|
//echo date ('Y/m/d - H:i:s')." - Siret $siren $nic en cours d'ajout".EOL;
|
|
|
|
|
$retInsert=$iDbW->insert('identite', $tabInsert, true);
|
2013-06-19 08:24:49 +00:00
|
|
|
|
if (!$retInsert) die('Erreur Mysql n<>'. mysql_errno() .' : '.mysql_error());
|
|
|
|
|
//else echo date ('Y/m/d - H:i:s')." - Siret $siren $nic ajout<75>".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$fp=fopen('siretBasculesInconnus.csv','a');
|
|
|
|
|
fwrite($fp, implode(';', $tabInsert)."\n");
|
|
|
|
|
fclose($fp);
|
|
|
|
|
$nbInsert++;
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
2013-06-19 08:24:49 +00:00
|
|
|
|
** On modifie la fiche de l'<EFBFBD>tablissement
|
2012-10-16 07:44:31 +00:00
|
|
|
|
**/
|
|
|
|
|
//$tabUpdate=;
|
|
|
|
|
$retUpdate=$iDbW->update('identite', $arrBase, "SIREN=$siren AND NIC=$nic");
|
2013-06-19 08:24:49 +00:00
|
|
|
|
if (!$retUpdate) die('Erreur lors de MAJ Mysql n<>'. mysql_errno() .' : '.mysql_error());
|
|
|
|
|
//else echo date ('Y/m/d - H:i:s')." - Siret $siren $nic modifi<66>".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
$nbUpdate++;
|
|
|
|
|
|
|
|
|
|
if ($cpt>1) {
|
|
|
|
|
//die(date ('Y/m/d - H:i:s')." - Siret $siren $nic : $cpt correspondances".EOL);
|
|
|
|
|
$tabSirenDoubles[]=$siren;// RAF
|
|
|
|
|
$fp=fopen('doublons.txt', 'a');
|
|
|
|
|
fwrite($fp, "$siren $nic : $cpt lignes\n");
|
|
|
|
|
fclose($fp);
|
|
|
|
|
//print_r($ret2);
|
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Doublons sur $siren $nic : $cpt lignes\n";
|
|
|
|
|
$nbDBl++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-19 08:24:49 +00:00
|
|
|
|
if ($k%10000==0) echo date ('Y/m/d - H:i:s')." - $k lignes trait<69>s, $siren $nic ($nbInsert ajouts, $nbUpdate maj et $nbDBl doublons)\n";
|
2012-10-16 07:44:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
|
|
|
|
|
?>
|