2337 lines
69 KiB
PHP
2337 lines
69 KiB
PHP
<?php
|
|
// --- Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
|
|
|
|
// --- Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// --- Composer autoload
|
|
require_once realpath(__DIR__ . '/../../vendor/autoload.php');
|
|
|
|
// --- Create application, bootstrap, and run
|
|
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
|
|
|
|
$displayUsage = false;
|
|
try {
|
|
//Options
|
|
$opts = new Zend_Console_Getopt(array(
|
|
'help|?' => "Aide.",
|
|
'id=s' => "Identifiant du traitement",
|
|
'file=s' => "Traitement manuel avec spécification du fichier",
|
|
'key=s' => "Liste des clés pour l'enrichissement",
|
|
'otherid=s' => "Utilise un autre id que SIREN/SIRET",
|
|
'reprise' => "Reprendre un fichier à la ligne n-1",
|
|
'ask' => "Interaction avec l'utilisateur lors d'une reprise manuelle",
|
|
'doublon=s' => "Option dédoublonnage par fichier",
|
|
));
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
$displayUsage = true;
|
|
}
|
|
|
|
// --- Aide / Options
|
|
if (count($opts->getOptions())==0 || isset($opts->help)) {
|
|
$displayUsage = true;
|
|
}
|
|
|
|
// --- Usage
|
|
if ($displayUsage) {
|
|
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' => array(
|
|
'sql' => '',
|
|
'table' => 'SELECT code, libelle AS label FROM jo.tabFJur',
|
|
),
|
|
'capital' => '',
|
|
'capitalDev' => '',
|
|
'ape_etab' => array(
|
|
'sql' => '',
|
|
'table' => 'SELECT codNaf5 AS code, libNaf5 AS label FROM jo.tabNaf5',
|
|
),
|
|
'ape_entrep' => array(
|
|
'sql' => '',
|
|
'table' => 'SELECT codNaf5 AS code, libNaf5 AS label FROM jo.tabNaf5',
|
|
),
|
|
'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' => array(
|
|
'sql' => 'APE_ENT as nafEnInsee',
|
|
'table' => 'SELECT codNaf5 AS code, libNaf5 AS label FROM jo.tabNaf5',
|
|
),
|
|
'nafEtInsee' => 'APE_ETAB as nafEtInsee',
|
|
'APRM' => '',
|
|
'ACTIVNAT' => '',
|
|
'ORIGINE' => '',
|
|
'MODET' => '',
|
|
'EXPLET' => '',
|
|
'LIEUACT' => '',
|
|
'ACTISURF' => '',
|
|
'DEFET' => '',
|
|
'MODEN' => '',
|
|
'PRODPART' => '',
|
|
'EXPLEN' => '',
|
|
'DEFEN' => '',
|
|
'MONOREG' => '',
|
|
'REGIMP' => '',
|
|
'MONOACT' => '',
|
|
'DCREN' => '',
|
|
'SIEGE' => '',
|
|
'AUXILT' => '',
|
|
'SAISONAT' => '',
|
|
'CIVILITE' => '',
|
|
'TCA' => '',
|
|
'TCAEXP' => '',
|
|
'EFF_ENT' => '',
|
|
'DCRET' => '',
|
|
'TEFF_ENT' => '',
|
|
'ADR_DEP' => '',
|
|
'ADR_COM' => '',
|
|
'EFF_ET' => '',
|
|
'TEFF_ET' => '',
|
|
'CODEVOIE' => 'CONCAT( LEFT(CODEVOIE,4), RIGHT(CODEVOIE,1) ) AS 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' => '',
|
|
'insMMINTRET' => '',
|
|
'insMMINTREN' => '',
|
|
'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', //=> Faux getIdentite
|
|
'numRC2' => 'numRC2',
|
|
'raisonSocialeRncs' => 'raisonSociale AS raisonSocialeRncs',
|
|
'sigleRncs' => 'sigle AS sigleRncs',
|
|
'dateNaiss' => 'dateNaiss',
|
|
'lieuNaiss' => 'lieuNaiss',
|
|
'nationalite' => 'nationalite',
|
|
'pays' => 'pays',
|
|
'nafEnRncs' => 'naf AS nafEnRncs',
|
|
'cjRncs' => array(
|
|
'sql' => 'cj AS cjRncs',
|
|
'table' => 'SELECT code, libelle AS label FROM jo.tabFJur',
|
|
),
|
|
'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',
|
|
),
|
|
'contentieuxDE' => array(
|
|
'db' => 'jo.greffes_affaires_siren',
|
|
'cle' => array(
|
|
'nbContentieuxDE' => 'SUM(IF(qualite="DE",1,0)) as nbContentieuxDE',
|
|
'nbContentieuxDF' => 'SUM(IF(qualite="DF",1,0)) as nbContentieuxDF',
|
|
'topContentieuxDE' => 'IF(SUM(IF(qualite="DE",1,0))>0,1,0) as topContentieuxDE',
|
|
'topContentieuxDF' => 'IF(SUM(IF(qualite="DF",1,0))>0,1,0) as topContentieuxDF',
|
|
),
|
|
'where' => ' WHERE entSiren=$siren',
|
|
),
|
|
'data' => array(
|
|
'nicSiege',
|
|
'tva',
|
|
'dateFermetureEn',
|
|
'dateFermetureEt',
|
|
'activite',
|
|
'situationJuridique',
|
|
'indiScore',
|
|
'dirigeant',
|
|
'bilanN',
|
|
'bilanN1',
|
|
'bilanN2',
|
|
'annonces',
|
|
'AdresseNormalise',
|
|
'AdresseNormaliseInsee',
|
|
'SiretSuc',
|
|
'privilege',
|
|
'GPS',
|
|
'NaceEtab',
|
|
'NaceEnt',
|
|
'TelOrder',
|
|
'LienHead',
|
|
'LienHeadUltimate',
|
|
'ZonePrioritaire',
|
|
'AdresseDom',
|
|
'Iris',
|
|
),
|
|
'multiple' => array(
|
|
'actionnaires',
|
|
'participations',
|
|
'annoncetxt',
|
|
'groupes',
|
|
'etablissementliste',
|
|
'contentieuxliste',
|
|
'contentieuxlisteDEseuls',
|
|
'contentieuxlisteDFseuls',
|
|
),
|
|
);
|
|
|
|
$configApp = new Zend_Config($application->getOptions());
|
|
Zend_Registry::set('config', $configApp);
|
|
define('LOG_PATH', $configApp->path->data.'/log');
|
|
|
|
//Définition bdd local
|
|
try {
|
|
$db = Zend_Db::factory($configApp->resources->db);
|
|
$dbMetier = Zend_Db::factory($configApp->profil->db->metier);
|
|
Zend_Db_Table::setDefaultAdapter($dbMetier);
|
|
} catch ( Exception $e ) {
|
|
exit ( $e->getMessage() );
|
|
}
|
|
|
|
// Doctrine conn
|
|
$config = new \Doctrine\DBAL\Configuration();
|
|
$connectionParams = array(
|
|
'dbname' => $configApp->profil->db->metier->params->dbname,
|
|
'user' => $configApp->profil->db->metier->params->username,
|
|
'password' => $configApp->profil->db->metier->params->password,
|
|
'host' => $configApp->profil->db->metier->params->host,
|
|
'charset' => 'utf8',
|
|
'driver' => 'pdo_mysql',
|
|
);
|
|
|
|
try {
|
|
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
if (APPLICATION_ENV == 'development') {
|
|
echo '<pre>'; print_r($e); echo '</pre>';
|
|
} else {
|
|
echo "Le service rencontre actuellement un problème technique.";
|
|
}
|
|
exit;
|
|
}
|
|
Zend_Registry::set('doctrine', $conn);
|
|
|
|
if ($opts->id) {
|
|
$commandesM = new Application_Model_Commandes($db);
|
|
$commande = $commandesM->find(intval($opts->id))->current();
|
|
$file = basename($commande->fichier);
|
|
|
|
//Init file information
|
|
$commandesM->update(array('nbLigneT'=>0,'error'=>''), "id = ".$commande->id);
|
|
} else {
|
|
$file = $opts->file;
|
|
}
|
|
$extension = strrchr($file,'.');
|
|
$file = str_replace($extension, '', $file);
|
|
|
|
if (!file_exists($configApp->profil->path->data.'/export')) mkdir($configApp->profil->path->data.'/export');
|
|
|
|
if ($opts->id) {
|
|
$profilM = new Application_Model_Profil($db);
|
|
$profil = $profilM->find($commande->idProfil)->current();
|
|
$profilEntete = json_decode($profil->criteres, true);
|
|
|
|
$profilDoublon = null;
|
|
if ($profil->doublon!='') {
|
|
$profilDoublon = json_decode($profil->doublon, true);
|
|
}
|
|
}
|
|
else {
|
|
$profilDoublon = null;
|
|
if ($opts->doublon && $opts->doublon!='') {
|
|
$profilDoublon = explode(' ', $opts->doublon);
|
|
}
|
|
}
|
|
|
|
$tabExtract = array();
|
|
$tabEntete = array();
|
|
$tabIdentifiant = array();
|
|
$tabData = array();
|
|
|
|
$posKeySiren = $posKeySiret = $posKeyNic = $posKeySpecial = false;
|
|
|
|
//Fichier de définition
|
|
$inFile = $configApp->profil->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é spécifique
|
|
if ( $opts->otherid ) {
|
|
|
|
if ( strtolower($data[$c]) == strtolower($opts->otherid) ) {
|
|
$posKeySpecial = $c;
|
|
}
|
|
|
|
} else {
|
|
|
|
//Détection clé importante
|
|
switch(strtolower($data[$c])) {
|
|
case 'siren':
|
|
$posKeySiren = $c;
|
|
break;
|
|
case 'nic':
|
|
$posKeyNic = $c;
|
|
break;
|
|
case 'siret':
|
|
$posKeySiret = $c;
|
|
break;
|
|
case 'ref':
|
|
$posKeyRef = $c;
|
|
break;
|
|
}
|
|
|
|
}
|
|
$tabExtract[] = $data[$c];
|
|
}
|
|
|
|
if ( !$opts->otherid ) {
|
|
|
|
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 ( $opts->otherid ) {
|
|
|
|
$tabIdentifiant[] = $data[$posKeySpecial];
|
|
|
|
} else {
|
|
|
|
//Gestion des identifiants obligatoire (SIREN, NIC, SIRET)
|
|
if ( $posKeySiret!==false ){
|
|
$tabIdentifiant[] = $data[$posKeySiret];
|
|
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
$tabIdentifiant[] = $data[$posKeySiren].$data[$posKeyNic];
|
|
} elseif ( $posKeySiren !==false ){
|
|
$tabIdentifiant[] = $data[$posKeySiren];
|
|
}
|
|
|
|
}
|
|
|
|
//Gestion des autres colonnes fournies par le client
|
|
for ($c=0; $c < $num; $c++) {
|
|
$colname = $tabExtract[$c];
|
|
if (!in_array(strtolower($colname), array('siren', 'siret', 'nic'))){
|
|
$tabData[$row-1][$colname] = $data[$c];
|
|
}
|
|
}
|
|
|
|
//Création clé dédoublonnage
|
|
if (null != $profilDoublon) {
|
|
$keyDoublon = '';
|
|
foreach ($profilDoublon as $item) {
|
|
switch($item) {
|
|
case 'siret': $keyDoublon.= $data[$posKeySiret]; break;
|
|
case 'siren': $keyDoublon.= $data[$posKeySiren]; break;
|
|
case 'nic': $keyDoublon.= $data[$posKeyNic]; break;
|
|
case 'ref': $keyDoublon.= $data[$posKeyRef]; break;
|
|
}
|
|
}
|
|
$tabData[$row-1]['keyDoublon'] = $keyDoublon;
|
|
}
|
|
|
|
}
|
|
$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;
|
|
|
|
$dico = new Scores_Extract_Dict();
|
|
|
|
//Liste des champs SQL
|
|
foreach($tabExtract as $i => $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;
|
|
}
|
|
}
|
|
//Traitement pour les clé BDD
|
|
else {
|
|
//Add original key
|
|
$tabEntete[] = $key;
|
|
}
|
|
|
|
//Ajout à la requete SQL
|
|
foreach($tabDico as $element => $select) {
|
|
if ( array_key_exists('db', $select) && array_key_exists($key, $select['cle']) ) {
|
|
$elementsup = $select['cle'][$key];
|
|
if ( is_array($elementsup) && array_key_exists('table', $elementsup) ) {
|
|
//Specify supplemental head
|
|
$tabEntete[] = $key.'Lib';
|
|
//Load generic table - always return array('code', 'label')
|
|
if ( is_array($elementsup['table']) ) {
|
|
${'tab'.ucfirst($key)} = $elementsup['table'];
|
|
}
|
|
else {
|
|
$stmt = $dbMetier->query($elementsup['table']);
|
|
${'tab'.ucfirst($key)} = $stmt->fetchAll();
|
|
}
|
|
|
|
if( array_key_exists('sql', $select['cle'][$key]) && $select['cle'][$key]['sql']!='' ) {
|
|
$strKey = $select['cle'][$key]['sql'];
|
|
}
|
|
}
|
|
elseif ( $select['cle'][$key]!='' ) {
|
|
$strKey = $select['cle'][$key];
|
|
}
|
|
|
|
//If string exist add supplemental fields for the sql request
|
|
if (isset(${$element.'Fields'})) {
|
|
${$element.'Fields'}.= ', ';
|
|
}
|
|
|
|
if ($strKey!==false){
|
|
${$element.'Fields'}.= $strKey;
|
|
}
|
|
else {
|
|
${$element.'Fields'}.= $key;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
if ( in_array($element, array('data', 'multiple')) && in_array($key, $select) ) {
|
|
${$key.'Data'} = $values;
|
|
if ( $values ) {
|
|
$tabExtract[$i] = $key;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Ajout colonne obligatoire
|
|
$tabEntete[] = 'nicSiege';
|
|
${'nicSiegeData'} = '';
|
|
$tabEntete[] = 'SiretValide';
|
|
if( null != $profilDoublon ) {
|
|
$tabEntete[] = 'Doublon';
|
|
}
|
|
//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 = $configApp->profil->path->data.'/export/'.$commande->fichierOut;
|
|
$rowReprise = 0;
|
|
$fp = fopen($outFile, 'r+');
|
|
if ($fp === false) {
|
|
echo "Impossible d'ouvrir $outFile";
|
|
exit(1);
|
|
}
|
|
while (($data = fgetcsv($fp, 0, ',', '"')) !== FALSE) {
|
|
$rowReprise++;
|
|
}
|
|
|
|
} else {
|
|
$outFile = $configApp->profil->path->data.'/export/'.$file.'-'.date('YmdHis').'.csv';
|
|
//Ecriture de l'entete du fichier
|
|
$fp = fopen($outFile, 'w');
|
|
if ($fp === false) {
|
|
echo "Impossible d'ouvrir $outFile";
|
|
exit(1);
|
|
}
|
|
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;
|
|
$doublonList = array();
|
|
$iDb = new Metier_Util_Db();
|
|
|
|
//Vérification et création des données
|
|
foreach($tabIdentifiant as $item)
|
|
{
|
|
$extendNbRow = 0;
|
|
$tabNewData = array();
|
|
|
|
echo "Ligne ".($row+1)." - ";
|
|
|
|
if ( $opts->reprise && $row < $rowReprise ) {
|
|
|
|
//Reprise
|
|
$row++;
|
|
echo "Reprise";
|
|
|
|
} else {
|
|
|
|
if ( $opts->otherid ) {
|
|
|
|
$id = $item;
|
|
$tabNewData[$extendNbRow] = $tabData[$row];
|
|
|
|
//Récupération des données SQL
|
|
foreach($tabDico as $element => $select)
|
|
{
|
|
//Retour lignes multiples
|
|
if ( $element == 'multiple' )
|
|
{
|
|
$values = false;
|
|
$isSelected = false;
|
|
foreach($select as $selectItem){
|
|
if ( in_array($selectItem, $tabExtract) ) {
|
|
$isSelected = true;
|
|
break;
|
|
}
|
|
}
|
|
$retour = array();
|
|
if ( $isSelected && function_exists($selectItem.'Multiple') ) {
|
|
if( ${$selectItem.'Data'}!=false ){
|
|
$values = ${$selectItem.'Data'};
|
|
}
|
|
$retour = call_user_func($selectItem.'MultipleById', $id, $values);
|
|
}
|
|
if (count($retour)>0) {
|
|
$originalLine = $tabNewData[$extendNbRow];
|
|
foreach($retour as $i => $retourItem) {
|
|
$tabNewData[$extendNbRow+$i] = array_merge($originalLine,$retourItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$siretValide = null;
|
|
$sirenValide = null;
|
|
$nicValide = null;
|
|
|
|
$siren = substr($item, 0, 9);
|
|
$nic = substr($item, 9);
|
|
|
|
//Simple vérification SIREN, seulement des chiffres
|
|
if ( !preg_match('/[0-9]{9}/', $siren) ) {
|
|
$sirenValide = false;
|
|
}
|
|
|
|
//Simple vérification NIC, seulement des chiffres
|
|
if ( $nic!='' && !preg_match('/[0-9]{5}/', $nic) ) {
|
|
$nicValide = false;
|
|
} else {
|
|
$nicValide = true;
|
|
}
|
|
|
|
//Vérification algorithme
|
|
if ( $sirenValide!==false && $nicValide!==false ) {
|
|
|
|
$siretValide = siretValide($item);
|
|
if ($posKeySiret!==false) {
|
|
if ($siretValide===false) {
|
|
$sirenValide = sirenValide($siren);
|
|
} else {
|
|
$sirenValide = true;
|
|
}
|
|
}
|
|
|
|
if ($posKeySiren!==false && $posKeyNic!==false) {
|
|
$sirenValide = sirenValide($siren);
|
|
}
|
|
|
|
}
|
|
|
|
$tabNewData[$extendNbRow] = $tabData[$row];
|
|
|
|
//On définit le tableau de retour (les colonnes du fichier client sont déjà présentent)
|
|
if ( $posKeySiret!==false ){
|
|
$tabNewData[$extendNbRow]['siret'] = (string) $item;
|
|
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
$tabNewData[$extendNbRow]['siren'] = (string) $siren;
|
|
$tabNewData[$extendNbRow]['nic'] = (string) $nic;
|
|
} elseif ( $posKeySiren !==false ){
|
|
$tabNewData[$extendNbRow]['siren'] = (string) $siren;
|
|
}
|
|
|
|
$tabNewData[$extendNbRow]['SiretValide'] = ($siretValide===true) ? 1 : 0;
|
|
|
|
//Clé de doublon
|
|
$keyDoublon = null;
|
|
if ( array_key_exists('keyDoublon', $tabData[$row])) {
|
|
$keyDoublon = $tabData[$row]['keyDoublon'];
|
|
}
|
|
|
|
if ( null !== $keyDoublon && in_array($keyDoublon, $doublonList) ) {
|
|
$tabNewData[$extendNbRow]['doublon'] = 1;
|
|
} elseif ( $sirenValide===false || intval($siren)==0 ){
|
|
//Siren faux
|
|
} elseif ( $nicValide===false ){
|
|
$tabNewData[$extendNbRow]['SiretValide'] = "NIC source invalide";
|
|
} else {
|
|
|
|
//Vérifier les nic, ou sélectionner le nic du siege actif
|
|
$nicV = $nic; //Surcharge pour le nic
|
|
$strNic = '';
|
|
$sqlNic = 'SELECT LPAD(nic,5,0) AS nicTmp, cj AS cjTmp, IF(siege=1,1,0) AS triSiege 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 triSiege 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 ){
|
|
$tabNewData[$extendNbRow]['siren'] = $siren;
|
|
$tabNewData[$extendNbRow]['nic'] = $nic;
|
|
}
|
|
|
|
//Récupération des données SQL
|
|
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 ) {
|
|
$tabNewData[$extendNbRow] = array_merge( $tabNewData[$extendNbRow] , $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 $selectItem)
|
|
{
|
|
if ( isset(${$selectItem.'Data'}) )
|
|
{
|
|
$values = false;
|
|
if( ${$selectItem.'Data'}!=false ){
|
|
$values = ${$selectItem.'Data'};
|
|
}
|
|
$retour = call_user_func($selectItem.'Data', $siren, $nicV, $values);
|
|
$tabNewData[$extendNbRow] = $tabNewData[$extendNbRow] + $retour;
|
|
}
|
|
}
|
|
}
|
|
|
|
//Retour lignes multiples
|
|
elseif ( $element == 'multiple' )
|
|
{
|
|
$values = false;
|
|
$isSelected = false;
|
|
foreach($select as $selectItem){
|
|
if ( in_array($selectItem, $tabExtract) ) {
|
|
$isSelected = true;
|
|
break;
|
|
}
|
|
}
|
|
$retour = array();
|
|
if ( $isSelected && function_exists($selectItem.'Multiple') ) {
|
|
if( ${$selectItem.'Data'}!=false ){
|
|
$values = ${$selectItem.'Data'};
|
|
}
|
|
$retour = call_user_func($selectItem.'Multiple', $siren, $nicV, $values);
|
|
}
|
|
if (count($retour)>0) {
|
|
$originalLine = $tabNewData[$extendNbRow];
|
|
foreach($retour as $i => $retourItem) {
|
|
$tabNewData[$extendNbRow+$i] = array_merge($originalLine,$retourItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Traitement des libellés génériques
|
|
else
|
|
{
|
|
foreach($select['cle'] as $cle => $values)
|
|
{
|
|
if ( in_array($cle.'Lib', $tabEntete) && isset(${'tab'.ucfirst($cle)}) )
|
|
{
|
|
$retour[$cle.'Lib'] = 'Non trouvé';
|
|
$codeFromData = $tabNewData[$extendNbRow][$cle];
|
|
foreach( ${'tab'.ucfirst($cle)} as $cleItem ) {
|
|
if ( $codeFromData == $cleItem['code'] ) {
|
|
$retour[$cle.'Lib'] = $cleItem['label'];
|
|
break;
|
|
}
|
|
}
|
|
$tabNewData[$extendNbRow] = $tabNewData[$extendNbRow] + $retour;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Enregistrement clés de doublon pour rappel
|
|
if ( null !== $keyDoublon ) {
|
|
$doublonList[] = $keyDoublon;
|
|
}
|
|
|
|
}
|
|
|
|
//Trier pour la sortie
|
|
$nbLines = count($tabNewData);
|
|
for($i=0;$i<$nbLines;$i++) {
|
|
$tabSortie = array();
|
|
foreach($tabEntete as $key){
|
|
$tabSortie[] = isset($tabNewData[$i][$key]) ? $tabNewData[$i][$key] : '';
|
|
}
|
|
fputcsv($fp, $tabSortie, ',', '"');
|
|
}
|
|
|
|
$extendNbRow++;
|
|
$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)
|
|
{
|
|
$iTva = new Metier_Partenaires_MTva();
|
|
$iTva->setCompanyId($siren);
|
|
$iTva->getTVA();
|
|
$tabData['tva'] = isset($iTva->vatNumber) ? $iTva->vatNumber : '';
|
|
return $tabData;
|
|
}
|
|
|
|
function dateFermetureEtEntete($values)
|
|
{
|
|
return array(
|
|
'dateFermetureEt',
|
|
'codeFermetureEt',
|
|
);
|
|
}
|
|
|
|
function dateFermetureEtData($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$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)
|
|
{
|
|
global $iDb;
|
|
$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 Metier_Bodacc_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)
|
|
{
|
|
global $iDb;
|
|
$tabTmp = array('P','D','R','A');
|
|
$tabData['situationJuridique'] = 'NC';
|
|
$tabData['situationParution'] = '';
|
|
$tabData['situationDernCode'] = '';
|
|
$tabData['situationDernEven'] = '';
|
|
foreach ($tabTmp as $sit) {
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
$tmp = $iInsee->getAnnoncesLegales($siren, 0, $sit);
|
|
if (count($tmp) > 0) {
|
|
$tmp=$tmp[0];
|
|
$tabData['situationJuridique'] = $sit;
|
|
$tabData['situationParution'] = $tmp['DateParution'];
|
|
$tabData['situationDernCode'] = $tmp['evenements'][0]['CodeEven'];
|
|
$tabData['situationDernEven'] = preg_replace('/ +/', ' ',
|
|
strtr($tmp['evenements'][0]['LibEven'],array("\r"=>' ',"\n"=>' ',"\t"=>' ',','=>' ',';'=>' ','"'=>' ',"'"=>' ')));
|
|
break;
|
|
}
|
|
}
|
|
if (in_array($tabData['situationJuridique'], array('NC','R'))) {
|
|
$rep = $iDb->select('rncs_entrep', 'actif, dateRad', "siren='".$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)
|
|
{
|
|
global $iDb;
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
$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)
|
|
{
|
|
$tabPostes = explode(',', $values);
|
|
$annee = 0;
|
|
$tabData = array();
|
|
$mBil = new Metier_Partenaires_MBilans();
|
|
$mBil->setSiren($siren);
|
|
/*
|
|
* @todo : Pouvoir appeler la liste des bilans en fonction du TYPE, sans les chiffres
|
|
* jo.bilans => Liste mais postes dans chaine de caractère
|
|
* jo.bilans_postes => Liste + postes directement
|
|
*/
|
|
$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)
|
|
{
|
|
$tabPostes = explode(',', $values);
|
|
$annee = 1;
|
|
$tabData = array();
|
|
$mBil = new Metier_Partenaires_MBilans();
|
|
$mBil->setSiren($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)
|
|
{
|
|
global $iDb;
|
|
$tabPostes = explode(',', $values);
|
|
$annee = 2;
|
|
$tabData = array();
|
|
$mBil = new Metier_Partenaires_MBilans();
|
|
$mBil->setSiren($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)
|
|
{
|
|
$mBil = new Metier_Partenaires_MBilans();
|
|
$mBil->setSiren($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 = $mBil->bilanSimplifie2Normal($tabBi);
|
|
$tabBi = $tabBi + $bilanT;
|
|
}
|
|
return $tabBi;
|
|
}
|
|
|
|
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)
|
|
{
|
|
global $iDb;
|
|
$tabData = array();
|
|
if ($values!==false) {
|
|
$tabDeja = array();
|
|
$tabTmp = explode(',', $values);
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
$iInsee->AnnoncesLegalesVisu = true;
|
|
$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',
|
|
'indiScoreDate',
|
|
'encours',
|
|
'dateBilan',
|
|
);
|
|
}
|
|
|
|
function indiScoreData($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$tabData = array();
|
|
$ret = $iDb->select('jo.scores_surveillance', 'indiScore, encours, indiScoreDate, dateBilan', 'siren='.$siren, false, MYSQL_ASSOC);
|
|
if (isset($ret[0]['indiScore'])) {
|
|
$tabData['indiScore'] = $ret[0]['indiScore'];
|
|
$tabData['indiScoreDate'] = $ret[0]['indiScoreDate'];
|
|
$tabData['encours'] = $ret[0]['encours'];
|
|
$tabData['dateBilan'] = $ret[0]['dateBilan'];
|
|
} else {
|
|
$tabData['indiScore'] = 'Aucune donnée';
|
|
$tabData['indiScoreDate'] = 'Aucune donnée';
|
|
$tabData['encours'] = 'Aucune donnée';
|
|
$tabData['dateBilan'] = 'Aucune donnée';
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function AdresseNormaliseEntete($values)
|
|
{
|
|
return array(
|
|
'L1',
|
|
'L2',
|
|
'L3',
|
|
'L4',
|
|
'L5',
|
|
'L6',
|
|
'L7',
|
|
'ProcessCode',
|
|
'ProcessLabel',
|
|
'ProcessDate',
|
|
'QualityCode',
|
|
'QualityLabel',
|
|
'DateInsert',
|
|
'DateUpdate',
|
|
);
|
|
}
|
|
|
|
function AdresseNormaliseData($siren, $nic, $values = false)
|
|
{
|
|
$output = array();
|
|
$head = AdresseNormaliseEntete('');
|
|
foreach($head as $item) {
|
|
$output[$item] = '';
|
|
}
|
|
|
|
try {
|
|
$etabM = new Application_Model_JoEtablissements();
|
|
$sql = $etabM->select(true)->columns(array('LPAD(source,3,0) AS source', 'LPAD(source_id,20,0) AS sourceId'))
|
|
->where('siren=?', $siren)
|
|
->where('nic=?', $nic);
|
|
$etabResult = $etabM->fetchRow($sql);
|
|
$source = $etabResult->source;
|
|
$sourceId = $etabResult->source_id;
|
|
} catch (Zend_Db_Exception $e) {}
|
|
|
|
$infoRNVP = null;
|
|
|
|
try {
|
|
$rnvp = new Metier_Rnvp_Adresse();
|
|
$rnvp->setCompanyId($source . $sourceId);
|
|
$infoRNVP = $rnvp->format();
|
|
} catch (Exception $e) {}
|
|
|
|
if ($infoRNVP !== null) {
|
|
foreach ($head as $item) {
|
|
$output[$item] = $infoRNVP->{$item};
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
function AdresseNormaliseInseeEntete($values)
|
|
{
|
|
return array(
|
|
'AdresseL1_NOM',
|
|
'AdresseL2_NOM2',
|
|
'AdresseL3_ADRCOMP',
|
|
'AdresseL4_VOIE',
|
|
'AdresseL5_DISTSP',
|
|
'AdresseL6_POST',
|
|
'AdresseL7_PAYS',
|
|
);
|
|
}
|
|
|
|
function AdresseNormaliseInseeData($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
$output['L1_NOM'] ='';
|
|
$output['L2_NOM2'] ='';
|
|
$output['L3_ADRCOMP'] ='';
|
|
$output['L4_VOIE'] ='';
|
|
$output['L5_DISTSP'] ='';
|
|
$output['L6_POST'] ='';
|
|
$output['L7_PAYS'] ='';
|
|
$tmp = $iInsee->getAdresse($siren, $nic, 0);
|
|
if (count($tmp)>0) {
|
|
$output['L1_NOM'] = $tmp['L1_NOM'];
|
|
$output['L2_NOM2'] = $tmp['L2_NOM2'];
|
|
$output['L3_ADRCOMP'] = $tmp['L3_ADRCOMP'];
|
|
$output['L4_VOIE'] = $tmp['L4_VOIE'];
|
|
$output['L5_DISTSP'] = $tmp['L5_DISTSP'];
|
|
$output['L6_POST'] = $tmp['L6_POST'];
|
|
$output['L7_PAYS'] = $tmp['L1_PAYS'];
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
function SiretSucEntete($values)
|
|
{
|
|
return array(
|
|
'SiretSuc',
|
|
'SiretSucNbDem',
|
|
'SiretSucSiege',
|
|
'SiretSucActif',
|
|
'SiretSucCodeEve',
|
|
'SiretSucDateEve',
|
|
'SiretSucOrigine',
|
|
);
|
|
}
|
|
|
|
function SiretSucData($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
|
|
//Init
|
|
$tabData = array();
|
|
$nouveauSiret = '';
|
|
$nbDem = 0;
|
|
$codeEve = '';
|
|
$dateEve = '';
|
|
$origine = '';
|
|
$siege = '';
|
|
|
|
$strIdentite = "SIREN,NIC,ACTIF AS sdActif";
|
|
|
|
// First item
|
|
$ret = $iDb->select('insee.identite', $strIdentite, "SIREN=$siren AND NIC=$nic", false);
|
|
if ( count($ret)>0 ) {
|
|
|
|
$tmp = $ret[0];
|
|
$actif = intval($tmp['sdActif']);
|
|
|
|
$tabAncienSiret = array();
|
|
|
|
while ($actif==0) {
|
|
// Recherche du nouveau siret
|
|
$tabAssoc = $iInsee->getSiretAssoc($siren, $nic);
|
|
if ( array_key_exists('suc', $tabAssoc) && count($tabAssoc['suc'])>0 )
|
|
{
|
|
$nouveauSiret = trim(''.$tabAssoc['suc']['siren'].$tabAssoc['suc']['nic']);
|
|
$tabAncienSiret[$nouveauSiret]++;
|
|
|
|
if ( $nouveauSiret!='' && $tabAncienSiret[''.$siren.$nic]<=2 )
|
|
{
|
|
$nbDem++; //Nombre de déménagement
|
|
$siren = substr($nouveauSiret,0,9);
|
|
$nic = substr($nouveauSiret,9,5);
|
|
$ret = $iDb->select('insee.identite', $strIdentite, "SIREN=$siren AND NIC=$nic", false);
|
|
$tmp = $ret[0];
|
|
|
|
$actif = intval($tmp['sdActif']);
|
|
$codeEve = $tabAssoc['suc']['codeEve'];
|
|
$dateEve = $tabAssoc['suc']['dateEve'];
|
|
$origine = $tabAssoc['suc']['origine'];
|
|
$siege = $tabAssoc['suc']['siege'];
|
|
|
|
} else {
|
|
break;
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
$tabData['SiretSuc'] = $nouveauSiret;
|
|
$tabData['SiretSucNbDem'] = $nbDem;
|
|
$tabData['SiretSucSiege'] = $siege;
|
|
$tabData['SiretSucActif'] = $actif;
|
|
$tabData['SiretSucCodeEve'] = $codeEve;
|
|
$tabData['SiretSucDateEve'] = $dateEve;
|
|
$tabData['SiretSucOrigine'] = $origine;
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function privilegeEntete($values)
|
|
{
|
|
return array(
|
|
'privilege',
|
|
);
|
|
}
|
|
|
|
function privilegeData($siren, $nic, $values = false)
|
|
{
|
|
$return = 'Non';
|
|
//Présence de privilèges
|
|
$nbPrivileges = 0;
|
|
$iPriv = new Metier_Partenaires_MPrivileges();
|
|
$ret = $iPriv->getPrivilegesDetail($siren);
|
|
$nbPrivileges = count($ret);
|
|
if ($nbPrivileges>0) {
|
|
$return = 'Oui';
|
|
} else {
|
|
$iDb = new Metier_Util_Db();
|
|
$sql = "SELECT count(*) AS nbPriv FROM ge_cs2 WHERE cs = 'P' AND dateFin >= NOW() AND dateSuppr=0 AND siren='$siren';";
|
|
$ret = $iDb->query($sql);
|
|
if (count($ret) > 0) {
|
|
if ($ret[0]['nbPriv']>0) {
|
|
$return = 'Oui';
|
|
}
|
|
}
|
|
}
|
|
$tabData['privilege'] = $return;
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function GPSEntete($values)
|
|
{
|
|
return array(
|
|
'latitude',
|
|
'longitude',
|
|
'altitude',
|
|
'precis',
|
|
);
|
|
}
|
|
|
|
function GPSData($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$tabData['latitude'] = '';
|
|
$tabData['longitude'] = '';
|
|
$tabData['altitude'] = '';
|
|
$tabData['precis'] = '';
|
|
|
|
$result = $iDb->select(
|
|
'etablissements e',
|
|
"LPAD(e.adr_num,4,0) AS adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville",
|
|
"siren=$siren AND nic=$nic", false, MYSQL_ASSOC);
|
|
if (count($result)>0) {
|
|
$MInsee = new Metier_Insee_MInsee($iDb);
|
|
$etab = $result[0];
|
|
$mMap=new Metier_Partenaires_MMap();
|
|
$mMap->geoCodeAdresse(
|
|
$etab['adr_num']
|
|
,'',
|
|
$etab['adr_typeVoie'],
|
|
$MInsee->getCodeVoie($etab['adr_typeVoie']),
|
|
$etab['adr_libVoie'],
|
|
$etab['adr_cp'],
|
|
$etab['adr_ville'],
|
|
'France'
|
|
);
|
|
$tabData['latitude'] = $mMap->latitudeDec;
|
|
$tabData['longitude'] = $mMap->longitudeDec;
|
|
$tabData['altitude'] = $mMap->altitude;
|
|
$tabData['precis'] = $mMap->precision;
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function NaceEtabEntete($values)
|
|
{
|
|
return array(
|
|
'NaceEtab',
|
|
'NaceEtabLib',
|
|
);
|
|
}
|
|
function NaceEtabData($siren, $nic, $values)
|
|
{
|
|
global $iDb;
|
|
$tabData = array(
|
|
'NaceEtab' => '',
|
|
'NaceEtabLib' => '',
|
|
);
|
|
$result = $iDb->select('jo.etablissements e, jo.tabNaf5 n, insee.tabNace i',
|
|
"CONCAT(n.codNaf1, SUBSTRING(n.codNaf5,1,4)) AS codNace, i.libelleFR",
|
|
"siren=$siren AND nic=$nic AND n.codNaf5=e.ape_etab AND i.codNace=SUBSTRING(n.codNaf5,1,4)", false, MYSQL_ASSOC);
|
|
if (count($result)>0) {
|
|
$tabData['NaceEtab'] = $result[0]['codNace'];
|
|
$tabData['NaceEtabLib'] = $result[0]['libelleFR'];
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function NaceEntEntete()
|
|
{
|
|
return array(
|
|
'NaceEn',
|
|
'NaceEnLib',
|
|
);
|
|
}
|
|
function NaceEntData($siren, $nic, $values)
|
|
{
|
|
global $iDb;
|
|
$tabData = array(
|
|
'NaceEn' => '',
|
|
'NaceEnLib' => '',
|
|
);
|
|
$result = $iDb->select('jo.etablissements e, jo.tabNaf5 n, insee.tabNace i',
|
|
"CONCAT(n.codNaf1, SUBSTRING(n.codNaf5,1,4)) AS codNace, i.libelleFR",
|
|
"siren=$siren AND nic=$nic AND n.codNaf5=e.ape_entrep AND i.codNace=SUBSTRING(n.codNaf5,1,4)", false, MYSQL_ASSOC);
|
|
if (count($result)>0) {
|
|
$tabData['NaceEn'] = $result[0]['codNace'];
|
|
$tabData['NaceEnLib'] = $result[0]['libelleFR'];
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function TelOrderEntete()
|
|
{
|
|
return array(
|
|
'TelOrderTypeTel',
|
|
'TelOrderInfoTel',
|
|
'TelOrderTelephone',
|
|
'TelOrderSource',
|
|
'TelOrderDate',
|
|
);
|
|
}
|
|
function TelOrderData($siren, $nic, $values)
|
|
{
|
|
global $iDb;
|
|
$c = new Metier_Partenaires_MTel();
|
|
$result = $c->getTel($siren, $nic, true, 1);
|
|
$tabData = array();
|
|
if ( count($result)>0 ) {
|
|
foreach ($result as $p) {
|
|
if ($p['typeTel']=='tel') {
|
|
$tabData = array(
|
|
'TelOrderTypeTel' => $p['typeTel'],
|
|
'TelOrderInfoTel' => $p['infoTel'],
|
|
'TelOrderTelephone' => $p['telephone'],
|
|
'TelOrderSource' => $p['source'],
|
|
'TelOrderDate' => $p['dateMAJ'],
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function LienHeadEntete()
|
|
{
|
|
return array(
|
|
'HeadId',
|
|
'HeadSiren',
|
|
'HeadIsin',
|
|
'HeadPpPm',
|
|
'HeadRS',
|
|
'HeadPays',
|
|
);
|
|
}
|
|
|
|
function LienHeadData($siren, $nic, $values)
|
|
{
|
|
$c = new Metier_Liens_Base();
|
|
$c->setId($siren, 'siren');
|
|
$c->stopAtFirstIsin = true;
|
|
$id = $c->getHead();
|
|
$result = $c->getIdentity($id);
|
|
$tabData = array();
|
|
if ( $result ) {
|
|
$tabData = array(
|
|
'HeadId' => $result->id,
|
|
'HeadSiren' => $result->siren,
|
|
'HeadIsin' => $result->isin,
|
|
'HeadPpPm' => $result->PpPm,
|
|
'HeadRS' => $result->RS,
|
|
'HeadPays' => $result->adresse_pays
|
|
);
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function LienHeadUltimateEntete()
|
|
{
|
|
return array(
|
|
'HeadId',
|
|
'HeadSiren',
|
|
'HeadIsin',
|
|
'HeadPpPm',
|
|
'HeadRS',
|
|
'HeadPays',
|
|
'HeadCivilite',
|
|
'HeadNom',
|
|
'HeadPrenom',
|
|
'HeadNomUsage',
|
|
'HeadNaissanceDate',
|
|
'HeadNaissanceDeptPays',
|
|
'HeadNaissanceLieu',
|
|
);
|
|
}
|
|
|
|
function LienHeadUltimateData($siren, $nic, $values)
|
|
{
|
|
$c = new Metier_Liens_Base();
|
|
$c->setId($siren, 'siren');
|
|
$c->stopAtPP = false;
|
|
$id = $c->getHead();
|
|
$result = $c->getIdentity($id);
|
|
$tabData = array();
|
|
if ( $result ) {
|
|
$tabData = array(
|
|
'HeadId' => $result->id,
|
|
'HeadSiren' => $result->siren,
|
|
'HeadIsin' => $result->isin,
|
|
'HeadPpPm' => $result->PpPm,
|
|
'HeadRS' => $result->RS,
|
|
'HeadPays' => $result->adresse_pays,
|
|
'HeadCivilite' => $result->civilite,
|
|
'HeadNom' => $result->nom,
|
|
'HeadPrenom' => $result->prenom,
|
|
'HeadNomUsage' => $result->nom_usage,
|
|
'HeadNaissanceDate' => $result->naissance_date,
|
|
'HeadNaissanceDeptPays' => $result->naissance_dept_pays,
|
|
'HeadNaissanceLieu' => $result->naissance_lieu,
|
|
);
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function ZonePrioritaireEntete() {
|
|
return array(
|
|
'ZUS',
|
|
'NZUS',
|
|
'ZRU',
|
|
'NZRU',
|
|
'ZFU',
|
|
'NZFU',
|
|
'CUCS',
|
|
'NCUCS',
|
|
'ZRR',
|
|
'NZRR',
|
|
'ZAFR',
|
|
'NZAFR',
|
|
);
|
|
}
|
|
function ZonePrioritaireData($siren, $nic, $value) {
|
|
global $iDb;
|
|
$tabData = array();
|
|
$result = $iDb->select(
|
|
'jo.etablissements e, insee.identite i',
|
|
"LPAD(e.adr_num,4,0) AS adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp,
|
|
LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville, i.ADR_DEP, LPAD(i.ADR_COM,3,0) AS ADR_COM, i.CODEVOIE",
|
|
"i.SIREN=e.siren AND i.NIC=e.nic AND e.siren=$siren AND e.nic=$nic", false, MYSQL_ASSOC);
|
|
if (count($result) > 0) {
|
|
$r = $result[0];
|
|
$iAmabis = new Metier_Partenaires_MAmabis();
|
|
$tabData = $iAmabis->getZonage($r['adr_num'], $r['adr_btq'], $r['adr_typeVoie'], $r['adr_libVoie'],
|
|
$r['adr_cp'], $r['adr_ville'], trim($r['ADR_DEP'].$r['ADR_COM'].$r['CODEVOIE']),
|
|
false, 'TEST', false);
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function AdresseDomEntete() {
|
|
return array(
|
|
'AdresseDomNb',
|
|
);
|
|
}
|
|
function AdresseDomData($siren, $nic, $value) {
|
|
global $iDb;
|
|
$tabData = array();
|
|
$result = $iDb->select(
|
|
'jo.etablissements e, insee.identite i',
|
|
"LPAD(e.adr_num,4,0) AS adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp,
|
|
LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville, i.ADR_DEP, LPAD(i.ADR_COM,3,0) AS ADR_COM, i.CODEVOIE",
|
|
"i.SIREN=e.siren AND i.NIC=e.nic AND e.siren=$siren AND e.nic=$nic", false, MYSQL_ASSOC);
|
|
if (count($result) > 0) {
|
|
$r = $result[0];
|
|
$c = new Metier_Insee_MInsee($iDb);
|
|
$dom = $c->infoAdresseDom($r['adr_num'], $r['adr_btq'], $r['adr_typeVoie'], $r['adr_libVoie'],
|
|
trim(preg_replace('/ +/', ' ', $r['adr_comp'])), $r['adr_cp'], $r['adr_ville']);
|
|
$tabData['AdresseDomNb'] = $dom[0]['nbEntrep'];
|
|
}
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function IrisEntete() {
|
|
return array(
|
|
'codIris',
|
|
'codComIris',
|
|
'libIris',
|
|
'typIris',
|
|
'evoIris',
|
|
'trIris',
|
|
'grdQuartier',
|
|
'rivoli',
|
|
);
|
|
}
|
|
function IrisData($siren, $nic, $values) {
|
|
global $iDb;
|
|
$tabData = array();
|
|
$result = $iDb->select(
|
|
'jo.etablissements e, insee.identite i',
|
|
"LPAD(e.adr_num,4,0) AS adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp,
|
|
LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville, i.ADR_DEP, LPAD(i.ADR_COM,3,0) AS ADR_COM, i.CODEVOIE",
|
|
"i.SIREN=e.siren AND i.NIC=e.nic AND e.siren=$siren AND e.nic=$nic", false, MYSQL_ASSOC);
|
|
if (count($result) > 0) {
|
|
$r = $result[0];
|
|
$c = new Metier_Insee_MInsee($iDb);
|
|
$tabData = $c->getInfosIris($r['ADR_DEP'].$r['ADR_COM'],substr($r['CODEVOIE'],0,4),
|
|
$r['adr_num'], $r['adr_btq'], $r['adr_typeVoie'], $r['adr_libVoie']);
|
|
}
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function actionnairesEntete()
|
|
{
|
|
return array(
|
|
'ActSiren',
|
|
'ActActif',
|
|
'ActPDetention',
|
|
'ActPVote',
|
|
'ActType',
|
|
'ActRS',
|
|
'ActPP',
|
|
'ActPPDateNaiss',
|
|
'ActPPLieuNaiss',
|
|
'ActPPNat',
|
|
'ActAdresseNum',
|
|
'ActAdresseBTQ',
|
|
'ActAdresseCodeVoie',
|
|
'ActAdresseLibVoie',
|
|
'ActAdresseCompl',
|
|
'ActAdresseCP',
|
|
'ActAdresseVille',
|
|
'ActAdressePays',
|
|
'ActIdLoc1Type',
|
|
'ActIdLoc1Num',
|
|
'ActIdLoc2Type',
|
|
'ActIdLoc2Num',
|
|
'ActIdLoc3Type',
|
|
'ActIdLoc3Num',
|
|
'ActDateEffetLien',
|
|
'ActDate'
|
|
);
|
|
}
|
|
|
|
function actionnairesMultiple($siren, $nic)
|
|
{
|
|
$liensM = new Metier_Liens_Base();
|
|
$liensM->setId($siren, 'siren');
|
|
$result = $liensM->getActionnaires(null, true);
|
|
$tabData = array();
|
|
if (count($result)>0) {
|
|
foreach($result as $item) {
|
|
$formatElement = array();
|
|
$formatElement['ActSiren'] = $item->siren;
|
|
$formatElement['ActActif'] = $item->actif;
|
|
$formatElement['ActPDetention'] = $item->PDetention;
|
|
$formatElement['ActPVote'] = $item->Pvote;
|
|
$formatElement['ActType'] = $item->PpPm;
|
|
$formatElement['ActRS'] = $item->RS;
|
|
if ($item->PpPm == 'PP') {
|
|
$formatElement['ActPP'] = $item->civilite.' '.
|
|
$item->nom.' '.$item->prenom.
|
|
' ('.$item->nom_usage.') ';
|
|
$formatElement['ActPPDateNaiss'] = $item->naissance_date;
|
|
$formatElement['ActPPLieuNaiss'] = $item->naissance_lieu;
|
|
$formatElement['ActPPNat'] = $item->nat;
|
|
} else {
|
|
$formatElement['ActPP'] = '';
|
|
$formatElement['ActPPDateNaiss'] = '';
|
|
$formatElement['ActPPLieuNaiss'] = '';
|
|
$formatElement['ActPPNat'] = '';
|
|
}
|
|
$formatElement['ActAdresseNum'] = $item->adresse_num;
|
|
$formatElement['ActAdresseBTQ'] = $item->adresse_btq;
|
|
$formatElement['ActAdresseCodeVoie'] = $item->adresse_codvoie;
|
|
$formatElement['ActAdresseLibVoie'] = $item->adresse_libvoie;
|
|
$formatElement['ActAdresseCompl'] = $item->adresse_comp;
|
|
$formatElement['ActAdresseCP'] = $item->adresse_cp;
|
|
$formatElement['ActAdresseVille'] = $item->adresse_ville;
|
|
$formatElement['ActAdressePays'] = $item->adresse_pays;
|
|
$formatElement['ActIdLoc1Type'] = $item->idLoc1Type;
|
|
$formatElement['ActIdLoc1Num'] = $item->idLoc1Num;
|
|
$formatElement['ActIdLoc2Type'] = $item->idLoc2Type;
|
|
$formatElement['ActIdLoc2Num'] = $item->idLoc2Num;
|
|
$formatElement['ActIdLoc3Type'] = $item->idLoc3Type;
|
|
$formatElement['ActIdLoc3Num'] = $item->idLoc3Num;
|
|
$formatElement['ActDateEffetLien'] = $item->dateEffetLien;
|
|
if ($item->dateUpdate!='0000-00-00 00:00:00') {
|
|
$formatElement['ActDate'] = substr($item->dateUpdate,0,10);
|
|
} else {
|
|
$formatElement['ActDate'] = substr($item->dateInsert,0,10);
|
|
}
|
|
|
|
$tabData[] = $formatElement;
|
|
}
|
|
}
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function participationsEntete()
|
|
{
|
|
return array(
|
|
'ParSiren',
|
|
'ParActif',
|
|
'ParPDetention',
|
|
'ParPVote',
|
|
'ParType',
|
|
'ParRS',
|
|
'ParPP',
|
|
'ParPPDateNaiss',
|
|
'ParPPLieuNaiss',
|
|
'ParPPNat',
|
|
'ParAdresseNum',
|
|
'ParAdresseBTQ',
|
|
'ParAdresseCodeVoie',
|
|
'ParAdresseLibVoie',
|
|
'ParAdresseCompl',
|
|
'ParAdresseCP',
|
|
'ParAdresseVille',
|
|
'ParAdressePays',
|
|
'ParIdLoc1Type',
|
|
'ParIdLoc1Num',
|
|
'ParIdLoc2Type',
|
|
'ParIdLoc2Num',
|
|
'ParIdLoc3Type',
|
|
'ParIdLoc3Num',
|
|
'ParDateEffetLien',
|
|
'ParDate'
|
|
);
|
|
}
|
|
|
|
function participationsMultiple($siren, $nic)
|
|
{
|
|
$liensM = new Metier_Liens_Base();
|
|
$liensM->setId($siren, 'siren');
|
|
$result = $liensM->getParticipations(null,true);
|
|
$tabData = array();
|
|
if (count($result)>0) {
|
|
foreach($result as $item) {
|
|
$formatElement = array();
|
|
$formatElement['ParSiren'] = $item->siren;
|
|
$formatElement['ParActif'] = $item->actif;
|
|
$formatElement['ParPDetention'] = $item->PDetention;
|
|
$formatElement['ParPvote'] = $item->Pvote;
|
|
$formatElement['ParType'] = $item->PpPm;
|
|
$formatElement['ParRS'] = $item->RS;
|
|
if ($item->PpPm == 'PP') {
|
|
$formatElement['ParPP'] = $item->civilite.' '.
|
|
$item->nom.' '.$item->prenom.
|
|
' ('.$item->nom_usage.') '.
|
|
$formatElement['ParPPDateNaiss'] = $item->naissance_date;
|
|
$formatElement['ParPPLieuNaiss'] = $item->naissance_lieu;
|
|
$formatElement['ParPPNat'] = $item->nat;
|
|
} else {
|
|
$formatElement['ParPP'] = '';
|
|
$formatElement['ParPPDateNaiss'] = '';
|
|
$formatElement['ParPPLieuNaiss'] = '';
|
|
$formatElement['ParPPNat'] = '';
|
|
}
|
|
$formatElement['ParAdresseNum'] = $item->adresse_num;
|
|
$formatElement['ParAdresseBTQ'] = $item->adresse_btq;
|
|
$formatElement['ParAdresseCodeVoie'] = $item->adresse_codvoie;
|
|
$formatElement['ParAdresseLibVoie'] = $item->adresse_libvoie;
|
|
$formatElement['ParAdresseCompl'] = $item->adresse_comp;
|
|
$formatElement['ParAdresseCP'] = $item->adresse_cp;
|
|
$formatElement['ParAdresseVille'] = $item->adresse_ville;
|
|
$formatElement['ParAdressePays'] = $item->adresse_pays;
|
|
$formatElement['ParIdLoc1Type'] = $item->idLoc1Type;
|
|
$formatElement['ParIdLoc1Num'] = $item->idLoc1Num;
|
|
$formatElement['ParIdLoc2Type'] = $item->idLoc2Type;
|
|
$formatElement['ParIdLoc2Num'] = $item->idLoc2Num;
|
|
$formatElement['ParIdLoc3Type'] = $item->idLoc3Type;
|
|
$formatElement['ParIdLoc3Num'] = $item->idLoc3Num;
|
|
$formatElement['ParDateEffetLien'] = $item->dateEffetLien;
|
|
if ($item->dateUpdate!='0000-00-00 00:00:00') {
|
|
$formatElement['ParDate'] = substr($item->dateUpdate,0,10);
|
|
} else {
|
|
$formatElement['ParDate'] = substr($item->dateInsert,0,10);
|
|
}
|
|
|
|
$tabData[] = $formatElement;
|
|
}
|
|
}
|
|
|
|
return $tabData;
|
|
}
|
|
|
|
function annoncetxtEntete()
|
|
{
|
|
return array(
|
|
'AnnonceLib',
|
|
'AnnonceDate',
|
|
'AnnonceDateParution',
|
|
'AnnonceTxt',
|
|
);
|
|
}
|
|
function annoncetxtMultiple($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$tabData = array();
|
|
$tabTmp = '';
|
|
if ( !empty($values)) {
|
|
$tabTmp = explode(',', $values);
|
|
}
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
$iInsee->AnnoncesLegalesVisu = true;
|
|
$response = $iInsee->getAnnoncesLegales($siren, 0, $tabTmp, false, true);
|
|
foreach ($response as $tabAnn){
|
|
foreach ($tabAnn['evenements'] as $codEve) {
|
|
$dateEven = $tabAnn['dateJugement'];
|
|
if ($dateEven=='0000-00-00') $dateEven=$tabAnn['dateEffet'];
|
|
if ($dateEven=='0000-00-00') $dateEven=$tabAnn['DateParution'];
|
|
|
|
$formatElement['AnnonceLib'] = strtr($codEve['LibEven'],array(','=>' ',"'"=>' ','"'=>' ',';'=>' '));
|
|
$formatElement['AnnonceDate'] = $dateEven;
|
|
$formatElement['AnnonceDateParution'] = $tabAnn['DateParution'];
|
|
$formatElement['AnnonceTxt'] = $tabAnn['texteAnnonce'];
|
|
|
|
$tabData[] = $formatElement;
|
|
}
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function groupesEntete()
|
|
{
|
|
return array(
|
|
'Niveau',
|
|
'LienSiren',
|
|
'LienNom',
|
|
'LienPays',
|
|
'LienPmin',
|
|
);
|
|
}
|
|
function groupesMultiple($siren, $nic, $values = false)
|
|
{
|
|
$tabData = array();
|
|
$c = new Metier_Liens_Base();
|
|
$c->setId($siren, 'siren');
|
|
$identity = $c->getIdentity();
|
|
|
|
$level = 0;
|
|
$tabData[] = array(
|
|
'Niveau' => 'N'.$level,
|
|
'LienSiren' => $identity->siren,
|
|
'LienNom' => $identity->RS,
|
|
'LienPays' => $identity->adresse_pays,
|
|
'LienPmin' => '',
|
|
);
|
|
|
|
$level = $level+1;
|
|
$result = $c->getTreeRecursive($identity->id, 33, $level, 6);
|
|
foreach ($result as $item) {
|
|
$tabData[] = array(
|
|
'Niveau' => 'N'.$level,
|
|
'LienSiren' => $item['siren'],
|
|
'LienNom' => $item['name'],
|
|
'LienPays' => $item['pays'],
|
|
'LienPmin' => $item['pmin'],
|
|
);
|
|
$children = array();
|
|
if ( count($item['children'])>0 ) {
|
|
$children = groupesChildren($item['children'], $level+1);
|
|
}
|
|
$tabData = array_merge($tabData, $children);
|
|
}
|
|
return $tabData;
|
|
}
|
|
function groupesMultipleById($id, $values = false)
|
|
{
|
|
$tabData = array();
|
|
|
|
$c = new Metier_Liens_Base();
|
|
$c->setId($id, 'ref');
|
|
$identity = $c->getIdentity();
|
|
|
|
$level = 0;
|
|
$tabData[] = array(
|
|
'Niveau' => 'N'.$level,
|
|
'LienSiren' => $identity->siren,
|
|
'LienNom' => $identity->RS,
|
|
'LienPays' => $identity->adresse_pays,
|
|
'LienPmin' => '',
|
|
);
|
|
|
|
$level = $level+1;
|
|
$result = $c->getTreeRecursive($identity->id, 33, $level, 6);
|
|
foreach ($result as $item) {
|
|
$tabData[] = array(
|
|
'Niveau' => 'N'.$level,
|
|
'LienSiren' => $item['siren'],
|
|
'LienNom' => $item['name'],
|
|
'LienPays' => $item['pays'],
|
|
'LienPmin' => $item['pmin'],
|
|
);
|
|
$children = array();
|
|
if ( count($item['children'])>0 ) {
|
|
$children = groupesChildren($item['children'], $level+1);
|
|
}
|
|
$tabData = array_merge($tabData, $children);
|
|
}
|
|
return $tabData;
|
|
}
|
|
function groupesChildren($tab, $level)
|
|
{
|
|
$result = array();
|
|
if ( count($tab)>0 ) {
|
|
$head = array();
|
|
foreach($tab as $k => $item) {
|
|
$head[] = array(
|
|
'Niveau' => 'N'.$level,
|
|
'LienSiren' => $item['siren'],
|
|
'LienNom' => $item['name'],
|
|
'LienPays' => $item['pays'],
|
|
'LienPmin' => $item['pmin'],
|
|
);
|
|
$result = array_merge($result, $head);
|
|
$children = array();
|
|
if ( count($item['children'])>0 ) {
|
|
$children = groupesChildren($item['children'], $level+1);
|
|
}
|
|
$result = array_merge($result, $children);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
function etablissementlisteEntete()
|
|
{
|
|
return array(
|
|
'etabSIRET',
|
|
'etabSIEGE',
|
|
'etabACTIF',
|
|
);
|
|
}
|
|
function etablissementlisteMultiple($siren, $nic, $values = false)
|
|
{
|
|
global $iDb;
|
|
$mInsee = new Metier_Insee_MInsee($iDb);
|
|
$result = $mInsee->getEtablissements($siren);
|
|
$tabData = array();
|
|
if (count($result['reponses']) > 0) {
|
|
foreach ($result['reponses'] as $r) {
|
|
$tabData[] = array(
|
|
'etabSIRET' => $r['Siret'],
|
|
'etabSIEGE' => $r['Siege'],
|
|
'etabACTIF' => $r['Actif'],
|
|
);
|
|
}
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
function contentieuxlisteDEseulsEntete($values)
|
|
{
|
|
return contentieuxlisteEntete($values);
|
|
}
|
|
|
|
function contentieuxlisteDFseulsEntete($values)
|
|
{
|
|
return contentieuxlisteEntete($values);
|
|
}
|
|
|
|
function contentieuxlisteEntete($values)
|
|
{
|
|
if ($values!==false) {
|
|
$values = explode(',', $values);
|
|
$tmp = array();
|
|
foreach($values as $value){
|
|
$tmp[] = $value;
|
|
}
|
|
if(in_array('historique',$tmp)){
|
|
$tmp[]='dateDecision';
|
|
$tmp[]='libelleDecision';
|
|
}
|
|
return $tmp;
|
|
} else {
|
|
return array(
|
|
'idAffaire',
|
|
);
|
|
}
|
|
}
|
|
function contentieuxlisteDEseulsMultiple($siren, $nic=0, $values = false)
|
|
{
|
|
$qualite=' AND s.qualite="DE"';
|
|
return contentieuxlisteMultiple($siren, $nic, $values,$qualite);
|
|
}
|
|
function contentieuxlisteDFseulsMultiple($siren, $nic=0, $values = false)
|
|
{
|
|
$qualite=' AND s.qualite="DF"';
|
|
return contentieuxlisteMultiple($siren, $nic, $values,$qualite);
|
|
}
|
|
function contentieuxlisteMultiple($siren, $nic=0, $values = false,$qualite='')
|
|
{
|
|
global $iDb;
|
|
$histojoin='';
|
|
$fields=array(
|
|
'IdAffaire' => 'a.idAffaire as IdAffaire',
|
|
'Tiers' => 's.qualite as Tiers',
|
|
'StatusCode' => 'etatAffaire as StatusCode',
|
|
'StatusLabel' => 'etatAffaire as StatusLabel',
|
|
'CategoryCode' => 'codNatureDemande as CategoryCode',
|
|
'CategoryLabel' => 'codNatureDemande as CategoryLabel',
|
|
'Label' => 'natureDemande as Label',
|
|
'DateAffaire' => 'dateEnrolement as DateAffaire',
|
|
'NomPartie' => 's.nomPartie as NomPartie',
|
|
'NomDemandeur' => 'nomDemandeur as NomDemandeur',
|
|
'NomDefendeur' => 'nomDefendeur as NomDefendeur',
|
|
'CodeGreffe' => 'codeGreffe as CodeGreffe',
|
|
'NomGreffe' => 'nomGreffe as NomGreffe',
|
|
'Representants' => 'representants as Representants',
|
|
'NomsRepresentants' => 'rep0nom as NomsRepresentants',
|
|
'Parties' => 'a.parties as Parties',
|
|
'CategorieAffaire' => 'typeAffaireEnum as CategorieAffaire',
|
|
'Historique' => 'h.numLigneHisto as Historique',
|
|
'DateDecision' => 'h.dateDecision as DateDecision',
|
|
'LibelleDecision' => 'h.libelleDecision as LibelleDecision'
|
|
);
|
|
if(!$values){
|
|
$tabFields=array(
|
|
'IdAffaire' => 'a.idAffaire as IdAffaire',
|
|
);
|
|
}else{
|
|
$tabFields = explode(',', $values);
|
|
}
|
|
if(in_array('Historique',$tabFields)){
|
|
$histojoin=' left join greffes_affaires_histo h on h.idAffaire=a.idAffaire ';
|
|
$tabFields[]='DateDecision';
|
|
$tabFields[]='LibelleDecision';
|
|
}
|
|
|
|
foreach($tabFields as $field){
|
|
if(isset($fields[$field])){
|
|
$tabSelect[]=$fields[$field];
|
|
}else{
|
|
throw new Exception(__METHOD__ . ': ' . $field . ' does not exist');
|
|
return;
|
|
}
|
|
}
|
|
$select = implode(',',$tabSelect);
|
|
$conn = Zend_Registry::get('doctrine');
|
|
$sql='select '.$select .'
|
|
from (greffes_affaires_siren s inner join greffes_affaires a using(id)) '.$histojoin.' where
|
|
entSiren=:siren'.$qualite;
|
|
/*$sql='select dateEnrolement as dateAffaire,typeAffaireEnum as categorieAffaire,codNatureDemande as typeAffaire,natureDemande,nomDemandeur,
|
|
nomDefendeur,etatAffaire as statutAffaire,codeGreffe,nomGreffe,representants,rep0nom as nomsRepresentants
|
|
from greffes_affaires_siren s inner join greffes_affaires a using(id) where entSiren=:siren';*/
|
|
try {
|
|
$stmt=$conn->prepare($sql);
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->execute();
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
throw new Exception(__METHOD__ . ': ' . $e->getMessage());
|
|
}
|
|
$tabData=$stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
//if(false){
|
|
if(in_array('StatusLabel',$tabFields) || in_array('CategoryLabel',$tabFields)){
|
|
$status = include APPLICATION_PATH . '/../library/Metier/Ctx/AffaireStatus.php';
|
|
$categories = include APPLICATION_PATH . '/../library/Metier/Table/AffairesTypes.php';
|
|
foreach($tabData as $k => $row){
|
|
if(isset($row['StatusLabel']) && isset($status[$row['StatusLabel']])){$tabData[$k]['StatusLabel']=$status[$row['StatusLabel']];}
|
|
if(isset($row['CategoryLabel']) && isset($categories[$row['CategoryLabel']])){$tabData[$k]['CategoryLabel']=$categories[$row['CategoryLabel']];}
|
|
}
|
|
}
|
|
if(in_array('Parties',$tabFields) || in_array('Representants',$tabFields)){
|
|
foreach($tabData as $k => $row){
|
|
if(isset($row['Parties']) && !empty($row['Parties'])){
|
|
$text='';
|
|
$parties=json_decode($row['Parties']);
|
|
foreach($parties as $p){
|
|
$text.=(isset($p->nomPartie)?$p->nomPartie:'').' ('.(isset($p->entreprise->siren)?$p->entreprise->siren:'').') ';
|
|
if(isset($p->representants) && !empty($p->representants)){
|
|
foreach ($p->representants as $r){
|
|
$text.=' '.isset($r->nom)?' # '.$r->nom:'';
|
|
}
|
|
}
|
|
$text.=' | ';
|
|
}
|
|
//echo $tabData[$k]['parties'];echo $text;
|
|
$tabData[$k]['Parties']=$text;
|
|
}
|
|
if(isset($row['Representants']) && !empty($row['Representants'])){
|
|
$parties=(array)json_decode($row['Representants']);
|
|
if(is_array($parties)){
|
|
foreach($parties as $p){
|
|
$text=isset($p->nom)?$p->nom.' - ':'';
|
|
}}else{
|
|
$text=isset($parties['nom'])?$parties['nom']:$row['Representants'];
|
|
}
|
|
$tabData[$k]['Representants']=$text;
|
|
}
|
|
}
|
|
}
|
|
return $tabData;
|
|
}
|
|
|
|
/* == 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);
|
|
}
|
|
|