7466 lines
333 KiB
PHP
7466 lines
333 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 $iBodacc;
|
|
|
|
protected $AnnoncesPosition = 0;
|
|
protected $AnnoncesNb = 20;
|
|
|
|
protected $SituationCloture = false;
|
|
|
|
protected $Identite;
|
|
|
|
/**
|
|
* PDO Connection with Doctrine
|
|
* @var \Doctrine\DBAL\Connection
|
|
*/
|
|
protected $conn;
|
|
|
|
protected $iDb;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function __construct($db = null)
|
|
{
|
|
if ($db === null) {
|
|
$this->iDb = new Metier_Util_Db();
|
|
} else {
|
|
$this->iDb = $db;
|
|
}
|
|
|
|
$this->conn = Zend_Registry::get('doctrine');
|
|
|
|
$this->iBodacc = new Metier_Bodacc_MBodacc();
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
//Siren non précisé ou incorrect.
|
|
if (!Metier_Util_String::valideData($siren, 9, 9, 'N')) {
|
|
return $erreur;
|
|
}
|
|
// Siren vide
|
|
elseif (intval($siren) == 0) {
|
|
return $erreur;
|
|
} else {
|
|
if (!isset($nic) || trim($nic)=='') {
|
|
$somme = 0;
|
|
// Traitement IMPAIR
|
|
for ($i=0; $i<=8; $i+=2) {
|
|
$somme+= (integer) substr($siren, $i, 1);
|
|
}
|
|
// Traitement PAIR
|
|
for ($i=1; $i<=7; $i+=2) {
|
|
$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;
|
|
}
|
|
|
|
// Le Siren est faux
|
|
if ((integer) ($somme/10) != ($somme/10)) {
|
|
// Les siren débutant par 200 sont toujours valides (sirens provisoires de la BDF?!)
|
|
if (substr($siren, 0, 3) != '200') {
|
|
return $erreur;
|
|
}
|
|
}
|
|
} else {
|
|
// Nic de format incorrect.
|
|
if (!Metier_Util_String::valideData($nic, 1, 5, 'N')) {
|
|
return $erreur;
|
|
}
|
|
$SIRET = $siren . $nic;
|
|
if ($siren != 356000000) {
|
|
$somme=0;
|
|
// Traitement PAIR
|
|
for ($i=0; $i<=12; $i+=2) {
|
|
$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;
|
|
}
|
|
// Traitement IMPAIR
|
|
for ($i=1; $i<=13; $i+=2) {
|
|
$somme+= (integer) substr($SIRET, $i, 1);
|
|
}
|
|
// Le Siret est faux
|
|
if ((integer) ($somme/10) != ($somme/10)) {
|
|
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);
|
|
}
|
|
// Le NIC de l'établissement de LA POSTE est faux !
|
|
if ($somme%5 != 0) {
|
|
return $erreur;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Test de la validité du siren demandé
|
|
* @param int $siren
|
|
* SIREN à tester
|
|
* @param int $numEtab
|
|
* N° d'établissement dont ont doit calculer le NIC
|
|
* @return int
|
|
*/
|
|
public function getNic($siren, $numEtab=1)
|
|
{
|
|
if (!$this->valideSiren($siren)) {
|
|
return -1;
|
|
}
|
|
// Nic de format incorrect.
|
|
elseif (!Metier_Util_String::valideData($numEtab, 1, 4, 'N')) {
|
|
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;
|
|
}
|
|
|
|
$stmt = $this->conn->prepare('SELECT CJ FROM insee.identite WHERE SIREN=:siren');
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->execute();
|
|
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
/**
|
|
* 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 = Metier_Util_String::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,
|
|
);
|
|
|
|
$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();
|
|
$stmt = $this->conn->executeQuery("SELECT codNaf700 AS naf, libNaf700 AS LibNaf FROM jo.tabNaf4");
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$tabNafs[$row->naf] = $row->LibNaf;
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT codNaf5 AS naf, libNaf5 AS LibNaf, codNaf1 FROM jo.tabNaf5");
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$tabNafs[$row->naf] = $row->LibNaf;
|
|
$tabNace[$row->naf] = $row->codNaf1.preg_replace('/^0/', '', substr($row->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();
|
|
$stmt = $this->conn->executeQuery("SELECT codNafa AS nafa, libNafa FROM jo.tabNafa");
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$result[$row->naf] = $row->libNafa;
|
|
}
|
|
$this->tabCodesNafa = $result;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Libelle Nafa
|
|
* @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 ";
|
|
}
|
|
|
|
if (empty($nic)) {
|
|
$tabSupId = $this->getEvenementsAssocId($siren);
|
|
if (count($tabSupId) > 0) {
|
|
$sqlIdentifiant.= " OR id IN(".join(',', $tabSupId).")";
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT 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
|
|
FROM insee.insee_even WHERE $sqlIdentifiant ORDER BY insDATEMAJ DESC LIMIT $iDeb, $iMax";
|
|
|
|
$stmt = $this->conn->executeQuery($sql);
|
|
|
|
while ($even = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$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";
|
|
}
|
|
|
|
if (empty($nic)) {
|
|
$tabSupId = $this->getEvenementsAssocId($siren);
|
|
if (count($tabSupId) > 0) {
|
|
$sqlIdentifiant.= " OR id IN(".join(',', $tabSupId).")";
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT count(*) AS nb FROM insee.insee_even WHERE $sqlIdentifiant ORDER BY insDATEMAJ DESC";
|
|
$stmt = $this->conn->executeQuery($sql);
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->nb;
|
|
}
|
|
|
|
/**
|
|
* Recherche les identifiants des événements INSEE associés
|
|
* @param string $siren
|
|
* @return array
|
|
*/
|
|
protected function getEvenementsAssocId($siren)
|
|
{
|
|
$tabSupId = array();
|
|
|
|
if ($this->tabAssocId === null) {
|
|
$siretDeb = $siren.'00000';
|
|
$siretFin = $siren.'99999';
|
|
|
|
// Recherche d'évènement pour lesquels le SIREN est ASSOCIE
|
|
$stmt = $this->conn->executeQuery("SELECT id FROM insee.insee_even
|
|
WHERE insSIREN != $siren AND insSIRETASS BETWEEN $siretDeb AND $siretFin
|
|
GROUP BY insSIREN, ROUND(insSIRETASS/100000) ORDER BY insDATEMAJ DESC");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$tabSupId[] = $row->id;
|
|
}
|
|
}
|
|
|
|
// Recherche d'évènement pour lesquels le SIREN est Prédécesseur ou Successeur
|
|
$stmt = $this->conn->executeQuery("SELECT id FROM insee.insee_even
|
|
WHERE insSIREN != $siren AND insSIRETASS BETWEEN $siretDeb AND $siretFin
|
|
GROUP BY insSIREN, ROUND(insSIRETPS/100000) ORDER BY insDATEMAJ DESC");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$tabSupId[] = $row->id;
|
|
}
|
|
}
|
|
|
|
$this->tabAssocId = $tabSupId;
|
|
} else {
|
|
$tabSupId = $this->tabAssocId;
|
|
}
|
|
|
|
return $tabSupId;
|
|
}
|
|
|
|
|
|
/**
|
|
* Libelle FJ
|
|
* @param string $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) {
|
|
$stmt = $this->conn->prepare("SELECT libelle AS LibFJ, libelleCourt AS LibCourt FROM jo.tabFJur WHERE code = :fj");
|
|
$stmt->bindValue('fj', $fj);
|
|
$stmt->execute();
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$libLong = $result->LibFJ;
|
|
$libCourt = $result->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';
|
|
}
|
|
|
|
/**
|
|
* Codes FJ
|
|
* @return array
|
|
*/
|
|
public function getCodesFJ()
|
|
{
|
|
$tabFJ = array();
|
|
$cache = dirname(__FILE__) . '/../Table/CodesFJ.php';
|
|
if (file_exists($cache)) {
|
|
$result = include $cache;
|
|
} else {
|
|
$stmt = $this->conn->executeQuery("SELECT code AS FJ, libelle AS libFJ FROM jo.tabFJur WHERE code >= 1000");
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$result[$row->FJ] = str_replace('"', '\"', $row->LibFJ);
|
|
}
|
|
}
|
|
|
|
return array_keys($result);
|
|
}
|
|
|
|
/**
|
|
* 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 = Metier_Util_String::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 = '';
|
|
|
|
$fields = "'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, e.identite_pre, IF(e.siege=2,0.5,e.siege) AS triSiege,
|
|
IF (e.adr_dep=99, (SELECT libPays FROM jo.tabPays p WHERE p.codePaysInsee=e.adr_com) , 'France') AS libPays";
|
|
|
|
$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';
|
|
}
|
|
$sqlWhere = "siren=$siren $strDep $strActif $strSiege";
|
|
}
|
|
// --- Search without NIC
|
|
elseif ($nic == '') {
|
|
$sqlWhere = "e.siren=$siren $strActif $strSiege";
|
|
}
|
|
// --- Search with NIC
|
|
else {
|
|
$sqlWhere = "siren=$siren AND (nic=$nic OR siege=1) $strActif $strSiege";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT count(*) AS nb FROM jo.etablissements e WHERE $sqlWhere");
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$nbTot = $result->nb;
|
|
|
|
$sqlOrder = "ORDER BY triSiege DESC, e.actif DESC, e.nic DESC";
|
|
$sqlLimit = "LIMIT $deb, $nbRep";
|
|
|
|
// --- 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);
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT count(*) AS nb FROM jo.etablissements
|
|
WHERE siren IN ($strSiren) AND siege=1");
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$nbTot = $result->nb;
|
|
$sql = "SELECT $fields FROM jo.etablissements e
|
|
WHERE siren IN ($strSiren) AND siege=1
|
|
ORDER BY e.rang DESC, e.actif DESC, e.nic ASC $sqlLimit";
|
|
$strInfo = 'Siren saisi invalide';
|
|
}
|
|
} else {
|
|
$sql = "SELECT $fields FROM jo.etablissements e
|
|
WHERE $sqlWhere $sqlOrder $sqlLimit";
|
|
}
|
|
|
|
try {
|
|
$stmt = $this->conn->executeQuery($sql);
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
}
|
|
|
|
// --- Affichage de la liste des établissements
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tel = sprintf('%010d', strtr($row['tel'], array('-'=>'', '/'=>'', '.'=>'', ','=>'')));
|
|
if ($tel != '0000000000') {
|
|
$tel = implode('.', str_split($tel, 2));
|
|
} else {
|
|
$tel = '';
|
|
}
|
|
|
|
$fax = sprintf('%010d', strtr($row['fax'], array('-'=>'', '/'=>'', '.'=>'', ','=>'')));
|
|
if ($fax != '0000000000') {
|
|
$fax = implode('.', str_split($fax, 2));
|
|
} else {
|
|
$fax = '';
|
|
}
|
|
|
|
// Cas des noms vides à l'INSEE (une centaine)
|
|
$nom = trim($row['raisonSociale']);
|
|
if ($nom == '') {
|
|
$nom = preg_replace('/,.*$/', '', $row['identite_pre']);
|
|
}
|
|
|
|
$tabRet[] = array(
|
|
'Localisation' => $row['Loc'],
|
|
'id' => $row['id'],
|
|
'Pertinence' => 100,
|
|
'Source' => $row['source'],
|
|
'SoruceId' => $row['source_id'],
|
|
'Siret' => $row['siret'],
|
|
'Siege' => $row['siege'],
|
|
'Nom' => $nom,
|
|
'Sigle' => $row['sigle'],
|
|
'Enseigne' => $etab['enseigne'],
|
|
'Adresse' => trim(preg_replace('/ +/', ' ', trim($row['adr_num'] .' '.
|
|
$row['adr_btq'] .' '. $row['adr_typeVoie'] .' '. $row['adr_libVoie']))),
|
|
'Adresse2' => trim(preg_replace('/ +/', ' ', $row['adr_comp'])),
|
|
'CP' => $row['adr_cp'],
|
|
'Ville' => $row['adr_ville'],
|
|
'Pays' => ($row['adr_dep'] != 99 ? $row['libPays'] : 'France'),
|
|
'Tel' => $tel,
|
|
'Fax' => $fax,
|
|
'FJ' => $row['cj'],
|
|
'FJLib' => $this->getLibelleFJ($row['cj']),
|
|
'Siren' => $row['siren'],
|
|
'Nic' => $row['nic'],
|
|
'Actif' => $row['actif'],
|
|
'NafEtab' => $row['ape_etab'], // Etablissement
|
|
'NafEnt' => $row['ape_entrep'], // Entreprise
|
|
'NafEtabLib' => $this->getLibelleNaf($row['ape_etab']),
|
|
'NafEntLib' => $this->getLibelleNaf($row['ape_entrep']),
|
|
'EffEtTr' => $row['teff_etab'],
|
|
'EffEtTrLib' => self::$tabEffectif[$row['teff_etab']],
|
|
);
|
|
}
|
|
}
|
|
|
|
// Evite l'affichage d'un 0 inutile sur l'Extranet
|
|
if ($dep == 0) {
|
|
$dep = '';
|
|
}
|
|
|
|
return array(
|
|
'criteres' => array(
|
|
'autreId' => $id,
|
|
'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";
|
|
}
|
|
|
|
$fields = "'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,
|
|
IF (e.adr_dep=99, (SELECT libPays FROM jo.tabPays p WHERE p.codePaysInsee=e.adr_com) , 'France') AS libPays";
|
|
|
|
if ($typeId == 'TEL') {
|
|
Metier_Util_Log::write('I', "Recherche par TEL de $id avec un maximum de $nbRep réponses", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$stmt = $this->conn->executeQuery("SELECT count(*) AS nb FROM jo.etablissements
|
|
WHERE TEL=$id OR FAX=$id $filtreActif");
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$nbTot = $result->nb;
|
|
$stmt = $this->conn->executeQuery("SELECT $fields FROM jo.etablissements e
|
|
WHERE TEL=$id OR FAX=$id $filtreActif
|
|
ORDER BY e.siege DESC, e.actif DESC $limit");
|
|
} 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];
|
|
}
|
|
}
|
|
// Années du type 1900 ou 2000
|
|
else {
|
|
$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';
|
|
}
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT count(*) AS nb FROM jo.etablissements
|
|
WHERE autre_id IN ('$strId') $filtreActif $strDep");
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$nbTot = $result->nb;
|
|
$stmt = $this->conn->executeQuery("SELECT $fields FROM jo.etablissements e
|
|
WHERE autre_id IN ('$strId') $filtreActif $strDep
|
|
ORDER BY siege DESC $limit");
|
|
}
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRet[] = array(
|
|
'Localisation' => $row['Loc'],
|
|
'id' => $row['id'],
|
|
'Pertinence' => 100,
|
|
'Source' => $row['source'],
|
|
'SourceId' => $row['source_id'],
|
|
'Siret' => $row['siret'],
|
|
'Siege' => $row['siege'],
|
|
'Nom' => $row['raisonSociale'],
|
|
'Sigle' => $row['sigle'],
|
|
'Enseigne' => $row['enseigne'],
|
|
'Adresse' => trim(preg_replace('/ +/', ' ', trim($row['adr_num'] .' '.
|
|
$row['adr_btq'] .' '. $row['adr_typeVoie'] .' '. $row['adr_libVoie']))),
|
|
'Adresse2' => trim(preg_replace('/ +/', ' ', $row['adr_comp'])),
|
|
'CP' => $row['adr_cp'],
|
|
'Ville' => $row['adr_ville'],
|
|
'Pays' => ($row['adr_dep'] != 99 ? $row['libPays'] : 'France'),
|
|
'Tel' => $row['tel'],
|
|
'Fax' => $row['fax'],
|
|
'FJ' => $row['cj'],
|
|
'FJLib' => $this->getLibelleFJ($row['cj']),
|
|
'Siren' => $row['siren'],
|
|
'Nic' => $row['nic'],
|
|
'Actif' => $row['actif'],
|
|
'NafEtab' => $row['ape_etab'], // Etablissement
|
|
'NafEnt' => $row['ape_entrep'], // Entreprise
|
|
'NafEtabLib' => $this->getLibelleNaf($row['ape_etab']),
|
|
'NafEntLib' => $this->getLibelleNaf($row['ape_entrep']),
|
|
);
|
|
}
|
|
}
|
|
|
|
// Evite l'affichage d'un 0 inutile sur l'Extranet
|
|
if ($dep == 0) {
|
|
$dep = '';
|
|
}
|
|
|
|
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
|
|
*/
|
|
public function sirenExiste($siren)
|
|
{
|
|
$siren = $siren*1;
|
|
$stmt = $this->conn->executeQuery("SELECT id FROM jo.etablissements WHERE siren=$siren LIMIT 0,1");
|
|
if ($stmt->rowCount()) {
|
|
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();
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM jo.etablissements e
|
|
WHERE $where ORDER BY siege DESC, actif DESC, nic DESC $limit");
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
$etab = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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 = '')
|
|
{
|
|
$tabRet = array();
|
|
if (trim($codeIso) != '') {
|
|
$strWhere = "devIso='$codeIso'";
|
|
} else {
|
|
$strWhere = '1';
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT devIso, devNom FROM jo.tabDevises WHERE $strWhere");
|
|
if ($stmt->rowCount()) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$tabRet[$row->devIso] = $row->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";
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE 1 $strIdCA $strType ORDER BY sirenGrp");
|
|
if ($stmt->rowCount()) {
|
|
if (!$condense) {
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
} else {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRet[$row['id']] = preg_replace('/ +/', ' ', $row['Mand']);
|
|
}
|
|
return $tabRet;
|
|
}
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
* 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";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE 1 $strIdCA $strType $strCp ORDER BY sirenGrp");
|
|
if ($stmt->rowCount()) {
|
|
if (!$condense) {
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
} else {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRet[$row['id']] = preg_replace('/ +/', ' ', $row['Mand']);
|
|
}
|
|
return $tabRet;
|
|
}
|
|
}
|
|
|
|
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';
|
|
$stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE id=$idMand");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
|
|
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";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE 1 AND type='H' $strIdCA ORDER BY sirenGrp");
|
|
if ($stmt->rowCount()) {
|
|
if (!$condense) {
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
} else {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRet[$row['id']] = preg_replace('/ +/', ' ', $row['Mand']);
|
|
}
|
|
return $tabRet;
|
|
}
|
|
}
|
|
|
|
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) {
|
|
$stmt = $this->conn->executeQuery("SELECT CONCAT(Nom,' ',Prenom,' ',adresse,' ',adresseComp,' ',cp,' ',ville) as Mand FROM jo.tabMandataires WHERE id=$idMand");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
}
|
|
|
|
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 ";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT siren, nic, apen5, apen4, apet5, apet4 FROM insee.bascule WHERE $where");
|
|
if ($stmt->rowCount() == 0) {
|
|
return false;
|
|
}
|
|
|
|
$tabRet = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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 = '';
|
|
|
|
// Liste des établissements
|
|
if ($id > 0 && $siren < 1000) {
|
|
$where = " id=$id ";
|
|
} elseif ($nic != 0) {
|
|
$where = " siren=$siren AND nic=$nic ";
|
|
} elseif ($siren != 0) {
|
|
$where = " siren=$siren ";
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM jo.etablissements e
|
|
WHERE $where ORDER BY siege DESC, actif DESC, nic DESC $limit");
|
|
$nbEtab = $stmt->rowCount();
|
|
if ($nbEtab > 0) {
|
|
$etab = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$nic = $etab['nic'];
|
|
}
|
|
$timer['tableEtablissements'] = microtime(true);
|
|
|
|
// Si aucun résultat et siren est valide, on part chez Infogreffe
|
|
if ($accesDist && $nbEtab == 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) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM jo.infos_entrep WHERE siren=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$tab = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$waldec = $tab['waldec'];
|
|
if (!array_key_exists('sirenDoublon', $tab)) {
|
|
$stmt = $this->conn->executeQuery("SELECT LPAD(siren,9,'0') AS sirenDoublon FROM jo.infos_entrep WHERE sirenDoublon=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$tab['sirenDoublon'] = $result->sirenDoublon;
|
|
}
|
|
}
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT CONCAT(LPAD(SIREN,9,0), LPAD(NIC,5,0)) AS siret
|
|
FROM jo.etablissements
|
|
WHERE SIREN=$siren AND SIEGE=1 ORDER BY ACTIF%10 DESC, NIC DESC");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$siretSiege = $result->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";
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT 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, TRIM(LEADING '0' FROM DCREN) AS 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, TRIM(LEADING '0' FROM DCRET) AS 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
|
|
FROM insee.identite WHERE SIREN=$siren $strNic ORDER BY SIEGE DESC, ACTIF DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$tabInsee = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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;
|
|
$stmt = $this->conn->executeQuery("SELECT count(*) AS nbEtabs FROM jo.etablissements
|
|
WHERE siren=$siren AND NIC<100000 AND ACTIF%10=1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$nbEtab = $result->nbEtabs;
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT mois FROM insee.insee_nondiff
|
|
WHERE siren=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$moisNonDiff = $result->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' || trim($tabInsee['EXPLET']) == '') {
|
|
switch ($tabInsee['PRODPART']*1) {
|
|
// Locataire d'un fond de commerce
|
|
case 1:
|
|
$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'];
|
|
$stmt = $this->conn->executeQuery("SELECT j.codPays, j.numPays, j.codPays3, j.codePaysInpi,
|
|
j.libPays, i.LIBCOG, i.ACTUAL FROM jo.tabPays j, insee.insee_tabPays i
|
|
WHERE j.codePaysInsee=$codePaysInsee AND j.codePaysInsee=substring( i.COG, 3, 3 )
|
|
AND i.ACTUAL IN (1,4) AND j.numPays is NOT NULL");
|
|
if ($stmt->rowCount() == 1) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$codePaysIso2 = $result->codPays;
|
|
} elseif ($stmt->rowCount() > 1) {
|
|
$codePaysIso2 = '';
|
|
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if (trim(preg_replace('/[^A-Z]/', '', strtoupper(strtr($result['libPays'],
|
|
'àáâãäåæçèéêëìíîïðñòóôõöùúûüýÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝ',
|
|
"aaaaaaaceeeeiiiionooooouuuuyyAAAAAAACEEEEIIIIONOOOOOUUUUY")))) == trim(preg_replace('/[^A-Z]/', '', strtoupper($result['LIBCOG'])))) {
|
|
$codePaysIso2 = $result['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']);
|
|
// On récupere le code Rivoli s'il est absent de SIRENE (cf. doc Sirene)
|
|
if ($tabInsee['CODEVOIE']=='' && count($tabIris) > 0) {
|
|
$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
|
|
$stmt = $this->conn->executeQuery("SELECT insEVE, IF(insDATEVE=0, idFlux*1, insDATEVE) AS insDATEVE
|
|
FROM insee.insee_even WHERE insSIREN=$siren AND insNIC=$nic
|
|
AND insEVE IN ('OD','TD','MPF','MNP','420','425','620','621','650') ORDER BY insDATEVE DESC");
|
|
if ($stmt->rowCount() > 0) {
|
|
$tabModif = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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';
|
|
}
|
|
|
|
$aprm = substr($tabInsee['APRM'], -1, 1) == 'Z' ? '' : $tabInsee['APRM'];
|
|
|
|
$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' => $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)) {
|
|
$stmt = $this->conn->executeQuery("SELECT id, nom, adresse, adrCp, adrVille,
|
|
nbEtoiles, typeClasse, categorie, dateClasse, tel, fax, mail, web,
|
|
typeChambres, capacite FROM jo.tourisme WHERE siren=$siren AND nic=$nic");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$tabRet['NafEtabLib'].= ' ('.$result['nbEtoiles'].' étoiles le '.
|
|
Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['dateClasse']).')';
|
|
if ($tabRet['Tel'] == '') {
|
|
$tabRet['Tel'] = $result['tel'];
|
|
}
|
|
if ($tabRet['Fax'] == '') {
|
|
$tabRet['Fax'] = $result['fax'];
|
|
}
|
|
if ($tabRet['Web'] == '') {
|
|
$tabRet['Web'] = $result['web'];
|
|
}
|
|
if ($tabRet['Mail'] == '') {
|
|
$tabRet['Mail'] = $result['mail'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Nombre d'actions du capital si disponible
|
|
if ($etab['capital'] > 0) {
|
|
$stmt = $this->conn->executeQuery("SELECT capital, deviseCapital, nbActions, actionNominale, dateInfo
|
|
FROM sdv1.capitalActions WHERE siren=$siren AND capital>0 ORDER BY dateInfo DESC LIMIT 0,1");
|
|
$tabRet['CapitalNbActions'] = 0;
|
|
$tabRet['CapitalMtActions'] = 0;
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
if ($etab['capital'] == $result['capital']) {
|
|
$tabRet['CapitalNbActions'] = $result['nbActions'];
|
|
$tabRet['CapitalMtActions'] = $result['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) {
|
|
$stmt = $this->conn->executeQuery("SELECT DCREN FROM insee.identite WHERE SIREN=$siren AND DCREN>0 ORDER BY DCREN ASC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$tabRet['DateCreaEn'] = $result->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->conn->update('insee.identite', array('DCREN'=>$dateCreaEn),
|
|
array('SIREN'=>$siren, '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
|
|
$stmt = $this->conn->executeQuery("SELECT encours, scoreSolv, scoreDir, scoreConf, DATE(dateInsert)*1 AS dateInsert, DATE(dateUpdate)*1 AS dateUpdate FROM jo.scores_cutoff WHERE siren=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
if ($result['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 ($result['dateUpdate'] > $result['dateInsert']) {
|
|
$dateMaj = str_replace('-', '', $result['dateUpdate']);
|
|
} else {
|
|
$dateMaj = str_replace('-', '', $result['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'])) {
|
|
$stmt = $this->conn->executeQuery("SELECT dirNom, dirNomUsage, dirPrenom, insCIVILITE
|
|
FROM insee.insee_even WHERE insSIREN=$siren ORDER BY insDATEVE DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$dir = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$tabRet['dir1Nom'] = strtoupper($dir['dirNom']);
|
|
$tabRet['dir1Prenom'] = ucwords(strtolower($dir['dirPrenom']));
|
|
$tabRet['dir1NomUsage'] = strtoupper($dir['dirNomUsage']);
|
|
if ($dir['insCIVILITE'] == 1) {
|
|
$tabRet['dir1Genre'] = 'M';
|
|
} elseif ($dir['insCIVILITE'] == 2) {
|
|
$tabRet['dir1Genre'] = 'F';
|
|
} elseif ($tabRet['dir1Genre'] != 'M' && $tabRet['dir1Genre'] != 'F') {
|
|
$tabRet['dir1Genre'] = '';
|
|
}
|
|
$entrep['sexe'] = $tabRet['dir1Genre'];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (intval($siren) > 100 && $tabInsee['ACTIF'] == 0) {
|
|
if ($etab['nic']*1>0) {
|
|
$strNic = 'AND insNIC='.$etab['nic'];
|
|
} else {
|
|
$strNic = '';
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT insDATEVE FROM insee.insee_even
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$tabRet['DateClotEt'] = $result->insDATEVE;
|
|
}
|
|
$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
|
|
$stmt = $this->conn->executeQuery("SELECT Capital, CapitalDev FROM jo.bodacc_detail
|
|
WHERE siren=$siren AND capital != 0 $strEvenVtLg
|
|
ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$annCap = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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']=='') {
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM historiques.entrep e, historiques.texte x
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
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'];
|
|
$stmt = $this->conn->executeQuery("SELECT c.devise, c.valeur, c.date, l.devNom,
|
|
l.devNomPays, l.devPaysIso FROM sdv1.devise_liste l, sdv1.devise_cours c
|
|
WHERE c.devise='$dev' and l.devIso='$dev' ORDER BY c.date DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$dev = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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) {
|
|
$stmt = $this->conn->executeQuery("SELECT RC, FJ, Tribunal_Code FROM jo.bodacc_detail
|
|
WHERE siren=$siren AND RC != '' $strEvenVtLg ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$bodacc = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
if ($tabRet['AutreId']=='') {
|
|
$tabRet['AutreId'] = $bodacc['RC'];
|
|
}
|
|
if ($tabRet['Tribunal'] == '') {
|
|
$tabRet['Tribunal'] = $bodacc['Tribunal_Code'];
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($tabRet['FJ_lib'] == '') {
|
|
$stmt = $this->conn->executeQuery("SELECT FJ FROM jo.bodacc_detail
|
|
WHERE siren=$siren AND FJ != '' $strEvenVtLg ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$tabRet['FJ_lib'] = $result->FJ;
|
|
}
|
|
}
|
|
|
|
// Recherche de l'activité réelle
|
|
$stmt = $this->conn->executeQuery("SELECT Activite FROM jo.
|
|
bodacc_detail WHERE siren=$siren AND Activite != ''
|
|
AND Activite NOT LIKE 'non precis%' $strEvenVtLg
|
|
ORDER BY Bodacc_Date_Parution DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$annCap = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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)) {
|
|
$stmt = $this->conn->executeQuery("SELECT Assoc_Web, Assoc_Mail, Assoc_Objet,
|
|
Assoc_NObjet, Assoc_Nom, typeAsso, Waldec FROM jo.asso WHERE siren=$siren
|
|
AND dateSuppr=0 AND (Assoc_Objet != '' OR Assoc_NObjet != '')
|
|
ORDER BY Date_Parution DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$annCap = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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)) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM historiques.entrep e, historiques.texte x
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
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);
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.rncs_dirigeants
|
|
WHERE siren=$siren AND actif%10=1 AND fonction_lib NOT LIKE '%Administrateur%'
|
|
ORDER BY actif DESC, fonction_lib DESC");
|
|
if ($stmt->rowCount() == 0) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.rncs_dirigeants
|
|
WHERE siren=$siren AND actif%10=0 AND fonction_lib NOT LIKE '%Administrateur%'
|
|
ORDER BY actif DESC, fonction_lib DESC");
|
|
}
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
$k = 1;
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
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 {
|
|
$stmt = $this->conn->executeQuery("SELECT d.num, d.dateEffet, d.Rubrique, d.fonction, d.rs,
|
|
d.nom, d.prenom, d.nomUsage, d.depart, d.dateInsert, f.libelle
|
|
FROM jo.bodacc_dirigeants d, jo.bodacc_detail b, jo.bodacc_fonctions f
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
$k = 1;
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$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)) {
|
|
$stmt = $this->conn->executeQuery("SELECT Assoc_Web, Assoc_Mail FROM jo.asso
|
|
WHERE siren=$siren AND dateSuppr=0 AND (Assoc_Web != '' OR Assoc_Mail != '')
|
|
ORDER BY Date_Parution DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$annCap = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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'];
|
|
$stmt = $this->conn->executeQuery("SELECT Activite, Sous_Prefecture, Assoc_Web,
|
|
Assoc_Mail, Assoc_Objet, Assoc_Fusion, Assoc_Date_Declaration2
|
|
FROM jo.asso WHERE id=$id AND dateSuppr=0");
|
|
if ($stmt->rowCount() > 0) {
|
|
$annCap = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM jo.rncs_entrep WHERE siren=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$entrep = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
// ETRANGER
|
|
if (isset($entrep['numGreffe'])) {
|
|
$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'];
|
|
$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'];
|
|
}
|
|
}
|
|
// On signal que l'entreprise est active au RCS
|
|
if ($entrep['actif'] == 1 || $entrep['actif'] == 11) {
|
|
$tabRet['EntActiveRCS'] = 1;
|
|
}
|
|
// On signal que l'entreprise est radié du RCS
|
|
else {
|
|
$tabRet['EntActiveRCS'] = 0;
|
|
// On signal que l'entreprise est radié du RCS
|
|
if ($tabRet['SituationJuridique'] == '') {
|
|
$tabRet['SituationJuridique'] = 'RR';
|
|
}
|
|
}
|
|
|
|
// Spécificité EIRL
|
|
if ($fjInpi == 1000) {
|
|
$stmt = $this->conn->executeQuery("SELECT denomination, activite FROM jo.rncs_eirl WHERE siren=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$tabRet['Activite'] = $result->activite;
|
|
}
|
|
}
|
|
|
|
// Informations sur l'établissement au RNCS
|
|
$stmt = $this->conn->executeQuery("SELECT id, siege, actif, enseigne,
|
|
nomCommercial, adrNumVoie, adrIndRep, adrLibVoie, adrTypeVoie, adrVoie, cp,
|
|
commune, adrComp, adresse1, adresse2, adresse3, naf, dateFermeture, flux,
|
|
dateInsert, DATE(dateUpdate) AS jourUpdate FROM jo.rncs_etab
|
|
WHERE siren=$siren AND nic=$nic");
|
|
if ($stmt->rowCount() > 0) {
|
|
$entrep = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$tabRet['EtabActifRCS'] = 0;
|
|
if ($entrep['jourUpdate'] != '0000-00-00' &&
|
|
str_replace('-', '', $entrep['jourUpdate'])*1>str_replace('-', '', $tabRet['DateMajRCS'])) {
|
|
$tabRet['DateMajRCS'] = $entrep['jourUpdate'];
|
|
}
|
|
// On signal que l'établissement est actif au RCS
|
|
if ($entrep['actif']*1 == 1) {
|
|
$tabRet['EtabActifRCS'] = 1;
|
|
}
|
|
$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
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.artisanat WHERE siren=$siren");
|
|
if ($stmt->rowCount() > 0) {
|
|
$entrep = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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
|
|
// Artisan Commerçant
|
|
if ($tabRet['numGreffe']*1 > 0) {
|
|
$fjInpi = 1100;
|
|
}
|
|
// Artisan
|
|
else {
|
|
$fjInpi = 1300;
|
|
}
|
|
|
|
// 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'];
|
|
}
|
|
}
|
|
// On signal que l'entreprise est active au RCS
|
|
if ($entrep['actif'] == 1 || $entrep['actif'] == 11) {
|
|
$tabRet['EntActiveRCS'] = 1;
|
|
}
|
|
// On signal que l'entreprise est radié du RCS
|
|
else {
|
|
$tabRet['EntActiveRCS'] = 0;
|
|
// On signal que l'entreprise est radié du RCS
|
|
if ($tabRet['SituationJuridique'] == '') {
|
|
$tabRet['SituationJuridique'] = 'RR';
|
|
}
|
|
}
|
|
|
|
$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');
|
|
// Il y a au moins une annonce de radiation au Bodacc
|
|
if (count($tabRad) > 0) {
|
|
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
|
|
$stmt = $this->conn->executeQuery("SELECT siren, dateExercice, dureeExercice, monnaie,
|
|
typeBilan, unite, postes, dateProvPartenaire, dateInsert FROM jo.bilans
|
|
WHERE siren=$siren AND typeBilan IN ('N','S') ORDER BY dateExercice DESC LIMIT 0,1");
|
|
if ($stmt->rowCount() > 0) {
|
|
$entrep = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$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'];
|
|
// Ajaccio
|
|
if ($tabRet['Dept'] == '2A') {
|
|
$tabRet['NumRM'].= '.1';
|
|
}
|
|
// Bastia
|
|
elseif ($tabRet['Dept'] == '2B') {
|
|
$tabRet['NumRM'].= '.2';
|
|
} 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'";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT id, siren, nic, civ, nom, prenom, nom_usage, lieuNais, dateNais, d.codFct, f.libelle, tel, fax, email, dateInsert, dateUpdate
|
|
FROM sdv1.dirigeantsOp d, jo.bodacc_fonctions f WHERE $where");
|
|
if ($stmt->rowCount()) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRet[] = array(
|
|
'Id' => $row['id'],
|
|
'Fonction' => $row['codFct'],
|
|
'Titre' => $row['libelle'],
|
|
'Societe' => '',
|
|
'Civilite' => $row['civ'],
|
|
'Nom' => trim(strtoupper($row['nom'])),
|
|
'Prenom' => ucwords(strtolower($row['prenom'])),
|
|
'NomUsage' => $row['nom_usage'],
|
|
'NaissDate' => $row['dateNais'],
|
|
'NaissVille' => $row['lieuNais'],
|
|
'NaissDepPays' => '',
|
|
'Tel' => $row['tel'],
|
|
'Fax' => $row['fax'],
|
|
'Email' => $row['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) {
|
|
$stmt = $this->conn->executeQuery("SELECT d.num, d.dateEffet, d.Rubrique, d.fonction,
|
|
d.dirSiren, d.rs, d.nom, d.prenom, d.nomUsage, d.depart, d.dateInsert, f.libelle
|
|
FROM jo.bodacc_dirigeants d, jo.bodacc_detail b, jo.bodacc_fonctions f
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRet[] = array(
|
|
'Fonction' => $row['fonction'],
|
|
'Titre' => $row['libelle'],
|
|
'Siren' => $row['dirSiren'],
|
|
'Societe' => $row['rs'],
|
|
'Nom' => trim(strtr($row['nom'], array(
|
|
"Modification d'"=>'',
|
|
"Modification de"=>'',
|
|
"Nomination d'un"=>'',
|
|
))),
|
|
'Prenom' => $row['prenom'],
|
|
'NomUsage' => $row['nomUsage'],
|
|
'Ancien' => $row['depart'],
|
|
'DateFct' => $row['dateEffet'], //Date au format AAAA-MM-DD
|
|
);
|
|
}
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM historiques.entrep e, historiques.texte x
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if (($ann['CODEVE']<20) || ($ann['CODEVE']>=30 && $ann['CODEVE']<42)
|
|
|| ($ann['CODEVE']>=51 && $ann['CODEVE']<80)) {
|
|
$pattern = '/Administration(?:.|)\:(.*)(?:Adresse.*|Commentaires?|Activit(?:e|é)|Etablissement principal|Date d\'effet|Date.de.d.but d.activit.)(?:.|)\:/Uisu';
|
|
if (preg_match($pattern, $ann['annonceTxt'], $matches)) {
|
|
$iDir = 0;
|
|
$tabAdministration = $this->iBodacc->getDirigeants($matches[1]);
|
|
foreach ($tabAdministration as $tabDir) {
|
|
$nom = preg_replace('/ +/u', ' ', $tabDir['nom']);
|
|
$nom = trim(strtr($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']),
|
|
'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']),
|
|
);
|
|
// Mauvaise idée performance
|
|
try {
|
|
$this->conn->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'],
|
|
));
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
}
|
|
$iDir++;
|
|
}
|
|
} //End foreach
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$histo || ($histo && count($tabRet) == 0)) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.rncs_dirigeants WHERE siren=$siren AND actif%10=1");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if ($row['naissance_date'] != '0000-00-00') {
|
|
$dateNaiss = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['naissance_date']);
|
|
} else {
|
|
$dateNaiss = '';
|
|
}
|
|
|
|
if ($row['flux'] != '0000-00-00') {
|
|
$dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['flux']);
|
|
} else {
|
|
$dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['dateInsert']);
|
|
}
|
|
|
|
$nom = trim($row['nom']);
|
|
$nomUsage='';
|
|
if (trim($row['naissance_nom']) != '') {
|
|
$nom = trim($row['naissance_nom']);
|
|
$nomUsage = trim($row['nom']);
|
|
}
|
|
$tabRet[] = array(
|
|
'Fonction' => $row['fonction_code'],
|
|
'Titre' => $row['fonction_lib'],
|
|
'Siren' => $row['dirSiren'],
|
|
'Societe' => $row['dirRS'],
|
|
'Civilite' => $row['civilite'],
|
|
'Nom' => $nom,
|
|
'Prenom' => $row['prenom'],
|
|
'NomUsage' => $nomUsage,
|
|
'NaissDate' => $dateNaiss,
|
|
'NaissVille' => $row['naissance_lieu'],
|
|
'NaissDepPays' => '', // 25
|
|
'Ancien' => 0,
|
|
'DateFct' => $dateModif, //Format AAAA-MM-DD
|
|
'Cinf' => $row['cinf'],
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Recherche de CAC si liste des dirigeants actifs **/
|
|
if (!$histo) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.bodacc_dirigeants d, jo.bodacc_detail b, jo.bodacc_fonctions f
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
$k = 0;
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$rs = trim(strtoupper($row['rs']));
|
|
$nom = preg_replace('/en fonction le .*/i', '', $row['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($row['prenom']);
|
|
if ($prenom == '' && $rs== '' && $nom != '') {
|
|
$rs = $nom;
|
|
$nom = '';
|
|
}
|
|
$tabRet[] = array(
|
|
'Fonction' => $row['fonction'],
|
|
'Titre' => $row['libelle'],
|
|
'Siren' => $row['dirSiren'],
|
|
'Societe' => $rs,
|
|
'Nom' => $nom,
|
|
'Prenom' => $prenom,
|
|
'NomUsage' => $row['nomUsage'],
|
|
'Ancien' => $row['depart'],
|
|
'DateFct' => $row['dateEffet'], //Format AAAA-MM-DD
|
|
);
|
|
$k++;
|
|
// On s'arrête à 2 CAC (pb des co-cac non gérés)
|
|
if ($k>1) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Si on ne trouve absolument rien, on regarde quand même dans l'historique RNCS **/
|
|
if (count($tabRet)==0) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.rncs_dirigeants WHERE siren=$siren AND actif%10=0
|
|
ORDER BY dateUpdate DESC");
|
|
if ($stmt->rowCount() > 0) {
|
|
$dateUpdatePre = null;
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if ($row['naissance_date'] != '0000-00-00') {
|
|
$dateNaiss = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['naissance_date']);
|
|
} else {
|
|
$dateNaiss = '';
|
|
}
|
|
if ($row['flux'] != '0000-00-00') {
|
|
$dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['flux']);
|
|
} else {
|
|
$dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['dateInsert']);
|
|
}
|
|
|
|
if ($dateUpdatePre === null) {
|
|
$dateUpdatePre = $row['dateUpdate'];
|
|
}
|
|
if ($row['dateUpdate'] != $dateUpdatePre) {
|
|
break;
|
|
}
|
|
$tabRet[] = array(
|
|
'Fonction' => $row['fonction_code'],
|
|
'Titre' => $row['fonction_lib'],
|
|
'Siren' => $row['dirSiren'],
|
|
'Societe' => $row['dirRS'],
|
|
'Civilite' => $row['civilite'],
|
|
'Nom' => trim($dir['nom']),
|
|
'Prenom' => $row['prenom'],
|
|
'NomUsage' => '',
|
|
'NaissDate' => $dateNaiss,
|
|
'NaissVille' => $row['naissance_lieu'],
|
|
'NaissDepPays' => '', // 25
|
|
'Ancien' => 1,
|
|
'DateFct' => $dateModif, //Format AAAA-MM-DD
|
|
'Cinf' => $row['cinf'],
|
|
);
|
|
$dateUpdatePre = $row['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 = '';
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT SIREN, CJ, CIVILITE, DIR_DATEN, DIR_LIEUN
|
|
FROM insee.identite WHERE SIREN=$siren AND (DIR_DATEN>0 OR DIR_LIEUN != '')
|
|
ORDER BY DIR_DATEN DESC, DIR_LIEUN DESC");
|
|
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
|
|
$tabRet[] = array(
|
|
'Titre' => 'Personne physique',
|
|
'Societe' => '',
|
|
'Civilite' => $civilite,
|
|
'Nom' => trim($nom),
|
|
'Prenom' => trim($prenom),
|
|
'NomUsage' => '',
|
|
'NaissDate' => Metier_Util_Date::dateT('Ymd', 'd/m/Y', $row['DIR_DATEN']),
|
|
'NaissVille' => $row['DIR_LIEUN'],
|
|
'NaissDepPays' => '',
|
|
'Ancien' => 0,
|
|
'DateFct' => $tabIdentite['DateCrea'],
|
|
);
|
|
|
|
$this->conn->insert('jo.rncs_dirigeants', array(
|
|
'siren' => $siren,
|
|
'raisonSociale' => $etab['Nom'],
|
|
'civilite' => $civilite,
|
|
'nom' => trim($nom),
|
|
'prenom' => trim($prenom),
|
|
'naissance_nom' => '',
|
|
'naissance_date'=> $row['DIR_DATEN'],
|
|
'naissance_lieu'=> $row['DIR_LIEUN'],
|
|
'fonction_code' => 1050,
|
|
'fonction_lib' => 'Personne physique',
|
|
'actif' => 1,
|
|
'dateInsert' => date('YmdHis'),
|
|
'source' => 'inp',
|
|
));
|
|
}
|
|
}
|
|
|
|
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";
|
|
$stmt = $this->conn->executeQuery($sql);
|
|
|
|
$nb = 0;
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$nb = $result->nb;
|
|
}
|
|
|
|
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 getAnnoncesLegalesEffacement($siren, $rubrique, $tabRet)
|
|
{
|
|
$effacement = 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();
|
|
$stmt = $this->conn->executeQuery("SELECT codEven, affProcol FROM jo.tabEvenements WHERE affProcol>0");
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabNoProcol[$row['codEven']] = $row['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);
|
|
}
|
|
$effacement = true;
|
|
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);
|
|
}
|
|
$effacement = true;
|
|
} 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) {
|
|
$effacement = true;
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
$effacement = true;
|
|
}
|
|
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);
|
|
$effacement = true;
|
|
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(false);
|
|
$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);
|
|
$effacement = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// --- 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);
|
|
$effacement = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $effacement;
|
|
}
|
|
|
|
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)
|
|
{
|
|
$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')";
|
|
}
|
|
}
|
|
$stmt = $this->conn->executeQuery($sql);
|
|
|
|
// --- Traitement des resultats
|
|
if ($stmt->rowCount() > 0) {
|
|
// --- Identite Light de l'entité
|
|
if ($this->Identite === null) {
|
|
$this->Identite = $this->getIdentiteLight($siren);
|
|
}
|
|
// --- Parcours des annonces
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
// --- 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'])).'. ';
|
|
}
|
|
|
|
for ($mandNum = 1; $mandNum < 5; $mandNum++) {
|
|
if (trim($ann['inter'.$mandNum.'type']) != ''
|
|
&& ($ann['inter'.$mandNum.'id']>0 || trim($ann['inter'.$mandNum.'nom']) != '')) {
|
|
$texteAnnonce.= $tabInter[$ann['inter'.$mandNum.'type']].' : '.$ann['inter'.$mandNum.'nom'];
|
|
if ($ann['inter'.$mandNum.'id'] != 0) {
|
|
$mandStmt = $this->conn->executeQuery("SELECT sirenGrp, sirenMand,
|
|
tel, fax, email FROM jo.tabMandataires
|
|
WHERE id=".$ann['inter'.$mandNum.'id']);
|
|
$mand = $mandStmt->fetch(\PDO::FETCH_ASSOC);
|
|
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) {
|
|
if ($this->getAnnoncesLegalesEffacement($siren, $rubrique, $tabRet) === true) {
|
|
return 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();
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT Societe_Rcs, Categorie, Num_Affaire, Date_Parution,
|
|
Num_Parution, Url_Annonce_Html, Url_Annonce_Pdf, Annonce_Html, dateInsert
|
|
FROM jo.balo WHERE Societe_Rcs='$siren' $strIdAnn ORDER BY Date_Parution DESC, Num_Affaire LIMIT $offset, $lignes");
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabRetEven = array( 0 => array(
|
|
'CodeEven' => $mBalo->getLibEven($row['Categorie']),
|
|
'LibEven' => $row['Categorie']
|
|
));
|
|
}
|
|
|
|
$texte = '';
|
|
if ($idAnnonce != 0) {
|
|
$texte = strtr(
|
|
preg_replace('/<html.*<body.*>/Uis', '',
|
|
preg_replace('/( class=".*")/ie', ' ', $row['Annonce_Html'])),
|
|
array(' '=>' ', '</html>'=>'', '</body>'=>'')
|
|
);
|
|
}
|
|
|
|
$tabRet[] = array(
|
|
'id' => $row['Num_Affaire'].'.'.$row['Num_Parution'],
|
|
'BodaccCode' => 'BALO',
|
|
'BodaccNum' => $row['Num_Parution'],
|
|
'NumAnnonce' => $row['Num_Affaire'],
|
|
'DateParution' => $row['Date_Parution'],
|
|
'typeAnnonce' => 'Insertion',
|
|
'dateInsertionSD' => $row['dateInsert'],
|
|
'evenements' => $tabRetEven,
|
|
'Lien_Annonce_Pdf' => basename($row['Url_Annonce_Pdf']),
|
|
'texteAnnonce' => $texte,
|
|
);
|
|
}
|
|
}
|
|
|
|
return $tabRet;
|
|
}
|
|
|
|
/**
|
|
* Retourne le nombre d'annonce Balo pour un siren
|
|
* @param string $siren
|
|
* @return int
|
|
*/
|
|
public function getAnnoncesBaloCount($siren)
|
|
{
|
|
$nb = 0;
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT COUNT(*) AS nb FROM jo.balo WHERE Societe_Rcs='$siren' ORDER BY Date_Parution DESC, Num_Affaire");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->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 = "";
|
|
}
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.boamp_lots l, jo.boamp b, jo.boamp_detail d
|
|
WHERE 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");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$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';
|
|
}
|
|
$objetMarche = trim($ann['objet'].' '.$ann['objetAutre'].' '.$ann['autres']);
|
|
if ($idA != 0) {
|
|
if ($ann['Boamp_Code'] == 'MAPA') {
|
|
$texte = $ann['annonce'];
|
|
} else {
|
|
$texte = strtr(preg_replace('/<html.*<body.*>/Uis', '',
|
|
preg_replace('/<p\s+.*>/Uis', '',
|
|
preg_replace('/( class=".*")/ie', ' ', $ann['annonce']))),
|
|
array(' '=>' ', '</html>'=>'', '</body>'=>'', '</p>'=>'<br/>')
|
|
);
|
|
}
|
|
}
|
|
$tabRet[] = array(
|
|
'id' => 'A.'.$ann['id'],
|
|
'BodaccCode' => $ann['Boamp_Code'],
|
|
'BodaccNum' => $ann['Boamp_Num'],
|
|
'NumAnnonce' => $numAnn,
|
|
'DateParution' => $ann['Boamp_Date_Parution'],
|
|
'Departement' => $ann['Boamp_Dept'],
|
|
'typeAnnonce' => $ann['typeAnnonce'],
|
|
'dateInsertionSD' => $ann['dateInsert'],
|
|
'Montant' => $ann['montant'],
|
|
'Organisme' => strtoupper($ann['raisonSociale']),
|
|
'Objet' => $objetMarche,
|
|
'evenements' => $tabRetEven,
|
|
'infosComp' => '',
|
|
'Lien_Annonce_Html' => $lienMapa,
|
|
'texteAnnonce' => $texte,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- 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 = "";
|
|
}
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM jo.boamp b, jo.boamp_detail d
|
|
WHERE d.siren=$siren AND d.id=b.id $strIdAnn GROUP BY b.id ORDER BY d.Boamp_Date_Parution DESC");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$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
|
|
) {
|
|
$stmt2 = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.boamp_lots l
|
|
WHERE l.idAnn=$id");
|
|
while ($ann2 = $stmt2->fetch(\PDO::FETCH_ASSOC)) {
|
|
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';
|
|
} 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';
|
|
}
|
|
if ($idA != 0) {
|
|
if ($ann['Boamp_Code'] == 'MAPA') {
|
|
$texte = $ann['annonce'];
|
|
} else {
|
|
$texte = strtr(preg_replace('/<html.*<body.*>/Uis', '',
|
|
preg_replace('/<p\s+.*>/Uis', '',
|
|
preg_replace('/( class=".*")/ie', ' ', $ann['annonce']))),
|
|
array(' '=>' ', '</html>'=>'', '</body>'=>'', '</p>'=>'<br/>')
|
|
);
|
|
}
|
|
}
|
|
$tabRet[] = array(
|
|
'id' => 'O.'.$id,
|
|
'BodaccCode' => $ann['Boamp_Code'],
|
|
'BodaccNum' => $ann['Boamp_Num'],
|
|
'NumAnnonce' => $numAnn,
|
|
'DateParution' => $ann['Boamp_Date_Parution'],
|
|
'Departement' => $ann['Boamp_Dept'],
|
|
'typeAnnonce' => $ann['typeAnnonce'],
|
|
'dateInsertionSD' => $ann['dateInsert'],
|
|
'evenements' => $tabRetEven,
|
|
'infosComp' => '',
|
|
'Lien_Annonce_Html' => $lienMapa,
|
|
'texteAnnonce' => $texte,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = 0;
|
|
$bodaccM = 0;
|
|
|
|
// --- Recherche dans les avis d'attribution
|
|
if ($type=='' || $type=='A') {
|
|
$stmt = $this->conn->executeQuery("SELECT COUNT(l.id) AS nb FROM jo.boamp_lots l, jo.boamp b, jo.boamp_detail d
|
|
WHERE l.siren=$siren AND l.idAnn=b.id AND l.idAnn=d.id GROUP BY b.id ORDER BY l.Boamp_Date_Parution");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$bodaccA = $result->nb;
|
|
}
|
|
}
|
|
|
|
// --- Recherche dans les avis de marchés
|
|
if ($type=='' || $type=='M') {
|
|
$stmt = $this->conn->executeQuery("SELECT COUNT(d.id) AS nb FROM jo.boamp b, jo.boamp_detail d
|
|
WHERE d.siren=$siren AND d.id=b.id GROUP BY b.id ORDER BY d.Boamp_Date_Parution DESC");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$bodaccM = $result->nb;
|
|
}
|
|
}
|
|
|
|
return $bodaccA + $bodaccM;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @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";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM jo.asso WHERE $strIdAnn AND dateSuppr=0 ORDER BY Date_Parution DESC LIMIT $offset,$lignes");
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tabEven = explode(';', $row['codEven']);
|
|
$tabRetEven = array();
|
|
if ($row['typeAnnonce'] != 'Insertion') {
|
|
$tabRetEven[] = array(
|
|
'CodeEven'=>'0000',
|
|
'LibEven'=> $row['typeAnnonce'].' de l\'annonce du '.
|
|
Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $row['corrDate_Parution'])
|
|
);
|
|
} else {
|
|
if (trim($row['codEven']) != '') {
|
|
foreach ($tabEven as $even) {
|
|
$tabRetEven[] = array(
|
|
'CodeEven' => $even,
|
|
'LibEven' => $this->iBodacc->getEvenement($even)
|
|
);
|
|
}
|
|
} else {
|
|
$tabRetEven[] = array(
|
|
'CodeEven' => 0000,
|
|
'LibEven' => $row['Type_Annonce']
|
|
);
|
|
}
|
|
}
|
|
|
|
// Rubrique
|
|
if (preg_match('/cr(é|e)ation/iu', $row['Type_Annonce'])) {
|
|
$rub = 'creations';
|
|
} elseif (preg_match('/Dissolution/i', $row['Type_Annonce'])) {
|
|
$rub = 'radiations';
|
|
} else {
|
|
$rub = 'mmd';
|
|
}
|
|
|
|
// typeAnnonce
|
|
if (preg_match('/Annulation/i', $row['Type_Annonce'])) {
|
|
$type = 'Suppression';
|
|
} elseif (preg_match('/Rectif/i', $row['Type_Annonce'])) {
|
|
$type = 'Rectificatif';
|
|
} else {
|
|
$type = 'Insertion';
|
|
}
|
|
|
|
$dateInsert = '';
|
|
if (str_replace('-', '', $row['Date_Parution'])*1>=20070401) {
|
|
$dateInsert = $row['Date_Parution'];
|
|
}
|
|
|
|
$texte = '';
|
|
if ($idAnnonce != 0) {
|
|
if (mb_detect_encoding($row['Annonce_Html']) == 'UTF-8') {
|
|
$texte = utf8_decode($row['Annonce_Html']);
|
|
} else {
|
|
$texte = $row['Annonce_Html'];
|
|
}
|
|
}
|
|
|
|
$tabRet[] = array(
|
|
'id' => $row['id'],
|
|
'BodaccCode' => 'ASSO',
|
|
'BodaccNum' => $row['Num_Parution'],
|
|
'NumAnnonce' => $row['Num_Annonce'],
|
|
'DateParution' => $row['Date_Parution'],
|
|
'Departement' => $row['Departement'],
|
|
'Tribunal' => $row['Sous_Prefecture'],
|
|
'Rubrique' => $rub,
|
|
'typeAnnonce' => $type,
|
|
'dateInsertionSD' => $dateInsert,
|
|
'evenements' => $tabRetEven,
|
|
'texteAnnonce' => $texte,
|
|
);
|
|
}
|
|
}
|
|
|
|
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";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT COUNT(*) AS nb FROM jo.asso WHERE $strIdAnn AND dateSuppr=0");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->nb;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/** @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 **/
|
|
$stmt = $this->conn->executeQuery("SELECT raisonSociale, isin, nscrl, tel, fax, web, mail,
|
|
DATE(dateUpdate)*1 as dateUpdate FROM jo.infos_entrep WHERE siren=$siren");
|
|
if ($stmt->rowCount()) {
|
|
$idComp = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
// 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'];
|
|
}
|
|
|
|
return $tabRet;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $naf4
|
|
* @param number $dep
|
|
* @return boolean|multitype:[]
|
|
*/
|
|
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%')";
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT n.`id CC`, n.`nom CC`, n.`editeur CC`, n.`nb page CC`, n.`isbn CC`, n.`date edition CC`, c.infoCC, joCCmaj
|
|
FROM jo.conv_naf n, jo.conventions c WHERE n.naf='$naf4' AND substring(n.`id CC`,1,4)=c.numBrochure $strDep GROUP BY n.`id CC`");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
}
|
|
}
|
|
|
|
protected function findSiteWeb($rs)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $siren
|
|
* @param string $type
|
|
* @param string $annee
|
|
* @return boolean|multitype:[]
|
|
*/
|
|
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).')';
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT importExport, annee, rangNational, deptSiege
|
|
FROM jo.importExport WHERE siren=$siren $strImportExport $strAnnees ORDER BY annee DESC, importExport ASC");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Elements provenant du Notice 80 hors identité
|
|
* @param string $siren
|
|
* @param string $nic
|
|
* @return multitype:
|
|
*/
|
|
public function getInfosNotice($siren, $nic)
|
|
{
|
|
try {
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM insee.insee_notices WHERE insSIREN=$siren AND insNIC=$nic ORDER BY dateNotice DESC LIMIT 0,1");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
}
|
|
|
|
try {
|
|
$stmt = $this->conn->executeQuery("SELECT 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 FROM insee.insee_even WHERE insSIREN=$siren AND insNIC=$nic ORDER BY dateNotice DESC LIMIT 0,1");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $adresseNum
|
|
* @param unknown $adresseBtq
|
|
* @param unknown $adresseVoie
|
|
* @param unknown $adresseRue
|
|
* @param unknown $adresseComp
|
|
* @param unknown $cp
|
|
* @param unknown $ville
|
|
* @param string $active
|
|
* @return boolean|boolean|multitype:[]
|
|
*/
|
|
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 ";
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT id, siren, nic, enActif, etActif, procol, nom, nom2,
|
|
sigle, enseigne, adrNum, adrBtq, adrTypVoie, adrLibVoie, ville, cp, adrComp, adrDistSp,
|
|
cj, apen, apet, nbEntrep, dateInsert, dateUpdate FROM jo.tabAdrDom
|
|
WHERE adrNum=$num AND adrBtq='$indRep' AND adrTypVoie LIKE '%$typeVoie%' AND
|
|
adrLibVoie LIKE '%$libVoie%' AND cp=$cp $strAdrActive GROUP BY siren ORDER BY enActif DESC");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
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'];
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT NOM2, ADR_COMP, ADR_DISTSP, PAYS
|
|
FROM insee.identite WHERE SIREN=$siren AND NIC=$nic");
|
|
if ($stmt->rowCount() > 0) {
|
|
$tabIdentite = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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) {
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM insee.cedexa WHERE siren=$siren AND nic=$nic");
|
|
if ($stmt->rowCount() > 0) {
|
|
$tabCedex = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $siren
|
|
* @param number $nic
|
|
* @return mixed
|
|
*/
|
|
public 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";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT infoTel, count(*) AS nb FROM jo.telephonie
|
|
WHERE siren=$siren AND typeTel='an8' ORDER BY nb DESC LIMIT 0,1");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
if ($result->nb > 0) {
|
|
$an8en = $result->infoTel;
|
|
$stmt = $this->conn->executeQuery("SELECT infoTel FROM jo.telephonie
|
|
WHERE siren=$siren $strNic AND typeTel='an8' ORDER BY dateProvPartenaire DESC LIMIT 0,1");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$an8et = $result->infoTel;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Recherche des activités réglementées possibles Naf4&5 ou An8
|
|
$stmt = $this->conn->executeQuery("SELECT id, libActivite, listeActivite, naf5, naf4, codAn8, listeCJ, nomAutorite
|
|
FROM jo.tabActivReg WHERE naf5='$naf5en' OR naf5='$naf5et' OR naf4='$naf4en' OR naf4='$naf4et' OR codAn8='$an8en' OR codAn8='$an8et'");
|
|
if ($stmt->rowCount()) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
// Filtre 'listeActivite' : Si défini, on recherche la présence de mots dans l'activité
|
|
if (trim($row['listeActivite']) != '') {
|
|
$ok = false;
|
|
$tabTmp = explode(';', trim($row['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($row['listeCJ']) != '') {
|
|
$ok = false;
|
|
$tabTmp = explode(';', trim($row['listeCJ']));
|
|
foreach ($tabTmp as $strTmp) {
|
|
if (preg_match("/^$strTmp/", $fj)) {
|
|
$ok = true;
|
|
}
|
|
}
|
|
if (!$ok) {
|
|
continue;
|
|
}
|
|
}
|
|
return array(
|
|
'idActivite' => $row['id'],
|
|
'libActivite' => $row['libActivite'],
|
|
'nomAutorite' => $row['nomAutorite'],
|
|
);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $naf5
|
|
* @return string|string
|
|
*/
|
|
public function getCodeNace($naf5)
|
|
{
|
|
if ($naf5 != '') {
|
|
$this->setTabCodesNaf();
|
|
return $this->tabCodesNace[$naf5];
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $refClient
|
|
* @param unknown $idClient
|
|
* @param unknown $login
|
|
* @param number $deb
|
|
* @param number $nbRep
|
|
* @param number $maxRep
|
|
* @return array
|
|
*/
|
|
public function getEtabClients($refClient, $idClient, $login, $deb=0, $nbRep=20, $maxRep=200)
|
|
{
|
|
$this->setTabCodesNaf();
|
|
$deb = $deb*1;
|
|
$nbRep = $nbRep*1;
|
|
$limit = "LIMIT $deb, $nbRep";
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT '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 FROM jo.etablissements e, jo.surveillances_site s
|
|
WHERE 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");
|
|
|
|
$nbTot = $stmt->rowCount();
|
|
if ($nbTot > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$tel = sprintf('%010d', strtr($row['tel'], array('-'=>'', '/'=>'', '.'=>'', ','=>'')));
|
|
if ($tel != '0000000000') {
|
|
$tel = implode('.', str_split($tel, 2));
|
|
} else {
|
|
$tel='';
|
|
}
|
|
|
|
$fax = sprintf('%010d', strtr($row['fax'], array('-'=>'', '/'=>'', '.'=>'', ','=>'')));
|
|
if ($fax != '0000000000') {
|
|
$fax = implode('.', str_split($fax, 2));
|
|
} else {
|
|
$fax = '';
|
|
}
|
|
|
|
$tabRet[] = array(
|
|
'Localisation' => $row['Loc'],
|
|
'id' => $row['id'],
|
|
'Pertinence' => 100,
|
|
'Siret' => $row['siret'],
|
|
'Siege' => $row['siege'],
|
|
'Nom' => $row['raisonSociale'],
|
|
'Sigle' => $row['sigle'],
|
|
'Enseigne' => $row['enseigne'],
|
|
'Adresse' => trim(preg_replace('/ +/', ' ',
|
|
trim($row['adr_num'] .' '. $$row['adr_btq'] .' '. $row['adr_typeVoie']
|
|
.' '. $row['adr_libVoie']))),
|
|
'Adresse2' => trim(preg_replace('/ +/', ' ', $row['adr_comp'])),
|
|
'CP' => $row['adr_cp'],
|
|
'Ville' => $row['adr_ville'],
|
|
'Tel' => $tel,
|
|
'Fax' => $fax,
|
|
'FJ' => $row['cj'],
|
|
'FJLib' => $this->getLibelleFJ($row['cj']),
|
|
'Siren' => $row['siren'],
|
|
'Nic' => $row['nic'],
|
|
'Actif' => $row['actif'],
|
|
'NafEtab' => $row['ape_etab'], // Etablissement
|
|
'NafEnt' => $row['ape_entrep'], // Entreprise
|
|
'NafEtabLib' => $this->getLibelleNaf($row['ape_etab']),
|
|
'NafEntLib' => $this->getLibelleNaf($row['ape_entrep']),
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
// Evite l'affichage d'un 0 inutile sur l'Extranet
|
|
if ($dep==0) {
|
|
$dep='';
|
|
}
|
|
|
|
return array(
|
|
'criteres' => array('siren'=>$siren, 'nic'=>$nic, 'dep'=>$dep),
|
|
'nbReponses' => count($tabRet),
|
|
'nbReponsesTotal' => $nbTot,
|
|
'reponses' => $tabRet);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $siren
|
|
* @param string $nic
|
|
* @return boolean|boolean|string[]|boolean[]|unknown[]|mixed[]|NULL[]
|
|
*/
|
|
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";
|
|
}
|
|
$stmt = $this->conn->executeQuery("SELECT 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
|
|
FROM insee.insee_avis WHERE siren=$siren $strNic");
|
|
$tabInfos = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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->conn->insert('insee.insee_avis', $tabInsert);
|
|
if (preg_match("/droit d'opposition/", $tabInsert['erreurs'])) {
|
|
$this->conn->insert('insee.insee_nondiff', array(
|
|
'siren' => $siren,
|
|
'dateInsert' => date('YmdHis')
|
|
));
|
|
}
|
|
$tabInfos['enCache'] = false;
|
|
} else {
|
|
return false;
|
|
}
|
|
return $tabInfos;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $naf
|
|
* @return array
|
|
*/
|
|
public function listeProduits($naf)
|
|
{
|
|
$tabRet = array();
|
|
$stmt = $this->conn->executeQuery("SELECT codCpf, libCpf FROM insee.tabCpf WHERE codCpf IN (SELECT cpf FROM insee.tabNafCpf WHERE naf='$naf')");
|
|
|
|
if ($stmt->rowCount()) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
$tabRet[$row->codCpf] = $row->libCpf;
|
|
}
|
|
|
|
return $tabRet;
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
* 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='')
|
|
{
|
|
$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
|
|
$stmt = $this->conn->executeQuery("SELECT codeOPS, libInstitution, codeAnnexe, Limitations
|
|
FROM sdv1.retraiteNaf WHERE naf5='$naf5' or naf5='$naf4'");
|
|
if ($stmt->rowCount() == 1) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
$limite = $row['Limitations'];
|
|
if ($row['codeOPS'] != null) {
|
|
return $row['codeOPS'];
|
|
} elseif ($row['Annexe'] != '') {
|
|
$annexe = $row['Annexe'];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Recherche par Département
|
|
$stmt = $this->conn->executeQuery("SELECT codeOPS, libInstitution
|
|
FROM sdv1.retraiteDep
|
|
WHERE codeDep=$dep AND codeAnnexe IN ('$annexe','A','B') GROUP BY codeAnnexe ASC");
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if ($row['codeOPS'] != '') {
|
|
return $row['codeOPS'];
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Info OPS
|
|
* @param unknown $idOPS
|
|
* @return unknown
|
|
*/
|
|
public function getInfoOPS($idOPS)
|
|
{
|
|
$stmt = $this->conn->executeQuery(
|
|
"SELECT siren,nic,codeOPS,nomLong,nomCourt,adresse1,adresse2,cp,ville,groupe,declaration,rattachement,codeOPSdest
|
|
FROM sdv1.retraiteCaisses WHERE codeOPS='$idOPS'");
|
|
if ($stmt->rowCount()) {
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
* Retourne la date de changement de statut de siège à établissment secondaire pour un établissement donné
|
|
* @param string $siren
|
|
* Siren de l'entreprise
|
|
* @param string $nic
|
|
* Nic de l'étabissement
|
|
*/
|
|
public function isAncienSiege($siren, $nic)
|
|
{
|
|
$stmt = $this->conn->executeQuery(
|
|
"SELECT 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
|
|
FROM insee.insee_even WHERE insSIREN=$siren AND insNIC=$nic AND insMNICSIEGE=1 ORDER BY insDATEVE DESC LIMIT 0,1");
|
|
if ($stmt->rowCount()) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insDATEVE;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
|
|
$datePre = $dateSuc = 0;
|
|
$nicPre = $nicSuc = 0;
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT 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 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%')
|
|
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%')
|
|
)");
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if ($row['sirVersion'] == 4) {
|
|
if (in_array($row['insEVE'], array('CTE', 'CTS', 'MTAE', 'MTAS'))) {
|
|
$typeLien = 'suc';
|
|
} elseif (in_array($row['insEVE'], array('STE', 'STS', 'MTDE', 'MTDS'))) {
|
|
$typeLien = 'pre';
|
|
} else {
|
|
$typeLien = 'ind';
|
|
}
|
|
} else {
|
|
switch ($row['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 ($row['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;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Le NIC prédécesseur ne peut pas être le NIC actuel
|
|
if ($nicPre > 0 && $nicPre == $row['insNIC']) {
|
|
continue;
|
|
}
|
|
// Le NIC successeur ne peut pas être le NIC actuel
|
|
if ($nicSuc > 0 && $nicSuc == $row['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 = $row['insDATEVE'];
|
|
$nicPre = $row['insNIC'];
|
|
}
|
|
if ($typeLien == 'suc') {
|
|
$dateSuc = $row['insDATEVE'];
|
|
$nicSuc = $row['insNIC'];
|
|
}
|
|
|
|
// Data
|
|
$adr1 = $row['insL1_NOMEN'];
|
|
if ($adr1 == null) {
|
|
$adr1 = $row['insNOMEN'];
|
|
}
|
|
$adr2 = $row['insL2_COMP'];
|
|
if ($adr2 == null) {
|
|
$adr2 = $row['insENSEIGNE'];
|
|
}
|
|
$adr4 = $row['insL4_VOIE'];
|
|
if ($adr4 == null) {
|
|
$adr4 = preg_replace('/ +/', ' ', $row['insNUMVOIE'].' '.$row['insINDREP'].' '.
|
|
$row['insTYPVOIE'].' '.$row['insLIBVOIE']);
|
|
}
|
|
|
|
$tabRet[$typeLien] = array(
|
|
'siren' => $row['insSIREN'],
|
|
'nic' => $row['insNIC'],
|
|
'apeEtab' => $row['insAPET700'],
|
|
'codeEve' => $row['insEVE'],
|
|
'dateEve' => $row['insDATEVE'],
|
|
'adrL1' => trim($adr1),
|
|
'adrL2' => trim($adr2),
|
|
'adrL3' => trim($row['insL3_CADR']),
|
|
'adrL4' => trim($adr4),
|
|
'adrL5' => trim($row['insL5_DISP']),
|
|
'adrL6' => trim($row['insL6_POST']),
|
|
'adrL7' => trim($row['insL7_ETRG']),
|
|
'depCom' => $row['insDEPCOM'],
|
|
'rivoli' => $row['insCODEVOIE'],
|
|
'siege' => $row['insSIEGE'],
|
|
'destinat' => $row['insDESTINAT'],
|
|
'typEtab' => $row['insTYPETAB'],
|
|
'origine' => $row['insORIGINE'],
|
|
);
|
|
}
|
|
}
|
|
|
|
return $tabRet;
|
|
}
|
|
|
|
/**
|
|
* Info Sirene
|
|
* @param unknown $dept
|
|
* @param unknown $siren
|
|
* @param string $apen
|
|
* @return string[]|unknown[]|mixed[]
|
|
*/
|
|
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';
|
|
}
|
|
}
|
|
|
|
$stmt = $this->conn->prepare("SELECT siret,nom,adr1,adr2,adr3,cp,ville,tel,fax FROM insee.insee_drsiren WHERE dept = :dept");
|
|
$stmt->bindValue('dept', $dept);
|
|
$stmt->execute();
|
|
$ret = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
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']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Informations Iris
|
|
* @param unknown $codeCommune
|
|
* @param unknown $codeRivoli
|
|
* @param unknown $adrNum
|
|
* @param unknown $adrIndRep
|
|
* @param unknown $adrTypVoie
|
|
* @param unknown $adrLibVoie
|
|
* @return array
|
|
*/
|
|
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',
|
|
);
|
|
$result = null;
|
|
if (trim($codeRivoli) == '') {
|
|
$adrLibVoie2 = addslashes($adrLibVoie);
|
|
$stmt = $this->conn->executeQuery("SELECT codeInsee, codeIris, rivoli, typVoie, libVoie, typeNum, numd,indd, numf, indf, codeInseeIris
|
|
FROM insee.iris WHERE codeInsee='$codeCommune' AND libVoie LIKE '$adrLibVoie2%' GROUP BY codeInsee, rivoli");
|
|
if ($stmt->rowCount() == 1) {
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
$codeRivoli = $result['rivoli'];
|
|
} elseif ($stmt->rowCount() > 1 && $adrLibVoie != '') {
|
|
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
if ($result['typVoie'] == strtoupper($adrTypVoie)) {
|
|
$codeRivoli = $result['rivoli'];
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
return array();
|
|
}
|
|
}
|
|
|
|
$adrNum = intval($adrNum);
|
|
$stmt = $this->conn->executeQuery("SELECT codeInsee, codeIris, rivoli, codeInseeIris
|
|
FROM insee.iris WHERE codeInsee='$codeCommune' AND rivoli LIKE '$codeRivoli%' GROUP BY codeInseeIris");
|
|
$strAdr = '';
|
|
if ($stmt->rowCount() > 1) {
|
|
// Numéro impaire
|
|
if ($adrNum > 0 && $adrNum&1) {
|
|
$strAdr = "AND typeNum=1 AND $adrNum BETWEEN numd AND numf ";
|
|
}
|
|
// Numéro paire
|
|
elseif ($adrNum >= 0) {
|
|
$strAdr = "AND typeNum=2 AND $adrNum BETWEEN numd AND numf ";
|
|
}
|
|
|
|
$stmt2 = $this->conn->executeQuery("SELECT codeInsee, codeIris, rivoli, codeInseeIris, numd, indd, numf, indf
|
|
FROM insee.iris WHERE codeInsee='$codeCommune' AND rivoli LIKE '$codeRivoli%' $strAdr GROUP BY codeInseeIris");
|
|
if ($stmt2->rowCount() == 1) {
|
|
$result = $stmt2->fetch(\PDO::FETCH_ASSOC);
|
|
} elseif ($stmt2->rowCount() > 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;
|
|
while ($row = $stmt2->fetch(\PDO::FETCH_ASSOC)) {
|
|
$numIrisDeb = $row['numd'] + ord(strtoupper($row['indd'])) / 100;
|
|
$numIrisFin = $row['numf'] + ord(strtoupper($row['indf'])) / 100;
|
|
// Le numéro de la rue correspond au début de la tranche des numéros IRIS
|
|
if ($adrNum = $row['numd'] && $numAdrRep >= $numIrisDeb) {
|
|
$result = $row;
|
|
break;
|
|
}
|
|
// Le numéro de la rue correspond à la fin de la tranche des numéros IRIS
|
|
elseif ($adrNum = $row['numf'] && $numAdrRep <= $numIrisFin) {
|
|
$result = $row;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($result === null) {
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
}
|
|
|
|
if ($result !== null || $codeRivoli == '') {
|
|
$codeIris = $result['codeIris'];
|
|
$codeComIris = $result['codeInseeIris'];
|
|
$stmt = $this->conn->executeQuery("SELECT CODE_IRIS AS codeInseeIris, SUBSTRING(CODE_IRIS,6,4) AS codeIris, LIB_IRIS, TYP_IRIS, MODIF_IRIS, TRIRIS, GRD_QUART
|
|
FROM insee.insee_tabIris WHERE DEPCOM='$codeCommune' AND (TYP_IRIS='Z' OR CODE_IRIS='$codeComIris')");
|
|
if ($stmt->rowCount()) {
|
|
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
return array(
|
|
'codIris' => $row['codeIris'],
|
|
'codComIris' => $row['codeInseeIris'],
|
|
'libIris' => $row['LIB_IRIS'],
|
|
'typIris' => $tabTypeIris[$row['TYP_IRIS']],
|
|
'evoIris' => $row['MODIF_IRIS'],
|
|
'trIris' => $row['TRIRIS'],
|
|
'grdQuartier' => $row['GRD_QUART'],
|
|
'rivoli' => $codeRivoli,
|
|
);
|
|
}
|
|
}
|
|
|
|
if ($result) {
|
|
return $result;
|
|
}
|
|
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
// 9 : 200 millions d'euros ou plus)
|
|
if ($montantCA >= 200000000) {
|
|
return 9;
|
|
}
|
|
// 8 : De 100 millions à moins de 200 millions d'euros
|
|
elseif ($montantCA >= 100000000) {
|
|
return 8;
|
|
}
|
|
// 7 : De 50 millions à moins de 100 millions d'euros
|
|
elseif ($montantCA >= 50000000) {
|
|
return 7;
|
|
}
|
|
// 6 : De 20 millions à moins de 50 millions d'euros
|
|
elseif ($montantCA >= 20000000) {
|
|
return 6;
|
|
}
|
|
// 5 : De 10 millions à moins de 20 millions d'euros
|
|
elseif ($montantCA >= 10000000) {
|
|
return 5;
|
|
}
|
|
// 4 : De 5 millions à moins de 10 millions d'euros
|
|
elseif ($montantCA >= 5000000) {
|
|
return 4;
|
|
}
|
|
// 3 : De 2 millions à moins de 5 millions d'euros
|
|
elseif ($montantCA >= 2000000) {
|
|
return 3;
|
|
}
|
|
// 2 : De 1 million à moins de 2 millions d'euros
|
|
elseif ($montantCA >= 1000000) {
|
|
return 2;
|
|
}
|
|
// 1 : De 0,5 à moins de 1 million d'euros
|
|
elseif ($montantCA >= 500000) {
|
|
return 1;
|
|
}
|
|
// Non renseignée ou moins de 0,5 million d'euros
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$stmt = $this->conn->prepare("SELECT id, naf5, annee, SUM(montant), SUM(nombre), SUM(montant)/SUM(nombre) AS moyenne
|
|
FROM jo.ratios_secteurs WHERE 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");
|
|
$stmt->bindValue('naf', $naf);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
$caSecteur = round($result->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' ";
|
|
}
|
|
|
|
$stmt = $this->conn->executeQuery("SELECT codComInsee, idVoieCom, cleRivoli, voieNature, voieLib, 1 AS score
|
|
FROM insee.fantoirVoi WHERE codComInsee='$codeCommune' $strTypesVoies AND voieLib='$adrLibVoie2'");
|
|
if ($stmt->rowCount() == 0) {
|
|
return '';
|
|
} else {
|
|
while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
|
if (($row->voieNature == $typeVoieOff || $row->voieNature == $typeVoieNoff)
|
|
&& $row->voieLib == $adrLibVoie) {
|
|
$codeVoie = $row->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 < :date ORDER BY insDATEMAJ DESC LIMIT 1";
|
|
|
|
switch (strtoupper($even)) {
|
|
case 'NOMEN':
|
|
$stmt = $this->conn->prepare("SELECT insNOMEN FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insNOMEN;
|
|
}
|
|
break;
|
|
case 'SIGLE':
|
|
$stmt = $this->conn->prepare("SELECT insSIGLE FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insSIGLE;
|
|
}
|
|
break;
|
|
case 'APEN':
|
|
$stmt = $this->conn->prepare("SELECT insAPEN700 FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insAPEN700;
|
|
}
|
|
break;
|
|
case 'APET':
|
|
if (!empty($nic)) {
|
|
$sqlIdentifiant.= " AND insNIC = :nic";
|
|
}
|
|
$stmt = $this->conn->prepare("SELECT insAPET700 FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('nic', $nic);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insAPET700;
|
|
}
|
|
break;
|
|
case 'NICSIEGE':
|
|
$stmt = $this->conn->prepare("SELECT insNICSIEGE FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insNICSIEGE;
|
|
}
|
|
break;
|
|
case 'CJ':
|
|
$stmt = $this->conn->prepare("SELECT insCJ FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insCJ;
|
|
}
|
|
break;
|
|
case 'ENSEIGNE':
|
|
if (!empty($nic)) {
|
|
$sqlIdentifiant.= " AND insNIC = :nic";
|
|
}
|
|
$stmt = $this->conn->prepare("SELECT insENSEIGNE FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('nic', $nic);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $result->insENSEIGNE;
|
|
}
|
|
break;
|
|
case 'ADRESSE':
|
|
if (!empty($nic)) {
|
|
$sqlIdentifiant.= " AND insNIC = :nic";
|
|
}
|
|
$stmt = $this->conn->prepare("SELECT insL2_COMP, insL3_CADR, insL4_VOIE, insL5_DISP, insL6_POST, insL7_ETRG FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('nic', $nic);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$row = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $row->insL2_COMP.' '.
|
|
$row->insL3_CADR.' '.
|
|
$row->insL4_VOIE.' '.
|
|
$row->insL5_DISP.' '.
|
|
$row->insL6_POST.' '.
|
|
$row->insL7_ETRG.' ';
|
|
}
|
|
|
|
break;
|
|
case 'EFFECTIF':
|
|
if (!empty($nic)) {
|
|
$sqlIdentifiant.= " AND insNIC = :nic";
|
|
}
|
|
$stmt = $this->conn->prepare("SELECT insEFENCENT, insTEFET FROM insee.insee_even WHERE $sqlIdentifiant AND $where");
|
|
$stmt->bindValue('siren', $siren);
|
|
$stmt->bindValue('nic', $nic);
|
|
$stmt->bindValue('date', $dateEven);
|
|
$stmt->execute();
|
|
if ($stmt->rowCount() > 0) {
|
|
$row = $stmt->fetch(\PDO::FETCH_OBJ);
|
|
return $row->insEFENCENT . ' (Tranche '.$row->insTEFET . ')';
|
|
}
|
|
break;
|
|
}
|
|
|
|
return '';
|
|
}
|
|
}
|