From 55a21524b02ead607363e5dc96e2f0812236adc1 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 2 Feb 2017 10:00:45 +0100 Subject: [PATCH] Library update --- library/Metier/Bodacc/MBodacc.php | 251 +- library/Metier/Insee/MInsee.php | 3149 ++++++++++++--------- library/Metier/Partenaires/MAmabis.php | 104 +- library/Metier/Partenaires/MFacto.php | 76 +- library/Metier/Partenaires/MMap.php | 6 + library/Metier/Partenaires/MTva.php | 68 +- library/Metier/Util/Db.php | 19 +- library/Scores/Ws/Server.php | 17 +- library/SphinxSearch/sphinxapi-2.2.10.php | 68 +- library/SphinxSearch/sphinxapi-2.2.9.php | 68 +- 10 files changed, 2360 insertions(+), 1466 deletions(-) diff --git a/library/Metier/Bodacc/MBodacc.php b/library/Metier/Bodacc/MBodacc.php index 601652e3..00206241 100644 --- a/library/Metier/Bodacc/MBodacc.php +++ b/library/Metier/Bodacc/MBodacc.php @@ -493,6 +493,12 @@ class Metier_Bodacc_MBodacc */ protected $conn; + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + /** * Bodacc * @param \Doctrine\DBAL\Connection $conn @@ -505,6 +511,10 @@ class Metier_Bodacc_MBodacc $this->conn = $conn; } + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } + /* Charge toute la table des tribunaux pour ne pas lancer systématiquement des * requètes sur le serveur MySQL lors des intégrations de Bodacc */ @@ -545,11 +555,18 @@ class Metier_Bodacc_MBodacc return include $cache; } else { $tribunaux = array(); - $sql = "SELECT triCode, triNom, triCP, triSiret FROM jo.tribunaux WHERE triCode IS NOT NULL"; - $stmt = $this->conn->prepare($sql); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($t = $stmt->fetch(\PDO::FETCH_OBJ)) { $dep = intval(substr($t->triCP, 0, 2)); if ($dep == 97 || $dep == 98) { @@ -578,11 +595,18 @@ class Metier_Bodacc_MBodacc return include $cache; } else { $result = array(); - $sql = "SELECT codeFct, libelle FROM jo.bodacc_fonctions"; - $stmt = $this->conn->prepare($sql); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { $result[intval($row->codeFct)] = $row->libelle; } @@ -619,10 +643,18 @@ class Metier_Bodacc_MBodacc FROM jo.tribunaux t, jo.tribunauxInsee i WHERE i.CodeInsee= :inseeCode AND i.triId=t.triId ORDER BY t.triNumGreffe DESC, t.triId ASC"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('inseeCode', $codeInseeCommune); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('inseeCode', $codeInseeCommune); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); } @@ -643,16 +675,24 @@ class Metier_Bodacc_MBodacc t.triSiret, t.triAdrNum, t.triAdrIndRep, t.triAdrTypeVoie, t.triAdrVoie, t.triAdrComp, t.triVille, t.triStatut, t.triDateCessation, t.triCommentaire, t.triNumGreffe FROM jo.tribunaux t WHERE t.triCP BETWEEN :dep1 AND :dep2 ORDER BY t.triType ASC"; - $stmt = $this->conn->prepare($sql); - if ($dep < 96) { - $stmt->bindValue('dep1', $dep.'000'); - $stmt->bindValue('dep2', $dep.'999'); - } else { - $stmt->bindValue('dep1', $dep.'00'); - $stmt->bindValue('dep2', $dep.'99'); + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + if ($dep < 96) { + $stmt->bindValue('dep1', $dep.'000'); + $stmt->bindValue('dep2', $dep.'999'); + } else { + $stmt->bindValue('dep1', $dep.'00'); + $stmt->bindValue('dep2', $dep.'99'); + } + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } - $stmt->execute(); - if ($stmt->rowCount()) { + if ($stmtNb > 0) { $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); } @@ -666,10 +706,18 @@ class Metier_Bodacc_MBodacc public function getTribunalIdCA($codeTribunal) { $sql = "SELECT triIdSup FROM jo.tribunaux WHERE triCode = :code"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('code', $codeTribunal); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('code', $codeTribunal); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { return $stmt->fetch(\PDO::FETCH_ASSOC); } @@ -695,11 +743,18 @@ class Metier_Bodacc_MBodacc return include $cache; } else { $result = array(); - $sql = "SELECT codEven, libEven, Bodacc_Code, Rubrique, version, lienEtab FROM jo.tabEvenements"; - $stmt = $this->conn->prepare($sql); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { $result[$row->codEven] = array( 'libEven' => $row->libEven, @@ -726,11 +781,17 @@ class Metier_Bodacc_MBodacc return include $cache; } else { $result = array(); - $sql = "SELECT libDeviseBodacc, devIso FROM jo.bodacc_devises"; - $stmt = $this->conn->prepare($sql); - $stmt->execute(); - if ($stmt->rowCount()) { + try { + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { $result[$row->libDeviseBodacc] = $row->devIso; } @@ -1170,7 +1231,7 @@ class Metier_Bodacc_MBodacc } catch (\Doctrine\DBAL\DBALException $e) { continue; } - if ($stmt->rowCount()) { + if ($stmt->rowCount() > 0) { $tabPrenom = $stmt->fetch(\PDO::FETCH_ASSOC); // C'est plutôt le nom de famille au début de la chaîne if ($i == 0) { @@ -1209,12 +1270,20 @@ class Metier_Bodacc_MBodacc $sql = "SELECT Bodacc_Code, Bodacc_Annee_Parution, Bodacc_Num, Num_Annonce, Tribunal_Dept, Tribunal_Code, Rubrique_Bodacc, length(annonce) as Long FROM jo.bodacc WHERE Bodacc_Code=:code AND Bodacc_Annee_Parution=:annee AND Bodacc_Num=:num"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('code', $bodaccCode); - $stmt->bindValue('annee', $annee); - $stmt->bindValue('num', $num); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('code', $bodaccCode); + $stmt->bindValue('annee', $annee); + $stmt->bindValue('num', $num); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { $result[] = array( 'BodaccCode' => $ann->Bodacc_Code, @@ -1301,10 +1370,18 @@ class Metier_Bodacc_MBodacc $sql = "SELECT id, dep, nomJal, siteWeb, email, adresse, cp, ville, tel, fax, parution, aboAnnuel, infos FROM jo.tabJAL WHERE dep = :dep"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('dep', $dep); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('dep', $dep); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); } @@ -1316,10 +1393,18 @@ class Metier_Bodacc_MBodacc $result = array(); $sql = "SELECT id, nomJal FROM jo.tabJAL WHERE sedDateAbo!=0 GROUP BY nomJal ORDER BY nomJal ASC"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('dep', $dep); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('dep', $dep); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { $result['_'.$row->id] = $row->nomJal; } @@ -1338,37 +1423,69 @@ class Metier_Bodacc_MBodacc { $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%' "; $sql = "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"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('siren', $siren); - $stmt->execute(); - $annCap = $stmt->fetch(\PDO::FETCH_ASSOC); - if ($fj < 7000 || $fj > 7999) { - $activite = trim($annCap['Activite']); - } - - if ($activite == '' && ($fj > 90 && $fj < 94 || $fj > 9000 && $fj < 9400)) { - $sql = "SELECT Assoc_Objet, Assoc_NObjet FROM jo.asso WHERE siren=:siren AND (Assoc_Objet!='' OR Assoc_NObjet!='') ORDER BY Date_Parution DESC LIMIT 0,1"; + $stmtNb = 0; + try { $stmt = $this->conn->prepare($sql); $stmt->bindValue('siren', $siren); $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { $annCap = $stmt->fetch(\PDO::FETCH_ASSOC); - $activite = trim($annCap['Assoc_NObjet']); - if ($activite == '') { - $activite = trim($annCap['Assoc_Objet']); + if ($fj < 7000 || $fj > 7999) { + $activite = trim($annCap['Activite']); + } + } + + if ($activite == '' && ($fj > 90 && $fj < 94 || $fj > 9000 && $fj < 9400)) { + $sql = "SELECT Assoc_Objet, Assoc_NObjet FROM jo.asso + WHERE siren=:siren AND (Assoc_Objet!='' OR Assoc_NObjet!='') + ORDER BY Date_Parution DESC LIMIT 0,1"; + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { + $annCap = $stmt->fetch(\PDO::FETCH_ASSOC); + $activite = trim($annCap['Assoc_NObjet']); + if ($activite == '') { + $activite = trim($annCap['Assoc_Objet']); + } } } elseif ($activite == '' && ($fj < 7000 || $fj > 7999)) { $sql = "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"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('siren', $siren); - $stmt->execute(); - if ($stmt->rowCount()) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) { - if (($ann['CODEVE'] < 20) || ($ann['CODEVE'] >= 30 && $ann['CODEVE'] < 42) || ($ann['CODEVE'] >= 51 && $ann['CODEVE'] < 80)) { + 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) { + if (strpos(substr($matches[1], -20), 'cess') === false + && strpos(substr($matches[1], -20), 'date') === false) { $activite = $matches[2]; break; } diff --git a/library/Metier/Insee/MInsee.php b/library/Metier/Insee/MInsee.php index 1a6728b3..a0d4a849 100644 --- a/library/Metier/Insee/MInsee.php +++ b/library/Metier/Insee/MInsee.php @@ -80,10 +80,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table */ protected $conn; + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + protected $iDb; /** - * + * MInsee */ public function __construct($db = null) { @@ -98,6 +104,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $this->iBodacc = new Metier_Bodacc_MBodacc(); } + /** + * Set Logger from app registry + */ + public function setLogger() + { + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } + } + /** * Défini une date limite de prise en compte des événements * @param string $date AAAAMMJJ @@ -209,12 +225,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table elseif (!Metier_Util_String::valideData($numEtab, 1, 4, 'N')) { return -1; } else { - for ($cle=0; $cle<10; $cle++) { + for ($cle = 0; $cle < 10; $cle++) { if ($this->valideSiren($siren, ''.$nic.''.$cle)) { return $cle; } } } + return -1; } @@ -280,11 +297,18 @@ class Metier_Insee_MInsee extends Metier_Insee_Table return false; } - $stmt = $this->conn->prepare('SELECT CJ FROM insee.identite WHERE SIREN=:siren'); - $stmt->bindValue('siren', $siren); - $stmt->execute(); + try { + $stmt = $this->conn->prepare('SELECT CJ FROM insee.identite WHERE SIREN=:siren'); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + return $stmt->fetch(\PDO::FETCH_ASSOC); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } - return $stmt->fetch(\PDO::FETCH_ASSOC); + return false; } /** @@ -475,9 +499,15 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $stmt = $this->conn->executeQuery("SELECT codNafa AS nafa, libNafa FROM jo.tabNafa"); + while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { + $result[$row->naf] = $row->libNafa; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } $this->tabCodesNafa = $result; } @@ -541,202 +571,207 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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); + try { + $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.', '; + } - 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)"; + if (trim($even['insDESTINAT']) != '' && $even['insDESTINAT'] != 'NR' && $even['insDESTINAT']*1 != 9) { + $libDet.= $this->tabDestinat['i'.trim($even['insDESTINAT'])].', '; } - $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'])].', '; - $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; + } - $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, + ); } - $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 { + 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; } - } - $dateEve = $even['insDATEVE']; - $dateMaj = $even['insDATEMAJ']; - if (str_replace('-', '', $dateEve*1) == 0) { - $dateEve = $dateMaj; - } + $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'; + } + } - $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, - ); + $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, + ); + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -768,8 +803,14 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } $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); + try { + $stmt = $this->conn->executeQuery($sql); + $result = $stmt->fetch(\PDO::FETCH_OBJ); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } return $result->nb; } @@ -787,25 +828,36 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $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; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } // 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; + try { + $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; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } - $this->tabAssocId = $tabSupId; } else { $tabSupId = $this->tabAssocId; @@ -825,10 +877,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table { $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); + try { + $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); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $libLong = $result->LibFJ; $libCourt = $result->LibCourt; if ($court) { @@ -864,9 +922,15 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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); + try { + $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); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } @@ -1027,9 +1091,15 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $stmt = $this->conn->executeQuery("SELECT count(*) AS nb FROM jo.etablissements e WHERE $sqlWhere"); + $result = $stmt->fetch(\PDO::FETCH_OBJ); + $nbTot = $result->nb; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $sqlOrder = "ORDER BY triSiege DESC, e.actif DESC, e.nic DESC"; $sqlLimit = "LIMIT $deb, $nbRep"; @@ -1050,10 +1120,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } $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; + try { + $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; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $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"; @@ -1067,6 +1143,9 @@ class Metier_Insee_MInsee extends Metier_Insee_Table try { $stmt = $this->conn->executeQuery($sql); } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } // --- Affichage de la liste des établissements @@ -1178,13 +1257,26 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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"); + try { + $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; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + + try { + $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"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } elseif ($typeId == 'AUTRE') { /** Formatage des numéros de RC **/ $tabId = array($id); @@ -1221,13 +1313,26 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } } - $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"); + try { + $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; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + + try { + $stmt = $this->conn->executeQuery("SELECT $fields FROM jo.etablissements e + WHERE autre_id IN ('$strId') $filtreActif $strDep + ORDER BY siege DESC $limit"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } if ($stmt->rowCount() > 0) { @@ -1289,7 +1394,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table public function sirenExiste($siren) { $siren = $siren*1; - $stmt = $this->conn->executeQuery("SELECT id FROM jo.etablissements WHERE siren=$siren LIMIT 0,1"); + try { + $stmt = $this->conn->executeQuery("SELECT id FROM jo.etablissements WHERE siren=$siren LIMIT 0,1"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } if ($stmt->rowCount()) { return true; } @@ -1321,15 +1432,21 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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"); + try { + $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"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } if ($stmt->rowCount() > 0) { $etab = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -1401,10 +1518,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } 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; + try { + $stmt = $this->conn->executeQuery("SELECT devIso, devNom FROM jo.tabDevises WHERE $strWhere"); + if ($stmt->rowCount() > 0) { + while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { + $tabRet[$row->devIso] = $row->devNom; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -1438,15 +1561,21 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } 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']); + try { + $stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE 1 $strIdCA $strType ORDER BY sirenGrp"); + if ($stmt->rowCount() > 0) { + 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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -1474,7 +1603,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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 "; + $strCp = "AND cp BETWEEN $cpDep"."00 AND $cpDep"."99 "; } elseif ($cpDep > 999) { $strCp = "AND cp=$cpDep "; } else { @@ -1487,15 +1616,21 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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']); + try { + $stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE 1 $strIdCA $strType $strCp ORDER BY sirenGrp"); + if ($stmt->rowCount() > 0) { + 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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -1511,9 +1646,15 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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); + try { + $stmt = $this->conn->executeQuery("SELECT $fields FROM jo.tabMandataires WHERE id=$idMand"); + if ($stmt->rowCount() > 0) { + return $stmt->fetch(\PDO::FETCH_ASSOC); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } return array(); @@ -1533,15 +1674,21 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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']); + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -1557,9 +1704,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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); + try { + $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); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } @@ -1588,9 +1742,15 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $stmt = $this->conn->executeQuery("SELECT siren, nic, apen5, apen4, apet5, apet4 FROM insee.bascule WHERE $where"); + if ($stmt->rowCount() == 0) { + return false; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } $tabRet = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -1805,13 +1965,20 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } 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(); + try { + $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(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nbEtab > 0) { $etab = $stmt->fetch(\PDO::FETCH_ASSOC); $nic = $etab['nic']; @@ -1866,27 +2033,39 @@ class Metier_Insee_MInsee extends Metier_Insee_Table // 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; + try { + $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; + } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } - $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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } $timer['infosEntrep'] = microtime(true); @@ -1900,75 +2079,93 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } 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; + try { + $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']); + } } - 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'], + ); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } - } - // 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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } - $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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } $timer['tableIdentite'] = microtime(true); } @@ -2091,19 +2288,19 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $activitePJ_An8 = ''; foreach ($tmp as $tmp2) { - if ($tmp2['typeTel']=='tel' && ($tel==''||$tel==trim($tab['tel']))) { + 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']))) { + if ($tmp2['typeTel']=='fax' && ($fax == '' || $fax == trim($tab['fax']))) { $fax = implode('.', str_split($tmp2['telephone'], 2)); } - if ($tmp2['typeTel']=='web' && $tab['web']=='') { + if ($tmp2['typeTel'] ==' web' && $tab['web'] == '') { $tab['web'] = $tmp2['infoTel']; } - if ($tmp2['typeTel']=='mail' && $tab['mail']=='') { + if ($tmp2['typeTel'] == 'mail' && $tab['mail'] == '') { $tab['mail'] = $tmp2['infoTel']; } - if ($tmp2['typeTel']=='an8') { + if ($tmp2['typeTel'] == 'an8') { $activitePJ_An8 = $tmp2['infoTel']; } } @@ -2137,13 +2334,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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 + 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', @@ -2158,21 +2355,22 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 'E'=>'Reprise totale ou partielle d\'exploitation individuelle', */ $typeExploitation = 10; - } elseif ($nbEtab<2) { + } 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 + 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'], 0, 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 (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 + } elseif ($tabInsee['ORIGINE']*1 != 0 + && $tabInsee['ORIGINE']*1 != 8 + && $tabInsee['ORIGINE']*1 != 9 + && $tabInsee['ORIGINE'] != 'NR') { + $typeExploitation = 10; // Exploitation directe } } break; @@ -2201,26 +2399,32 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $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'; } } - // Exception lié à anomalies de données INSEE - if ($codePaysIso2 == '' && $codePaysInsee == 237) { - $codePaysIso2 = 'KR'; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -2286,9 +2490,9 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } $dir1Genre=''; - if ($tabInsee['CIVILITE']==1) { + if ($tabInsee['CIVILITE'] == 1) { $dir1Genre='M'; - } elseif ($tabInsee['CIVILITE']==2) { + } elseif ($tabInsee['CIVILITE'] == 2) { $dir1Genre='F'; } @@ -2490,19 +2694,25 @@ class Metier_Insee_MInsee extends Metier_Insee_Table // 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']; + try { + $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']; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } - $timer['nbActionsCapital']=microtime(true); + $timer['nbActionsCapital'] = microtime(true); // Numéro de TVA non défini if (!$vatDefined) { @@ -2522,16 +2732,23 @@ class Metier_Insee_MInsee extends Metier_Insee_Table // 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'])); + try { + $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'])); + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -2632,26 +2849,34 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } // 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'] = ''; + try { + $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'] = ''; + } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } @@ -2770,97 +2995,133 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $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; + } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } 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; + try { + $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; } - 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'; + $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; } - break; } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } } 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'; + try { + $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'; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } $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']; + try { + $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['Tribunal'] == '') { - $tabRet['Tribunal'] = $bodacc['Tribunal_Code']; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } 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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } // 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']); + try { + $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']); + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -2869,64 +3130,76 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } 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']); + try { + $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)'; + } } - $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)'; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } 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; + try { + $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; + } } } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } $timer['activiteReelle']=microtime(true); @@ -2992,27 +3265,33 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $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++; } - $k++; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -3022,36 +3301,49 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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']); + + try { + $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']); + } } - if ($tabRet['Mail'] == '') { - $tabRet['Mail'] = trim($annCap['Assoc_Mail']); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } } 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']; + try { + $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']; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -3175,126 +3467,144 @@ class Metier_Insee_MInsee extends Metier_Insee_Table // 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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } // 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) { - $rncsEtab = $stmt->fetch(\PDO::FETCH_ASSOC); - $tabRet['EtabActifRCS'] = 0; - if ($rncsEtab['jourUpdate'] != '0000-00-00' && - str_replace('-', '', $rncsEtab['jourUpdate'])*1 > str_replace('-', '', $tabRet['DateMajRCS'])) { - $tabRet['DateMajRCS'] = $rncsEtab['jourUpdate']; - } - // On signal que l'établissement est actif au RCS - if ($rncsEtab['actif']*1 == 1) { - $tabRet['EtabActifRCS'] = 1; - } - $tabRet['NomCommercial'] = $rncsEtab['nomCommercial']; - $tabRet['enseigneLong'] = $rncsEtab['enseigne']; + try { + $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) { + $rncsEtab = $stmt->fetch(\PDO::FETCH_ASSOC); + $tabRet['EtabActifRCS'] = 0; + if ($rncsEtab['jourUpdate'] != '0000-00-00' && + str_replace('-', '', $rncsEtab['jourUpdate'])*1 > str_replace('-', '', $tabRet['DateMajRCS'])) { + $tabRet['DateMajRCS'] = $rncsEtab['jourUpdate']; + } + // On signal que l'établissement est actif au RCS + if ($rncsEtab['actif']*1 == 1) { + $tabRet['EtabActifRCS'] = 1; + } + $tabRet['NomCommercial'] = $rncsEtab['nomCommercial']; + $tabRet['enseigneLong'] = $rncsEtab['enseigne']; - if ($codePaysIso2 != 'FR' && $codePaysIso2 != '') { - $tabRet['Adresse'] = trim(preg_replace('/ +/', ' ', $rncsEtab['adrNumVoie'] .' '.$rncsEtab['adrIndRep'].' '. - $rncsEtab['adrTypeVoie'].' '.$rncsEtab['adrVoie'])); - $tabRet['Adresse2'] = trim(preg_replace('/ +/', ' ', $rncsEtab['adrComp'])); - $tabRet['AdresseNum'] = $rncsEtab['adrNumVoie']; - $tabRet['AdresseBtq'] = $rncsEtab['adrIndRep']; - $tabRet['AdresseVoie'] = $rncsEtab['adrTypeVoie']; - $tabRet['AdresseRue'] = $rncsEtab['adrVoie']; - $tabRet['CP'] = $rncsEtab['cp']; - $tabRet['Ville'] = $rncsEtab['commune']; + if ($codePaysIso2 != 'FR' && $codePaysIso2 != '') { + $tabRet['Adresse'] = trim(preg_replace('/ +/', ' ', $rncsEtab['adrNumVoie'] .' '.$rncsEtab['adrIndRep'].' '. + $rncsEtab['adrTypeVoie'].' '.$rncsEtab['adrVoie'])); + $tabRet['Adresse2'] = trim(preg_replace('/ +/', ' ', $rncsEtab['adrComp'])); + $tabRet['AdresseNum'] = $rncsEtab['adrNumVoie']; + $tabRet['AdresseBtq'] = $rncsEtab['adrIndRep']; + $tabRet['AdresseVoie'] = $rncsEtab['adrTypeVoie']; + $tabRet['AdresseRue'] = $rncsEtab['adrVoie']; + $tabRet['CP'] = $rncsEtab['cp']; + $tabRet['Ville'] = $rncsEtab['commune']; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } $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) { - $rmEntrep = $stmt->fetch(\PDO::FETCH_ASSOC); - if (isset($entrep['numRM'])) { - $tabRet['AutreId'] = $rmEntrep['numRM']; - if ($tabRet['Activite']=='') { - $tabRet['Activite'] = $rmEntrep['activite']; - } - if ($tabRet['APRM'] == '') { - $tabRet['APRM'] = $rmEntrep['aprm']; - $tabRet['APRM_Lib'] = $this->getLibelleNafa($entrep['aprm']); - } + try { + $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) { + $rmEntrep = $stmt->fetch(\PDO::FETCH_ASSOC); + if (isset($entrep['numRM'])) { + $tabRet['AutreId'] = $rmEntrep['numRM']; + if ($tabRet['Activite']=='') { + $tabRet['Activite'] = $rmEntrep['activite']; + } + if ($tabRet['APRM'] == '') { + $tabRet['APRM'] = $rmEntrep['aprm']; + $tabRet['APRM_Lib'] = $this->getLibelleNafa($entrep['aprm']); + } - if (strtoupper(trim($rmEntrep['nom'].' '.$rmEntrep['prenom'].' '.$rmEntrep['nomUsage'])) != strtoupper(trim($tabRet['Nom']))) { - $tabRet['nomLong'] = strtoupper(trim($rmEntrep['nom'].' '.$rmEntrep['prenom'].' '.$rmEntrep['nomUsage'])); - } - if (strtoupper(trim($rmEntrep['sigle'])) != strtoupper(trim($tabRet['Sigle']))) { - $tabRet['sigleLong']= strtoupper($rmEntrep['sigle']); - } + if (strtoupper(trim($rmEntrep['nom'].' '.$rmEntrep['prenom'].' '.$rmEntrep['nomUsage'])) != strtoupper(trim($tabRet['Nom']))) { + $tabRet['nomLong'] = strtoupper(trim($rmEntrep['nom'].' '.$rmEntrep['prenom'].' '.$rmEntrep['nomUsage'])); + } + if (strtoupper(trim($rmEntrep['sigle'])) != strtoupper(trim($tabRet['Sigle']))) { + $tabRet['sigleLong']= strtoupper($rmEntrep['sigle']); + } - $tabRet['dateImmat'] = $rmEntrep['debutActivite']; - $tabRet['dateRad'] = $rmEntrep['radiation']; + $tabRet['dateImmat'] = $rmEntrep['debutActivite']; + $tabRet['dateRad'] = $rmEntrep['radiation']; - // Si on est au greffe, on est artisan commercant - // Artisan Commerçant - if ($tabRet['numGreffe']*1 > 0) { - $fjInpi = 1100; - } - // Artisan - else { - $fjInpi = 1300; - } + // 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($rmEntrep['qualite'].' '.$rmEntrep['qualif'])); - $tabRet['dir1NomPrenom'] = strtoupper($rmEntrep['nom']).' '.ucwords(strtolower($rmEntrep['prenom'])); - $tabRet['dir1Nom'] = strtoupper($rmEntrep['nom']); - $tabRet['dir1Prenom'] = ucwords(strtolower($rmEntrep['prenom'])); - $tabRet['dir1DateNaiss'] = $rmEntrep['dateNaiss']; - $tabRet['dir1LieuNaiss'] = $rmEntrep['lieuNaiss']; - - if ($tabRet['DateMajRCS'] == '') { - if ($rmEntrep['jourUpdate'] != '0000-00-00') { - $tabRet['DateMajRCS'] = $rmEntrep['jourUpdate']; + // 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['DateMajRCS'] = $rmEntrep['dateInsert']; + $tabRet['FJ2'] = $tabRet['FJ']; + $tabRet['FJ2_Lib'] = $tabRet['FJ_lib']; } - } - // On signal que l'entreprise est active au RCS - if ($rmEntrep['actif'] == 1 || $rmEntrep['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'] = $rmEntrep['nomCommercial']; - $tabRet['enseigneLong'] = $rmEntrep['enseigne']; + $tabRet['dir1Titre'] = ucwords(strtolower($rmEntrep['qualite'].' '.$rmEntrep['qualif'])); + $tabRet['dir1NomPrenom'] = strtoupper($rmEntrep['nom']).' '.ucwords(strtolower($rmEntrep['prenom'])); + $tabRet['dir1Nom'] = strtoupper($rmEntrep['nom']); + $tabRet['dir1Prenom'] = ucwords(strtolower($rmEntrep['prenom'])); + $tabRet['dir1DateNaiss'] = $rmEntrep['dateNaiss']; + $tabRet['dir1LieuNaiss'] = $rmEntrep['lieuNaiss']; + + if ($tabRet['DateMajRCS'] == '') { + if ($rmEntrep['jourUpdate'] != '0000-00-00') { + $tabRet['DateMajRCS'] = $rmEntrep['jourUpdate']; + } else { + $tabRet['DateMajRCS'] = $rmEntrep['dateInsert']; + } + } + // On signal que l'entreprise est active au RCS + if ($rmEntrep['actif'] == 1 || $rmEntrep['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'] = $rmEntrep['nomCommercial']; + $tabRet['enseigneLong'] = $rmEntrep['enseigne']; + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -3385,83 +3695,89 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } // 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) { - $bilEntrep = $stmt->fetch(\PDO::FETCH_ASSOC); - $tabRet['bilanAnnee'] = substr($bilEntrep['dateExercice'], 0, 4); - $tabRet['bilanDate'] = $bilEntrep['dateExercice']; - $tabRet['bilanMois'] = $bilEntrep['dureeExercice']; - $tabRet['bilanDevise'] = $bilEntrep['monnaie']; - if ($bilEntrep['dateProvPartenaire'] > 0) { - $tabRet['bilanDateMaj'] = Metier_Util_Date::dateT('Ymd', 'Y-m-d', $bilEntrep['dateProvPartenaire']); - } else { - $tabRet['bilanDateMaj'] = Metier_Util_Date::dateT('Y-m-d', 'Y-m-d', $bilEntrep['dateInsert']); - } + try { + $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) { + $bilEntrep = $stmt->fetch(\PDO::FETCH_ASSOC); + $tabRet['bilanAnnee'] = substr($bilEntrep['dateExercice'], 0, 4); + $tabRet['bilanDate'] = $bilEntrep['dateExercice']; + $tabRet['bilanMois'] = $bilEntrep['dureeExercice']; + $tabRet['bilanDevise'] = $bilEntrep['monnaie']; + if ($bilEntrep['dateProvPartenaire'] > 0) { + $tabRet['bilanDateMaj'] = Metier_Util_Date::dateT('Ymd', 'Y-m-d', $bilEntrep['dateProvPartenaire']); + } else { + $tabRet['bilanDateMaj'] = Metier_Util_Date::dateT('Y-m-d', 'Y-m-d', $bilEntrep['dateInsert']); + } - switch (strtoupper(trim($bilEntrep['unite']))) { - case 'M': $unite = 'M'; break; - case 'K': $unite = 'K'; break; - default: $unite = 'U'; break; - } - $tabTmp = explode(';', $bilEntrep['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]; + switch (strtoupper(trim($bilEntrep['unite']))) { + case 'M': $unite = 'M'; break; + case 'K': $unite = 'K'; break; + default: $unite = 'U'; break; + } + $tabTmp = explode(';', $bilEntrep['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($bilEntrep['typeBilan'])=='S') { + $mBil = new Metier_Partenaires_MBilans(); + $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; } - if (strtoupper($bilEntrep['typeBilan'])=='S') { - $mBil = new Metier_Partenaires_MBilans(); - $tabTmp = $mBil->bilanSimplifie2Normal($tabBilan); - $tabBilan = array_merge($tabTmp, $tabBilan); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } - - $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']); @@ -3497,12 +3813,12 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $iBourse = new Metier_Partenaires_MBourse(); $bourse = $iBourse->getInfosBourse($siren); $tabRet['Bourse'] = array( - 'placeCotation' => $bourse['placeCotation'], - 'nombreTitres' => $bourse['nombreTitres'], - 'capitalisation' => $bourse['close']*$bourse['nombreTitres'], - 'derCoursDate' => $bourse['date'], - 'derCoursCloture' => $bourse['close'] - ); + 'placeCotation' => $bourse['placeCotation'], + 'nombreTitres' => $bourse['nombreTitres'], + 'capitalisation' => $bourse['close']*$bourse['nombreTitres'], + 'derCoursDate' => $bourse['date'], + 'derCoursCloture' => $bourse['close'] + ); $timer['infosBoursieres'] = microtime(true); } @@ -3538,29 +3854,36 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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, - ); + try { + $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() > 0) { + 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, + ); + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } @@ -3579,239 +3902,269 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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 - ); + try { + $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 + ); + } + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } - $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) { + try { + $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++; } - $iDir++; - } - } //End foreach + } //End foreach + } } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } 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 = ''; - } + try { + $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']); - } + 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']); + $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'], + ); } - $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'], - ); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } /** 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; + try { + $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; + } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } /** 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']); - } + try { + $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) { + 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 ($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']; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -3837,40 +4190,51 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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); + try { + $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'], + ); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } - $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', - )); + try { + $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', + )); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } } @@ -3919,13 +4283,20 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } return $nb; @@ -4287,7 +4658,8 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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'))) { + if ($ann['typeEven'] >= 1000 && $ann['typeEven'] <= 1999 && !in_array($ann['typeEven'], + array('1005', '1010', '1050', '1055', '1550'))) { $annonceFilter[] = $ann; } } @@ -4673,10 +5045,17 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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']; + try { + $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']; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } + if (array_key_exists($evenProcolLast, $tabNoProcol)) { if ($this->debug) { file_put_contents('procol.log', "Vérification Effacement procol : $evenProcolLast\n", FILE_APPEND); @@ -5219,7 +5598,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table if ($this->debug && $rubrique == 'D') { file_put_contents('procol.log', $sql."\n", FILE_APPEND); } - $stmt = $this->conn->executeQuery($sql); + try { + $stmt = $this->conn->executeQuery($sql); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } // --- Traitement des resultats if ($stmt->rowCount() > 0) { @@ -5707,6 +6092,9 @@ class Metier_Insee_MInsee extends Metier_Insee_Table FROM jo.balo WHERE Societe_Rcs='$siren' $strIdAnn ORDER BY Date_Parution DESC, Num_Affaire LIMIT $offset, $lignes"); } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } if ($stmt->rowCount() > 0) { @@ -5751,10 +6139,17 @@ class Metier_Insee_MInsee extends Metier_Insee_Table { $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; + try { + $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; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } return $nb; @@ -5791,19 +6186,21 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } } try { - $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 $strIdAnn AND d.id=b.id - GROUP BY b.id ORDER BY l.Boamp_Date_Parution DESC LIMIT $offset,$lignes"); - } catch(\Doctrine\DBAL\DBALException $e) { - //file_put_contents('test.log', $e->getMessage()); + $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 $strIdAnn AND d.id=b.id + GROUP BY b.id ORDER BY l.Boamp_Date_Parution DESC LIMIT $offset,$lignes"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } if ($stmt->rowCount() > 0) { while ($ann = $stmt->fetch(\PDO::FETCH_ASSOC)) { @@ -5839,8 +6236,8 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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']; + $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='. @@ -5855,7 +6252,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table preg_replace('//Uis', '', preg_replace('/( class=".*")/ie', ' ', $ann['annonce']))), array(' '=>' ', ''=>'', ''=>'', '

'=>'
') - ); + ); } } $tabRet[] = array( @@ -5900,8 +6297,10 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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 LIMIT $offset,$lignes"); - } catch(\Doctrine\DBAL\DBALException $e) { - //file_put_contents('test.log', $e->getMessage()); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } if ($stmt->rowCount() > 0) { @@ -5968,11 +6367,11 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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. + $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) { @@ -6020,21 +6419,33 @@ class Metier_Insee_MInsee extends Metier_Insee_Table // --- Recherche dans les avis d'attribution if ($type=='' || $type=='A') { - $stmt = $this->conn->executeQuery("SELECT COUNT(b.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 d.id=b.id"); - if ($stmt->rowCount()) { - $result = $stmt->fetch(\PDO::FETCH_OBJ); - $bodaccA = $result->nb; + try { + $stmt = $this->conn->executeQuery("SELECT COUNT(b.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 d.id=b.id"); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_OBJ); + $bodaccA = $result->nb; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } // --- 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"); - if ($stmt->rowCount()) { - $result = $stmt->fetch(\PDO::FETCH_OBJ); - $bodaccM = $result->nb; + try { + $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"); + if ($stmt->rowCount()) { + $result = $stmt->fetch(\PDO::FETCH_OBJ); + $bodaccM = $result->nb; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } @@ -6065,14 +6476,21 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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) { + $annonceNb = 0; + try { + $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"); + $annonceNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($annonceNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $tabEven = explode(';', $row['codEven']); $tabRetEven = array(); @@ -6168,12 +6586,19 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $stmt = $this->conn->executeQuery("SELECT COUNT(*) AS nb FROM jo.asso WHERE $strIdAnn AND dateSuppr=0"); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_OBJ); + return $result->nb; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } + return 0; } @@ -6185,27 +6610,33 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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 = ''; + try { + $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() > 0) { + $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']; + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } - $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; @@ -6228,10 +6659,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } $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); + try { + $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() > 0) { + return $stmt->fetchAll(\PDO::FETCH_ASSOC); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } @@ -6256,7 +6693,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } elseif ($type == 'E') { $strimportExport = " AND importExport='E' "; } - if ($annee*1>0) { + if ($annee*1 > 0) { $strAnnees = " AND annee=$annee "; } else { $tabAnnees = array(); @@ -6266,10 +6703,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } $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); + try { + $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() > 0) { + return $stmt->fetch(\PDO::FETCH_ASSOC); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } } @@ -6289,10 +6732,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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()) { + if ($stmt->rowCount() > 0) { return $stmt->fetch(\PDO::FETCH_ASSOC); } } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } try { @@ -6304,10 +6750,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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()) { + if ($stmt->rowCount() > 0) { return $stmt->fetch(\PDO::FETCH_ASSOC); } } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } return array(); @@ -6351,13 +6800,20 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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); + + try { + $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() > 0) { + return $stmt->fetchAll(\PDO::FETCH_ASSOC); + } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } return false; @@ -6424,29 +6880,35 @@ class Metier_Insee_MInsee extends Metier_Insee_Table //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']; + try { + $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; + } } - 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; + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); } } } @@ -6485,25 +6947,40 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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; + try { + $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() > 0) { + $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() > 0) { + $result = $stmt->fetch(\PDO::FETCH_OBJ); + $an8et = $result->infoTel; + } } } + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } } // 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()) { + $actregNb = 0; + try { + $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'"); + $actregNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($actregNb > 0) { 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']) != '') { @@ -6575,14 +7052,22 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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"); + try { + $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(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } - $nbTot = $stmt->rowCount(); if ($nbTot > 0) { while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $tel = sprintf('%010d', strtr($row['tel'], array('-'=>'', '/'=>'', '.'=>'', ','=>''))); @@ -6864,9 +7349,19 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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()) { + $listeNb = 0; + try { + $stmt = $this->conn->executeQuery("SELECT codCpf, libCpf FROM insee.tabCpf + WHERE codCpf IN (SELECT cpf FROM insee.tabNafCpf WHERE naf='$naf')"); + $listeNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + + if ($listeNb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { $tabRet[$row->codCpf] = $row->libCpf; } @@ -6915,8 +7410,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } // Recherche par Département - $stmt = $this->conn->executeQuery("SELECT codeOPS, libInstitution - FROM sdv1.retraiteDep + $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)) { @@ -6955,12 +7449,20 @@ class Metier_Insee_MInsee extends Metier_Insee_Table */ 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()) { + $nb = 0; + try { + $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"); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { $result = $stmt->fetch(\PDO::FETCH_OBJ); return $result->insDATEVE; } @@ -6984,6 +7486,8 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $datePre = $dateSuc = 0; $nicPre = $nicSuc = 0; + $nb = 0; + try { $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, @@ -6995,8 +7499,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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) { + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($row['sirVersion'] == 4) { if (in_array($row['insEVE'], array('CTE', 'CTS', 'MTAE', 'MTAS'))) { @@ -7142,10 +7651,17 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } } - $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); + try { + $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); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } if ($tel == '') { $tel = $ret['tel']; } @@ -7184,12 +7700,22 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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) { + $rivoliNb = 0; + try { + $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"); + $rivoliNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($rivoliNb == 1) { $result = $stmt->fetch(\PDO::FETCH_ASSOC); $codeRivoli = $result['rivoli']; - } elseif ($stmt->rowCount() > 1 && $adrLibVoie != '') { + } elseif ($rivoliNb > 1 && $adrLibVoie != '') { while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($result['typVoie'] == strtoupper($adrTypVoie)) { $codeRivoli = $result['rivoli']; @@ -7202,10 +7728,17 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } $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"); + $rivoliNb = 0; + try { + $stmt = $this->conn->executeQuery("SELECT codeInsee, codeIris, rivoli, codeInseeIris + FROM insee.iris WHERE codeInsee='$codeCommune' AND rivoli LIKE '$codeRivoli%' GROUP BY codeInseeIris"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $strAdr = ''; - if ($stmt->rowCount() > 1) { + if ($rivoliNb > 1) { // Numéro impaire if ($adrNum > 0 && $adrNum&1) { $strAdr = "AND typeNum=1 AND $adrNum BETWEEN numd AND numf "; @@ -7254,7 +7787,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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()) { + if ($stmt->rowCount() > 0) { $row = $stmt->fetch(\PDO::FETCH_ASSOC); return array( 'codIris' => $row['codeIris'], @@ -7336,13 +7869,22 @@ class Metier_Insee_MInsee extends Metier_Insee_Table */ 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) { + $nb = 0; + try { + $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(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + + if ($nb > 0) { $result = $stmt->fetch(\PDO::FETCH_OBJ); $caSecteur = round($result->moyenne * 1000); // Encours moyen secteur * nb salariés @@ -7396,9 +7938,16 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $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) { + $nb = 0; + try { + $stmt = $this->conn->executeQuery("SELECT codComInsee, idVoieCom, cleRivoli, voieNature, voieLib, 1 AS score + FROM insee.fantoirVoi WHERE codComInsee='$codeCommune' $strTypesVoies AND voieLib='$adrLibVoie2'"); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb == 0) { return ''; } else { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) { @@ -7426,34 +7975,56 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $table = 'insee.insee_even'; $where = "insDATEVE < :date ORDER BY insDATEMAJ DESC LIMIT 1"; + $nb = 0; 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) { + try { + $stmt = $this->conn->prepare("SELECT insNOMEN FROM insee.insee_even WHERE $sqlIdentifiant AND $where"); + $stmt->bindValue('siren', $siren); + $stmt->bindValue('date', $dateEven); + $stmt->execute(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 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) { + try { + $stmt = $this->conn->prepare("SELECT insSIGLE FROM insee.insee_even WHERE $sqlIdentifiant AND $where"); + $stmt->bindValue('siren', $siren); + $stmt->bindValue('date', $dateEven); + $stmt->execute(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 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) { + try { + $stmt = $this->conn->prepare("SELECT insAPEN700 FROM insee.insee_even WHERE $sqlIdentifiant AND $where"); + $stmt->bindValue('siren', $siren); + $stmt->bindValue('date', $dateEven); + $stmt->execute(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { $result = $stmt->fetch(\PDO::FETCH_OBJ); return $result->insAPEN700; } @@ -7462,32 +8033,53 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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) { + try { + $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(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 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) { + try { + $stmt = $this->conn->prepare("SELECT insNICSIEGE FROM insee.insee_even WHERE $sqlIdentifiant AND $where"); + $stmt->bindValue('siren', $siren); + $stmt->bindValue('date', $dateEven); + $stmt->execute(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 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) { + try { + $stmt = $this->conn->prepare("SELECT insCJ FROM insee.insee_even WHERE $sqlIdentifiant AND $where"); + $stmt->bindValue('siren', $siren); + $stmt->bindValue('date', $dateEven); + $stmt->execute(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { $result = $stmt->fetch(\PDO::FETCH_OBJ); return $result->insCJ; } @@ -7496,12 +8088,19 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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) { + try { + $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(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { $result = $stmt->fetch(\PDO::FETCH_OBJ); return $result->insENSEIGNE; } @@ -7510,12 +8109,19 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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) { + try { + $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(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { $row = $stmt->fetch(\PDO::FETCH_OBJ); return $row->insL2_COMP.' '. $row->insL3_CADR.' '. @@ -7530,12 +8136,19 @@ class Metier_Insee_MInsee extends Metier_Insee_Table 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) { + try { + $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(); + $nb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($nb > 0) { $row = $stmt->fetch(\PDO::FETCH_OBJ); return $row->insEFENCENT . ' (Tranche '.$row->insTEFET . ')'; } diff --git a/library/Metier/Partenaires/MAmabis.php b/library/Metier/Partenaires/MAmabis.php index b0b9be4f..a99f1be1 100644 --- a/library/Metier/Partenaires/MAmabis.php +++ b/library/Metier/Partenaires/MAmabis.php @@ -12,10 +12,20 @@ class Metier_Partenaires_MAmabis */ protected $conn; + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + public function __construct() { $this->conn = Zend_Registry::get('doctrine'); + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } + $this->client = new SoapClient(null, array( 'location' => 'http://sw2.amabis.com:5100/', 'uri' => 'http://www.amabis.com/ns.xsd', @@ -51,16 +61,23 @@ class Metier_Partenaires_MAmabis $adresse = addslashes(trim(preg_replace('/ +/', ' ', "$adrNum $adrIndRep $adrTypeVoie $adrLibVoie"))); $ville = addslashes($ville); $majForcee = false; + $stmtNb = 0; + try { + $sql = "SELECT zus, zru, zfu, cucs, rnvpStatut, rnvpCorr, rnvpTrt, adr3, adr4, adr5, adr6, + adr7, numVoieA, indRepA, typeVoieAlong, typeVoieAcourt, corpVoie, motDir, motDirD, + libVoieSec, adr4n32, adr4n38, clePostaleVoie, secteur, cleRoutage, cpx, cleAd, + codPaysIso2, codPaysIso3, libPays, codeInsee + FROM jo.zonage WHERE address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'"; + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } - $sql = "SELECT zus, zru, zfu, cucs, rnvpStatut, rnvpCorr, rnvpTrt, adr3, adr4, adr5, adr6, - adr7, numVoieA, indRepA, typeVoieAlong, typeVoieAcourt, corpVoie, motDir, motDirD, - libVoieSec, adr4n32, adr4n38, clePostaleVoie, secteur, cleRoutage, cpx, cleAd, - codPaysIso2, codPaysIso3, libPays, codeInsee - FROM jo.zonage WHERE address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'"; - $stmt = $this->conn->prepare($sql); - $stmt->execute(); - - if ($stmt->rowCount() > 0) { + if ($stmtNb > 0) { $zones = $stmt->fetch(\PDO::FETCH_ASSOC); if ($zones['rnvpStatut'] === null && $rnvp) { $majForcee = true; @@ -113,7 +130,7 @@ class Metier_Partenaires_MAmabis } } - if ($stmt->rowCount() == 0 || $majForcee) { + if ($stmtNb == 0 || $majForcee) { try { // Le RNVP ne fonctionne pas sans la Raison Sociale qui est la 1ère ligne d'adresse if (trim($raisonSociale) == '') { @@ -128,7 +145,6 @@ class Metier_Partenaires_MAmabis new SoapParam('type=M', 'options') ); - /** Découpage des ZFU, CUCS etcs... **/ $fp = fopen(LOG_PATH.'/amabis.log', 'a'); fwrite($fp, date('d-m-Y H:i:s').' - '.implode("\n", $rep)."\n============================================================================\n"); @@ -225,25 +241,45 @@ class Metier_Partenaires_MAmabis $villeL = addslashes($ville); $sql = "SELECT dateInsert*1 as dateInsert FROM jo.zonage WHERE address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'"; - $stmt = $this->conn->prepare($sql); - $stmt->execute(); - if ($stmt->rowCount() > 0) { + $majNb = 0; + try { + $majStmt = $this->conn->prepare($sql); + $majStmt->execute(); + $majNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($majNb > 0) { $result = $stmt->fetch(\PDO::FETCH_OBJ); $dateInsert = $result->dateInsert; if ($dateInsert != 0) { - $this->conn->update('jo.zonage', array_merge($tabUpdate, - array('dateInsert' => $dateInsert)), - array( - 'address' => $adresseL, - 'adr_cp' => $cp, - 'adr_ville' => $villeL, - )); + try { + $this->conn->update('jo.zonage', array_merge($tabUpdate, + array('dateInsert' => $dateInsert)), + array( + 'address' => $adresseL, + 'adr_cp' => $cp, + 'adr_ville' => $villeL, + )); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } } } if ($dateInsert == 0) { - $this->conn->insert('jo.zonage', array_merge($tabInsert, $tabUpdate)); + try { + $this->conn->insert('jo.zonage', array_merge($tabInsert, $tabUpdate)); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } $tabTmp[0] = explode(',', $tabZones['LOCREFCLEP']); @@ -264,7 +300,13 @@ class Metier_Partenaires_MAmabis 'source' => 'Amabis', 'dateInsert' => date('YmdHis'), ); - $this->conn->insert('jo.villesCP', $tabInsert); + try { + $this->conn->insert('jo.villesCP', $tabInsert); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } /** Autres Informations de la RNVP **/ @@ -286,11 +328,19 @@ class Metier_Partenaires_MAmabis $codeInsee = substr($codeRivoli, 0, 5); $sql = "SELECT typeZone, arreteDate, decretDate, decretNum, decretModifieDate, decretModifieNum, dateDebut, dateFin FROM jo.zonageInsee WHERE codeInsee=:code"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('code', $codeInsee); - $stmt->execute(); + $zonageNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('code', $codeInsee); + $stmt->execute(); + $zonageNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $tabRep['ZRR'] = $tabRep['AFR'] = 'NON'; - if ($stmt->rowCount() > 0) { + if ($zonageNb > 0) { while ($zones = $stmt->fetch(\PDO::FETCH_ASSOC)) { switch ($zones['typeZone']) { case 'ZRR': diff --git a/library/Metier/Partenaires/MFacto.php b/library/Metier/Partenaires/MFacto.php index 1a877e79..55256083 100644 --- a/library/Metier/Partenaires/MFacto.php +++ b/library/Metier/Partenaires/MFacto.php @@ -16,6 +16,12 @@ D. 067 200 329 I 2010-06-30 La CS est valide jusq'au 30/06/2010... Quid */ class Metier_Partenaires_MFacto { + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + public $risqueImpaye = false; // Y a t'il un risque d'impayé ? public $risqueImpayeMois = 0; public $profilPayeur = 0; // 0:N/D, 1:Excellent, 2=Bon, 3=Normal, 4=Lent, 5=Mauvais ou Défaut @@ -93,6 +99,10 @@ class Metier_Partenaires_MFacto public function __construct() { $this->conn = Zend_Registry::get('doctrine'); + + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } } public function setTypeFic($typeFic) @@ -150,11 +160,19 @@ class Metier_Partenaires_MFacto WHERE siren=:siren AND (dateSuppr=0 OR dateConf>dateSuppr) AND (dateFin=0 OR dateFin>NOW()) AND cs NOT IN (20,22,27,33,34) ORDER BY dateConf DESC, dateInsert DESC"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('siren', $siren); - $stmt->execute(); + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $tabRet = array(); - if ($stmt->rowCount() > 0) { + if ($stmtNb > 0) { while ($tabCS = $stmt->fetch(\PDO::FETCH_ASSOC)) { $dateEven = $tabCS['dateConf']; if ($dateEven == '0000-00-00') { @@ -179,15 +197,23 @@ class Metier_Partenaires_MFacto public function getCoteSpecialeOld($siren) { - $sql = "SELECT DATMAJ1, NUMGFH, CSAVAN, CSAPRE, SIRENE + $sql = "SELECT DATMAJ1, NUMGFH, CSAVAN, CSAPRE, SIRENE FROM sdv1.ge_cs c LEFT JOIN sdv1.ge_acheteurs a ON a.NUMACH=c.NUMGFH WHERE a.SIRENE=:siren ORDER BY a.SIRENE ASC, c.DATMAJ1 DESC"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('siren', $siren); - $stmt->execute(); + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } $tabRet = array(); - if ($stmt->rowCount() > 0) { + if ($stmtNb > 0) { while ($tabCS = $stmt->fetch(\PDO::FETCH_ASSOC)) { $tabRet[] = array( 'DateEven' => $tabCS['DATMAJ1'], @@ -228,10 +254,18 @@ class Metier_Partenaires_MFacto p.CODDEV, a.SIRENE, a.RAISOC, a.CODPOS, a.VILLE FROM sdv1.ge_paiements p LEFT JOIN sdv1.ge_acheteurs a ON a.NUMACH=p.NUMACH WHERE a.SIRENE=:siren AND DATEDIFF(NOW(),p.DATECH)<736 AND p.DATECHconn->prepare($sql); - $stmt->bindValue('siren', $siren); - $stmt->execute(); - if ($stmt->rowCount() > 0) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($tabPai = $stmt->fetch(\PDO::FETCH_ASSOC)) { $nbJoursMoyen = $tabPai['nbJourRetard'] - $tabPai['nbJourPaiement']; if ($nbJoursMoyen < 6) { @@ -387,10 +421,18 @@ class Metier_Partenaires_MFacto WHERE idClient='SURBODPRDFTSRECOCASH' AND siren=:siren AND dateSuppr=0 AND ABS(DATEDIFF(dateAjout, NOW()))<365 ORDER BY dateConf DESC, dateAjout DESC"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('siren', $siren); - $stmt->execute(); - if ($stmt->rowCount() > 0) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { while ($tabCS = $stmt->fetch(\PDO::FETCH_ASSOC)) { $dateMAJ = Metier_Util_Date::dateT('Y-m-d', 'M Y', $tabCS['dateAjout']); $libProfil = "En date du $dateMAJ : Contentieux importants."; diff --git a/library/Metier/Partenaires/MMap.php b/library/Metier/Partenaires/MMap.php index 6088d9ab..8b3b711d 100644 --- a/library/Metier/Partenaires/MMap.php +++ b/library/Metier/Partenaires/MMap.php @@ -4,6 +4,12 @@ require_once __DIR__ . '/MMapFunctions.php'; class Metier_Partenaires_MMap { + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + private $referer =''; private $body = ''; private $header = ''; diff --git a/library/Metier/Partenaires/MTva.php b/library/Metier/Partenaires/MTva.php index 509adcfb..40ad0044 100644 --- a/library/Metier/Partenaires/MTva.php +++ b/library/Metier/Partenaires/MTva.php @@ -27,6 +27,12 @@ class Metier_Partenaires_MTva */ protected $conn; + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + /** * Remote Flag * @var boolean @@ -40,6 +46,10 @@ class Metier_Partenaires_MTva public function __construct() { $this->conn = Zend_Registry::get('doctrine'); + + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } } /** @@ -74,10 +84,18 @@ class Metier_Partenaires_MTva $sql = "SELECT LPAD(cle,2,0) AS cle, DATE_FORMAT(dateMod,'%Y%m%d') as DateMAJ FROM sdv1.siren_tva WHERE siren=:siren"; - $stmt = $this->conn->prepare($sql); - $stmt->bindValue('siren', $this->siren); - $stmt->execute(); - if ($stmt->rowCount() > 0) { + $stmtNb = 0; + try { + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $this->siren); + $stmt->execute(); + $stmtNb = $stmt->rowCount(); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } + if ($stmtNb > 0) { $exist = true; $result = $stmt->fetch(\PDO::FETCH_OBJ); $cle = $result->cle; @@ -104,7 +122,7 @@ class Metier_Partenaires_MTva return true; } - Metier_Util_Log::write('W', "Erreur impossible (car l'algo ne devrait pas passer par ici) sur le Siren $siren, numéro de TVA = FR $cle $siren. Durée = $duree s. Cas impossible !", __LINE__, __FILE__, __FUNCTION__, __CLASS__); + $this->logger->error("Erreur impossible (car l'algo ne devrait pas passer par ici) sur le Siren $siren, numéro de TVA = FR $cle $siren. Cas impossible !"); return true; } @@ -160,11 +178,23 @@ class Metier_Partenaires_MTva if (preg_match('/Yes, valid VAT number/i', $body) || preg_match('/Oui, numéro de TVA valide/i', $body)) { if ($exist) { - $this->conn->update('sdv1.siren_tva', array('cle' => intval($this->cle), + try { + $this->conn->update('sdv1.siren_tva', array('cle' => intval($this->cle), 'duree' => $time), array('siren' => $this->siren)); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } else { - $this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren, - 'cle' => intval($this->cle), 'duree' => $time)); + try { + $this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren, + 'cle' => intval($this->cle), 'duree' => $time)); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } $this->vatNumber = "FR".$this->cle.$this->siren; $this->vatDefined = true; @@ -172,16 +202,28 @@ class Metier_Partenaires_MTva } } } catch (RequestException $e) { - Metier_Util_Log::write('I', "TVA ".$e->getMessage(), __LINE__, __FILE__, __FUNCTION__, __CLASS__); + $this->logger->error($e->getMessage()); } // Non disponible if ($exist) { - $this->conn->update('sdv1.siren_tva', array('cle' => 'NULL', 'duree' => $time), - array('siren' => $this->siren)); + try { + $this->conn->update('sdv1.siren_tva', array('cle' => 'NULL', 'duree' => $time), + array('siren' => $this->siren)); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } else { - $this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren, - 'cle' => 'NULL', 'duree' => $time)); + try { + $this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren, + 'cle' => 'NULL', 'duree' => $time)); + } catch (\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + } } $this->vatNumber = "FR".$this->cle.$this->siren; diff --git a/library/Metier/Util/Db.php b/library/Metier/Util/Db.php index 25009d36..4dd72efd 100644 --- a/library/Metier/Util/Db.php +++ b/library/Metier/Util/Db.php @@ -6,6 +6,12 @@ class Metier_Util_Db */ protected $db = null; + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + /** * * @var unknown @@ -21,6 +27,10 @@ class Metier_Util_Db if ($db === null) { $this->db = Zend_Db_Table::getDefaultAdapter(); } + + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } } /** @@ -265,11 +275,14 @@ class Metier_Util_Db $duree = 'N/D'; } if ($this->errorCode == 0) { - $msg = date('Y-m-d H:i:s') ." - DEBUG - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree; + if ($this->logger != null) { + $this->logger->debug($this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree); + } } else { - $msg = date('Y-m-d H:i:s') ." - ERROR - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree; + if ($this->logger != null) { + $this->logger->error($this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree); + } } - file_put_contents(LOG_PATH . '/mysql.log', $msg . "\n", FILE_APPEND); } /** diff --git a/library/Scores/Ws/Server.php b/library/Scores/Ws/Server.php index 399573aa..d86543cc 100644 --- a/library/Scores/Ws/Server.php +++ b/library/Scores/Ws/Server.php @@ -240,6 +240,12 @@ class Scores_Ws_Server */ protected $conn; + /** + * Logger + * @var \Monolog\Logger + */ + protected $logger; + /** * Server SOAP * Document/Literal Wrapped - WS-I Compliant @@ -247,6 +253,11 @@ class Scores_Ws_Server public function __construct() { $this->conn = Zend_Registry::get('doctrine'); + + if (Zend_Registry::isRegistered('logger')) { + $this->logger = Zend_Registry::get('logger'); + } + $this->listeDroits = include APPLICATION_PATH . '/../library/Scores/Account/Access.php'; $this->listeCategory = include APPLICATION_PATH . '/../library/Scores/Account/Category.php'; } @@ -568,9 +579,9 @@ class Scores_Ws_Server try { $result = $stmt->fetch(\PDO::FETCH_OBJ); } catch (\Doctrine\DBAL\DBALException $e) { - $c = Zend_Registry::get('config'); - file_put_contents($c->profil->path->shared.'/log/application.log', - date('Y-m-d H:i:s').'- AUTH : '.$e->getMessage()."\n", FILE_APPEND); + if ($this->logger != null) { + $this->logger->error("AUTH : ".$e->getMessage()); + } return '0000'; } diff --git a/library/SphinxSearch/sphinxapi-2.2.10.php b/library/SphinxSearch/sphinxapi-2.2.10.php index 9fa33b51..456507e9 100644 --- a/library/SphinxSearch/sphinxapi-2.2.10.php +++ b/library/SphinxSearch/sphinxapi-2.2.10.php @@ -141,7 +141,7 @@ define ( "SPH_GROUPBY_ATTRPAIR", 5 ); function sphPackI64 ( $v ) { assert ( is_numeric($v) ); - + // x64 if ( PHP_INT_SIZE>=8 ) { @@ -153,7 +153,7 @@ function sphPackI64 ( $v ) if ( is_int($v) ) return pack ( "NN", $v < 0 ? -1 : 0, $v ); - // x32, bcmath + // x32, bcmath if ( function_exists("bcmul") ) { if ( bccomp ( $v, 0 ) == -1 ) @@ -190,16 +190,16 @@ function sphPackI64 ( $v ) function sphPackU64 ( $v ) { assert ( is_numeric($v) ); - + // x64 if ( PHP_INT_SIZE>=8 ) { assert ( $v>=0 ); - + // x64, int if ( is_int($v) ) return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); - + // x64, bcmath if ( function_exists("bcmul") ) { @@ -207,12 +207,12 @@ function sphPackU64 ( $v ) $l = bcmod ( $v, 4294967296 ); return pack ( "NN", $h, $l ); } - + // x64, no-bcmath $p = max ( 0, strlen($v) - 13 ); $lo = (int)substr ( $v, $p ); $hi = (int)substr ( $v, 0, $p ); - + $m = $lo + $hi*1316134912; $l = $m % 4294967296; $h = $hi*2328 + (int)($m/4294967296); @@ -223,7 +223,7 @@ function sphPackU64 ( $v ) // x32, int if ( is_int($v) ) return pack ( "NN", 0, $v ); - + // x32, bcmath if ( function_exists("bcmul") ) { @@ -236,7 +236,7 @@ function sphPackU64 ( $v ) $p = max(0, strlen($v) - 13); $lo = (float)substr($v, $p); $hi = (float)substr($v, 0, $p); - + $m = $lo + $hi*1316134912.0; $q = floor($m / 4294967296.0); $l = $m - ($q * 4294967296.0); @@ -292,11 +292,11 @@ function sphUnpackU64 ( $v ) // x32, bcmath if ( function_exists("bcmul") ) return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); - + // x32, no-bcmath $hi = (float)$hi; $lo = (float)$lo; - + $q = floor($hi/10000000.0); $r = $hi - $q*10000000.0; $m = $lo + $r*4967296.0; @@ -339,7 +339,7 @@ function sphUnpackI64 ( $v ) return $lo; return sprintf ( "%.0f", $lo - 4294967296.0 ); } - + $neg = ""; $c = 0; if ( $hi<0 ) @@ -348,7 +348,7 @@ function sphUnpackI64 ( $v ) $lo = ~$lo; $c = 1; $neg = "-"; - } + } $hi = sprintf ( "%u", $hi ); $lo = sprintf ( "%u", $lo ); @@ -360,7 +360,7 @@ function sphUnpackI64 ( $v ) // x32, no-bcmath $hi = (float)$hi; $lo = (float)$lo; - + $q = floor($hi/10000000.0); $r = $hi - $q*10000000.0; $m = $lo + $r*4967296.0; @@ -550,7 +550,7 @@ class SphinxClient $this->_path = $host; return; } - + $this->_host = $host; $port = intval($port); assert ( 0<=$port && $port<65536 ); @@ -630,14 +630,14 @@ class SphinxClient $fp = @fsockopen ( $host, $port, $errno, $errstr ); else $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); - + if ( !$fp ) { if ( $this->_path ) $location = $this->_path; else $location = "{$this->_host}:{$this->_port}"; - + $errstr = trim ( $errstr ); $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; $this->_connerror = true; @@ -768,7 +768,7 @@ class SphinxClient /// set matching mode function SetMatchMode ( $mode ) { - trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED ); + //trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED ); assert ( $mode==SPH_MATCH_ALL || $mode==SPH_MATCH_ANY || $mode==SPH_MATCH_PHRASE @@ -863,7 +863,7 @@ class SphinxClient $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); } } - + /// set string filter /// only match records where $attribute value is equal function SetFilterString ( $attribute, $value, $exclude=false ) @@ -871,7 +871,7 @@ class SphinxClient assert ( is_string($attribute) ); assert ( is_string($value) ); $this->_filters[] = array ( "type"=>SPH_FILTER_STRING, "attr"=>$attribute, "exclude"=>$exclude, "value"=>$value ); - } + } /// set range filter /// only match records if $attribute value is beetwen $min and $max (inclusive) @@ -970,7 +970,7 @@ class SphinxClient assert ( is_string ( $select ) ); $this->_select = $select; } - + function SetQueryFlag ( $flag_name, $flag_value ) { $known_names = array ( "reverse_scan", "sort_method", "max_predicted_time", "boolean_simplify", "idf", "global_idf" ); @@ -982,10 +982,10 @@ class SphinxClient "idf" => array ("normalized", "plain", "tfidf_normalized", "tfidf_unnormalized" ), "global_idf" => array ( true, false ), ); - + assert ( isset ( $flag_name, $known_names ) ); assert ( in_array( $flag_value, $flags[$flag_name], true ) || ( $flag_name=="max_predicted_time" && is_int ( $flag_value ) && $flag_value>=0 ) ); - + if ( $flag_name=="reverse_scan" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 0, $flag_value==1 ); if ( $flag_name=="sort_method" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 1, $flag_value=="kbuffer" ); if ( $flag_name=="max_predicted_time" ) @@ -998,7 +998,7 @@ class SphinxClient if ( $flag_name=="global_idf" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 5, $flag_value ); if ( $flag_name=="idf" && ( $flag_value=="tfidf_normalized" || $flag_value=="tfidf_unnormalized" ) ) $this->_query_flags = sphSetBit ( $this->_query_flags, 6, $flag_value=="tfidf_normalized" ); } - + /// set outer order by parameters function SetOuterSelect ( $orderby, $offset, $limit ) { @@ -1014,7 +1014,7 @@ class SphinxClient $this->_hasouter = true; } - + ////////////////////////////////////////////////////////////////////////////// /// clear all filters (for multi-queries) @@ -1038,7 +1038,7 @@ class SphinxClient { $this->_overrides = array (); } - + function ResetQueryFlag () { $this->_query_flags = sphSetBit ( 0, 6, true ); // default idf=tfidf_normalized @@ -1126,7 +1126,7 @@ class SphinxClient case SPH_FILTER_FLOATRANGE: $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); break; - + case SPH_FILTER_STRING: $req .= pack ( "N", strlen($filter["value"]) ) . $filter["value"]; break; @@ -1196,11 +1196,11 @@ class SphinxClient // select-list $req .= pack ( "N", strlen($this->_select) ) . $this->_select; - + // max_predicted_time if ( $this->_predictedtime>0 ) $req .= pack ( "N", (int)$this->_predictedtime ); - + $req .= pack ( "N", strlen($this->_outerorderby) ) . $this->_outerorderby; $req .= pack ( "NN", $this->_outeroffset, $this->_outerlimit ); if ( $this->_hasouter ) @@ -1356,7 +1356,7 @@ class SphinxClient if ( $type==SPH_ATTR_FLOAT ) { list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); + list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); $attrvals[$attr] = $fval; continue; } @@ -1384,11 +1384,11 @@ class SphinxClient } else if ( $type==SPH_ATTR_STRING ) { $attrvals[$attr] = substr ( $response, $p, $val ); - $p += $val; + $p += $val; } else if ( $type==SPH_ATTR_FACTORS ) { $attrvals[$attr] = substr ( $response, $p, $val-4 ); - $p += $val-4; + $p += $val-4; } else { $attrvals[$attr] = sphFixUint($val); @@ -1469,7 +1469,7 @@ class SphinxClient if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; if ( !isset($opts["load_files_scattered"]) ) $opts["load_files_scattered"] = false; - + ///////////////// // build request @@ -1760,7 +1760,7 @@ class SphinxClient fclose ( $this->_socket ); $this->_socket = false; - + return true; } diff --git a/library/SphinxSearch/sphinxapi-2.2.9.php b/library/SphinxSearch/sphinxapi-2.2.9.php index c6c1978b..1f828986 100644 --- a/library/SphinxSearch/sphinxapi-2.2.9.php +++ b/library/SphinxSearch/sphinxapi-2.2.9.php @@ -133,7 +133,7 @@ define ( "SPH_GROUPBY_ATTRPAIR", 5 ); function sphPackI64 ( $v ) { assert ( is_numeric($v) ); - + // x64 if ( PHP_INT_SIZE>=8 ) { @@ -145,7 +145,7 @@ function sphPackI64 ( $v ) if ( is_int($v) ) return pack ( "NN", $v < 0 ? -1 : 0, $v ); - // x32, bcmath + // x32, bcmath if ( function_exists("bcmul") ) { if ( bccomp ( $v, 0 ) == -1 ) @@ -182,16 +182,16 @@ function sphPackI64 ( $v ) function sphPackU64 ( $v ) { assert ( is_numeric($v) ); - + // x64 if ( PHP_INT_SIZE>=8 ) { assert ( $v>=0 ); - + // x64, int if ( is_int($v) ) return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); - + // x64, bcmath if ( function_exists("bcmul") ) { @@ -199,12 +199,12 @@ function sphPackU64 ( $v ) $l = bcmod ( $v, 4294967296 ); return pack ( "NN", $h, $l ); } - + // x64, no-bcmath $p = max ( 0, strlen($v) - 13 ); $lo = (int)substr ( $v, $p ); $hi = (int)substr ( $v, 0, $p ); - + $m = $lo + $hi*1316134912; $l = $m % 4294967296; $h = $hi*2328 + (int)($m/4294967296); @@ -215,7 +215,7 @@ function sphPackU64 ( $v ) // x32, int if ( is_int($v) ) return pack ( "NN", 0, $v ); - + // x32, bcmath if ( function_exists("bcmul") ) { @@ -228,7 +228,7 @@ function sphPackU64 ( $v ) $p = max(0, strlen($v) - 13); $lo = (float)substr($v, $p); $hi = (float)substr($v, 0, $p); - + $m = $lo + $hi*1316134912.0; $q = floor($m / 4294967296.0); $l = $m - ($q * 4294967296.0); @@ -284,11 +284,11 @@ function sphUnpackU64 ( $v ) // x32, bcmath if ( function_exists("bcmul") ) return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); - + // x32, no-bcmath $hi = (float)$hi; $lo = (float)$lo; - + $q = floor($hi/10000000.0); $r = $hi - $q*10000000.0; $m = $lo + $r*4967296.0; @@ -331,7 +331,7 @@ function sphUnpackI64 ( $v ) return $lo; return sprintf ( "%.0f", $lo - 4294967296.0 ); } - + $neg = ""; $c = 0; if ( $hi<0 ) @@ -340,7 +340,7 @@ function sphUnpackI64 ( $v ) $lo = ~$lo; $c = 1; $neg = "-"; - } + } $hi = sprintf ( "%u", $hi ); $lo = sprintf ( "%u", $lo ); @@ -352,7 +352,7 @@ function sphUnpackI64 ( $v ) // x32, no-bcmath $hi = (float)$hi; $lo = (float)$lo; - + $q = floor($hi/10000000.0); $r = $hi - $q*10000000.0; $m = $lo + $r*4967296.0; @@ -542,7 +542,7 @@ class SphinxClient $this->_path = $host; return; } - + $this->_host = $host; $port = intval($port); assert ( 0<=$port && $port<65536 ); @@ -622,14 +622,14 @@ class SphinxClient $fp = @fsockopen ( $host, $port, $errno, $errstr ); else $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); - + if ( !$fp ) { if ( $this->_path ) $location = $this->_path; else $location = "{$this->_host}:{$this->_port}"; - + $errstr = trim ( $errstr ); $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; $this->_connerror = true; @@ -760,7 +760,7 @@ class SphinxClient /// set matching mode function SetMatchMode ( $mode ) { - trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED ); + //trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED ); assert ( $mode==SPH_MATCH_ALL || $mode==SPH_MATCH_ANY || $mode==SPH_MATCH_PHRASE @@ -855,7 +855,7 @@ class SphinxClient $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); } } - + /// set string filter /// only match records where $attribute value is equal function SetFilterString ( $attribute, $value, $exclude=false ) @@ -863,7 +863,7 @@ class SphinxClient assert ( is_string($attribute) ); assert ( is_string($value) ); $this->_filters[] = array ( "type"=>SPH_FILTER_STRING, "attr"=>$attribute, "exclude"=>$exclude, "value"=>$value ); - } + } /// set range filter /// only match records if $attribute value is beetwen $min and $max (inclusive) @@ -962,7 +962,7 @@ class SphinxClient assert ( is_string ( $select ) ); $this->_select = $select; } - + function SetQueryFlag ( $flag_name, $flag_value ) { $known_names = array ( "reverse_scan", "sort_method", "max_predicted_time", "boolean_simplify", "idf", "global_idf" ); @@ -974,10 +974,10 @@ class SphinxClient "idf" => array ("normalized", "plain", "tfidf_normalized", "tfidf_unnormalized" ), "global_idf" => array ( true, false ), ); - + assert ( isset ( $flag_name, $known_names ) ); assert ( in_array( $flag_value, $flags[$flag_name], true ) || ( $flag_name=="max_predicted_time" && is_int ( $flag_value ) && $flag_value>=0 ) ); - + if ( $flag_name=="reverse_scan" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 0, $flag_value==1 ); if ( $flag_name=="sort_method" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 1, $flag_value=="kbuffer" ); if ( $flag_name=="max_predicted_time" ) @@ -990,7 +990,7 @@ class SphinxClient if ( $flag_name=="global_idf" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 5, $flag_value ); if ( $flag_name=="idf" && ( $flag_value=="tfidf_normalized" || $flag_value=="tfidf_unnormalized" ) ) $this->_query_flags = sphSetBit ( $this->_query_flags, 6, $flag_value=="tfidf_normalized" ); } - + /// set outer order by parameters function SetOuterSelect ( $orderby, $offset, $limit ) { @@ -1006,7 +1006,7 @@ class SphinxClient $this->_hasouter = true; } - + ////////////////////////////////////////////////////////////////////////////// /// clear all filters (for multi-queries) @@ -1030,7 +1030,7 @@ class SphinxClient { $this->_overrides = array (); } - + function ResetQueryFlag () { $this->_query_flags = sphSetBit ( 0, 6, true ); // default idf=tfidf_normalized @@ -1118,7 +1118,7 @@ class SphinxClient case SPH_FILTER_FLOATRANGE: $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); break; - + case SPH_FILTER_STRING: $req .= pack ( "N", strlen($filter["value"]) ) . $filter["value"]; break; @@ -1188,11 +1188,11 @@ class SphinxClient // select-list $req .= pack ( "N", strlen($this->_select) ) . $this->_select; - + // max_predicted_time if ( $this->_predictedtime>0 ) $req .= pack ( "N", (int)$this->_predictedtime ); - + $req .= pack ( "N", strlen($this->_outerorderby) ) . $this->_outerorderby; $req .= pack ( "NN", $this->_outeroffset, $this->_outerlimit ); if ( $this->_hasouter ) @@ -1348,7 +1348,7 @@ class SphinxClient if ( $type==SPH_ATTR_FLOAT ) { list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); + list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); $attrvals[$attr] = $fval; continue; } @@ -1376,11 +1376,11 @@ class SphinxClient } else if ( $type==SPH_ATTR_STRING ) { $attrvals[$attr] = substr ( $response, $p, $val ); - $p += $val; + $p += $val; } else if ( $type==SPH_ATTR_FACTORS ) { $attrvals[$attr] = substr ( $response, $p, $val-4 ); - $p += $val-4; + $p += $val-4; } else { $attrvals[$attr] = sphFixUint($val); @@ -1461,7 +1461,7 @@ class SphinxClient if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; if ( !isset($opts["load_files_scattered"]) ) $opts["load_files_scattered"] = false; - + ///////////////// // build request @@ -1752,7 +1752,7 @@ class SphinxClient fclose ( $this->_socket ); $this->_socket = false; - + return true; }