6699 lines
290 KiB
PHP
6699 lines
290 KiB
PHP
|
<?php
|
||
|
global $timer;
|
||
|
|
||
|
class Metier_Insee_MInsee extends Metier_Insee_Table
|
||
|
{
|
||
|
/**
|
||
|
* Désactive les calculs pour ne faire que de la visualisation
|
||
|
* @var boolean
|
||
|
*/
|
||
|
public $AnnoncesLegalesVisu = false;
|
||
|
|
||
|
/**
|
||
|
* Debug mode
|
||
|
* @var boolean
|
||
|
*/
|
||
|
public $debug = false;
|
||
|
|
||
|
/**
|
||
|
* Log time execution of request
|
||
|
* @var boolean
|
||
|
*/
|
||
|
protected $debugtime = false;
|
||
|
|
||
|
/**
|
||
|
* Date de fin de recherche des événements AAAAMMJJ
|
||
|
* Envoyer cette date à toutes les méthodes
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $companyEvenDateStop = null;
|
||
|
|
||
|
/**
|
||
|
* Date de début/jugement/publication du plan SSAAMMJJ
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $debutPlan;
|
||
|
|
||
|
/**
|
||
|
* Durée du plan en mois
|
||
|
* @var int
|
||
|
*/
|
||
|
protected $dureePlan;
|
||
|
|
||
|
/**
|
||
|
* Date de fin du plan SSAAMMJJ
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $finPlan;
|
||
|
|
||
|
/**
|
||
|
* Présence d'un appel de jugement
|
||
|
*/
|
||
|
protected $appelJugement = false;
|
||
|
|
||
|
/**
|
||
|
* Liste des événements associés
|
||
|
* @var array
|
||
|
*/
|
||
|
protected $tabAssocId = null;
|
||
|
|
||
|
protected $tabCodesNaf = array();
|
||
|
protected $tabCodesNafa = array();
|
||
|
protected $tabCodesNace = array();
|
||
|
|
||
|
protected $body = '';
|
||
|
protected $codeRetour = 0;
|
||
|
protected $header = array();
|
||
|
|
||
|
protected $iDb;
|
||
|
protected $iBodacc;
|
||
|
|
||
|
protected $AnnoncesPosition = 0;
|
||
|
protected $AnnoncesNb = 20;
|
||
|
|
||
|
protected $SituationCloture = false;
|
||
|
|
||
|
protected $Identite;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
public function __construct($db = null)
|
||
|
{
|
||
|
if ( $db === null ) {
|
||
|
$this->iDb = new WDB();
|
||
|
} else {
|
||
|
$this->iDb = $db;
|
||
|
}
|
||
|
|
||
|
$this->iBodacc = new Metier_Bodacc_MBodacc($this->iDb);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Défini une date limite de prise en compte des événements
|
||
|
* @param string $date AAAAMMJJ
|
||
|
*/
|
||
|
public function setEvenLimit($date)
|
||
|
{
|
||
|
$this->companyEvenDateStop = $date;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test de la validité du siren demandé
|
||
|
* @param int SIREN à tester
|
||
|
* @param int NIC (facultatif)
|
||
|
* @param mixed Message textuel d'erreur à afficher en cas d'erreur ou false
|
||
|
* @return mixed true, false ou Message d'erreur passé en paramètre
|
||
|
*/
|
||
|
public function valideSiren($siren, $nic='', $erreur=false)
|
||
|
{
|
||
|
$siren = str_pad($siren, 9, '0', STR_PAD_LEFT);
|
||
|
if (!empty($nic)) {
|
||
|
$nic = str_pad($nic, 5, '0', STR_PAD_LEFT);
|
||
|
}
|
||
|
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect.
|
||
|
return $erreur;
|
||
|
elseif ($siren*1==0) // Siren vide
|
||
|
return $erreur;
|
||
|
else
|
||
|
{
|
||
|
if (!isset($nic) || trim($nic)=='')
|
||
|
{
|
||
|
$somme=0;
|
||
|
for ($i=0; $i<=8; $i+=2) // Traitement IMPAIR
|
||
|
$somme+=(integer)substr($siren,$i,1);
|
||
|
|
||
|
for ($i=1; $i<=7; $i+=2)
|
||
|
{ // Traitement PAIR
|
||
|
$var_tmp=(string)(2*((integer)substr($siren,$i,1)));
|
||
|
$som_tmp=0;
|
||
|
for($j=0;$j<strlen($var_tmp);$j++)
|
||
|
$som_tmp+=(integer)substr($var_tmp,$j,1);
|
||
|
$somme+=$som_tmp;
|
||
|
}
|
||
|
|
||
|
if ((integer)($somme/10)!=($somme/10))
|
||
|
{ // Le Siren est faux
|
||
|
if (substr($siren,0,3)!='200') // Les siren débutant par 200 sont toujours valides (sirens provisoires de la BDF?!)
|
||
|
return $erreur;
|
||
|
}
|
||
|
} else {
|
||
|
if (!Metier_Util_String::valideData($nic,1,5,'N')) // Nic de format incorrect.
|
||
|
return $erreur;
|
||
|
|
||
|
$SIRET=$siren.$nic;
|
||
|
if ($siren<>356000000) {
|
||
|
$somme=0;
|
||
|
for ($i=0; $i<=12; $i+=2)
|
||
|
{ // Traitement PAIR
|
||
|
$var_tmp=(string)(2*((integer)substr($SIRET,$i,1)));
|
||
|
$som_tmp=0;
|
||
|
for($j=0;$j<strlen($var_tmp);$j++)
|
||
|
$som_tmp+=(integer)substr($var_tmp,$j,1);
|
||
|
$somme+=$som_tmp;
|
||
|
}
|
||
|
for ($i=1; $i<=13; $i+=2) // Traitement IMPAIR
|
||
|
$somme+=(integer)substr($SIRET,$i,1);
|
||
|
|
||
|
if ((integer)($somme/10)!=($somme/10))// Le Siret est faux
|
||
|
return $erreur;
|
||
|
} else {
|
||
|
// Cas particulier du siren de LA POSTE : 356 000 000 00000
|
||
|
$somme=14;
|
||
|
for ($i=9; $i<=13; $i++)
|
||
|
$somme+=(integer)substr($SIRET,$i,1);
|
||
|
if ($somme%5!=0) // Le NIC de l'établissement de LA POSTE est faux !
|
||
|
return $erreur;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test de la validité du siren demandé
|
||
|
* @param int $siren
|
||
|
* SIREN à tester
|
||
|
* @param int $numEtab
|
||
|
* N° d'établissement dont ont fdoit calculer le NIC
|
||
|
* @return int
|
||
|
*/
|
||
|
public function getNic($siren, $numEtab=1)
|
||
|
{
|
||
|
if (!$this->valideSiren($siren))
|
||
|
return -1;
|
||
|
elseif (!Metier_Util_String::valideData($numEtab,1,4,'N')) // Nic de format incorrect.
|
||
|
return -1;
|
||
|
else {
|
||
|
for ($cle=0; $cle<10; $cle++) {
|
||
|
if ($this->valideSiren($siren, ''.$nic.''.$cle))
|
||
|
return $cle;
|
||
|
}
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Vérifie si le n° de département est un département français valide
|
||
|
* @param int Numéro de département Français
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function isDepartement($dept)
|
||
|
{
|
||
|
return array_key_exists($dept, self::$tabDep);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne le libellé du département si département français valide
|
||
|
* @param int Numéro de département Français
|
||
|
* @return string Libellé département
|
||
|
*/
|
||
|
public function getDepartement($dept, $article=false)
|
||
|
{
|
||
|
if ($article)
|
||
|
return self::$tabDepArt[$dept];
|
||
|
|
||
|
return self::$tabDep[$dept];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Effectif moyen
|
||
|
* @param string $trancheEffectif
|
||
|
* @return number
|
||
|
*/
|
||
|
public function getEffectifMoyen($trancheEffectif)
|
||
|
{
|
||
|
$trancheEffectif=$trancheEffectif*1;
|
||
|
if ($trancheEffectif==0) return 0;
|
||
|
elseif ($trancheEffectif==53) return 10000;
|
||
|
else {
|
||
|
$libEffectif=self::$tabEffectif[$trancheEffectif];
|
||
|
$tabTmp=explode('à', $libEffectif);
|
||
|
$eff_min=trim(str_replace(' ','', $tabTmp[0]));
|
||
|
$tabTmp=explode('salari', $tabTmp[1]);
|
||
|
$eff_max=trim(str_replace(' ','', $tabTmp[0]));
|
||
|
return floor(($eff_min+$eff_max)/2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne le code forme juridique d'une entreprise.
|
||
|
* @param int Numéro de SIREN (9 chiffres) ou SIRET (14 chiffres)
|
||
|
* @return string Forme Juridique sur 4 caractères ou <b>false</b>en cas d'erreur ou si inexistant
|
||
|
*/
|
||
|
public function getFJInsee($siren_siret)
|
||
|
{
|
||
|
$len=strlen($siren_siret);
|
||
|
if ($len==9)
|
||
|
$siren=$siren_siret;
|
||
|
elseif ($len==14)
|
||
|
$siren=$siren_siret;
|
||
|
else
|
||
|
return false;
|
||
|
$rep=$this->iDb->select('insee.identite', 'CJ', "SIREN='$siren'");
|
||
|
return $rep[0][0];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Recherche Etablissements
|
||
|
*
|
||
|
* @param string $raisonSociale
|
||
|
* @param string $adresse
|
||
|
* @param string $codePostal
|
||
|
* @param string $ville
|
||
|
* @param string $siege
|
||
|
* @param int $actif
|
||
|
* @param int $deb
|
||
|
* @param int $nbRep
|
||
|
* @param int $maxRep
|
||
|
* @param string $pertinence
|
||
|
* @param bool $uniquementAvecSiren
|
||
|
* @param string $ape_etab
|
||
|
* @param int $fj
|
||
|
* @return array
|
||
|
*/
|
||
|
public function rechercheEtab($raisonSociale, $adresse='', $codePostal='', $ville='', $siege='', $actif=2, $deb=0, $nbRep=20, $maxRep=200, $pertinence=false, $uniquementAvecSiren='', $ape_etab='', $fj=null)
|
||
|
{
|
||
|
$tabAdr = $this->structureVoie(strtoupper($adresse));
|
||
|
$numAdresse = preg_replace('/^0+/','',''.$tabAdr['num']*1);
|
||
|
$adresse = trimAccent($tabAdr['libVoie']);
|
||
|
$formR = array(
|
||
|
'type' => 'ent',
|
||
|
'siret' => '',
|
||
|
'raisonSociale' => $raisonSociale,
|
||
|
'numVoie' => $numAdresse,
|
||
|
'voie' => $adresse,
|
||
|
'cpVille' => $codePostal.' '.$ville,
|
||
|
'actif' => $actif,
|
||
|
'siege' => $siege,
|
||
|
'fj' => $fj,
|
||
|
);
|
||
|
if ($ape_etab<>'') $formR['naf']=$ape_etab;
|
||
|
|
||
|
require_once 'Metier/sphinx/rechercheFonc.php';
|
||
|
if ($uniquementAvecSiren=='')
|
||
|
$result = rechercheEnt($formR, $deb, $nbRep, $maxRep);
|
||
|
else
|
||
|
$result = rechercheEnt($formR, $deb, $nbRep, $maxRep, $uniquementAvecSiren);
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Recherche dirigeant
|
||
|
* @param string $nom
|
||
|
* @param string $prenom
|
||
|
* @param string $fonction
|
||
|
* @param string $dateNaiss
|
||
|
* @param string $villeNaiss
|
||
|
* @param number $deb
|
||
|
* @param integer $nbRep
|
||
|
* @param integer $maxRep
|
||
|
* @param string $pertinence
|
||
|
* @return array
|
||
|
*/
|
||
|
public function rechercheDir($nom, $prenom='', $fonction='', $dateNaiss='', $villeNaiss='', $deb=0, $nbRep=20, $maxRep=200, $pertinence=false)
|
||
|
{
|
||
|
Metier_Util_Log::write('I',"rechercheDir de $nom, $prenom, $fonction, $dateNaiss, $villeNaiss (Max Rep=$nbRep)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||
|
$jour=$mois=$annee='';
|
||
|
if ($dateNaiss<>'' && $dateNaiss<>'//' && $dateNaiss<>'0/0/0') {
|
||
|
$tabDateNaiss=explode('/', $dateNaiss);
|
||
|
|
||
|
$jour=$tabDateNaiss[0]*1;
|
||
|
if ($jour<1 || $jour>31) $jour='';
|
||
|
|
||
|
$mois =$tabDateNaiss[1]*1;
|
||
|
if ($mois<1 || $mois>12) $mois='';
|
||
|
|
||
|
$annee=$tabDateNaiss[2]*1;
|
||
|
if ($annee>0 && $annee<100) $annee=('19'.$annee)*1;
|
||
|
if ($annee<1800 || $annee>date('Y')*1) $annee='';
|
||
|
}
|
||
|
$formR = array(
|
||
|
'type' => 'dir',
|
||
|
'nom' => $nom,
|
||
|
'prenom' => $prenom,
|
||
|
'dirDateNaissAAAA' => $annee,
|
||
|
'dirDateNaissMM' => $mois,
|
||
|
'dirDateNaissJJ' => $jour,
|
||
|
// 'departement' => 'D',
|
||
|
'cpVille' => $villeNaiss,
|
||
|
);
|
||
|
|
||
|
$version = defined('SPHINX_DIR_VERSION') ? SPHINX_DIR_VERSION : 1;
|
||
|
$result = array();
|
||
|
require_once 'Metier/sphinx/rechercheFonc.php';
|
||
|
$result = rechercheDir($formR, $deb, $nbRep, $maxRep);
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Vérifie si le code voie est une abréviation autorisée (selon la Norme AFNOR XP Z 10-011)
|
||
|
* @param string $codeVoie
|
||
|
* @return boolean
|
||
|
*/
|
||
|
public function isCodeVoie($codeVoie)
|
||
|
{
|
||
|
return array_key_exists($codeVoie, $this->tabCodeVoie);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne le libellé du code voie selon les abréviations autorisées pour les types de voie (Norme AFNOR XP Z 10-011)
|
||
|
* @param string Code voie
|
||
|
* @return string Libellé de la voie
|
||
|
*/
|
||
|
public function getCodeVoie($codeVoie)
|
||
|
{
|
||
|
return $this->tabCodeVoie[$codeVoie];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Initialise la table des codes NAF 4 et 5 positions
|
||
|
*/
|
||
|
protected function setTabCodesNaf()
|
||
|
{
|
||
|
if (count($this->tabCodesNaf)==0) {
|
||
|
$cacheNaf = dirname(__FILE__) . '/../Table/CodesNaf.php';
|
||
|
$cacheNace = dirname(__FILE__) . '/../Table/CodesNace.php';
|
||
|
if ( file_exists($cacheNaf) ) {
|
||
|
$this->tabCodesNaf = include $cacheNaf;
|
||
|
$this->tabCodesNace = include $cacheNace;
|
||
|
} else {
|
||
|
$tabNafs = $tabNace = array();
|
||
|
$tabTmp = $this->iDb->select('jo.tabNaf4', 'codNaf700 AS naf, libNaf700 AS LibNaf', 1, false, MYSQL_ASSOC);
|
||
|
foreach ($tabTmp as $i=>$tabNaf) {
|
||
|
$tabNafs[$tabNaf['naf']]=$tabNaf['LibNaf'];
|
||
|
}
|
||
|
|
||
|
$tabTmp = $this->iDb->select('jo.tabNaf5', 'codNaf5 AS naf, libNaf5 AS LibNaf, codNaf1', 1, false, MYSQL_ASSOC);
|
||
|
foreach ($tabTmp as $i=>$tabNaf) {
|
||
|
$tabNafs[$tabNaf['naf']]=$tabNaf['LibNaf'];
|
||
|
$tabNace[$tabNaf['naf']]=$tabNaf['codNaf1'].preg_replace('/^0/','',substr($tabNaf['naf'],0,4));
|
||
|
}
|
||
|
$this->tabCodesNaf = $tabNafs;
|
||
|
$this->tabCodesNace = $tabNace;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param unknown $code_naf
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getLibelleNaf($code_naf)
|
||
|
{
|
||
|
if ($code_naf == '')
|
||
|
return '';
|
||
|
|
||
|
$this->setTabCodesNaf();
|
||
|
return $this->tabCodesNaf[$code_naf];
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @return multitype:
|
||
|
*/
|
||
|
public function getCodesNaf()
|
||
|
{
|
||
|
$this->setTabCodesNaf();
|
||
|
return array_keys($this->tabCodesNaf);
|
||
|
}
|
||
|
|
||
|
/** Initialise la table des codes NAFA rev 2
|
||
|
**/
|
||
|
protected function setTabCodesNafa()
|
||
|
{
|
||
|
if (count($this->tabCodesNafa)==0) {
|
||
|
$cache = dirname(__FILE__) . '/../Table/CodesNafa.php';
|
||
|
if ( file_exists($cache) ) {
|
||
|
$this->tabCodesNafa = include $cache;
|
||
|
} else {
|
||
|
$tabNafs = array();
|
||
|
$tabTmp = $this->iDb->select('jo.tabNafa', 'codNafa AS nafa, libNafa', 1, true, MYSQL_ASSOC);
|
||
|
foreach ($tabTmp as $i=>$tabNaf) {
|
||
|
$tabNafs[$tabNaf['nafa']] = $tabNaf['libNafa'];
|
||
|
}
|
||
|
$this->tabCodesNafa = $tabNafs;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param unknown $code_nafa
|
||
|
* @return string|multitype:
|
||
|
*/
|
||
|
public function getLibelleNafa($code)
|
||
|
{
|
||
|
if ($code == '') {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
$this->setTabCodesNafa();
|
||
|
return $this->tabCodesNafa[$code];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Liste des événements
|
||
|
* @param string $siren
|
||
|
* @param string $nic
|
||
|
* @param integer $iDeb
|
||
|
* @param integer $iMax
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getEvenements($siren, $nic = null, $iDeb = 0, $iMax = 1000)
|
||
|
{
|
||
|
$nic = intval($nic);
|
||
|
|
||
|
$tabRet = array();
|
||
|
|
||
|
$sqlIdentifiant = "insSIREN=$siren";
|
||
|
if ( !empty($nic) ) $sqlIdentifiant.= " AND insNIC=$nic ";
|
||
|
|
||
|
//Recherche événements associé
|
||
|
if ( empty($nic) ) {
|
||
|
$tabSupId = $this->getEvenementsAssocId($siren);
|
||
|
|
||
|
if ( count($tabSupId)>0 ) {
|
||
|
$sqlIdentifiant.= " OR id IN(".join(',', $tabSupId).")";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$result = $this->iDb->select(
|
||
|
'insee.insee_even',
|
||
|
'id, LPAD(insSIREN,9,0) as insSIREN, siretValide, LPAD(insNIC,5,0) as insNIC, insLIBCOM, insSIEGE, insAUXILT, insORIGINE, insTEFET, insAPET700, insAPRM, insMODET, insMARCHET, insSAISONAT, insACTIVNAT, insENSEIGNE, insL1_NOMEN, insL2_COMP, insL4_VOIE, insL3_CADR, insNUMVOIE, insINDREP, insTYPVOIE, insLIBVOIE, insL5_DISP, insL6_POST, insCODPOS, insL7_ETRG, insRPET, insDEPCOM, insCODEVOIE, insDREACTET, insEXPLET, insDAPET, insLIEUACT, insACTISURF, insDEFET, insTEL, insCJ, insCIVILITE, insTEFEN, insAPEN700, insMODEN, insMARCHEN, insNOMEN, insTYPCREH, insEVE, insDATEVE, insTRAN, insNICTRAN, insMNICSIEGE, insMNOMEN, insMCJ, insMAPEN, insFiller1, insFiller2, insMMARCHEN, insMORDIN, insEFENCENT, insSIGLE, insNBETEXPL, insNICSIEGE, insDEPCOMEN, insFiller3, insMENSEIGNE, insMAPET, insMNATURE, insMADRESSE, insMEFET, insMSINGT, insMTELT, insMMARCHET, insMAUXILT, insSINGT, insEFETCENT, insSIRETPS, insDESTINAT, insDATEMAJ, idFlux, dirNom, dirNomUsage, dirPrenom, insDCRET, insDCREN, insPRODPART, insSIRETASS, insDREACTEN, insEXPLEN, insFiller4, insDEFEN, insMONOREG, insREGIMP, insMONOACT, insMSIGLE, insMEXPLEN, insRPEN, insMEXPLET, insTYPETAB, insDAPEN',
|
||
|
"$sqlIdentifiant ORDER BY insDATEMAJ DESC LIMIT $iDeb, $iMax",
|
||
|
true, MYSQL_ASSOC);
|
||
|
|
||
|
foreach ( $result as $even ) {
|
||
|
|
||
|
$libDet = '';
|
||
|
if ($even['insMNOMEN']==1) {
|
||
|
$libDet.= 'Modification de la raison sociale : '.$even['insNOMEN'];
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'NOMEN');
|
||
|
if ($strPre<>'' && $strPre<>$even['insNOMEN']) $libDet.=" (Précédent : $strPre)";
|
||
|
$libDet.= ', ';
|
||
|
}
|
||
|
if ($even['insMENSEIGNE']==1) {
|
||
|
$libDet.= 'Modification de l\'enseigne : '.$even['insENSEIGNE'];
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'ENSEIGNE');
|
||
|
if ($strPre<>'' && $strPre<>$even['insENSEIGNE']) $libDet.=" (Précédent : $strPre)";
|
||
|
$libDet.= ', ';
|
||
|
}
|
||
|
if ($even['insMSIGLE']==1) {
|
||
|
$libDet.= 'Modification du sigle : '.$even['insSIGLE'];
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'SIGLE');
|
||
|
if ($strPre<>'' && $strPre<>$even['insSIGLE']) $libDet.=" (Précédent : $strPre)";
|
||
|
$libDet.= ', ';
|
||
|
}
|
||
|
if ($even['insMAPEN']==1) {
|
||
|
$libDet.= 'Modification de l\'activité de l\'entreprise : '.$even['insAPEN700'].' - '.$this->getLibelleNaf($even['insAPEN700']);
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'APEN');
|
||
|
if ($strPre<>'' && $strPre<>$even['insAPEN700']) $libDet.=" (Précédent : $strPre - ".$this->getLibelleNaf($strPre).')';
|
||
|
$libDet.= ', ';
|
||
|
}
|
||
|
if ($even['insMAPET']==1) {
|
||
|
$libDet.= 'Modification de l\'activité de l\'établissement : '.$even['insAPET700'].' - '.$this->getLibelleNaf($even['insAPET700']);
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'APET');
|
||
|
if ($strPre<>'' && $strPre<>$even['insAPET700']) $libDet.=" (Précédent : $strPre - ".$this->getLibelleNaf($strPre).')';
|
||
|
$libDet.= ', ';
|
||
|
}
|
||
|
if ($even['insMNICSIEGE']==1) {
|
||
|
$libDet.='Modification du nic du siège : '.$even['insNICSIEGE'];
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'NIC');
|
||
|
if ($strPre<>'' && $strPre<>$even['insNICSIEGE']) $libDet.=" (Précédent : $strPre)";
|
||
|
$libDet.=', ';
|
||
|
}
|
||
|
if ($even['insMADRESSE']==1) {
|
||
|
$libDet.='Modification de l\'adresse : '.$even['insL2_COMP'].' '.$even['insL3_CADR'].' '.$even['insL4_VOIE'].' '.$even['insL5_DISP'].' '.$even['insL6_POST'].' '.$even['insL7_ETRG'];
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'ADRESSE');
|
||
|
if ($strPre<>'' && $strPre<>$even['insL2_COMP'].' '.$even['insL3_CADR'].' '.$even['insL4_VOIE'].' '.$even['insL5_DISP'].' '.$even['insL6_POST'].' '.$even['insL7_ETRG']) $libDet.=" (Précédent : $strPre)";
|
||
|
$libDet.=', ';
|
||
|
}
|
||
|
if ($even['insMEFET']==1) $libDet.='Modification de l\'effectif : '.$even['insEFENCENT'].' (Tranche '.$even['insTEFET'].'), ';
|
||
|
if ($even['insEXPLET']=='O') $strTmp='Exploitant';
|
||
|
elseif ($even['insEXPLET']=='N') $strTmp='Non exploitant participant au système productif';
|
||
|
elseif ($even['insEXPLET']=='X') $strTmp='Non exploitant ne participant pas au système productif';
|
||
|
if ($even['insMEXPLET']==1) $libDet.='Modification du caractère exploitant de l\'établissement : '.$strTmp.', ';
|
||
|
if ($even['insEXPLEN']=='O') $strTmp='Exploitant';
|
||
|
elseif ($even['insEXPLEN']=='N') $strTmp='Non exploitant participant au système productif';
|
||
|
elseif ($even['insEXPLEN']=='X') $strTmp='Non exploitant ne participant pas au système productif';
|
||
|
if ($even['insMEXPLEN']==1) $libDet.='Modification du caractère exploitant de l\'entreprise : '.$strTmp.', ';
|
||
|
if ($even['insMCJ']==1) {
|
||
|
$libDet.='Modification de la forme juridique : '.$even['insCJ'].' - '.$this->getLibelleFJ($even['insCJ']);
|
||
|
$strPre = $this->getInfoPrecedente($siren, $even['insNIC'], $even['insDATEVE'], 'CJ');
|
||
|
if ($strPre<>'' && $strPre<>$even['insCJ']) $libDet.=" (Précédent : $strPre - ".$this->getLibelleFJ($even['insCJ']).')';
|
||
|
$libDet.=', ';
|
||
|
}
|
||
|
if ($even['insAUXILT']==1) $strTmp='Auxiliaire';
|
||
|
else $strTmp='Non auxiliaire';
|
||
|
if ($even['insMAUXILT']==1) $libDet.='Modification du caractère auxiliaire de l\'établissement : '.$strTmp.', ';
|
||
|
|
||
|
if (trim($even['insDESTINAT'])<>'' && $even['insDESTINAT']<>'NR' && $even['insDESTINAT']*1<>9)
|
||
|
$libDet.=$this->tabDestinat['i'.trim($even['insDESTINAT'])].', ';
|
||
|
|
||
|
$libDet.=$this->tabTypEtab['i'.trim($even['insTYPETAB'])].', ';
|
||
|
|
||
|
$typeSiretAss='';
|
||
|
if ( $even['insSIREN'] != $siren ) {
|
||
|
|
||
|
if ( substr($even['insSIRETASS'],0,9) == $siren ) {
|
||
|
switch ($even['insPRODPART']*1) {
|
||
|
case 1: $typeSiretAss='Loueur de fond'; break;
|
||
|
case 2: $typeSiretAss='Locataire du fond'; break;
|
||
|
case 3: $typeSiretAss='Prestataire de personnel'; break;
|
||
|
}
|
||
|
|
||
|
$dateEve=$even['insDATEVE'];
|
||
|
$dateMaj=$even['insDATEMAJ'];
|
||
|
if (str_replace('-','',$dateEve*1)==0) $dateEve=$dateMaj;
|
||
|
|
||
|
$tabRet[]=array(
|
||
|
'codeEven' => 'I'.$even['insEVE'],
|
||
|
'nic' => substr($even['insSIRETASS'],9,5),
|
||
|
'siretAssocie'=>''.$even['insSIREN'].$even['insNIC'],
|
||
|
'typeSiretAss'=>$typeSiretAss,
|
||
|
'siege' => $even['insSIEGE'],
|
||
|
'libEven' => "Modification d'une entreprise/établissement lié",//$tabEvenInsee['i'.trim($even['insEVE'])],
|
||
|
'libEvenDet'=> '',//substr($libDet,0,-3),
|
||
|
'dateMAJ' => $dateMaj,
|
||
|
'dateEven' => $dateEve,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
if ( substr($even['insSIRETPS'],0,9) == $siren ) {
|
||
|
$typeSiretAss='Prédécesseur ou Successeur';
|
||
|
$dateEve=$even['insDATEVE'];
|
||
|
$dateMaj=$even['insDATEMAJ'];
|
||
|
if (str_replace('-','',$dateEve*1)==0) $dateEve=$dateMaj;
|
||
|
|
||
|
$tabRet[]=array(
|
||
|
'codeEven' => 'I'.$even['insEVE'],
|
||
|
'nic' => substr($even['insSIRETPS'],9,5),
|
||
|
'siretAssocie'=>''.$even['insSIREN'].$even['insNIC'],
|
||
|
'typeSiretAss'=>$typeSiretAss,
|
||
|
'siege' => $even['insSIEGE'],
|
||
|
'libEven' => "Modification d'une entreprise/établissement lié",//$tabEvenInsee['i'.trim($even['insEVE'])],
|
||
|
'libEvenDet'=> '',//substr($libDet,0,-3),
|
||
|
'dateMAJ' => $dateMaj,
|
||
|
'dateEven' => $dateEve,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
|
||
|
switch (intval($even['insPRODPART'])) {
|
||
|
case 1: $typeSiretAss='Loueur de fond'; break;
|
||
|
case 2: $typeSiretAss='Locataire du fond'; break;
|
||
|
case 3: $typeSiretAss='Prestataire de personnel'; break;
|
||
|
}
|
||
|
|
||
|
$siretAss=$even['insSIRETASS'];
|
||
|
if (intval($siretAss)==0) {
|
||
|
$tabPS=array();
|
||
|
$siretAss=$even['insSIRETPS'];
|
||
|
if ($siretAss*1>0)
|
||
|
$tabPS=$this->getIdentiteLight(substr($siretAss,0,9));
|
||
|
$tabEt=$this->getIdentiteLight($siren);
|
||
|
if ($tabPS['actif']==1 && $tabEt['actif']==0) $typeSiretAss='Successeur';
|
||
|
elseif ($tabPS['actif']==0 && $tabEt['actif']==1) $typeSiretAss='Prédécesseur';
|
||
|
else $typeSiretAss='Prédécesseur ou Successeur';
|
||
|
}
|
||
|
|
||
|
$dateEve=$even['insDATEVE'];
|
||
|
$dateMaj=$even['insDATEMAJ'];
|
||
|
if (str_replace('-','',$dateEve*1)==0) $dateEve=$dateMaj;
|
||
|
|
||
|
$tabRet[]=array(
|
||
|
'codeEven' => 'I'.$even['insEVE'],
|
||
|
'nic' => $even['insNIC'],
|
||
|
'siretAssocie' => $siretAss,
|
||
|
'typeSiretAss' => $typeSiretAss,
|
||
|
'siege' => $even['insSIEGE'],
|
||
|
'libEven' => $this->tabEvenInsee['i'.trim($even['insEVE'])],
|
||
|
'libEvenDet' => substr($libDet,0,-2),
|
||
|
'dateMAJ' => $dateMaj,
|
||
|
'dateEven' => $dateEve,
|
||
|
);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Compte le nombre d'événements
|
||
|
* @param string $siren
|
||
|
* @param string $nic
|
||
|
* @return integer
|
||
|
*/
|
||
|
public function getEvenementsCount($siren, $nic = null)
|
||
|
{
|
||
|
$nic = intval($nic);
|
||
|
|
||
|
$tabRet = $tabId = array();
|
||
|
|
||
|
$sqlIdentifiant = "insSIREN=$siren";
|
||
|
if ( !empty($nic) ) $sqlIdentifiant.= " AND insNIC=$nic ";
|
||
|
|
||
|
//Recherche événements associé
|
||
|
if ( empty($nic) ) {
|
||
|
$tabSupId = $this->getEvenementsAssocId($siren);
|
||
|
|
||
|
if ( count($tabSupId)>0 ) {
|
||
|
$sqlIdentifiant.= " OR id IN(".join(',', $tabSupId).")";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//Nombre total
|
||
|
$result = $this->iDb->select('insee.insee_even', 'COUNT(*) AS nb', "$sqlIdentifiant ORDER BY insDATEMAJ DESC",false, MYSQL_ASSOC);
|
||
|
|
||
|
return $result[0]['nb'];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Recherche les identifiants des événements INSEE associés
|
||
|
* @param string $siren
|
||
|
* @return array
|
||
|
*/
|
||
|
protected function getEvenementsAssocId($siren)
|
||
|
{
|
||
|
if ($this->tabAssocId === null) {
|
||
|
|
||
|
$siretDeb = $siren.'00000';
|
||
|
$siretFin = $siren.'99999';
|
||
|
|
||
|
$tabSupId = array();
|
||
|
|
||
|
//Recherche d'évènement pour lesquels le SIREN est ASSOCIE
|
||
|
$result = $this->iDb->select('insee.insee_even', 'id', "insSIREN!=$siren AND insSIRETASS BETWEEN $siretDeb AND $siretFin GROUP BY insSIREN, ROUND(insSIRETASS/100000) ORDER BY insDATEMAJ DESC",false, MYSQL_ASSOC);
|
||
|
if ( count($result)>0 ) {
|
||
|
foreach ($result as $tmp) {
|
||
|
$tabSupId[] = $tmp['id'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//Recherche d'évènement pour lesquels le SIREN est Prédécesseur ou Successeur
|
||
|
$result = $this->iDb->select('insee.insee_even', 'id', "insSIREN!=$siren AND insSIRETASS BETWEEN $siretDeb AND $siretFin GROUP BY insSIREN, ROUND(insSIRETPS/100000) ORDER BY insDATEMAJ DESC",false, MYSQL_ASSOC);
|
||
|
if ( count($result)>0 ) {
|
||
|
foreach ($result as $tmp) {
|
||
|
$tabSupId[] = $tmp['id'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$this->tabAssocId = $tabSupId;
|
||
|
|
||
|
} else {
|
||
|
|
||
|
$tabSupId = $this->tabAssocId;
|
||
|
|
||
|
}
|
||
|
|
||
|
return $tabSupId;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param unknown $code_forme_juridique
|
||
|
* @param string $court
|
||
|
* @return string|unknown
|
||
|
*/
|
||
|
public function getLibelleFJ($code_forme_juridique, $court=false)
|
||
|
{
|
||
|
$fj=$code_forme_juridique*1;
|
||
|
if ($fj>0 && $fj<10000) {
|
||
|
$tmp=$this->iDb->select('jo.tabFJur', 'libelle AS LibFJ, libelleCourt AS LibCourt', "code=$fj", false, MYSQL_ASSOC);
|
||
|
$libLong =@$tmp[0]['LibFJ'];
|
||
|
$libCourt=@$tmp[0]['LibCourt'];
|
||
|
if ($court) {
|
||
|
if ($libCourt=='') {
|
||
|
if (strlen($libLong)>20) return substr($libLong,0,17).'...';
|
||
|
else return $libLong;
|
||
|
}
|
||
|
return $libCourt;
|
||
|
}
|
||
|
else
|
||
|
return $libLong;
|
||
|
}
|
||
|
if ($court) return "En chiffrement";
|
||
|
return 'En instance de chiffrement';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getCodesFJ()
|
||
|
{
|
||
|
$tabFJ = array();
|
||
|
$cache = dirname(__FILE__) . '/../Table/CodesFJ.php';
|
||
|
if ( file_exists($cache) ) {
|
||
|
$tabFJ = include $cache;
|
||
|
} else {
|
||
|
$tabTmp=$this->iDb->select('jo.tabFJur', 'code AS FJ, libelle AS libFJ', 'code>=1000', false, MYSQL_ASSOC);
|
||
|
foreach ($tabTmp as $i=>$tabCJ)
|
||
|
$tabFJ[$tabCJ['FJ']]=str_replace('"','\"',$tabCJ['libFJ']);
|
||
|
}
|
||
|
|
||
|
return array_keys($tabFJ);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Découpe une ligne d'adresse textuelle en un tableau contenant les différentes composantes de l'adresse
|
||
|
* <pre>Array (
|
||
|
* [adrComp0] => Maison des associations
|
||
|
* [num] => 33
|
||
|
* [typeVoie] => R
|
||
|
* [libVoie] => Louis Blanc
|
||
|
* [cp] => ...
|
||
|
* [ville] => ... Si contenu dans l'adresse
|
||
|
* )</pre>
|
||
|
*
|
||
|
* @param string $strLigneDAdresse La ligne d'adresse textuelle (ex : Maison des associations, 33 rue Louis Blanc
|
||
|
* @return array tableau contenant l'adresse structurée ici
|
||
|
*/
|
||
|
public function structureVoie($strLigneDAdresse)
|
||
|
{
|
||
|
$tabRet=$tabAdr=array();
|
||
|
$strLigneDAdresse=trim($strLigneDAdresse);
|
||
|
if ($strLigneDAdresse=='') return $tabRet;
|
||
|
$tabLignes=explode(',', preg_replace('/,$/', '', $strLigneDAdresse));
|
||
|
foreach ($tabLignes as $strLigneDAdresse) {
|
||
|
$strLigneDAdresse=trimAccent($strLigneDAdresse);
|
||
|
$strLigneDAdresse=preg_replace('/[^0-9a-zA-Z]/', ' ', $strLigneDAdresse);
|
||
|
$strLigneDAdresse=trim(preg_replace('/ +/', ' ', $strLigneDAdresse));
|
||
|
//echo "1. Adresse nettoyées = $strLigneDAdresse".PHP_EOL;
|
||
|
$adrAvecCP=preg_match("/(.*)([0-9]{5,5}|[0-9][0-9] [0-9]{3,3})([\D]*)/", $strLigneDAdresse, $tabAdrTmp);
|
||
|
if ($adrAvecCP) {
|
||
|
//echo "Adresse avec Code Postal\n";
|
||
|
//print_r($tabAdrTmp);
|
||
|
$strLigneDAdresse=trim($tabAdrTmp[1]);
|
||
|
$tabRet['cp']=$tabAdrTmp[2];
|
||
|
$tabRet['ville']=trim(strtoupper($tabAdrTmp[3]));
|
||
|
}// else echo "Adresse sans Code Postal\n";
|
||
|
$adrAvecNum=preg_match("/^([0-9]{1,4})(.*)/", $strLigneDAdresse, $tabAdrTmp);
|
||
|
if ($adrAvecNum) {
|
||
|
//echo "Adresse avec Numéro de voie\n";
|
||
|
//print_r($tabAdrTmp);
|
||
|
$tabRet['num']=$tabAdrTmp[1];
|
||
|
if (preg_match("/^\s(B|BIS|T|TER|Q|a|c|d|e|f|g|h|i|j|k|l|m|n|o|p|s)\s(.*)/i", $tabAdrTmp[2], $tabAdrTmp2))
|
||
|
{ //echo "Adresse avec Bis, Ter, Q...\n";
|
||
|
//print_r($tabAdrTmp2);
|
||
|
$tabRet['indRep']=strtoupper(trim($tabAdrTmp2[1]));
|
||
|
$typeVoie=trim($tabAdrTmp2[2]);
|
||
|
} else {
|
||
|
$typeVoie=trim($tabAdrTmp[2]);
|
||
|
}
|
||
|
} else {
|
||
|
$typeVoie=trim($strLigneDAdresse);
|
||
|
}
|
||
|
// On récupère le type de voie si possible et le libellé de la voie
|
||
|
$voieTrouvee=false;
|
||
|
foreach ($this->tabCodeVoie as $code=>$voie) {
|
||
|
if (preg_match("/^($voie |$voie".'s '."|$code )(.*)/i", $typeVoie, $tabAdrTmp)) {
|
||
|
//echo "Adresse avec type de voie\n";
|
||
|
//print_r($tabAdrTmp);
|
||
|
$tabRet['typeVoie']=$code;
|
||
|
$tabRet['libVoie']=trim(strtoupper($tabAdrTmp[2]));
|
||
|
$voieTrouvee=true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (!$voieTrouvee) $tabAdr[]=$typeVoie;
|
||
|
}
|
||
|
foreach ($tabAdr as $k=>$ligne)
|
||
|
$tabRet['adrComp'.$k]=trim(strtoupper($ligne));
|
||
|
|
||
|
if (!isset($tabRet['libVoie'])) { $tabRet['libVoie']=$ligne; unset($tabRet['adrComp'.$k]); }
|
||
|
|
||
|
if (isset($tabRet['adrComp0'])) {
|
||
|
if ($tabRet['adrComp0']=='BIS' || $tabRet['adrComp0']=='B') {
|
||
|
$tabRet['indRep']='B';
|
||
|
$tabRet['adrComp0']='';
|
||
|
} elseif ($tabRet['adrComp0']=='TER' || $tabRet['adrComp0']=='T') {
|
||
|
$tabRet['indRep']='T';
|
||
|
$tabRet['adrComp0']='';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Liste des établissements par siren/nic
|
||
|
* @param string $siren
|
||
|
* @param string $nic
|
||
|
* @param int $deb
|
||
|
* @param int $nbRep
|
||
|
* @param int $maxRep
|
||
|
* @param int $dep
|
||
|
* @param int $actif
|
||
|
* @param int $siege
|
||
|
*/
|
||
|
public function getEtablissements($siren, $nic='', $deb=0, $nbRep=20, $maxRep=200, $dep=0, $actif=-1, $siege=null)
|
||
|
{
|
||
|
$this->setTabCodesNaf();
|
||
|
$deb = $deb*1;
|
||
|
$dep = $dep*1;
|
||
|
$nbRep = $nbRep*1;
|
||
|
|
||
|
$strInfo = '';
|
||
|
|
||
|
$limit="LIMIT $deb, $nbRep";
|
||
|
|
||
|
$sqlInfo="'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, LPAD(e.siren, 9, 0) AS siren, LPAD(e.nic, 5, 0) AS nic, e.siege, ".
|
||
|
"e.raisonSociale, e.enseigne, e.sigle, 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, e.adr_dep, LPAD(e.adr_com,3,0) AS adr_com, LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep, e.teff_etab, ".
|
||
|
"CONCAT(siren, nic) AS siret, e.actif, e.identite_pre, IF(e.siege=2,0.5,e.siege) AS triSiege";
|
||
|
|
||
|
$strActif = $strDep = '';
|
||
|
if (intval($actif)==1) $strActif=' AND e.actif=1 ';
|
||
|
elseif (intval($actif)==0) $strActif=' AND e.actif=0 ';
|
||
|
|
||
|
$strSiege='';
|
||
|
if ($siege===null) $strSiege='';
|
||
|
elseif ($siege==1) $strSiege='AND e.siege=1 ';
|
||
|
elseif ($siege==0) $strSiege='AND e.siege IN(0,2) ';
|
||
|
|
||
|
$listeEtab = array();
|
||
|
|
||
|
// --- Search with "departement"
|
||
|
if ($dep>0 && $dep<99999) {
|
||
|
if ($dep<96) $strDep='AND adr_cp BETWEEN '.$dep.'000 AND '.$dep.'999';
|
||
|
elseif ($dep>9999) $strDep="AND adr_cp BETWEEN $dep AND $dep";
|
||
|
else $strDep='AND adr_cp BETWEEN '.$dep.'00 AND '.$dep.'99';
|
||
|
$whereCount = "siren=$siren $strDep $strActif $strSiege";
|
||
|
$whereSelect = "siren=$siren $strDep $strActif $strSiege ORDER BY triSiege DESC, e.actif DESC, e.nic DESC $limit";
|
||
|
}
|
||
|
// --- Search without NIC
|
||
|
elseif ($nic=='') {
|
||
|
$whereCount = "siren=$siren $strActif $strSiege";
|
||
|
$whereSelect = "e.siren=$siren $strActif $strSiege ORDER BY triSiege DESC, e.actif DESC, e.nic DESC $limit";
|
||
|
}
|
||
|
// --- Search with NIC
|
||
|
else {
|
||
|
$whereCount = "siren=$siren AND (nic=$nic OR siege=1) $strActif $strSiege";
|
||
|
$whereSelect = "siren=$siren AND (nic=$nic OR siege=1) $strActif $strSiege ORDER BY triSiege DESC, e.actif DESC, e.nic DESC $limit";
|
||
|
}
|
||
|
|
||
|
$tabTmp = $this->iDb->select('jo.etablissements e', 'count(*)', $whereCount);
|
||
|
if (count($tabTmp)>0) {
|
||
|
$nbTot = $tabTmp[0][0];
|
||
|
if ($nbTot>0) {
|
||
|
$listeEtab = $this->iDb->select('jo.etablissements e', $sqlInfo, $whereSelect, false, MYSQL_ASSOC);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Vérification du SIREN
|
||
|
if ($nbTot==0 && $actif==-1) {
|
||
|
require_once 'Metier/sphinx/rechercheFonc.php';
|
||
|
$liste = verificationDuSiret($siren);
|
||
|
if ($liste != false) {
|
||
|
//print 'Essayez :<br/>';
|
||
|
$listeSiren=array();
|
||
|
foreach ($liste as $s) {
|
||
|
if (sommeDeControle($s) != 0) {
|
||
|
//print 'erreur somme de controle sur '.$s.' ('.sommeDeControle($s).')<br/>';
|
||
|
} else {
|
||
|
$listeSiren[]=$s;
|
||
|
}
|
||
|
}
|
||
|
$strSiren = implode(',',$listeSiren);
|
||
|
$tabTmp = $this->iDb->select('jo.etablissements', 'count(*)', "siren IN ($strSiren) AND siege=1");
|
||
|
if (count($tabTmp)>0) {
|
||
|
$nbTot = $tabTmp[0];
|
||
|
$listeEtab = $this->iDb->select(
|
||
|
'jo.etablissements e', $sqlInfo,
|
||
|
"siren IN ($strSiren) AND siege=1 ORDER BY e.rang DESC, e.actif DESC, e.nic ASC $limit",
|
||
|
true, MYSQL_ASSOC);
|
||
|
}
|
||
|
$strInfo='Siren saisi invalide';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Affichage de la liste des établissements
|
||
|
if ( count($listeEtab)>0 ) {
|
||
|
foreach ($listeEtab as $etab) {
|
||
|
$tel=sprintf('%010d', strtr($etab['tel'],array('-'=>'', '/'=>'','.'=>'',','=>'')));
|
||
|
if ($tel<>'0000000000') $tel=implode('.', str_split($tel,2));
|
||
|
else $tel='';
|
||
|
|
||
|
$fax=sprintf('%010d', strtr($etab['fax'],array('-'=>'', '/'=>'','.'=>'',','=>'')));
|
||
|
if ($fax<>'0000000000') $fax=implode('.', str_split($fax,2));
|
||
|
else $fax='';
|
||
|
|
||
|
$nom = trim($etab['raisonSociale']);
|
||
|
// Cas des noms vides à l'INSEE (une centaine)
|
||
|
if ($nom=='') $nom = preg_replace('/,.*$/','',$etab['identite_pre']);
|
||
|
|
||
|
$pays = 'France';
|
||
|
if ( $etab['adr_dep']==99 ) {
|
||
|
$resultPays = $this->iDb->select("jo.tabPays", "libPays", "codePaysInsee = ".$etab['adr_com'], false, MYSQL_ASSOC);
|
||
|
if ( count($resultPays)>0 ) {
|
||
|
$pays = $resultPays[0]['libPays'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$tabRet[] = array(
|
||
|
'Localisation' => $etab['Loc'],
|
||
|
'id' => $etab['id'],
|
||
|
'Pertinence' => 100,
|
||
|
'Source' => $etab['source'],
|
||
|
'SoruceId' => $etab['source_id'],
|
||
|
'Siret' => $etab['siret'],
|
||
|
'Siege' => $etab['siege'],
|
||
|
'Nom' => $nom,
|
||
|
'Sigle' => $etab['sigle'],
|
||
|
'Enseigne' => $etab['enseigne'],
|
||
|
'Adresse' => trim(preg_replace('/ +/', ' ', trim( $etab['adr_num'] .' '. $etab['adr_btq'] .' '.
|
||
|
$etab['adr_typeVoie'] .' '. $etab['adr_libVoie']))),
|
||
|
'Adresse2' => trim(preg_replace('/ +/', ' ', $etab['adr_comp'])),
|
||
|
'CP' => $etab['adr_cp'],
|
||
|
'Ville' => $etab['adr_ville'],
|
||
|
'Pays' => $pays,
|
||
|
'Tel' => $tel,
|
||
|
'Fax' => $fax,
|
||
|
'FJ' => $etab['cj'],
|
||
|
'FJLib' => $this->getLibelleFJ($etab['cj']),
|
||
|
'Siren' => $etab['siren'],
|
||
|
'Nic' => $etab['nic'],
|
||
|
'Actif' => $etab['actif'],
|
||
|
'NafEtab' => $etab['ape_etab'], // Etablissement
|
||
|
'NafEnt' => $etab['ape_entrep'], // Entreprise
|
||
|
'NafEtabLib' => $this->getLibelleNaf($etab['ape_etab']),
|
||
|
'NafEntLib' => $this->getLibelleNaf($etab['ape_entrep']),
|
||
|
'EffEtTr' => $etab['teff_etab'],
|
||
|
'EffEtTrLib' => self::$tabEffectif[$etab['teff_etab']],
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($dep==0) $dep=''; // Evite l'affichage d'un 0 inutile sur l'Extranet
|
||
|
|
||
|
return array(
|
||
|
'criteres' => array('siren'=>$siren, 'nic'=>$nic, 'dep'=>$dep),
|
||
|
'info' => $strInfo,
|
||
|
'nbReponses' => count($tabRet),
|
||
|
'nbReponsesTotal' => $nbTot,
|
||
|
'reponses' => $tabRet
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Liste des établissements par Identifiant TEL/AUTRE
|
||
|
* @param string $typeId
|
||
|
* @param string $id
|
||
|
* @param int $deb
|
||
|
* @param int $nbRep
|
||
|
* @param int $maxRep
|
||
|
* @param int $dep
|
||
|
* @param int $actif
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getEtablissementsParId($typeId, $id, $deb=0, $nbRep=20, $maxRep=200, $dep=0, $actif=2)
|
||
|
{
|
||
|
$this->setTabCodesNaf();
|
||
|
$deb=$deb*1;
|
||
|
$dep=$dep*1;
|
||
|
|
||
|
$nbRep=$nbRep*1;
|
||
|
$limit="LIMIT $deb, $nbRep";
|
||
|
|
||
|
$filtreActif = '';
|
||
|
if ( $actif==1 || $actif==0 ) {
|
||
|
$filtreActif = " AND WHERE actif=$actif";
|
||
|
}
|
||
|
|
||
|
if ($typeId=='TEL') {
|
||
|
Metier_Util_Log::write('I',"Recherche par TEL de $id avec un maximum de $nbRep réponses",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||
|
|
||
|
$tabTmp=$this->iDb->select('jo.etablissements', 'count(*)', "TEL=$id OR FAX=$id $filtreActif");
|
||
|
$nbTot=$tabTmp[0][0];
|
||
|
$listeEtab=$this->iDb->select('jo.etablissements e',
|
||
|
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, LPAD(e.siren, 9, 0) AS siren, LPAD(e.nic, 5, 0) AS nic, e.siege, ".
|
||
|
"e.raisonSociale, e.enseigne, e.sigle, 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, e.adr_dep, LPAD(e.adr_com,3,0) AS adr_com, LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep,".
|
||
|
"CONCAT(e.siren, e.nic) as siret, e.actif",
|
||
|
"TEL=$id OR FAX=$id $filtreActif ORDER BY e.siege DESC, e.actif DESC $limit", false, MYSQL_ASSOC);
|
||
|
|
||
|
} elseif ($typeId=='AUTRE') {
|
||
|
/** Formatage des numéros de RC **/
|
||
|
$tabId=array($id);
|
||
|
if (preg_match('/(\d*)(\D)(\d*)/', $id,$matches)) {
|
||
|
if (strlen($matches[1])<=2) {
|
||
|
// Années du type 54 ou 07
|
||
|
if ($matches[1]>date('y')) $deb='19'.$matches[1];
|
||
|
else $deb='20'.$matches[1];
|
||
|
} else // Années du type 1900 ou 2000
|
||
|
$deb=substr($matches[1],2,2);
|
||
|
$numero =$matches[3]*1;
|
||
|
for ($i=strlen($numero); $i<=7; $i++) {
|
||
|
$tabId[]=$matches[1].$matches[2].sprintf('%0'.$i.'s',$numero);
|
||
|
$tabId[]=$deb.$matches[2].sprintf('%0'.$i.'s',$numero);
|
||
|
}
|
||
|
}
|
||
|
$strId=implode("','", $tabId);
|
||
|
|
||
|
/** Gestion du numéro de département ou CP **/
|
||
|
$strDep='';
|
||
|
if ($dep>0 && $dep<99999) {
|
||
|
if ($dep<96) $strDep='AND adr_cp BETWEEN '.$dep.'000 AND '.$dep.'999';
|
||
|
elseif ($dep>9999) $strDep="AND adr_cp BETWEEN $dep AND $dep";
|
||
|
else $strDep='AND adr_cp BETWEEN '.$dep.'00 AND '.$dep.'99';
|
||
|
}
|
||
|
$tabTmp=$this->iDb->select('jo.etablissements', 'count(*)', "autre_id IN ('$strId') $filtreActif $strDep");
|
||
|
$nbTot=$tabTmp[0][0];
|
||
|
$listeEtab=$this->iDb->select('jo.etablissements e',
|
||
|
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, LPAD(e.siren, 9, 0) AS siren, LPAD(e.nic, 5, 0) AS nic, e.siege, ".
|
||
|
"e.raisonSociale, e.enseigne, e.sigle, 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, e.adr_dep, LPAD(e.adr_com,3,0) AS adr_com, LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep, e.teff_etab, ".
|
||
|
"CONCAT(e.siren, e.nic) as siret, e.actif",
|
||
|
"autre_id IN ('$strId') $filtreActif $strDep ORDER BY siege DESC $limit", false, MYSQL_ASSOC);
|
||
|
|
||
|
}
|
||
|
foreach ($listeEtab as $etab)
|
||
|
{
|
||
|
$pays = 'France';
|
||
|
if ( $etab['adr_dep']==99 ) {
|
||
|
$resultPays = $this->iDb->select("jo.tabPays", "libPays", "codePaysInsee = ".$etab['adr_com'], false, MYSQL_ASSOC);
|
||
|
$pays = $resultPays[0]['libPays'];
|
||
|
}
|
||
|
|
||
|
$tabRet[]=array(
|
||
|
'Localisation'=>$etab['Loc'],
|
||
|
'id'=>$etab['id'],
|
||
|
'Pertinence'=>100,
|
||
|
'Source' => $etab['source'],
|
||
|
'SourceId' => $etab['source_id'],
|
||
|
'Siret'=>$etab['siret'],
|
||
|
'Siege'=>$etab['siege'],
|
||
|
'Nom'=>$etab['raisonSociale'],
|
||
|
'Sigle'=>$etab['sigle'],
|
||
|
'Enseigne'=>$etab['enseigne'],
|
||
|
'Adresse'=>trim(preg_replace('/ +/', ' ', trim( $etab['adr_num'] .' '. $etab['adr_btq'] .' '.
|
||
|
$etab['adr_typeVoie'] .' '. $etab['adr_libVoie']))),
|
||
|
'Adresse2'=>trim(preg_replace('/ +/', ' ', $etab['adr_comp'])),
|
||
|
'CP'=>$etab['adr_cp'],
|
||
|
'Ville'=>$etab['adr_ville'],
|
||
|
'Pays' => $pays,
|
||
|
'Tel'=>$etab['tel'],
|
||
|
'Fax'=>$etab['fax'],
|
||
|
'FJ'=>$etab['cj'],
|
||
|
'FJLib'=>$this->getLibelleFJ($etab['cj']),
|
||
|
'Siren'=>$etab['siren'],
|
||
|
'Nic'=>$etab['nic'],
|
||
|
'Actif'=>$etab['actif'],
|
||
|
'NafEtab'=>$etab['ape_etab'], // Etablissement
|
||
|
'NafEnt'=>$etab['ape_entrep'], // Entreprise
|
||
|
'NafEtabLib'=>$this->getLibelleNaf($etab['ape_etab']),
|
||
|
'NafEntLib' =>$this->getLibelleNaf($etab['ape_entrep']),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
if ($dep==0) $dep=''; // Evite l'affichage d'un 0 inutile sur l'Extranet
|
||
|
|
||
|
return array(
|
||
|
'criteres'=>array('autreId'=>$id, 'dep'=>$dep),
|
||
|
'nbReponses'=>count($tabRet),
|
||
|
'nbReponsesTotal'=>$nbTot,
|
||
|
'reponses'=>$tabRet);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne juste si un siren existe
|
||
|
*
|
||
|
* @param integer $siren
|
||
|
* @return bool
|
||
|
*/
|
||
|
function sirenExiste($siren)
|
||
|
{
|
||
|
$siren=$siren*1;
|
||
|
$listeEtab=$this->iDb->select('jo.etablissements', 'id', "siren=$siren LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (@count($listeEtab)>0)
|
||
|
return true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne l'identité issue de la table établissements
|
||
|
*
|
||
|
* @param integer $siren
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function getIdentiteLight($siren, $nic=0, $id=0)
|
||
|
{
|
||
|
$siren=$siren*1;
|
||
|
$nic=$nic*1;
|
||
|
$id=$id*1;
|
||
|
$limit=''; //LIMIT O,1' ;
|
||
|
if ($id>0 && $siren<1000) $where=" id=$id ";
|
||
|
elseif ($nic<>0) $where=" siren=$siren AND nic=$nic ";
|
||
|
elseif ($siren<>0) $where=" siren=$siren ";
|
||
|
else return array();
|
||
|
|
||
|
$tabRet = array();
|
||
|
|
||
|
$listeEtab=$this->iDb->select('jo.etablissements e',
|
||
|
"e.id, e.source, e.source_id, e.autre_id, LPAD(e.siren, 9, 0) as siren, LPAD(e.nic, 5, 0) as nic, e.siege, e.autre_id, e.triCode, ".
|
||
|
"e.raisonSociale, e.enseigne, e.sigle, e.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, LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep, ".
|
||
|
"e.adr_dep, LPAD(e.adr_com,3,0) AS adr_com, e.capital, e.capitalDev, e.capitalSrc, e.tca, e.teff_entrep, e.teff_etab, ".
|
||
|
"CONCAT(LPAD(e.siren,9,0), LPAD(e.nic,5,0)) as siret, e.actif, e.identite_pre",
|
||
|
"$where ORDER BY siege DESC, actif DESC, nic DESC $limit", false, MYSQL_ASSOC);
|
||
|
|
||
|
if ( count($listeEtab)>0 ) {
|
||
|
|
||
|
$etab = $listeEtab[0];
|
||
|
|
||
|
$nom = trim($etab['raisonSociale']);
|
||
|
// Cas des noms vides à l'INSEE (une centaine)
|
||
|
if ($nom=='') $nom = preg_replace('/,.*$/','',$etab['identite_pre']);
|
||
|
|
||
|
$tabRet = array(
|
||
|
'id' => $etab['id'],
|
||
|
'Siret' => $etab['siret'],
|
||
|
'Siege' => $etab['siege'],
|
||
|
'Nom' => $nom,
|
||
|
'Tribunal' => $etab['triCode'],
|
||
|
'Sigle' => $etab['sigle'],
|
||
|
'Enseigne' => $etab['enseigne'],
|
||
|
'Adresse' => trim(preg_replace('/ +/', ' ', trim(
|
||
|
$etab['adr_num'] .' '. $etab['adr_btq'] .' '.
|
||
|
$etab['adr_typeVoie'] .' '. $etab['adr_libVoie']))),
|
||
|
'Adresse2' => trim(preg_replace('/ +/', ' ', $etab['adr_comp'])),
|
||
|
'AdresseNum' => $etab['adr_num'],
|
||
|
'AdresseBtq' => $etab['adr_btq'],
|
||
|
'AdresseVoie' => $etab['adr_typeVoie'],
|
||
|
'AdresseRue' => $etab['adr_libVoie'],
|
||
|
'CP' => $etab['adr_cp'],
|
||
|
'Ville' => $etab['adr_ville'],
|
||
|
'Tel' => $etab['tel'],
|
||
|
'Fax' => $etab['fax'],
|
||
|
'FJ' => $etab['cj'],
|
||
|
'FJ_lib' => $this->getLibelleFJ($etab['cj']),
|
||
|
'Siren' => $etab['siren'],
|
||
|
'Nic' => $etab['nic'],
|
||
|
'Actif' => $etab['actif'],
|
||
|
'NafEtab' => $etab['ape_etab'],
|
||
|
'NafEnt' => $etab['ape_entrep'],
|
||
|
'NafEntLib' => $this->getLibelleNaf($etab['ape_entrep']),
|
||
|
'NafEtabLib' => $this->getLibelleNaf($etab['ape_etab']),
|
||
|
'AutreId' => $etab['autre_id'],
|
||
|
'Source' => $etab['source'],
|
||
|
'SourceId' => $etab['source_id'],
|
||
|
'Dept' => $etab['adr_dep'],
|
||
|
'codeCommune' => $etab['adr_com'],
|
||
|
'Capital' => $etab['capital'],
|
||
|
'CapitalDev' => $etab['capitalDev'],
|
||
|
'TrancheCA' => $etab['tca'],
|
||
|
'TrancheCALib' => self::$tabTCA[$etab['tca']],
|
||
|
'EffEnTr' => $etab['teff_entrep'],
|
||
|
'EffEnTrLib' => self::$tabEffectif[$etab['teff_entrep']],
|
||
|
'EffEtTr' => $etab['teff_etab'],
|
||
|
'EffEtTrLib' => self::$tabEffectif[$etab['teff_etab']],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne la liste des devise
|
||
|
*
|
||
|
* @param string $codeDevise Code ISO devise
|
||
|
* @return Devise ou liste des devises (si pas de code ISO en entrée)
|
||
|
*/
|
||
|
public function getDevises($codeIso='')
|
||
|
{
|
||
|
if (trim($codeIso)<>'') $strWhere="devIso='$codeIso'";
|
||
|
else $strWhere='1';
|
||
|
$liste=$this->iDb->select('jo.tabDevises', 'devIso, devNom', $strWhere, false, MYSQL_ASSOC);
|
||
|
$tabRet=array();
|
||
|
foreach ($liste as $ligne)
|
||
|
$tabRet[$ligne['devIso']]=$ligne['devNom'];
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne la liste des mandataires/administrateurs/oppositions d'une ou plusieurs cours d'appel
|
||
|
*
|
||
|
* @param array $arrIdCA Id S&D de la cour d'appel
|
||
|
* @param bool $condense Par défaut retourne un tableau concatenant Nom, prenom, adresse complète
|
||
|
* @param array $type Type d'opposition. Ex array('A','M') pour Admin/Mandataires. Autres: a'V'ocat,'H'uissier,'N'otaire
|
||
|
* @return Liste des Mandataires/Administrateurs de la cours d'appel
|
||
|
*/
|
||
|
public function getMandataires($arrIdCA=array(), $condense=true, $type=array())
|
||
|
{
|
||
|
if (count($arrIdCA)>0) $strIdCA='AND ( coursAppel in ('.implode(',', $arrIdCA).') OR coursAppel2 in ('.implode(',', $arrIdCA).') )';
|
||
|
else $strIdCA='';
|
||
|
|
||
|
if (count($type)>0) $strType="AND type in ('".implode("','", $type)."') ";
|
||
|
else $strType='';
|
||
|
|
||
|
|
||
|
if (!$condense)
|
||
|
$fields='id,sirenGrp,sirenMand,Nom,Prenom,type,tribunal,Statut,adresse,adresseComp,cp,ville,tel,fax,email,web,contact';
|
||
|
else
|
||
|
$fields="id, CONCAT(Nom,' ',Prenom,' ',adresse,' ',adresseComp,' ',cp,' ',ville) as Mand";
|
||
|
|
||
|
$liste=$this->iDb->select('jo.tabMandataires', $fields, "1 $strIdCA $strType ORDER BY sirenGrp", true, MYSQL_ASSOC);
|
||
|
$tabRet=array();
|
||
|
if (!$condense) foreach ($liste as $ligne) $tabRet[]=$ligne;
|
||
|
else foreach ($liste as $ligne) $tabRet[$ligne['id']]=preg_replace('/ +/',' ',$ligne['Mand']);
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne la liste des mandataires/administrateurs/oppositions correspondant à un nom
|
||
|
*
|
||
|
* @param string $nom Nom du mandataire
|
||
|
* @param bool $condense Par défaut retourne un tableau concatenant Nom, prenom, adresse complète
|
||
|
* @param array $type Type d'opposition. Ex array('A','M') pour Admin/Mandataires. Autres: a'V'ocat,'H'uissier,'N'otaire
|
||
|
* @return Liste des Mandataires/Administrateurs de la cours d'appel
|
||
|
*/
|
||
|
public function searchMandataires($nom, $condense=true, $type=array(), $cpDep=0)
|
||
|
{
|
||
|
$strIdCA="AND (Nom LIKE '%$nom%' OR Prenom LIKE '%$nom%') ";
|
||
|
|
||
|
if (count($type)>0) $strType="AND type in ('".implode("','", $type)."') ";
|
||
|
else $strType='';
|
||
|
|
||
|
if ($cpDep>0 && $cpDep<100) $strCp="AND cp BETWEEN $cpDep"."000 AND $cpDep"."999 ";
|
||
|
elseif ($cpDep>99 && $cpDep<1000) $strCp="AND cp BETWEEN $cpDep"."00 AND $cpDep"."99 ";
|
||
|
elseif ($cpDep>999) $strCp="AND cp=$cpDep ";
|
||
|
else $strCp='';
|
||
|
|
||
|
if (!$condense)
|
||
|
$fields='id,sirenGrp,sirenMand,Nom,Prenom,type,tribunal,Statut,adresse,adresseComp,cp,ville,tel,fax,email,web,contact';
|
||
|
else
|
||
|
$fields="id, CONCAT(Nom,' ',Prenom,' ',adresse,' ',adresseComp,' ',cp,' ',ville) as Mand";
|
||
|
|
||
|
$liste=$this->iDb->select('jo.tabMandataires', $fields, "1 $strIdCA $strType $strCp ORDER BY sirenGrp", false, MYSQL_ASSOC);
|
||
|
$tabRet=array();
|
||
|
if (!$condense) foreach ($liste as $ligne) $tabRet[]=$ligne;
|
||
|
else foreach ($liste as $ligne) $tabRet[$ligne['id']]=preg_replace('/ +/',' ',$ligne['Mand']);
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/** Récupère les informations du mandataire
|
||
|
**
|
||
|
** @param integer $idMand Identifiant SD du mandataire
|
||
|
** @return array
|
||
|
**/
|
||
|
public function getMandataire($idMand)
|
||
|
{
|
||
|
$fields='id,sirenGrp,sirenMand,Nom,Prenom,type,coursAppel,coursAppel2,tribunal,Statut,stagiaire,adresse,adresseComp,cp,ville,tel,fax,email,web,contact';
|
||
|
$liste=$this->iDb->select('jo.tabMandataires', $fields, "id=$idMand", true, MYSQL_ASSOC);
|
||
|
return @$liste[0];
|
||
|
}
|
||
|
|
||
|
|
||
|
public function getHuissiers($arrIdCA=array(), $condense=true) {
|
||
|
if (count($arrIdCA)>0)
|
||
|
$strIdCA="AND tribunal in ('".implode("','", $arrIdCA)."')";
|
||
|
|
||
|
else $strIdCA='';
|
||
|
if (!$condense)
|
||
|
$fields='id,sirenGrp,sirenMand,Nom,Prenom,type,tribunal,Statut,adresse,adresseComp,cp,ville,tel,fax,email,web,contact';
|
||
|
else
|
||
|
$fields="id, CONCAT(Nom,' ',Prenom,' ',adresse,' ',adresseComp,' ',cp,' ',ville) as Mand";
|
||
|
|
||
|
$liste=$this->iDb->select('jo.tabMandataires', $fields, "1 AND type='H' $strIdCA ORDER BY sirenGrp", false, MYSQL_ASSOC);
|
||
|
$tabRet=array();
|
||
|
if (!$condense) foreach ($liste as $ligne) $tabRet[]=$ligne;
|
||
|
else foreach ($liste as $ligne) $tabRet[$ligne['id']]=preg_replace('/ +/',' ',$ligne['Mand']);
|
||
|
//@wsLog('HUISSIERS',$strIdCA,count($liste));
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/** Retourne l'identite Textuelle d'un mandataires/administrateurs
|
||
|
**
|
||
|
** @param integer $idMand Id S&d du mandataire
|
||
|
** @return string Mandataire
|
||
|
**/
|
||
|
public function getMandatairesParId($idMand) {
|
||
|
if ($idMand>0) {
|
||
|
$liste=$this->iDb->select('jo.tabMandataires', "CONCAT(Nom,' ',Prenom,' ',adresse,' ',adresseComp,' ',cp,' ',ville) as Mand", "id=$idMand", false);
|
||
|
return $liste[0][0];
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param unknown $siren
|
||
|
* @param number $nic
|
||
|
* @param number $id
|
||
|
* @return boolean|Ambigous <string, multitype:>
|
||
|
*/
|
||
|
public function getNaf4($siren, $nic=0, $id=0)
|
||
|
{
|
||
|
$tabRet=array();
|
||
|
$siren=$siren*1;
|
||
|
$nic=$nic*1;
|
||
|
$id=$id*1;
|
||
|
if ($siren==0) return false;
|
||
|
if ($nic<>0) $where=" siren=$siren AND nic=$nic ";
|
||
|
else $where=" siren=$siren AND siege=1 ";
|
||
|
|
||
|
$insee = $this->iDb->select('insee.bascule', 'siren, nic, apen5, apen4, apet5, apet4', $where, false, MYSQL_ASSOC);
|
||
|
if ( count($insee)==0 ) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
$tabRet = $insee[0];
|
||
|
$tabRet['apen4_lib'] = $this->getLibelleNaf($tabRet['apen4']);
|
||
|
$tabRet['apet4_lib'] = $this->getLibelleNaf($tabRet['apet4']);
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
public function getIdentiteEntrepriseHisto($siren)
|
||
|
{
|
||
|
$notices = array(
|
||
|
// Date AAAAMMJJ => Nom table
|
||
|
20080401 => 'notice_200804',
|
||
|
20080501 => 'notice_200805stats',
|
||
|
20081201 => 'notice_200812',
|
||
|
20090901 => 'notice_200909',
|
||
|
20091001 => 'notice_200910',
|
||
|
20091201 => 'notice_200912',
|
||
|
20100301 => 'notice_201003',
|
||
|
20100601 => 'notice_201006',
|
||
|
20100901 => 'notice_201009',
|
||
|
20101201 => 'notice_201012',
|
||
|
20110301 => 'notice_201103',
|
||
|
20110601 => 'notice_201106',
|
||
|
20110901 => 'notice_201109',
|
||
|
20111201 => 'notice_201112',
|
||
|
20120301 => 'notice_201203',
|
||
|
20120601 => 'notice_201206',
|
||
|
20120901 => 'notice_201209',
|
||
|
20121201 => 'notice_201212',
|
||
|
20131201 => 'fichier_france_entiere_201312_D_1',
|
||
|
20140101 => 'fichier_france_entiere_201401_D_1',
|
||
|
20140601 => 'fichier_france_entiere_201406_D_1',
|
||
|
20140901 => 'fichier_france_entiere_201409_D_1',
|
||
|
20141201 => 'fichier_france_entiere_201412_D_1',
|
||
|
20150301 => 'fichier_france_entiere_201503_D_1',
|
||
|
);
|
||
|
|
||
|
$identite = array();
|
||
|
|
||
|
if ($this->companyEvenDateStop === null) {
|
||
|
$date = date('Ymd');
|
||
|
} else {
|
||
|
$date = $this->companyEvenDateStop;
|
||
|
}
|
||
|
|
||
|
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
||
|
$sql = $db->select()
|
||
|
->from(array('e'=>'insee_even'), array(
|
||
|
'CONCAT(LPAD(e.insSIREN,9,0), LPAD(e.insNIC,5,0)) AS Siret',
|
||
|
'LPAD(e.insSIREN,9,0) AS Siren',
|
||
|
'LPAD(e.insNIC,5,0) AS Nic',
|
||
|
'insSIEGE AS Siege',
|
||
|
'insNOMEN AS Nom',
|
||
|
'insCODPOS AS CP',
|
||
|
'insCJ AS FJ',
|
||
|
'insAPEN700 AS NafEnt',
|
||
|
'insAPEN700 AS NafEtab',
|
||
|
'insTEFEN AS EffEnTr',
|
||
|
'insEFENCENT AS Effectif',
|
||
|
'insDCRET AS DateCreaEt',
|
||
|
'insDCREN AS DateCreaEn',
|
||
|
'insEVE',
|
||
|
), 'insee')
|
||
|
->joinLeft(array('i'=>'insee_notices'), 'i.insSIREN=e.insSIREN AND i.insNIC=e.insNIC', array(
|
||
|
'insRECME AS RECME',
|
||
|
), 'insee')
|
||
|
->where('e.insSIREN = ?', $siren)
|
||
|
->where('idFlux < ?',$date)
|
||
|
->order('idFlux DESC')->order('insSIEGE DESC')->limit(1);
|
||
|
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_ASSOC);
|
||
|
if ($result !== null) {
|
||
|
$identite = $result;
|
||
|
}
|
||
|
// --- Recherche dans le stock
|
||
|
else {
|
||
|
$notices = array_reverse($notices, true);
|
||
|
foreach($notices as $noticeDate => $notice) {
|
||
|
if ($date > $noticeDate) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
$sql = $db->select()
|
||
|
->from(array('e'=>$notice), array(
|
||
|
'CONCAT(LPAD(SIREN,9,0), LPAD(NIC,5,0)) AS Siret',
|
||
|
'LPAD(SIREN,9,0) AS Siren',
|
||
|
'LPAD(NIC,5,0) AS Nic',
|
||
|
'SIEGE AS Siege',
|
||
|
'NOMEN_LONG AS Nom',
|
||
|
'CODPOS AS CP',
|
||
|
'CJ AS FJ',
|
||
|
'APEN700 AS NafEnt',
|
||
|
'APEN700 AS NafEtab',
|
||
|
'TEFEN AS EffEnTr',
|
||
|
'EFENCENT AS Effectif',
|
||
|
'DCRET AS DateCreaEt',
|
||
|
'insDCREN AS DateCreaEn',
|
||
|
), 'historiques')
|
||
|
->joinLeft(array('i'=>'insee_notices'), 'i.insSIREN=e.SIREN AND i.insNIC=e.NIC', array(
|
||
|
'insRECME AS RECME',
|
||
|
), 'insee')
|
||
|
->where('e.insSIREN = ?', $siren)
|
||
|
->where('idFlux < ?',$date)
|
||
|
->order('idFlux DESC')->order('insSIEGE DESC')->limit(1);
|
||
|
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_ASSOC);
|
||
|
if ($result !== null) {
|
||
|
$identite = $result;
|
||
|
}
|
||
|
}
|
||
|
if (count($identite)>0) {
|
||
|
// --- Actif
|
||
|
$identite['Actif'] = 1;
|
||
|
if (array_key_exists('insEVE', $identite)) {
|
||
|
if ( in_array($identite['insEVE'], array(
|
||
|
'M0F', // Fermeture de l'entreprise
|
||
|
'FF', // Fermeture de l'entreprise
|
||
|
'400', // Suppression d'un double
|
||
|
'410', // Cessation juridique de l'entreprise
|
||
|
'420', // Absence d'activité de l'entreprise (cessation économique de l'entreprise)
|
||
|
'SC', // Suppression par le calage
|
||
|
'SU', // Cessation juridique
|
||
|
'SS', // Fermeture (ou désactivation) siège
|
||
|
'RI', // Refus d'inscription du SIREN au RCS
|
||
|
)) ) {
|
||
|
$identite['Actif'] = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Capital
|
||
|
$sql = $db->select()
|
||
|
->from('rncs_modifs', array('valeur'), 'jo')
|
||
|
->where('champs = ?', 'capitalMontant')
|
||
|
->where('siren = ? ', $siren)
|
||
|
->where('flux < ?', $date)
|
||
|
->order('flux DESC')->limit(1);
|
||
|
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_OBJ);
|
||
|
$identite['Capital'] = '';
|
||
|
if ($result !== null) {
|
||
|
$identite['Capital'] = $result->valeur;
|
||
|
}
|
||
|
|
||
|
// --- Situation Juridique
|
||
|
$identite['SituationJuridique'] = '';
|
||
|
$tabProcol = $this->getAnnoncesLegales($siren, 0, 'P', false);
|
||
|
if ( count($tabProcol) > 0 ) {
|
||
|
$tabDates = array();
|
||
|
foreach ($tabProcol as $iProcol => $procol) {
|
||
|
$tabDates[] = $procol['dateJugement'];
|
||
|
}
|
||
|
rsort($tabDates);
|
||
|
$dateProcol = str_replace('-','',$tabDates[0])*1;
|
||
|
if ($this->dureePlan>0 && date('Ymd')<$this->finPlan) {
|
||
|
$identite['SituationJuridique'] = 'PL';
|
||
|
}
|
||
|
// Plan révolu
|
||
|
elseif ($this->dureePlan>0 && date('Ymd')>=$this->finPlan) {
|
||
|
$identite['SituationJuridique'] = '';
|
||
|
}
|
||
|
// Appel de jugement
|
||
|
elseif ($this->appelJugement) {
|
||
|
$identite['SituationJuridique'] = 'PA';
|
||
|
}
|
||
|
// En cours de procédure
|
||
|
else {
|
||
|
$identite['SituationJuridique'] = 'P';
|
||
|
}
|
||
|
} elseif (count($this->getAnnoncesLegales($siren, 0, 'A', false)) > 0) {
|
||
|
$identite['SituationJuridique'] = 'A';
|
||
|
} elseif (count($this->getAnnoncesLegales($siren, 0, 'D', false)) > 0) {
|
||
|
$identite['SituationJuridique'] = 'D';
|
||
|
}
|
||
|
// Fin Situation Juridique
|
||
|
|
||
|
return $identite;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param string $siren
|
||
|
* @param int $nic
|
||
|
* @param int $id
|
||
|
* @param string $forceVerif
|
||
|
* @param string $accesDist
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getIdentiteEntreprise($siren, $nic=0, $id=0, $forceVerif=false, $accesDist=true)
|
||
|
{
|
||
|
if($this->debugtime) {
|
||
|
$timer = array('debutIdentite'=>microtime(true));
|
||
|
$tdebIni = microtime(1);
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;getIdentiteEntreprise Début ---\n", FILE_APPEND);
|
||
|
}
|
||
|
|
||
|
$siren = $siren*1;
|
||
|
$nic = $nic*1;
|
||
|
$id = $id*1;
|
||
|
$limit = '';
|
||
|
if ($id>0 && $siren<1000) $where=" id=$id ";
|
||
|
elseif ($nic<>0) $where=" siren=$siren AND nic=$nic ";
|
||
|
elseif ($siren<>0) $where=" siren=$siren ";//AND siege=1 ";
|
||
|
$listeEtab = $this->iDb->select('jo.etablissements e',
|
||
|
"e.id, e.source, e.source_id, e.triCode, e.autre_id, LPAD(e.siren,9,0) as siren, LPAD(e.nic,5,0) as nic, e.siege, e.autre_id, ".
|
||
|
"e.raisonSociale, e.enseigne, e.sigle, 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, LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep, ".
|
||
|
"e.capital, e.capitalDev, e.capitalSrc, CONCAT(e.siren, e.nic) as siret, e.actif, ".
|
||
|
"e.age_entrep, e.age_etab, e.tca, e.tcaexp, e.teff_entrep, e.teff_etab",
|
||
|
"$where ORDER BY siege DESC, actif DESC, nic DESC $limit", false, MYSQL_ASSOC);
|
||
|
|
||
|
// Récupération des résultats
|
||
|
if (count($listeEtab) > 0) {
|
||
|
$etab = $listeEtab[0];
|
||
|
$nic = $etab['nic'];
|
||
|
}
|
||
|
$timer['tableEtablissements'] = microtime(true);
|
||
|
|
||
|
// Si aucun résultat et siren est valide, on part chez Infogreffe
|
||
|
if ($accesDist && count($listeEtab) == 0 && $this->valideSiren($siren) ) {
|
||
|
$iGeffes = new Metier_Partenaires_MGreffes($this->iDb);
|
||
|
$etabG = $iGeffes->getIdentite($siren);
|
||
|
if ($etabG) {
|
||
|
$adr = $this->structureVoie($etabG['Adresse']);
|
||
|
// Date de dernière MAJ
|
||
|
$lastMaj = str_replace('-','',$etabG['DateRadiation'])*1;
|
||
|
if (str_replace('-','',$etabG['DateCreation'])*1>$lastMaj)
|
||
|
$lastMaj = str_replace('-','',$etabG['DateCreation'])*1;
|
||
|
if (str_replace('-','',$etabG['DateUpdate'])*1>$lastMaj)
|
||
|
$lastMaj = str_replace('-','',$etabG['DateUpdate'])*1;
|
||
|
|
||
|
$etab = array(
|
||
|
'id' => $etabG['id'],
|
||
|
'siret' => $etabG['Siret'],
|
||
|
'siege' => $etabG['Siege'],
|
||
|
'raisonSociale' => $etabG['Nom'],
|
||
|
'sigle' => $etabG['Sigle'],
|
||
|
'enseigne' => $etabG['Enseigne'],
|
||
|
'Adresse' => $etabG['Adresse'],
|
||
|
'adr_comp' => $etabG['Adresse2'],
|
||
|
'adr_num' => $adr['num'],
|
||
|
'adr_btq' => $adr['adr_btq'],
|
||
|
'adr_typeVoie' => $adr['typeVoie'],
|
||
|
'adr_libVoie' => $adr['libVoie'],
|
||
|
'adr_dep' => substr($etabG['CP'],0,2),
|
||
|
'adr_cp' => $etabG['CP'],
|
||
|
'adr_ville' => $etabG['Ville'],
|
||
|
'tel' => $etabG['Tel'],
|
||
|
'fax' => $etabG['Fax'],
|
||
|
'cj' => $etabG['FJ'],
|
||
|
'siren' => $etabG['Siren'],
|
||
|
'nic' => $etabG['Nic'],
|
||
|
'actif' => $etabG['Actif'],
|
||
|
'ape_etab' => $etabG['NafEtab'],
|
||
|
'ape_entrep' => $etabG['NafEnt'],
|
||
|
'autre_id' => $etabG['NumRC'],
|
||
|
'dateMAJ' => Metier_Util_Date::dateT('Ymd','Y-m-d',$lastMaj),
|
||
|
);
|
||
|
}
|
||
|
$timer['accesInfogreffeCarInconnu'] = microtime(true);
|
||
|
}
|
||
|
|
||
|
// Informations locales issues de la table infos_entrep
|
||
|
if ($siren>100) {
|
||
|
$info = $this->iDb->select('jo.infos_entrep',
|
||
|
"raisonSociale, isin, nscrl, tel, fax, web, mail, latitude, longitude, precis, dateCreation, dateFermeture, naf, naf_lib, ca, effectif, nbEtab, activite, LPAD(sirenDoublon,9,'0') AS sirenDoublon, waldec",
|
||
|
"siren=$siren", false, MYSQL_ASSOC);
|
||
|
if ( count($info)>0 ) {
|
||
|
$tab=$info[0];
|
||
|
$waldec = $tab['waldec'];
|
||
|
if ( !array_key_exists('sirenDoublon', $tab) ) {
|
||
|
$info = $this->iDb->select('jo.infos_entrep', "LPAD(siren,9,'0') AS sirenDoublon", "sirenDoublon=$siren", false, MYSQL_ASSOC);
|
||
|
if ( count($info)>0 ) {
|
||
|
$tab['sirenDoublon']=$info[0]['sirenDoublon'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$insee = $this->iDb->select('jo.etablissements', "CONCAT(LPAD(SIREN,9,0), LPAD(NIC,5,0)) AS siret",
|
||
|
"SIREN=$siren AND SIEGE=1 ORDER BY ACTIF%10 DESC, NIC DESC", false, MYSQL_ASSOC);
|
||
|
if (count($insee) > 0) {
|
||
|
$siretSiege = $insee[0]['siret'];
|
||
|
}
|
||
|
|
||
|
$timer['infosEntrep']=microtime(true);
|
||
|
}
|
||
|
|
||
|
// Informations INSEE
|
||
|
$moisNonDiff = 0;
|
||
|
if ($siren>100) {
|
||
|
if ($nic>0) $strNic="AND NIC=$nic";
|
||
|
else $strNic="AND NIC<100000 AND SIEGE=1";
|
||
|
$insee = $this->iDb->select('insee.identite',
|
||
|
'ACTIF%10 AS ACTIF, actifEco%10 AS actifEco, NOM, NOM2, SIGLE, ENSEIGNE, ADR_NUMVOIE, ADR_BTQ, ADR_TYPVOIE, ADR_LIBVOIE, ADR_LIBCOM, ADR_CP, ADR_COMP, ADR_DISTSP, PAYS, DCREN, SIEGE, AUXILT, SAISONAT, CJ, CIVILITE, NBETAB, APE_ENT, APE_ETAB, PROCOL, PROCOL_TYPE, PROCOL_DATE, CAPITAL, EFF_ENT, NUMRC, TEL, FAX, DIR_FCT, DIR_IDEN, DIR_DATEN, DIR_LIEUN, CAPITAL_DATE, CAPITAL_DEV, DCRET, TEFF_ENT, ADR_DEP, LPAD(ADR_COM,3,0) AS ADR_COM, TCA, TCAEXP, EFF_ET, TEFF_ET, CODEVOIE, DATE_MAJ, APRM, ACTIVNAT, ORIGINE, MODET, EXPLET, LIEUACT, ACTISURF, DEFET, MODEN, PRODPART, EXPLEN, MONOREG, REGIMP, MONOACT, DEFEN, DEFET, IDENTITE_PRE, insL1_NOMEN, insL2_COMP, insL3_CADR, insL4_VOIE, insL5_DISP, insL6_POST, insL7_ETRG, dateMajRNVP, insCATEGORIE, insIND_PUBLIPO, RPET, ARRONET, CTONET, DU, TU, UU, TCD, ZEMET, ESAANN, ESAAPEN, DREACTET, AMINTRET, DREACTEN, AMINTREN, NOMEN_LONG, CEDEX, EPCI, NOM_COM, NATETAB, PRODET, PRODEN, hexavia',
|
||
|
"SIREN=$siren $strNic ORDER BY SIEGE DESC, ACTIF DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($insee) > 0) {
|
||
|
$tabInsee = $insee[0];
|
||
|
$tabNotice = $this->getInfosNotice($siren, $nic);
|
||
|
$tabInsee['TCA_AN'] = $tabNotice['insEAEANT'];
|
||
|
$tabInsee['RECME'] = $tabNotice['insRECME'];
|
||
|
// On force l'indicateur "actifEco" à 0 si l'établissement est juridiquement inactif
|
||
|
if ($tabInsee['ACTIF']*1==0) $tabInsee['actifEco']=0;
|
||
|
if (trim($tabInsee['CODEVOIE'])=='') {
|
||
|
$codeCommune = $tabInsee['ADR_DEP'].sprintf("%03s",$tabInsee['ADR_COM']);
|
||
|
$tabInsee['CODEVOIE']=$this->getCodeVoieRivoli($codeCommune, $tabInsee['ADR_TYPVOIE'], $tabInsee['ADR_LIBVOIE']);
|
||
|
}
|
||
|
}
|
||
|
// Siren absent de l'Insee
|
||
|
else {
|
||
|
$tabInsee = array(
|
||
|
'CIVILITE' => 0,
|
||
|
'NBETAB' => 1,
|
||
|
'TEL' => $etab['tel'],
|
||
|
'FAX' => $etab['fax'],
|
||
|
'Web' => '',
|
||
|
'Mail' => '',
|
||
|
'CJ' => $etab['cj'],
|
||
|
'CJ_lib' => $this->getLibelleFJ($etab['cj']),
|
||
|
'ACTIF' => $etab['actif'],
|
||
|
'APE_ETAB' => $etab['ape_etab'] ? $etab['ape_etab'] : $etab['ape_entrep'],
|
||
|
'APE_ENT' => $etab['ape_entrep'] ? $etab['ape_entrep'] : $etab['ape_etab'],
|
||
|
'CAPITAL' => $etab['capital'],
|
||
|
'CAPITAL_DEV' => $etab['capitalDev'],
|
||
|
'ADR_DEP' => $etab['adr_dep'],
|
||
|
'TEFF_ENT' => $etab['teff_entrep'],
|
||
|
'DEFEN' => '',
|
||
|
'TEFF_ET' => $etab['teff_etab'],
|
||
|
'DEFET' => '',
|
||
|
'TCA' => $etab['tca'],
|
||
|
'TCA_AN' => '',
|
||
|
'TCAEXP' => $etab['tcaexp'],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
// Nombre d'etablissements
|
||
|
$nbEtab = 0;
|
||
|
$tabTmp = $this->iDb->select('jo.etablissements', 'count(*) AS nbEtabs',
|
||
|
"siren=$siren AND NIC<100000 AND ACTIF%10=1", false, MYSQL_ASSOC);
|
||
|
if ( count($tabTmp)>0 ) {
|
||
|
$nbEtab = $tabTmp[0]['nbEtabs'];
|
||
|
}
|
||
|
|
||
|
$inseeND = $this->iDb->select('insee.insee_nondiff', 'siren, mois, dateInsert',"siren=$siren",false,MYSQL_ASSOC);
|
||
|
if ( count($inseeND)>0 ) {
|
||
|
$moisNonDiff = $tabTmp[0]['mois'];
|
||
|
}
|
||
|
$timer['tableIdentite']=microtime(true);
|
||
|
}
|
||
|
// Default
|
||
|
else {
|
||
|
$tabInsee = array(
|
||
|
'CIVILITE' => 0,
|
||
|
'NBETAB' => 1,
|
||
|
'TEL' => $etab['tel'],
|
||
|
'FAX' => $etab['fax'],
|
||
|
'Web' => '',
|
||
|
'Mail' => '',
|
||
|
'CJ' => $etab['cj'],
|
||
|
'CJ_lib' => $this->getLibelleFJ($etab['cj']),
|
||
|
'ACTIF' => $etab['actif'],
|
||
|
'APE_ETAB' => $etab['ape_etab']?$etab['ape_etab']:$etab['ape_entrep'],
|
||
|
'APE_ENT' => $etab['ape_entrep']?$etab['ape_entrep']:$etab['ape_etab'],
|
||
|
'CAPITAL' => '',
|
||
|
'CAPITAL_DEV' => '',
|
||
|
'ADR_DEP' => $etab['adr_dep'],
|
||
|
);
|
||
|
$nbEtab = 'N/C';
|
||
|
}
|
||
|
|
||
|
// Complement Identitaire
|
||
|
if (intval($siren) > 100 && count($info)==0) {
|
||
|
$idComp = $this->getIdentitePart($siren, $etab['raisonSociale'], $etab['enseigne'], $etab['sigle'], 0, $accesDist);
|
||
|
$tab = $idComp;
|
||
|
$timer['getIdentitePart']=microtime(true);
|
||
|
}
|
||
|
|
||
|
// Géocodage de l'adresse
|
||
|
$mMap = new Metier_Partenaires_MMap(false, $this->iDb);
|
||
|
$mMap->geoCodeAdresse($etab['adr_num'], '', $etab['adr_typeVoie'], $this->getCodeVoie($etab['adr_typeVoie']),
|
||
|
$etab['adr_libVoie'], $etab['adr_cp'], $etab['adr_ville'], 'France',
|
||
|
trim($tabInsee['ADR_DEP'].$tabInsee['ADR_COM'].$tabInsee['CODEVOIE']));
|
||
|
$tab['latitude'] = $mMap->latitudeDec;
|
||
|
$tab['longitude'] = $mMap->longitudeDec;
|
||
|
$tab['altitude'] = $mMap->altitude;
|
||
|
$tab['precis'] = $mMap->precision;
|
||
|
$timer['geoCodage'] = microtime(true);
|
||
|
|
||
|
// Accès provisoire à AMABIS
|
||
|
$repAmabis = array();
|
||
|
if ($accesDist) {
|
||
|
if($this->debugtime) {
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MAmabis Avant\n", FILE_APPEND);
|
||
|
$tdeb = microtime(1);
|
||
|
}
|
||
|
|
||
|
$iAmabis = new Metier_Partenaires_MAmabis($this->iDb);
|
||
|
$repAmabis = $iAmabis->getZonage($etab['adr_num'], $etab['adr_btq'], $etab['adr_typeVoie'], $etab['adr_libVoie'],
|
||
|
$etab['adr_cp'], $etab['adr_ville'], trim($tabInsee['ADR_DEP'].$tabInsee['ADR_COM'].$tabInsee['CODEVOIE']),
|
||
|
false, 'TEST', false);
|
||
|
$duree = round(microtime(1)-$tdeb,3);
|
||
|
|
||
|
if($this->debugtime) {
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MAmabis APRES ($duree s)\n", FILE_APPEND);
|
||
|
$timer['zonesPrioritaires'] = microtime(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// N° de TVA Intracommunautaire
|
||
|
$vatNumber = 'FR00000000000';
|
||
|
$vatDefined = false;
|
||
|
if (intval($siren) > 100) {
|
||
|
if($this->debugtime) {
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MTva Avant\n", FILE_APPEND);
|
||
|
$tdeb = microtime(1);
|
||
|
}
|
||
|
|
||
|
$iTva = new Metier_Partenaires_MTva($siren, $accesDist, $this->iDb);
|
||
|
$vatNumber = $iTva->vatNumber;
|
||
|
$vatDefined = $iTva->vatDefined;
|
||
|
|
||
|
if($this->debugtime) {
|
||
|
$duree=round(microtime(1)-$tdeb,3);
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MTva APRES ($duree s)\n", FILE_APPEND);
|
||
|
$timer['tvaIntra']=microtime(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$nom = trim($etab['raisonSociale']);
|
||
|
if ($nom=='') $nom = preg_replace('/,.*$/','',$tabInsee['IDENTITE_PRE']);
|
||
|
$nom2 = $tel = $fax = '';
|
||
|
if (strtoupper(trim($tabInsee['NOM2'])) != strtoupper(trim($etab['sigle']))) {
|
||
|
$nom2 = trim($tabInsee['NOM2']);
|
||
|
}
|
||
|
|
||
|
if (trim($tab['tel']) != '') $tel = trim($tab['tel']);
|
||
|
elseif ($tabInsee['TEL'] != '') $tel = implode('.', str_split($tabInsee['TEL'],2));
|
||
|
|
||
|
if (trim($tab['fax']) != '') $fax = trim($tab['fax']);
|
||
|
elseif ($tabInsee['FAX'] != '') $fax = implode('.', str_split($tabInsee['FAX'],2));
|
||
|
|
||
|
if (intval($siren) > 0) {
|
||
|
if($this->debugtime) {
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MTel Avant\n", FILE_APPEND);
|
||
|
$tdeb = microtime(1);
|
||
|
}
|
||
|
|
||
|
$iTel = new Metier_Partenaires_MTel(false, $this->iDb);
|
||
|
$tmp = $iTel->getTel($siren, $nic, true, 1);
|
||
|
|
||
|
if($this->debugtime) {
|
||
|
$duree=round(microtime(1)-$tdeb,3);
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MTel APRES ($duree s)\n", FILE_APPEND);
|
||
|
}
|
||
|
|
||
|
$activitePJ_An8='';
|
||
|
foreach ($tmp as $tmp2) {
|
||
|
if ($tmp2['typeTel']=='tel' && ($tel==''||$tel==trim($tab['tel'])) )
|
||
|
$tel=implode('.', str_split($tmp2['telephone'],2));
|
||
|
if ($tmp2['typeTel']=='fax' && ($fax==''||$fax==trim($tab['fax'])) )
|
||
|
$fax=implode('.', str_split($tmp2['telephone'],2));
|
||
|
if ($tmp2['typeTel']=='web' && $tab['web']=='') $tab['web']=$tmp2['infoTel'];
|
||
|
if ($tmp2['typeTel']=='mail' && $tab['mail']=='') $tab['mail']=$tmp2['infoTel'];
|
||
|
if ($tmp2['typeTel']=='an8') $activitePJ_An8=$tmp2['infoTel'];
|
||
|
}
|
||
|
$timer['telFax']=microtime(true);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Type d'exploitation
|
||
|
* 0 : N/C
|
||
|
* 1 : Locataire d'un fond de commerce
|
||
|
* 2 : Loueur d'un fond de commerce
|
||
|
* 3 : Prestataire de personnel
|
||
|
* 10: Exploitation directe
|
||
|
* 11: Sans activité ???
|
||
|
*/
|
||
|
$typeExploitation=0;
|
||
|
if (intval($siren) > 100 && strtoupper($tabInsee['EXPLET']) == 'O') {
|
||
|
switch ($tabInsee['PRODPART']*1) {
|
||
|
case 1: // Locataire d'un fond de commerce
|
||
|
$tabAnn2 = $this->getAnnoncesLegales($siren, 0, array(5700));
|
||
|
if (count($tabAnn2)>0) $typeExploitation=0;
|
||
|
else $typeExploitation=1;
|
||
|
break;
|
||
|
case 2: // Loueur d'un fond de commerce
|
||
|
case 3: // Prestataire de personnel
|
||
|
$typeExploitation = $tabInsee['PRODPART']*1;
|
||
|
break;
|
||
|
default:
|
||
|
if ( !($tabInsee['CJ']>=7000 && $tabInsee['CJ']<8000) && !($tabInsee['CJ']>=9000 && $tabInsee['CJ']<10000) ) {
|
||
|
if ($tabInsee['ORIGINE']*1==6) { // Prise en location-gérance
|
||
|
$typeExploitation=1; // Locataire d'un fond de commerce
|
||
|
} elseif ($tabInsee['ORIGINE']*1==1 || // Création pure
|
||
|
$tabInsee['ORIGINE']*1==3 || // Achat
|
||
|
$tabInsee['ORIGINE']*1==4) { // Apport
|
||
|
/*
|
||
|
'2'=>'Réinstallation après transfert',
|
||
|
'5'=>'Reprise au conjoint ou apport reçu',
|
||
|
|
||
|
'7'=>'Partage',
|
||
|
'8'=>'Reprise',
|
||
|
'9'=>'Autre modalité d\'acquisition',
|
||
|
'A'=>'Reprise globale d\'une exploitation agricole',
|
||
|
'B'=>'Poursuite de l\'exploitation agricole par le conjoint',
|
||
|
'C'=>'Transfert de propriété d\'une exploitation agricole',
|
||
|
'D'=>'Apport d\'exploitation(s) agricole(s) individuelle(s)',
|
||
|
'E'=>'Reprise totale ou partielle d\'exploitation individuelle',
|
||
|
*/
|
||
|
$typeExploitation = 10;
|
||
|
} elseif ($nbEtab<2) {
|
||
|
$tabAnn = $this->getAnnoncesLegales($siren, 0, 'L');
|
||
|
if (count($tabAnn)>0) {
|
||
|
if ($tabAnn[0]['DateParution']>$tabInsee['DCRET'] && ($tabAnn[0]['Departement']==$tabInsee['ADR_DEP']
|
||
|
|| $tabAnn[0]['Departement']==substr(''.$tabInsee['ADR_DEP'].''.$tabInsee['ADR_COM'],O,3)*1)) {
|
||
|
$typeExploitation=1; // Locataire d'un fond de commerce
|
||
|
}
|
||
|
} elseif (count($this->getAnnoncesLegales($siren, 0, 'G'))>0) {
|
||
|
$typeExploitation=2; // Loueur d'un fond de commerce
|
||
|
}
|
||
|
} elseif ($tabInsee['ORIGINE']*1 <>0 &&
|
||
|
$tabInsee['ORIGINE']*1 <>8 &&
|
||
|
$tabInsee['ORIGINE']*1 <>9 &&
|
||
|
$tabInsee['ORIGINE'] <>'NR') {
|
||
|
$typeExploitation=10; // Exploitation directe
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
$timer['typeExploitation'] = microtime(true);
|
||
|
|
||
|
// Recherche de prédécesseur ou successeur
|
||
|
if (intval($siren) > 100) {
|
||
|
$tabAssoc = $this->getSiretAssoc($siren, $nic);
|
||
|
if (count($tabAssoc)>0) {
|
||
|
if (isset($tabAssoc['pre'])) {
|
||
|
// Il y a un prédécesseur
|
||
|
if ($tabInsee['ORIGINE']*1==0 ||
|
||
|
$tabInsee['ORIGINE']*1==1 ||
|
||
|
$tabInsee['ORIGINE']*1==9 ||
|
||
|
$tabInsee['ORIGINE']=='NR')
|
||
|
$tabInsee['ORIGINE']=2; // Transfert
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$timer['siretPrecSuivant']=microtime(true);
|
||
|
|
||
|
// Code Pays
|
||
|
$codePaysIso2 = 'FR';
|
||
|
if ($tabInsee['ADR_DEP'] > 98) {
|
||
|
$codePaysInsee=$tabInsee['ADR_COM'];
|
||
|
$tabTmp = $this->iDb->select( 'jo.tabPays j, insee.insee_tabPays i',
|
||
|
'j.codPays, j.numPays, j.codPays3, j.codePaysInpi, j.libPays, i.LIBCOG, i.ACTUAL',
|
||
|
"j.codePaysInsee=$codePaysInsee AND j.codePaysInsee=substring( i.COG, 3, 3 ) AND i.ACTUAL IN (1,4) AND j.numPays is NOT NULL", false, MYSQL_ASSOC);
|
||
|
if (count($tabTmp)==1) {
|
||
|
$codePaysIso2=$tabTmp[0]['codPays'];
|
||
|
} else {
|
||
|
$codePaysIso2='';
|
||
|
foreach ($tabTmp as $tabTmp2) {
|
||
|
if (trim(preg_replace('/[^A-Z]/','',strtoupper(strtr($tabTmp2['libPays'], 'àáâãäåæçèéêëìíîïðñòóôõöùúûüýÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝ', "aaaaaaaceeeeiiiionooooouuuuyyAAAAAAACEEEEIIIIONOOOOOUUUUY")))) == trim(preg_replace('/[^A-Z]/','',strtoupper($tabTmp2['LIBCOG'])))) {
|
||
|
$codePaysIso2 = $tabTmp2['codPays'];
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
// Exception lié à anomalies de données INSEE
|
||
|
if ($codePaysIso2=='' && $codePaysInsee==237) $codePaysIso2='KR';
|
||
|
}
|
||
|
}
|
||
|
$timer['codePays']=microtime(true);
|
||
|
|
||
|
$tabIris = $this->getInfosIris($tabInsee['ADR_DEP'].$tabInsee['ADR_COM'], substr($tabInsee['CODEVOIE'],0,4),
|
||
|
$etab['adr_num'], $etab['adr_btq'], $etab['adr_typeVoie'], $etab['adr_libVoie']);
|
||
|
if ($tabInsee['CODEVOIE']=='') {
|
||
|
// On récupere le code Rivoli s'il est absent de SIRENE (cf. doc Sirene)
|
||
|
$tabInsee['CODEVOIE']=@$tabIris['Rivoli'];
|
||
|
}
|
||
|
$timer['codeIris']=microtime(true);
|
||
|
|
||
|
// Est-ce un ancien établissement siège ?
|
||
|
$ancienSiege=false;
|
||
|
$dateFinSiege=0;
|
||
|
if (intval($siren) > 100 ) {
|
||
|
if ($etab['siege']==0 || ($etab['siege']==1 && $tabInsee['ACTIF']==0)) {
|
||
|
$dateFinSiege = $this->isAncienSiege($siren,$nic);
|
||
|
if ($dateFinSiege>19000101) $ancienSiege=true;
|
||
|
}
|
||
|
}
|
||
|
$timer['ancienSiege']=microtime(true);
|
||
|
|
||
|
$tabInsee['actifEcoDate']='';
|
||
|
$tabInsee['actifEcoType']='';
|
||
|
|
||
|
if (intval($siren) > 100 && $tabInsee['ACTIF']*1 == 1 && $tabInsee['actifEco']*1 == 0) {
|
||
|
// L'établissement est actif juridiquement à l'INSEE mais sans activité économique
|
||
|
$tabTmp=$this->iDb->select('insee.insee_even', 'insEVE, IF(insDATEVE=0, idFlux*1, insDATEVE) AS insDATEVE',
|
||
|
"insSIREN=$siren AND insNIC=$nic AND insEVE IN ('OD','TD','MPF','MNP','420','425','620','621','650') ORDER BY insDATEVE DESC", false, MYSQL_ASSOC);
|
||
|
if (count($tabTmp)>0) {
|
||
|
$tabModif=$tabTmp[0];
|
||
|
switch(''.$tabModif['insEVE']) {
|
||
|
case 'OD':
|
||
|
case 'TD':
|
||
|
case '420': // Absence d'activité de l'entreprise (cessation économique de l.entreprise)
|
||
|
case '425': // Absence d'activité d'une entreprise suite à une mise à jour au répertoire //
|
||
|
case '620':
|
||
|
case '621':
|
||
|
case '650': // Fermé économiquement
|
||
|
$tabInsee['actifEcoType']='ECOF';
|
||
|
$tabInsee['actifEcoDate']=$tabModif['insDATEVE'];
|
||
|
break;
|
||
|
case 'MPF': // Présumé Fermé par la trimestrielle Insee
|
||
|
$tabInsee['actifEcoType']='PFER';
|
||
|
$tabInsee['actifEcoDate']=$tabModif['insDATEVE'];
|
||
|
break;
|
||
|
case 'MNP': // Présumé Fermé par la trimestrille NPAI
|
||
|
$tabInsee['actifEcoType']='NPAI';
|
||
|
$tabInsee['actifEcoDate']=$tabModif['insDATEVE'];
|
||
|
break;
|
||
|
default:
|
||
|
$tabInsee['actifEco']=1;
|
||
|
$tabInsee['actifEcoDate']='';
|
||
|
$tabInsee['actifEcoType']='';
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$dir1Genre='';
|
||
|
if ($tabInsee['CIVILITE']==1) $dir1Genre='M';
|
||
|
elseif ($tabInsee['CIVILITE']==2) $dir1Genre='F';
|
||
|
|
||
|
$tabRet = array(
|
||
|
'id' => $etab['id'],
|
||
|
'Siret' => $etab['siret'],
|
||
|
'SiretSiege' => $siretSiege,
|
||
|
'AncienSiege' => $ancienSiege,
|
||
|
'AncienSiegeDateFin'=> $dateFinSiege,
|
||
|
'Siege' => $etab['siege'],
|
||
|
'Tribunal'=> strtr($etab['triCode'],array('préfec'=>'','sous-p'=>'','Déclar'=>'')),
|
||
|
'Nom' => $nom, //EIRL
|
||
|
'Nom2' => $nom2,
|
||
|
'Sigle' => $etab['sigle'],
|
||
|
'Enseigne' => $etab['enseigne'], //EIRL
|
||
|
'Adresse' => trim(preg_replace('/ +/', ' ', trim( $etab['adr_num'] .' '. $etab['adr_btq'] .' '.$etab['adr_typeVoie'] .' '. $etab['adr_libVoie']))),
|
||
|
'Adresse2' => trim(preg_replace('/ +/', ' ', $etab['adr_comp'])),
|
||
|
'AdresseNum' => $etab['adr_num'],
|
||
|
'AdresseBtq' => $etab['adr_btq'],
|
||
|
'AdresseVoie' => $etab['adr_typeVoie'],
|
||
|
'AdresseRue' => $etab['adr_libVoie'],
|
||
|
'AdresseDistSP' => $tabInsee['ADR_DISTSP'],
|
||
|
'CP' => $etab['adr_cp'],
|
||
|
'Ville' => $etab['adr_ville'],
|
||
|
'Pays' => $tabInsee['PAYS'],
|
||
|
'PaysIso2' => $codePaysIso2,
|
||
|
'Civilite' => $tabInsee['CIVILITE'],
|
||
|
'NbEtab' => $nbEtab,
|
||
|
'Tel' => $tel,
|
||
|
'Fax' => $fax,
|
||
|
'Web' => $tab['web'],
|
||
|
'Mail' => $tab['mail'],
|
||
|
'GeoLat' => $tab['latitude'],
|
||
|
'GeoLon' => $tab['longitude'],
|
||
|
'GeoAlt' => $tab['altitude'],
|
||
|
'GeoPrecis'=> $tab['precis'],
|
||
|
'TvaNumero' => $vatNumber,
|
||
|
'TvaAttribue' => $vatDefined,
|
||
|
'FJ' => $tabInsee['CJ'],
|
||
|
'FJ_lib' => $this->getLibelleFJ($tabInsee['CJ']),
|
||
|
'RECME' => $tabInsee['RECME'],
|
||
|
'Siren' => $etab['siren'],
|
||
|
'Nic' => $etab['nic'],
|
||
|
'Actif' => $tabInsee['ACTIF'], // Etablissement juridiquement ACTIF
|
||
|
'ActifEco' => $tabInsee['actifEco'], // Etablissement économiquement ACTIF
|
||
|
'ActifEcoDate' => $tabInsee['actifEcoDate'], // Etablissement économiquement Inactif depuis
|
||
|
'ActifEcoType' => $tabInsee['actifEcoType'], // Type d'inactivité éco ECOF, NPAI, PFER ou vide
|
||
|
'NafEtab' => $tabInsee['APE_ETAB'],
|
||
|
'NafEnt' => $tabInsee['APE_ENT'],
|
||
|
'NaceEtab' => $this->getCodeNace($tabInsee['APE_ETAB']),
|
||
|
'NaceEnt' => $this->getCodeNace($tabInsee['APE_ENT']),
|
||
|
'NafEntLib' => $this->getLibelleNaf($tabInsee['APE_ENT']),
|
||
|
'NafEtabLib' => $this->getLibelleNaf($tabInsee['APE_ETAB']),
|
||
|
'AutreId' => $etab['autre_id'],
|
||
|
'Source' => $etab['source'],
|
||
|
'SourceId' => $etab['source_id'],
|
||
|
'Isin' => $tab['isin'],
|
||
|
'Capital' => $etab['capital'],//IKI
|
||
|
'CapitalDev' => $etab['capitalDev'],
|
||
|
'CapitalSrc' => $etab['capitalSrc'],
|
||
|
'DateCreaEt' => $tabInsee['DCRET'],
|
||
|
'DateCreaEn' => $tabInsee['DCREN'],
|
||
|
'SituationJuridique' => '',
|
||
|
'EffEnTr' => $tabInsee['TEFF_ENT'],
|
||
|
'EffEnTrLib' => self::$tabEffectif[intval($tabInsee['TEFF_ENT'])],
|
||
|
'EffEtTr' => $tabInsee['TEFF_ET'],
|
||
|
'EffEtTrLib' => self::$tabEffectif[intval($tabInsee['TEFF_ET'])],
|
||
|
'EffectifEtab' => $tabInsee['EFF_ET'],
|
||
|
'Effectif' => $tabInsee['EFF_ENT'],
|
||
|
'Dept' => $tabInsee['ADR_DEP'],
|
||
|
'codeCommune' => $tabInsee['ADR_COM'],
|
||
|
'TrancheCA' => $tabInsee['TCA'],
|
||
|
'TrancheCALib' => self::$tabTCA[$tabInsee['TCA']],
|
||
|
'TrancheCAexp' => $tabInsee['TCAEXP'],
|
||
|
'TrancheCAexpLib' => self::$tabTCAexp[$tabInsee['TCAEXP']],
|
||
|
'TrancheCAType' => 'I',
|
||
|
'AnneeEffEn' => $tabInsee['DEFEN'],
|
||
|
'AnneeEffEt' => $tabInsee['DEFET'],
|
||
|
'AnneeTCA' => $tabInsee['TCA_AN'],
|
||
|
'dir1Titre' => self::$tabFct[$tabInsee['DIR_FCT']],
|
||
|
'dir1NomPrenom' => preg_replace('/^EIRL\s/','',$tabInsee['DIR_IDEN']),
|
||
|
'dir1Genre' => $dir1Genre,
|
||
|
'Rivoli' => trim(substr($tabInsee['CODEVOIE'],0,4).' '.substr($tabInsee['CODEVOIE'],-1)),
|
||
|
'Hexavia' => $tabInsee['hexavia'],
|
||
|
'InfosIris' => $tabIris,
|
||
|
'NatureActivite' => $tabInsee['ACTIVNAT'], // Nature de l'activité
|
||
|
'OrigineCreation' => $tabInsee['ORIGINE'], // Origine de la création
|
||
|
'Auxiliaire' => $tabInsee['AUXILT'], // 1=Auxiliaire / 0=Non auxiliaire
|
||
|
'Saisonnalite' => $tabInsee['SAISONAT'], // P=Activité permanente / S=Activité saisonnière
|
||
|
'ACTISURF' => $tabInsee['ACTISURF'],
|
||
|
'EXPLEN' => $tabInsee['EXPLEN'],
|
||
|
'EXPLET' => $tabInsee['EXPLET'],
|
||
|
'LIEUACT' => $tabInsee['LIEUACT'],
|
||
|
'MODEN' => $tabInsee['MODEN'],
|
||
|
'MONOACT' => $tabInsee['MONOACT'],
|
||
|
'MONOREG' => $tabInsee['MONOREG'],
|
||
|
'REGIMP' => $tabInsee['REGIMP'],
|
||
|
'PRODPART' => $tabInsee['PRODPART'],
|
||
|
'GeoInfos' => $repAmabis,
|
||
|
'NonDiffusible' => $moisNonDiff,
|
||
|
'TypeExploitation' => $typeExploitation,
|
||
|
'DateMajINSEE' => str_replace('--','',Metier_Util_Date::dateT('Ymd','Y-m-d',$tabInsee['DATE_MAJ'])),
|
||
|
'APRM' => $tabInsee['APRM'],
|
||
|
'APRM_Lib' => $this->getLibelleNafa($tabInsee['APRM']),
|
||
|
'AutreSiret' => $tabAssoc,
|
||
|
'L1_NOMEN' => $tabInsee['insL1_NOMEN'], // Nom ou raison sociale de l'entreprise pour l'adressage
|
||
|
'L2_COMP' => $tabInsee['insL2_COMP'], // Complément de nom de l'entreprise pour l'adressage
|
||
|
'L3_CADR' => $tabInsee['insL3_CADR'], // Complément d'adresse pour l.adressage
|
||
|
'L4_VOIE' => $tabInsee['insL4_VOIE'], // Numéro et libellé dans la voie
|
||
|
'L5_DISP' => $tabInsee['insL5_DISP'], // Distribution spéciale
|
||
|
'L6_POST' => $tabInsee['insL6_POST'], // Ligne d'acheminement postal pour l'adressage
|
||
|
'L7_ETRG' => $tabInsee['insL7_ETRG'], // Libellé du pays pour les adresses à l'étranger
|
||
|
'IND_PUBLIPO' => $tabInsee['insIND_PUBLIPO'], // Indicateur du champ de publipostage
|
||
|
'dateMajRNVP' => $tabInsee['dateMajRNVP'],
|
||
|
'RNVP_Niveau' => 0,
|
||
|
'RPET' => $tabInsee['RPET'], //
|
||
|
'ARRONET' => $tabInsee['ARRONET'], //
|
||
|
'CTONET' => $tabInsee['CTONET'], //
|
||
|
'DU' => $tabInsee['DU'], //
|
||
|
'TU' => $tabInsee['TU'], //
|
||
|
'UU' => $tabInsee['UU'], //
|
||
|
'TCD' => $tabInsee['TCD'], //
|
||
|
'ZEMET' => $tabInsee['ZEMET'], //
|
||
|
'ESAANN' => $tabInsee['ESAANN'], //
|
||
|
'ESAAPEN' => $tabInsee['ESAAPEN'], //
|
||
|
'DREACTET' => $tabInsee['DREACTET'], //
|
||
|
'AMINTRET' => $tabInsee['AMINTRET'], //
|
||
|
'DREACTEN' => $tabInsee['DREACTEN'], //
|
||
|
'AMINTREN' => $tabInsee['AMINTREN'], //
|
||
|
'CATEGORIE' => $tabInsee['insCATEGORIE'], // Catégorie d'entreprise
|
||
|
'NOMEN_LONG' => $tabInsee['NOMEN_LONG'], // Nom ou raison sociale de l'entreprise
|
||
|
'PRODET' => $tabInsee['PRODET'],
|
||
|
'PRODEN' => $tabInsee['PRODEN'],
|
||
|
'NATETAB' => $tabInsee['NATETAB'],
|
||
|
'CEDEX' => $tabInsee['CEDEX'],
|
||
|
'EPCI' => $tabInsee['EPCI'],
|
||
|
);
|
||
|
|
||
|
// Set Identite pour les autres méthodes
|
||
|
$this->Identite = $tabRet;
|
||
|
|
||
|
// Estimation du Chiffre d'affaires
|
||
|
$cj1 = substr($tabInsee['CJ'],0,1)*1;
|
||
|
if ($tabRet['TrancheCA']*1==0 && $tabRet['AnneeTCA']*1==0 && $tabInsee['ACTIF']==1 && $tabInsee['CJ']<>1800 && $tabInsee['CJ']<>1900 && $cj1<>7 && $cj1<>8 && $cj1<>9) {
|
||
|
$caEstime = $this->getCAnafEffectif($tabInsee['APE_ENT'], $tabInsee['EFF_ENT']);
|
||
|
$tabRet['TrancheCA'] = $this->getTca($caEstime);
|
||
|
$tabRet['TrancheCALib'] = self::$tabTCA[$tabRet['TrancheCA']];
|
||
|
if ($tabRet['TrancheCA']*1>0) {
|
||
|
$tabRet['TrancheCAType'] = 'E';
|
||
|
$tabRet['AnneeTCA'] = date('Y')-2;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Si tourisme, recherche du classement
|
||
|
if (intval($siren) > 0) {
|
||
|
$tabNafTourisme = array(
|
||
|
'5510Z', // Hôtels et hébergement similaire
|
||
|
'5520Z', // Hébergement touristique et autre hébergement de co
|
||
|
'5530Z', // Terrains de camping et parcs pour caravanes ou véh
|
||
|
'702A', // Location de logements
|
||
|
'6820A', // Location de logements
|
||
|
'6820B', // Location de terrains et d'autres biens immobiliers
|
||
|
'551A', // Hôtels touristiques avec restaurant
|
||
|
'5610A', // Restauration traditionnelle
|
||
|
'741J', // Administration d'entreprises
|
||
|
'7010Z', // Activités des sièges sociaux
|
||
|
'552C', // Exploitation de terrains de camping
|
||
|
'702C', // Location d'autres biens immobiliers
|
||
|
'551C', // Hôtels touristiques sans restaurant
|
||
|
'553A', // Restauration de type traditionnel
|
||
|
);
|
||
|
if (in_array($tabInsee['APE_ENT'], $tabNafTourisme) || in_array($tabInsee['APE_ETAB'], $tabNafTourisme) ) {
|
||
|
$ret = $this->iDb->select('jo.tourisme', 'id, nom, adresse, adrCp, adrVille, nbEtoiles, typeClasse, categorie, dateClasse, tel, fax, mail, web, typeChambres, capacite', "siren=$siren AND nic=$nic", false, MYSQL_ASSOC);
|
||
|
if (isset($ret[0])) {
|
||
|
$tabRet['NafEtabLib'].=' ('.$ret[0]['nbEtoiles'].' étoiles le '.
|
||
|
Metier_Util_Date::dateT('Y-m-d','d/m/Y',$ret[0]['dateClasse']).')';
|
||
|
if ($tabRet['Tel']=='') $tabRet['Tel']=$ret[0]['tel'];
|
||
|
if ($tabRet['Fax']=='') $tabRet['Fax']=$ret[0]['fax'];
|
||
|
if ($tabRet['Web']=='') $tabRet['Web']=$ret[0]['web'];
|
||
|
if ($tabRet['Mail']=='') $tabRet['Mail']=$ret[0]['mail'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Nombre d'actions du capital si disponible
|
||
|
if ($etab['capital'] > 0) {
|
||
|
$insee=$this->iDb->select('sdv1.capitalActions',
|
||
|
'capital, deviseCapital, nbActions, actionNominale, dateInfo',
|
||
|
"siren=$siren AND capital>0 ORDER BY dateInfo DESC LIMIT 0,1",false,MYSQL_ASSOC);
|
||
|
$tabRet['CapitalNbActions']=0;
|
||
|
$tabRet['CapitalMtActions']=0;
|
||
|
if (count($insee)>0) {
|
||
|
if ($etab['capital']==$insee[0]['capital']) {
|
||
|
$tabRet['CapitalNbActions']=$insee[0]['nbActions'];
|
||
|
$tabRet['CapitalMtActions']=$insee[0]['actionNominale'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$timer['nbActionsCapital']=microtime(true);
|
||
|
|
||
|
// Numéro de TVA non défini
|
||
|
if (!$vatDefined) {
|
||
|
// Dom Tom ou étranger
|
||
|
if ($tabRet['Dept'] > 96) {
|
||
|
$tabRet['TvaFacultatif'] = 2;
|
||
|
}
|
||
|
// Micro-entreprise
|
||
|
if ($tabRet['FJ']*1 < 2000 && $tabRet['Effectif'] == 0 && $tabRet['TrancheCA'] == 0) {
|
||
|
$tabRet['TvaFacultatif'] = 1;
|
||
|
}
|
||
|
// Erreur lors de la récupération du numéro de TVA
|
||
|
if ($vatDefined === null) {
|
||
|
$tabRet['TvaFacultatif'] = 99;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Date de début d'activité de l'entreprise si absente INSEE
|
||
|
if (intval($siren) > 100 && $tabRet['DateCreaEn'] == 0) {
|
||
|
$insee = $this->iDb->select('insee.identite', 'DCREN', "SIREN=$siren AND DCREN>0 ORDER BY DCREN ASC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($insee)>0) {
|
||
|
$tabRet['DateCreaEn']=$insee[0]['DCREN'];
|
||
|
} else {
|
||
|
$tmp=$this->getAvisInsee($siren);
|
||
|
$dateCreaEn=Metier_Util_Date::dateT('Y-m-d','Ymd',$tmp['dateEtatEn']);
|
||
|
if (preg_match("/Prise d'activité/u", $tmp['etatEn']) &&
|
||
|
$dateCreaEn>19000101) {
|
||
|
$this->iDb->update('insee.identite', array(
|
||
|
'DCREN'=>$dateCreaEn),
|
||
|
"SIREN=$siren AND NIC=".$etab['nic']
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$timer['dateDebutActivite']=microtime(true);
|
||
|
|
||
|
// Adresse de domiciliation
|
||
|
$tabDom = $this->infoAdresseDom($tabRet['AdresseNum'], $tabRet['AdresseBtq'], $tabRet['AdresseVoie'],
|
||
|
$tabRet['AdresseRue'], $tabRet['Adresse2'], $tabRet['CP'], $tabRet['Ville']);
|
||
|
if (is_array($tabDom) && count($tabDom)>0) {
|
||
|
foreach($tabDom as $i=>$dom) {
|
||
|
$tabRet['AdresseDom']=1;
|
||
|
$tabRet['AdresseDomNb']=$dom['nbEntrep'];
|
||
|
$domiciliataire='';
|
||
|
if (preg_match('/^CHEZ (.*)$/i',$tabRet['Adresse2'], $matches)
|
||
|
&& !preg_match('/ M | M. | MR | MME | MLLE /i',$tabRet['Adresse2'])) {
|
||
|
$domiciliataire=$matches[1];
|
||
|
$tabRet['AdresseDom']=2;
|
||
|
}
|
||
|
$tabRet['AdresseDomEnt'][] = array( 'siren'=>$dom['siren'], 'nom'=>$dom['nom'] );
|
||
|
}
|
||
|
}
|
||
|
$timer['adresseDom']=microtime(true);
|
||
|
|
||
|
// --- Siren en doublon
|
||
|
if ($tab['sirenDoublon']>0) $tabRet['AutreSiren'] = array(
|
||
|
'listeSiren' => array(
|
||
|
'siren'=>$tab['sirenDoublon'],
|
||
|
'type' =>'doublon'
|
||
|
)
|
||
|
);
|
||
|
|
||
|
// --- Situation Juridique
|
||
|
if (intval($siren) > 100) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "=== Situation Juridique ===\n");
|
||
|
$tabProcol = $this->getAnnoncesLegales($siren, 0, 'P', false);
|
||
|
if ( count($tabProcol) > 0 ) {
|
||
|
$tabDates = array();
|
||
|
foreach ($tabProcol as $iProcol => $procol) {
|
||
|
$tabDates[] = $procol['dateJugement'];
|
||
|
}
|
||
|
rsort($tabDates);
|
||
|
$dateProcol = str_replace('-','',$tabDates[0])*1;
|
||
|
// Plan
|
||
|
if ($this->dureePlan>0 && date('Ymd')<$this->finPlan) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "Plan (PL) : ".$this->dureePlan."-".$this->finPlan."\n", FILE_APPEND);
|
||
|
$tabRet['SituationJuridique'] = 'PL';
|
||
|
}
|
||
|
// Plan révolu
|
||
|
elseif ($this->dureePlan>0 && date('Ymd')>=$this->finPlan) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "Plan revolu : ".$this->dureePlan."-".$this->finPlan."\n", FILE_APPEND);
|
||
|
$tabRet['SituationJuridique'] = '';
|
||
|
}
|
||
|
// Appel de jugement
|
||
|
elseif ($this->appelJugement) {
|
||
|
$tabRet['SituationJuridique'] = 'PA';
|
||
|
}
|
||
|
// Jugement de cloture après LJ
|
||
|
elseif ($this->SituationCloture) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "Cloture (CL) "."\n", FILE_APPEND);
|
||
|
$tabRet['SituationJuridique'] = 'CL';
|
||
|
}
|
||
|
// En cours de procédure
|
||
|
else {
|
||
|
if ($this->debug) file_put_contents('procol.log', "Procol (P) "."\n", FILE_APPEND);
|
||
|
$tabRet['SituationJuridique'] = 'P';
|
||
|
}
|
||
|
|
||
|
// RAZ SituationJuridique si cutoff plus récent que dernière procol
|
||
|
$tabTmp = $this->iDb->select('jo.scores_cutoff', 'encours, scoreSolv, scoreDir, scoreConf, DATE(dateInsert)*1 AS dateInsert, DATE(dateUpdate)*1 AS dateUpdate', "siren=$siren", false, MYSQL_ASSOC);
|
||
|
if( count($tabTmp) > 0 ) {
|
||
|
if ($tabTmp[0]['scoreSolv'] > 0) {
|
||
|
//Tri des dates de procol
|
||
|
$tabDates = array();
|
||
|
foreach ($tabProcol as $iProcol=>$procol) {
|
||
|
$tabDates[] = $procol['dateJugement'];
|
||
|
}
|
||
|
rsort($tabDates);
|
||
|
$dateProcol = str_replace('-','',$tabDates[0])*1;
|
||
|
if($tabTmp[0]['dateUpdate'] > $tabTmp[0]['dateInsert']) {
|
||
|
$dateMaj = str_replace('-','',$tabTmp[0]['dateUpdate']);
|
||
|
} else {
|
||
|
$dateMaj = str_replace('-','',$tabTmp[0]['dateInsert']);
|
||
|
}
|
||
|
if ($dateProcol <= $dateMaj) {
|
||
|
$tabRet['SituationJuridique']='';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} elseif (count($this->getAnnoncesLegales($siren, 0, 'A', false)) > 0) {
|
||
|
$tabRet['SituationJuridique'] = 'A';
|
||
|
} elseif (count($this->getAnnoncesLegales($siren, 0, 'D', false)) > 0) {
|
||
|
$tabRet['SituationJuridique'] = 'D';
|
||
|
}
|
||
|
if ($this->debug) file_put_contents('procol.log', "SituationJuridique = ".$tabRet['SituationJuridique']."\n", FILE_APPEND);
|
||
|
// Fin Situation Juridique
|
||
|
|
||
|
// Date de dernière mise à jour
|
||
|
$tabAnn=$this->getAnnoncesLegales($siren, 0, '', false, false);
|
||
|
$tabDates=array();
|
||
|
foreach ($tabAnn as $iAnn=>$ann) {
|
||
|
$tabDates[]=$ann['dateInsertionSD'];
|
||
|
}
|
||
|
rsort($tabDates);
|
||
|
$tabRet['dateMajANN']=Metier_Util_Date::dateT('Y-m-d','Y-m-d',$tabDates[0]);
|
||
|
if ($tabRet['dateMajANN']=='--') $tabRet['dateMajANN']='';
|
||
|
$timer['getAnnoncesLegales']=microtime(true);
|
||
|
}
|
||
|
|
||
|
if ( ($tabInsee['CJ']>0 && $tabInsee['CJ']<20 || $tabInsee['CJ']>999 && $tabInsee['CJ']<2000) && $tabInsee['DIR_FCT']=='') {
|
||
|
$tabRet['dir1Titre'] = self::$tabFct['PP'];
|
||
|
}
|
||
|
|
||
|
if ($tabInsee['CIVILITE']>0 && $tabRet['dir1NomPrenom']=='') {
|
||
|
if ($tabInsee['CIVILITE']==1) { $tabRet['dir1NomPrenom']='M. '; $tabRet['dir1Genre']='M'; }
|
||
|
elseif ($tabInsee['CIVILITE']==2) { $tabRet['dir1NomPrenom']='Mme '; $tabRet['dir1Genre']='F'; }
|
||
|
elseif ($tabRet['dir1Genre']<>'M' && $tabRet['dir1Genre']<>'F') $tabRet['dir1Genre']='';
|
||
|
$tabRet['dir1NomPrenom'].=$tabInsee['NOM'];
|
||
|
}
|
||
|
|
||
|
if (intval($siren) > 0) {
|
||
|
if ($tabInsee['CIVILITE']>0 && ($tabRet['dir1Nom']=='' || $tabRet['dir1Prenom'])) {
|
||
|
$tmp = $this->iDb->select('insee.insee_even', 'dirNom, dirNomUsage, dirPrenom, insCIVILITE',
|
||
|
"insSIREN=$siren ORDER BY insDATEVE DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
$tabRet['dir1Nom'] = strtoupper($tmp[0]['dirNom']);
|
||
|
$tabRet['dir1Prenom'] = ucwords(strtolower($tmp[0]['dirPrenom']));
|
||
|
$tabRet['dir1NomUsage'] = strtoupper($tmp[0]['dirNomUsage']);
|
||
|
if ($tmp[0]['insCIVILITE']==1) $tabRet['dir1Genre']='M';
|
||
|
elseif ($tmp[0]['insCIVILITE']==2) $tabRet['dir1Genre']='F';
|
||
|
elseif ($tabRet['dir1Genre']<>'M' && $tabRet['dir1Genre']<>'F') $tabRet['dir1Genre']='';
|
||
|
|
||
|
$entrep['sexe'] = $tabRet['dir1Genre'];
|
||
|
unset($tmp);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (intval($siren) > 100 && $tabInsee['ACTIF'] == 0) {
|
||
|
if ($etab['nic']*1>0) $strNic='AND insNIC='.$etab['nic'];
|
||
|
else $strNic='';
|
||
|
$tmp=$this->iDb->select('insee.insee_even', 'insDATEVE', "insSIREN=$siren $strNic AND ( insEVE LIKE 'FF' OR insEVE LIKE 'TF' OR insEVE LIKE '0F' OR insEVE LIKE 'TD' OR insEVE LIKE '0D' OR insEVE LIKE '410' OR insEVE LIKE '420' OR insEVE LIKE '425' OR insEVE LIKE '400' OR insEVE LIKE '430' OR insEVE LIKE '435' OR insDESTINAT<>'') ORDER BY insDATEVE DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
$tabRet['DateClotEt']=@$tmp[0]['insDATEVE'];
|
||
|
unset($tmp);
|
||
|
$timer['dateClotureInsee']=microtime(true);
|
||
|
}
|
||
|
|
||
|
if ($tabRet['TrancheCALib'] == '') $tabRet['TrancheCALib'] = 'N/C';
|
||
|
if ($tabRet['EffEnTrLib'] == '') $tabRet['EffEnTrLib'] = 'N/C';
|
||
|
|
||
|
$tabRet['CapitalLib'] = '';
|
||
|
if (intval($siren) > 100) {
|
||
|
$strEvenVtLg = " AND Rubrique<>'ventes' AND typeEven NOT LIKE '%2700%' AND typeEven NOT LIKE '%2701%' AND typeEven NOT LIKE '%2702%' AND typeEven NOT LIKE '%2703%' AND typeEven NOT LIKE '%2710%' AND typeEven NOT LIKE '%2720%' AND typeEven NOT LIKE '%2721%' AND typeEven NOT LIKE '%2725%' AND typeEven NOT LIKE '%2730%' AND typeEven NOT LIKE '%2740%' AND typeEven NOT LIKE '%2750%' AND typeEven NOT LIKE '%2800%' AND typeEven NOT LIKE '%2840%' AND typeEven NOT LIKE '%2850%' AND typeEven NOT LIKE '%2851%' AND typeEven NOT LIKE '%2860%' AND typeEven NOT LIKE '%2870%' AND typeEven NOT LIKE '%2875%' AND typeEven NOT LIKE '%2880%' AND typeEven NOT LIKE '%2881%' AND typeEven NOT LIKE '%2885%' AND typeEven NOT LIKE '%2890%' AND typeEven NOT LIKE '%2891%' AND typeEven NOT LIKE '%2892%' ";
|
||
|
if ($tabRet['CapitalSrc'] != 5) {
|
||
|
// Recherche du n° RC, de la Forme Juridique et du Capital au Bodacc
|
||
|
$bodacc = $this->iDb->select( 'jo.bodacc_detail', 'Capital, CapitalDev',
|
||
|
"siren=$siren AND capital<>0 $strEvenVtLg ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) > 0) {
|
||
|
$annCap = $bodacc[0];
|
||
|
if ($tabRet['Capital']==0 || $tabRet['CapitalDev']=='' || $tabRet['Capital']<>$annCap['Capital']*1) {
|
||
|
if ($tabInsee['CJ']>1999 && $tabInsee['CJ']<7000) {
|
||
|
$tabRet['Capital']=$annCap['Capital']*1;
|
||
|
$tabRet['CapitalDev']=$annCap['CapitalDev'];
|
||
|
$tabRet['CapitalSrc']=10;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($tabRet['Capital']==0 || $tabRet['CapitalDev']=='') {
|
||
|
$bodaccHisto = $this->iDb->select(
|
||
|
'historiques.entrep e, historiques.texte x',
|
||
|
'e.ANBASE, e.NOBOD, e.CODTRI, e.JAL, e.DATE, e.CODEVE, e.SSCODE, e.DEPT, e.NOANN, e.ROLE, e.SIREN, e.E1GSIR, e.E1GNIC, x.annonceNum, x.annonceTxt',
|
||
|
"e.E1GSIR=$siren AND e.ANBASE=x.annonceNum AND e.DATE BETWEEN 19890101 AND 20041231 AND x.annonceTxt LIKE '%capital%' GROUP BY e.ANBASE ORDER BY e.DATE DESC", false, MYSQL_ASSOC);
|
||
|
if (count($bodaccHisto)>0) {
|
||
|
foreach ($bodaccHisto as $ann) {
|
||
|
if ($ann['DATE']<19960101 && $ann['E1GSIR']<>$ann['SIREN']) continue;
|
||
|
$tabCodeTri = $ann['CODTRI'];
|
||
|
if ( ($ann['CODEVE']>=10 && $ann['CODEVE']<20) ||
|
||
|
($ann['CODEVE']>=30 && $ann['CODEVE']<42) ||
|
||
|
($ann['CODEVE']>=51 && $ann['CODEVE']<80) ) {
|
||
|
if (preg_match('/Capital(?:.|)\:(.*)(eur.|f|livre)/Uis', $ann['annonceTxt'], $matches) && $tabInsee['CJ']>1999 && $tabInsee['CJ']<7000)
|
||
|
$tabRet['Capital']=trim(strtr($matches[1],array(' '=>'', ',00 '=>'', '.00 '=>'')))*1;
|
||
|
if (substr(strtoupper($matches[2]),0,3)=='EUR')
|
||
|
$tabRet['CapitalDev']='EUR';
|
||
|
elseif (substr(strtoupper($matches[2]),0,3)=='LIV')
|
||
|
$tabRet['CapitalDev']='GBP';
|
||
|
else
|
||
|
$tabRet['CapitalDev']='FRF';
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if ($tabRet['CapitalDev']<>'' && $tabRet['CapitalDev']<>'EUR') {
|
||
|
$dev = $tabRet['CapitalDev'];
|
||
|
$deviseResult = $this->iDb->select('sdv1.devise_liste l, sdv1.devise_cours c', 'c.devise, c.valeur, c.date, l.devNom, l.devNomPays, l.devPaysIso',
|
||
|
"c.devise='$dev' and l.devIso='$dev' ORDER BY c.date DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($deviseResult) > 0) {
|
||
|
$dev = $deviseResult[0];
|
||
|
$devise = $tabRet['Capital'] * $dev['valeur'] * 1;
|
||
|
$tabRet['CapitalLib']=''.$dev['devNom'].' soit '.number_format(round($devise),null,null,' ').' EUR';
|
||
|
}
|
||
|
}
|
||
|
$timer['capital']=microtime(true);
|
||
|
|
||
|
// Recherche du code Tribunal du siège
|
||
|
if ($tabRet['CapitalSrc']<>5) {
|
||
|
$bodacc=$this->iDb->select('jo.bodacc_detail', 'RC, FJ, Tribunal_Code',
|
||
|
"siren=$siren AND RC<>'' $strEvenVtLg ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if ($tabRet['AutreId']=='') $tabRet['AutreId']=@$bodacc[0]['RC'];
|
||
|
if ($tabRet['Tribunal']=='') $tabRet['Tribunal']=@$bodacc[0]['Tribunal_Code'];
|
||
|
}
|
||
|
|
||
|
if ($tabRet['FJ_lib']=='') {
|
||
|
$bodacc = $this->iDb->select('jo.bodacc_detail', 'FJ',
|
||
|
"siren=$siren AND FJ<>'' $strEvenVtLg ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) > 0) {
|
||
|
$tabRet['FJ_lib'] = $bodacc[0]['FJ'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Recherche de l'activité réelle
|
||
|
$bodacc = $this->iDb->select('jo.bodacc_detail', 'Activite',
|
||
|
"siren=$siren AND Activite<>'' AND Activite NOT LIKE 'non precis%' $strEvenVtLg ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) > 0) {
|
||
|
$annCap = $bodacc[0];
|
||
|
if ($tabInsee['CJ']<7000 || $tabInsee['CJ']>7999) {
|
||
|
$tabRet['Activite']=trim($annCap['Activite']);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($tabRet['Activite']=='' && trim($tab['activite'])<>'') {
|
||
|
$tabRet['Activite']=trim($tab['activite']);
|
||
|
} elseif ($tabRet['Activite']=='' &&
|
||
|
($tabInsee['CJ']>90 && $tabInsee['CJ']<94 || $tabInsee['CJ']>9000 && $tabInsee['CJ']<9400) ) {
|
||
|
$siretMin=(''.$siren.'00000')*1;
|
||
|
$siretMax=(''.$siren.'99999')*1;
|
||
|
$bodacc = $this->iDb->select('jo.asso', 'Assoc_Web, Assoc_Mail, Assoc_Objet, Assoc_NObjet, Assoc_Nom, typeAsso, Waldec',
|
||
|
"siren=$siren AND dateSuppr=0 AND (Assoc_Objet<>'' OR Assoc_NObjet<>'') ORDER BY Date_Parution DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) > 0) {
|
||
|
$annCap = $bodacc[0];
|
||
|
$tabRet['Activite'] = trim($annCap['Assoc_NObjet']);
|
||
|
if (trim($tabRet['AutreId'])=='') {
|
||
|
$tabRet['AutreId'] = trim($annCap['Waldec']);
|
||
|
}
|
||
|
$tabRet['nomLong'] = trim($annCap['Assoc_Nom']);
|
||
|
if ($tabRet['Activite']=='') $tabRet['Activite'] = trim($annCap['Assoc_Objet']);
|
||
|
if ($tabRet['Web']=='') $tabRet['Web'] = trim($annCap['Assoc_Web']);
|
||
|
if ($tabRet['Mail']=='') $tabRet['Mail'] = trim($annCap['Assoc_Mail']);
|
||
|
if ($annCap['typeAsso'] == 'ASL' && $tabRet['FJ'] != 9150) {
|
||
|
$tabRet['FJ2'] = $tabRet['FJ'];
|
||
|
$tabRet['FJ2_Lib'] = $tabRet['FJ_lib'];
|
||
|
$tabRet['FJ'] = 9150;
|
||
|
$tabRet['FJ_lib'] = $this->getLibelleFJ(9150);
|
||
|
} elseif ($annCap['typeAsso'] == 'FOD') {
|
||
|
$tabRet['FJ_lib'].= ' (Fonds de dotation)';
|
||
|
}
|
||
|
}
|
||
|
if (trim($tabRet['AutreId'])=='') {
|
||
|
$tabRet['AutreId'] = trim($waldec);
|
||
|
}
|
||
|
}
|
||
|
elseif ($tabRet['Activite']=='' && ($tabInsee['CJ']<7000 || $tabInsee['CJ']>7999)) {
|
||
|
$bodaccHisto = $this->iDb->select('historiques.entrep e, historiques.texte x',
|
||
|
'e.ANBASE, e.NOBOD, e.CODTRI, e.JAL, e.DATE, e.CODEVE, e.SSCODE, e.DEPT, e.NOANN, e.ROLE, e.SIREN, e.E1GSIR, e.E1GNIC, x.annonceNum, x.annonceTxt',
|
||
|
"e.E1GSIR=$siren AND e.ANBASE=x.annonceNum AND e.DATE BETWEEN 19890101 AND 20041231 AND x.annonceTxt LIKE '%ctivit%' GROUP BY e.ANBASE ORDER BY e.DATE DESC", false, MYSQL_ASSOC);
|
||
|
if (count($bodaccHisto)>0) {
|
||
|
foreach ($bodaccHisto as $idx => $ann) {
|
||
|
if ($ann['DATE']<19960101 && $ann['E1GSIR']<>$ann['SIREN']) continue;
|
||
|
if ($tabCodeTri<>'' && $tabCodeTri<>@$ann['CODTRI']) $tabCodeTri = $ann['CODTRI'];
|
||
|
if ( ($ann['CODEVE']<20) || ($ann['CODEVE']>=30 && $ann['CODEVE']<42) ||
|
||
|
($ann['CODEVE']>=51 && $ann['CODEVE']<80) ) {
|
||
|
if (preg_match('/(.*)Activit(?:e|é)(?:.|)\:(.*)(?:Adresse(?:.*|)|Commentaires?|Administration|Etablissement principal|Date d\'effet|Date.de.d.but d.activit.|Capital|Nom commercial)(?:.|)\:/Uisu', $ann['annonceTxt'], $matches))
|
||
|
if (strpos(substr($matches[1],-20),'cess') === false &&
|
||
|
strpos(substr($matches[1],-20),'date') === false) {
|
||
|
$tabRet['Activite']=$matches[2];
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$timer['activiteReelle']=microtime(true);
|
||
|
|
||
|
$bodacc = $this->iDb->select('jo.rncs_dirigeants',
|
||
|
"nom, prenom, naissance_nom, civilite, fonction_code as code, fonction_lib as libelle, naissance_date AS dateNaiss, naissance_lieu AS lieuNaiss, dirRS as rs, '' as dateEffet",
|
||
|
"siren=$siren AND actif%10=1 AND fonction_lib NOT LIKE '%Administrateur%' ORDER BY actif DESC, fonction_lib DESC", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) == 0) {
|
||
|
$bodacc = $this->iDb->select('jo.rncs_dirigeants',
|
||
|
"nom, prenom, naissance_nom, civilite, fonction_code as code, fonction_lib as libelle, naissance_date AS dateNaiss, naissance_lieu AS lieuNaiss, dirRS as rs, '' as dateEffet",
|
||
|
"siren=$siren AND actif%10=0 AND fonction_lib NOT LIKE '%Administrateur%' ORDER BY actif DESC, fonction_lib DESC", false, MYSQL_ASSOC);
|
||
|
}
|
||
|
if (count($bodacc) > 0) {
|
||
|
$k = 1;
|
||
|
foreach ($bodacc as $ann) {
|
||
|
if ($tabInsee['CJ']>=7000 && $tabInsee['CJ']<=7999 && !in_array($ann['libelle'],
|
||
|
array('Maire', 'Président', 'Directeur général'))) {
|
||
|
continue;
|
||
|
}
|
||
|
$tabRet['dir'.$k.'Code'] = $ann['code'];
|
||
|
$tabRet['dir'.$k.'Titre'] = $ann['libelle'];
|
||
|
$nomNaiss='';
|
||
|
if (trim($ann['naissance_nom']) != '') {
|
||
|
if ($ann['civilite'] == 'MME' || $ann['civilite'] == 'MLLE') {
|
||
|
$nomNaiss=' née '.trim($ann['naissance_nom']);
|
||
|
$tabRet['dir'.$k.'Genre'] = 'F';
|
||
|
} elseif ($ann['civilite'] == 'M') {
|
||
|
$nomNaiss=' né '.trim($ann['naissance_nom']);
|
||
|
$tabRet['dir'.$k.'Genre'] = 'M';
|
||
|
} else {
|
||
|
$nomNaiss=' né(e) '.trim($ann['naissance_nom']);
|
||
|
}
|
||
|
}
|
||
|
if (trim($ann['rs']) != '') {
|
||
|
$tabRet['dir'.$k.'NomPrenom'] = $ann['rs'];
|
||
|
if (trim($ann['nom'])!='' || trim($ann['prenom'])!='')
|
||
|
$tabRet['dir'.$k.'NomPrenom'].=' repr. par '.$ann['nom'].' '.$ann['prenom'];
|
||
|
} else {
|
||
|
$tabRet['dir'.$k.'NomPrenom']=$ann['nom'].' '.$ann['prenom'].$nomNaiss;
|
||
|
$tabRet['dir'.$k.'Nom']=$ann['nom'];
|
||
|
$tabRet['dir'.$k.'Prenom']=$ann['prenom'];
|
||
|
if ($ann['civilite']=='M')
|
||
|
$tabRet['dir'.$k.'Genre']='M';
|
||
|
elseif ($ann['civilite']=='MME' || $ann['civilite']=='MLLE')
|
||
|
$tabRet['dir'.$k.'Genre']='F';
|
||
|
}
|
||
|
$tabRet['dir'.$k.'DateFct']=$ann['dateEffet'];
|
||
|
$tabRet['dir'.$k.'DateNaiss']=$ann['dateNaiss'];
|
||
|
$tabRet['dir'.$k.'LieuNaiss']=$ann['lieuNaiss'];
|
||
|
$tabRet['dir'.$k.'Genre']='';
|
||
|
if ($k==2) break;
|
||
|
$k++;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
$bodacc = $this->iDb->select('jo.bodacc_dirigeants d, jo.bodacc_detail b, jo.bodacc_fonctions f',
|
||
|
'd.num, d.dateEffet, d.Rubrique, d.fonction, d.rs, d.nom, d.prenom, d.nomUsage, d.depart, d.dateInsert, f.libelle',
|
||
|
"b.SIREN=$siren AND b.id=d.id AND b.typeEven NOT BETWEEN 5000 AND 5700 AND b.typeEven NOT BETWEEN 2700 AND 2900 AND d.fonction=f.codeFct AND d.depart<>1 AND f.triCode IN ('ASS','COG','DID','DIR','GER','PCS','PDG','PRD','PRE','PRT','VIC') GROUP BY d.fonction, d.rs, d.nom, d.prenom ORDER BY d.dateEffet DESC", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc)>0) {
|
||
|
$annCap = $bodacc[0];
|
||
|
$k=1;
|
||
|
foreach ($bodacc as $ann) {
|
||
|
$tabRet['dir'.$k.'Code']=$ann['fonction'];
|
||
|
$tabRet['dir'.$k.'Titre']=$ann['libelle'];
|
||
|
$tabRet['dir'.$k.'NomPrenom']=$ann['rs'].' '.$ann['nom'].' '.$ann['prenom'];
|
||
|
$tabRet['dir'.$k.'Nom']=$ann['nom'];
|
||
|
$tabRet['dir'.$k.'Prenom']=$ann['prenom'];
|
||
|
$tabRet['dir'.$k.'DateFct']=$ann['dateEffet'];
|
||
|
$tabRet['dir'.$k.'Genre']='';
|
||
|
if ($k==2) break;
|
||
|
$k++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$timer['dirigeants']=microtime(true);
|
||
|
|
||
|
// Recherche du site Web ou Email dans le JO ASSO
|
||
|
if ( ($tabRet['Web']=='' || $tabRet['Mail']=='') &&
|
||
|
($tabInsee['CJ']>90 && $tabInsee['CJ']<94 ||
|
||
|
$tabInsee['CJ']>9000 && $tabInsee['CJ']<9400) ) {
|
||
|
$siretMin = (''.$siren.'00000')*1;
|
||
|
$siretMax = (''.$siren.'99999')*1;
|
||
|
$bodacc = $this->iDb->select('jo.asso', 'Assoc_Web, Assoc_Mail',
|
||
|
"siren=$siren AND dateSuppr=0 AND (Assoc_Web<>'' OR Assoc_Mail<>'') ORDER BY Date_Parution DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) > 0) {
|
||
|
$annCap = $bodacc[0];
|
||
|
if ($tabRet['Web']=='') $tabRet['Web']=trim($annCap['Assoc_Web']);
|
||
|
if ($tabRet['Mail']=='') $tabRet['Mail']=trim($annCap['Assoc_Mail']);
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if ($etab['source']==3) {
|
||
|
$id = $etab['source_id'];
|
||
|
$bodacc = $this->iDb->select('jo.asso', 'Activite, Sous_Prefecture, Assoc_Web, Assoc_Mail, Assoc_Objet, Assoc_Fusion, Assoc_Date_Declaration2',
|
||
|
"id=$id AND dateSuppr=0", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc) > 0) {
|
||
|
$annCap = $bodacc[0];
|
||
|
$tabRet['Activite'] = $annCap['Assoc_Objet'];
|
||
|
$tabRet['Web'] = $annCap['Assoc_Web'];
|
||
|
$tabRet['Mail'] = $annCap['Assoc_Mail'];
|
||
|
$tabRet['VilleDecl'] = $annCap['Sous_Prefecture'];
|
||
|
if ($tabRet['Actif'] == 0) {
|
||
|
$tabRet['DateClotEt'] = $annCap['Assoc_Date_Declaration2'];
|
||
|
} else {
|
||
|
$tabRet['DateCreaEt'] = $annCap['Assoc_Date_Declaration2'];
|
||
|
$tabRet['DateCreaEn'] = $annCap['Assoc_Date_Declaration2'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$timer['association']=microtime(true);
|
||
|
|
||
|
// On initialise les dernères variables en prov. d'Infogreffes
|
||
|
if ( count($etabG) > 0) {
|
||
|
$tabRet['DateClotEt'] = $etabG['DateRadiation'];
|
||
|
$tabRet['dateImmat'] = $etabG['DateCreation'];
|
||
|
if ($tabRet['dateImmat']*1==0)
|
||
|
$tabRet['dateImmat']= substr($etabG['NumRC2'],0,4).'0101';
|
||
|
$tabRet['DateCreaEt'] = $tabRet['DateCreaEn'] = substr($etabG['NumRC2'],0,4).'0100';
|
||
|
|
||
|
$tabRet['FJ'] = $etabG['FJ'];
|
||
|
if ($etabG['FJ']==1900) {
|
||
|
$tabRet['dir1Titre']='PP';
|
||
|
$tabNom=explode(' ', $etabG['Nom']);
|
||
|
$tabNom[0]=strtoupper($tabNom[0]);
|
||
|
for($i=1; isset($tabNom[$i]); $i++)
|
||
|
if ($tabNom[$i]=='EPOUSE')
|
||
|
$tabNom[$i]='epouse';
|
||
|
elseif ($tabNom[$i-1]<>'epouse')
|
||
|
$tabNom[$i]=ucwords(strtolower($tabNom[$i]));
|
||
|
$tabRet['dir1NomPrenom']=implode(' ', $tabNom);
|
||
|
}
|
||
|
$tabRet['FJ_lib'] = $etabG['FJLib'];
|
||
|
$tabRet['AutreId'] = $etabG['NumRC'];
|
||
|
$tabRet['NafEtab'] = $etabG['NafEtab'];
|
||
|
$tabRet['NafEnt'] = $etabG['NafEnt'];
|
||
|
$tabRet['NafEntLib'] = $etabG['NafEntLib'];
|
||
|
$tabRet['NafEtabLib'] = $etabG['NafEtabLib'];
|
||
|
$tabRet['SiretSiege'] = $etabG['Siret'];
|
||
|
$tabRet['DateMajRCS'] = $etab['dateMAJ'];
|
||
|
$tabRet['numGreffe'] = $etabG['NumGreffe'];
|
||
|
$tabRet['numRC'] = $etabG['NumRC2'];
|
||
|
$tabRet['Enseigne'] = $etabG['Enseigne'];
|
||
|
$iRncs = new Metier_Partenaires_MRncs($this->iDb);
|
||
|
$tabRet['Tribunal'] = $iRncs->getCodeBodaccTribunal($etabG['NumGreffe']);
|
||
|
}
|
||
|
|
||
|
if ($tabRet['Siege']==1 && $tabRet['Actif'] && $tabRet['Tribunal']=='') {
|
||
|
$tabRet['Tribunal'] = $tabCodeTri;
|
||
|
}
|
||
|
|
||
|
if ( intval($siren) > 0) {
|
||
|
$rep = $this->iDb->select('jo.rncs_entrep',
|
||
|
'siren, sirenValide, actif, numGreffe, triCode, triId, numRC, numRC2, raisonSociale, nom, prenom, nomUsage, sigle, dateNaiss, lieuNaiss, sexe, nationalite, pays, naf, cj, capitalMontant, capitalDevise, capitalDevIso, dateImma, dateRad, dateRad*1 AS dateRadNum, capitalType, capitalCent, provisoires, flux, DATE(dateUpdate) AS jourUpdate',
|
||
|
"siren=$siren", false, MYSQL_ASSOC);
|
||
|
if (count($rep) > 0) {
|
||
|
$entrep = $rep[0];
|
||
|
if (isset($entrep['numGreffe'])) { //ETRANGER//
|
||
|
$tabRet['numGreffe'] = $entrep['numGreffe'];
|
||
|
$tabRet['numRC'] = $entrep['numRC2'];
|
||
|
if (( preg_match('/[A-Z]/i',substr($tabRet['AutreId'],2,2)) && !preg_match('/[A-Z]/i',substr($tabRet['AutreId'],0,2)) ) || $tabRet['AutreId']=='')
|
||
|
$tabRet['AutreId'] = $etabG['NumRC2'];
|
||
|
$tabRet['Tribunal'] = $entrep['triCode'];
|
||
|
if (strtoupper(trim($entrep['raisonSociale']))<>strtoupper(trim($tabRet['Nom'])))
|
||
|
$tabRet['nomLong'] = strtoupper($entrep['raisonSociale']);
|
||
|
if (strtoupper(trim($entrep['sigle']))<>strtoupper(trim($tabRet['Sigle'])))
|
||
|
$tabRet['sigleLong']= strtoupper($entrep['sigle']);
|
||
|
$tabRet['dateImmat'] = $entrep['dateImma'];
|
||
|
$tabRet['dateRad'] = $entrep['dateRad'];
|
||
|
//if ($entrep['actif']==0 && $entrep['dateRadNum']==0) {}
|
||
|
$tabRet['Capital'] = $entrep['capitalMontant']+($entrep['capitalCent']/100);
|
||
|
$tabRet['CapitalDev'] = $entrep['capitalDevIso'];
|
||
|
$tabRet['CapitalType'] = trim(strtoupper(substr($entrep['capitalType'],0,1)));
|
||
|
|
||
|
// Par défaut, la Forme juridique qui fait foie est celle de l'INPI
|
||
|
$fjInpi=$entrep['cj']*1;
|
||
|
if ($tabRet['FJ']*1<>$fjInpi && $fjInpi>0) {
|
||
|
$tabRet['FJ2'] = $tabRet['FJ'];
|
||
|
$tabRet['FJ2_Lib'] = $tabRet['FJ_lib'];
|
||
|
$tabRet['FJ'] = $fjInpi;
|
||
|
$tabRet['FJ_lib'] = $this->getLibelleFJ($fjInpi);
|
||
|
} else {
|
||
|
$tabRet['FJ2'] = $tabRet['FJ'];
|
||
|
$tabRet['FJ2_Lib'] = $tabRet['FJ_lib'];
|
||
|
}
|
||
|
if ($fjInpi>=1000 && $fjInpi<2000) {
|
||
|
$tabRet['dir1Titre']='Personne physique';
|
||
|
$tabRet['dir1Code']='1050';
|
||
|
$tabRet['dir1NomPrenom']=strtoupper($entrep['nom']).' '.ucwords(strtolower($entrep['prenom']));
|
||
|
$tabRet['dir1Nom']=strtoupper($entrep['nom']);
|
||
|
$tabRet['dir1Prenom']=ucwords(strtolower($entrep['prenom']));
|
||
|
$tabRet['dir1NomUsage']=strtoupper($entrep['nomUsage']);
|
||
|
$tabRet['dir1DateNaiss']=$entrep['dateNaiss'];
|
||
|
$tabRet['dir1LieuNaiss']=$entrep['lieuNaiss'];
|
||
|
$tabRet['dir1Genre']=$entrep['sexe'];
|
||
|
}
|
||
|
|
||
|
if ($tabRet['DateMajRCS']=='') {
|
||
|
if ($entrep['jourUpdate']<>'0000-00-00')
|
||
|
$tabRet['DateMajRCS']=$entrep['jourUpdate'];
|
||
|
else
|
||
|
$tabRet['DateMajRCS']=$entrep['flux'];
|
||
|
}
|
||
|
if ($entrep['actif']==1 || $entrep['actif']==11)
|
||
|
$tabRet['EntActiveRCS']=1; // On signal que l'entreprise est active au RCS
|
||
|
else {
|
||
|
$tabRet['EntActiveRCS']=0; // On signal que l'entreprise est radié du RCS
|
||
|
if ($tabRet['SituationJuridique']=='')
|
||
|
$tabRet['SituationJuridique']='RR'; // On signal que l'entreprise est radié du RCS
|
||
|
}
|
||
|
|
||
|
// Spécificité EIRL
|
||
|
if ($fjInpi==1000) {
|
||
|
$rep=$this->iDb->select('jo.rncs_eirl',
|
||
|
'denomination, activite',
|
||
|
"siren=$siren", false, MYSQL_ASSOC);
|
||
|
$entrep=$rep[0];
|
||
|
$tabRet['Activite']=$entrep['activite'];
|
||
|
}
|
||
|
|
||
|
// Informations sur l'établissement au RNCS
|
||
|
$rep = $this->iDb->select('jo.rncs_etab',
|
||
|
'id, siege, actif, enseigne, nomCommercial, adrNumVoie, adrIndRep, adrLibVoie, adrTypeVoie, adrVoie, cp, commune, adrComp, adresse1, adresse2, adresse3, naf, dateFermeture, flux, dateInsert, DATE(dateUpdate) AS jourUpdate',
|
||
|
"siren=$siren AND nic=$nic", false, MYSQL_ASSOC);
|
||
|
$entrep = $rep[0];
|
||
|
if (isset($entrep['id'])) {
|
||
|
$tabRet['EtabActifRCS']=0;
|
||
|
if ($entrep['jourUpdate']<>'0000-00-00' &&
|
||
|
str_replace('-','',$entrep['jourUpdate'])*1>str_replace('-','',$tabRet['DateMajRCS']))
|
||
|
$tabRet['DateMajRCS']=$entrep['jourUpdate'];
|
||
|
|
||
|
if ($entrep['actif']*1==1) $tabRet['EtabActifRCS']=1; // On signal que l'établissement est actif au RCS
|
||
|
$tabRet['NomCommercial']=$entrep['nomCommercial'];
|
||
|
$tabRet['enseigneLong']=$entrep['enseigne'];
|
||
|
|
||
|
if ($codePaysIso2<>'FR' && $codePaysIso2<>'') {
|
||
|
$tabRet['Adresse'] = trim(preg_replace('/ +/', ' ', $entrep['adrNumVoie'] .' '.$entrep['adrIndRep'].' '.
|
||
|
$entrep['adrTypeVoie'].' '.$entrep['adrVoie']));
|
||
|
$tabRet['Adresse2'] = trim(preg_replace('/ +/', ' ', $entrep['adrComp']));
|
||
|
$tabRet['AdresseNum'] = $entrep['adrNumVoie'];
|
||
|
$tabRet['AdresseBtq'] = $entrep['adrIndRep'];
|
||
|
$tabRet['AdresseVoie'] = $entrep['adrTypeVoie'];
|
||
|
$tabRet['AdresseRue'] = $entrep['adrVoie'];
|
||
|
$tabRet['CP'] = $entrep['cp'];
|
||
|
$tabRet['Ville'] = $entrep['commune'];
|
||
|
}
|
||
|
}
|
||
|
$timer['infosRNCS']=microtime(true);
|
||
|
} elseif ($siren>1000) {
|
||
|
// Recherche au RM
|
||
|
$rep = $this->iDb->select('jo.artisanat',
|
||
|
'siren, actif, numRM, denomination, sigle, nomCommercial, enseigne, fj, effectif, aprm, debutActivite, activite, adresse, cp, ville, cessation, radiation, nom,prenom,nomUsage,dateNaiss,lieuNaiss,qualite,qualif,dateQualif,dateFctDeb,dateFctFin,DATE(dateUpdate) AS jourUpdate, DATE(dateInsert) AS dateInsert',
|
||
|
"siren=$siren", false, MYSQL_ASSOC);
|
||
|
if (count($rep) > 0) {
|
||
|
$entrep = $rep[0];
|
||
|
if (isset($entrep['numRM'])) {
|
||
|
$tabRet['AutreId'] = $entrep['numRM'];
|
||
|
if ($tabRet['Activite']=='') $tabRet['Activite']=$entrep['activite'];
|
||
|
if ($tabRet['APRM']=='') {
|
||
|
$tabRet['APRM']=$entrep['aprm'];
|
||
|
$tabRet['APRM_Lib']=$this->getLibelleNafa($entrep['aprm']);
|
||
|
}
|
||
|
|
||
|
if (strtoupper(trim($entrep['nom'].' '.$entrep['prenom'].' '.$entrep['nomUsage']))<>strtoupper(trim($tabRet['Nom'])))
|
||
|
$tabRet['nomLong'] = strtoupper(trim($entrep['nom'].' '.$entrep['prenom'].' '.$entrep['nomUsage']));
|
||
|
if (strtoupper(trim($entrep['sigle']))<>strtoupper(trim($tabRet['Sigle'])))
|
||
|
$tabRet['sigleLong']= strtoupper($entrep['sigle']);
|
||
|
|
||
|
$tabRet['dateImmat'] = $entrep['debutActivite'];
|
||
|
$tabRet['dateRad'] = $entrep['radiation'];
|
||
|
|
||
|
// Si on est au greffe, on est artisan commercant
|
||
|
if ($tabRet['numGreffe']*1>0)
|
||
|
$fjInpi=1100; // Artisan Commerçant
|
||
|
else
|
||
|
$fjInpi=1300; // Artisan
|
||
|
|
||
|
// Par défaut, la Forme juridique qui fait foie est celle de l'INPI
|
||
|
if ($tabRet['FJ']*1<>$fjInpi) {
|
||
|
$tabRet['FJ2'] = $tabRet['FJ'];
|
||
|
$tabRet['FJ2_Lib'] = $tabRet['FJ_lib'];
|
||
|
$tabRet['FJ'] = $fjInpi;
|
||
|
$tabRet['FJ_lib'] = $this->getLibelleFJ($fjInpi);
|
||
|
} else {
|
||
|
$tabRet['FJ2'] = $tabRet['FJ'];
|
||
|
$tabRet['FJ2_Lib'] = $tabRet['FJ_lib'];
|
||
|
}
|
||
|
|
||
|
$tabRet['dir1Titre']=ucwords(strtolower($entrep['qualite'].' '.$entrep['qualif']));
|
||
|
$tabRet['dir1NomPrenom']=strtoupper($entrep['nom']).' '.ucwords(strtolower($entrep['prenom']));
|
||
|
$tabRet['dir1Nom']=strtoupper($entrep['nom']);
|
||
|
$tabRet['dir1Prenom']=ucwords(strtolower($entrep['prenom']));
|
||
|
$tabRet['dir1DateNaiss']=$entrep['dateNaiss'];
|
||
|
$tabRet['dir1LieuNaiss']=$entrep['lieuNaiss'];
|
||
|
|
||
|
if ($tabRet['DateMajRCS']=='') {
|
||
|
if ($entrep['jourUpdate']<>'0000-00-00')
|
||
|
$tabRet['DateMajRCS']=$entrep['jourUpdate'];
|
||
|
else
|
||
|
$tabRet['DateMajRCS']=$entrep['dateInsert'];
|
||
|
}
|
||
|
if ($entrep['actif']==1 || $entrep['actif']==11)
|
||
|
$tabRet['EntActiveRCS']=1; // On signal que l'entreprise est active au RCS
|
||
|
else {
|
||
|
$tabRet['EntActiveRCS']=0; // On signal que l'entreprise est radié du RCS
|
||
|
if ($tabRet['SituationJuridique']=='')
|
||
|
$tabRet['SituationJuridique']='RR'; // On signal que l'entreprise est radié du RCS
|
||
|
}
|
||
|
|
||
|
$tabRet['NomCommercial']=$entrep['nomCommercial'];
|
||
|
$tabRet['enseigneLong']=$entrep['enseigne'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($tabRet['dir1Genre']=='M' || $tabRet['dir1Genre']=='F') {
|
||
|
$tabRet['dir1Titre']='Personne physique';
|
||
|
$tabRet['dir1Code']='1050';
|
||
|
}
|
||
|
|
||
|
if ( $accesDist &&
|
||
|
// Département couvert par Infogreffe
|
||
|
!in_array($tabRet['Dept'], array(57, 67, 68, 97, 98, 99)) &&
|
||
|
// Forme Juridique présente au greffe
|
||
|
( $tabInsee['CJ']==1100 ||
|
||
|
$tabInsee['CJ']==1200 ||
|
||
|
$tabInsee['CJ']==1300 ||
|
||
|
$tabInsee['CJ']==1700 ||
|
||
|
($tabInsee['CJ']>=3100 && $tabInsee['CJ']<=3299) ||
|
||
|
($tabInsee['CJ']>=4100 && $tabInsee['CJ']<=4199) ||
|
||
|
($tabInsee['CJ']>=5100 && $tabInsee['CJ']<=5899) ||
|
||
|
($tabInsee['CJ']>=6100 && $tabInsee['CJ']<=6599) ||
|
||
|
$tabInsee['CJ']==9900 ||
|
||
|
preg_match('/EIRL/', $nom) || preg_match('/EIRL/', $nom2) ||
|
||
|
preg_match('/EIRL/', $tabRet['Sigle']) || preg_match('/EIRL/', $tabRet['Enseigne']) ||
|
||
|
preg_match('/EIRL/', $tabRet['Adresse']) || preg_match('/EIRL/', $tabRet['Adresse2'])
|
||
|
) &&
|
||
|
( $tabInsee['CJ']==1700 || // Agents commerciaux (uniquement au Greffes RSAC)
|
||
|
$tabRet['numRC']=='' || // Numéro de RCS absent = Anomalie (<à3%)
|
||
|
$tabRet['Tribunal']=='' || // Tribunal absent = anomalie
|
||
|
str_replace('-','',$tabRet['dateImmat'])*1==0 || // Pas de date d'immat = anomalie (<à9%)
|
||
|
($nbEtab*1==0 && str_replace('-','',$tabRet['dateRad'])*1==0) // Inactif sans date de RAD
|
||
|
)
|
||
|
) {
|
||
|
|
||
|
if ( $this->debugtime ) {
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MGreffes Avant\n", FILE_APPEND);
|
||
|
$tdeb=microtime(1);
|
||
|
}
|
||
|
|
||
|
$iGeffes = new Metier_Partenaires_MGreffes($this->iDb);
|
||
|
$etabG = $iGeffes->getIdentite($siren);
|
||
|
$iRncs = new Metier_Partenaires_MRncs($this->iDb);
|
||
|
|
||
|
if($this->debugtime) {
|
||
|
$duree=round(microtime(1)-$tdeb,3);
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;MGreffes APRES ($duree s)\n", FILE_APPEND);
|
||
|
}
|
||
|
|
||
|
if ($etabG) {
|
||
|
if ($tabRet['numRC']=='') $tabRet['numRC'] = $etabG['NumRC2'];
|
||
|
if ($tabRet['Tribunal']=='') $tabRet['Tribunal'] = $iRncs->getCodeBodaccTribunal($etabG['NumGreffe']);
|
||
|
if (str_replace('-','',$tabRet['dateImmat'])*1==0) $tabRet['dateImmat']= $etabG['DateCreation'];
|
||
|
if (str_replace('-','',$tabRet['dateRad'])*1==0) {
|
||
|
$tabRet['dateRad'] = $etabG['DateRadiation'];
|
||
|
if (str_replace('-','',$tabRet['dateRad'])*1>0 && $tabRet['SituationJuridique']=='')
|
||
|
$tabRet['SituationJuridique']='RR';
|
||
|
}
|
||
|
if (preg_match('/[A-Z]/i',substr($tabRet['AutreId'],2,2)) || $tabRet['AutreId']=='')
|
||
|
$tabRet['AutreId'] = $etabG['NumRC2'];
|
||
|
}
|
||
|
$timer['infosInfogreffes']=microtime(true);
|
||
|
}
|
||
|
|
||
|
// Si il n'y a aucun établissement actif et qu'on est radié au RCS : on part chercher la dernière annonce de Radiation au Bodacc
|
||
|
if (($nbEtab*1)==0 || (isset($entrep['numGreffe']) && $entrep['actif']==0 && $entrep['dateRadNum']==0)) {
|
||
|
$tabRad = $this->getAnnoncesLegales($siren, 0, 'R');
|
||
|
if (count($tabRad)>0) {
|
||
|
// Il y a au moins une annonce de radiation au Bodacc
|
||
|
if ($tabRet['SituationJuridique']=='')
|
||
|
$tabRet['SituationJuridique']='RP';
|
||
|
|
||
|
$dateEff=str_replace('-','', $tabRad[0]['dateEffet'])*1;
|
||
|
$dateJug=str_replace('-','', $tabRad[0]['dateJugement'])*1;
|
||
|
$datePar=str_replace('-','', $tabRad[0]['DateParution'])*1;
|
||
|
if ($dateEff>0)
|
||
|
$tabRet['dateRad']=$dateEff;
|
||
|
elseif ($dateJug>0)
|
||
|
$tabRet['dateRad']=$dateJug;
|
||
|
elseif ($datePar>0)
|
||
|
$tabRet['dateRad']=$datePar;
|
||
|
}
|
||
|
$timer['infosRadiation']=microtime(true);
|
||
|
}
|
||
|
|
||
|
// Eléments Financiers en provenance du dernier Bilan
|
||
|
$rep = $this->iDb->select('jo.bilans',
|
||
|
'siren, dateExercice, dureeExercice, monnaie, typeBilan, unite, postes, dateProvPartenaire, dateInsert',
|
||
|
"siren=$siren AND typeBilan IN ('N','S') ORDER BY dateExercice DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if ( count($rep)>0 ) {
|
||
|
$entrep = $rep[0];
|
||
|
$tabRet['bilanAnnee'] = substr($entrep['dateExercice'],0,4);
|
||
|
$tabRet['bilanDate'] = $entrep['dateExercice'];
|
||
|
$tabRet['bilanMois'] = $entrep['dureeExercice'];
|
||
|
$tabRet['bilanDevise'] = $entrep['monnaie'];
|
||
|
if ($entrep['dateProvPartenaire']>0)
|
||
|
$tabRet['bilanDateMaj']=Metier_Util_Date::dateT('Ymd','Y-m-d',$entrep['dateProvPartenaire']);
|
||
|
else
|
||
|
$tabRet['bilanDateMaj']=Metier_Util_Date::dateT('Y-m-d','Y-m-d',$entrep['dateInsert']);
|
||
|
|
||
|
switch (strtoupper(trim($entrep['unite']))) {
|
||
|
case 'M': $unite='M'; break;
|
||
|
case 'K': $unite='K'; break;
|
||
|
default: $unite='U'; break;
|
||
|
}
|
||
|
$tabTmp=explode(';', $entrep['postes']);
|
||
|
$tabBilan=array();
|
||
|
foreach ($tabTmp as $i=>$strTmp) {
|
||
|
$tabTmp2=explode('=', $strTmp);
|
||
|
if (isset($tabTmp2[1]))
|
||
|
if ($unite=='K' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376')
|
||
|
$tabBilan[$tabTmp2[0]]=$tabTmp2[1]*1000;
|
||
|
elseif ($unite=='M' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376')
|
||
|
$tabBilan[$tabTmp2[0]]=$tabTmp2[1]*1000000;
|
||
|
else $tabBilan[$tabTmp2[0]]=$tabTmp2[1];
|
||
|
}
|
||
|
if ( strtoupper($entrep['typeBilan'])=='S' ) {
|
||
|
$mBil = new Metier_Partenaires_MBilans(0, $this->iDb);
|
||
|
$tabTmp = $mBil->bilanSimplifie2Normal($tabBilan);
|
||
|
$tabBilan = array_merge($tabTmp, $tabBilan);
|
||
|
}
|
||
|
|
||
|
$tabRet['bilanDA'] = $tabBilan['DA'];
|
||
|
$tabRet['bilanFL'] = $tabBilan['FL'];
|
||
|
$tabRet['bilanHN'] = $tabBilan['HN'];
|
||
|
$tabRet['bilanYP'] = $tabBilan['YP'];
|
||
|
|
||
|
// Fiche AGS
|
||
|
$tabRet['bilanPQ'] = $tabBilan['PQ'];
|
||
|
$tabRet['bilanPU'] = $tabBilan['PU'];
|
||
|
$tabRet['bilanPY'] = $tabBilan['PY'];
|
||
|
$tabRet['bilanQC'] = $tabBilan['QC'];
|
||
|
|
||
|
// Tranche de CA Bilan Réel si TCA Insee ou Estimée < dernière clôture
|
||
|
if ($tabRet['AnneeTCA']<=$tabRet['bilanAnnee'] && $tabInsee['ACTIF']==1) {
|
||
|
$tabRet['TrancheCA']=$this->getTca($tabBilan['FL']);
|
||
|
$tabRet['TrancheCALib']=self::$tabTCA[$tabRet['TrancheCA']];
|
||
|
$tabRet['TrancheCAType']='R';
|
||
|
$tabRet['AnneeTCA']=$tabRet['bilanAnnee'];
|
||
|
}
|
||
|
|
||
|
// Contrôle de la cohérence du type d'exploitation
|
||
|
if ($tabBilan['AH']>0 && // Je possède un fond commercial
|
||
|
$tabRet['TypeExploitation']<>2 && // et je ne suis pas Loueur d'un fond
|
||
|
$tabRet['TypeExploitation']<>3 && // et je ne suis pas Prestataire de personnel
|
||
|
$tabRet['TypeExploitation']<>10) { // et je ne suis pas exploitant direct
|
||
|
$tabRet['TypeExploitation']=10;
|
||
|
}
|
||
|
|
||
|
// Controle de cohérence du capital car parfois absent en Alsace Moselle au RNCS
|
||
|
if ($tabRet['FJ']>2000 && $tabRet['Capital']==0 && $tabRet['CapitalDev']=='') {
|
||
|
$tabRet['Capital']=$tabRet['bilanDA'];
|
||
|
$tabRet['CapitalDev']=$tabRet['bilanDevise'];
|
||
|
}
|
||
|
|
||
|
$timer['infosBilan']=microtime(true);
|
||
|
} elseif ( $caEstime>0 && $tabInsee['ACTIF']==1 ) {
|
||
|
$tabRet['bilanAnnee'] = date('Y')-2;
|
||
|
$tabRet['bilanFLestime']=$caEstime;
|
||
|
}
|
||
|
|
||
|
$tabRet['TribunalLib'] = $this->iBodacc->getTribunalNom($tabRet['Tribunal']);
|
||
|
|
||
|
if($this->debugtime) {
|
||
|
$duree=round(microtime(1)-$tdebIni,3);
|
||
|
file_put_contents(LOG_PATH.'/accesDistant.log', date('YmdHis').";$siren;getIdentiteEntreprise Fin ($duree s) ===\n", FILE_APPEND);
|
||
|
}
|
||
|
|
||
|
// Si on n'a trouvé aucune activité, on prend le libellé de l'activité pages Jaunes
|
||
|
if ($tabRet['Activite']=='' && $activitePJ_An8<>'')
|
||
|
$tabRet['Activite']=$activitePJ_An8;
|
||
|
|
||
|
// Numero de Registre du métier si nécessaire
|
||
|
if ( ($tabRet['FJ']==1100 || $tabRet['FJ']==1300 || $tabRet['FJ']==11 || $tabRet['FJ']==13 || $tabInsee['APRM']<>'') &&
|
||
|
($tabRet['Dept']=='2A' || $tabRet['Dept']=='2B' || $tabRet['Dept']<98) ) {
|
||
|
// Artisan Commerçant OU Artisan en FRANCE
|
||
|
$tabRet['NumRM']=$siren.' RM '.$tabRet['Dept'];
|
||
|
if ($tabRet['Dept']=='2A') $tabRet['NumRM'].='.1'; // Ajaccio
|
||
|
elseif ($tabRet['Dept']=='2B') $tabRet['NumRM'].='.2'; // Bastia
|
||
|
elseif ($tabRet['Dept']==97) $tabRet['NumRM'].=substr($tabRet['codeCommune'],0,1);
|
||
|
}
|
||
|
|
||
|
// Recherche des infos boursières
|
||
|
$iBourse = new Metier_Partenaires_MBourse($siren, $this->iDb);
|
||
|
$bourse = $iBourse->getInfosBourse($siren);
|
||
|
$tabRet['Bourse'] = array(
|
||
|
'placeCotation' => $bourse['placeCotation'],
|
||
|
'nombreTitres' => $bourse['nombreTitres'],
|
||
|
'capitalisation' => $bourse['close']*$bourse['nombreTitres'],
|
||
|
'derCoursDate' => $bourse['date'],
|
||
|
'derCoursCloture' => $bourse['close']
|
||
|
);
|
||
|
$timer['infosBoursieres']=microtime(true);
|
||
|
}
|
||
|
|
||
|
// Date de dernière mise à jour
|
||
|
$lastMaj=str_replace('-','',$tabRet['DateMajINSEE'])*1;
|
||
|
if (str_replace('-','',$tabRet['DateMajRCS'])*1>$lastMaj)
|
||
|
$lastMaj=str_replace('-','',$tabRet['DateMajRCS'])*1;
|
||
|
if (str_replace('-','',$tabRet['bilanDateMaj'])*1>$lastMaj)
|
||
|
$lastMaj=str_replace('-','',$tabRet['bilanDateMaj'])*1;
|
||
|
if (str_replace('-','',$tabRet['dateMajANN'])*1>$lastMaj)
|
||
|
$lastMaj=str_replace('-','',$tabRet['dateMajANN'])*1;
|
||
|
$tabRet['dateMajIdentite']=Metier_Util_Date::dateT('Ymd','Y-m-d',$lastMaj);
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Dirigeants Opérationnel
|
||
|
* @param string $siren
|
||
|
* @param string $id
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getDirigeantsOp($siren, $id = null)
|
||
|
{
|
||
|
$siren=$siren*1;
|
||
|
$tabRet=array();
|
||
|
|
||
|
$where = "siren=$siren AND d.codFct=f.codeFct AND dateSuppr='0000-00-00 00:00:00.000000'";
|
||
|
if ($id!=null){
|
||
|
$where = "id=$id AND d.codFct=f.codeFct AND dateSuppr='0000-00-00 00:00:00.000000'";
|
||
|
}
|
||
|
|
||
|
$dirs=$this->iDb->select(
|
||
|
'sdv1.dirigeantsOp d, jo.bodacc_fonctions f',
|
||
|
'id, siren, nic, civ, nom, prenom, nom_usage, lieuNais, dateNais, d.codFct, f.libelle, tel, fax, email, dateInsert, dateUpdate',
|
||
|
$where, false, MYSQL_ASSOC);
|
||
|
|
||
|
foreach ($dirs as $k=>$dir) {
|
||
|
$tabRet[]=array(
|
||
|
'Id' => $dir['id'],
|
||
|
'Fonction' => $dir['codFct'],
|
||
|
'Titre' => $dir['libelle'],
|
||
|
'Societe' => '',
|
||
|
'Civilite' => $dir['civ'],
|
||
|
'Nom' => trim(strtoupper($dir['nom'])),
|
||
|
'Prenom' => ucwords(strtolower($dir['prenom'])),
|
||
|
'NomUsage' => $dir['nom_usage'],
|
||
|
'NaissDate' => $dir['dateNais'],
|
||
|
'NaissVille' => $dir['lieuNais'],
|
||
|
'NaissDepPays' => '',
|
||
|
'Tel' => $dir['tel'],
|
||
|
'Fax' => $dir['fax'],
|
||
|
'Email' => $dir['email'],
|
||
|
'Ancien' => 0,
|
||
|
'DateFct' => '',
|
||
|
'Cinf' => 0,
|
||
|
);
|
||
|
}
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne les dirigeants actuelles ou l'historique
|
||
|
* @param string $siren
|
||
|
* @param boolean $histo
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getDirigeants($siren, $histo = true)
|
||
|
{
|
||
|
$siren = intval($siren);
|
||
|
$tabRet = array();
|
||
|
|
||
|
if ($histo) {
|
||
|
|
||
|
$bodacc = $this->iDb->select('jo.bodacc_dirigeants d, jo.bodacc_detail b, jo.bodacc_fonctions f',
|
||
|
'd.num, d.dateEffet, d.Rubrique, d.fonction, d.dirSiren, d.rs, d.nom, d.prenom, d.nomUsage, d.depart, d.dateInsert, f.libelle',
|
||
|
"b.SIREN=$siren AND b.id=d.id AND b.typeEven NOT BETWEEN 5000 AND 5700 AND b.typeEven NOT BETWEEN 2700 AND 2900 AND d.fonction=f.codeFct GROUP BY d.fonction, d.rs, d.nom, d.prenom ORDER BY d.dateInsert DESC, d.dateEffet DESC, d.fonction DESC", true, MYSQL_ASSOC);
|
||
|
if (count($bodacc)>0) {
|
||
|
foreach ($bodacc as $k=>$ann) {
|
||
|
$tabRet[]=array(
|
||
|
'Fonction' => $ann['fonction'],
|
||
|
'Titre' => $ann['libelle'],
|
||
|
'Siren' => $ann['dirSiren'],
|
||
|
'Societe' => $ann['rs'],
|
||
|
'Nom' => trim(strtr($ann['nom'], array(
|
||
|
"Modification d'"=>'',
|
||
|
"Modification de"=>'',
|
||
|
"Nomination d'un"=>'',
|
||
|
))),
|
||
|
'Prenom' => $ann['prenom'],
|
||
|
'NomUsage' => $ann['nomUsage'],
|
||
|
'Ancien' => $ann['depart'],
|
||
|
'DateFct' => $ann['dateEffet'], //Date au format AAAA-MM-DD
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$bodaccHisto = $this->iDb->select('historiques.entrep e, historiques.texte x',
|
||
|
'e.ANBASE, e.NOBOD, e.CODTRI, e.JAL, e.DATE, e.CODEVE, e.SSCODE, e.DEPT, e.NOANN, e.ROLE, e.SIREN, e.E1GSIR, e.E1GNIC, x.annonceNum, x.annonceTxt',
|
||
|
"e.E1GSIR=$siren AND e.ANBASE=x.annonceNum AND e.DATE BETWEEN 19960101 AND 20050101 AND x.annonceTxt LIKE '%Administration%' GROUP BY e.ANBASE ORDER BY e.DATE DESC", true, MYSQL_ASSOC);
|
||
|
if (count($bodaccHisto)>0) {
|
||
|
foreach ($bodaccHisto as $ann) {
|
||
|
|
||
|
if ( ($ann['CODEVE']<20) ||
|
||
|
($ann['CODEVE']>=30 && $ann['CODEVE']<42) || ($ann['CODEVE']>=51 && $ann['CODEVE']<80) ) {
|
||
|
if (preg_match('/Administration(?:.|)\:(.*)(?:Adresse.*|Commentaires?|Activit(?:e|é)|Etablissement principal|Date d\'effet|Date.de.d.but d.activit.)(?:.|)\:/Uisu', $ann['annonceTxt'], $matches)) {
|
||
|
$iDir=0;
|
||
|
$tabAdministration = $this->iBodacc->getDirigeants($matches[1]);
|
||
|
foreach ($tabAdministration as $tabDir) {
|
||
|
$nom = trim(strtr(preg_replace('/ +/',' ', $tabDir['nom']), array(
|
||
|
"Modification d'"=>'',
|
||
|
"Modification"=>'',
|
||
|
"Modification de"=>'',
|
||
|
"Nomination d'un"=>'',
|
||
|
"Nomination en qualité d'"=>'',
|
||
|
"Nomination en qualité de"=>'',
|
||
|
"dont le est"=>'',
|
||
|
"nouvel"=>'',
|
||
|
"partant"=>'',
|
||
|
"ancien d'honneur"=>'',
|
||
|
"nouveaux"=>'',
|
||
|
"nouveau"=>'',
|
||
|
"ancien"=>'',
|
||
|
"Nouveau"=>'',
|
||
|
"Cette société se constitue Date de début d'"=>'',
|
||
|
)));
|
||
|
if ($nom<>'') {
|
||
|
$tabRet[] = array(
|
||
|
'Fonction' => $tabDir['fonction'],
|
||
|
'Titre' => $this->iBodacc->getFctDir($tabDir['fonction']),//.' ('.$tabDir['fonction'].')',
|
||
|
'Societe' => $tabDir['rs'],
|
||
|
'Nom' => $nom,
|
||
|
'Prenom' => $tabDir['prenom'],
|
||
|
'NomUsage' => $tabDir['nomUsage'],
|
||
|
'Ancien' => $tabDir['depart'],
|
||
|
'DateFct' => Metier_Util_Date::dateT('Ymd','Y-m-d', $ann['DATE']),
|
||
|
);
|
||
|
$this->iDb->insert('jo.bodacc_dirigeants_histo', array(
|
||
|
'siren' => $siren,
|
||
|
'id' => $ann['ANBASE'],
|
||
|
'num' => $iDir,
|
||
|
'dateEffet' => Metier_Util_Date::dateT('Ymd','Y-m-d', $ann['DATE']),
|
||
|
'fonction' => $tabDir['fonction'],
|
||
|
'rs' => $tabDir['rs'],
|
||
|
'nom' => $nom,
|
||
|
'prenom' => $tabDir['prenom'],
|
||
|
'nomUsage' => $tabDir['nomUsage'],
|
||
|
'depart' => $tabDir['depart'],
|
||
|
), true);
|
||
|
|
||
|
$iDir++;
|
||
|
}
|
||
|
} //End foreach
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!$histo || ($histo && count($tabRet)==0) )
|
||
|
{
|
||
|
$dirs=$this->iDb->select(
|
||
|
'jo.rncs_dirigeants',
|
||
|
'siren, raisonSociale, LPAD(dirSiren,9,0) AS dirSiren, dirRS, civilite, nom, prenom, naissance_nom, naissance_date, naissance_lieu, fonction_code, fonction_lib, cinf, dateFin, flux, dateInsert',
|
||
|
"siren=$siren AND actif%10=1", false, MYSQL_ASSOC);
|
||
|
|
||
|
foreach ($dirs as $k=>$dir) {
|
||
|
if ($dir['naissance_date']<>'0000-00-00') {
|
||
|
$dateNaiss=Metier_Util_Date::dateT('Y-m-d','d/m/Y', $dir['naissance_date']);
|
||
|
} else {
|
||
|
$dateNaiss='';
|
||
|
}
|
||
|
|
||
|
if ($dir['flux']<>'0000-00-00') {
|
||
|
$dateModif=Metier_Util_Date::dateT('Y-m-d','d/m/Y', $dir['flux']);
|
||
|
} else {
|
||
|
$dateModif=Metier_Util_Date::dateT('Y-m-d','d/m/Y', $dir['dateInsert']);
|
||
|
}
|
||
|
|
||
|
$nom = trim($dir['nom']);
|
||
|
$nomUsage='';
|
||
|
if (trim($dir['naissance_nom'])<>'') {
|
||
|
$nom=trim($dir['naissance_nom']);
|
||
|
$nomUsage=trim($dir['nom']);
|
||
|
}
|
||
|
$tabRet[] = array(
|
||
|
'Fonction' =>$dir['fonction_code'],
|
||
|
'Titre' =>$dir['fonction_lib'],
|
||
|
'Siren' =>$dir['dirSiren'],
|
||
|
'Societe' =>$dir['dirRS'],
|
||
|
'Civilite' =>$dir['civilite'],
|
||
|
'Nom' =>$nom,
|
||
|
'Prenom' =>$dir['prenom'],
|
||
|
'NomUsage' =>$nomUsage,
|
||
|
'NaissDate' =>$dateNaiss,
|
||
|
'NaissVille' =>$dir['naissance_lieu'],
|
||
|
'NaissDepPays' =>'', // 25
|
||
|
'Ancien' =>0,
|
||
|
'DateFct' =>$dateModif, //Format AAAA-MM-DD
|
||
|
'Cinf' =>$dir['cinf'],
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** Recherche de CAC si liste des dirigeants actifs **/
|
||
|
if (!$histo) {
|
||
|
$bodacc=$this->iDb->select(
|
||
|
'jo.bodacc_dirigeants d, jo.bodacc_detail b, jo.bodacc_fonctions f',
|
||
|
'd.num, d.dateEffet, d.Rubrique, d.fonction, LPAD(d.dirSiren,9,0) AS dirSiren, d.rs, d.nom, d.prenom, d.nomUsage, d.depart, d.dateInsert, f.libelle',
|
||
|
"b.SIREN=$siren AND b.id=d.id AND b.typeEven NOT BETWEEN 5000 AND 5700 AND b.typeEven NOT BETWEEN 2700 AND 2900 AND d.fonction=f.codeFct AND d.fonction BETWEEN 300 AND 304 GROUP BY d.fonction, d.rs, d.nom, d.prenom ORDER BY d.dateEffet DESC, d.fonction DESC", false, MYSQL_ASSOC);
|
||
|
if (count($bodacc)>0) {
|
||
|
foreach ($bodacc as $k=>$ann) {
|
||
|
$rs=trim(strtoupper($ann['rs']));
|
||
|
$nom=preg_replace('/en fonction le .*/i','',$ann['nom']);
|
||
|
$nom=preg_replace('/Nomination .*/i','',$nom);
|
||
|
$nom=preg_replace('/Modification .*/i','',$nom);
|
||
|
$nom=preg_replace('/Nouvelles?\s+$/i','',trim($nom));
|
||
|
$nom=preg_replace('/Nouveaux?\s+$/i','',trim($nom));
|
||
|
$nom=preg_replace('/ancien.*/i','',$nom);
|
||
|
$nom=preg_replace('/en remplacement d.*/i','',$nom);
|
||
|
$nom=trim(strtoupper(preg_replace('/(\.|,)$/','',trim($nom))));
|
||
|
$prenom=trim($ann['prenom']);
|
||
|
if ($prenom=='' && $rs=='' && $nom<>'') {
|
||
|
$rs=$nom;
|
||
|
$nom='';
|
||
|
}
|
||
|
//if ($rs==$nom)
|
||
|
$tabRet[]=array(
|
||
|
'Fonction' => $ann['fonction'],
|
||
|
'Titre' => $ann['libelle'],
|
||
|
'Siren' => $ann['dirSiren'],
|
||
|
'Societe' => $rs,
|
||
|
'Nom' => $nom,
|
||
|
'Prenom' => $prenom,
|
||
|
'NomUsage' => $ann['nomUsage'],
|
||
|
'Ancien' => $ann['depart'],
|
||
|
'DateFct' => $ann['dateEffet'], //Format AAAA-MM-DD
|
||
|
);
|
||
|
if ($k>1) break; // On s'arrête à 2 CAC (pb des co-cac non gérés)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** Si on ne trouve absolument rien, on regarde quand même dans l'histroique RNCS **/
|
||
|
if (count($tabRet)==0) {
|
||
|
$dirs=$this->iDb->select(
|
||
|
'jo.rncs_dirigeants',
|
||
|
'siren, raisonSociale, LPAD(dirSiren,9,0) AS dirSiren, dirRS, civilite, nom, prenom, naissance_nom, naissance_date, naissance_lieu, fonction_code, fonction_lib, cinf, dateFin, flux, dateInsert, date(dateUpdate)*1 as dateUpdate',
|
||
|
"siren=$siren AND actif%10=0 ORDER BY dateUpdate DESC", false, MYSQL_ASSOC);
|
||
|
|
||
|
$dateUpdatePre=$dirs[0]['dateUpdate'];
|
||
|
foreach ($dirs as $k=>$dir) {
|
||
|
if ($dir['naissance_date']<>'0000-00-00')
|
||
|
$dateNaiss=Metier_Util_Date::dateT('Y-m-d','d/m/Y', $dir['naissance_date']);
|
||
|
else
|
||
|
$dateNaiss='';
|
||
|
if ($dir['flux']<>'0000-00-00')
|
||
|
$dateModif=Metier_Util_Date::dateT('Y-m-d','d/m/Y', $dir['flux']);
|
||
|
else
|
||
|
$dateModif=Metier_Util_Date::dateT('Y-m-d','d/m/Y', $dir['dateInsert']);
|
||
|
if ($dir['dateUpdate']<>$dateUpdatePre) break;
|
||
|
$tabRet[] = array(
|
||
|
'Fonction' => $dir['fonction_code'],
|
||
|
'Titre' => $dir['fonction_lib'],
|
||
|
'Siren' => $dir['dirSiren'],
|
||
|
'Societe' => $dir['dirRS'],
|
||
|
'Civilite' => $dir['civilite'],
|
||
|
'Nom' => trim($dir['nom']),
|
||
|
'Prenom' => $dir['prenom'],
|
||
|
'NomUsage' => $tabDir['nomUsage'],
|
||
|
'NaissDate' => $dateNaiss,
|
||
|
'NaissVille' => $dir['naissance_lieu'],
|
||
|
'NaissDepPays' => '', // 25
|
||
|
'Ancien' => 1,
|
||
|
'DateFct' => $dateModif, //Format AAAA-MM-DD
|
||
|
'Cinf' => $dir['cinf'],
|
||
|
);
|
||
|
$dateUpdatePre=$dir['dateUpdate'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (count($tabRet)==0) {
|
||
|
if ($tabIdentite['FJ']*1>1000 && $tabIdentite['FJ']*1<2000) {
|
||
|
$tabTmp=explode(' ', $tabIdentite['Nom']);
|
||
|
$nom=$prenom='';
|
||
|
foreach ($tabTmp as $mot)
|
||
|
if (strtoupper($mot)==$mot)
|
||
|
$nom.=' '.$mot;
|
||
|
else
|
||
|
$prenom.=' '.$mot;
|
||
|
if ($etab['Civilite']*1==1) { $genre='Monsieur '; $civilite='M'; }
|
||
|
elseif ($etab['Civilite']*1==2) { $genre='Madame '; $civilite='MME'; }
|
||
|
else { $genre=''; $civilite=''; }
|
||
|
|
||
|
$tabTmp=$this->iDb->select('insee.identite',
|
||
|
'SIREN, CJ, CIVILITE, DIR_DATEN, DIR_LIEUN',
|
||
|
"SIREN=$siren AND (DIR_DATEN>0 OR DIR_LIEUN<>'') ORDER BY DIR_DATEN DESC, DIR_LIEUN DESC",
|
||
|
false, MYSQL_ASSOC);
|
||
|
$tabTmp=@$tabTmp[0];
|
||
|
|
||
|
$tabRet[] = array(
|
||
|
'Titre' => 'Personne physique',
|
||
|
'Societe' => '',
|
||
|
'Civilite' => $civilite,
|
||
|
'Nom' => trim($nom),
|
||
|
'Prenom' => trim($prenom),
|
||
|
'NomUsage' => '',
|
||
|
'NaissDate' => Metier_Util_Date::dateT('Ymd', 'd/m/Y', $tabTmp['DIR_DATEN']),// 07/09/1961
|
||
|
'NaissVille' => $tabTmp['DIR_LIEUN'], // LE RUSSEY//,
|
||
|
'NaissDepPays' => '', // 25
|
||
|
'Ancien' => 0,
|
||
|
'DateFct' => $tabIdentite['DateCrea'],//$tabIdentite['DateImma'],
|
||
|
);
|
||
|
$this->iDb->insert('jo.rncs_dirigeants', array(
|
||
|
'siren' => $siren,
|
||
|
'raisonSociale' => $etab['Nom'],
|
||
|
'civilite' => $civilite,
|
||
|
'nom' => trim($nom),
|
||
|
'prenom' => trim($prenom),
|
||
|
'naissance_nom' => '',
|
||
|
'naissance_date'=> $tabTmp['DIR_DATEN'],
|
||
|
'naissance_lieu'=> $tabTmp['DIR_LIEUN'],
|
||
|
'fonction_code' => 1050,
|
||
|
'fonction_lib' => 'Personne physique',
|
||
|
'actif' => 1,
|
||
|
'dateInsert' => date('YmdHis'),
|
||
|
'source' => 'inp',
|
||
|
), true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne le nombre d'annonces
|
||
|
* @param string $siren
|
||
|
* @param number $idAnnonce
|
||
|
* @param string $rubrique
|
||
|
* @param string $deleted
|
||
|
* @return int
|
||
|
*/
|
||
|
public function getAnnoncesLegalesCount($siren, $idAnnonce = 0, $rubrique = '', $deleted = false)
|
||
|
{
|
||
|
// --- Where Bodacc
|
||
|
$sqlBodaccWhere = "d.siren=$siren";
|
||
|
$sqlBodaccWhere.= $this->getAnnoncesLegalesRubrique('bodacc', $rubrique);
|
||
|
$sqlBodaccWhere.= " AND d.id=b.id AND b.Tribunal_Code=t.triCode";
|
||
|
// --- Annonces supprimées ou rectifiées
|
||
|
if ( $deleted === true ) {
|
||
|
$sqlBodaccWhere.= " AND (d.dateSuppr=0 OR d.dateSuppr!='0000-00-00 00:00:00' AND d.idSuppr=0) ";
|
||
|
} else {
|
||
|
$sqlBodaccWhere.= " AND d.dateSuppr=0 ";
|
||
|
}
|
||
|
$sqlBodacc = $this->getAnnoncesLegalesBodacc(true)." WHERE ".$sqlBodaccWhere;
|
||
|
|
||
|
// --- Where Histo
|
||
|
$sqlHistoWhere = "e.E1GSIR=$siren";
|
||
|
$sqlHistoWhere.= $this->getAnnoncesLegalesRubrique('histo', $rubrique);
|
||
|
$sqlHistoWhere.= " AND e.ANBASE=x.annonceNum AND e.DATE BETWEEN 19890101 AND 20041231";
|
||
|
$sqlHistoWhere.= " AND e.E1GSIR=e.SIREN";
|
||
|
$sqlHistoWhere.= " GROUP BY e.ANBASE ORDER BY e.DATE DESC";
|
||
|
$sqlHisto = $this->getAnnoncesLegalesHisto(true)." WHERE ".$sqlHistoWhere;
|
||
|
|
||
|
// --- Where Annonce
|
||
|
$sqlAnnonceWhere = "a.siren=$siren";
|
||
|
$sqlAnnonceWhere.= $this->getAnnoncesLegalesRubrique('annonce', $rubrique);
|
||
|
$sqlAnnonceWhere.= " AND a.tribunal=t.triCode AND a.dateSuppr=0";
|
||
|
if ($visualisation === true) {
|
||
|
// --- Ne pas afficher les annonces si la procédure à plus de 4 mois
|
||
|
$sqlAnnonceWhere.= " AND a.dateJugement > DATE_SUB(NOW(), INTERVAL 24 MONTH)";
|
||
|
}
|
||
|
$sqlAnnonceWhere.= " GROUP BY a.siren, a.dateJugement, a.typeEven ORDER BY a.dateJugement DESC";
|
||
|
$sqlAnnonce = $this->getAnnoncesLegalesAnnonce(true)." WHERE ".$sqlAnnonceWhere;
|
||
|
|
||
|
// --- SQL Union
|
||
|
$sql = "SELECT count(*) AS num FROM ( (".$sqlBodacc.") UNION ALL (".$sqlHisto.") UNION ALL (".$sqlAnnonce.") ) results ORDER BY unionDate DESC";
|
||
|
$annonceResult = $this->iDb->query($sql);
|
||
|
|
||
|
$nb = 0;
|
||
|
if (count($annonceResult)>0) {
|
||
|
$nb = $annonceResult[0]['num'];
|
||
|
}
|
||
|
return $nb;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Where SQL
|
||
|
* @param string $type bodacc, histo
|
||
|
* @param mixed $rubrique
|
||
|
* @return boolean|string
|
||
|
*/
|
||
|
public function getAnnoncesLegalesRubrique($type, $rubrique = '')
|
||
|
{
|
||
|
$where = '';
|
||
|
|
||
|
// --- Type Bodacc
|
||
|
if ($type == 'bodacc') {
|
||
|
// Procédure collective
|
||
|
if ($rubrique=='P' || $rubrique=='PH') {
|
||
|
$where = " AND d.Rubrique='procol'
|
||
|
AND d.typeEven NOT LIKE '%1005%'
|
||
|
AND d.typeEven NOT LIKE '%1010%'
|
||
|
AND d.typeEven NOT LIKE '%1050%'
|
||
|
AND d.typeEven NOT LIKE '%1055%'
|
||
|
AND d.typeEven NOT LIKE '%1550%' ";
|
||
|
}
|
||
|
// Dissolution de la société
|
||
|
elseif ($rubrique=='D') {
|
||
|
$where =" AND (d.typeEven LIKE '%2202%' OR d.typeEven LIKE '%2203%' OR d.typeEven LIKE '%2204%' OR
|
||
|
d.typeEven LIKE '%2210%' OR d.typeEven LIKE '%2211%' OR d.typeEven LIKE '%2212%') ";
|
||
|
}
|
||
|
// Absorption
|
||
|
elseif ($rubrique=='A') {
|
||
|
$where =" AND (d.typeEven LIKE '%2720%' OR d.typeEven LIKE '%2721%') ";
|
||
|
}
|
||
|
// BODACC A
|
||
|
elseif ($rubrique=='BODA') {
|
||
|
$where =" AND d.Rubrique IN ('creations','procol','ventes') ";
|
||
|
}
|
||
|
// BODACC B
|
||
|
elseif ($rubrique=='BODB') {
|
||
|
$where =" AND d.Rubrique IN ('mmd','radiations') ";
|
||
|
}
|
||
|
// Dépôt des comptes, BODACC C
|
||
|
elseif ($rubrique=='C' || $rubrique=='BODC') {
|
||
|
$where =" AND (d.Rubrique='comptes' OR d.typeEven LIKE '%3100%' OR d.typeEven LIKE '%3200%'
|
||
|
OR d.typeEven LIKE '%3300%' OR d.typeEven LIKE '%3999%') ";
|
||
|
} elseif ($rubrique=='R') {
|
||
|
$where =" AND (d.typeEven LIKE '%2202%' OR d.typeEven LIKE '%2203%' OR d.typeEven LIKE '%2204%' OR
|
||
|
d.typeEven LIKE '%2210%' OR d.typeEven LIKE '%2211%' OR d.typeEven LIKE '%2212%' OR
|
||
|
d.Rubrique='radiations') ";
|
||
|
}
|
||
|
// Location gérance Locataire
|
||
|
elseif ($rubrique=='L') {
|
||
|
$where =" AND (d.typeEven LIKE '%2800%' OR d.typeEven LIKE '%2875%' OR d.typeEven LIKE '%2880%' OR
|
||
|
d.typeEven LIKE '%2881%' OR d.typeEven LIKE '%2885%' OR d.typeEven LIKE '%2840%' OR
|
||
|
d.typeEven LIKE '%4355%') ";
|
||
|
}
|
||
|
// Location gérance Propriétaire
|
||
|
elseif ($rubrique=='G') {
|
||
|
$where =" AND (d.typeEven LIKE '%2850%' OR d.typeEven LIKE '%2851%' OR d.typeEven LIKE '%2860%' OR
|
||
|
d.typeEven LIKE '%2870%') ";
|
||
|
}
|
||
|
// Ventes/Cessions
|
||
|
elseif ($rubrique=='V') {
|
||
|
$where =" AND (d.typeEven LIKE '%5500%' OR d.typeEven LIKE '%5501%' OR d.typeEven LIKE '%5502%' OR
|
||
|
d.typeEven LIKE '%5503%' OR d.typeEven LIKE '%5510%' OR d.typeEven LIKE '%5600%' OR
|
||
|
d.typeEven LIKE '%5650%') ";
|
||
|
} elseif (is_array($rubrique) && count($rubrique)>0) {
|
||
|
$where =" AND (";
|
||
|
foreach ($rubrique as $codeEven) {
|
||
|
$tabTmp[]=" d.typeEven LIKE '%$codeEven%' ";
|
||
|
}
|
||
|
$where.= implode(' OR ',$tabTmp);
|
||
|
$where.=')';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Type historique
|
||
|
if ($type == 'histo') {
|
||
|
if ($rubrique=='P') {
|
||
|
$where =" AND e.E1GSIR NOT IN(340460104) AND e.CODEVE BETWEEN 50 AND 79 ";
|
||
|
}
|
||
|
elseif ($rubrique=='PH') {
|
||
|
$where =" AND e.CODEVE BETWEEN 50 AND 79 ";
|
||
|
}
|
||
|
elseif ($rubrique=='R') {
|
||
|
$where =" AND e.CODEVE BETWEEN 40 AND 42 ";
|
||
|
}
|
||
|
elseif ($rubrique=='L') {
|
||
|
$where =" AND e.CODEVE IN(37,42) ";
|
||
|
}
|
||
|
elseif ($rubrique=='G') {
|
||
|
$where =" AND e.CODEVE=38 ";
|
||
|
}
|
||
|
elseif ($rubrique=='BODA') {
|
||
|
$where =" AND e.JAL=1 ";
|
||
|
}
|
||
|
elseif ($rubrique=='BODB') {
|
||
|
$where =" AND e.JAL=200 ";
|
||
|
}
|
||
|
elseif (is_array($rubrique)) {
|
||
|
$tabCodEve = $tabCodRol = array();
|
||
|
foreach ($rubrique as $codeEvenTmp) {
|
||
|
$codRet=array_search($codeEvenTmp, $this->HistoRoleConvert); // Ne gère pas les ; de tabtmp2
|
||
|
if ($codRet) {
|
||
|
$tabCodRol[] = $codRet;
|
||
|
} else {
|
||
|
$tabCodEve[] = array_search($codeEvenTmp, $this->HistoEvenConvert)*1;
|
||
|
}
|
||
|
}
|
||
|
$where ='';
|
||
|
$tabCodEve = array_unique($tabCodEve);
|
||
|
$tabCodRol = array_unique($tabCodRol);
|
||
|
if (count($tabCodEve)>0) {
|
||
|
$where.=' AND e.CODEVE IN('.implode(',',$tabCodEve).') ';
|
||
|
}
|
||
|
if (count($tabCodRol)>0) {
|
||
|
$where.=" AND e.ROLE IN('".implode("','",$tabCodRol)."') ";
|
||
|
}
|
||
|
}
|
||
|
elseif ( !empty($rubrique) ) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Type annonce
|
||
|
if ($type == 'annonce') {
|
||
|
// Procédure collective
|
||
|
if ($rubrique=='P' || $rubrique=='PH') {
|
||
|
$where = " AND a.typeEven BETWEEN 1000 AND 1999 AND a.typeEven NOT IN(1005, 1010, 1050, 1055, 1550) ";
|
||
|
}
|
||
|
// Dissolution de la société
|
||
|
elseif ($rubrique=='D') {
|
||
|
$where = " AND a.typeEven IN (2202, 2203, 2204, 2210, 2211, 2212) ";
|
||
|
}
|
||
|
// Absorption
|
||
|
elseif ($rubrique=='A') {
|
||
|
$where = " AND a.typeEven IN (2720, 2721) ";
|
||
|
}
|
||
|
// Dépôt des comptes
|
||
|
elseif ($rubrique=='C' || $rubrique=='BODC') {
|
||
|
$where = " AND a.typeEven BETWEEN 3000 AND 3999 ";
|
||
|
} elseif ($rubrique=='R') {
|
||
|
$where = " AND a.typeEven IN (2202, 2203, 2204, 2210, 2211, 2212) ";
|
||
|
}
|
||
|
// Location gérance Locataire
|
||
|
elseif ($rubrique=='L') {
|
||
|
$where = " AND a.typeEven IN (2800, 2875, 2880, 2881, 2885, 2840) ";
|
||
|
}
|
||
|
// Location gérance Propriétaire
|
||
|
elseif ($rubrique=='G') {
|
||
|
$where = " AND a.typeEven IN (2850, 2851, 2860, 2870) ";
|
||
|
}
|
||
|
// Ventes/Cessions
|
||
|
elseif ($rubrique=='V') {
|
||
|
$where = " AND a.typeEven IN (5500, 5501, 5502, 5503, 5510, 5600, 5650) ";
|
||
|
} elseif (is_array($rubrique) && count($rubrique)>0) {
|
||
|
$where = " AND (a.typeEven IN (".implode(',',$rubrique).') OR ';
|
||
|
foreach ($rubrique as $codeEven) {
|
||
|
$tabTmp[] = " a.typeEven LIKE '%$codeEven%' ";
|
||
|
}
|
||
|
$where.= implode(' OR ',$tabTmp);
|
||
|
$where.= ')';
|
||
|
}
|
||
|
elseif ( !empty($rubrique) ) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $where;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Parse les annonces légales pour déterminer leur rubrique
|
||
|
* plus rapide d'executer sur la liste des annonces légales que d'executer les requetes SQL
|
||
|
* @param array $annonces Annonces au format BDD
|
||
|
* @param mixed $rubrique
|
||
|
* @return array
|
||
|
* Retourne une liste filtrer suivant la/les rubriques
|
||
|
*/
|
||
|
public function annoncesInRubrique($annonces, $rubrique)
|
||
|
{
|
||
|
$annonceFilter = array();
|
||
|
|
||
|
foreach ($annonces as $ann) {
|
||
|
|
||
|
// --- Formatage bodacc
|
||
|
if ($ann['SourceTable'] == 'bodacc') {
|
||
|
$typeEven = explode(' ', $ann['typeEven']);
|
||
|
// Procédure collective
|
||
|
if ($rubrique=='P' || $rubrique=='PH') {
|
||
|
$evenOk = true;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('1005','1010','1050','1055','1550'))) {
|
||
|
$evenOk = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($ann['Rubrique'] == 'procol' && $evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Dissolution de la société
|
||
|
elseif ($rubrique=='D') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2202','2203','2204','2210','2211','2212'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Absorption
|
||
|
elseif ($rubrique=='A') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2720','2721'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// BODACC A
|
||
|
elseif ($rubrique=='BODA') {
|
||
|
if (in_array($ann['Rubrique'], array('creations', 'procol', 'ventes'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// BODACC B
|
||
|
elseif ($rubrique=='BODB') {
|
||
|
if (in_array($ann['Rubrique'], array('mmd', 'radiations'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Dépôt des comptes, BODACC C
|
||
|
elseif ($rubrique=='C' || $rubrique=='BODC') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('3100','3200','3300','3999'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($ann['Rubrique'] == 'comptes' || $evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
} elseif ($rubrique=='R') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2202','2203','2204','2210','2211','2212'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($ann['Rubrique'] == 'radiations' || $evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Location gérance Locataire
|
||
|
elseif ($rubrique=='L') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2800','2875','2880','2881','2885','2840','4355'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Location gérance Propriétaire
|
||
|
elseif ($rubrique=='G') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2850','2851','2860','2870'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Ventes/Cessions
|
||
|
elseif ($rubrique=='V') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('5500','5501','5502','5503','5510','5600','5650'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
} elseif (is_array($rubrique) && count($rubrique) > 0) {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, $rubrique)) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Formattage Histo
|
||
|
elseif ($ann['SourceTable'] == 'histo') {
|
||
|
if ($rubrique=='P') {
|
||
|
if ($ann['E1GSIR'] != 340460104 && $ann['CODEVE'] >= 50 && $ann['CODEVE'] <= 79 ) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif ($rubrique=='PH') {
|
||
|
if ($ann['CODEVE'] >= 50 && $ann['CODEVE'] <= 79 ) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif ($rubrique=='R') {
|
||
|
if ($ann['CODEVE'] >= 40 && $ann['CODEVE'] <= 42 ) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif ($rubrique=='L') {
|
||
|
if (in_array($ann['CODEVE'], array(37,42))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif ($rubrique=='G') {
|
||
|
if ($ann['CODEVE'] == 38) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif ($rubrique=='BODA') {
|
||
|
if ($ann['JAL'] == 1) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif ($rubrique=='BODB') {
|
||
|
if ($ann['JAL'] == 200) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
elseif (is_array($rubrique)) {
|
||
|
$tabCodEve = $tabCodRol = array();
|
||
|
foreach ($rubrique as $codeEvenTmp) {
|
||
|
$codRet=array_search($codeEvenTmp, $this->HistoRoleConvert); // Ne gère pas les ; de tabtmp2
|
||
|
if ($codRet) {
|
||
|
$tabCodRol[] = $codRet;
|
||
|
} else {
|
||
|
$tabCodEve[] = array_search($codeEvenTmp, $this->HistoEvenConvert)*1;
|
||
|
}
|
||
|
}
|
||
|
$where ='';
|
||
|
$tabCodEve = array_unique($tabCodEve);
|
||
|
$tabCodRol = array_unique($tabCodRol);
|
||
|
if (in_array($ann['CODEVE'], $tabCodEve) || in_array($ann['ROLE'], $tabCodRol)) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Formattage Annonce
|
||
|
elseif ($ann['SourceTable'] == 'annonce') {
|
||
|
// Procédure collective
|
||
|
if ($rubrique=='P' || $rubrique=='PH') {
|
||
|
if ($ann['typeEven'] >= 1000 && $ann['typeEven'] <= 1999 && !in_array($ann['typeEven'], array('1005','1010','1050','1055','1550'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Dissolution de la société
|
||
|
elseif ($rubrique=='D') {
|
||
|
if (in_array($ann['typeEven'], array('2202','2203','2204','2210','2211','2212'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Absorption
|
||
|
elseif ($rubrique=='A') {
|
||
|
if (in_array($ann['typeEven'], array('2720','2721'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Dépôt des comptes
|
||
|
elseif ($rubrique=='C' || $rubrique=='BODC') {
|
||
|
if ($ann['typeEven'] >= 3000 && $ann['typeEven'] <= 3999) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
} elseif ($rubrique=='R') {
|
||
|
if (in_array($ann['typeEven'], array('2202','2203','2204','2210','2211','2212'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Location gérance Locataire
|
||
|
elseif ($rubrique=='L') {
|
||
|
if (in_array($ann['typeEven'], array('2800','2875','2880','2881','2885','2840'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Location gérance Propriétaire
|
||
|
elseif ($rubrique=='G') {
|
||
|
if (in_array($ann['typeEven'], array('2850','2851','2860','2870'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Ventes/Cessions
|
||
|
elseif ($rubrique=='V') {
|
||
|
if (in_array($ann['typeEven'], array('5500','5501','5502','5503','5510','5600','5650'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
} elseif (is_array($rubrique) && count($rubrique)>0) {
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, $rubrique)) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return $annonceFilter;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Tri les annonces de la fonction getAnnoncesLegales
|
||
|
* @param array $annonces
|
||
|
* @param mixed $rubrique
|
||
|
* @return array
|
||
|
*/
|
||
|
public function annoncesFilter($annonces, $rubrique)
|
||
|
{
|
||
|
$annonceFilter = array();
|
||
|
|
||
|
foreach ($annonces as $ann) {
|
||
|
|
||
|
$typeEven = array();
|
||
|
foreach ($ann['evenements'] as $item) {
|
||
|
$typeEven[] = $item['CodeEven'];
|
||
|
}
|
||
|
|
||
|
// Procédure collective
|
||
|
if ($rubrique=='P' || $rubrique=='PH') {
|
||
|
$evenOk = true;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('1005','1010','1050','1055','1550'))) {
|
||
|
$evenOk = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($ann['Rubrique'] == 'procol' && $evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Dissolution de la société
|
||
|
elseif ($rubrique=='D') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2202','2203','2204','2210','2211','2212'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Absorption
|
||
|
elseif ($rubrique=='A') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2720','2721'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// BODACC A
|
||
|
elseif ($rubrique=='BODA') {
|
||
|
if (in_array($ann['Rubrique'], array('creations', 'procol', 'ventes'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// BODACC B
|
||
|
elseif ($rubrique=='BODB') {
|
||
|
if (in_array($ann['Rubrique'], array('mmd', 'radiations'))) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Dépôt des comptes, BODACC C
|
||
|
elseif ($rubrique=='C' || $rubrique=='BODC') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('3100','3200','3300','3999'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($ann['Rubrique'] == 'comptes' || $evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
} elseif ($rubrique=='R') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2202','2203','2204','2210','2211','2212'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($ann['Rubrique'] == 'radiations' || $evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Location gérance Locataire
|
||
|
elseif ($rubrique=='L') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2800','2875','2880','2881','2885','2840','4355'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Location gérance Propriétaire
|
||
|
elseif ($rubrique=='G') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('2850','2851','2860','2870'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
// Ventes/Cessions
|
||
|
elseif ($rubrique=='V') {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, array('5500','5501','5502','5503','5510','5600','5650'))) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
} elseif (is_array($rubrique) && count($rubrique) > 0) {
|
||
|
$evenOk = false;
|
||
|
foreach($typeEven as $even) {
|
||
|
if (in_array($even, $rubrique)) {
|
||
|
$evenOk = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if ($evenOk === true) {
|
||
|
$annonceFilter[] = $ann;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $annonceFilter;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Analyse les annonces légales pour déterminer si en plan
|
||
|
* @param string $type Type d'annonce bodacc|histo|annonces
|
||
|
* @param int $fj Code catégorie juridique
|
||
|
* @param array $annonce Une annonce
|
||
|
*/
|
||
|
public function getAnnoncesLegalesPlan($type, $fj, $annonce)
|
||
|
{
|
||
|
$evenDetect = array(
|
||
|
'1407', // Modification de plan
|
||
|
'1409', // Modification du plan de continuation
|
||
|
'1413', // Arrêt du plan de continuation
|
||
|
'1414', // Arrêt du plan de redressement
|
||
|
'1101', // Arrêt du plan de sauvegarde
|
||
|
);
|
||
|
$fjDetect = array(
|
||
|
16,1600, // Exploitant agricole
|
||
|
63,6316,6317,6318, // Société coopérative agricole
|
||
|
5431,5432,5531,5532, // SMIA, SICA
|
||
|
5631,5632,6532,
|
||
|
6533,6534,6535, // GAEC, GFA, Gpt Agricole Foncier
|
||
|
6597,6598,
|
||
|
);
|
||
|
|
||
|
// --- Bodacc
|
||
|
if ($type == 'bodacc') {
|
||
|
$tabEven = explode(';', $annonce['typeEven']);
|
||
|
foreach ($tabEven as $even) {
|
||
|
if ( intval($even)!=0 ) {
|
||
|
if ( ($this->dureePlan==0 || $this->dureePlan==120) && in_array($even, $evenDetect) ) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "BODACC MATCH DUREE PLAN \n", FILE_APPEND);
|
||
|
// --- Lecture dureePlan dans annonce
|
||
|
$this->debutPlan = str_replace('-','',$annonce['dateJugement']); // SSAAMMJJ
|
||
|
if ( preg_match('/dur.e(?:.*)plan(?:.*)(\d+)\s+ans?/Uisu', $annonce['annonce'], $matches) ) {
|
||
|
$this->dureePlan = $matches[1]*12; // 10 ans = 120 mois
|
||
|
}
|
||
|
|
||
|
// --- Duree du Plan par défaut sur FJ et par défaut
|
||
|
if ($this->dureePlan<1 || $this->dureePlan>120 ) {
|
||
|
if ( in_array($fj, $fjDetect) ) {
|
||
|
$this->dureePlan = 180; // 15 ans
|
||
|
} else {
|
||
|
$this->dureePlan = 120; // 10 ans = 120 mois
|
||
|
}
|
||
|
}
|
||
|
$this->finPlan = Metier_Util_Date::period2Days($this->debutPlan, $this->dureePlan.' mois');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Historique
|
||
|
if ($type == 'histo') {
|
||
|
if ( ($this->dureePlan==0 || $this->dureePlan==120) && $annonce['CODEVE']==75 ) { // Modification de plan
|
||
|
$this->debutPlan = $annonce['DATE']; // SSAAMMJJ
|
||
|
if (preg_match('/dur.e(?:.*)plan(?:.*)(\d+)\s+ans?/Uisu', $annonce['annonceTxt'], $matches)) {
|
||
|
$this->dureePlan = $matches[1]*12; // 10 ans = 120 mois
|
||
|
if ($this->debug) file_put_contents('procol.log', "HISTO MATCH DUREE PLAN \n", FILE_APPEND);
|
||
|
}
|
||
|
// --- Duree du Plan par défaut sur FJ et par défaut
|
||
|
if ($this->dureePlan<1 || $this->dureePlan>120 ) {
|
||
|
if ( in_array($fj, $fjDetect) ) {
|
||
|
$this->dureePlan = 180; // 15 ans
|
||
|
} else {
|
||
|
$this->dureePlan = 120; // 10 ans = 120 mois
|
||
|
}
|
||
|
}
|
||
|
$this->finPlan = Metier_Util_Date::period2Days($this->debutPlan, $this->dureePlan.' mois');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Annonce
|
||
|
if ($type == 'annonce') {
|
||
|
if ( ($this->dureePlan<1 || $this->dureePlan==120) && in_array($annonce['typeEven'], $evenDetect) ) {
|
||
|
$this->debutPlan = str_replace('-', '', $annonce['dateJugement']); // SSAAMMJJ
|
||
|
if (preg_match('/dur.e(?:.*)plan(?:.*)(\d+)\s+ans?/Uisu', $annonce['annonce'], $matches)) {
|
||
|
$this->dureePlan = $matches[1]*12; // 10 ans = 120 mois
|
||
|
} elseif (preg_match('/dur.e(?:.*)plan(?:.*)(\d+)\s+ans?/Uisu', $annonce['annonce'], $matches)) {
|
||
|
$this->dureePlan = $matches[1]*12; // 10 ans = 120 mois
|
||
|
}
|
||
|
if ($this->dureePlan<1 || $this->dureePlan>120) {
|
||
|
if ( in_array($fj, $fjDetect) ) {
|
||
|
$this->dureePlan = 180; // 15 ans
|
||
|
} else {
|
||
|
$this->dureePlan = 120; // 10 ans = 120 mois
|
||
|
}
|
||
|
}
|
||
|
$this->finPlan = Metier_Util_Date::period2Days($this->debutPlan, $this->dureePlan.' mois');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected function getAnnoncesLegalesBodacc($count = false)
|
||
|
{
|
||
|
if ($count === true) {
|
||
|
$sql = "SELECT b.id AS id, b.Bodacc_Date_Parution AS unionDate, 'bodacc' AS SourceTable";
|
||
|
} else {
|
||
|
if ($this->AnnoncesLegalesVisu) {
|
||
|
$unionDate = 'b.Bodacc_Date_Parution AS unionDate';
|
||
|
} else {
|
||
|
$unionDate = 'd.dateJugement AS unionDate';
|
||
|
}
|
||
|
$sql = "SELECT
|
||
|
b.id AS id,
|
||
|
/* BODACC */
|
||
|
b.Bodacc_Code,
|
||
|
b.Bodacc_Annee_Parution,
|
||
|
b.Bodacc_Num,
|
||
|
b.Num_Annonce,
|
||
|
b.Bodacc_Date_Parution,
|
||
|
b.Tribunal_Dept,
|
||
|
b.Tribunal_Code,
|
||
|
d.Rubrique,
|
||
|
b.typeAnnonce,
|
||
|
b.corrNum_Annonce,
|
||
|
b.corrBodacc_Date_Parution,
|
||
|
b.corrPage,
|
||
|
b.corrNumParution,
|
||
|
b.corrTexteRectificatif,
|
||
|
b.annonce,
|
||
|
b.dateInsert,
|
||
|
d.typeEven,
|
||
|
d.dateEffet,
|
||
|
d.dateDebutActivite,
|
||
|
d.dateCessationActivite,
|
||
|
d.dateJugement,
|
||
|
d.dateFinObservation,
|
||
|
d.VenteMt,
|
||
|
d.VenteDev,
|
||
|
d.FJ,
|
||
|
d.Capital,
|
||
|
d.CapitalDev,
|
||
|
CONCAT(d.commentaires,' ',d.fusion) AS complement,
|
||
|
d.raisonSociale,
|
||
|
d.nomCommercial,
|
||
|
d.enseigne,
|
||
|
d.sigle,
|
||
|
d.adresse,
|
||
|
d.codePostal,
|
||
|
d.ville,
|
||
|
d.adresseSiege,
|
||
|
d.codePostalSiege,
|
||
|
d.villeSiege,
|
||
|
/* HISTO */
|
||
|
'' AS ANBASE,
|
||
|
'' AS NOBOD,
|
||
|
'' AS CODTRI,
|
||
|
'' AS JAL,
|
||
|
'' AS DATE,
|
||
|
'' AS CODEVE,
|
||
|
'' AS SSCODE,
|
||
|
'' AS DEPT,
|
||
|
'' AS NOANN,
|
||
|
'' AS ROLE,
|
||
|
'' AS SIREN,
|
||
|
'' AS E1GSIR,
|
||
|
'' AS E1GNIC,
|
||
|
'' AS annonceNum,
|
||
|
'' AS annonceTxt,
|
||
|
/* ANNONCE */
|
||
|
'' AS strEven,
|
||
|
'' AS dateCessationPaiement,
|
||
|
'' AS dateEffetFinP,
|
||
|
'' AS numero,
|
||
|
'' AS inter1type,
|
||
|
'' AS inter1id,
|
||
|
'' AS inter1nom,
|
||
|
'' AS inter2type,
|
||
|
'' AS inter2id,
|
||
|
'' AS inter2nom,
|
||
|
'' AS inter3type,
|
||
|
'' AS inter3id,
|
||
|
'' AS inter3nom,
|
||
|
'' AS inter4type,
|
||
|
'' AS inter4id,
|
||
|
'' AS inter4nom,
|
||
|
'' AS tribunal,
|
||
|
'' AS montant,
|
||
|
'' AS actionsNb,
|
||
|
'' AS nouvActivite,
|
||
|
'' AS nouvDir,
|
||
|
'' AS nouvAdr,
|
||
|
'' AS nouvFJ,
|
||
|
'' AS source,
|
||
|
'' AS parutionIdJal,
|
||
|
'' AS parutionNum,
|
||
|
'' AS dateSource,
|
||
|
/* UNION NEEDED */
|
||
|
t.triCode,
|
||
|
t.triNom,
|
||
|
t.triSiret,
|
||
|
t.triCP,
|
||
|
IF(d.dateSuppr=0,'',d.dateSuppr) AS deleted,
|
||
|
".$unionDate.",
|
||
|
'bodacc' AS SourceTable
|
||
|
FROM jo.bodacc_detail d, jo.bodacc b, jo.tribunaux t";
|
||
|
}
|
||
|
|
||
|
return $sql;
|
||
|
}
|
||
|
|
||
|
protected function getAnnoncesLegalesHisto($count = false)
|
||
|
{
|
||
|
if ($count === true) {
|
||
|
$sql = "SELECT e.ANBASE AS id, DATE_FORMAT(e.DATE, '%Y-%m-%d') AS unionDate, 'histo' AS SourceTable";
|
||
|
} else {
|
||
|
$sql = "SELECT
|
||
|
e.ANBASE AS id,
|
||
|
/* BODACC */
|
||
|
'' AS Bodacc_Code,
|
||
|
'' AS Bodacc_Annee_Parution,
|
||
|
'' AS Bodacc_Num,
|
||
|
'' AS Num_Annonce,
|
||
|
'' AS Bodacc_Date_Parution,
|
||
|
'' AS Tribunal_Dept,
|
||
|
'' AS Tribunal_Code,
|
||
|
'' AS Rubrique,
|
||
|
'' AS typeAnnonce,
|
||
|
'' AS corrNum_Annonce,
|
||
|
'' AS corrBodacc_Date_Parution,
|
||
|
'' AS corrPage,
|
||
|
'' AS corrNumParution,
|
||
|
'' AS corrTexteRectificatif,
|
||
|
'' AS annonce,
|
||
|
'' AS dateInsert,
|
||
|
'' AS typeEven,
|
||
|
'' AS dateEffet,
|
||
|
'' AS dateDebutActivite,
|
||
|
'' AS dateCessationActivite,
|
||
|
'' AS dateJugement,
|
||
|
'' AS dateFinObservation,
|
||
|
'' AS VenteMt,
|
||
|
'' AS VenteDev,
|
||
|
'' AS FJ,
|
||
|
'' AS Capital,
|
||
|
'' AS CapitalDev,
|
||
|
'' AS complement,
|
||
|
'' AS raisonSociale,
|
||
|
'' AS nomCommercial,
|
||
|
'' AS enseigne,
|
||
|
'' AS sigle,
|
||
|
'' AS adresse,
|
||
|
'' AS codePostal,
|
||
|
'' AS ville,
|
||
|
'' AS adresseSiege,
|
||
|
'' AS codePostalSiege,
|
||
|
'' AS villeSiege,
|
||
|
/* HISTO */
|
||
|
e.ANBASE,
|
||
|
e.NOBOD,
|
||
|
e.CODTRI,
|
||
|
e.JAL,
|
||
|
e.DATE,
|
||
|
e.CODEVE,
|
||
|
e.SSCODE,
|
||
|
e.DEPT,
|
||
|
e.NOANN,
|
||
|
e.ROLE,
|
||
|
e.SIREN AS siren,
|
||
|
e.E1GSIR,
|
||
|
e.E1GNIC,
|
||
|
x.annonceNum,
|
||
|
x.annonceTxt,
|
||
|
/* ANNONCE */
|
||
|
'' AS strEven,
|
||
|
'' AS dateCessationPaiement,
|
||
|
'' AS dateEffetFinP,
|
||
|
'' AS numero,
|
||
|
'' AS inter1type,
|
||
|
'' AS inter1id,
|
||
|
'' AS inter1nom,
|
||
|
'' AS inter2type,
|
||
|
'' AS inter2id,
|
||
|
'' AS inter2nom,
|
||
|
'' AS inter3type,
|
||
|
'' AS inter3id,
|
||
|
'' AS inter3nom,
|
||
|
'' AS inter4type,
|
||
|
'' AS inter4id,
|
||
|
'' AS inter4nom,
|
||
|
'' AS tribunal,
|
||
|
'' AS montant,
|
||
|
'' AS actionsNb,
|
||
|
'' AS nouvActivite,
|
||
|
'' AS nouvDir,
|
||
|
'' AS nouvAdr,
|
||
|
'' AS nouvFJ,
|
||
|
'' AS source,
|
||
|
'' AS parutionIdJal,
|
||
|
'' AS parutionNum,
|
||
|
'' AS dateSource,
|
||
|
/* UNION NEEDED */
|
||
|
'' AS triCode,
|
||
|
'' AS triNom,
|
||
|
'' AS triSiret,
|
||
|
'' AS triCP,
|
||
|
'' AS deleted,
|
||
|
DATE_FORMAT(e.DATE, '%Y-%m-%d') AS unionDate,
|
||
|
'histo' AS SourceTable
|
||
|
FROM historiques.texte x, historiques.entrep e";
|
||
|
}
|
||
|
|
||
|
return $sql;
|
||
|
}
|
||
|
|
||
|
protected function getAnnoncesLegalesAnnonce($count = false)
|
||
|
{
|
||
|
if ($count == true) {
|
||
|
$sql = "SELECT a.id AS id, a.dateJugement AS unionDate, 'annonce' AS SourceTable";
|
||
|
} else {
|
||
|
if ($this->AnnoncesLegalesVisu) {
|
||
|
$unionDate = 'a.dateJugement AS unionDate';
|
||
|
} else {
|
||
|
$unionDate = 'a.dateJugement AS unionDate';
|
||
|
}
|
||
|
$sql = "SELECT
|
||
|
a.id AS id,
|
||
|
/* BODACC */
|
||
|
'' AS Bodacc_Code,
|
||
|
'' AS Bodacc_Annee_Parution,
|
||
|
'' AS Bodacc_Num,
|
||
|
'' AS Num_Annonce,
|
||
|
'' AS Bodacc_Date_Parution,
|
||
|
'' AS Tribunal_Dept,
|
||
|
'' AS Tribunal_Code,
|
||
|
'' AS Rubrique,
|
||
|
'' AS typeAnnonce,
|
||
|
'' AS corrNum_Annonce,
|
||
|
'' AS corrBodacc_Date_Parution,
|
||
|
'' AS corrPage,
|
||
|
'' AS corrNumParution,
|
||
|
'' AS corrTexteRectificatif,
|
||
|
a.annonce,
|
||
|
a.dateInsert,
|
||
|
a.typeEven,
|
||
|
'' AS dateEffet,
|
||
|
'' AS dateDebutActivite,
|
||
|
'' AS dateCessationActivite,
|
||
|
a.dateJugement,
|
||
|
'' AS dateFinObservation,
|
||
|
'' AS VenteMt,
|
||
|
'' AS VenteDev,
|
||
|
'' AS FJ,
|
||
|
'' AS Capital,
|
||
|
'' AS CapitalDev,
|
||
|
a.complement,
|
||
|
a.raisonSociale,
|
||
|
'' AS nomCommercial,
|
||
|
'' AS enseigne,
|
||
|
'' AS sigle,
|
||
|
a.adresse,
|
||
|
a.codePostal,
|
||
|
a.ville,
|
||
|
'' AS adresseSiege,
|
||
|
'' AS codePostalSiege,
|
||
|
'' AS villeSiege,
|
||
|
/* HISTO */
|
||
|
'' AS ANBASE,
|
||
|
'' AS NOBOD,
|
||
|
'' AS CODTRI,
|
||
|
'' AS JAL,
|
||
|
'' AS DATE,
|
||
|
'' AS CODEVE,
|
||
|
'' AS SSCODE,
|
||
|
'' AS DEPT,
|
||
|
'' AS NOANN,
|
||
|
'' AS ROLE,
|
||
|
a.siren,
|
||
|
'' AS E1GSIR,
|
||
|
'' AS E1GNIC,
|
||
|
'' AS annonceNum,
|
||
|
'' AS annonceTxt,
|
||
|
/* ANNONCE */
|
||
|
a.strEven,
|
||
|
a.dateCessationPaiement,
|
||
|
a.dateEffetFinP,
|
||
|
a.numero,
|
||
|
a.inter1type,
|
||
|
a.inter1id,
|
||
|
a.inter1nom,
|
||
|
a.inter2type,
|
||
|
a.inter2id,
|
||
|
a.inter2nom,
|
||
|
a.inter3type,
|
||
|
a.inter3id,
|
||
|
a.inter3nom,
|
||
|
a.inter4type,
|
||
|
a.inter4id,
|
||
|
a.inter4nom,
|
||
|
a.tribunal,
|
||
|
a.montant,
|
||
|
a.actionsNb,
|
||
|
a.nouvActivite,
|
||
|
a.nouvDir,
|
||
|
a.nouvAdr,
|
||
|
a.nouvFJ,
|
||
|
a.source,
|
||
|
a.parutionIdJal,
|
||
|
a.parutionNum,
|
||
|
DATE_FORMAT(a.dateSource, '%Y-%m-%d') AS dateSource,
|
||
|
/* UNION NEEDED */
|
||
|
t.triCode,
|
||
|
t.triNom,
|
||
|
t.triSiret,
|
||
|
t.triCP,
|
||
|
'' AS deleted,
|
||
|
".$unionDate.",
|
||
|
'annonce' AS SourceTable
|
||
|
FROM jo.annonces a, jo.tribunaux t";
|
||
|
}
|
||
|
|
||
|
return $sql;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Liste des annonces légales pour un siren donnée
|
||
|
* @param integer $siren
|
||
|
* @param integer $idAnnonce
|
||
|
* @param mixed $rubrique Filter par rubrique
|
||
|
* (P)rocol, (D)issolution, (R)adiation, (A)bsorption, (L)ocataire, (G)érance:propriétaire,
|
||
|
* (V)endeur, bodacc (C), (BODA) (BODB) (BODC) ou tableau des codeEven
|
||
|
* @param bool $forceVerif
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getAnnoncesLegales($siren, $idAnnonce=0, $rubrique='', $forceVerif=false, $allTextes=false, $deleted=false)
|
||
|
{
|
||
|
// @todo : Gerer la pagination LIMIT 0,20 - LIMIT 19,20
|
||
|
$siren = intval($siren);
|
||
|
$tabRet = array();
|
||
|
$this->dureePlan = 0; // Par défaut, on ne trouve aucune durée de plan
|
||
|
|
||
|
if ( !is_array($rubrique) && !in_array($rubrique, array('','P','PH','D','A','C','R','L','G','V','BODA','BODB','BODC')) ) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if ($idAnnonce != 0) {
|
||
|
// --- Annonce
|
||
|
if (substr($idAnnonce,0,2) == '0.') {
|
||
|
$idAnnonce = substr($idAnnonce,2);
|
||
|
$sqlAnnonceWhere = "a.id=$idAnnonce";
|
||
|
$sqlAnnonceWhere.= " AND a.tribunal=t.triCode AND a.dateSuppr=0";
|
||
|
$sqlAnnonceWhere.= " GROUP BY a.siren, a.dateJugement, a.typeEven ORDER BY a.dateJugement DESC";
|
||
|
$sql = $this->getAnnoncesLegalesAnnonce()." WHERE ".$sqlAnnonceWhere;
|
||
|
}
|
||
|
// --- Histo
|
||
|
elseif ($idAnnonce < 0) {
|
||
|
$idAnnonce = abs($idAnnonce);
|
||
|
$sqlHistoWhere = "e.ANBASE=$idAnnonce ";
|
||
|
$sqlHistoWhere.= " AND e.ANBASE=x.annonceNum AND e.DATE BETWEEN 19890101 AND 20041231";
|
||
|
/*$sqlHistoWhere.= " AND e.E1GSIR=e.SIREN";*/
|
||
|
$sqlHistoWhere.= " GROUP BY e.ANBASE ORDER BY e.DATE DESC";
|
||
|
$sql = $this->getAnnoncesLegalesHisto()." WHERE ".$sqlHistoWhere;
|
||
|
}
|
||
|
// --- Bodacc
|
||
|
elseif ($idAnnonce > 0) {
|
||
|
$sqlBodaccWhere ="d.id=$idAnnonce ";
|
||
|
$sqlBodaccWhere.= " AND d.id=b.id AND b.Tribunal_Code=t.triCode";
|
||
|
$sql = $this->getAnnoncesLegalesBodacc()." WHERE ".$sqlBodaccWhere;
|
||
|
}
|
||
|
} else {
|
||
|
// --- Where Bodacc
|
||
|
$sqlBodaccWhere = "d.siren=$siren";
|
||
|
$sqlBodaccWhere.= $this->getAnnoncesLegalesRubrique('bodacc', $rubrique);
|
||
|
$sqlBodaccWhere.= " AND d.id=b.id AND b.Tribunal_Code=t.triCode";
|
||
|
// --- Annonces supprimées ou rectifiées
|
||
|
if ( $deleted === true ) {
|
||
|
$sqlBodaccWhere.= " AND (d.dateSuppr=0 OR d.dateSuppr!='0000-00-00 00:00:00' AND d.idSuppr=0) ";
|
||
|
} else {
|
||
|
$sqlBodaccWhere.= " AND d.dateSuppr=0 ";
|
||
|
}
|
||
|
$sqlBodacc = $this->getAnnoncesLegalesBodacc()." WHERE ".$sqlBodaccWhere;
|
||
|
|
||
|
// --- Where Histo
|
||
|
$sqlHistoRubrique = $this->getAnnoncesLegalesRubrique('histo', $rubrique);
|
||
|
if ($sqlHistoRubrique !== false) {
|
||
|
$sqlHistoWhere = "e.E1GSIR=$siren";
|
||
|
$sqlHistoWhere.= $sqlHistoRubrique;
|
||
|
$sqlHistoWhere.= " AND e.ANBASE=x.annonceNum AND (e.DATE BETWEEN 19960101 AND 20041231 OR e.DATE<19960101 AND e.E1GSIR=e.SIREN)";
|
||
|
$sqlHistoWhere.= " GROUP BY e.ANBASE";
|
||
|
$sqlHisto = $this->getAnnoncesLegalesHisto()." WHERE ".$sqlHistoWhere;
|
||
|
}
|
||
|
|
||
|
// --- Where Annonce
|
||
|
$sqlAnnonceRubrique = $this->getAnnoncesLegalesRubrique('annonce', $rubrique);
|
||
|
if ($sqlAnnonceRubrique !== false) {
|
||
|
$sqlAnnonceWhere = "a.siren=$siren";
|
||
|
$sqlAnnonceWhere.= $sqlAnnonceRubrique;
|
||
|
$sqlAnnonceWhere.= " AND a.tribunal=t.triCode AND a.dateSuppr=0";
|
||
|
// --- Ne pas utiliser les annonces si la procédure à plus de 4 mois
|
||
|
$sqlAnnonceWhere.= " AND a.dateJugement > DATE_SUB(NOW(), INTERVAL 24 MONTH)";
|
||
|
$sqlAnnonceWhere.= " GROUP BY a.siren, a.dateJugement, a.typeEven";
|
||
|
$sqlAnnonce = $this->getAnnoncesLegalesAnnonce()." WHERE ".$sqlAnnonceWhere;
|
||
|
}
|
||
|
|
||
|
// --- SQL Union
|
||
|
$sql = "SELECT * FROM ( (".$sqlBodacc.") ";
|
||
|
if (!empty($sqlHisto)) {
|
||
|
$sql.= " UNION ALL (".$sqlHisto.") ";
|
||
|
}
|
||
|
if (!empty($sqlAnnonce)) {
|
||
|
$sql.= " UNION ALL (".$sqlAnnonce.") ";
|
||
|
}
|
||
|
|
||
|
// --- Gestion des événements à date
|
||
|
if ($this->companyEvenDateStop != null ) {
|
||
|
$sql.= ") results WHERE unionDate < '".$this->companyEvenDateStop."'";
|
||
|
} else {
|
||
|
$sql.= ") results";
|
||
|
}
|
||
|
|
||
|
// --- Gestion de l'ordre de tri
|
||
|
if ($this->AnnoncesLegalesVisu) {
|
||
|
$sql.= " ORDER BY unionDate DESC";
|
||
|
} else {
|
||
|
$sql.= " ORDER BY unionDate ASC, FIELD(SourceTable, 'histo', 'annonce', 'bodacc')";
|
||
|
}
|
||
|
}
|
||
|
$annonceResult = $this->iDb->query($sql);
|
||
|
|
||
|
// --- Traitement des resultats
|
||
|
if (count($annonceResult) > 0) {
|
||
|
// --- Identite Light de l'entité
|
||
|
if ($this->Identite === null) {
|
||
|
$this->Identite = $this->getIdentiteLight($siren);
|
||
|
}
|
||
|
// --- Parcours des annonces
|
||
|
foreach ($annonceResult as $ann) {
|
||
|
// --- Formatage bodacc
|
||
|
if ($ann['SourceTable'] == 'bodacc') {
|
||
|
$tabEven = explode(';', $ann['typeEven']);
|
||
|
$tabRetEven = array();
|
||
|
// --- Annonce rubrique insertion
|
||
|
if ($ann['typeAnnonce']!='Insertion') {
|
||
|
// --- Sélection des événements
|
||
|
foreach ($tabEven as $even) {
|
||
|
if (intval($even) != 0) {
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $even,
|
||
|
'LibEven' => $this->iBodacc->getEvenement($even)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
// Libellé générique
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => '0000',
|
||
|
'LibEven' => $ann['typeAnnonce']." de l'annonce du ".Metier_Util_Date::dateT('Y-m-d','d/m/Y',$ann['corrBodacc_Date_Parution'])
|
||
|
);
|
||
|
}
|
||
|
// --- Annonce autre rubrique
|
||
|
else {
|
||
|
if (trim($ann['typeEven'])!='') {
|
||
|
foreach ($tabEven as $even) {
|
||
|
if ( intval($even)!=0 ) {
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $even,
|
||
|
'LibEven' => $this->iBodacc->getEvenement($even)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
// --- Detection plan
|
||
|
if ($this->AnnoncesLegalesVisu === false) {
|
||
|
$this->getAnnoncesLegalesPlan('bodacc', $this->Identite['FJ'], $ann);
|
||
|
}
|
||
|
} else {
|
||
|
switch ($ann['Rubrique']) {
|
||
|
case 'mmd': $codeEven='2313'; $libEven = "Modification(s) diverse(s)"; break;
|
||
|
case 'comptes': $codeEven='3999'; $libEven = "Dépôt des comptes"; break;
|
||
|
case 'creations': $codeEven='4999'; $libEven = "Création d'entreprise"; break;
|
||
|
case 'procol': $codeEven='1999'; $libEven = "Procédure collective"; break;
|
||
|
case 'radiations': $codeEven='6700'; $libEven = "Radiation"; break;
|
||
|
case 'ventes': $codeEven='5999'; $libEven = "Vente/Cession"; break;
|
||
|
default: $codeEven='0000'; $libEven = $ann['Rubrique']; break;
|
||
|
}
|
||
|
$tabRetEven[]=array('CodeEven'=>$codeEven,'LibEven'=>$libEven);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$dateCes = str_replace('-','', $ann['dateCessationActivite'])*1;
|
||
|
$dateDeb = str_replace('-','', $ann['dateDebutActivite'])*1;
|
||
|
$dateEff = str_replace('-','', $ann['dateEffet'])*1;
|
||
|
if ($dateCes>0) {
|
||
|
$dateEffet=$ann['dateCessationActivite'];
|
||
|
} elseif ($dateDeb>0) {
|
||
|
$dateEffet=$ann['dateDebutActivite'];
|
||
|
} else {
|
||
|
$dateEffet=$ann['dateEffet'];
|
||
|
}
|
||
|
$adresseAnn=trim(preg_replace('/ +/',' ', $ann['adresseSiege'].' '.$ann['codePostalSiege'].' '.$ann['villeSiege']));
|
||
|
|
||
|
if (strlen($adresse)<8) {
|
||
|
$adresseAnn=trim(preg_replace('/ +/',' ', $ann['adresse'].' '.$ann['codePostal'].' '.$ann['ville']));
|
||
|
}
|
||
|
// --- Retour bodacc
|
||
|
$retFormat = array(
|
||
|
'id' => $ann['id'],
|
||
|
'BodaccCode' => 'BOD'.$ann['Bodacc_Code'],
|
||
|
'BodaccNum' => $ann['Bodacc_Num'],
|
||
|
'NumAnnonce' => $ann['Num_Annonce'],
|
||
|
'DateParution' => $ann['Bodacc_Date_Parution'],
|
||
|
'Departement' => $ann['Tribunal_Dept'],
|
||
|
'Tribunal' => $ann['triNom'],
|
||
|
'TribunalCode' => $ann['triCode'],
|
||
|
'TribunalSiret' => $ann['triSiret'],
|
||
|
'Rubrique' => $ann['Rubrique'],
|
||
|
'typeAnnonce' => $ann['typeAnnonce'],
|
||
|
'texteRectificatif' => $ann['corrTexteRectificatif'],
|
||
|
'dateEffet' => $dateEffet,
|
||
|
'dateJugement' => $ann['dateJugement'],
|
||
|
'dateFin' => $ann['dateFinObservation'],
|
||
|
'montantVente' => trim($ann['VenteMt'].' '.$ann['VenteDev']),
|
||
|
'libFJ' => $ann['FJ'],
|
||
|
'codFJ' => $this->iBodacc->getCodeFormeJur($ann['FJ']),
|
||
|
'capital' => $ann['Capital'],
|
||
|
'capitalDev' => $ann['CapitalDev'],
|
||
|
'raisonSociale' => $ann['raisonSociale'],
|
||
|
'nomCommercial' => $ann['nomCommercial'],
|
||
|
'sigle' => $ann['sigle'],
|
||
|
'adresse' => $adresseAnn,
|
||
|
'dateInsertionSD' => $ann['dateInsert'],
|
||
|
'evenements' => $tabRetEven,
|
||
|
'complement' => $ann['complement'],
|
||
|
'deleted' => $ann['deleted'],
|
||
|
'texteAnnonce' => $ann['annonce'],
|
||
|
);
|
||
|
$tabRet[] = $retFormat;
|
||
|
}
|
||
|
// --- Formattage Histo
|
||
|
elseif ($ann['SourceTable'] == 'histo') {
|
||
|
|
||
|
if ($ann['JAL']==1) $Bodacc_Code='BODA';
|
||
|
elseif ($ann['JAL']==200) $Bodacc_Code='BODB';
|
||
|
|
||
|
if ($ann['CODEVE']<20) $rub='creations'; // 4xxx
|
||
|
elseif ($ann['CODEVE']<=25) $rub='ventes'; // 5xxx
|
||
|
elseif ($ann['CODEVE']<40) $rub='mmd'; // 2xxx
|
||
|
elseif ($ann['CODEVE']<42) $rub='radiations'; // 6xxx
|
||
|
elseif ($ann['CODEVE']<50) $rub='mmd'; // 2xxx
|
||
|
elseif ($ann['CODEVE']<80) $rub='procol'; // 1xxx
|
||
|
|
||
|
$tabEvens = array();
|
||
|
$newCodeEven = $this->HistoEvenConvert[$ann['CODEVE']];
|
||
|
if ($newCodeEven*1==2318) {
|
||
|
$tabNewEven = explode(';', $this->HistoRoleConvert[$ann['ROLE']]);
|
||
|
if (count($tabNewEven)>0) {
|
||
|
foreach ($tabNewEven as $newCodeEven) {
|
||
|
$tabEvens[] = array(
|
||
|
'CodeEven' => $newCodeEven,
|
||
|
'LibEven' => $this->iBodacc->getEvenement($newCodeEven));
|
||
|
}
|
||
|
} else {
|
||
|
$tabEvens[] = array(
|
||
|
'CodeEven' => $newCodeEven,
|
||
|
'LibEven' => $this->iBodacc->getEvenement($newCodeEven)
|
||
|
);
|
||
|
}
|
||
|
} else {
|
||
|
|
||
|
$tabEvens[] = array(
|
||
|
'CodeEven' => $newCodeEven,
|
||
|
'LibEven' => $this->iBodacc->getEvenement($newCodeEven)
|
||
|
);
|
||
|
|
||
|
// --- Detection plan
|
||
|
if ($this->AnnoncesLegalesVisu === false) {
|
||
|
$this->getAnnoncesLegalesPlan('histo', $this->Identite['FJ'], $ann);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
// Recherche du capital et de la FJ dans le texte histo
|
||
|
if ( ($ann['CODEVE']>=10 && $ann['CODEVE']<20)
|
||
|
|| ($ann['CODEVE']>=30 && $ann['CODEVE']<42)
|
||
|
|| ($ann['CODEVE']>=51 && $ann['CODEVE']<80) ) {
|
||
|
// Recherche du capital
|
||
|
if (preg_match('/Capital(?:.|)\:(.*)(eur.|f|livre)/Uis', $ann['annonceTxt'], $matches)) {
|
||
|
$capital=trim(strtr($matches[1],array(' '=>'', ',00 '=>'', '.00 '=>'')))*1;
|
||
|
if (substr(strtoupper($matches[2]),0,3)=='EUR')
|
||
|
$capitalDev = 'EUR';
|
||
|
elseif (substr(strtoupper($matches[2]),0,3)=='LIV')
|
||
|
$capitalDev = 'GBP';
|
||
|
else
|
||
|
$capitalDev = 'FRF';
|
||
|
} else
|
||
|
$capital=$capitalDev='';
|
||
|
// Recherche de la forme juridique
|
||
|
if (preg_match('/Forme(?:.|)\:(.*)(Capital|Adresse|Activit.|Administration|Commentaire)(?:.|)\:/Uisu', $ann['annonceTxt'], $matches)) {
|
||
|
$libFJ = trim($matches[1]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Retour histo
|
||
|
$retFormat = array(
|
||
|
'id' => -$ann['ANBASE'],
|
||
|
'BodaccCode' => $Bodacc_Code,
|
||
|
'BodaccNum' => $ann['NOBOD'],
|
||
|
'NumAnnonce' => $ann['NOANN'],
|
||
|
'DateParution' => substr($ann['DATE'],0,4).'-'.substr($ann['DATE'],4,2).'-'.substr($ann['DATE'],6,2),
|
||
|
'Departement' => $ann['DEPT'],
|
||
|
'Tribunal' => $this->iBodacc->getTribunalNom($ann['CODTRI']), //$ann['triNom'],
|
||
|
'TribunalSiret' => $this->iBodacc->getTribunalSiret($ann['CODTRI']),//$ann['triSiret'],
|
||
|
'Rubrique' => $rub,
|
||
|
'typeAnnonce' => 'Insertion',
|
||
|
'dateEffet' => substr($ann['DATE'],0,4).'-'.substr($ann['DATE'],4,2).'-'.substr($ann['DATE'],6,2),
|
||
|
'dateJugement' => substr($ann['DATE'],0,4).'-'.substr($ann['DATE'],4,2).'-'.substr($ann['DATE'],6,2),
|
||
|
'dateFin' => '',
|
||
|
'montantVente' => '',
|
||
|
'libFJ' => $libFJ,
|
||
|
'codFJ' => $this->iBodacc->getCodeFormeJur($libFJ),
|
||
|
'capital' => $capital,
|
||
|
'capitalDev' => $capitalDev,
|
||
|
'raisonSociale' => '',//$ann['raisonSociale'],
|
||
|
'nomCommercial' => '',//$ann['nomCommercial'],
|
||
|
'sigle' => '',//$ann['sigle'],
|
||
|
'adresse' => '',//$adresseAnn,
|
||
|
'dateInsertionSD' => '',
|
||
|
'evenements' => $tabEvens,
|
||
|
'texteAnnonce' => $ann['NOANN'].' - '.$ann['annonceTxt'],
|
||
|
);
|
||
|
$tabRet[] = $retFormat;
|
||
|
}
|
||
|
// --- Formattage Annonce
|
||
|
elseif ($ann['SourceTable'] == 'annonce') {
|
||
|
$rubriqueRet = '';
|
||
|
$tabInter = array(
|
||
|
'A' => 'Administrateur judiciaire',
|
||
|
'M' => 'Mandataire judiciaire',
|
||
|
'H' => 'Huissier',
|
||
|
'L' => 'Liquidateur',
|
||
|
'R' => 'Représentant des Créanciers',
|
||
|
'O' => 'Opposition',
|
||
|
'U' => 'Curateur',
|
||
|
'C' => 'Commissaire au plan',
|
||
|
'S' => 'Syndic',
|
||
|
'D' => 'Commissaire au concordat',
|
||
|
'T' => 'Conciliateur',
|
||
|
'V' => 'Avocat',
|
||
|
'N' => 'Notaire',
|
||
|
'J' => 'Juge Commissaire',
|
||
|
'K' => 'Juge Commissaire Suppléant',
|
||
|
);
|
||
|
$dept = substr($ann['triCP'],0,2)*1;
|
||
|
$depotComptes = false;
|
||
|
if ($dept==97) $dept = substr($ann['triCP'],0,3)*1;
|
||
|
$adresse='';
|
||
|
|
||
|
/** Ajout des informations identitaires pour les annonces collecte avant Décembre 2008 **/
|
||
|
if ( trim($ann['raisonSociale'])=='' || trim($ann['adresse'])==''
|
||
|
|| trim($ann['codePostal'])=='' || trim($ann['ville'])=='') {
|
||
|
$ann['raisonSociale'] = $this->Identite['Nom'];
|
||
|
$ann['adresse'] = $this->Identite['Adresse'];
|
||
|
$ann['codePostal'] = $this->Identite['CP'];
|
||
|
$ann['ville'] = $this->Identite['Ville'];
|
||
|
}
|
||
|
$adresse.=ucfirst(strtolower($ann['adresse'])).', ';
|
||
|
|
||
|
$adresse=trim(preg_replace('/^0+/','', preg_replace('/ +/',' ', $adresse)));
|
||
|
if (preg_match('/(3100|3200|3300|3999)/', $ann['typeEven'].';'.$ann['strEven'])) {
|
||
|
$depotComptes = true;
|
||
|
$strRCS = 'Siren : '. $ann['siren'] . '. ';
|
||
|
} else
|
||
|
$strRCS = $ann['siren'] . ' RCS '. ucfirst(strtolower(strtr($ann['triNom'], array('TGIcc '=>'','TGI '=>'','TC '=>'','TI '=>'',)))).'. ';
|
||
|
|
||
|
$texteAnnonce = 'Date : '.strtolower(Metier_Util_Date::dateT('Y-m-d','d M Y',$ann['dateJugement'])) .'. '. $this->iBodacc->getEvenement($ann['typeEven']).'. '.
|
||
|
$strRCS . trim($ann['raisonSociale']). '. Adresse : '. $adresse.' '.$ann['codePostal'].' '.$ann['ville'].'. ';
|
||
|
|
||
|
if (trim($ann['numero'])<>'') $texteAnnonce.='Jugement Numéro : '.trim($ann['numero']).'. ';
|
||
|
|
||
|
if ($ann['dateCessationPaiement']*1<>0) $texteAnnonce.='Cessation des paiements le '.strtolower(Metier_Util_Date::dateT('Y-m-d','d M Y',$ann['dateCessationPaiement'])).'. ';
|
||
|
|
||
|
if (trim($ann['inter1type'])<>'' && ($ann['inter1id']>0 || trim($ann['inter1nom'])<>'') ) {
|
||
|
$texteAnnonce.=$tabInter[$ann['inter1type']].' : '.$ann['inter1nom'];
|
||
|
if ($ann['inter1id']<>0) {
|
||
|
$tabTmp=$this->iDb->select( 'jo.tabMandataires', 'sirenGrp, sirenMand, tel, fax, email', 'id='.$ann['inter1id'], false, MYSQL_ASSOC);
|
||
|
$mand=$tabTmp[0];
|
||
|
if ($mand['sirenGrp']<>0) $texteAnnonce.=', Siren SCP '.$mand['sirenGrp'];
|
||
|
if ($mand['sirenMand']<>0) $texteAnnonce.=', Siren '.$mand['sirenMand'];
|
||
|
if ($mand['tel']<>'') $texteAnnonce.=', Telephone '.$mand['tel'];
|
||
|
if ($mand['fax']<>'') $texteAnnonce.=', Telecopie '.$mand['fax'];
|
||
|
if ($mand['email']<>'') $texteAnnonce.=', E-mail : '.$mand['email'];
|
||
|
}
|
||
|
$texteAnnonce.='. ';
|
||
|
}
|
||
|
if (trim($ann['inter2type'])<>'' && ($ann['inter2id']>0 || trim($ann['inter2nom'])<>'') ) {
|
||
|
$texteAnnonce.=$tabInter[$ann['inter2type']].' : '.$ann['inter2nom'];
|
||
|
if ($ann['inter2id']<>0) {
|
||
|
$tabTmp=$this->iDb->select( 'jo.tabMandataires', 'sirenGrp, sirenMand, tel, fax, email', 'id='.$ann['inter2id'], false, MYSQL_ASSOC);
|
||
|
$mand=$tabTmp[0];
|
||
|
if ($mand['sirenGrp']<>0) $texteAnnonce.=', Siren SCP '.$mand['sirenGrp'];
|
||
|
if ($mand['sirenMand']<>0) $texteAnnonce.=', Siren '.$mand['sirenMand'];
|
||
|
if ($mand['tel']<>'') $texteAnnonce.=', Telephone '.$mand['tel'];
|
||
|
if ($mand['fax']<>'') $texteAnnonce.=', Telecopie '.$mand['fax'];
|
||
|
if ($mand['email']<>'') $texteAnnonce.=', E-mail : '.$mand['email'];
|
||
|
}
|
||
|
$texteAnnonce.='. ';
|
||
|
}
|
||
|
if (trim($ann['inter3type'])<>'' && ($ann['inter3id']>0 || trim($ann['inter3nom'])<>'') ) {
|
||
|
$texteAnnonce.=$tabInter[$ann['inter3type']].' : '.$ann['inter3nom'];
|
||
|
if ($ann['inter3id']<>0) {
|
||
|
$tabTmp=$this->iDb->select( 'jo.tabMandataires', 'sirenGrp, sirenMand, tel, fax, email', 'id='.$ann['inter3id'], false, MYSQL_ASSOC);
|
||
|
$mand=$tabTmp[0];
|
||
|
if ($mand['sirenGrp']<>0) $texteAnnonce.=', Siren SCP '.$mand['sirenGrp'];
|
||
|
if ($mand['sirenMand']<>0) $texteAnnonce.=', Siren '.$mand['sirenMand'];
|
||
|
if ($mand['tel']<>'') $texteAnnonce.=', Telephone '.$mand['tel'];
|
||
|
if ($mand['fax']<>'') $texteAnnonce.=', Telecopie '.$mand['fax'];
|
||
|
if ($mand['email']<>'') $texteAnnonce.=', E-mail : '.$mand['email'];
|
||
|
}
|
||
|
$texteAnnonce.='. ';
|
||
|
}
|
||
|
if (trim($ann['inter4type'])<>'' && ($ann['inter4id']>0 || trim($ann['inter4nom'])<>'') ) {
|
||
|
$texteAnnonce.=$tabInter[$ann['inter4type']].' : '.$ann['inter4nom'];
|
||
|
if ($ann['inter4id']<>0) {
|
||
|
$tabTmp=$this->iDb->select( 'jo.tabMandataires', 'sirenGrp, sirenMand, tel, fax, email', 'id='.$ann['inter4id'], false, MYSQL_ASSOC);
|
||
|
$mand=$tabTmp[0];
|
||
|
if ($mand['sirenGrp']<>0) $texteAnnonce.=', Siren SCP '.$mand['sirenGrp'];
|
||
|
if ($mand['sirenMand']<>0) $texteAnnonce.=', Siren '.$mand['sirenMand'];
|
||
|
if ($mand['tel']<>'') $texteAnnonce.=', Telephone '.$mand['tel'];
|
||
|
if ($mand['fax']<>'') $texteAnnonce.=', Telecopie '.$mand['fax'];
|
||
|
if ($mand['email']<>'') $texteAnnonce.=', E-mail : '.$mand['email'];
|
||
|
}
|
||
|
$texteAnnonce.='. ';
|
||
|
}
|
||
|
|
||
|
if (trim($ann['nouvActivite'])<>'') $texteAnnonce.=' Activité : '.trim($ann['nouvActivite']).'. ';
|
||
|
if (trim($ann['nouvDir'])<>'') $texteAnnonce.=' Administration : '.trim($ann['nouvDir']).'. ';
|
||
|
if (trim($ann['nouvAdr'])<>'') $texteAnnonce.=' Nouvelle adresse : '.trim($ann['nouvAdr']).'. ';
|
||
|
if ($ann['nouvFJ']*1>0) $texteAnnonce.=' Transformation de la société en '.$this->getLibelleFJ($ann['nouvFJ']).'. ';
|
||
|
|
||
|
if ($ann['dateEffetFinP']*1<>'') {
|
||
|
if ($depotComptes)
|
||
|
$texteAnnonce.=' Comptes annuels et rapports de l\'exercice clos le : '.strtolower(Metier_Util_Date::dateT('Y-m-d','d M Y',$ann['dateEffetFinP'])).'. ';
|
||
|
else
|
||
|
$texteAnnonce.=' Date d\'effet : '.strtolower(Metier_Util_Date::dateT('Y-m-d','d M Y',$ann['dateEffetFinP'])).'. ';
|
||
|
}
|
||
|
|
||
|
if (trim($ann['complement'])<>'') $texteAnnonce.=' Observations : '.trim($ann['complement']).'.';
|
||
|
|
||
|
$tabRetEven = array();
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $ann['typeEven'],
|
||
|
'LibEven' => $this->iBodacc->getEvenement($ann['typeEven'])
|
||
|
);
|
||
|
if ($ann['typeEven']==2102 || $ann['typeEven']==2100) $capital=true;
|
||
|
else $capital=false;
|
||
|
|
||
|
if (trim($ann['strEven']) != '') {
|
||
|
$tabEven = explode(';', $ann['strEven']);
|
||
|
foreach ($tabEven as $even) {
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $even,
|
||
|
'LibEven' => $this->iBodacc->getEvenement($even)
|
||
|
);
|
||
|
if ($even>=1000 && $even<2000) $rubriqueRet='procol';
|
||
|
elseif ($even>=2000 && $even<3000) $rubriqueRet='mmd';
|
||
|
elseif ($even>=3000 && $even<4000) $rubriqueRet='comptes';
|
||
|
elseif ($even>=4000 && $even<5000) $rubriqueRet='creations';
|
||
|
elseif ($even>=5000 && $even<6000) $rubriqueRet='ventes';
|
||
|
elseif ($even>=6000 && $even<7000) $rubriqueRet='radiations';
|
||
|
if ($even==2102 || $even==2100) $capital=true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Detection plan
|
||
|
if ($this->AnnoncesLegalesVisu === false) {
|
||
|
$this->getAnnoncesLegalesPlan('annonce', $this->Identite['FJ'], $ann);
|
||
|
}
|
||
|
|
||
|
$strVente='';
|
||
|
$nouvCapital='';
|
||
|
if ($ann['montant']>0) {
|
||
|
if ($capital) {
|
||
|
$nouvCapital=$ann['montant'];
|
||
|
$texteAnnonce.=' Nouveau capital : '.trim($ann['montant']). ' euros';
|
||
|
if ($ann['actionsNb']>0)
|
||
|
$texteAnnonce.=' divisé en '.$ann['actionsNb'].' actions de '. round($ann['montant']/$ann['actionsNb']). ' euros';
|
||
|
} elseif (!preg_match('/ pour un montant de /Uis', $ann['complement'])) {
|
||
|
$texteAnnonce.=' Montant : '.trim($ann['montant']). ' euros';
|
||
|
$strVente=trim($ann['montant']). ' EUR';
|
||
|
}
|
||
|
$texteAnnonce.='. ';
|
||
|
}
|
||
|
|
||
|
// On ne prend l'annonce saisie directement que si elle est plus volumineuse
|
||
|
if (trim($ann['annonce'])<>'' && strlen(trim($ann['annonce']))>strlen($texteAnnonce))
|
||
|
$texteAnnonce=trim($ann['annonce']);
|
||
|
|
||
|
$texteAnnonce = preg_replace('/ +/', ' ', strtr($texteAnnonce, array('*'=>' ', '/'=>' ', '..'=>'.')));
|
||
|
|
||
|
if (str_replace('-', '', $ann['dateSource'])*1 != 0) {
|
||
|
$dateParution = $ann['dateSource'];
|
||
|
} else {
|
||
|
$dateParution = $ann['dateInsert'];
|
||
|
}
|
||
|
|
||
|
$retFormat = array(
|
||
|
'id' => '0.'.$ann['id'],
|
||
|
'BodaccCode' => $ann['source'].'-'.$ann['parutionIdJal'],
|
||
|
'BodaccNum' => $ann['parutionNum'],
|
||
|
'NumAnnonce' => 0,
|
||
|
'DateParution' => $dateParution,
|
||
|
'Departement' => $dept,
|
||
|
'Tribunal' => $ann['triNom'],
|
||
|
'TribunalSiret' => $ann['triSiret'],
|
||
|
'Rubrique' => $rubriqueRet,
|
||
|
'typeAnnonce' => 'insertion',
|
||
|
'dateEffet' => $ann['dateCessationPaiement'],
|
||
|
'dateJugement' => $ann['dateJugement'],
|
||
|
'dateFin' => $ann['dateEffetFinP'],
|
||
|
'montantVente' => $strVente,
|
||
|
'libFJ' => $ann['nouvFJ'],
|
||
|
'codFJ' => $this->iBodacc->getCodeFormeJur($ann['nouvFJ']),
|
||
|
'capital' => $nouvCapital,
|
||
|
'capitalDev' => 'EUR',
|
||
|
'raisonSociale' => $ann['raisonSociale'],
|
||
|
'nomCommercial' => '',
|
||
|
'sigle' => '',
|
||
|
'adresse' => $ann['nouvAdr'],
|
||
|
'dateInsertionSD' => $ann['dateInsert'],
|
||
|
'evenements' => $tabRetEven,
|
||
|
'texteAnnonce' => $texteAnnonce,
|
||
|
'complement' => $ann['complement'],
|
||
|
);
|
||
|
if ($depotComptes) {
|
||
|
$retFormat['dateEffet'] = $ann['dateEffetFinP'];
|
||
|
}
|
||
|
$tabRet[] = $retFormat;
|
||
|
}
|
||
|
} // --- Fin du parcours des annonces
|
||
|
|
||
|
// --- Effacement procol
|
||
|
if ($this->AnnoncesLegalesVisu === false) {
|
||
|
$MaxPeriodProcol = 80000;
|
||
|
// --- Si il y a des annonces
|
||
|
if (count($tabRet) > 0) {
|
||
|
$tabJugements = array();
|
||
|
$TopEvenCloture = false;
|
||
|
// --- Liste des jugements principaux - Tri chronologique par date de jugement
|
||
|
foreach ($tabRet as $i => $ann) {
|
||
|
$item = new stdClass();
|
||
|
$item->date = str_replace('-','', $ann['dateJugement']);
|
||
|
$item->dateISO8601 = $ann['dateJugement'];
|
||
|
$item->code = $ann['evenements'][0]['CodeEven'];
|
||
|
$tabJugements[] = $item;
|
||
|
// Detection TopDepart Cloture
|
||
|
if (in_array($item->code, array(1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1311,1312,1313,1314,1417))) {
|
||
|
$TopEvenCloture = true;
|
||
|
}
|
||
|
// Dernier Evenement de Procol
|
||
|
$evenProcolLastDate = $item->date;
|
||
|
$evenProcolLast = $item->code;
|
||
|
if ($this->debug) file_put_contents('procol.log', "Parcours Even : $evenProcolLastDate - $evenProcolLast ($TopEvenCloture)\n", FILE_APPEND);
|
||
|
}
|
||
|
// --- Gestions des conditions pour l'affichage de l'indicateur procédure collectives
|
||
|
if ($rubrique=='P') {
|
||
|
if ($this->debug) file_put_contents('procol.log', "Rubrique P = ".print_r($tabRet,1)."\n", FILE_APPEND);
|
||
|
// Si plan recherche des annonces suivantes
|
||
|
if ($this->dureePlan > 0) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "=== Vérification Elimination du plan === \n", FILE_APPEND);
|
||
|
// Tableau chronologique des dates de jugement => code jugement
|
||
|
foreach ($tabJugements as $i => $j) {
|
||
|
if ($this->debug) file_put_contents('procol.log', $j->date.'>'.$this->debutPlan.', Jugement='.$j->code."\n", FILE_APPEND);
|
||
|
// Si plan suivi de SV, RJ, LJ ou clôture alors pas de plan
|
||
|
if ($j->date > $this->debutPlan && in_array($j->code, array(
|
||
|
// Sauvegarde
|
||
|
1100, 1101,
|
||
|
// RJ
|
||
|
1200, 1201, 1202, 1211, 1217,
|
||
|
// LJ
|
||
|
1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310, 1311, 1312, 1313, 1314,
|
||
|
// Extension SV, LJ, RJ
|
||
|
1417, 1418, 1419,
|
||
|
// Cloture
|
||
|
1500, 1501, 1502, 1503, 1504, 1514 ))) {
|
||
|
$this->dureePlan = 0;
|
||
|
}
|
||
|
}
|
||
|
if ($this->debug) file_put_contents('procol.log', "Durée du plan : ".$this->dureePlan."\n", FILE_APPEND);
|
||
|
}
|
||
|
|
||
|
// --- Gestion de la cloture
|
||
|
if (substr($this->Identite['FJ'],0,1) != 1 && $TopEvenCloture && in_array($evenProcolLast, array(1502,1503))) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "=== Cloture ===\n", FILE_APPEND);
|
||
|
if ($this->debug) file_put_contents('procol.log', "Cloture après procédure\n", FILE_APPEND);
|
||
|
$this->SituationCloture = true;
|
||
|
}
|
||
|
// --- Evenements effaçant l'indicateur P dans Situation Juridique
|
||
|
else {
|
||
|
if ($this->debug) file_put_contents('procol.log', "=== Traitement effacement procol ===\n", FILE_APPEND);
|
||
|
$tabNoProcol = array();
|
||
|
$tmp = $this->iDb->select('jo.tabEvenements', 'codEven, affProcol', 'affProcol>0', false, MYSQL_ASSOC);
|
||
|
foreach ($tmp as $tmp2) {
|
||
|
$tabNoProcol[$tmp2['codEven']] = $tmp2['affProcol'];
|
||
|
}
|
||
|
if (array_key_exists($evenProcolLast, $tabNoProcol)) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "Vérification Effacement procol : $evenProcolLast\n", FILE_APPEND);
|
||
|
switch ($tabNoProcol[$evenProcolLast]) {
|
||
|
// PAS DE MENTION DE LA PROCOL
|
||
|
case 1:
|
||
|
if ($this->debug) file_put_contents('procol.log', "affProcol = 1\n", FILE_APPEND);
|
||
|
$tabRet = array();
|
||
|
break;
|
||
|
// Ne pas mentionner la procol si CJ=1xxx OU si actif et CJ!=9xxx et even de plus d'un mois
|
||
|
case 2:
|
||
|
if (substr($this->Identite['FJ'],0,1)*1==1) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "affProcol = 2\n", FILE_APPEND);
|
||
|
$tabRet = array();
|
||
|
} elseif ($this->Identite['Actif']*1 > 0 && substr($this->Identite['FJ'],0,1)*1 != 9) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "affProcol = 2\n", FILE_APPEND);
|
||
|
$maxLatence = date('Ymd',mktime(0,0,0,
|
||
|
substr($evenProcolLastDate,4,2)*1+1,
|
||
|
substr($evenProcolLastDate,6,2),
|
||
|
substr($evenProcolLastDate,0,4)));
|
||
|
if (date('Ymd') > $maxLatence) {
|
||
|
$tabRet = array();
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
// Pas Procol si actif RCS
|
||
|
case 3:
|
||
|
if ($this->Identite['Actif']*1>0) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "affProcol = 3\n", FILE_APPEND);
|
||
|
$tabRet = array();
|
||
|
}
|
||
|
break;
|
||
|
// Le dernier jugement est un appel => Procol Suspendu
|
||
|
case 4:
|
||
|
if ($this->debug) file_put_contents('procol.log', "affProcol = 4\n", FILE_APPEND);
|
||
|
$this->appelJugement = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Procédure trop ancienne plus de 12 ans et actif
|
||
|
$dateTropAncienne = (date('Ymd')*1) - $MaxPeriodProcol;
|
||
|
if ($evenProcolLastDate < $dateTropAncienne && $this->Identite['Actif']*1 > 0) {
|
||
|
$derPr = Metier_Util_Date::dateT('Ymd','d/m/Y', $evenProcolLastDate);
|
||
|
$tabRet = array();
|
||
|
if ($this->debug) file_put_contents('procol.log', "Procédure trop ancienne plus de 12 ans et actif\n", FILE_APPEND);
|
||
|
}
|
||
|
// --- En Procol mais présence d'une annonce de cloture ou LJ avec Bilan publié ultérieurement
|
||
|
elseif ( in_array($evenProcolLast, array(
|
||
|
1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1311,1312,1313,
|
||
|
1500,1501,1502,1503,1504
|
||
|
)) ) {
|
||
|
$mBil = new Metier_Partenaires_MBilans($siren, $this->iDb);
|
||
|
$tabBilans = $mBil->listeBilans($accesDist);
|
||
|
$derExercice = 0;
|
||
|
foreach ($tabBilans as $idx => $bilan) {
|
||
|
if ($bilan['dateExercice'] > $derExercice) {
|
||
|
$derExercice = $bilan['dateExercice'];
|
||
|
}
|
||
|
}
|
||
|
if ($derExercice > $evenProcolLastDate) {
|
||
|
if ($this->debug) file_put_contents('procol.log', "En Procol mais présence d'une annonce de cloture ou LJ avec Bilan publié ultérieurement\n", FILE_APPEND);
|
||
|
if ($this->debug) file_put_contents('procol.log', "$derExercice > $evenProcolLastDate\n", FILE_APPEND);
|
||
|
$derEx = Metier_Util_Date::dateT('Ymd', 'd/m/Y', $derExercice);
|
||
|
$derPr = Metier_Util_Date::dateT('Ymd', 'd/m/Y', $evenProcolLastDate);
|
||
|
$tabRet = array();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// --- Dissolution mais bilan après événements
|
||
|
elseif ($rubrique == 'D') {
|
||
|
$mBil = new Metier_Partenaires_MBilans($siren, $this->iDb);
|
||
|
$tabBilans = $mBil->listeBilans(false, 3);
|
||
|
$derExercice = 0;
|
||
|
foreach ($tabBilans as $idx => $bilan){
|
||
|
if ($bilan['dateExercice'] > $derExercice) {
|
||
|
$derExercice = $bilan['dateExercice'];
|
||
|
}
|
||
|
}
|
||
|
if ($derExercice > $evenProcolDateLast) {
|
||
|
$derEx = Metier_Util_Date::dateT('Ymd','d/m/Y', $derExercice);
|
||
|
$derPr = Metier_Util_Date::dateT('Ymd','d/m/Y', $evenProcolDateLast);
|
||
|
$tabRet = array();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne les annonces du bulletin des annonces légales officielles
|
||
|
* @param string $siren
|
||
|
* @param int $idAnnonce
|
||
|
* @param int $offset
|
||
|
* @param int $lignes
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getAnnoncesBalo($siren, $idAnnonce=0, $offset=0, $lignes=100)
|
||
|
{
|
||
|
$siren = str_pad($siren, 9, '0', STR_PAD_LEFT);
|
||
|
|
||
|
$strIdAnn='';
|
||
|
$tabRet=array();
|
||
|
|
||
|
if ($idAnnonce>0) {
|
||
|
$tmp=explode('.', $idAnnonce);
|
||
|
if (is_numeric($tmp[0])) $num=$tmp[0];
|
||
|
if (is_numeric($tmp[1])) $par=$tmp[1];
|
||
|
$strIdAnn=" AND Num_Affaire='$num' AND Num_Parution='$par' ";
|
||
|
}
|
||
|
|
||
|
$mBalo = new Metier_Bodacc_MBalo();
|
||
|
|
||
|
$bodacc = $this->iDb->select('jo.balo', "Societe_Rcs, Categorie, Num_Affaire, Date_Parution, Num_Parution,
|
||
|
Url_Annonce_Html, Url_Annonce_Pdf, Annonce_Html, dateInsert",
|
||
|
"Societe_Rcs='$siren' $strIdAnn ORDER BY Date_Parution DESC, Num_Affaire LIMIT $offset, $lignes",
|
||
|
false, MYSQL_ASSOC);
|
||
|
|
||
|
$k=0;
|
||
|
if (count($bodacc) > 0) {
|
||
|
foreach ($bodacc as $k => $ann) {
|
||
|
$tabRetEven = array();
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $mBalo->getLibEven($ann['Categorie']),
|
||
|
'LibEven' => $ann['Categorie']
|
||
|
);
|
||
|
|
||
|
$tabRet[$k]=array(
|
||
|
'id' => $ann['Num_Affaire'].'.'.$ann['Num_Parution'],
|
||
|
'BodaccCode' => 'BALO',
|
||
|
'BodaccNum' => $ann['Num_Parution'],
|
||
|
'NumAnnonce' => $ann['Num_Affaire'],
|
||
|
'DateParution' => $ann['Date_Parution'],
|
||
|
'typeAnnonce' => 'Insertion',
|
||
|
'dateInsertionSD' => $ann['dateInsert'],
|
||
|
'evenements' => $tabRetEven,
|
||
|
'Lien_Annonce_Pdf' => basename($ann['Url_Annonce_Pdf']),
|
||
|
);
|
||
|
if ($idAnnonce<>0) {
|
||
|
$tabRet[$k]['texteAnnonce'] = strtr(
|
||
|
preg_replace('/<html.*<body.*>/Uis', '',
|
||
|
preg_replace('/( class=".*")/ie', ' ', $ann['Annonce_Html'])),
|
||
|
array(' '=>' ', '</html>'=>'', '</body>'=>'')
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne le nombre d'annonce Balo pour un siren
|
||
|
* @param string $siren
|
||
|
* @return int
|
||
|
*/
|
||
|
public function getAnnoncesBaloCount($siren)
|
||
|
{
|
||
|
$bodacc = $this->iDb->select('jo.balo', "count(*) AS nb",
|
||
|
"Societe_Rcs='$siren' ORDER BY Date_Parution DESC, Num_Affaire", false, MYSQL_ASSOC);
|
||
|
$nb = 0;
|
||
|
if (count($bodacc)>0) {
|
||
|
$nb = $bodacc[0]['nb'];
|
||
|
}
|
||
|
return $nb;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne les annonces du bulletin officiel des annonces de marché publique
|
||
|
* @param string $siren
|
||
|
* @param string $idAnnonce
|
||
|
* @param string|array $type A:Avis d'attribution, M:Avis de marché
|
||
|
* @param int $offset
|
||
|
* @param int $lignes
|
||
|
* @return Ambigous <string, multitype:multitype:string unknown multitype:multitype:string multitype:string NULL multitype:string unknown Ambigous <string, unknown> multitype:multitype:string Ambigous <number, unknown> , unknown>
|
||
|
*/
|
||
|
public function getAnnoncesBoamp($siren, $idAnnonce='', $type=array('A', 'M'), $offset=0, $lignes=100)
|
||
|
{
|
||
|
$siren = intval($siren);
|
||
|
|
||
|
$strIdAnn = '';
|
||
|
$idA = 0;
|
||
|
$tabRet = array();
|
||
|
|
||
|
$mBoamp = new Metier_Bodacc_MBoamp();
|
||
|
|
||
|
// --- Recherche dans les avis d'attribution
|
||
|
if ( is_string($type) && $type=='A' || is_array($type) && in_array('A',$type) ) {
|
||
|
|
||
|
if ($idAnnonce != '') {
|
||
|
$tmp = explode('.', $idAnnonce);
|
||
|
$idA = $tmp[1];
|
||
|
if ($tmp[0]=='A') $strIdAnn=" AND l.id='$idA' ";
|
||
|
elseif ($tmp[0]=='O') $strIdAnn="";
|
||
|
}
|
||
|
|
||
|
$bodacc = $this->iDb->select('jo.boamp_lots l, jo.boamp b, jo.boamp_detail d',
|
||
|
"l.id, l.idAnn, l.Boamp_Code, l.Boamp_Rubrique, b.Boamp_Rubrique_Lib, b.typeAnnonce, l.Boamp_Date_Parution, b.Boamp_Num, b.Boamp_Annee_Parution, b.Num_AnnoncePre, b.Num_Annonce, b.Boamp_Dept, b.annonce, l.num, l.`desc` AS description, l.nom, d.raisonSociale, l.montantTxt, sum(l.montant) AS montant, l.montantAnMin, l.montantAnMax, l.trancheCond, l.trancheFerme, l.dateAttrib, l.intitule, l.nomenclature, l.objets, l.cpv, l.cpvComp, l.volume, l.execution, l.livraison, l.dureeJours, l.dureeMois, l.dateDeb, l.dateFin, l.dateInsert, d.titre, d.objet, d.titreMarche, d.typeObjetMarche, d.objetAutre, d.autres",
|
||
|
"l.siren=$siren AND l.idAnn=b.id AND l.idAnn=d.id $strIdAnn GROUP BY b.id ORDER BY l.Boamp_Date_Parution DESC LIMIT $offset,$lignes", false, MYSQL_ASSOC);
|
||
|
|
||
|
$k = 0;
|
||
|
if (count($bodacc)>0) {
|
||
|
foreach ($bodacc as $k => $ann) {
|
||
|
$tabRetEven=array();
|
||
|
if ($ann['nom']<>'') $strMontant=' "'.strtoupper($ann['raisonSociale']).'"';
|
||
|
|
||
|
if ($ann['montant']*1>0) $strMontant.=' ('.number_format($ann['montant'], 2, ',', ' ').' EUR)';
|
||
|
elseif ($ann['montantTxt']<>'') $strMontant.=' ('.$ann['montantTxt'].')';
|
||
|
elseif ($ann['montantAnMin']<>'' && $ann['montantAnMax'])
|
||
|
$strMontant.=' ('.$ann['montantAnMin'].' à '.$ann['montantAnMax'].')';
|
||
|
elseif ($ann['trancheCond']<>'' && $ann['trancheFerme'])
|
||
|
$strMontant.=' ('.$ann['trancheCond'].' / '.$ann['trancheFerme'].')';
|
||
|
else $strMontant.='';
|
||
|
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $mBoamp->getCodEvenSd($ann['Boamp_Rubrique']),
|
||
|
'LibEven' => $mBoamp->getLibEvenBoamp($ann['Boamp_Rubrique'],$ann['Boamp_Rubrique_Lib']).$strMontant
|
||
|
);
|
||
|
|
||
|
// Axxx pour lot attribué ou Oxxx pour Organisation
|
||
|
if ($ann['Num_AnnoncePre']<>0) $numAnn=$ann['Num_AnnoncePre'].'-'.$ann['Num_Annonce'];
|
||
|
else $numAnn=$ann['Num_Annonce'];
|
||
|
if ($ann['Boamp_Code']=='MAPA') {
|
||
|
$lienMapa = 'http://www.boamp.fr/index.php?action=avis&num_parution=MAPA&num_annonce='.
|
||
|
$ann['Num_AnnoncePre'].'-'.$ann['Num_Annonce'].'&total=500&_s=0&indice=0';
|
||
|
} else {
|
||
|
$lettre = substr($ann['Boamp_Code'],-1);
|
||
|
$annee = $ann['Boamp_Annee_Parution'];
|
||
|
$num = sprintf("%04d",$ann['Boamp_Num']);
|
||
|
$numPar = $lettre.$annee.$num;
|
||
|
$lienMapa = 'http://www.boamp.fr/index.php?action=avis&num_parution='.
|
||
|
$numPar.'&num_annonce='.$ann['Num_Annonce'].'&total=500&_s=0&indice=0';
|
||
|
}
|
||
|
$infosComp='';
|
||
|
$objetMarche=trim($ann['objet'].' '.$ann['objetAutre'].' '.$ann['autres']);
|
||
|
//titre, titreMarche, typeObjetMarche
|
||
|
$tabRet[$k] = array(
|
||
|
'id'=>'A.'.$ann['id'],
|
||
|
'BodaccCode'=>$ann['Boamp_Code'],
|
||
|
'BodaccNum'=>$ann['Boamp_Num'],
|
||
|
'NumAnnonce'=>$numAnn,
|
||
|
'DateParution'=>$ann['Boamp_Date_Parution'],
|
||
|
'Departement'=>$ann['Boamp_Dept'],
|
||
|
//'Tribunal'=>$ann['triNom'],
|
||
|
//'TribunalSiret'=>$ann['triSiret'],
|
||
|
//'Rubrique'=>$ann['Boamp_Rubrique_Lib'],
|
||
|
'typeAnnonce'=>$ann['typeAnnonce'],
|
||
|
'dateInsertionSD'=>$ann['dateInsert'],
|
||
|
'Montant'=>$ann['montant'],
|
||
|
'Organisme'=>strtoupper($ann['raisonSociale']),
|
||
|
'Objet'=>$objetMarche,
|
||
|
'evenements'=>$tabRetEven,
|
||
|
'infosComp'=>$infosComp, // Non géré
|
||
|
'Lien_Annonce_Html'=>$lienMapa, // Non géré
|
||
|
);
|
||
|
|
||
|
if ($idA<>0) {
|
||
|
if ($ann['Boamp_Code']=='MAPA') {
|
||
|
$tabRet[$k]['texteAnnonce'] = $ann['annonce'];
|
||
|
} else {
|
||
|
$tabRet[$k]['texteAnnonce'] = strtr(
|
||
|
preg_replace('/<html.*<body.*>/Uis', '',
|
||
|
preg_replace('/<p\s+.*>/Uis', '',
|
||
|
preg_replace('/( class=".*")/ie', ' ', $ann['annonce']))),
|
||
|
array(' '=>' ', '</html>'=>'', '</body>'=>'', '</p>'=>'<br/>')
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// --- Recherche dans les avis de marchés
|
||
|
if ( is_string($type) && $type=='M' || is_array($type) && in_array('M',$type) ) {
|
||
|
|
||
|
if ($idAnnonce<>'') {
|
||
|
$tmp = explode('.', $idAnnonce);
|
||
|
$idA = $tmp[1];
|
||
|
if ($tmp[0]=='A') $strIdAnn=" AND d.id='$idA' ";
|
||
|
elseif ($tmp[0]=='O') $strIdAnn="";
|
||
|
}
|
||
|
|
||
|
$bodacc = $this->iDb->select('jo.boamp b, jo.boamp_detail d',
|
||
|
"d.id, d.Boamp_Code, d.Boamp_Rubrique, b.Boamp_Rubrique_Lib, b.typeAnnonce, d.Boamp_Date_Parution, b.Boamp_Num, b.Boamp_Annee_Parution, b.Num_AnnoncePre, b.Num_Annonce, b.Boamp_Dept, b.annonce, titre AS description, d.raisonSociale, d.estimValeur AS montantTxt, d.estimValeurMin AS montantAnMin, d.estimValeurMax AS montantAnMax, objet, cpv_obj, cpv_comp, d.dateInsert",
|
||
|
"d.siren=$siren AND d.id=b.id $strIdAnn GROUP BY b.id ORDER BY d.Boamp_Date_Parution DESC", false, MYSQL_ASSOC);
|
||
|
|
||
|
if (count($bodacc)>0) {
|
||
|
foreach ($bodacc as $k => $ann) {
|
||
|
$id = $ann['id'];
|
||
|
$rub = $ann['Boamp_Rubrique'];
|
||
|
$tabRetEven = array();
|
||
|
$strMontant = '';
|
||
|
if ($ann['objet']<>'') $strMontant.=' "'.$ann['objet'].'"';
|
||
|
|
||
|
if ($rub=='6' || // Avis d'attribution
|
||
|
$rub=='7' || // Avis en cas de transparence ex ante volontaire
|
||
|
$rub=='77' || // Avis d'attribution
|
||
|
$rub=='8' || // Avis d'attribution
|
||
|
$rub=='82' || // Rectificatif
|
||
|
$rub=='83' || // Rectificatif
|
||
|
$rub=='84' || // Avis d'attribution comportant des lots infructueux
|
||
|
$rub=='9' || // Résultat de marché
|
||
|
$rub=='92' || // Rectificatif
|
||
|
$rub=='93' || // Résultat de marché / Infructueux - Sans suite
|
||
|
$rub=='94' || // Résultat de marché / Résultat de marché comportant des lots infructueux
|
||
|
$rub=='96' || // Annulation - Rectificatif - Sans suite - Infructueux
|
||
|
$rub=='977' // Annulation - Rectificatif / Avis en cas de transparence ex ante volontaire
|
||
|
) {
|
||
|
$tabTmp = $this->iDb->select('jo.boamp_lots l',
|
||
|
"l.id, l.idAnn, l.Boamp_Code, l.Boamp_Rubrique, l.Boamp_Date_Parution, l.num, l.desc AS description, l.nom, l.montantTxt, l.montant, l.montantAnMin, l.montantAnMax, l.trancheCond, l.trancheFerme, l.dateAttrib, l.intitule, l.nomenclature, l.objets, l.cpv, l.cpvComp, l.volume, l.execution, l.livraison, l.dureeJours, l.dureeMois, l.dateDeb, l.dateFin",
|
||
|
"l.idAnn=$id", false, MYSQL_ASSOC);
|
||
|
foreach ($tabTmp as $k2=>$ann2) {
|
||
|
if ($ann2['nom']<>'') $strMontant.=' "'.strtoupper($ann2['nom']).'"';
|
||
|
if ($ann2['montant']*1>0) $strMontant.=' ('.number_format($ann2['montant'], 2, ',', ' ').' EUR)';
|
||
|
elseif ($ann2['montantTxt']<>'') $strMontant.=' ('.$ann2['montantTxt'].')';
|
||
|
elseif ($ann2['montantAnMin']<>'' && $ann2['montantAnMax'])
|
||
|
$strMontant.=' ('.$ann2['montantAnMin'].' à '.$ann2['montantAnMax'].')';
|
||
|
elseif ($ann2['trancheCond']<>'' && $ann2['trancheFerme'])
|
||
|
$strMontant.=' ('.$ann['trancheCond'].' / '.$ann['trancheFerme'].')';
|
||
|
else $strMontant.='';
|
||
|
}
|
||
|
}
|
||
|
$tabRetEven[] = array(
|
||
|
'CodeEven' => $mBoamp->getCodEvenSd($ann['Boamp_Rubrique']),
|
||
|
'LibEven' => $mBoamp->getLibEvenBoamp($ann['Boamp_Rubrique'], $ann['Boamp_Rubrique_Lib']).$strMontant
|
||
|
);
|
||
|
|
||
|
// Axxx pour lot attribué ou Oxxx pour Organisation
|
||
|
if ($ann['Num_AnnoncePre']<>0) $numAnn=$ann['Num_AnnoncePre'].'-'.$ann['Num_Annonce'];
|
||
|
else $numAnn=$ann['Num_Annonce'];
|
||
|
if ($ann['Boamp_Code']=='MAPA')
|
||
|
$lienMapa='http://www.boamp.fr/index.php?action=avis&num_parution=MAPA&num_annonce='.$ann['Num_AnnoncePre'].'-'.$ann['Num_Annonce'].'&total=500&_s=0&indice=0';//&affichage_avis=officiel';
|
||
|
else {
|
||
|
$lettre = substr($ann['Boamp_Code'],-1);
|
||
|
$annee = $ann['Boamp_Annee_Parution'];
|
||
|
$num = sprintf("%04d",$ann['Boamp_Num']);
|
||
|
$numPar=$lettre.$annee.$num;
|
||
|
$lienMapa='http://www.boamp.fr/index.php?action=avis&num_parution='.$numPar.'&num_annonce='.$ann['Num_Annonce'].'&total=500&_s=0&indice=0';
|
||
|
}
|
||
|
$infosComp='';
|
||
|
$tabRet[$k] = array(
|
||
|
'id'=>'O.'.$id,
|
||
|
'BodaccCode'=>$ann['Boamp_Code'],
|
||
|
'BodaccNum'=>$ann['Boamp_Num'],
|
||
|
'NumAnnonce'=>$numAnn,
|
||
|
'DateParution'=>$ann['Boamp_Date_Parution'],
|
||
|
'Departement'=>$ann['Boamp_Dept'],
|
||
|
//'Tribunal'=>$ann['triNom'],
|
||
|
//'TribunalSiret'=>$ann['triSiret'],
|
||
|
//'Rubrique'=>$ann['Boamp_Rubrique_Lib'],
|
||
|
'typeAnnonce'=>$ann['typeAnnonce'],
|
||
|
'dateInsertionSD'=>$ann['dateInsert'],
|
||
|
'evenements'=>$tabRetEven,
|
||
|
'infosComp'=>$infosComp, // Non géré
|
||
|
'Lien_Annonce_Html'=>$lienMapa, // Non géré
|
||
|
);
|
||
|
|
||
|
if ($idA<>0) {
|
||
|
if ($ann['Boamp_Code']=='MAPA') {
|
||
|
$tabRet[$k]['texteAnnonce'] = $ann['annonce'];
|
||
|
} else {
|
||
|
$tabRet[$k]['texteAnnonce'] = strtr(
|
||
|
preg_replace('/<html.*<body.*>/Uis', '',
|
||
|
preg_replace('/<p\s+.*>/Uis', '',
|
||
|
preg_replace('/( class=".*")/ie', ' ', $ann['annonce']))),
|
||
|
array(' '=>' ', '</html>'=>'', '</body>'=>'', '</p>'=>'<br/>')
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
Metier_Util_Log::write('I', "getAnnoncesBoamp(siren=$siren, idAnnonce=$idAnnonce, $idA)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Nombre total d'annonces BOAMP
|
||
|
* @param string $siren
|
||
|
* @param string $type A:avis d'attribution, M:Avis de marché
|
||
|
*/
|
||
|
public function getAnnoncesBoampCount($siren, $type='')
|
||
|
{
|
||
|
$bodaccA = array();
|
||
|
$bodaccM = array();
|
||
|
|
||
|
// --- Recherche dans les avis d'attribution
|
||
|
if ( $type=='' || $type=='A' ) {
|
||
|
$bodaccA = $this->iDb->select('jo.boamp_lots l, jo.boamp b, jo.boamp_detail d', "l.id",
|
||
|
"l.siren=$siren AND l.idAnn=b.id AND l.idAnn=d.id GROUP BY b.id ORDER BY l.Boamp_Date_Parution",
|
||
|
false, MYSQL_ASSOC);
|
||
|
}
|
||
|
|
||
|
// --- Recherche dans les avis de marchés
|
||
|
if ( $type=='' || $type=='M') {
|
||
|
$bodaccM = $this->iDb->select('jo.boamp b, jo.boamp_detail d', "d.id",
|
||
|
"d.siren=$siren AND d.id=b.id GROUP BY b.id ORDER BY d.Boamp_Date_Parution DESC",
|
||
|
false, MYSQL_ASSOC);
|
||
|
}
|
||
|
|
||
|
$nb = count($bodaccA) + count($bodaccM);
|
||
|
|
||
|
return $nb;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param unknown $siren
|
||
|
* @param number $idAnnonce
|
||
|
* @param number $offset
|
||
|
* @param number $lignes
|
||
|
*/
|
||
|
public function getAnnoncesAsso($siren, $idAnnonce=0, $offset=0, $lignes=100)
|
||
|
{
|
||
|
Metier_Util_Log::write('I', "Début getAnnoncesAsso(siren=$siren, idAnnonce=$idAnnonce)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||
|
|
||
|
$siretMin=$siren.'00000';
|
||
|
$siretMax=$siren.'99999';
|
||
|
$strIdAnn='';
|
||
|
$tabRet=array();
|
||
|
|
||
|
if ($idAnnonce>0){
|
||
|
$strIdAnn="id=$idAnnonce";
|
||
|
} elseif (substr($siren,0,1)=='W' && $idAnnonce == 0) {
|
||
|
$strIdAnn = "Waldec='$siren'";
|
||
|
} else {
|
||
|
$strIdAnn = "siren=$siren";
|
||
|
}
|
||
|
|
||
|
$bodacc=$this->iDb->select('jo.asso', "id, Assoc_Nom, siren, nic, Waldec, Activite, Num_Annonce, Date_Parution, Num_Parution, Departement, Sous_Prefecture, Type_Annonce, Annonce_Html, Assoc_Objet, Assoc_Adresse, Assoc_NObjet, Assoc_AObjet, Assoc_NAdresse, Assoc_Fusion, Assoc_Annulation, Assoc_ANom, Assoc_NNom, Assoc_Date_Declaration, Assoc_Date_Declaration2, typeAnnonce, codEven, dateInsert", "$strIdAnn AND dateSuppr=0 ORDER BY Date_Parution DESC LIMIT $offset,$lignes", false, MYSQL_ASSOC);
|
||
|
|
||
|
$k=0;
|
||
|
if (count($bodacc)>0) {
|
||
|
foreach ($bodacc as $k=>$ann) {
|
||
|
$tabEven=explode(';', $ann['codEven']);
|
||
|
$tabRetEven=array();
|
||
|
if ($ann['typeAnnonce']<>'Insertion')//BODACC n°002 A du 04/01/2006.
|
||
|
$tabRetEven[]=array('CodeEven'=>'0000',
|
||
|
'LibEven'=> $ann['typeAnnonce'].' de l\'annonce './*n°'.
|
||
|
$ann['corrNum_Annonce'].' BODACC n°'.
|
||
|
$ann['corrNumParution'].*/' du '.
|
||
|
Metier_Util_Date::dateT('Y-m-d','d/m/Y',$ann['corrDate_Parution'])/*.' (page '.
|
||
|
$ann['corrPage'].')'*/);
|
||
|
else {
|
||
|
if (trim($ann['codEven'])<>'') {
|
||
|
foreach ($tabEven as $even)
|
||
|
$tabRetEven[]=array('CodeEven'=>$even,'LibEven'=>$this->iBodacc->getEvenement($even));
|
||
|
}
|
||
|
else {
|
||
|
$tabRetEven[]=array('CodeEven'=>0000,//$mAsso->getLibEven($ann['Categorie']),
|
||
|
'LibEven'=> $ann['Type_Annonce']);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Rubrique
|
||
|
if (preg_match('/cr(é|e)ation/iu', $ann['Type_Annonce']))
|
||
|
$rub='creations';
|
||
|
elseif (preg_match('/Dissolution/i', $ann['Type_Annonce']))
|
||
|
$rub='radiations';
|
||
|
else
|
||
|
$rub='mmd';
|
||
|
// typeAnnonce
|
||
|
if (preg_match('/Annulation/i', $ann['Type_Annonce']))
|
||
|
$type='Suppression';
|
||
|
elseif (preg_match('/Rectif/i', $ann['Type_Annonce']))
|
||
|
$type='Rectificatif';
|
||
|
else
|
||
|
$type='Insertion';
|
||
|
if (str_replace('-','',$ann['Date_Parution'])*1>=20070401) $dateInsert=$ann['Date_Parution'];
|
||
|
else $dateInsert='';
|
||
|
|
||
|
$tabRet[$k]=array(
|
||
|
'id'=>$ann['id'],
|
||
|
'BodaccCode'=>'ASSO',
|
||
|
'BodaccNum'=>$ann['Num_Parution'],
|
||
|
'NumAnnonce'=>$ann['Num_Annonce'],
|
||
|
'DateParution'=>$ann['Date_Parution'],
|
||
|
'Departement'=>$ann['Departement'],
|
||
|
'Tribunal'=>$ann['Sous_Prefecture'],
|
||
|
//'TribunalSiret'=>$ann['triSiret'],
|
||
|
'Rubrique'=>$rub,
|
||
|
'typeAnnonce'=>$type,
|
||
|
'dateInsertionSD'=>$dateInsert,
|
||
|
'evenements'=>$tabRetEven,
|
||
|
//'Lien_Annonce_Pdf'=>basename($ann['Url_Annonce_Pdf']),
|
||
|
);
|
||
|
if ($idAnnonce<>0){
|
||
|
/*if ( preg_match( "~(\x00[\x80-\xff]|[\x00-\x07][\x00-\xff]~", $ann['Annonce_Html'] ) )
|
||
|
$tabRet[$k]['texteAnnonce']='utf8 : '.$ann['Annonce_Html'];
|
||
|
else */
|
||
|
//$tabRet[$k]['texteAnnonce']=strip_tags(strtr(htmlentities($ann['Annonce_Html']),array('>'=>'>','&'=>'&','<'=>'<')));
|
||
|
|
||
|
if (mb_detect_encoding($ann['Annonce_Html']) == 'UTF-8'){
|
||
|
$tmp = utf8_decode($ann['Annonce_Html']);
|
||
|
} else {
|
||
|
$tmp = $ann['Annonce_Html'];
|
||
|
}
|
||
|
$tabRet[$k]['texteAnnonce'] = $tmp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
Metier_Util_Log::write('I', "Fin getAnnoncesAsso(siren=$siren, idAnnonce=$idAnnonce) : ".count($tabRet).' annonce(s)', __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Nombre d'annonces association
|
||
|
* @param int $idAnnonce
|
||
|
* @param string $siren
|
||
|
*/
|
||
|
public function getAnnoncesAssoCount($siren, $idAnnonce = 0)
|
||
|
{
|
||
|
$strIdAnn = '';
|
||
|
|
||
|
if ($idAnnonce>0) {
|
||
|
$strIdAnn="id=$idAnnonce";
|
||
|
} elseif (substr($siren,0,1)=='W' && $idAnnonce == 0) {
|
||
|
$strIdAnn = "Waldec='$siren'";
|
||
|
} else {
|
||
|
$strIdAnn = "siren=$siren";
|
||
|
}
|
||
|
|
||
|
$bodacc=$this->iDb->select('jo.asso', "COUNT(*) AS nb", "$strIdAnn AND dateSuppr=0", false, MYSQL_ASSOC);
|
||
|
$nb = 0;
|
||
|
if (count($bodacc)>0) {
|
||
|
$nb = $bodacc[0]['nb'];
|
||
|
}
|
||
|
return $nb;
|
||
|
}
|
||
|
|
||
|
/** @todo $nic inutilisé pour l'instant **/
|
||
|
public function getIdentitePart($siren, $rs, $enseigne, $sigle, $nic=0, $refresh=false)
|
||
|
{
|
||
|
$dateUpdate=0;
|
||
|
$lastYear=date('Ymd',mktime(0,0,0,date('m'),date('d'),date('Y')-1))*1;
|
||
|
$tabRet=array();
|
||
|
|
||
|
/** Chargement initial au cas ou la requête Coface plante **/
|
||
|
$tabTmp=$this->iDb->select('jo.infos_entrep', 'raisonSociale, isin, nscrl, tel, fax, web, mail, DATE(dateUpdate)*1 as dateUpdate', "siren=$siren", false, MYSQL_ASSOC);
|
||
|
$idComp=@$tabTmp[0];
|
||
|
if (isset($idComp['raisonSociale'])) {
|
||
|
// L'entrep est en base infos_entrep
|
||
|
if ($idComp['web']<>'http://') $web=$idComp['web'];
|
||
|
else $web='';
|
||
|
$tabRet=array( 'raisonSociale'=>$idComp['raisonSociale'],
|
||
|
'isin'=>$idComp['isin'],
|
||
|
'nscrl'=>$idComp['nscrl'],
|
||
|
'tel'=>$idComp['tel'],
|
||
|
'fax'=>$idComp['fax'],
|
||
|
'web'=>$web,
|
||
|
'mail'=>$idComp['mail'],
|
||
|
'enCache'=>true,
|
||
|
);
|
||
|
$dateUpdate=$idComp['dateUpdate'];
|
||
|
}
|
||
|
|
||
|
// On ne rafraichie que si demandé et
|
||
|
// que la requête en base est trop ancienne et nscrl est vide ou tel ou web
|
||
|
$refresh=false;
|
||
|
if ($refresh && $refresh && $dateUpdate<$lastYear && ($idComp['nscrl']==0 || $idComp['tel']=='') ) {
|
||
|
$timeout=20;
|
||
|
// La mise à jour ne se fera pas si lastMAJ<365
|
||
|
/*$strUpdate='AND (DATEDIFF(NOW(),dateUpdate)<365 OR (nscrl<>0 AND DATEDIFF(NOW(),dateUpdate)>0))';
|
||
|
$timeout=10;
|
||
|
$strUpdate='AND nscrl<>0 AND DATEDIFF(NOW(),dateUpdate)>0';*/
|
||
|
$referer='';
|
||
|
$url='http://www.elliscore.fr/portail/entreprise_identite/identite.asp?ip=pagespro&lg=fr&nsiren='.$siren;
|
||
|
$tdeb=microtime(1);
|
||
|
$page=getUrl($url, '', '', $referer, false, 'www.elliscore.fr', '', $timeout);
|
||
|
$duree=round(microtime(1)-$tdeb,3);
|
||
|
$this->body=$page['body'];
|
||
|
$this->codeRetour=$page['code'];
|
||
|
$this->header=$page['header'];
|
||
|
if ($this->codeRetour==408)
|
||
|
// Si timeout, on sort afin de ne pas écraser les données en base
|
||
|
return $tabRet;
|
||
|
|
||
|
$tabRet['nscrl']=@getTextInHtml($this->body, '&nscrl=', '=','&');
|
||
|
$strTmp=trim(str_replace(chr(160), ' ', html_entity_decode(utf8_encode(@getTextInHtml($this->body, '<td WIDTH="40%" bgcolor="#F3E5CC" class="tabligne"> <b> Raison sociale<br>', '<td WIDTH="60%" bgcolor="#FFF3DE" class="tabval"><b>','</tr>')))));
|
||
|
$tmp=explode('<br>', $strTmp);
|
||
|
$tabRet['raisonSociale']=trim($tmp[0]);
|
||
|
unset($tmp[0]);
|
||
|
$tabRet['adresse']=trim(strip_tags(implode(',', $tmp)));
|
||
|
|
||
|
$tel=trim(@getTextInHtml($this->body, '<td bgcolor="#F3E5CC" class="tabligne"><b>Téléphone<br>', '<td bgcolor="#FFF3DE" class="tabval" valign="top">', '<br>'));
|
||
|
$fax=trim(@getTextInHtml($this->body, 'Télécopie</b></td>', '<br>', '</td>'));
|
||
|
$web=trim(@getTextInHtml($this->body, '><b>Adresse internet <br>', '<a class="tabval" HREF="', '" target="_new">'));
|
||
|
$mail=trim(@getTextInHtml($this->body, '<a class="tabval" href="mailto:', ':', '">'));
|
||
|
$bourse=trim(@getTextInHtml($this->body, 'Ville Bourse</b></td>', 'class="tabval">', '</td>'));
|
||
|
$tmp=explode('<br>', $bourse);
|
||
|
$isin=trim($tmp[0]);
|
||
|
$tabRet['bourseMarche']=trim($tmp[1]);
|
||
|
$tabRet['bourseVille']=trim($tmp[2]);
|
||
|
|
||
|
/** On ne charge les valeurs tel, fax, web et mail que si non vides
|
||
|
**/
|
||
|
if ($tel<>'') $tabRet['tel']=$tel;
|
||
|
if ($fax<>'') $tabRet['fax']=$fax;
|
||
|
if ($web<>'') $tabRet['web']=$web;
|
||
|
if ($mail<>'') $tabRet['mail']=$mail;
|
||
|
if (($tabRet['isin']<>'' || trim($tmp[0])<>'') && trim($tmp[0])<>$tabRet['isin']) {
|
||
|
if (trim($tmp[0])<>'' && $tabRet['isin']=='')
|
||
|
$tabRet['isin']=$isin;
|
||
|
} elseif ($isin<>'') $tabRet['isin']=$isin;
|
||
|
|
||
|
$tabRet['bourseIsin']=$tabRet['isin'];
|
||
|
|
||
|
if ($tabRet['web']=='' || $tabRet['web']=='http://') {
|
||
|
$tabRet['web']=trim($this->findSiteWeb($rs));
|
||
|
}
|
||
|
if ($tabRet['web']=='' && $enseigne<>'') {
|
||
|
$tabRet['web']=trim($this->findSiteWeb($enseigne));
|
||
|
}
|
||
|
if ($tabRet['web']=='' && $sigle<>'') {
|
||
|
$tabRet['web']=trim($this->findSiteWeb($sigle));
|
||
|
}
|
||
|
|
||
|
if ($tabRet['web']<>'http://') $web=$tabRet['web'];
|
||
|
else $web='';
|
||
|
|
||
|
$tabRet['enCache']=false;
|
||
|
$tabRet['duree']=$duree;
|
||
|
|
||
|
$tabUpdate=array( 'raisonSociale'=>$tabRet['raisonSociale'],
|
||
|
'isin'=>$tabRet['bourseIsin'],
|
||
|
'nscrl'=>$tabRet['nscrl'],
|
||
|
'tel'=>$tabRet['tel'],
|
||
|
'fax'=>$tabRet['fax'],
|
||
|
'web'=>$web,
|
||
|
'mail'=>$tabRet['mail'],
|
||
|
// 'dateCreation'=>$idComp['dateCreation'],
|
||
|
// 'dateFermeture'=>$idComp['dateFermeture'],
|
||
|
// 'naf'=>$idComp['naf'],
|
||
|
// 'naf_lib'=>$this->getLibelleNaf($idComp['naf']),
|
||
|
// 'ca'=>str_replace('€','?', $idComp['ca']),
|
||
|
// 'nbEtab'=>$idComp['nbEtab'],
|
||
|
// 'effectif'=>$idComp['effectif'],
|
||
|
);
|
||
|
$tabInsert=array_merge($tabUpdate,array('siren'=>$siren));
|
||
|
if (!$this->iDb->insert('jo.infos_entrep', $tabInsert))
|
||
|
$this->iDb->update('jo.infos_entrep', $tabUpdate, "siren=$siren");
|
||
|
}
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
public function listeConventions($naf4, $dep=0)
|
||
|
{
|
||
|
$dep=$dep*1;
|
||
|
if ($dep>0) {
|
||
|
if ($dep<10) $dep='Dep0'.$dep;
|
||
|
else $dep='Dep'.$dep;
|
||
|
$strDep="AND (n.territoire='' OR n.territoire LIKE '%$dep%')";
|
||
|
}
|
||
|
$listeCC=$this->iDb->select('jo.conv_naf n, jo.conventions c',
|
||
|
'n.`id CC`, n.`nom CC`, n.`editeur CC`, n.`nb page CC`, n.`isbn CC`, n.`date edition CC`, c.infoCC, joCCmaj',
|
||
|
"n.naf='$naf4' AND substring(n.`id CC`,1,4)=c.numBrochure $strDep GROUP BY n.`id CC`", false, MYSQL_ASSOC);
|
||
|
return $listeCC;
|
||
|
}
|
||
|
|
||
|
protected function findSiteWeb($rs)
|
||
|
{
|
||
|
/** @TODO Provisoirement tant qu'on ne vérifie pas le .fr ou .com auprès d'un registrar **/
|
||
|
return false;
|
||
|
|
||
|
$referer='http://www.google.fr/';
|
||
|
$url='http://www.google.fr/search?hl=fr&q='.urlencode($rs).'&btnG=Rechercher&meta=cr%3DcountryFR';
|
||
|
$page=getUrl($url, '', '', $referer, false, 'www.google.fr','', 5);
|
||
|
$fp=fopen('./findSiteWeb.log', 'a+');
|
||
|
if ($page['code']==200) {
|
||
|
$levMin=100;
|
||
|
$pctMin=0;
|
||
|
$urlLev=$urlPct='';
|
||
|
$body=$page['body'];
|
||
|
preg_match_all('/<a href="(.*)"/iU', $body, $matches);
|
||
|
$urlapprox="http://$rs.";
|
||
|
|
||
|
foreach ($matches[1] as $i=>$url)
|
||
|
{
|
||
|
$lev=@levenshtein ($urlapprox,$url);
|
||
|
if ($lev>0 && $lev<$levMin) {
|
||
|
$levMin=$lev;
|
||
|
$urlLev=$url;
|
||
|
}
|
||
|
$sim=similar_text($urlapprox,$url,$pct);
|
||
|
if ($pct>$pctMin && strpos($url, 'zonebourse')===false) {
|
||
|
$pctMin=$pct;
|
||
|
$urlPct=$url;
|
||
|
}
|
||
|
fwrite($fp, date('Y-m-d H:i:s') .' - '. $page['code'] . " - $rs - $i - $lev (Min=$levMin) - $pct (Min=$pctMin) - $urlLev - $urlPct - $url\n");
|
||
|
//2008-05-20 20:01:08 - 200- ARKEMA FRANCE - 53 - 20 - 10 - http://www.arkema.fr/ - http://www.zonebourse.com/ARKEMA-17031/ - /intl/fr/about.html
|
||
|
|
||
|
}
|
||
|
|
||
|
fclose($fp);
|
||
|
|
||
|
if ($levMin<15 && $pctMin>44 && $urlLev==$urlPct) {
|
||
|
fwrite($fp, date('Y-m-d H:i:s') .' - '. $page['code'] . " - $rs - $i - $lev (Min=$levMin) - $pct (Min=$pctMin) - $urlLev - $urlPct - $url !!! RETURNED !!!\n");
|
||
|
return $urlLev;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
fclose($fp);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public function getImportExport($siren, $type='', $annee='')
|
||
|
{
|
||
|
if ($type=='') $strimportExport=" AND importExport IN ('I','E') ";
|
||
|
elseif ($type=='I') $strimportExport=" AND importExport='I' ";
|
||
|
elseif ($type=='E') $strimportExport=" AND importExport='E' ";
|
||
|
if ($annee*1>0) $strAnnees=" AND annee=$annee ";
|
||
|
else {
|
||
|
$tabAnnees=array();
|
||
|
$strAnnees=' AND annee IN (';
|
||
|
for ($an=date('Y')-6; $an<date('Y'); $an++)
|
||
|
$tabAnnees[]=$an;
|
||
|
$strAnnees.=implode(',', $tabAnnees).')';
|
||
|
}
|
||
|
$tabImportExport=$this->iDb->select('jo.importExport', 'importExport, annee, rangNational, deptSiege', "1 $strImportExport $strAnnees AND siren=$siren ORDER BY annee DESC, importExport ASC",false, MYSQL_ASSOC);
|
||
|
return $tabImportExport;
|
||
|
}
|
||
|
|
||
|
public function getInfosNotice($siren, $nic)
|
||
|
{
|
||
|
/** Elements provenant du Notice 80 hors identité **/
|
||
|
$tabTmp=$this->iDb->select('insee.insee_notices',
|
||
|
"LPAD(insSIREN,9,0) AS insSIREN, LPAD(insNIC,5,0) AS insNIC, insL4_VOIE, insL6_POST, LPAD(insRPET,2,0) AS insRPET, insDEPCOMEN,
|
||
|
LPAD(insRPEN,2,0) AS insRPEN, insARRONET, insCTONET, insTCD, LPAD(insZEMET,2,0) AS insZEMET, insDU,
|
||
|
insTU, LPAD(insUU,2,0) AS insUU, LPAD(insMMINTRET,2,0) AS insMMINTRET, LPAD(insMMINTREN,2,0) AS insMMINTREN, insVMAJ, insVMAJ1,
|
||
|
insVMAJ2, insVMAJ3, insRECME, insEAEANT, insEAEAPET, insEAESEC1T, insEAESEC2T, insEAEANN, insEAEAPEN, insEAESEC1N,
|
||
|
insEAESEC2N, insEAESEC3N, insEAESEC4N, dateNotice",
|
||
|
"insSIREN=$siren AND insNIC=$nic ORDER BY dateNotice DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
|
||
|
if (count($tabTmp)==0) {
|
||
|
$tabTmp=$this->iDb->select('insee.insee_even',
|
||
|
"LPAD(insSIREN,9,0) AS insSIREN, LPAD(insNIC,5,0) AS insNIC, insL4_VOIE, insL6_POST, LPAD(insRPET,2,0) AS insRPET, insDEPCOMEN,
|
||
|
LPAD(insRPEN,2,0) AS insRPEN, insARRONET, insCTONET, insTCD, LPAD(insZEMET,2,0) AS insZEMET, insDU,
|
||
|
insTU, LPAD(insUU,2,0) AS insUU, insAMINTRET, insAMINTREN, insVMAJ, insVMAJ1, insVMAJ2, insVMAJ3, '' AS insRECME,
|
||
|
'' AS insEAEANT, '' AS insEAEAPET, '' AS insEAESEC1T, '' AS insEAESEC2T, insESAANN AS insEAEANN,
|
||
|
insESAPEN AS insEAEAPEN, insESASEC1N AS insEAESEC1N, insESASEC2N AS insEAESEC2N,
|
||
|
insESASEC3N AS insEAESEC3N, insESASEC4N AS insEAESEC4N, dateInsert AS dateNotice",
|
||
|
"insSIREN=$siren AND insNIC=$nic ORDER BY dateInsert DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
}
|
||
|
|
||
|
return $tabTmp[0];
|
||
|
}
|
||
|
|
||
|
public function infoAdresseDom($adresseNum, $adresseBtq, $adresseVoie, $adresseRue, $adresseComp, $cp, $ville, $active=true)
|
||
|
{
|
||
|
$adresseNum=trim($adresseNum)*1;
|
||
|
$adresseBtq='';//trim($adresseBtq);
|
||
|
$adresseVoie=trim($adresseVoie);
|
||
|
$adresseRue=trim($adresseRue);
|
||
|
$cp=trim($cp);
|
||
|
$ville=trim($ville);
|
||
|
|
||
|
if ($adresseNum=='' && $adresseBtq=='' && $adresseVoie=='' && $adresseRue=='' && $cp=='' && $ville=='')
|
||
|
return false;
|
||
|
|
||
|
$tabAdr=$this->structureVoie($adresseNum.' '.$adresseBtq.' '.$adresseVoie.' '.$adresseRue);
|
||
|
$num=$tabAdr['num']*1;
|
||
|
if ($num==0) return false;
|
||
|
$indRep=trim($tabAdr['indRep']);
|
||
|
$typeVoie=trim($tabAdr['typeVoie']);
|
||
|
$libVoie=trim(substr($tabAdr['libVoie'],-5));
|
||
|
|
||
|
$strAdrActive='';
|
||
|
if ($active) {
|
||
|
$strAdrActive.=" AND (enActif=1 OR etActif=1) AND nbEntrep>30 AND pasEntrepDom=0 AND siren>1000 ";
|
||
|
}
|
||
|
$tabTmp=$this->iDb->select('jo.tabAdrDom',
|
||
|
'id, siren, nic, enActif, etActif, procol, nom, nom2, sigle, enseigne, adrNum, adrBtq, adrTypVoie, adrLibVoie, ville, cp, adrComp, adrDistSp, cj, apen, apet, nbEntrep, dateInsert, dateUpdate',
|
||
|
"adrNum=$num AND adrBtq='$indRep' AND adrTypVoie LIKE '%$typeVoie%' AND adrLibVoie LIKE '%$libVoie%' AND cp=$cp $strAdrActive GROUP BY siren ORDER BY enActif DESC, nbEntrep DESC", false, MYSQL_ASSOC);
|
||
|
if (count($tabTmp)>0) {
|
||
|
return $tabTmp;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne l'adresse normalisé
|
||
|
* @param string $siren
|
||
|
* @param string $nic
|
||
|
* @param string $cedexa (1=>On, 0=>Off)
|
||
|
* @return array
|
||
|
* L1_NOM, L2_NOM2, L3_ADRCOMP, L4_VOIE, L5_DISTSP, L6_POST, L7_PAYS
|
||
|
*/
|
||
|
public function getAdresse($siren, $nic, $cedexa=1)
|
||
|
{
|
||
|
// Table etablissements
|
||
|
$tabIdentite = $this->getIdentiteLight($siren, $nic);
|
||
|
$codeVoie = strtoupper($this->getCodeVoie($tabIdentite['AdresseVoie']));
|
||
|
if ($codeVoie=='') $codeVoie=$tabIdentite['AdresseVoie'];
|
||
|
$tabRet = array(
|
||
|
'L1_NOM' => $tabIdentite['Nom'],
|
||
|
'L2_NOM2' => $tabIdentite['Enseigne'],
|
||
|
'L3_ADRCOMP' => '',
|
||
|
'L4_VOIE' => trim(preg_replace('/ +/',' ',preg_replace('/^0+/','',$tabIdentite['AdresseNum'].' '.
|
||
|
$tabIdentite['AdresseBtq'].' '. $codeVoie.' '. $tabIdentite['AdresseRue']))),
|
||
|
'L5_DISTSP' => $tabIdentite['Adresse2'],
|
||
|
'L6_POST' => $tabIdentite['CP'].' '.$tabIdentite['Ville'],
|
||
|
'L7_PAYS' => '',
|
||
|
);
|
||
|
|
||
|
if (strlen($tabRet['L4_VOIE'])>38) {
|
||
|
$tabRet['L4_VOIE']=trim(preg_replace('/ +/',' ',preg_replace('/^0+/','',
|
||
|
$tabIdentite['AdresseNum'].' '.
|
||
|
$tabIdentite['AdresseBtq'].' '.
|
||
|
$tabIdentite['AdresseVoie'].' '.
|
||
|
$tabIdentite['AdresseRue'])));
|
||
|
}
|
||
|
|
||
|
//Notice 80 - Override $tabRet
|
||
|
$tabNotice = $this->getInfosNotice($siren, $nic);
|
||
|
if ($tabNotice['L6_POST']<>'' && $tabNotice['L6_POST']<>$tabRet['L6_POST']) {
|
||
|
$tabRet['L6_POST'] = $tabNotice['L6_POST'];
|
||
|
}
|
||
|
|
||
|
$tabTmp = $this->iDb->select('insee.identite','NOM2, ADR_COMP, ADR_DISTSP, PAYS',
|
||
|
"SIREN=$siren AND NIC=$nic", false, MYSQL_ASSOC);
|
||
|
$tabIdentite = $tabTmp[0];
|
||
|
if ($tabIdentite['NOM2']<>'' && $tabIdentite['NOM2']<>$tabRet['L2_NOM2']) {
|
||
|
$tabRet['L2_NOM2']=$tabIdentite['NOM2'];
|
||
|
}
|
||
|
if ($tabIdentite['ADR_COMP']<>'' && $tabIdentite['ADR_COMP']<>$tabRet['L3_ADRCOMP']) {
|
||
|
$tabRet['L3_ADRCOMP']=$tabIdentite['ADR_COMP'];
|
||
|
}
|
||
|
if ($tabIdentite['ADR_DISTSP']<>'' && $tabIdentite['ADR_DISTSP']<>$tabRet['L5_DISTSP']) {
|
||
|
$tabRet['L5_DISTSP']=$tabIdentite['ADR_DISTSP'];
|
||
|
}
|
||
|
if ($tabIdentite['PAYS']<>'' && $tabIdentite['PAYS']<>$tabRet['L7_PAYS']) {
|
||
|
$tabRet['L7_PAYS']=$tabIdentite['PAYS'];
|
||
|
}
|
||
|
|
||
|
//Cedexa
|
||
|
if ($cedexa = 1) {
|
||
|
$tabTmp = $this->iDb->select('insee.cedexa','contrat, hexavia, codePostal, l1_nom, l2_nomComp, l3_compGeo, l4_numVoie, l4_indRep, l4_libVoie, l5_distrib, l5_numMS, l5_libCom, l6_codCedex, l6_achCedex, codeInsee, actif, dateFlux, dateInsert, dateUpdate', "siren=$siren AND nic=$nic", false, MYSQL_ASSOC);
|
||
|
if ( count($tabTmp)>0 ) {
|
||
|
$tabCedex = $tabTmp[0];
|
||
|
|
||
|
if ($tabCedex['l2_nomComp']<>'' && $tabCedex['l2_nomComp']<>$tabRet['L2_NOM2']) {
|
||
|
$tabRet['L2_NOM2']=$tabCedex['l2_nomComp'];
|
||
|
}
|
||
|
if ($tabCedex['l3_compGeo']<>'' && $tabCedex['l3_compGeo']<>$tabRet['L3_ADRCOMP']) {
|
||
|
$tabRet['L3_ADRCOMP']=$tabCedex['l3_compGeo'];
|
||
|
}
|
||
|
$l4=trim(preg_replace('/ +/',' ',preg_replace('/^0+/','', $tabCedex['l4_numVoie'].' '.$tabCedex['l4_indRep'].' '.$tabCedex['l4_libVoie'])));
|
||
|
if ($l4<>'' && $l4<>$tabRet['L4_VOIE']) {
|
||
|
$tabRet['L4_VOIE']=$l4;
|
||
|
}
|
||
|
$l5=trim(preg_replace('/ +/',' ', $tabCedex['l5_distrib'].' '.$tabCedex['l5_numMS'].' '.$tabCedex['l5_libCom']));
|
||
|
if ($l5<>'' && $l5<>$tabRet['L5_DISTSP']) {
|
||
|
$tabRet['L5_DISTSP']=$l5;
|
||
|
}
|
||
|
$l6=trim(preg_replace('/ +/',' ', $tabCedex['l6_codCedex'].' '.$tabCedex['l6_achCedex']));
|
||
|
if ($l6<>'' && $l6<>$tabRet['L6_POST']) {
|
||
|
$tabRet['L6_POST']=$l6;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
|
||
|
function getActivite($siren, $nic=0)
|
||
|
{
|
||
|
$tabIdentite=$this->getIdentiteLight($siren, $nic);
|
||
|
// F.Jur
|
||
|
$fj=$tabIdentite['FJ'];
|
||
|
// Naf 5
|
||
|
$naf5en=$tabIdentite['NafEnt'];
|
||
|
$naf5et=$tabIdentite['NafEtab'];
|
||
|
// Naf 4
|
||
|
$naf4en=$naf4et=-1;
|
||
|
$tabNaf4=$this->getNaf4($siren, $nic);
|
||
|
if (isset($tabNaf4['apen4']))
|
||
|
$naf4en=$tabNaf4['apen4'];
|
||
|
if (isset($tabNaf4['apet4']))
|
||
|
$naf4et=$tabNaf4['apet4'];
|
||
|
|
||
|
// Activité Pages Jaunes
|
||
|
$strNic='';
|
||
|
$an8en=$an8et=-1;
|
||
|
if ($nic*1>0) $strNic="AND nic=$nic";
|
||
|
$ret=$this->iDb->select('jo.telephonie',
|
||
|
'infoTel, count(*) AS nb',
|
||
|
"siren=$siren AND typeTel='an8' GROUP BY infoTel ORDER BY nb DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($ret)>0) {
|
||
|
$an8en=$ret[0]['infoTel'];
|
||
|
$ret=$this->iDb->select('jo.telephonie',
|
||
|
'infoTel',
|
||
|
"siren=$siren $strNic AND typeTel='an8' ORDER BY dateProvPartenaire DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
if (count($ret)>0)
|
||
|
$an8et=$ret[0]['infoTel'];
|
||
|
}
|
||
|
|
||
|
// Recherche des activités réglementées possibles Naf4&5 ou An8
|
||
|
$ret=$this->iDb->select('jo.tabActivReg',
|
||
|
'id, libActivite, listeActivite, naf5, naf4, codAn8, listeCJ, nomAutorite',
|
||
|
"naf5='$naf5en' OR naf5='$naf5et' OR naf4='$naf4en' OR
|
||
|
naf4='$naf4et' OR codAn8='$an8en' OR codAn8='$an8et'", false, MYSQL_ASSOC);
|
||
|
foreach ($ret as $iRet=>$tabAct) {
|
||
|
// Filtre 'listeActivite' : Si défini, on recherche la présence de mots dans l'activité
|
||
|
if (trim($tabAct['listeActivite'])<>'') {
|
||
|
$ok=false;
|
||
|
$tabTmp=explode(';',trim($tabAct['listeActivite']));
|
||
|
$tabIdentite=$this->getIdentiteEntreprise($siren, $nic);
|
||
|
foreach ($tabTmp as $strTmp)
|
||
|
if (preg_match("/$strTmp/i", $tabIdentite['Activite'])) $ok=true;
|
||
|
if (!$ok) continue;
|
||
|
}
|
||
|
// Filtre 'listeCJ' : Si défini, on limite aux CJ listées
|
||
|
if (trim($tabAct['listeCJ'])<>'') {
|
||
|
$ok=false;
|
||
|
$tabTmp=explode(';',trim($tabAct['listeCJ']));
|
||
|
foreach ($tabTmp as $strTmp)
|
||
|
if (preg_match("/^$strTmp/", $fj)) $ok=true;
|
||
|
if (!$ok) continue;
|
||
|
}
|
||
|
return array( 'idActivite'=>$tabAct['id'],
|
||
|
'libActivite'=>$tabAct['libActivite'],
|
||
|
'nomAutorite'=>$tabAct['nomAutorite'],
|
||
|
);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public function getCodeNace($naf5)
|
||
|
{
|
||
|
if ($naf5<>'') {
|
||
|
$this->setTabCodesNaf();
|
||
|
return $this->tabCodesNace[$naf5];
|
||
|
}
|
||
|
else
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
public function getEtabClients($refClient, $idClient, $login, $deb=0, $nbRep=20, $maxRep=200)
|
||
|
{
|
||
|
$this->setTabCodesNaf();
|
||
|
$deb=$deb*1;
|
||
|
$nbRep=$nbRep*1;
|
||
|
$limit="LIMIT $deb, $nbRep";
|
||
|
|
||
|
// $strLogin=" AND idClient=$idClient ";
|
||
|
|
||
|
$listeEtab=$this->iDb->select(
|
||
|
'jo.etablissements e, jo.surveillances_site s',
|
||
|
"'Etab' AS Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, e.adr_cp, e.adr_ville, LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep, CONCAT(e.siren, e.nic) AS siret, e.actif",
|
||
|
"s.login='$login' AND s.siren=e.siren AND (s.nic=e.nic OR e.siege=1) AND s.ref='$refClient' ORDER BY e.siege DESC, e.actif DESC $limit", false, MYSQL_ASSOC);
|
||
|
$nbTot=count($listeEtab);
|
||
|
foreach ($listeEtab as $etab) {
|
||
|
$tel=sprintf('%010d', strtr($etab['tel'],array('-'=>'', '/'=>'','.'=>'',','=>'')));
|
||
|
if ($tel<>'0000000000') $tel=implode('.', str_split($tel,2));
|
||
|
else $tel='';
|
||
|
|
||
|
$fax=sprintf('%010d', strtr($etab['fax'],array('-'=>'', '/'=>'','.'=>'',','=>'')));
|
||
|
if ($fax<>'0000000000') $fax=implode('.', str_split($fax,2));
|
||
|
else $fax='';
|
||
|
|
||
|
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
|
||
|
'id'=>$etab['id'],
|
||
|
'Pertinence'=>100,
|
||
|
'Siret'=>$etab['siret'],
|
||
|
'Siege'=>$etab['siege'],
|
||
|
'Nom'=>$etab['raisonSociale'],
|
||
|
'Sigle'=>$etab['sigle'],
|
||
|
'Enseigne'=>$etab['enseigne'],
|
||
|
'Adresse'=>trim(preg_replace('/ +/', ' ', trim( $etab['adr_num'] .' '. $etab['adr_btq'] .' '.
|
||
|
$etab['adr_typeVoie'] .' '. $etab['adr_libVoie']))),
|
||
|
'Adresse2'=>trim(preg_replace('/ +/', ' ', $etab['adr_comp'])),
|
||
|
'CP'=>$etab['adr_cp'],
|
||
|
'Ville'=>$etab['adr_ville'],
|
||
|
'Tel'=>$tel,
|
||
|
'Fax'=>$fax,
|
||
|
'FJ'=>$etab['cj'],
|
||
|
'FJLib'=>$this->getLibelleFJ($etab['cj']),
|
||
|
'Siren'=>$etab['siren'],
|
||
|
'Nic'=>$etab['nic'],
|
||
|
'Actif'=>$etab['actif'],
|
||
|
'NafEtab'=>$etab['ape_etab'], // Etablissement
|
||
|
'NafEnt'=>$etab['ape_entrep'], // Entreprise
|
||
|
'NafEtabLib'=>$this->getLibelleNaf($etab['ape_etab']),
|
||
|
'NafEntLib' =>$this->getLibelleNaf($etab['ape_entrep']),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
if ($dep==0) $dep=''; // Evite l'affichage d'un 0 inutile sur l'Extranet
|
||
|
|
||
|
return array( 'criteres'=>array('siren'=>$siren, 'nic'=>$nic, 'dep'=>$dep),
|
||
|
'nbReponses'=>count($tabRet),
|
||
|
'nbReponsesTotal'=>$nbTot,
|
||
|
'reponses'=>$tabRet);
|
||
|
}
|
||
|
|
||
|
public function getAvisInsee($siren, $nic='')
|
||
|
{
|
||
|
if ($siren*1==0 || !$this->valideSiren($siren, $nic)) return false;
|
||
|
if ($nic=='' || $nic*1==0 || $nic>99999)
|
||
|
$strNic=" AND nic=nicSiege";
|
||
|
else $strNic=" AND nic=$nic";
|
||
|
$tabTmp=$this->iDb->select('insee.insee_avis',
|
||
|
'raiSoc, dateMaj, siren, nic, etatEt, dateEtatEt, typeEtab, adresseEt0, adresseEt1, adresseEt2, adresseEt3, fj, fjLib, nafEt, nafEtLib, effEtPeriode, effEtTr, erreurs, adresseEn0, adresseEn1, adresseEn2, adresseEn3, nafEn, nafEnLib, effEnPeriode, effEnTr, fjEn, fjEnLib, employes, etatEn, dateEtatEn, nicSiege, nbEtabActifs, dateInsert, dateUpdate, DATE(IF(dateUpdate>dateInsert, dateUpdate, dateInsert))*1 AS dateMajSD',
|
||
|
"siren=$siren $strNic", false, MYSQL_ASSOC);
|
||
|
$tabInfos=@$tabTmp[0];
|
||
|
if ($tabInfos['dateMajSD']==date('Ymd')) {
|
||
|
$tabInfos['enCache']=true;
|
||
|
return $tabInfos;
|
||
|
}
|
||
|
|
||
|
/** Initialisation de la session sur le site de l'Insee **/
|
||
|
$url = 'http://avis-situation-sirene.insee.fr/avisitu/jsp/avis.jsp';
|
||
|
$referer = $cookie = '';
|
||
|
$page = getUrl($url, $cookie, '', $referer, false, 'avis-situation-sirene.insee.fr', '', 5);
|
||
|
//Code en 4xx ou 5xx signifie une erreur du serveur
|
||
|
$codeN = floor($page['code']/100);
|
||
|
if($codeN==4 || $codeN==5) {
|
||
|
return false;
|
||
|
}
|
||
|
else {
|
||
|
$tabInfos=array();
|
||
|
$referer = $url;
|
||
|
$body = $page['body'];
|
||
|
$serviceDispo = true;
|
||
|
|
||
|
if (preg_match("/<form name=\"demForm\" method=\"post\" action=\"\/avisitu\/IdentificationListeSiret.do/Uis", $body, $matches)) {
|
||
|
$cookie = $page['header']['Set-Cookie'];
|
||
|
usleep(round(rand(500000,2000000)));
|
||
|
|
||
|
$dep=$depActif='';
|
||
|
if ($nic=='') $crit='S'; // l'établissement siège
|
||
|
else $crit=''; // établissement particulier, saisissez le NIC
|
||
|
/* $crit='T'; // tous les établissements de l'entreprise
|
||
|
$crit='T'; // tous les établissements de l'entreprise du département $dep
|
||
|
$crit='A'; // tous les établissements actifs de l'entreprise
|
||
|
$crit='A'; // tous les établissements actifs de l'entreprise du département $depActif
|
||
|
*/
|
||
|
//Post du formulaire
|
||
|
$url = 'http://avis-situation-sirene.insee.fr/avisitu/IdentificationListeSiret.do';
|
||
|
//$url='http://avis-situation-sirene.insee.fr/avisituV2/IdentificationDetailEtab.do';
|
||
|
$post = array(
|
||
|
'siren' => $siren,
|
||
|
'critere' => $crit, // S pour le siège ou vide avec un NIC !!!
|
||
|
'nic' => $nic,
|
||
|
'departement' => $dep,
|
||
|
'departement_actif' => $depActif,
|
||
|
'bSubmit' => 'Valider');
|
||
|
$page = getUrl($url, $cookie, $post, $referer, false, 'avis-situation-sirene.insee.fr', '', 5);
|
||
|
$referer=$url;
|
||
|
$body = $page['body'];
|
||
|
|
||
|
if (preg_match("/<h3>Fiche établissement<\/h3>/Uis", $body, $matches))//<li class="ongletActif">établissement</li>
|
||
|
$tabInfos['fiche']='etab';
|
||
|
|
||
|
if (preg_match('/<div class="TitreGauche">(.*)<br\/>/Uis', $body, $matches)) {
|
||
|
$tabInfos['raiSoc']=str_replace(''',"'",trim($matches[1]));
|
||
|
}
|
||
|
|
||
|
if (preg_match("/Dernière mise à jour : (.*)<\/div>/Uis", $body, $matches))
|
||
|
$tabInfos['dateMaj']=Metier_Util_Date::dateT('d/m/Y','Y-m-d',trim($matches[1]));
|
||
|
|
||
|
$s1=substr($siren,0,3);
|
||
|
$s2=substr($siren,3,3);
|
||
|
$s3=substr($siren,6,3);
|
||
|
if (preg_match('/<div class="TitreDroite">(?:.*)('.$s1.'(?:.*)'.$s2.'(?:.*)'.$s3.')(?:.*)(\d\d\d\d\d)(?:.*)<\/div>/Uis', $body, $matches)) {
|
||
|
$tabInfos['siren'] = trim(str_replace(' ','',$matches[1]));
|
||
|
$tabInfos['nic'] = trim($matches[2]);
|
||
|
if ($nic=='') $nic=$tabInfos['nic'];
|
||
|
} else
|
||
|
$tabInfos['siren']=$siren;
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Etat : <\/label>(.*)depuis le(.*)<\/p>/Uis', $body, $matches)) {
|
||
|
$tabInfos['etatEt'] = trim($matches[1]);
|
||
|
$tabInfos['dateEtatEt']=Metier_Util_Date::dateT('d/m/Y','Y-m-d',trim($matches[2]));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Catégorie d\'établissement : <\/label>(.*)<\/p>/Uis', $body, $matches)) {
|
||
|
$tabInfos['typeEtab']= trim($matches[1]);
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Adresse d\'implantation \: <\/label>(?:.*)<ul id="adresse">(.*)<\/ul>/Uis', $body, $matches)) {
|
||
|
$strTmp=trim($matches[1]);
|
||
|
$tabTmp=explode('</li>', $strTmp);
|
||
|
foreach ($tabTmp as $i=>$strTmp)
|
||
|
$tabInfos['adresseEt'][$i]=trim(str_replace('<li>','',$strTmp));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/gorie juridique \:(?:.*)<\/label>(.*) -(.*)<\/p>/Uis', $body, $matches)) {
|
||
|
$tabInfos['fj']= trim($matches[1]);
|
||
|
$tabInfos['fjLib']= trim($matches[2]);
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Activité principale exercée \:(?:.*)<\/label>(.*) -(.*)<\/p>/Uisu', $body, $matches)) {
|
||
|
$tabInfos['nafEt']=trim($matches[1]);
|
||
|
$tabInfos['nafEtLib']=str_replace(''',"'",trim($matches[2]));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">(?:.*)Tranche d'effectif(.*)<\/label>(.*)<\/p>/Uis', $body, $matches)) {
|
||
|
$tabInfos['effEtPeriode']=trim($matches[1]);
|
||
|
$tabInfos['effEtTr']=trim($matches[2]);
|
||
|
}
|
||
|
|
||
|
// $body contient l'avis de situation au format html
|
||
|
$tabErreurs=array();
|
||
|
if (preg_match('/name="erreurs" value="(.*)" class="erreurText" readonly/Ui', $body, $matches1) ||
|
||
|
preg_match('/name="erreurs_bis" value="(.*)" class="erreurTextBis" readonly/Ui', $body, $matches2)) {
|
||
|
$tabErreurs[]=@$matches1[1];
|
||
|
$tabErreurs[]=@$matches2[1];
|
||
|
//die('<font color="red">ERREUR '.utf8_encode(implode(' ', $tabErreurs)).'</font>'); // Gérer le retour d'une erreur
|
||
|
}
|
||
|
$tabInfos['erreurs']=implode('/',$tabErreurs);
|
||
|
|
||
|
//$tabInfos['debugEtab']=$body;
|
||
|
usleep(round(rand(500000,1000000)));
|
||
|
|
||
|
$url="http://avis-situation-sirene.insee.fr/avisitu/IdentificationEtabToEntr.do?nic=$nic&siren=$siren";
|
||
|
$page = getUrl($url, $cookie, '', $referer, false, 'avis-situation-sirene.insee.fr', '', 5);
|
||
|
$body = $page['body'];
|
||
|
//$tabInfos['debugEntrep']=$body;
|
||
|
if (preg_match('/<label id="labelFiche">Adresse d\'implantation \: <\/label>(?:.*)<ul id="adresse">(.*)<\/ul>/Uis', $body, $matches)) {
|
||
|
$strTmp=trim($matches[1]);
|
||
|
$tabTmp=explode('</li>', $strTmp);
|
||
|
foreach ($tabTmp as $i=>$strTmp)
|
||
|
$tabInfos['adresseEn'][$i]=trim(str_replace('<li>','',$strTmp));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Activité principale exercée \:(?:.*)<div id="adresse">(.*) -(.*)<\/div>/Uisu', $body, $matches)) {
|
||
|
$tabInfos['nafEn']=trim($matches[1]);
|
||
|
$tabInfos['nafEnLib']=str_replace(''',"'",trim($matches[2]));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">(?:.*)Tranche d'effectif(.*)<\/label>(?:.*)<div id="adresse">(.*)<\/div>/Uis', $body, $matches)) {
|
||
|
$tabInfos['effEnPeriode']=trim($matches[1]);
|
||
|
$tabInfos['effEnTr']=trim($matches[2]);
|
||
|
}
|
||
|
|
||
|
if (preg_match('/gorie juridique \:(?:.*)<div id="adresse">(.*) -(.*)<\/div>/Uis', $body, $matches)) {
|
||
|
$tabInfos['fjEn']= trim($matches[1]);
|
||
|
$tabInfos['fjEnLib']= str_replace(''',"'",trim($matches[2]));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Entreprise employeuse \:(?:.*)<div id="adresse">(.*)<\/div>/Uis', $body, $matches)) {
|
||
|
$tabInfos['employes']= trim($matches[1]);
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Etat : <\/label>(?:.*)<div id="adresse">(.*) le (.*)<\/div>/Uis', $body, $matches)) {
|
||
|
$tabInfos['etatEn'] = str_replace(''',"'",trim($matches[1]));
|
||
|
$tabInfos['dateEtatEn']=Metier_Util_Date::dateT('d/m/Y','Y-m-d',trim($matches[2]));
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">NIC siège \:(?:.*)<div id="adresse">(.*)<\/div>/Uisu', $body, $matches)) {
|
||
|
$tabInfos['nicSiege']= trim($matches[1]);
|
||
|
}
|
||
|
|
||
|
if (preg_match('/<label id="labelFiche">Nb d\'établissements actifs \:(?:.*)<div id="adresse">(.*)<\/div>/Uisu', $body, $matches)) {
|
||
|
$tabInfos['nbEtabActifs']= trim($matches[1]);
|
||
|
}
|
||
|
$tabInfos2=array();
|
||
|
for($i=0; $i<5; $i++) {
|
||
|
$tabInfos2['adresseEt'.$i]=str_replace(''',"'",$tabInfos['adresseEt'][$i]);
|
||
|
$tabInfos2['adresseEn'.$i]=str_replace(''',"'",$tabInfos['adresseEn'][$i]);
|
||
|
}
|
||
|
unset($tabInfos['fiche']);
|
||
|
unset($tabInfos['adresseEt']);
|
||
|
unset($tabInfos['adresseEn']);
|
||
|
|
||
|
$tabInsert=array_merge($tabInfos,$tabInfos2);
|
||
|
$tabInsert['dateInsert']=date('YmdHis');
|
||
|
$this->iDb->insert('insee.insee_avis', $tabInsert, true);
|
||
|
|
||
|
if (preg_match("/droit d'opposition/", $tabInsert['erreurs'])) {
|
||
|
$this->iDb->insert('insee.insee_nondiff', array('siren'=>$siren,
|
||
|
'dateInsert'=>date('YmdHis')));
|
||
|
}
|
||
|
$tabInfos['enCache']=false;
|
||
|
}
|
||
|
else {
|
||
|
return false;
|
||
|
}
|
||
|
return $tabInfos;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public function listeProduits($naf)
|
||
|
{
|
||
|
$tabRet=array();
|
||
|
$ret=$this->iDb->select('insee.tabCpf', 'codCpf, libCpf',
|
||
|
"codCpf IN (SELECT cpf FROM insee.tabNafCpf WHERE naf='$naf')", false, MYSQL_ASSOC);
|
||
|
foreach ($ret as $iRet=>$tabCpf) {
|
||
|
$tabRet[$tabCpf['codCpf']]=$tabCpf['libCpf'];
|
||
|
}
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/** Retourne l'identifiant de l'Organisme de protection sociale compétent
|
||
|
**
|
||
|
** @param string $naf5 Code Naf de l'entreprise
|
||
|
** @param integer $codeCommune Code commune de l'entreprise
|
||
|
** @param integer $fj Forme juridique de l'entreprise
|
||
|
** @param date $dateCreation Date de création de l'entreprise
|
||
|
** @param integer $activiteReelle Activité réelle de l'entreprise
|
||
|
** @return
|
||
|
*/
|
||
|
public function getOPS($naf5, $codeCommune, $fj, $dateCreation, $activiteReelle='') {
|
||
|
/*
|
||
|
* 1. Vérifier si le NAF est dans la table sdv1.retraiteNaf (répertoire professionnel)
|
||
|
* 1.1. Si présent,
|
||
|
*
|
||
|
*/
|
||
|
$tabRet=array();
|
||
|
$naf4=substr($naf5,0,4);
|
||
|
$dep=substr($codeCommune,0,2);
|
||
|
if ($dep=='2A' || $dep=='2B') $dep=20;
|
||
|
else $dep=$dep*1;
|
||
|
if ($dep>96) $dep=substr($codeCommune,0,3)*1;
|
||
|
// Recherche par NAF
|
||
|
$ret=$this->iDb->select('sdv1.retraiteNaf',
|
||
|
'codeOPS, libInstitution, codeAnnexe, Limitations',
|
||
|
"naf5='$naf5' or naf5='$naf4'", false, MYSQL_ASSOC);
|
||
|
//print_r($ret);
|
||
|
//die();
|
||
|
if (count($ret)>0) {
|
||
|
$tabRet=array('competenceType'=>'professionnel');
|
||
|
foreach ($ret as $iRet=>$tabCaisses) {
|
||
|
if (count($ret)==1) {
|
||
|
$limite=$tabCaisses['Limitations'];
|
||
|
if ($tabCaisses['codeOPS']<>null) {
|
||
|
//echo "Cas 1 : NAF $naf5 unique, annexe ".$tabCaisses['codeAnnexe']." - ".$tabCaisses['libInstitution']." (".$tabCaisses['Limitations'].")".PHP_EOL;
|
||
|
//print_r($this->getInfoOPS($tabCaisses['codeOPS']));
|
||
|
return $tabCaisses['codeOPS'];
|
||
|
} elseif ($tabCaisses['Annexe']<>'') {
|
||
|
$annexe=$tabCaisses['Annexe'];
|
||
|
//echo "Cas 2 : NAF $naf5, Annexe $annexe".PHP_EOL;
|
||
|
//print_r($this->getInfoOPS($idOPS));
|
||
|
break;
|
||
|
}
|
||
|
} else {
|
||
|
echo "Cas 3.1 : Non géré $naf5 !".PHP_EOL;
|
||
|
//print_r($this->getInfoOPS($idOPS));
|
||
|
print_r($tabCaisses);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Recherche par Département
|
||
|
$ret=$this->iDb->select('sdv1.retraiteDep',
|
||
|
'codeOPS, libInstitution',
|
||
|
"codeDep=$dep AND codeAnnexe IN ('$annexe','A','B') GROUP BY codeAnnexe ASC", false, MYSQL_ASSOC);
|
||
|
if (count($ret)>0) {
|
||
|
$tabRet=array('competenceType'=>'interprofessionnel');
|
||
|
foreach ($ret as $iRet=>$tabCaisses) {
|
||
|
//if (count($ret)==1) {
|
||
|
if ($tabCaisses['codeOPS']<>'') {
|
||
|
// echo "Cas 2.1 : NAF $naf5, Annexe $annexe".PHP_EOL;
|
||
|
//echo "Cas 2.1 : NAF $naf5, annexe ".$tabCaisses['codeAnnexe']." - ".$tabCaisses['libInstitution']." (".$tabCaisses['Limitations'].")".PHP_EOL;
|
||
|
//print_r($this->getInfoOPS($tabCaisses['codeOPS']));
|
||
|
return $tabCaisses['codeOPS'];
|
||
|
} else {
|
||
|
//echo "Cas 2.2 : Non géré $naf5".PHP_EOL;
|
||
|
//print_r($tabCaisses);
|
||
|
}
|
||
|
/*} else {
|
||
|
echo "Cas 3.2 : Non géré $naf5".PHP_EOL;
|
||
|
print_r($tabCaisses);
|
||
|
}*/
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public function getInfoOPS($idOPS)
|
||
|
{
|
||
|
$tabRet=array();
|
||
|
$ret=$this->iDb->select('sdv1.retraiteCaisses',
|
||
|
'siren,nic,codeOPS,nomLong,nomCourt,adresse1,adresse2,cp,ville,groupe,declaration,rattachement,codeOPSdest',
|
||
|
"codeOPS='$idOPS'", false, MYSQL_ASSOC);
|
||
|
return @$ret[0];
|
||
|
}
|
||
|
|
||
|
/** Retourne la date de changement de statut de siège à établissment secondaire pour un établissement donné
|
||
|
**
|
||
|
** @param integer $siren Siren de l'entreprise
|
||
|
** @param integer $nic Nic de l'étabissement
|
||
|
** @return date Date de changement d'état
|
||
|
*/
|
||
|
public function isAncienSiege($siren, $nic)
|
||
|
{
|
||
|
$tabRet=array();
|
||
|
$ret=$this->iDb->select('insee.insee_even',
|
||
|
'insSIREN, insNIC, insDATEVE, insEVE, insAPET700, insSIEGE, insLIBCOM, insL1_NOMEN, insL2_COMP, insL4_VOIE, insL3_CADR, insL5_DISP, insL6_POST, insCODPOS, insL7_ETRG, insDEPCOM, insCODEVOIE, insNICTRAN, insSIRETPS, insDATEMAJ, idFlux, insSIRETASS, insEVE, insDESTINAT, insTYPETAB, insORIGINE',
|
||
|
"insSIREN=$siren AND insNIC=$nic AND insMNICSIEGE=1 ORDER BY insDATEVE DESC LIMIT 0,1", false, MYSQL_ASSOC);
|
||
|
return $ret[0]['insDATEVE'];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Recherche les siret associés à un siret (successeur et/ou prédécesseur)
|
||
|
* @param int $siren
|
||
|
* Siren de l'entreprise
|
||
|
* @param int $nic
|
||
|
* Nic de l'étabissement
|
||
|
* @param int $lien
|
||
|
* Type de lien (-1=prédécesseur, 0=prédécesseur et/ou successeur, 1=successeur)
|
||
|
*/
|
||
|
public function getSiretAssoc($siren, $nic, $lien=0)
|
||
|
{
|
||
|
$tabRet = array();
|
||
|
$ret = $this->iDb->select('insee.insee_even',
|
||
|
'LPAD(insSIREN,9,0) AS insSIREN, LPAD(insNIC,5,0) AS insNIC, insDATEVE, insEVE, insAPET700, insSIEGE, insLIBCOM, insL1_NOMEN, insL2_COMP, insL4_VOIE, insL3_CADR, insL5_DISP, insL6_POST, insCODPOS, insL7_ETRG, insDEPCOM, insCODEVOIE, insNICTRAN, insSIRETPS, insDATEMAJ, idFlux, insSIRETASS, insDESTINAT, insTYPETAB, insORIGINE, insTRAN, insNOMEN, insENSEIGNE, insNUMVOIE, insINDREP, insTYPVOIE, insLIBVOIE, sirVersion',
|
||
|
"insSIREN=$siren AND insNIC<>$nic AND (insEVE IN ('510','520','530','540', 'CTS','CTE','STS','STE','MTDS','MTDE','MTAS','MTAE') OR insEVE LIKE 'T%') AND insDATEMAJ IN (
|
||
|
SELECT insDATEMAJ FROM insee.insee_even WHERE insSIREN=$siren AND insNIC=$nic AND (insEVE IN ('510','520','530','540', 'CTS','CTE','STS','STE','MTDS','MTDE','MTAS','MTAE') OR insEVE LIKE 'T%')
|
||
|
)", false, MYSQL_ASSOC);
|
||
|
|
||
|
$datePre = $dateSuc = 0;
|
||
|
$nicPre = $nicSuc = 0;
|
||
|
|
||
|
if (count($ret) > 0) {
|
||
|
foreach ($ret as $iRet=>$tabEve) {
|
||
|
if ($tabEve['sirVersion'] == 4) {
|
||
|
if (in_array($tabEve['insEVE'], array('CTE','CTS','MTAE','MTAS'))) {
|
||
|
$typeLien = 'suc';
|
||
|
}
|
||
|
elseif (in_array($tabEve['insEVE'], array('STE','STS','MTDE','MTDS'))) {
|
||
|
$typeLien = 'pre';
|
||
|
}
|
||
|
else {
|
||
|
$typeLien = 'ind';
|
||
|
}
|
||
|
} else {
|
||
|
switch($tabEve['insTYPETAB']*1) {
|
||
|
case 8:
|
||
|
case 10:
|
||
|
case 20:
|
||
|
case 30:
|
||
|
if ($lien == 1) continue;
|
||
|
$typeLien = 'pre';
|
||
|
break;
|
||
|
case 9:
|
||
|
case 11:
|
||
|
case 21:
|
||
|
case 31:
|
||
|
if ($lien == -1) continue;
|
||
|
$typeLien = 'suc';
|
||
|
break;
|
||
|
default:
|
||
|
switch($tabEve['insTRAN']) {
|
||
|
case 'D': if ($lien == 1) continue; $typeLien='pre'; break(2);
|
||
|
case 'A': if ($lien == -1) continue; $typeLien='suc'; break(2);
|
||
|
default : if ($lien != 0) continue; $typeLien='ind'; break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Le NIC prédécesseur ne peut pas être le NIC actuel
|
||
|
if ($nicPre > 0 && $nicPre == $tabEve['insNIC']) {
|
||
|
continue;
|
||
|
}
|
||
|
// Le NIC successeur ne peut pas être le NIC actuel
|
||
|
if ($nicSuc > 0 && $nicSuc == $tabEve['insNIC']) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
// L'évènement successeur ne peut pas être antérieur au prédécesseur
|
||
|
if ($dateSuc > 0 && $datePre > 0 && $dateSuc < $datePre) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
// Predecesseur et Successeur en mémoire
|
||
|
if ($typeLien == 'pre') {
|
||
|
$datePre = $tabEve['insDATEVE'];
|
||
|
$nicPre = $tabEve['insNIC'];
|
||
|
}
|
||
|
if ($typeLien == 'suc') {
|
||
|
$dateSuc = $tabEve['insDATEVE'];
|
||
|
$nicSuc = $tabEve['insNIC'];
|
||
|
}
|
||
|
|
||
|
// Data
|
||
|
$adr1 = $tabEve['insL1_NOMEN'];
|
||
|
if ($adr1 == null) {
|
||
|
$adr1=$tabEve['insNOMEN'];
|
||
|
}
|
||
|
$adr2 = $tabEve['insL2_COMP'];
|
||
|
if ($adr2 == null) {
|
||
|
$adr2=$tabEve['insENSEIGNE'];
|
||
|
}
|
||
|
$adr4 = $tabEve['insL4_VOIE'];
|
||
|
if ($adr4 == null) {
|
||
|
$adr4 = preg_replace('/ +/',' ', $tabEve['insNUMVOIE'].' '.$tabEve['insINDREP'].' '.
|
||
|
$tabEve['insTYPVOIE'].' '.$tabEve['insLIBVOIE']);
|
||
|
}
|
||
|
|
||
|
$tabRet[$typeLien] = array(
|
||
|
'siren' => $tabEve['insSIREN'],
|
||
|
'nic' => $tabEve['insNIC'],
|
||
|
'apeEtab' => $tabEve['insAPET700'],
|
||
|
'codeEve' => $tabEve['insEVE'],
|
||
|
'dateEve' => $tabEve['insDATEVE'],
|
||
|
'adrL1' => trim($adr1),
|
||
|
'adrL2' => trim($adr2),
|
||
|
'adrL3' => trim($tabEve['insL3_CADR']),
|
||
|
'adrL4' => trim($adr4),
|
||
|
'adrL5' => trim($tabEve['insL5_DISP']),
|
||
|
'adrL6' => trim($tabEve['insL6_POST']),
|
||
|
'adrL7' => trim($tabEve['insL7_ETRG']),
|
||
|
'depCom' => $tabEve['insDEPCOM'],
|
||
|
'rivoli' => $tabEve['insCODEVOIE'],
|
||
|
'siege' => $tabEve['insSIEGE'],
|
||
|
'destinat' => $tabEve['insDESTINAT'],
|
||
|
'typEtab' => $tabEve['insTYPETAB'],
|
||
|
'origine' => $tabEve['insORIGINE'],
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
public function getInfoSirene($dept, $siren, $apen=false)
|
||
|
{
|
||
|
$strAdr1Comp=$tel='';
|
||
|
if ($siren>=100000000 && $siren<300000000){
|
||
|
$dept=18;
|
||
|
$strAdr1Comp=', Pôle Secteur Public';
|
||
|
} else {
|
||
|
if (!$apen) {
|
||
|
$tabId=$this->getIdentiteLight($siren);
|
||
|
$apen=$tabId['NafEnt'];
|
||
|
$strAdr1Comp=', Pôle Agricole';
|
||
|
}
|
||
|
$apen2=''.substr($apen,0,2);
|
||
|
if ($apen2=='01' || $apen2=='02') {
|
||
|
$dept=59; //
|
||
|
$tel='03.20.62.86.45';
|
||
|
}
|
||
|
}
|
||
|
$ret=$this->iDb->select('insee.insee_drsiren', 'siret,nom,adr1,adr2,adr3,cp,ville,tel,fax',
|
||
|
"dept='$dept'", false, MYSQL_ASSOC);
|
||
|
$ret=$ret[0];
|
||
|
if ($tel=='') $tel=$ret['tel'];
|
||
|
return array('siret'=>$ret['siret'],
|
||
|
'nom'=>$ret['nom'],
|
||
|
'adr1'=>$ret['adr1'].$strAdr1Comp,
|
||
|
'adr2'=>$ret['adr2'],
|
||
|
'adr3'=>$ret['adr3'],
|
||
|
'cp'=>$ret['cp'],
|
||
|
'ville'=>$ret['ville'],
|
||
|
'standard'=>'09.72.72.6000',
|
||
|
'tel'=>$tel,
|
||
|
'fax'=>$ret['fax']);
|
||
|
}
|
||
|
|
||
|
|
||
|
public function getInfosIris($codeCommune, $codeRivoli, $adrNum, $adrIndRep, $adrTypVoie, $adrLibVoie)
|
||
|
{
|
||
|
$tabTypeIris=array('A'=>'IRIS d\'activité', 'H'=>'IRIS d\'habitat', 'D'=>'IRIS divers (grande zone peu habité dont parcs, ports, forêts, ...)', 'Z'=>'Commune non découpée en IRIS');
|
||
|
$tabRet=$ret2=array();
|
||
|
if (trim($codeRivoli)=='') {
|
||
|
$adrLibVoie2=addslashes($adrLibVoie);
|
||
|
$ret=$this->iDb->select('insee.iris', 'codeInsee, codeIris, rivoli, typVoie, libVoie, typeNum, numd,indd, numf, indf, codeInseeIris',
|
||
|
"codeInsee='$codeCommune' AND libVoie LIKE '$adrLibVoie2%' GROUP BY codeInsee, rivoli", false, MYSQL_ASSOC);
|
||
|
if (count($ret)==1)
|
||
|
$codeRivoli=$ret[0]['rivoli'];
|
||
|
elseif (count($ret)>1 && $adrLibVoie<>'') {
|
||
|
foreach ($ret as $retTmp) {
|
||
|
if ($retTmp['typVoie']==strtoupper($adrTypVoie)) {
|
||
|
$codeRivoli=$retTmp['rivoli'];
|
||
|
$trouve=true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
} else
|
||
|
return $tabRet;
|
||
|
}
|
||
|
$ret=$this->iDb->select('insee.iris', 'codeInsee, codeIris, rivoli, codeInseeIris',
|
||
|
"codeInsee='$codeCommune' AND rivoli LIKE '$codeRivoli%' GROUP BY codeInseeIris", false, MYSQL_ASSOC);
|
||
|
$adrNum=preg_replace('/^0/','',$adrNum)*1;
|
||
|
$strAdr='';
|
||
|
if (count($ret)>1) {
|
||
|
if($adrNum>0 && $adrNum&1) {
|
||
|
// Numéro impaire
|
||
|
$strAdr=" AND typeNum=1 AND $adrNum BETWEEN numd AND numf ";
|
||
|
} elseif($adrNum>=0) {
|
||
|
// Numéro paire
|
||
|
$strAdr=" AND typeNum=2 AND $adrNum BETWEEN numd AND numf ";
|
||
|
}
|
||
|
$ret=$this->iDb->select('insee.iris', 'codeInsee, codeIris, rivoli, codeInseeIris, numd,indd, numf, indf',
|
||
|
"codeInsee='$codeCommune' AND rivoli LIKE '$codeRivoli%' $strAdr GROUP BY codeInseeIris", false, MYSQL_ASSOC);
|
||
|
if (count($ret)>1 && $codeRivoli<>'') {
|
||
|
/** Attention, dans cette logique, le Bis fonctionne mais le Quater passe avant le Ter alors que
|
||
|
2 bis
|
||
|
3 ter
|
||
|
4 quater
|
||
|
mais il peut aussi s'agir de suites A, B, C, D, etc...
|
||
|
**/
|
||
|
$numAdrRep=$adrNum+ord(strtoupper($adrIndRep))/100;
|
||
|
foreach ($ret as $i=>$tabIris) {
|
||
|
$numIrisDeb=$tabIris['numd']+ord(strtoupper($tabIris['indd']))/100;
|
||
|
$numIrisFin=$tabIris['numf']+ord(strtoupper($tabIris['indf']))/100;
|
||
|
if ($adrNum==$tabIris['numd'] && $numAdrRep>=$numIrisDeb) {
|
||
|
// Le numéro de la rue correspond au début de la tranche des numéros IRIS
|
||
|
$ret2=array(0=>$tabIris);
|
||
|
break;
|
||
|
}
|
||
|
elseif ($adrNum==$tabIris['numf'] && $numAdrRep<=$numIrisFin) {
|
||
|
// Le numéro de la rue correspond à la fin de la tranche des numéros IRIS
|
||
|
$ret2=array(0=>$tabIris);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (count($ret2)<>1) {
|
||
|
|
||
|
} else {
|
||
|
$ret=$ret2;
|
||
|
}
|
||
|
}
|
||
|
} /*elseif ($codeRivoli<>'') {
|
||
|
|
||
|
}*/
|
||
|
if (count($ret)<2 || $codeRivoli=='') {
|
||
|
$codeIris=@$ret[0]['codeIris'];
|
||
|
$codeComIris=@$ret[0]['codeInseeIris'];
|
||
|
$ret=$this->iDb->select('insee.insee_tabIris', 'CODE_IRIS AS codeInseeIris, SUBSTRING(CODE_IRIS,6,4) AS codeIris, LIB_IRIS, TYP_IRIS, MODIF_IRIS, TRIRIS, GRD_QUART',
|
||
|
"DEPCOM='$codeCommune' AND (TYP_IRIS='Z' OR CODE_IRIS='$codeComIris')", false, MYSQL_ASSOC);
|
||
|
$tabRet=array('codIris'=>$ret[0]['codeIris'],
|
||
|
'codComIris'=>$ret[0]['codeInseeIris'],
|
||
|
'libIris'=>$ret[0]['LIB_IRIS'],
|
||
|
'typIris'=>$tabTypeIris[$ret[0]['TYP_IRIS']],
|
||
|
'evoIris'=>$ret[0]['MODIF_IRIS'],
|
||
|
'trIris'=>$ret[0]['TRIRIS'],
|
||
|
'grdQuartier'=>$ret[0]['GRD_QUART'],
|
||
|
'rivoli'=>$codeRivoli,
|
||
|
);
|
||
|
} else {
|
||
|
//typVoie, libVoie, rivoli, typeNum 1:chiffres impaires, 2:chiffres paires
|
||
|
//numd, indd, numf, indf
|
||
|
}
|
||
|
return $tabRet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Donne la tranche de CA à partir du CA réel
|
||
|
* @param double $montantCA Chiffre d'affaires réel ou estimé
|
||
|
* @return integer Tranche de CA
|
||
|
*/
|
||
|
public function getTca($montantCA)
|
||
|
{
|
||
|
$montantCA=$montantCA*1;
|
||
|
if ($montantCA>=200000000) // 9 : 200 millions d'euros ou plus)
|
||
|
return 9;
|
||
|
elseif ($montantCA>=100000000) // 8 : De 100 millions à moins de 200 millions d'euros
|
||
|
return 8;
|
||
|
elseif ($montantCA>= 50000000) // 7 : De 50 millions à moins de 100 millions d'euros
|
||
|
return 7;
|
||
|
elseif ($montantCA>= 20000000) // 6 : De 20 millions à moins de 50 millions d'euros
|
||
|
return 6;
|
||
|
elseif ($montantCA>= 10000000) // 5 : De 10 millions à moins de 20 millions d'euros
|
||
|
return 5;
|
||
|
elseif ($montantCA>= 5000000) // 4 : De 5 millions à moins de 10 millions d'euros
|
||
|
return 4;
|
||
|
elseif ($montantCA>= 2000000) // 3 : De 2 millions à moins de 5 millions d'euros
|
||
|
return 3;
|
||
|
elseif ($montantCA>= 1000000) // 2 : De 1 million à moins de 2 millions d'euros
|
||
|
return 2;
|
||
|
elseif ($montantCA>= 500000) // 1 : De 0,5 à moins de 1 million d'euros
|
||
|
return 1;
|
||
|
else
|
||
|
return 0; // Non renseignée ou moins de 0,5 million d'euros
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* CA Moyen par salarié pour un secteur donné
|
||
|
* @param string $naf
|
||
|
* Naf de l'entreprise
|
||
|
* @param integer $effectif
|
||
|
* Effectif de l'entreprise
|
||
|
* @return int
|
||
|
*/
|
||
|
public function getCAnafEffectif($naf, $effectif=0)
|
||
|
{
|
||
|
$tabTmp=$this->iDb->select('jo.ratios_secteurs', 'id, naf5, annee, SUM(montant), SUM(nombre), SUM(montant)/SUM(nombre) AS moyenne', "naf5='$naf' AND id=267 AND ANNEE>(SELECT MAX(annee) FROM jo.ratios_secteurs WHERE naf5='$naf' AND id=267)-2 GROUP BY id, naf5", false, MYSQL_ASSOC);
|
||
|
if (count($tabTmp)>0) {
|
||
|
$caSecteur=round($tabTmp[0]['moyenne']*1000);
|
||
|
// Encours moyen secteur * nb salariés
|
||
|
if ($effectif>0) return $caSecteur*$effectif;
|
||
|
else return $caSecteur;
|
||
|
} else
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Code Voie Rivoli
|
||
|
* @param string $codeCommune
|
||
|
* @param string $adrTypVoie
|
||
|
* @param string $adrLibVoie
|
||
|
* @return string
|
||
|
*/
|
||
|
public function getCodeVoieRivoli($codeCommune, $adrTypVoie, $adrLibVoie)
|
||
|
{
|
||
|
$codeVoie = '';
|
||
|
$adrTypVoie = strtoupper($adrTypVoie);
|
||
|
$adrLibVoie = strtoupper($adrLibVoie);
|
||
|
$adrLibVoie2 = addslashes($adrLibVoie);
|
||
|
|
||
|
$tabVoiesNoff = array(
|
||
|
'LD' => '',
|
||
|
'R' => 'RUE',
|
||
|
'CITE' => 'CTE',
|
||
|
'FG' => 'FBG',
|
||
|
'PL' => 'PCE',
|
||
|
'QU' => 'QUAI',
|
||
|
'QUA' => 'QRT',
|
||
|
'SQ' => 'SQR',
|
||
|
'VLGE' => 'VGE',
|
||
|
'VOI' => 'VOIE'
|
||
|
);
|
||
|
|
||
|
if (array_key_exists($adrTypVoie, $tabVoiesNoff) || in_array($adrTypVoie, $tabVoiesNoff)) {
|
||
|
$typeVoieNoff = $adrTypVoie;
|
||
|
$typeVoieOff = $tabVoiesNoff[$adrTypVoie];
|
||
|
if ($typeVoieOff == 'QUA') {
|
||
|
$strTypesVoies = " AND voieNature IN('QUA','QRT','QUR') ";
|
||
|
} else {
|
||
|
$strTypesVoies = " AND voieNature IN('$typeVoieNoff','$typeVoieOff') ";
|
||
|
}
|
||
|
} else {
|
||
|
$typeVoieOff = $typeVoieNoff = $adrTypVoie;
|
||
|
$strTypesVoies =" AND voieNature='$typeVoieOff' ";
|
||
|
}
|
||
|
|
||
|
$ret = $this->iDb->select('insee.fantoirVoi', "codComInsee, idVoieCom, cleRivoli, voieNature, voieLib, 1 AS score",
|
||
|
"codComInsee='$codeCommune' $strTypesVoies AND voieLib='$adrLibVoie2'", false, MYSQL_ASSOC);
|
||
|
$nbRet = count($ret);
|
||
|
if ($nbRet==0) {
|
||
|
return '';//'Aucune correspondance Rivoli'.PHP_EOL;
|
||
|
} else {
|
||
|
foreach($ret as $i=>$iRet) {
|
||
|
if (($iRet['voieNature']==$typeVoieOff || $iRet['voieNature']==$typeVoieNoff) && $iRet['voieLib']==$adrLibVoie) {
|
||
|
$codeVoie=$iRet['idVoieCom'];
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $codeVoie;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Information de l'événement précédent associé
|
||
|
* @param string $siren
|
||
|
* @param string $nic
|
||
|
* @param string $dateEven
|
||
|
* @param string $even
|
||
|
* @return string
|
||
|
*/
|
||
|
protected function getInfoPrecedente($siren, $nic = null, $dateEven, $even)
|
||
|
{
|
||
|
$sqlIdentifiant = "insSIREN=$siren";
|
||
|
|
||
|
$table = 'insee.insee_even';
|
||
|
$where = "insDATEVE < $dateEven ORDER BY insDATEMAJ DESC LIMIT 1";
|
||
|
|
||
|
switch ( strtoupper($even) ) {
|
||
|
case 'NOMEN':
|
||
|
$result = $this->iDb->select($table, "insNOMEN", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insNOMEN'];
|
||
|
}
|
||
|
break;
|
||
|
case 'SIGLE':
|
||
|
$result = $this->iDb->select($table, "insSIGLE", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insSIGLE'];
|
||
|
}
|
||
|
break;
|
||
|
case 'APEN':
|
||
|
$result = $this->iDb->select($table, "insAPEN700", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insAPEN700'];
|
||
|
}
|
||
|
break;
|
||
|
case 'APET':
|
||
|
if ( !empty($nic) ) $sqlIdentifiant.= " AND insNIC=$nic";
|
||
|
$result = $this->iDb->select($table, "insAPET700", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insAPET700'];
|
||
|
}
|
||
|
break;
|
||
|
case 'NICSIEGE':
|
||
|
$result = $this->iDb->select($table, "insNICSIEGE", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insNICSIEGE'];
|
||
|
}
|
||
|
break;
|
||
|
case 'CJ':
|
||
|
$result = $this->iDb->select($table, "insCJ", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insCJ'];
|
||
|
}
|
||
|
break;
|
||
|
case 'ENSEIGNE':
|
||
|
if ( !empty($nic) ) $sqlIdentifiant.= " AND insNIC=$nic";
|
||
|
$result = $this->iDb->select($table, "insENSEIGNE", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insENSEIGNE'];
|
||
|
}
|
||
|
break;
|
||
|
case 'ADRESSE':
|
||
|
if ( !empty($nic) ) $sqlIdentifiant.= " AND insNIC=$nic";
|
||
|
$result = $this->iDb->select($table, "insL2_COMP, insL3_CADR, insL4_VOIE, insL5_DISP, insL6_POST, insL7_ETRG", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insL2_COMP'].' '.
|
||
|
$result[0]['insL3_CADR'].' '.
|
||
|
$result[0]['insL4_VOIE'].' '.
|
||
|
$result[0]['insL5_DISP'].' '.
|
||
|
$result[0]['insL6_POST'].' '.
|
||
|
$result[0]['insL7_ETRG'];
|
||
|
}
|
||
|
break;
|
||
|
case 'EFFECTIF':
|
||
|
if ( !empty($nic) ) $sqlIdentifiant.= " AND insNIC=$nic";
|
||
|
$result = $this->iDb->select($table, "insEFENCENT, insTEFET", "$sqlIdentifiant AND $where");
|
||
|
if ( count($result)>0 ) {
|
||
|
return $result[0]['insEFENCENT'].' (Tranche '.$result[0]['insTEFET'].')';
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
}
|