1276 lines
33 KiB
PHP
1276 lines
33 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
error_reporting(E_ALL & ~E_STRICT & ~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') : 'development'));
|
|
|
|
// 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.",
|
|
'id=s' => "Identifiant du traitement",
|
|
'file=s' => "Traitement manuel avec spécification du fichier",
|
|
'reprise' => "Reprendre un fichier à la ligne n-1",
|
|
'ask' => "Interaction avec l'utilisateur lors d'une reprise manuelle",
|
|
)
|
|
);
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Usage
|
|
if(isset($opts->help) || !isset($opts->id) && !isset($opts->file) )
|
|
{
|
|
echo $opts->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Traiter la demande en créant les requetes sql nécessaires
|
|
$tabDico = array(
|
|
'etablissements' => array(
|
|
'db' => 'jo.etablissements',
|
|
'cle' => array(
|
|
'idSd' => "CONCAT(source,'-',source_id) AS idSd",
|
|
'source' => '',
|
|
'triCode' => '',
|
|
'autre_id' => '',
|
|
'actif' => '',
|
|
'siege' => '',
|
|
'raisonSociale' => '',
|
|
'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' => '',
|
|
'ape_entrep' => '',
|
|
'SiretEnBase' => 'nic>0 as SiretEnBase',
|
|
),
|
|
'where' => ' WHERE siren=$siren AND nic=$nicV',
|
|
),
|
|
'identite' => array(
|
|
'db' => 'insee.identite',
|
|
'cle' => array(
|
|
'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' => '',
|
|
'NBETEXPL' => 'NBETAB as NBETEXPL',
|
|
'dateMajInsee' => 'dateUpdate as dateMajInsee',
|
|
),
|
|
'where' => ' WHERE SIREN=$siren AND NIC=$nicV',
|
|
),
|
|
'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',
|
|
),
|
|
'where' => ' WHERE insSIREN=$siren AND insNIC=$nicV',
|
|
),
|
|
'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',
|
|
),
|
|
'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',
|
|
),
|
|
'where' => ' WHERE siren=$siren AND nic=$nicV',
|
|
),
|
|
'infos_entrep' => array(
|
|
'db' => 'jo.infos_entrep',
|
|
'cle' => array(
|
|
'isin' => '',
|
|
'tel' => '',
|
|
'fax' => '',
|
|
'web' => '',
|
|
'mail' => '',
|
|
),
|
|
'where' => ' WHERE siren=$siren',
|
|
),
|
|
'data' => array(
|
|
'nicSiege',
|
|
'tva',
|
|
'dateFermetureEn',
|
|
'dateFermetureEt',
|
|
'activite',
|
|
'situationJuridique',
|
|
'situationParution',
|
|
'situationDernCode',
|
|
'situationDernEven',
|
|
'indiScore',
|
|
'dirigeant',
|
|
'bilanN',
|
|
'bilanN1',
|
|
'bilanN2',
|
|
'annonces',
|
|
'AdresseNormalise'
|
|
),
|
|
);
|
|
|
|
//MetadataCache pour la base de données
|
|
$frontendOptions = array(
|
|
'lifetime' => 14400,
|
|
'automatic_serialization' => true
|
|
);
|
|
$backendOptions = array();
|
|
$cache = Zend_Cache::factory('Core','Apc', $frontendOptions, $backendOptions);
|
|
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
|
|
|
|
//Définition bdd local
|
|
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
|
|
try {
|
|
$db = Zend_Db::factory($dbConfig->db);
|
|
} catch ( Exception $e ) {
|
|
exit ( $e->getMessage() );
|
|
}
|
|
|
|
if ($opts->id) {
|
|
$commandesM = new Application_Model_Commandes($db);
|
|
$commande = $commandesM->find(intval($opts->id))->current();
|
|
$file = basename($commande->fichier);
|
|
} else {
|
|
$file = $opts->file;
|
|
}
|
|
$extension = strrchr($file,'.');
|
|
$file = str_replace($extension, '', $file);
|
|
|
|
$path = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'path');
|
|
if (!file_exists($path->data.'/export')) mkdir($path->data.'/export');
|
|
|
|
if ($opts->id) {
|
|
$profilM = new Application_Model_Profil($db);
|
|
$profil = $profilM->find($commande->idProfil)->current();
|
|
$profilEntete = json_decode($profil->criteres, true);
|
|
}
|
|
|
|
//Chargement des classes metier
|
|
require_once realpath(dirname(__FILE__)).'/../config/config.php';
|
|
require_once 'framework/fwk.php';
|
|
require_once 'Metier/insee/classMInsee.php';
|
|
|
|
//Définition bdd metier
|
|
$dbConfig = array(
|
|
'host' => MYSQL_HOST,
|
|
'port' => MYSQL_PORT,
|
|
'username' => MYSQL_USER,
|
|
'password' => MYSQL_PASS,
|
|
'dbname' => MYSQL_DEFAULT_DB,
|
|
'persistent' => true,
|
|
'driver_options' => array(MYSQLI_INIT_COMMAND => 'SET NAMES UTF8;'),
|
|
);
|
|
try {
|
|
$dbMetier = Zend_Db::factory('Mysqli', $dbConfig);
|
|
} catch ( Exception $e ) {
|
|
exit ( $e->getMessage() );
|
|
}
|
|
|
|
$tabExtract = array();
|
|
$tabEntete = array();
|
|
$tabIdentifiant = array();
|
|
$tabData = array();
|
|
|
|
$posKeySiren = $posKeySiret = $posKeyNic = false;
|
|
|
|
//Fichier de définition
|
|
$inFile = $path->data.'/clients/'.$file.'.csv';
|
|
|
|
//Lire le fichier csv
|
|
$row = 0;
|
|
if (($handle = fopen($inFile, 'r')) !== FALSE) {
|
|
while (($data = fgetcsv($handle, 0, ',', '"')) !== FALSE) {
|
|
$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);
|
|
}
|
|
|
|
//Ajout des entetes provenant du profil
|
|
if ($opts->id) {
|
|
$tabExtract = array_merge($tabExtract, $profilEntete);
|
|
}
|
|
|
|
$nbIdentifiant = count($tabIdentifiant);
|
|
//echo "Chargement de $row lignes dont $nbIdentifiant lignes avec identifiants.\n";
|
|
$rowTotal = $nbIdentifiant;
|
|
|
|
require_once 'Scores/Enrichissement.php';
|
|
$dico = new Enrichissement();
|
|
|
|
//Liste des champs SQL
|
|
foreach($tabExtract as $key)
|
|
{
|
|
$strKey = false;
|
|
|
|
//Détection element(VAL1,VAL2)
|
|
$values = false;
|
|
if (preg_match('/(.*)\((.*)\)/', $key, $matches))
|
|
{
|
|
$key = $matches[1];
|
|
$values = $matches[2];
|
|
}
|
|
|
|
//Traitement spécial pour le champs, ajout et remplacement sur entete
|
|
if (function_exists($key.'Entete')){
|
|
$keys = call_user_func($key.'Entete', $values);
|
|
foreach($keys as $item){
|
|
$tabEntete[] = $item;
|
|
}
|
|
} else {
|
|
$tabEntete[] = $key;
|
|
}
|
|
|
|
//Ajout à la requete SQL
|
|
foreach($tabDico as $element => $select)
|
|
{
|
|
if ( array_key_exists('db', $select) && array_key_exists($key, $select['cle']) )
|
|
{
|
|
if (isset(${$element.'Fields'})){ ${$element.'Fields'}.= ', '; }
|
|
|
|
if ($select['cle'][$key]!=''){
|
|
$strKey = $select['cle'][$key];
|
|
}
|
|
|
|
if ($strKey!==false){
|
|
${$element.'Fields'}.= $strKey;
|
|
} else {
|
|
${$element.'Fields'}.= $key;
|
|
}
|
|
break;
|
|
}
|
|
if ( $element == 'data' && in_array($key, $select) )
|
|
{
|
|
${$key.'Data'} = $values;
|
|
}
|
|
}
|
|
}
|
|
//Ajout colonne obligatoire SiretValide
|
|
$tabEntete[] = 'SiretValide';
|
|
unset($tabExtract);
|
|
|
|
//Construction de l'entete pour le fichier
|
|
$tabEnteteF = array();
|
|
if (count($tabEntete)>0){
|
|
foreach ( $tabEntete as $key ) {
|
|
$lib = $dico->getDicoLib($key);
|
|
if ( $lib ) {
|
|
$tabEnteteF[] = $lib;
|
|
} else {
|
|
$tabEnteteF[] = $key;
|
|
}
|
|
}
|
|
}
|
|
|
|
//Définition du fichier de sortie
|
|
if ( $opts->reprise ) {
|
|
$outFile = $path->data.'/export/'.$commande->fichierOut;
|
|
|
|
$rowReprise = 0;
|
|
$fp = fopen($outFile, 'r+');
|
|
while (($data = fgetcsv($fp, 0, ',', '"')) !== FALSE) {
|
|
$rowReprise++;
|
|
}
|
|
|
|
} else {
|
|
$outFile = $path->data.'/export/'.$file.'-'.date('YmdHis').'.csv';
|
|
|
|
//Ecriture de l'entete du fichier
|
|
$fp = fopen($outFile, 'w');
|
|
if (count($tabEnteteF)>0){
|
|
fputcsv($fp, $tabEnteteF, ',', '"');
|
|
}
|
|
|
|
//Mise à jour des éléments
|
|
if ($opts->id) {
|
|
$commandesM->update(array(
|
|
'dateStart'=>date('Y-m-d H:i:s'),
|
|
'fichierOut' => basename($outFile)),
|
|
"id = ".$commande->id);
|
|
}
|
|
|
|
}
|
|
|
|
$row = 0;
|
|
|
|
//Vérification et création des données
|
|
foreach($tabIdentifiant as $item)
|
|
{
|
|
echo "Ligne ".($row+1)." - ";
|
|
|
|
if ( $opts->reprise && $row < $rowReprise ) {
|
|
//Reprise
|
|
$row++;
|
|
echo "Reprise";
|
|
} else {
|
|
|
|
$siretValide = false;
|
|
$sirenValide = false;
|
|
|
|
$siren = substr($item, 0, 9);
|
|
$nic = substr($item, 9);
|
|
|
|
//Simple vérification, seulement des chiffres
|
|
if (!preg_match('/[0-9]{9}/', $siren)) {
|
|
$siretValide = $sirenValide = false;
|
|
} else {
|
|
//Vérification par algorithme
|
|
$siretValide = siretValide($item);
|
|
if ($posKeySiret!==false) {
|
|
if ($siretValide===false) {
|
|
$sirenValide = sirenValide($siren);
|
|
} else {
|
|
$sirenValide = true;
|
|
}
|
|
}
|
|
|
|
if ($posKeySiren!==false && $posKeyNic!==false) {
|
|
$sirenValide = sirenValide($siren);
|
|
}
|
|
}
|
|
|
|
//On définit le tableau de retour
|
|
if ( $posKeySiret!==false ){
|
|
$tabData[$row]['siret'] = $item;
|
|
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
$tabData[$row]['siren'] = $siren;
|
|
$tabData[$row]['nic'] = $nic;
|
|
} elseif ( $posKeySiren !==false ){
|
|
$tabData[$row]['siren'] = $siren;
|
|
}
|
|
|
|
$tabData[$row]['SiretValide'] = ($siretValide===true) ? 1 : 0;
|
|
|
|
if ( $sirenValide===false || intval($siren)==0 ){
|
|
//Siren faux
|
|
} else {
|
|
|
|
//Vérifier les nic, ou sélectionner le nic du siege actif
|
|
$nicV = $nic; //Surcharge pour le nic
|
|
$strNic = '';
|
|
$sqlNic = 'SELECT nic as nicTmp, cj as cjTmp FROM jo.etablissements WHERE siren='.$siren;
|
|
|
|
//Si identifiant est un siret, char(14) alors on vérifie que le NIC existe
|
|
if (strlen($item)==14 && intval($nic)>0){
|
|
$stmt = $dbMetier->query($sqlNic.' AND nic='.$nic);
|
|
$result = $stmt->fetchAll();
|
|
if (count($result)==0){
|
|
$nicV = 0;
|
|
$fJur = '0000';
|
|
} else {
|
|
//nic : On considère qu'il est vrai si on a un résultat
|
|
$fJur = $result[0]['cjTmp'];
|
|
}
|
|
}
|
|
|
|
if (intval($nicV)==0){
|
|
$strNic = ' AND nic>-1 AND actif>-1 ORDER BY siege DESC, actif DESC, nicTmp DESC LIMIT 0,1';
|
|
$stmt = $dbMetier->query($sqlNic.$strNic);
|
|
$result = $stmt->fetchAll();
|
|
if (count($result)>0){
|
|
$nicV = $result[0]['nicTmp'];
|
|
$fJur = $result[0]['cjTmp'];
|
|
} else {
|
|
$nicV = '00000';
|
|
$fJur = '0000';
|
|
}
|
|
}
|
|
|
|
if ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
$tabData[$row]['siren'] = $siren;
|
|
$tabData[$row]['nic'] = $nic;
|
|
}
|
|
|
|
//Récupération des données
|
|
foreach($tabDico as $element => $select)
|
|
{
|
|
//Traitement par requete SQL
|
|
if (isset(${$element.'Fields'})){
|
|
$where = $select['where'];
|
|
eval( "\$where = \"$where\";" );
|
|
${$element.'SQL'} = 'SELECT '.${$element.'Fields'}.' FROM '.$select['db'].$where;
|
|
|
|
try {
|
|
$stmt = $dbMetier->query(${$element.'SQL'});
|
|
$result = $stmt->fetchAll();
|
|
if ( count($result)>0 ) {
|
|
$tabData[$row] = array_merge( $tabData[$row] , $result[0]);
|
|
}
|
|
} catch (Zend_Db_Exception $e) {
|
|
|
|
//Enregistrement du message d'erreur
|
|
if ($opts->id) {
|
|
$commandesM->update(array('error'=>$e->getMessage()), "id = ".$commande->id);
|
|
}
|
|
|
|
//Arret du script
|
|
exit;
|
|
}
|
|
|
|
}
|
|
//Traitement par fonction
|
|
if( $element == 'data' )
|
|
{
|
|
foreach($select as $item)
|
|
{
|
|
if (isset(${$item.'Data'}))
|
|
{
|
|
$values = false;
|
|
if( ${$item.'Data'}!=false ){
|
|
$values = ${$item.'Data'};
|
|
}
|
|
$retour = call_user_func($item.'Data', $siren, $nicV, $values);
|
|
$tabData[$row] = $tabData[$row] + $retour;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//Trier pour la sortie
|
|
$tabSortie = array();
|
|
foreach($tabEntete as $key){
|
|
$tabSortie[] = isset($tabData[$row][$key]) ? $tabData[$row][$key] : '';
|
|
}
|
|
fputcsv($fp, $tabSortie, ',', '"');
|
|
|
|
$row++;
|
|
echo "OK";
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
//Mise à jour des lignes traitées dans la base
|
|
if ($opts->id) {
|
|
$commandesM->update(array('nbLigneT'=>$row), "id = ".$commande->id);
|
|
}
|
|
}
|
|
fclose($fp);
|
|
if ($opts->id) {
|
|
$commandesM->update( array('dateStop' => date('Y-m-d H:i:s')) , "id = ".$commande->id);
|
|
}
|
|
|
|
|
|
/* == FUNCTION DATA == */
|
|
|
|
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();
|
|
$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);
|
|
if (count($ret)==0) {
|
|
$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);
|
|
}
|
|
$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;
|
|
$iBodacc = new MBodacc();
|
|
$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)
|
|
{
|
|
$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']='';
|
|
}
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
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)
|
|
{
|
|
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');
|
|
}
|
|
}
|
|
function bilanNData($siren, $nic, $values = false)
|
|
{
|
|
require_once 'Metier/partenaires/classMBilans.php';
|
|
$tabPostes = explode(',', $values);
|
|
$annee = 0;
|
|
$tabData = array();
|
|
$mBil = new MBilans($siren);
|
|
$tabBilans = $mBil->listeBilans(false, 9);
|
|
if (count($tabBilans)>0) {
|
|
$tabBi = findBilan($siren, $tabBilans, $annee);
|
|
$tabData['bilanNdateCloture'] = $tabBi['DATE_CLOTURE'];
|
|
$tabData['bilanNdureeMois'] = $tabBi['DUREE_MOIS'];
|
|
if (count($tabPostes)>0) {
|
|
foreach ($tabPostes as $poste) {
|
|
if (isset($tabBi[$poste])){
|
|
$tabData['bilanN'.$poste] = $tabBi[$poste];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function bilanN1Entete($values)
|
|
{
|
|
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');
|
|
}
|
|
}
|
|
function bilanN1Data($siren, $nic, $values = false)
|
|
{
|
|
require_once 'Metier/partenaires/classMBilans.php';
|
|
$tabPostes = explode(',', $values);
|
|
$annee = 1;
|
|
$tabData = array();
|
|
$mBil = new MBilans($siren);
|
|
$tabBilans = $mBil->listeBilans(false, 9);
|
|
if (count($tabBilans)>0) {
|
|
$tabBi = findBilan($siren, $tabBilans, $annee);
|
|
$tabData['bilanN1dateCloture'] = $tabBi['DATE_CLOTURE'];
|
|
$tabData['bilanN1dureeMois'] = $tabBi['DUREE_MOIS'];
|
|
if (count($tabPostes)>0) {
|
|
foreach ($tabPostes as $poste) {
|
|
if (isset($tabBi[$poste])){
|
|
$tabData['bilanN1'.$poste] = $tabBi[$poste];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function bilanN2Entete($values)
|
|
{
|
|
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');
|
|
}
|
|
}
|
|
function bilanN2Data($siren, $nic, $values = false)
|
|
{
|
|
require_once 'Metier/partenaires/classMBilans.php';
|
|
$tabPostes = explode(',', $values);
|
|
$annee = 2;
|
|
$tabData = array();
|
|
$mBil = new MBilans($siren);
|
|
$tabBilans = $mBil->listeBilans(false, 9);
|
|
if (count($tabBilans)>0) {
|
|
$tabBi = findBilan($siren, $tabBilans, $annee);
|
|
$tabData['bilanN2dateCloture'] = $tabBi['DATE_CLOTURE'];
|
|
$tabData['bilanN2dureeMois'] = $tabBi['DUREE_MOIS'];
|
|
if (count($tabPostes)>0) {
|
|
foreach ($tabPostes as $poste) {
|
|
if (isset($tabBi[$poste])){
|
|
$tabData['bilanN2'.$poste] = $tabBi[$poste];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function findBilan($siren, $tabBilans, $position = 0)
|
|
{
|
|
require_once 'Metier/partenaires/classMBilans.php';
|
|
$mBil = new MBilans($siren);
|
|
//Trier et Supprimer les bilans consolidés
|
|
$tabBilN = $tabBilS = array();
|
|
foreach ($tabBilans as $typeMil => $bilan) {
|
|
$temp = $mBil->getBilan(substr($typeMil,1), substr($typeMil,0,1));
|
|
$annee = $bilan['millesime'];
|
|
if (substr($typeMil,0,1)=='N') {
|
|
$tabBilN[$annee] = $temp;
|
|
} elseif (substr($typeMil,0,1)=='S') {
|
|
$tabBilS[$annee] = $temp;
|
|
}
|
|
}
|
|
$tabBil = $tabBilN + $tabBilS; //On comble les trous par des bilans simplifié
|
|
krsort($tabBil); // Tri décroissant
|
|
$tabBi = array();
|
|
$countBilan = 0;
|
|
foreach($tabBil as $annee => $bilan){
|
|
$tabBi = $bilan;
|
|
if ($countBilan == $position) break;
|
|
$countBilan++;
|
|
}
|
|
if ($tabBi['CONSOLIDE'] == 'S'){
|
|
$bilanT = bilanSimplifie2Normal($tabBi);
|
|
$tabBi = $tabBi + $bilanT;
|
|
}
|
|
return $tabBi;
|
|
}
|
|
|
|
|
|
function bilanSimplifie2Normal($bilanRS)
|
|
{
|
|
$tabBS2BN = array(
|
|
'AH'=>'010',
|
|
'AI'=>'012',
|
|
'AI1'=>'013',
|
|
'AJ'=>'014',
|
|
'AK'=>'016',
|
|
'AK1'=>'017',
|
|
'AT'=>'028',
|
|
'AU'=>'030',
|
|
'AU1'=>'031',
|
|
'BH'=>'040',
|
|
'BI'=>'042',
|
|
'BI1'=>'043',
|
|
'BJ'=>'044',
|
|
'BK'=>'048',
|
|
'BK1'=>'049',
|
|
'BL'=>'050',
|
|
'BM'=>'052',
|
|
'BM1'=>'053',
|
|
'BT'=>'060',
|
|
'BU'=>'062',
|
|
'BU1'=>'063',
|
|
'BV'=>'064',
|
|
'BW'=>'066',
|
|
'BW1'=>'067',
|
|
'BX'=>'068',
|
|
'BY'=>'070',
|
|
'BY1'=>'071',
|
|
'BZ'=>'072',
|
|
'CA'=>'074',
|
|
'CA1'=>'075',
|
|
'CD'=>'080',
|
|
'CE'=>'082',
|
|
'CE1'=>'083',
|
|
'CF'=>'084',
|
|
'CG'=>'086',
|
|
'CG1'=>'087',
|
|
'CH'=>'092',
|
|
'CI'=>'094',
|
|
'CI1'=>'095',
|
|
'CJ'=>'096',
|
|
'CK'=>'098',
|
|
'CK1'=>'099',
|
|
'CO'=>'110',
|
|
'1A'=>'112',
|
|
'1A1'=>'113',
|
|
'DA'=>'120',
|
|
'DC'=>'124',
|
|
'DD'=>'126',
|
|
'DF'=>'130',
|
|
'DG'=>'132',
|
|
'DH'=>'134',
|
|
'DI'=>'136',
|
|
'DK'=>'140',
|
|
'DL'=>'142',
|
|
'DR'=>'154',
|
|
'DP'=>'154',
|
|
'DU'=>'156',
|
|
'DV'=>'169',
|
|
'DW'=>'164',
|
|
'DX'=>'166',
|
|
'EA'=>'172-169',
|
|
'EB'=>'174',
|
|
'EC'=>'176',
|
|
'EE'=>'180',
|
|
'EH'=>'156-195',
|
|
'FA'=>'210-209',
|
|
'FB'=>'209',
|
|
'FC'=>'210',
|
|
'FD'=>'214-215',
|
|
'FE'=>'215',
|
|
'FF'=>'214',
|
|
'FH'=>'217',
|
|
'FI'=>'218',
|
|
'FK'=>'209+215+217',
|
|
'FL'=>'210+214+218',
|
|
'FM'=>'222',
|
|
'FN'=>'224',
|
|
'FO'=>'226',
|
|
'FQ'=>'230',
|
|
'FR'=>'232',
|
|
'FS'=>'234',
|
|
'FT'=>'236',
|
|
'FU'=>'238',
|
|
'FV'=>'240',
|
|
'FW'=>'242',
|
|
'FX'=>'244',
|
|
'FY'=>'250',
|
|
'FZ'=>'252',
|
|
'GA'=>'254',
|
|
'GE'=>'262',
|
|
'GF'=>'264',
|
|
'GG'=>'270',
|
|
'GP'=>'280',
|
|
'GU'=>'294',
|
|
'GW'=>'270+280+294',
|
|
'HD'=>'290',
|
|
'HH'=>'300',
|
|
'HI'=>'290-300',
|
|
'HK'=>'306',
|
|
'HL'=>'232+280+290',
|
|
'HM'=>'264+294+300+306',
|
|
'HN'=>'310',
|
|
'YY'=>'374',
|
|
'YZ'=>'378',
|
|
'YP'=>'376',
|
|
);
|
|
|
|
$bilanRN=array();
|
|
foreach ($tabBS2BN as $posteRN => $formule) {
|
|
if (preg_match('/\+|\-/', $formule)) {
|
|
$tabTmp=preg_split('/\+|\-/', $formule, -1, PREG_SPLIT_OFFSET_CAPTURE);
|
|
//$bilanRN[$posteRN]=0;
|
|
$scalc='';
|
|
foreach ($tabTmp as $i=>$tab) {
|
|
if ($i==0) {
|
|
$bilanRN[$posteRN]=$bilanRS[$tab[0]];
|
|
$scalc.=$bilanRS[$tab[0]];
|
|
}
|
|
else {
|
|
$signe=$formule[$tab[1]-1];
|
|
$scalc.=$signe;
|
|
if ($signe=='+') $bilanRN[$posteRN]+=$bilanRS[$tab[0]];
|
|
elseif ($signe=='-') $bilanRN[$posteRN]-=$bilanRS[$tab[0]];
|
|
$scalc.=$bilanRS[$tab[0]];
|
|
}
|
|
}
|
|
$bilanRN[$posteRN]=$bilanRN[$posteRN];
|
|
}
|
|
else $bilanRN[$posteRN]=$bilanRS[$formule];
|
|
}
|
|
if ($bilanRS['240']<>0) {
|
|
$bilanRN['BL']=$bilanRS['050'];
|
|
$bilanRN['BM']=$bilanRS['052'];
|
|
} else {
|
|
$bilanRN['BN']=$bilanRS['050'];
|
|
$bilanRN['BO']=$bilanRS['052'];
|
|
}
|
|
|
|
if ($bilanRS['070']<>0 || $bilanRS['074']<>0 || $bilanRS['052']<>0 || $bilanRS['062']<>0)
|
|
$bilanRN['GC']=$bilanRS['256'];
|
|
elseif ($bilanRS['070']==0 && $bilanRS['074']==0 && $bilanRS['052']==0 && $bilanRS['062']==0 && $bilanRS['254']<>0)
|
|
$bilanRN['GD']=$bilanRS['256'];
|
|
|
|
if ($bilanRS['584']<>0) {
|
|
$bilanRN['HB']=$bilanRS['584'];
|
|
$bilanRN['HA']=$bilanRS['290']-$bilanRS['584'];
|
|
} else
|
|
$bilanRN['HA']=$bilanRS['290'];
|
|
|
|
if ($bilanRS['582']<>0) {
|
|
$bilanRN['HF']=$bilanRS['582'];
|
|
$bilanRN['HE']=$bilanRS['582']-$bilanRS['300'];
|
|
} else
|
|
$bilanRN['HE']=$bilanRS['300'];
|
|
|
|
return $bilanRN;
|
|
}
|
|
|
|
function annoncesEntete($values)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
function annoncesData($siren, $nic, $values = false)
|
|
{
|
|
$tabData = array();
|
|
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;
|
|
}
|
|
|
|
function indiScoreEntete($values)
|
|
{
|
|
return array(
|
|
'indiScore',
|
|
'encours',
|
|
'dateBilan',
|
|
);
|
|
}
|
|
|
|
function indiScoreData($siren, $nic, $values = false)
|
|
{
|
|
$tabData = array();
|
|
$iDb = new WDB();
|
|
$ret = $iDb->select('jo.scores_surveillance', 'indiScore, encours, indiScoreDate, dateBilan, indiScorePre, encoursPre, indiScoreDatePre', 'siren='.$siren, false, MYSQL_ASSOC);
|
|
if (isset($ret[0]['indiScore'])) {
|
|
$tabData['indiScore'] = $ret[0]['indiScore'];
|
|
$tabData['encours'] = $ret[0]['encours'];
|
|
$tabData['dateBilan'] = $ret[0]['dateBilan'];
|
|
} else {
|
|
/*$iDb->insert('scores_surveillance', array('siren'=>$siren), false);
|
|
$tabData['indiScore'] = 'En cours';
|
|
$tabData['encours'] = 'En cours';
|
|
$ret = $iDb->select('jo.bilans', 'MAX(dateExercice) as dateBilan', 'siren='.$siren, false, MYSQL_ASSOC);
|
|
$tabData['dateBilan']= $ret[0]['dateBilan'];*/
|
|
$tabData['indiScore'] = 'Aucune donnée';
|
|
$tabData['encours'] = 'Aucune donnée';
|
|
$tabData['dateBilan'] = 'Aucune donnée';
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function AdresseNormaliseEntete($values)
|
|
{
|
|
return array(
|
|
'AdresseL1_NOM',
|
|
'AdresseL2_NOM2',
|
|
'AdresseL3_ADRCOMP',
|
|
'AdresseL4_VOIE',
|
|
'AdresseL5_DISTSP',
|
|
'AdresseL6_POST',
|
|
'AdresseL7_PAYS',
|
|
);
|
|
|
|
}
|
|
|
|
function AdresseNormaliseData($siren, $nic, $values = false)
|
|
{
|
|
$iInsee = new MInsee();
|
|
$output['AdresseL1_NOM'] ='';
|
|
$output['AdresseL2_NOM2'] ='';
|
|
$output['AdresseL3_ADRCOMP'] ='';
|
|
$output['AdresseL4_VOIE'] ='';
|
|
$output['AdresseL5_DISTSP'] ='';
|
|
$output['AdresseL6_POST'] ='';
|
|
$output['AdresseL7_PAYS'] ='';
|
|
$tmp = $iInsee->getAdresse($siren, $nic);
|
|
if (count($tmp)>0) {
|
|
$output['AdresseL1_NOM'] = $tmp['L1_NOM'];
|
|
$output['AdresseL2_NOM2'] = $tmp['L2_NOM2'];
|
|
$output['AdresseL3_ADRCOMP'] = $tmp['L3_ADRCOMP'];
|
|
$output['AdresseL4_VOIE'] = $tmp['L4_VOIE'];
|
|
$output['AdresseL5_DISTSP'] = $tmp['L5_DISTP'];
|
|
$output['AdresseL6_POST'] = $tmp['L6_POST'];
|
|
$output['AdresseL7_PAYS'] = $tmp['L1_PAYS'];
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
|
|
/* == FUNCTION == */
|
|
|
|
/**
|
|
* 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;
|
|
for ($cpt = 0; $cpt<strlen($siren); $cpt++) {
|
|
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)
|
|
$tmp-= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
|
|
}
|
|
else
|
|
$tmp = substr($siren, $cpt, 1);
|
|
$somme+= intval($tmp);
|
|
}
|
|
if (($somme % 10) == 0)
|
|
$estValide = true; // Si la somme est un multiple de 10 alors le SIREN est valide
|
|
else
|
|
$estValide = false;
|
|
}
|
|
return $estValide;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
for ($cpt = 0; $cpt<strlen($siret); $cpt++) {
|
|
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)
|
|
$tmp-= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
|
|
}
|
|
else
|
|
$tmp = substr($siret, $cpt, 1);
|
|
$somme+= intval($tmp);
|
|
}
|
|
if (($somme % 10) == 0)
|
|
$estValide = true; // Si la somme est un multiple de 10 alors le SIRET est valide
|
|
else
|
|
$estValide = false;
|
|
}
|
|
return $estValide;
|
|
}
|
|
|
|
/**
|
|
* writeCSV
|
|
* @param array $list
|
|
* @param array $entete
|
|
* @param string $filename
|
|
*/
|
|
function writeCSV($list, $entete, $filename)
|
|
{
|
|
$fp = fopen($filename, 'w');
|
|
if (count($entete)>0){
|
|
fputcsv($fp, $entete, ',', '"');
|
|
}
|
|
foreach ($list as $fields) {
|
|
fputcsv($fp, $fields, ',', '"');
|
|
}
|
|
fclose($fp);
|
|
}
|
|
|