2011-11-15 13:58:10 +00:00
#!/usr/bin/php
< ? php
2011-11-22 12:53:09 +00:00
ini_set ( 'memory_limit' , '1024M' );
2011-11-15 13:58:10 +00:00
//error_reporting(E_ALL & ~E_NOTICE);
// Define path to application directory
defined ( 'APPLICATION_PATH' )
|| define ( 'APPLICATION_PATH' , realpath ( dirname ( __FILE__ ) . '/../application' ));
// Define application environment
defined ( 'APPLICATION_ENV' )
|| define ( 'APPLICATION_ENV' , ( getenv ( 'APPLICATION_ENV' ) ? getenv ( 'APPLICATION_ENV' ) : 'production' ));
// Ensure library/ is on include_path
set_include_path ( implode ( PATH_SEPARATOR , array (
realpath ( APPLICATION_PATH . '/../library' ),
get_include_path (),
)));
/** Zend_Application */
require_once 'Zend/Application.php' ;
// Create application, bootstrap, and run
$application = new Zend_Application (
APPLICATION_ENV ,
APPLICATION_PATH . '/configs/application.ini'
);
try {
$opts = new Zend_Console_Getopt (
//Options
array (
'help|?' => " Aide. " ,
'ignore=i' => " Nombre de ligne à ignoré. " ,
'file=s' => " Définir le chemin du fichier " ,
)
);
$opts -> parse ();
} catch ( Zend_Console_Getopt_Exception $e ) {
echo $e -> getUsageMessage ();
exit ;
}
//Usage
if ( isset ( $opts -> help ) || ! isset ( $opts -> file ))
{
echo $opts -> getUsageMessage ();
exit ;
}
2011-11-18 11:11:14 +00:00
//Traiter la demande en créant les requetes sql nécessaires
2011-11-15 13:58:10 +00:00
$tabDico = array (
'etablissements' => array (
'db' => 'jo.etablissements' ,
'cle' => array (
2011-11-16 15:17:13 +00:00
'idSd' => " CONCAT(source,'-',source_id) AS idSd " ,
'source' => '' ,
'triCode' => '' ,
'autre_id' => '' ,
'actif' => '' ,
'siege' => '' ,
2011-11-16 13:47:10 +00:00
'raisonSociale' => '' ,
2011-11-16 15:17:13 +00:00
'enseigne' => '' ,
'sigle' => '' ,
'marques' => '' ,
'adr_num' => '' ,
'adr_btq' => '' ,
'adr_typeVoie' => '' ,
'adr_libVoie' => '' ,
'adr_comp' => '' ,
'adr_cp' => '' ,
'adr_ville' => '' ,
'adr_dep' => '' ,
'adr_codeCom' => 'CONCAT(if (adr_dep>100,round(adr_dep/10),adr_dep*1),adr_com) AS adr_codeCom' ,
'telEtab' => 'tel as telEtab' ,
'faxEtab' => 'fax as faxEtab' ,
'cj' => '' ,
'capital' => '' ,
'capitalDev' => '' ,
'ape_etab' => '' ,
2011-11-17 11:03:30 +00:00
'ape_entrep' => '' ,
'SiretEnBase' => 'nic>0 as SiretEnBase' ,
2011-11-18 11:22:43 +00:00
),
2011-12-05 17:10:16 +00:00
'where' => ' WHERE siren=$siren AND nic=$nicV' ,
2011-11-16 13:47:10 +00:00
),
'identite' => array (
'db' => 'insee.identite' ,
'cle' => array (
2011-11-16 15:17:13 +00:00
'etActifInsee' => 'ACTIF as etActifInsee' ,
'nomInsee' => 'NOM as nomInsee' ,
'nomInsee2' => 'NOM2 as nomInsee2' ,
'sigleInsee' => 'SIGLE as sigleInsee' ,
'enseigneInsee' => 'ENSEIGNE as enseigneInsee' ,
'adrNumVoieInsee' => 'ADR_NUMVOIE as adrNumVoieInsee' ,
'adrBtqInsee' => 'ADR_BTQ as adrBtqInsee' ,
'adrTypeVoieInsee' => 'ADR_TYPVOIE as adrTypeVoieInsee' ,
'adrVoieInsee' => 'ADR_LIBVOIE as adrVoieInsee' ,
'adrCompInsee' => 'ADR_COMP as adrCompInsee' ,
'adrCPInsee' => 'ADR_CP as adrCPInsee' ,
'adrVilleInsee' => 'ADR_LIBCOM as adrVilleInsee' ,
'adrDistSPInsee' => 'ADR_DISTSP as adrDistSPInsee' ,
'CjInsee' => 'CJ as CjInsee' ,
'nafEnInsee' => 'APE_ENT as nafEnInsee' ,
'nafEtInsee' => 'APE_ETAB as nafEtInsee' ,
'APRM' => '' ,
'ACTIVNAT' => '' ,
'ORIGINE' => '' ,
'MODET' => '' ,
'EXPLET' => '' ,
'LIEUACT' => '' ,
'ACTISURF' => '' ,
'MODEN' => '' ,
'PRODPART' => '' ,
'EXPLEN' => '' ,
'MONOREG' => '' ,
'REGIMP' => '' ,
'MONOACT' => '' ,
'DCREN' => '' ,
'AUXILT' => '' ,
'SAISONAT' => '' ,
'CIVILITE' => '' ,
'TCA' => '' ,
'TCAEXP' => '' ,
'EFF_ENT' => '' ,
'DCRET' => '' ,
'EFF_ET' => '' ,
'CODEVOIE' => '' ,
'dateMajInsee' => 'dateUpdate as dateMajInsee' ,
2011-11-18 11:22:43 +00:00
),
2011-12-05 17:10:16 +00:00
'where' => ' WHERE SIREN=$siren AND NIC=$nicV' ,
2011-11-16 13:47:10 +00:00
),
2011-11-17 11:03:30 +00:00
'notice' => array (
'db' => 'insee.insee_notices' ,
'cle' => array (
'insRPET' => '' ,
'insDEPCOMEN' => '' ,
'insRPEN' => '' ,
'insARRONET' => '' ,
'insCTONET' => '' ,
'insTCD' => '' ,
'insZEMET' => '' ,
'insDU' => '' ,
'insTU' => '' ,
'insUU' => '' ,
'insRECME' => '' ,
'insEAEANT' => '' ,
'insEAEAPET' => '' ,
'insEAESEC1T' => '' ,
'insEAESEC2T' => '' ,
'insEAEANN' => '' ,
'insEAEAPEN' => '' ,
'insEAESEC1N' => '' ,
'insEAESEC2N' => '' ,
'insEAESEC3N' => '' ,
'insEAESEC4N' => '' ,
'dateMajNotice' => 'dateNotice as dateMajNotice' ,
2011-11-18 11:22:43 +00:00
),
2011-12-05 17:10:16 +00:00
'where' => ' WHERE insSIREN=$siren AND insNIC=$nicV' ,
2011-11-17 11:03:30 +00:00
),
'rncs_entrep' => array (
'db' => 'jo.rncs_entrep' ,
'cle' => array (
'entActiveRncs' => 'actif AS entActiveRncs' ,
'numRC2' => 'numRC2' ,
'raisonSocialeRncs' => 'raisonSociale AS raisonSocialeRncs' ,
'sigleRncs' => 'sigle AS sigleRncs' ,
'dateNaiss' => 'dateNaiss' ,
'lieuNaiss' => 'lieuNaiss' ,
'nationalite' => 'nationalite' ,
'pays' => 'pays' ,
'nafEnRncs' => 'naf AS nafEnRncs' ,
'cjRncs' => 'cj AS cjRncs' ,
'dateImma' => 'dateImma' ,
'dateRad' => 'dateRad' ,
'capitalType' => 'capitalType' ,
'dateMajEnRncs' => 'flux AS dateMajEnRncs' ,
2011-11-18 11:22:43 +00:00
),
2011-11-17 11:03:30 +00:00
'where' => ' WHERE siren=$siren' ,
),
'rncs_etab' => array (
'db' => 'jo.rncs_etab' ,
'cle' => array (
'etActifRncs' => 'actif AS etActifRncs' ,
'siegeRncs' => 'siege AS siegeRncs' ,
'enseigneRncs' => 'enseigne AS enseigneRncs' ,
'nomCommercialRncs' => 'nomCommercial AS nomCommercialRncs' ,
'adrNumVoieRncs' => 'adrNumVoie AS adrNumVoieRncs' ,
'adrIndRepRncs' => 'adrIndRep AS adrIndRepRncs' ,
'adrLibVoieRncs' => 'adrLibVoie AS adrLibVoieRncs' ,
'adrTypeVoieRncs' => 'adrTypeVoie AS adrTypeVoieRncs' ,
'adrVoieRncs' => 'adrVoie AS adrVoieRncs' ,
'cpRncs' => 'cp AS cpRncs' ,
'villeRncs' => 'commune AS villeRncs' ,
'adrCompRncs' => 'adrComp AS adrCompRncs' ,
'nafEtRncs' => 'naf AS nafEtRncs' ,
'dateMajEtRncs' => 'flux AS dateMajEtRncs' ,
2011-11-18 11:22:43 +00:00
),
2011-12-05 17:10:16 +00:00
'where' => ' WHERE siren=$siren AND nic=$nicV' ,
2011-11-17 11:03:30 +00:00
),
'infos_entrep' => array (
'db' => 'jo.infos_entrep' ,
'cle' => array (
'isin' => '' ,
'tel' => '' ,
'fax' => '' ,
'web' => '' ,
'mail' => '' ,
2011-11-18 11:22:43 +00:00
),
2011-11-17 11:03:30 +00:00
'where' => ' WHERE siren=$siren' ,
),
2011-11-16 13:47:10 +00:00
'data' => array (
2011-11-17 17:12:23 +00:00
'nicSiege' ,
2011-11-17 11:03:30 +00:00
'tva' ,
'dateFermetureEn' ,
'dateFermetureEt' ,
'activite' ,
2011-11-17 17:12:23 +00:00
'situationJuridique' ,
2011-11-17 11:03:30 +00:00
'situationParution' ,
'situationDernCode' ,
2011-11-17 17:12:23 +00:00
'situationDernEven' ,
2011-11-17 11:03:30 +00:00
'indiScore' ,
2011-11-17 17:12:23 +00:00
'dirigeant' ,
2011-11-17 11:03:30 +00:00
'encours' ,
'dateBilan' ,
2011-11-17 17:12:23 +00:00
'bilanN' ,
'bilanN1' ,
'bilanN2' ,
'annonces' ,
2011-11-15 13:58:10 +00:00
),
);
2011-11-22 12:53:09 +00:00
$file = basename ( $opts -> file );
$extension = strrchr ( $file , '.' );
$file = str_replace ( $extension , '' , $file );
$outFile = $file . '-' . date ( 'YmdHis' ) . '.csv' ;
2011-11-18 11:11:14 +00:00
define ( 'MYSQL_HOST' , '192.168.78.230' );
define ( 'MYSQL_USER' , 'wsuser' );
define ( 'MYSQL_PASS' , 'scores' );
define ( 'MYSQL_DEFAULT_DB' , 'jo' );
//Définition bdd
$dbConfig = array (
'host' => MYSQL_HOST ,
'username' => MYSQL_USER ,
'password' => MYSQL_PASS ,
'dbname' => MYSQL_DEFAULT_DB ,
);
$db = Zend_Db :: factory ( 'PDO_MYSQL' , $dbConfig );
//Chargement des classes metier
require_once realpath ( dirname ( __FILE__ )) . '/../config/config.php' ;
2011-11-22 19:37:51 +00:00
require_once 'Metier/insee/classMInsee.php' ;
2011-11-18 11:11:14 +00:00
require_once 'framework/common/mysql.php' ;
$tabExtract = array ();
$tabEntete = array ();
$tabIdentifiant = array ();
$tabData = array ();
$posKeySiren = $posKeySiret = $posKeyNic = false ;
//Lire le fichier csv
$row = 0 ;
if (( $handle = fopen ( $opts -> file , 'r' )) !== FALSE ) {
2011-11-22 12:53:09 +00:00
while (( $data = fgetcsv ( $handle , 0 , ',' , '"' )) !== FALSE ) {
2011-11-18 11:11:14 +00:00
$num = count ( $data );
//Traitement de la première ligne
if ( $row == 0 ) {
for ( $c = 0 ; $c < $num ; $c ++ ) {
//Détection clé importante
switch ( strtolower ( $data [ $c ])) {
case 'siren' :
$posKeySiren = $c ;
break ;
case 'nic' :
$posKeyNic = $c ;
break ;
case 'siret' :
$posKeySiret = $c ;
break ;
}
$tabExtract [] = $data [ $c ];
}
if ( $posKeySiren !== false && $posKeyNic !== false && $posKeySiret !== false || $posKeySiren !== false && $posKeySiret !== false ){
die ( " Trop de clé! " );
}
if ( $posKeySiren === false && $posKeySiret === false ){
die ( " Aucune clé détecté! " );
}
//Traitement des identifiants
} else {
if ( $posKeySiret !== false ){
$tabIdentifiant [] = $data [ $posKeySiret ];
} elseif ( $posKeySiren !== false && $posKeyNic !== false ){
$tabIdentifiant [] = $data [ $posKeySiren ] . $data [ $posKeyNic ];
} elseif ( $posKeySiren !== false ){
$tabIdentifiant [] = $data [ $posKeySiren ];
}
for ( $c = 0 ; $c < $num ; $c ++ ) {
$colname = $tabExtract [ $c ];
if ( ! in_array ( strtolower ( $colname ), array ( 'siren' , 'siret' , 'nic' ))){
$tabData [ $row - 1 ][ $colname ] = $data [ $c ];
}
}
}
$row ++ ;
}
fclose ( $handle );
}
$nbIdentifiant = count ( $tabIdentifiant );
echo " Chargement de $row lignes dont $nbIdentifiant lignes avec identifiants. \n " ;
$rowTotal = $nbIdentifiant ;
2011-11-15 13:58:10 +00:00
//Liste des champs SQL
foreach ( $tabExtract as $key )
{
$strKey = false ;
2011-11-17 17:12:23 +00:00
//Détection element(VAL1,VAL2)
$values = false ;
if ( preg_match ( '/(.*)\(.*\)/' , $key , $matches ))
{
$key = $matches [ 1 ];
$values = $matches [ 2 ];
}
2011-11-16 13:47:10 +00:00
//Traitement spécial pour le champs, ajout et remplacement sur entete
2011-11-17 15:29:32 +00:00
if ( function_exists ( $key . 'Entete' )){
2011-11-22 12:53:09 +00:00
$keys = call_user_func ( $key . 'Entete' , $values );
2011-11-17 15:29:32 +00:00
foreach ( $keys as $item ){
$tabEntete [] = $item ;
}
} else {
$tabEntete [] = $key ;
2011-11-15 13:58:10 +00:00
}
2011-11-16 13:47:10 +00:00
//Ajout à la requete SQL
2011-11-15 13:58:10 +00:00
foreach ( $tabDico as $element => $select )
{
2011-11-18 11:11:14 +00:00
if ( array_key_exists ( 'db' , $select ) && array_key_exists ( $key , $select [ 'cle' ]) )
2011-11-15 13:58:10 +00:00
{
if ( isset ( $ { $element . 'Fields' })){ $ { $element . 'Fields' } .= ', ' ; }
2011-11-16 13:47:10 +00:00
if ( $select [ 'cle' ][ $key ] != '' ){
$strKey = $select [ 'cle' ][ $key ];
}
2011-11-15 13:58:10 +00:00
if ( $strKey !== false ){
$ { $element . 'Fields' } .= $strKey ;
} else {
$ { $element . 'Fields' } .= $key ;
}
break ;
2011-11-17 11:03:30 +00:00
}
2011-11-22 12:53:09 +00:00
if ( $element == 'data' && in_array ( $key , $select ) )
2011-11-17 11:03:30 +00:00
{
2011-11-22 12:53:09 +00:00
$ { $key . 'Data' } = $values ;
2011-11-15 13:58:10 +00:00
}
}
}
2011-11-22 12:53:09 +00:00
2011-12-05 17:10:16 +00:00
//Ajout colonne obligatoire SiretValide
$tabEntete [] = 'SiretValide' ;
unset ( $tabExtract );
2011-11-15 13:58:10 +00:00
//Vérification et création des données
2011-11-18 11:11:14 +00:00
$row = 0 ;
2011-11-15 13:58:10 +00:00
foreach ( $tabIdentifiant as $item )
{
2011-12-05 17:10:16 +00:00
echo " Lignes " . ( $row + 1 ) . " / $rowTotal " ;
2011-11-15 13:58:10 +00:00
$siretValide = false ;
$sirenValide = false ;
2011-11-22 12:53:09 +00:00
$siren = substr ( $item , 0 , 9 );
$nic = substr ( $item , 9 );
2011-11-15 13:58:10 +00:00
//Vérification par algorithme
2011-12-05 17:10:16 +00:00
$siretValide = siretValide ( $item );
if ( $posKeySiret !== false ){
2011-11-15 13:58:10 +00:00
if ( $siretValide === false ){
2011-11-22 12:53:09 +00:00
$sirenValide = sirenValide ( $siren );
2011-11-15 13:58:10 +00:00
} else {
$sirenValide = true ;
}
}
if ( $posKeySiren !== false && $posKeyNic !== false ) {
$sirenValide = sirenValide ( $siren );
}
//On définit le tableau de retour
if ( $posKeySiret !== false ){
2011-11-18 11:11:14 +00:00
$tabData [ $row ][ 'siret' ] = $item ;
2011-11-15 13:58:10 +00:00
} elseif ( $posKeySiren !== false && $posKeyNic !== false ){
2011-11-18 11:11:14 +00:00
$tabData [ $row ][ 'siren' ] = $siren ;
$tabData [ $row ][ 'nic' ] = $nic ;
2011-11-15 13:58:10 +00:00
} elseif ( $posKeySiren !== false ){
2011-11-18 11:11:14 +00:00
$tabData [ $row ][ 'siren' ] = $siren ;
2011-11-15 13:58:10 +00:00
}
2011-12-05 17:10:16 +00:00
$tabData [ $row ][ 'SiretValide' ] = ( $siretValide === true ) ? 1 : 0 ;
2011-11-15 13:58:10 +00:00
2011-11-22 12:53:09 +00:00
if ( $sirenValide === false || intval ( $siren ) == 0 ){
2011-11-15 13:58:10 +00:00
echo " - Siren Invalide - " ;
echo " \n " ;
$row ++ ;
continue ;
}
2011-12-05 17:10:16 +00:00
2011-11-15 13:58:10 +00:00
//Vérifier les nic, ou sélectionner le nic du siege actif
2011-12-05 17:10:16 +00:00
$nicV = $nic ; //Surcharge pour le nic
2011-11-15 13:58:10 +00:00
$strNic = '' ;
$sqlNic = 'SELECT nic as nicTmp, cj as cjTmp FROM jo.etablissements WHERE siren=' . $siren ;
if ( strlen ( $item ) == 14 && intval ( $nic ) > 0 ){
$stmt = $db -> query ( $sqlNic . ' AND nic=' . $nic );
$result = $stmt -> fetchAll ();
if ( count ( $result ) == 0 ){
2011-12-05 17:10:16 +00:00
$nicV = 0 ;
2011-11-17 17:12:23 +00:00
$fJur = '0000' ;
} else {
2011-12-05 17:10:16 +00:00
//nic : On considère qu'il est vrai si on a un résultat
2011-11-17 17:12:23 +00:00
$fJur = $result [ 0 ][ 'cjTmp' ];
2011-11-16 13:47:10 +00:00
}
}
2011-11-15 13:58:10 +00:00
2011-12-05 17:10:16 +00:00
if ( intval ( $nicV ) == 0 ){
2011-11-15 13:58:10 +00:00
$strNic = ' AND nic>-1 AND actif>-1 ORDER BY siege DESC, actif DESC, nicTmp DESC LIMIT 0,1' ;
$stmt = $db -> query ( $sqlNic . $strNic );
$result = $stmt -> fetchAll ();
if ( count ( $result ) > 0 ){
2011-12-05 17:10:16 +00:00
$nicV = $result [ 0 ][ 'nicTmp' ];
2011-11-17 17:12:23 +00:00
$fJur = $result [ 0 ][ 'cjTmp' ];
2011-11-15 13:58:10 +00:00
} else {
2011-12-05 17:10:16 +00:00
$nicV = '00000' ;
2011-11-17 17:12:23 +00:00
$fJur = '0000' ;
2011-11-15 13:58:10 +00:00
}
}
if ( $posKeySiren !== false && $posKeyNic !== false ){
2011-11-18 11:11:14 +00:00
$tabData [ $row ][ 'siren' ] = $siren ;
$tabData [ $row ][ 'nic' ] = $nic ;
2011-11-15 13:58:10 +00:00
}
2011-11-16 13:47:10 +00:00
//Récupération des données
2011-11-15 13:58:10 +00:00
foreach ( $tabDico as $element => $select )
{
2011-11-16 13:47:10 +00:00
//Traitement par requete SQL
2011-11-15 13:58:10 +00:00
if ( isset ( $ { $element . 'Fields' })){
2011-11-16 13:47:10 +00:00
$where = $select [ 'where' ];
eval ( " \$ where = \" $where\ " ; " );
2011-11-15 13:58:10 +00:00
$ { $element . 'SQL' } = 'SELECT ' . $ { $element . 'Fields' } . ' FROM ' . $select [ 'db' ] . $where ;
$stmt = $db -> query ( $ { $element . 'SQL' });
$result = $stmt -> fetchAll ();
if ( count ( $result ) > 0 ){
2011-11-18 11:11:14 +00:00
$tabData [ $row ] = array_merge ( $tabData [ $row ] , $result [ 0 ]);
2011-11-15 13:58:10 +00:00
}
}
2011-11-16 13:47:10 +00:00
//Traitement par fonction
2011-11-22 12:53:09 +00:00
if ( $element == 'data' )
2011-11-16 13:47:10 +00:00
{
2011-11-22 12:53:09 +00:00
foreach ( $select as $item )
{
if ( isset ( $ { $item . 'Data' }))
{
$values = false ;
if ( $ { $item . 'Data' } != false ){
$values = explode ( ',' , $ { $item . 'Data' });
}
2011-12-05 17:10:16 +00:00
$tabData [ $row ] = array_merge ( $tabData [ $row ], call_user_func ( $item . 'Data' , $siren , $nicV , $values ));
2011-11-22 12:53:09 +00:00
}
}
2011-11-16 13:47:10 +00:00
}
2011-11-15 13:58:10 +00:00
}
echo " \n " ;
$row ++ ;
}
//Mettre dans l'ordre les données
$tabSortie = array ();
$row = 0 ;
foreach ( $tabData as $data ){
2011-11-22 12:53:09 +00:00
foreach ( $tabEntete as $key ){
2011-11-17 11:16:56 +00:00
$tabSortie [ $row ][] = isset ( $tabData [ $row ][ $key ]) ? $tabData [ $row ][ $key ] : '' ;
2011-11-15 13:58:10 +00:00
}
$row ++ ;
}
2011-11-18 10:08:51 +00:00
writeCSV ( $tabSortie , $tabEntete , $outFile );
2011-11-15 13:58:10 +00:00
2011-11-16 13:47:10 +00:00
/* == FUNCTION DATA == */
2011-11-17 17:12:23 +00:00
function nicSiegeData ( $siren , $nic , $values = false )
{
$tabData [ 'nicSiege' ] = $nic ;
return $tabData ;
}
function tvaData ( $siren , $nic , $values = false )
{
require_once 'Metier/partenaires/classMTva.php' ;
$iTva = @ new MTva ( $siren , false );
$tabData [ 'tva' ] = isset ( $iTva -> vatNumber ) ? $iTva -> vatNumber : '' ;
return $tabData ;
}
function dateFermetureEtEntete ( $values )
{
return array (
'dateFermetureEt' ,
'codeFermetureEt' ,
);
}
function dateFermetureEtData ( $siren , $nic , $values = false )
{
$iDb = new WDB ();
2011-11-22 12:53:09 +00:00
$ret = $iDb -> select ( 'insee.insee_even' , 'insEVE, insDATEVE' , 'insSIREN=' . $siren . ' AND insNIC=' . $nic . " AND insEVE IN('FF','OF','400','410','420','425','430','435') ORDER BY insDATEVE DESC LIMIT 1 " , false , MYSQL_ASSOC );
2011-11-17 17:12:23 +00:00
if ( mysql_errno () > 0 ) die ( 'Erreur B2 ' . mysql_errno () . ' : ' . mysql_error () );
if ( count ( $ret ) == 0 ) {
2011-11-22 12:53:09 +00:00
$siret = $siren . $nic ;
$ret = $iDb -> select ( 'insee.insee_even' , 'insEVE, insDATEVE' , " insSIRETPS= $siret AND insEVE IN('510','530') ORDER BY insDATEVE DESC LIMIT 1 " , false , MYSQL_ASSOC );
2011-11-17 17:12:23 +00:00
}
$tabData [ 'dateFermetureEt' ] = isset ( $ret [ 0 ][ 'insDATEVE' ]) ? $ret [ 0 ][ 'insDATEVE' ] : '' ;
$tabData [ 'codeFermetureEt' ] = isset ( $ret [ 0 ][ 'insEVE' ]) ? $ret [ 0 ][ 'insEVE' ] : '' ;
return $tabData ;
}
function dateFermetureEnEntete ( $values )
{
return array (
'dateFermetureEn' ,
'codeFermetureEn' ,
);
}
function dateFermetureEnData ( $siren , $nic , $values = false )
{
$iDb = new WDB ();
$ret = @ $iDb -> select ( 'insee.insee_even' , 'insEVE, insDATEVE' , 'insSIREN=' . $siren . " AND insEVE IN('FF','410','420','425') ORDER BY insDATEVE DESC " , false , MYSQL_ASSOC );
if ( mysql_errno () > 0 ) die ( 'Erreur B3 ' . mysql_errno () . ' : ' . mysql_error () );
$tabData [ 'dateFermetureEn' ] = isset ( $ret [ 0 ][ 'insDATEVE' ]) ? $ret [ 0 ][ 'insDATEVE' ] : '' ;
$tabData [ 'codeFermetureEn' ] = isset ( $ret [ 0 ][ 'insEVE' ]) ? $ret [ 0 ][ 'insEVE' ] : '' ;
return $tabData ;
}
function activiteData ( $siren , $nic , $values = false )
{
global $fJur ;
$tmp = @ $iBodacc -> getActiviteReelle ( $siren , $fJur );
$tabData [ 'activite' ] = @ preg_replace ( '/ +/' , ' ' , strtr ( $tmp , array ( " \r " => ' ' , " \n " => ' ' , " \t " => ' ' , ',' => ' ' , ';' => ' ' , '"' => ' ' , " ' " => ' ' )));
return $tabData ;
}
function situationJuridiqueEntete ( $values )
{
return array (
'situationJuridique' ,
'situationParution' ,
'situationDernCode' ,
'situationDernEven' ,
);
}
function situationJuridiqueData ( $siren , $nic , $values = false )
2011-11-17 15:29:32 +00:00
{
$tabTmp = array ( 'P' , 'A' , 'D' );
$tabData [ 'situationJuridique' ] = '' ;
foreach ( $tabTmp as $sit ) {
$iInsee = new MInsee ();
$tmp = $iInsee -> getAnnoncesLegales ( $cel [ $pos [ 'SIREN' ]], 0 , $sit , false );
if ( count ( $tmp ) > 0 ) {
$tmp = $tmp [ 0 ];
$tabData [ 'situationJuridique' ] = $sit ;
$tabData [ 'situationParution' ] =@ $tmp [ 'DateParution' ];
$tabData [ 'situationDernCode' ] =@ $tmp [ 0 ][ 'CodeEven' ];
$tabData [ 'situationDernEven' ] =@ preg_replace ( '/ +/' , ' ' , strtr ( $tmp [ 0 ][ 'LibEven' ], array ( " \r " => ' ' , " \n " => ' ' , " \t " => ' ' , ',' => ' ' , ';' => ' ' , '"' => ' ' , " ' " => ' ' )));
break ;
}
}
if ( $tabData [ 'situationJuridique' ] == '' ) {
$iDb = new WDB ();
$rep = $iDb -> select ( 'rncs_entrep' , 'actif, dateRad' , " siren= " . $cel [ $pos [ 'SIREN' ]], false , MYSQL_ASSOC );
$entrep = @ $rep [ 0 ];
if ( isset ( $entrep [ 'actif' ]) && $entrep [ 'actif' ] * 1 == 0 )
$tabData [ 'situationJuridique' ] = 'R' ;
$tabData [ 'situationParution' ] =@ $entrep [ 'dateRad' ];
$tabData [ 'situationDernCode' ] = '' ;
$tabData [ 'situationDernEven' ] = '' ;
}
2011-11-16 13:47:10 +00:00
2011-11-17 15:29:32 +00:00
return $tabData ;
2011-11-16 13:47:10 +00:00
}
2011-11-17 17:12:23 +00:00
function dirigeantEntete ( $values )
{
return array (
'dirigeant1Nom' ,
'dirigeant1Fonction' ,
'dirigeant1DateNaiss' ,
'dirigeant1LieuNaiss' ,
'dirigeant2Nom' ,
'dirigeant2Fonction' ,
'dirigeant2DateNaiss' ,
'dirigeant2LieuNaiss' ,
);
}
function dirigeantData ( $siren , $nic , $values = false )
{
$iInsee = new MInsee ();
$tmp = $iInsee -> getDirigeants ( $siren , false );
$tabData [ 'dirigeant1Nom' ] = '' ;
$tabData [ 'dirigeant1Fonction' ] = '' ;
$tabData [ 'dirigeant1DateNaiss' ] = '' ;
$tabData [ 'dirigeant1LieuNaiss' ] = '' ;
$tabData [ 'dirigeant2Nom' ] = '' ;
$tabData [ 'dirigeant2Fonction' ] = '' ;
$tabData [ 'dirigeant2DateNaiss' ] = '' ;
$tabData [ 'dirigeant2LieuNaiss' ] = '' ;
if ( count ( $tmp ) > 0 ) {
$dir = $tmp [ 0 ];
if ( $dir [ 'Societe' ] <> '' ) $tabData [ 'dirigeant1Nom' ] .= $dir [ 'Societe' ] . ' repr. par ' ;
$tabData [ 'dirigeant1Nom' ] .= trim ( $dir [ 'Civilite' ] . ' ' . $dir [ 'Nom' ] . ' ' . $dir [ 'Prenom' ]);
$tabData [ 'dirigeant1Fonction' ] = $dir [ 'Titre' ];
$tabData [ 'dirigeant1DateNaiss' ] = $dir [ 'NaissDate' ];
$tabData [ 'dirigeant1LieuNaiss' ] = $dir [ 'NaissVille' ];
}
if ( count ( $tmp ) > 1 ) {
$dir = $tmp [ 1 ];
if ( $dir [ 'Societe' ] <> '' ) $tabData [ 'dirigeant2Nom' ] .= $dir [ 'Societe' ] . ' repr. par ' ;
$tabData [ 'dirigeant2Nom' ] .= trim ( $dir [ 'Civilite' ] . ' ' . $dir [ 'Nom' ] . ' ' . $dir [ 'Prenom' ]);
$tabData [ 'dirigeant2Fonction' ] = $dir [ 'Titre' ];
$tabData [ 'dirigeant2DateNaiss' ] = $dir [ 'NaissDate' ];
$tabData [ 'dirigeant2LieuNaiss' ] = $dir [ 'NaissVille' ];
}
return $tabData ;
}
function bilanNEntete ( $values )
{
2011-11-18 09:24:45 +00:00
if ( $values !== false ) {
$values = explode ( ',' , $values );
$tmp = array ();
foreach ( $values as $value ){
$tmp [] = 'bilanN' . $value ;
}
return array_merge (
array ( 'bilanNdateCloture' , 'bilanNdureeMois' )
, $tmp
);
} else {
return array ( 'bilanNdateCloture' , 'bilanNdureeMois' );
}
2011-11-17 17:12:23 +00:00
}
function bilanNData ( $siren , $nic , $values = false )
{
2011-11-18 09:24:45 +00:00
require_once 'Metier/partenaires/classMBilans.php' ;
$tabPostes = explode ( ',' , $values );
$tabData = array ();
$annee = 0 ;
2011-11-17 17:12:23 +00:00
2011-11-18 09:24:45 +00:00
$mBil = new MBilans ( $siren );
$tabBilans = $mBil -> listeBilans ( false , 3 );
if ( count ( $tabBilans ) > 0 ) {
$tabBil = array ();
foreach ( $tabBilans as $typeMil => $bilan ) {
$tabBil [] = $mBil -> getBilan ( substr ( $typeMil , 1 ), substr ( $typeMil , 0 , 1 ));
}
$tabBi = $tabBil [ $annee ];
$tabData [ 'bilanNdateCloture' ] = $tabBi [ 'DATE_CLOTURE' ];
$tabData [ 'bilanNdureeMois' ] = $tabBi [ 'DUREE_MOIS' ];
if ( count ( $tabPostes ) > 0 ){
foreach ( $tabPostes as $poste ) {
if ( isset ( $tabBi [ $poste ])){
$tabData [ $poste ] = $tabBi [ $poste ];
}
}
}
}
return $tabData ;
2011-11-17 17:12:23 +00:00
}
function bilanN1Entete ( $values )
{
2011-11-18 09:24:45 +00:00
if ( $values !== false ) {
$values = explode ( ',' , $values );
$tmp = array ();
foreach ( $values as $value ){
$tmp [] = 'bilanN1' . $value ;
}
return array_merge (
array ( 'bilanN1dateCloture' , 'bilanN1dureeMois' )
, $tmp
);
} else {
return array ( 'bilanN1dateCloture' , 'bilanN1dureeMois' );
}
2011-11-17 17:12:23 +00:00
}
function bilanN1Data ( $siren , $nic , $values = false )
{
2011-11-18 09:24:45 +00:00
require_once 'Metier/partenaires/classMBilans.php' ;
$tabPostes = explode ( ',' , $values );
$tabData = array ();
$annee = 1 ;
$mBil = new MBilans ( $siren );
$tabBilans = $mBil -> listeBilans ( false , 3 );
if ( count ( $tabBilans ) > 0 ) {
$tabBil = array ();
foreach ( $tabBilans as $typeMil => $bilan ) {
$tabBil [] = $mBil -> getBilan ( substr ( $typeMil , 1 ), substr ( $typeMil , 0 , 1 ));
}
$tabBi = $tabBil [ $annee ];
$tabData [ 'bilanN1dateCloture' ] = $tabBi [ 'DATE_CLOTURE' ];
$tabData [ 'bilanN1dureeMois' ] = $tabBi [ 'DUREE_MOIS' ];
if ( count ( $tabPostes ) > 0 ){
foreach ( $tabPostes as $poste ) {
if ( isset ( $tabBi [ $poste ])){
$tabData [ $poste ] = $tabBi [ $poste ];
}
}
}
}
return $tabData ;
2011-11-17 17:12:23 +00:00
}
function bilanN2Entete ( $values )
{
2011-11-18 09:24:45 +00:00
if ( $values !== false ) {
$values = explode ( ',' , $values );
$tmp = array ();
foreach ( $values as $value ){
$tmp [] = 'bilanN2' . $value ;
}
return array_merge (
array ( 'bilanN2dateCloture' , 'bilanN2dureeMois' )
, $tmp
);
} else {
return array ( 'bilanN2dateCloture' , 'bilanN2dureeMois' );
}
2011-11-17 17:12:23 +00:00
}
function bilanN2Data ( $siren , $nic , $values = false )
{
2011-11-18 09:24:45 +00:00
require_once 'Metier/partenaires/classMBilans.php' ;
$tabPostes = explode ( ',' , $values );
$tabData = array ();
$annee = 2 ;
$mBil = new MBilans ( $siren );
$tabBilans = $mBil -> listeBilans ( false , 3 );
if ( count ( $tabBilans ) > 0 ) {
$tabBil = array ();
foreach ( $tabBilans as $typeMil => $bilan ) {
$tabBil [] = $mBil -> getBilan ( substr ( $typeMil , 1 ), substr ( $typeMil , 0 , 1 ));
}
$tabBi = $tabBil [ $annee ];
$tabData [ 'bilanN2dateCloture' ] = $tabBi [ 'DATE_CLOTURE' ];
$tabData [ 'bilanN2dureeMois' ] = $tabBi [ 'DUREE_MOIS' ];
if ( count ( $tabPostes ) > 0 ){
foreach ( $tabPostes as $poste ) {
if ( isset ( $tabBi [ $poste ])){
$tabData [ $poste ] = $tabBi [ $poste ];
}
}
}
}
return $tabData ;
2011-11-17 17:12:23 +00:00
}
function annoncesEntete ( $values )
{
2011-11-18 09:24:45 +00:00
if ( $values !== false ) {
$values = explode ( ',' , $values );
$tmp = array ();
foreach ( $values as $value ){
$tmp [] = 'Annonce' . $value . 'Lib' ;
$tmp [] = 'Annonce' . $value . 'Date' ;
$tmp [] = 'Annonce' . $value . 'DateParution' ;
}
return $tmp ;
} else {
return array ();
2011-11-17 17:12:23 +00:00
}
}
function annoncesData ( $siren , $nic , $values = false )
{
2011-11-18 09:24:45 +00:00
if ( $values !== false ) {
$tabDeja = array ();
$tabTmp = explode ( ',' , $values );
$iInsee = new MInsee ();
$tabEven = $iInsee -> getAnnoncesLegales ( $siren , 0 , $tabTmp );
foreach ( $tabTmp as $even ){
foreach ( $tabEven as $tabAnn ){
foreach ( $tabAnn [ 'evenements' ] as $codEve ){
if ( $even == $codEve [ 'CodeEven' ] && ! in_array ( $even , $tabDeja )) {
$tabDeja [] = $even ;
$dateEven = $tabAnn [ 'dateJugement' ];
if ( $dateEven == '0000-00-00' ) $dateEven = $tabAnn [ 'dateEffet' ];
if ( $dateEven == '0000-00-00' ) $dateEven = $tabAnn [ 'DateParution' ];
$tabData [ 'Annonce' . $even . 'Lib' ] = strtr ( $codEve [ 'LibEven' ], array ( ',' => ' ' , " ' " => ' ' , '"' => ' ' , ';' => ' ' ));
$tabData [ 'Annonce' . $even . 'Date' ] = $dateEven ;
$tabData [ 'Annonce' . $even . 'DateParution' ] = $tabAnn [ 'DateParution' ];
}
}
}
}
return $tabData ();
} else {
return $tabData ();
}
2011-11-17 17:12:23 +00:00
}
2011-11-16 13:47:10 +00:00
/* == FUNCTION == */
2011-11-15 13:58:10 +00:00
/**
* Verifie si un SIREN est valide
* @ param Le code SIREN dont on veut vérifier la validité .
* @ return Un booléen qui vaut 'true' si le code SIREN passé en
* paramètre est valide , false sinon .
*/
function sirenValide ( $siren ) {
if ( ( strlen ( $siren ) != 9 ) || ( is_nan ( $siren )) )
$estValide = false ;
else {
// Donc le SIREN est un numérique à 9 chiffres
$somme = 0 ;
$tmp = 0 ;
2011-11-22 19:37:51 +00:00
for ( $cpt = 0 ; $cpt < strlen ( $siren ); $cpt ++ ) {
2011-11-15 13:58:10 +00:00
if (( $cpt % 2 ) == 1 ) { // Les positions paires : 2ème, 4ème, 6ème et 8ème chiffre
$tmp = substr ( $siren , $cpt , 1 ) * 2 ; // On le multiplie par 2
if ( $tmp > 9 )
2011-12-05 17:10:16 +00:00
$tmp -= 9 ; // Si le résultat est supérieur à 9, on lui soustrait 9
2011-11-15 13:58:10 +00:00
}
else
$tmp = substr ( $siren , $cpt , 1 );
2011-12-05 17:10:16 +00:00
$somme += intval ( $tmp );
2011-11-15 13:58:10 +00:00
}
2011-11-22 19:37:51 +00:00
if (( $somme % 10 ) == 0 )
2011-11-15 13:58:10 +00:00
$estValide = true ; // Si la somme est un multiple de 10 alors le SIREN est valide
else
$estValide = false ;
}
return $estValide ;
2011-11-16 13:47:10 +00:00
}
2011-11-15 13:58:10 +00:00
/**
* Verifie si un SIRET est valide
* @ param Le code SIRET dont on veut vérifier la validité .
* @ return Un booléen qui vaut 'true' si le code SIRET passé en
* paramètre est valide , false sinon .
*/
function siretValide ( $siret ) {
if ( ( strlen ( $siret ) != 14 ) || ( is_nan ( $siret )) )
$estValide = false ;
else {
// Donc le SIRET est un numérique à 14 chiffres
// Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
// correspondent au numéro d'établissement
// et enfin le dernier chiffre est une clef de LUHN.
$somme = 0 ;
$tmp = 0 ;
2011-11-22 19:37:51 +00:00
for ( $cpt = 0 ; $cpt < strlen ( $siret ); $cpt ++ ) {
2011-11-15 13:58:10 +00:00
if (( $cpt % 2 ) == 0 ) { // Les positions impaires : 1er, 3è, 5è, etc...
$tmp = substr ( $siret , $cpt , 1 ) * 2 ; // On le multiplie par 2
if ( $tmp > 9 )
2011-12-05 17:10:16 +00:00
$tmp -= 9 ; // Si le résultat est supérieur à 9, on lui soustrait 9
2011-11-15 13:58:10 +00:00
}
else
$tmp = substr ( $siret , $cpt , 1 );
2011-12-05 17:10:16 +00:00
$somme += intval ( $tmp );
2011-11-15 13:58:10 +00:00
}
if (( $somme % 10 ) == 0 )
$estValide = true ; // Si la somme est un multiple de 10 alors le SIRET est valide
else
$estValide = false ;
}
return $estValide ;
}
2011-11-16 13:47:10 +00:00
/**
* writeCSV
* @ param array $list
* @ param array $entete
* @ param string $filename
*/
2011-11-15 13:58:10 +00:00
function writeCSV ( $list , $entete , $filename )
{
$fp = fopen ( $filename , 'w' );
if ( count ( $entete ) > 0 ){
2011-11-22 12:53:09 +00:00
fputcsv ( $fp , $entete , ',' , '"' );
2011-11-15 13:58:10 +00:00
}
foreach ( $list as $fields ) {
2011-11-22 12:53:09 +00:00
fputcsv ( $fp , $fields , ',' , '"' );
2011-11-15 13:58:10 +00:00
}
fclose ( $fp );
}