diff --git a/library/Metier/Insee/MInsee.php b/library/Metier/Insee/MInsee.php index 25ffe59f..51c15748 100644 --- a/library/Metier/Insee/MInsee.php +++ b/library/Metier/Insee/MInsee.php @@ -3094,7 +3094,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $tabRet['numGreffe'] = $etabG['NumGreffe']; $tabRet['numRC'] = $etabG['NumRC2']; $tabRet['Enseigne'] = $etabG['Enseigne']; - $iRncs = new Metier_Partenaires_MRncs($this->iDb); + $iRncs = new Metier_Partenaires_MRncs(); $tabRet['Tribunal'] = $iRncs->getCodeBodaccTribunal($etabG['NumGreffe']); } @@ -3334,7 +3334,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $iGeffes = new Metier_Partenaires_MGreffes(); $etabG = $iGeffes->getIdentite($siren); - $iRncs = new Metier_Partenaires_MRncs($this->iDb); + $iRncs = new Metier_Partenaires_MRncs(); if ($this->debugtime) { $duree=round(microtime(1)-$tdeb, 3); diff --git a/library/Metier/Partenaires/MPrivileges.php b/library/Metier/Partenaires/MPrivileges.php index 2c2e1deb..4b7fdfb2 100644 --- a/library/Metier/Partenaires/MPrivileges.php +++ b/library/Metier/Partenaires/MPrivileges.php @@ -95,7 +95,7 @@ class Metier_Partenaires_MPrivileges $where.= " ORDER BY i.dateFraiche DESC, i.insType ASC, i.insDate ASC;"; $tables = "jo.greffes_privileges i"; - $iRncs = new Metier_Partenaires_MRncs($this->iDb); + $iRncs = new Metier_Partenaires_MRncs(); $tabRet = array(); $tabPriv = $this->iDb->select($tables, $fields, $where, true, MYSQL_ASSOC); if (count($tabPriv) > 0) { @@ -149,7 +149,7 @@ class Metier_Partenaires_MPrivileges */ public function getPrivilegesCumul($siren, $tabTypes=array('03', '04')) { - $iRncs = new Metier_Partenaires_MRncs($this->iDb); + $iRncs = new Metier_Partenaires_MRncs(); $tabRet = array(); $tabTmp = $this->getPrivilegesDetail($siren, $tabTypes); diff --git a/library/Metier/Partenaires/MRncs.php b/library/Metier/Partenaires/MRncs.php index a2279ffa..dff85032 100644 --- a/library/Metier/Partenaires/MRncs.php +++ b/library/Metier/Partenaires/MRncs.php @@ -36,12 +36,11 @@ class Metier_Partenaires_MRncs 9100 => array('codeSd'=>'T', 'lib'=>'Conciliateur'), ); - public $tabDevises=array(); - public $tabPays=array(); - public $tabTribunaux=array(); - public $tabMandataires=array(); - public $tabJugements=array(); - private $iDb; + public $tabDevises = array(); + public $tabPays = array(); + public $tabTribunaux = array(); + public $tabMandataires = array(); + public $tabJugements = array(); /** Partie Extranet IMR Infogreffe **/ public $body=''; @@ -53,13 +52,25 @@ class Metier_Partenaires_MRncs public $maxDemJour=10; public $matching=null; - public function __construct($db = null) + /** + * PDO Connection with Doctrine + * @var \Doctrine\DBAL\Connection + */ + protected $conn; + + /** + * Flag to get remote data + * @var string + */ + protected $remote = false; + + /** + * RNCS + */ + public function __construct() { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } + $this->conn = Zend_Registry::get('doctrine'); + $this->tabDevises = $this->getTabDevisesInpi(); $this->tabPays = $this->getTabPaysInpi(); $this->tabTribunaux = $this->getTabTribunaux(); @@ -67,6 +78,14 @@ class Metier_Partenaires_MRncs $this->tabJugements = $this->getTabJugements(); } + /** + * Active la récupération des données distantes + */ + public function setRemote() + { + $this->remote = true; + } + public function getLibFctDir($codeFonctionDirectionRncs) { $codeFonctionDirectionRncs = $codeFonctionDirectionRncs*1; @@ -89,12 +108,14 @@ class Metier_Partenaires_MRncs if (file_exists($cache)) { return include $cache; } else { - $rep = $this->iDb->select('jo.tabDevises', 'devInpi, devIso', 'devInpi>0', false, MYSQL_ASSOC); - $tabDevises = array(); - foreach ($rep as $k=>$dev) { - $tabDevises[$dev['devInpi']*1]=$dev['devIso']; + $sql = "SELECT devInpi, devIso FROM jo.tabDevises WHERE devInpi>0 ORDER BY devInpi ASC"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { + $tabDevises[intval($item->devInpi)] = $item->devIso; + } } - return $tabDevises; } } @@ -114,7 +135,7 @@ class Metier_Partenaires_MRncs } /** - * + * Table Jugements * @return array */ public function getTabJugements() @@ -123,12 +144,15 @@ class Metier_Partenaires_MRncs if (file_exists($cache)) { return include $cache; } else { - $rep = $this->iDb->select('jo.tabJugeRncs', 'codJugement, codEven', '1', false, MYSQL_ASSOC); $tabJug = array(); - foreach ($rep as $k => $dev) { - $tabJug[$dev['codJugement']*1] = $dev['codEven']; + $sql = "SELECT codJugement, codEven FROM jo.tabJugeRncs"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { + $tabJug[intval($item->codJugement)] = $item->codEven; + } } - return $tabJug; } } @@ -146,18 +170,21 @@ class Metier_Partenaires_MRncs * Initialisation du tableau privé des pays Inpi <=> ISO * @return array */ - private function getTabPaysInpi() + protected function getTabPaysInpi() { $cache = dirname(__FILE__) . '/../Table/PaysInpi.php'; if (file_exists($cache)) { return include $cache; } else { - $rep = $this->iDb->select('jo.tabPays', 'codePaysInpi, codPays', 'codePaysInpi>0', false, MYSQL_ASSOC); $tabPays = array(); - foreach ($rep as $k => $dev) { - $tabPays[$dev['codePaysInpi']*1] = $dev['codPays']; + $sql = "SELECT codePaysInpi, codPays FROM jo.tabPays WHERE codePaysInpi>0 ORDER BY codePaysInpi ASC"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($item = $stmt->fetch(PDO::FETCH_OBJ)) { + $tabPays[$item->codePaysInpi*1] = $item->codPays; + } } - return $tabPays; } } @@ -166,39 +193,43 @@ class Metier_Partenaires_MRncs * Tableau des mandataires suceptibles d'être tranmis par l'INPI * @return array */ - private function getTabMandataires() + protected function getTabMandataires() { - $tabTmp = $this->iDb->select('jo.tabMandataires', - "UPPER(CONCAT(SUBSTRING(Nom,1,4),'-',SUBSTRING(Prenom,1,3))) AS NomPre, SUBSTRING(cp,1,2) AS dep, COUNT(*) AS Nb, sirenMand, id, sirenGrp, Nom, Prenom, type, coursAppel, tribunal, Statut, adresse, adresseComp, cp, ville, tel, fax, email, web, contact", - "TYPE IN ('A', 'M') GROUP BY NomPre, dep, sirenMand ORDER BY NomPre ASC", true, MYSQL_ASSOC); - $tabMandSD = array(); - foreach ($tabTmp as $mand) { - $tabMandSD[] = array( - 'id' => $mand['id'], - 'siren' => $mand['sirenMand'], - 'nom' => $mand['Nom'], - 'prenom'=> $mand['Prenom'], - 'type' => $mand['type'], - 'adr1' => $mand['adresse'], - 'adr2' => $mand['adresseComp'], - 'cp' => $mand['cp'], - 'ville' => $mand['ville'], - 'tel' => $mand['tel'], - 'fax' => $mand['fax'], - 'email' => $mand['email'], - ); + $sql = "SELECT UPPER(CONCAT(SUBSTRING(Nom,1,4),'-',SUBSTRING(Prenom,1,3))) AS NomPre, + SUBSTRING(cp,1,2) AS dep, COUNT(*) AS Nb, sirenMand, id, sirenGrp, Nom, Prenom, + type, coursAppel, tribunal, Statut, adresse, adresseComp, cp, ville, tel, fax, email, web, contact + FROM jo.tabMandataires WHERE TYPE IN ('A', 'M') GROUP BY NomPre, dep, sirenMand ORDER BY NomPre ASC"; + $stmt = $this->conn->executeQuery($sql); + if ($stmt->rowCount() > 0) { + while ($mand = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $tabMandSD[] = array( + 'id' => $mand['id'], + 'siren' => $mand['sirenMand'], + 'nom' => $mand['Nom'], + 'prenom' => $mand['Prenom'], + 'type' => $mand['type'], + 'adr1' => $mand['adresse'], + 'adr2' => $mand['adresseComp'], + 'cp' => $mand['cp'], + 'ville' => $mand['ville'], + 'tel' => $mand['tel'], + 'fax' => $mand['fax'], + 'email' => $mand['email'], + ); + } } + return $tabMandSD; } /** * Donne l'id du mandataire en fonction de son libellé INPI - * @param unknown $strNomPrenom + * @param string $strNomPrenom * @param string $adresse * @param string $cp * @param string $ville * @param string $debug - * @return boolean|Ambigous + * @return boolean|integer */ public function getIdMandataireInpi($strNomPrenom, $adresse='', $cp='', $ville='', $debug=false) { @@ -209,28 +240,30 @@ class Metier_Partenaires_MRncs return false; } - $tabTmp = $this->iDb->select( - 'jo.tabMandataires', - "id, Nom, Prenom, adresse, adresseComp, cp, ville, MATCH (Nom, Prenom, adresse, adresseComp, ville) AGAINST ('$strNomPrenom $adresse $ville' IN NATURAL LANGUAGE MODE) AS score", - "TYPE IN ('A', 'M') AND (Nom<>'' OR Prenom <>'') AND MATCH (Nom, Prenom, adresse, adresseComp, ville) AGAINST ('$strNomPrenom $adresse $ville' IN NATURAL LANGUAGE MODE) ORDER BY score DESC LIMIT 0,10", false, MYSQL_ASSOC); - $nbRet = count($tabTmp); - if ($nbRet == 0) { - return false; - } elseif ($nbRet == 1) { - $this->matching = $tabTmp[0]['score']; - return $tabTmp[0]['id']; - } else { - foreach ($tabTmp as $i=>$iRet) { + $sql = "SELECT id, Nom, Prenom, adresse, adresseComp, cp, ville, + MATCH (Nom, Prenom, adresse, adresseComp, ville) AGAINST ('$strNomPrenom $adresse $ville' IN NATURAL LANGUAGE MODE) AS score + FROM jo.tabMandataires + WHERE TYPE IN ('A', 'M') AND (Nom!='' OR Prenom!='') + AND MATCH (Nom, Prenom, adresse, adresseComp, ville) AGAINST ('$strNomPrenom $adresse $ville' IN NATURAL LANGUAGE MODE) + ORDER BY score DESC LIMIT 0,10"; + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() == 1) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + $this->matching = $result['score']; + return $result['id']; + } elseif ($stmt->rowCount() > 1) { + while ($iRet = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($debug) { - echo "je compare '$cp' avec '".$iRet['cp']."' et '$ville' avec '".$iRet["ville"]."' (score=".$iRet['score'].")".PHP_EOL; + echo "je compare '$cp' avec '".$iRet['cp']."' et '$ville' avec '".$iRet["ville"]."' (score=".$iRet['score'].")\n"; } if ((($iRet['cp'] == $cp || substr($iRet['cp'], 0, 2) == $cp2) && ($iRet["ville"] == $ville || preg_replace('/ 0/', ' ', $iRet["ville"]) == $ville) || (strpos($iRet["ville"], $ville) > 0 && $nbRet == 1) || $iRet["score"] > 17) - || ($cp == '' && $ville == '' && $iRet["score"] >6.88)) { - $this->matching = $iRet['score']; - return $iRet['id']; - } + || ($cp == '' && $ville == '' && $iRet["score"] > 6.88)) { + $this->matching = $iRet['score']; + return $iRet['id']; + } } } @@ -255,18 +288,24 @@ class Metier_Partenaires_MRncs * Initialisation du tableau privé des codes tribunaux Greffes/Inpi avec le libellé Bodacc * @return array */ - private function getTabTribunaux() + protected function getTabTribunaux() { $cache = dirname(__FILE__) . '/../Table/RncsTribunaux.php'; if (file_exists($cache)) { return include $cache; } else { - $rep=$this->iDb->select('jo.tribunaux', 'triNumGreffe, triNom, triId, triCode', 'triNumGreffe IS NOT NULL', false, MYSQL_ASSOC); - $tabTribunaux=array(); - foreach ($rep as $k=>$dev) { - $tabTribunaux[$dev['triNumGreffe']*1]['Id']=$dev['triId']; - $tabTribunaux[$dev['triNumGreffe']*1]['Nom']=$dev['triNom']; - $tabTribunaux[$dev['triNumGreffe']*1]['Code']=$dev['triCode']; + $tabTribunaux = array(); + $sql = "SELECT triNumGreffe, triNom, triId, triCode FROM jo.tribunaux WHERE triNumGreffe IS NOT NULL"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { + $tabTribunaux[$item->triNumGreffe*1] = array( + 'Id' => $item->triId, + 'Nom' => $item->triNom, + 'Code' => $item->triCode, + ); + } } return $tabTribunaux; } @@ -274,31 +313,38 @@ class Metier_Partenaires_MRncs /** * Libellé des FJ - * @param unknown $code_forme_juridique + * @param number $code_forme_juridique * @return string */ private function getLibelleFJ($code_forme_juridique) { $fj = $code_forme_juridique*1; + $label = 'En instance de chiffrement'; if ($fj > 0 && $fj < 10000) { - $tmp = $this->iDb->select('jo.tabFJur', 'libelle AS LibFJ', "code=$fj"); - return @$tmp[0][0]; + $stmt = $this->conn->executeQuery("SELECT libelle AS LibFJ FROM jo.tabFJur WHERE code=$fj"); + if ($stmt->rowCount() > 0) { + $label = $stmt->fetchColumn('LibFJ'); + } } - return 'En instance de chiffrement'; + return $label; } /** * Libellé des NAF - * @param unknown $codeNaf - * @return Ambigous <> + * @param string $codeNaf + * @return string */ private function getLibelleNaf($codeNaf) { - $ret = $this->iDb->query("SELECT libNaf700 AS LibNaf FROM jo.tabNaf4 WHERE codNaf700='$codeNaf' + $stmt = $this->conn->executeQuery("SELECT libNaf700 AS LibNaf FROM jo.tabNaf4 WHERE codNaf700='$codeNaf' UNION SELECT libNaf5 AS LibNaf FROM jo.tabNaf5 WHERE codNaf5='$codeNaf'"); - $res = $this->iDb->fetch(MYSQL_ASSOC); - return $res['LibNaf']; + $label = "Inconnu"; + if ($stmt->rowCount() > 0) { + $label = $stmt->fetchColumn('LibNaf'); + } + + return $label; } /** @@ -308,7 +354,7 @@ class Metier_Partenaires_MRncs */ public function getLibTribunal($numTribunal) { - if ($numTribunal*1>0) { + if ($numTribunal*1 > 0) { return $this->tabTribunaux[$numTribunal*1]['Nom']; } @@ -322,7 +368,7 @@ class Metier_Partenaires_MRncs */ public function getCodeBodaccTribunal($numTribunal) { - if ($numTribunal*1>0) { + if ($numTribunal*1 > 0) { return $this->tabTribunaux[$numTribunal*1]['Code']; } @@ -336,7 +382,7 @@ class Metier_Partenaires_MRncs */ public function getIdTribunal($numTribunal) { - if ($numTribunal*1>0) { + if ($numTribunal*1 > 0) { return $this->tabTribunaux[$numTribunal*1]['Id']; } @@ -352,382 +398,444 @@ class Metier_Partenaires_MRncs */ public function getIdentiteEtab($siren, $nic=0) { - $siren=$siren*1; - $nic=$nic*1; - if ($nic>0) { - $strSql=" AND nic=$nic"; + $siren = $siren*1; + $nic = $nic*1; + if ($nic > 0) { + $strSql = " AND nic=$nic"; } else { - $strSql=" AND siege=1 ORDER BY actif DESC, nic DESC"; + $strSql = " AND siege=1 ORDER BY actif DESC, nic DESC"; } - $rep=$this->iDb->select('jo.rncs_etab', 'siren, nic, siege, actif, enseigne, nomCommercial, adrNumVoie, adrIndRep, adrLibVoie, adrTypeVoie, adrVoie, cp, commune, adrComp, adresse1, adresse2, adresse3, naf, dateFermeture, flux, DATE(dateUpdate) AS jourUpdate', "siren=$siren $strSql", false, MYSQL_ASSOC); - if (count($rep)==0) { + $sql = "SELECT siren, nic, siege, actif, enseigne, nomCommercial, adrNumVoie, adrIndRep, + adrLibVoie, adrTypeVoie, adrVoie, cp, commune, adrComp, adresse1, adresse2, adresse3, + naf, dateFermeture, flux, DATE(dateUpdate) AS jourUpdate + FROM jo.rncs_etab WHERE siren=:siren $strSql"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() == 0) { return false; } - $entrep = $rep[0]; + $result = $stmt->fetch(\PDO::FETCH_ASSOC); - if ($entrep['jourUpdate']<>'0000-00-00') { - $dateMaj=$entrep['jourUpdate']; + if ($result['jourUpdate'] != '0000-00-00') { + $dateMaj = $result['jourUpdate']; } else { - $dateMaj=$entrep['flux']; + $dateMaj = $result['flux']; } - if (trim($entrep['adresse1'])=='') { - $adresse1=trim(preg_replace('/ +/', ' ', $entrep['adrNumVoie'].' '.strtoupper($entrep['adrIndRep']).' '. strtoupper($entrep['adrLibVoie']))); + if (trim($result['adresse1'])=='') { + $adresse1 = trim(preg_replace('/ +/', ' ', $result['adrNumVoie'].' '. + strtoupper($result['adrIndRep']).' '. strtoupper($result['adrLibVoie']))); } else { - $adresse1=trim(strtoupper($entrep['adresse1'])); + $adresse1 = trim(strtoupper($result['adresse1'])); } - if (trim($entrep['adresse2'])=='') { - $adresse2=trim(strtoupper($entrep['adrComp'])); + if (trim($result['adresse2']) == '') { + $adresse2 = trim(strtoupper($result['adrComp'])); } else { - $adresse2=trim(strtoupper($entrep['adresse2'])); + $adresse2 = trim(strtoupper($result['adresse2'])); } - if (trim($entrep['adresse3'])=='') { - $adresse3=''; + if (trim($result['adresse3'])=='') { + $adresse3 = ''; } else { - $adresse3=trim(strtoupper($entrep['adresse3'])); + $adresse3 = trim(strtoupper($result['adresse3'])); } - $tabIdentite=array( - 'siren' => $entrep['siren'], - 'nic' => $entrep['nic'], - 'siret' => $entrep['siren'].$entrep['nic'], - 'actif' => $entrep['actif'], - 'actifEt' => $entrep['actif'], - 'siege' => $entrep['siege'], - 'enseigne' => strtoupper($entrep['enseigne']), - 'nomCommercial' => strtoupper($entrep['nomCommercial']), - 'adrNumVoie' => $entrep['adrNumVoie'], - 'adrIndRep' => strtoupper($entrep['adrIndRep']), - 'adrLibVoie' => strtoupper($entrep['adrLibVoie']), - 'adrTypeVoie' => strtoupper($entrep['adrTypeVoie']), - 'adrVoie' => strtoupper($entrep['adrVoie']), - 'adrComp' => strtoupper($entrep['adrComp']), - 'cp' => strtoupper($entrep['cp']), - 'commune' => strtoupper($entrep['commune']), - 'adresse1' => $adresse1, - 'adresse2' => $adresse2, - 'adresse3' => $adresse3, - 'nafEtab' => $entrep['naf'], - 'nafEtabLib' => $this->getLibelleNaf($entrep['naf']), - 'dateFerEtab' => $entrep['dateFermeture'], - 'dateMajEtab' => $dateMaj, + $tabIdentite = array( + 'siren' => $result['siren'], + 'nic' => $result['nic'], + 'siret' => $result['siren'].$result['nic'], + 'actif' => $result['actif'], + 'actifEt' => $result['actif'], + 'siege' => $result['siege'], + 'enseigne' => strtoupper($result['enseigne']), + 'nomCommercial' => strtoupper($result['nomCommercial']), + 'adrNumVoie' => $result['adrNumVoie'], + 'adrIndRep' => strtoupper($result['adrIndRep']), + 'adrLibVoie' => strtoupper($result['adrLibVoie']), + 'adrTypeVoie' => strtoupper($result['adrTypeVoie']), + 'adrVoie' => strtoupper($result['adrVoie']), + 'adrComp' => strtoupper($result['adrComp']), + 'cp' => strtoupper($result['cp']), + 'commune' => strtoupper($result['commune']), + 'adresse1' => $adresse1, + 'adresse2' => $adresse2, + 'adresse3' => $adresse3, + 'nafEtab' => $result['naf'], + 'nafEtabLib' => $this->getLibelleNaf($result['naf']), + 'dateFerEtab' => $result['dateFermeture'], + 'dateMajEtab' => $dateMaj, ); + return array_merge($tabIdentite, $this->getInfosEntrep($siren)); } /** - * - * @param unknown $siren - * @return multitype:number unknown mixed string Ambigous Ambigous <> + * InfosEntrep + * @param string $siren + * @return array */ public function getInfosEntrep($siren) { - $siren=$siren*1; - $rep = $this->iDb->select('jo.rncs_entrep', 'siren, sirenValide, actif, numGreffe, triCode, triId, numRC, numRC2, raisonSociale, nom, prenom, nomUsage, sigle, dateNaiss, lieuNaiss, sexe, nationalite, pays, naf, cj, capitalMontant, capitalDevise, capitalDevIso, dateImma, dateRad, capitalType, capitalCent, provisoires, flux, DATE(dateUpdate) AS jourUpdate', "siren=$siren", false, MYSQL_ASSOC); + $siren = $siren*1; - if (count($rep)>0) { - $entrep=$rep[0]; - - if ($entrep['jourUpdate']<>'0000-00-00') { - $dateMaj=$entrep['jourUpdate']; + $sql = "SELECT siren, sirenValide, actif, numGreffe, triCode, triId, numRC, numRC2, raisonSociale, nom, prenom, nomUsage, sigle, dateNaiss, lieuNaiss, sexe, nationalite, pays, naf, cj, capitalMontant, capitalDevise, capitalDevIso, dateImma, dateRad, capitalType, capitalCent, provisoires, flux, DATE(dateUpdate) AS jourUpdate + FROM jo.rncs_entrep WHERE siren=:siren"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $entrep = $stmt->fetch(\PDO::FETCH_ASSOC); + if ($entrep['jourUpdate'] != '0000-00-00') { + $dateMaj = $entrep['jourUpdate']; } else { - $dateMaj=$entrep['flux']; + $dateMaj = $entrep['flux']; } - $tabIdentite = array( - 'siren' => $entrep['siren'], - 'sirenValide' => $entrep['sirenValide'], - 'actif' => $entrep['actif'], - 'actifEn' => $entrep['actif'], - 'numGreffe' => $entrep['numGreffe'], - 'triCode' => $entrep['triCode'], - 'triId' => $entrep['triId'], - 'libGreffe' => preg_replace('/^(TC |TGI |TGIcc |TMX |Tribunal Inconnu)/Ui', '', $this->getLibTribunal($entrep['numGreffe']*1)), - 'numRC' => $entrep['numRC2'], - 'raisonSociale' => strtoupper($entrep['raisonSociale']), - 'nom' => strtoupper($entrep['nom']), + 'siren' => $entrep['siren'], + 'sirenValide' => $entrep['sirenValide'], + 'actif' => $entrep['actif'], + 'actifEn' => $entrep['actif'], + 'numGreffe' => $entrep['numGreffe'], + 'triCode' => $entrep['triCode'], + 'triId' => $entrep['triId'], + 'libGreffe' => preg_replace('/^(TC |TGI |TGIcc |TMX |Tribunal Inconnu)/Ui', '', $this->getLibTribunal($entrep['numGreffe']*1)), + 'numRC' => $entrep['numRC2'], + 'raisonSociale' => strtoupper($entrep['raisonSociale']), + 'nom' => strtoupper($entrep['nom']), 'prenom' => strtoupper($entrep['prenom']), - 'nomUsage' => strtoupper($entrep['nomUsage']), - 'sigle' => strtoupper($entrep['sigle']), - 'dateNaiss' => $entrep['dateNaiss'], - 'lieuNaiss' => strtoupper($entrep['lieuNaiss']), - 'sexe' => $entrep['sexe'], - 'pays' => $entrep['pays'], + 'nomUsage' => strtoupper($entrep['nomUsage']), + 'sigle' => strtoupper($entrep['sigle']), + 'dateNaiss' => $entrep['dateNaiss'], + 'lieuNaiss' => strtoupper($entrep['lieuNaiss']), + 'sexe' => $entrep['sexe'], + 'pays' => $entrep['pays'], 'cj' => $entrep['cj'], - 'cjLib' => $this->getLibelleFJ($entrep['cj']), + 'cjLib' => $this->getLibelleFJ($entrep['cj']), 'nafEnt' => $entrep['naf'], - 'nafEntLib' => $this->getLibelleNaf($entrep['naf']), - 'capital' => $entrep['capitalMontant']+($entrep['capitalCent']/100), + 'nafEntLib' => $this->getLibelleNaf($entrep['naf']), + 'capital' => $entrep['capitalMontant']+($entrep['capitalCent']/100), 'capitalDev' => $entrep['capitalDevIso'], - 'capitalType' => $entrep['capitalType'], - 'dateImma' => $entrep['dateImma'], - 'dateRad' => $entrep['dateRad'], - 'provisoires' => $entrep['provisoires'], + 'capitalType' => $entrep['capitalType'], + 'dateImma' => $entrep['dateImma'], + 'dateRad' => $entrep['dateRad'], + 'provisoires' => $entrep['provisoires'], 'dateMajEnt' => $dateMaj, ); return $tabIdentite; } + return false; } /** - * + * Liste des depots * @param string $siren * @param string $dateDepot AAAA-MM-JJ * @return array */ public function getListeDepots($siren, $dateDepot = null) { - $where = "e.siren=$siren ORDER BY e.dateDepot DESC, e.codeInterne ASC"; + $sql = "SELECT e.siren, e.codeInterne, e.dateDepot, e.codeEven, l.libEven, e.flux, DATE(e.dateInsert) AS dateInsert + FROM jo.rncs_even e LEFT JOIN jo.tabEvenRncs l ON e.codeEven=l.codeEven"; + $where = " e.siren=$siren ORDER BY e.dateDepot DESC, e.codeInterne ASC"; if (null != $dateDepot) { - $where = "e.siren=$siren AND e.dateDepot='$dateDepot'"; + $where = " e.siren=$siren AND e.dateDepot='$dateDepot'"; } - - $rep=$this->iDb->select( - 'jo.rncs_even e LEFT JOIN jo.tabEvenRncs l ON e.codeEven=l.codeEven', - 'e.siren, e.codeInterne, e.dateDepot, e.codeEven, l.libEven, e.flux, DATE(e.dateInsert) AS dateInsert', - $where, false, MYSQL_ASSOC); - - $tabDepots=array(); - if (count($rep)>0) { - foreach ($rep as $iDepot=>$depot) { + $sql.= " WHERE ".$where; + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + $tabDepots = array(); + if ($stmt->rowCount() > 0) { + while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { $tabDepots[] = array( - 'codDepot' => $depot['codeEven'], - 'libDepot' => $depot['libEven'], - 'datDepot' => $depot['dateDepot'], - 'refDepot' => $depot['codeInterne'], - 'datRncs' => $depot['flux'], - 'datSed' => $depot['dateInsert'], + 'codDepot' => $result['codeEven'], + 'libDepot' => $result['libEven'], + 'datDepot' => $result['dateDepot'], + 'refDepot' => $result['codeInterne'], + 'datRncs' => $result['flux'], + 'datSed' => $result['dateInsert'], ); } } + return $tabDepots; } /** - * - * @param unknown $siren - * @return multitype:multitype:NULL unknown Ambigous + * Liste des jugements + * @param string $siren + * @return array */ public function getListeJugements($siren) { - $siren=$siren*1; - $rep=$this->iDb->select( - 'jo.rncs_jugements j, jo.tabJugeRncs l, jo.tabEvenements e', - 'siren, j.dateEffet, j.codeJugement, j.flux, l.libJugement, e.codEven, e.libEven, - adm1id, adm1codeFct, adm1type, adm1nom, adm1adrNum, adm1adrInd, adm1adrType, adm1adrLibVoie, adm1adrVoie, adm1adr1, adm1adr2, adm1adr3, adm1adrCP, adm1adrVille, - adm2id, adm2codeFct, adm2type, adm2nom, adm2adrNum, adm2adrInd, adm2adrType, adm2adrLibVoie, adm2adrVoie, adm2adr1, adm2adr2, adm2adr3, adm2adrCP, adm2adrVille', - "j.siren=$siren AND j.codeJugement=l.codJugement AND l.codEven=e.codEven ORDER BY j.dateEffet DESC", false, MYSQL_ASSOC); - $tabDepots=array(); - foreach ($rep as $iDepot=>$depot) { - $tabDepots[]=array( - 'codEven' => $depot['codEven'], - 'libEven' => $depot['libEven'], - 'dateEffet' => $depot['dateEffet'], - 'adm1id' => $depot['adm1id'], - 'adm1code' => $depot['adm1codeFct'], - 'adm1type' => $depot['adm1type'], - 'adm1fonction' => @$this->getLibFctDir($depot['adm1codeFct']), - 'adm1nom' => $depot['adm1nom'], - 'adm1adrNum' => $depot['adm1adrNum'], - 'adm1adrInd' => $depot['adm1adrInd'], - 'adm1adrType' => $depot['adm1adrType'], - 'adm1adrVoie' => $depot['adm1adrLibVoie'], // @todo : adm1adr1, , adm1adr3, - 'adm1adr2' => $depot['adm1adr2'], - 'adm1adrCP' => $depot['adm1adrCP'], - 'adm1adrVille' => $depot['adm1adrVille'], - 'adm2id' => $depot['adm2id'], - 'adm2code' => $depot['adm2codeFct'], - 'adm2type' => $depot['adm2type'], - 'adm2fonction' => @$this->getLibFctDir($depot['adm2codeFct']), - 'adm2nom' => $depot['adm2nom'], - 'adm2adrNum' => $depot['adm2adrNum'], - 'adm2adrInd' => $depot['adm2adrInd'], - 'adm2adrType' => $depot['adm2adrType'], - 'adm2adrVoie' => $depot['adm2adrLibVoie'], // @todo : adm1adr1, adm1adr2, adm1adr3, - 'adm2adr2' => $depot['adm2adr2'], - 'adm2adrCP' => $depot['adm2adrCP'], - 'adm2adrVille' => $depot['adm2adrVille'], - ); + $siren = $siren*1; + $tabDepots = array(); + $sql = "SELECT siren, j.dateEffet, j.codeJugement, j.flux, l.libJugement, e.codEven, e.libEven, + adm1id, adm1codeFct, adm1type, adm1nom, adm1adrNum, adm1adrInd, adm1adrType, adm1adrLibVoie, adm1adrVoie, adm1adr1, adm1adr2, adm1adr3, adm1adrCP, adm1adrVille, + adm2id, adm2codeFct, adm2type, adm2nom, adm2adrNum, adm2adrInd, adm2adrType, adm2adrLibVoie, adm2adrVoie, adm2adr1, adm2adr2, adm2adr3, adm2adrCP, adm2adrVille + FROM jo.rncs_jugements j, jo.tabJugeRncs l, jo.tabEvenements e + WHERE j.siren=:siren AND j.codeJugement=l.codJugement AND l.codEven=e.codEven ORDER BY j.dateEffet DESC"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $tabDepots[] = array( + 'codEven' => $result['codEven'], + 'libEven' => $result['libEven'], + 'dateEffet' => $result['dateEffet'], + 'adm1id' => $result['adm1id'], + 'adm1code' => $result['adm1codeFct'], + 'adm1type' => $result['adm1type'], + 'adm1fonction' => @$this->getLibFctDir($result['adm1codeFct']), + 'adm1nom' => $result['adm1nom'], + 'adm1adrNum' => $result['adm1adrNum'], + 'adm1adrInd' => $result['adm1adrInd'], + 'adm1adrType' => $result['adm1adrType'], + 'adm1adrVoie' => $result['adm1adrLibVoie'], // @todo : adm1adr1, , adm1adr3, + 'adm1adr2' => $result['adm1adr2'], + 'adm1adrCP' => $result['adm1adrCP'], + 'adm1adrVille' => $result['adm1adrVille'], + 'adm2id' => $result['adm2id'], + 'adm2code' => $result['adm2codeFct'], + 'adm2type' => $result['adm2type'], + 'adm2fonction' => @$this->getLibFctDir($result['adm2codeFct']), + 'adm2nom' => $result['adm2nom'], + 'adm2adrNum' => $result['adm2adrNum'], + 'adm2adrInd' => $result['adm2adrInd'], + 'adm2adrType' => $result['adm2adrType'], + 'adm2adrVoie' => $result['adm2adrLibVoie'], // @todo : adm1adr1, adm1adr2, adm1adr3, + 'adm2adr2' => $result['adm2adr2'], + 'adm2adrCP' => $result['adm2adrCP'], + 'adm2adrVille' => $result['adm2adrVille'], + ); + } } + return $tabDepots; } + /** + * Evenements + * @param string $siren + * @param number $nic + * @param string $type + * @param string $dateDeb + * @param string $dateFin + * @return array + */ public function getEvenements($siren, $nic=0, $type='', $dateDeb='', $dateFin='') { - $tabEven=array( - 'p120'=>'Réactivation de l\'entreprise', - 'p410'=>'Cessation juridique de l\'entreprise', - 'pCAP'=>'Modification du capital social', - 'pCAT'=>'Modification du type de capital', - 'pCJ' =>'Modification de la forme juridique', - 'pIMM'=>'Modification de la date d\'immatriculation', - 'pRAD'=>'Modification de la date de radiation', - 'pNTR'=>'Modification du greffe d\'enregistrement', - 'pNRC'=>'Modification du numéro du RC', - 'pNOM'=>'Modification de la dénomination', + $tabEven = array( + 'p120' => 'Réactivation de l\'entreprise', + 'p410' => 'Cessation juridique de l\'entreprise', + 'pCAP' => 'Modification du capital social', + 'pCAT' => 'Modification du type de capital', + 'pCJ' => 'Modification de la forme juridique', + 'pIMM' => 'Modification de la date d\'immatriculation', + 'pRAD' => 'Modification de la date de radiation', + 'pNTR' => 'Modification du greffe d\'enregistrement', + 'pNRC' => 'Modification du numéro du RC', + 'pNOM' => 'Modification de la dénomination', ); - $tabRet=array(); - $siren=$siren*1; - if ($nic>0) { - $strNic =" AND nic=$nic "; + + $tabRet = array(); + $siren = $siren*1; + + if ($nic > 0) { + $strNic = " AND nic=$nic"; } - if ($type<>'') { - $strType=" AND champs='$type' "; + if ($type != '') { + $strType = " AND champs='$type'"; } - if ($dateDeb<>'') { - $strDateDeb=" AND flux>='$dateDeb' "; + if ($dateDeb != '') { + $strDateDeb = " AND flux>='$dateDeb'"; } - if ($dateFin<>'') { - $strDateFin=" AND flux<='$dateFin' "; + if ($dateFin != '') { + $strDateFin = " AND flux<='$dateFin'"; } - $rep=$this->iDb->select( - 'jo.rncs_modifs', - 'siren, nic, `table`, champs, valeur, flux, dateInsert', - "siren=$siren $strNic $strType $strDateDeb $strDateFin AND `table`='rncs_entrep' ORDER BY flux DESC", false, MYSQL_ASSOC); - foreach ($rep as $iModif=>$modif) { - $codEve=array(); - switch ($modif['champs']) { - case 'actif': - if ($modif['valeur']*1==0) { - $codEve[]='410'; - } // Cessation - elseif ($modif['valeur']*1==1) { - $codEve[]='120'; - } // Réactivation - break; - case 'raisonSociale': $codEve[]='NOM'; break; - case 'capitalMontant': $codEve[]='CAP'; break; - case 'capitalType': $codEve[]='CAT'; break; - case 'cj': $codEve[]='CJ'; break; - case 'dateImma': $codEve[]='IMM'; break; - case 'dateRad': $codEve[]='RAD'; break; - case 'numGreffe': $codEve[]='NTR'; break; - case 'numRC2': $codEve[]='NRC'; break; - } - foreach ($codEve as $even) { - $tabRet[]=array( - 'codeEven' => 'P'.$even, - 'nic' => 0, - 'siretAssocie'=>0, - 'typeSiretAss'=>0, - 'siege' => 1, - 'libEven' => $tabEven['p'.trim($even)], - 'libEvenDet'=> '', - 'dateMAJ' => $modif['dateInsert'], - 'dateEven' => $modif['flux'], - ); - } - } - } - - public function getIntervenants($siren) - { - $tabJuge = $this->getListeJugements($siren); - $tabDepots =$tabDeja = array(); - $tabAdm = array( - 'A'=>'Administrateur judiciaire', - 'C'=>'Commissaire au plan', - 'D'=>'Commissaire au concordat', - 'H'=>'Huissier', - 'J'=>'Juge Commissaire', - 'K'=>'Juge Commissaire suppléant', - 'L'=>'Liquidateur', - 'M'=>'Mandataire judiciaire', - 'N'=>'Notaire', - 'O'=>'Opposition', - 'R'=>'Représentant des créanciers', - 'S'=>'Syndic', - 'T'=>'Conciliateur', - 'U'=>'Curateur', - 'V'=>'Avocat', - ); - foreach ($tabJuge as $iDepot => $depot) { - if ($depot['adm1code']>0 && !in_array($depot['adm1code'], $tabDeja)) { - $tabDepots[] = array( - 'codEven' => $depot['codEven'], - 'libEven' => $depot['libEven'], - 'dateEffet' => $depot['dateEffet'], - 'admid' => $depot['adm1id'], - 'admcode' => $depot['adm1code'], - 'admtype' => $depot['adm1type'], - 'admfonction' => $depot['adm1fonction'], - 'admnom' => $depot['adm1nom'], - 'admadrNum' => $depot['adm1adrNum'], - 'admadrInd' => $depot['adm1adrInd'], - 'admadrType' => $depot['adm1adrType'], - 'admadrVoie' => $depot['adm1adrVoie'], // @todo : adm1adr1, adm1adr2, adm1adr3, - 'admadr2' => $depot['adm1adr2'], - 'admadrCP' => $depot['adm1adrCP'], - 'admadrVille' => $depot['adm1adrVille'], - ); - $tabDeja[] = $depot['adm1code']; - } - if ($depot['adm2code']>0 && !in_array($depot['adm2code'], $tabDeja)) { - $tabDepots[]=array( - 'codEven' => $depot['codEven'], - 'libEven' => $depot['libEven'], - 'dateEffet' => $depot['dateEffet'], - 'admid' => $depot['adm2id'], - 'admcode' => $depot['adm2code'], - 'admtype' => $depot['adm2type'], - 'admfonction' => $depot['adm2fonction'], - 'admnom' => $depot['adm2nom'], - 'admadrNum' => $depot['adm2adrNum'], - 'admadrInd' => $depot['adm2adrInd'], - 'admadrType' => $depot['adm2adrType'], - 'admadrVoie' => $depot['adm2adrVoie'], // @todo : adm1adr1, adm1adr2, adm1adr3, - 'admadr2' => $depot['adm2adr2'], - 'admadrCP' => $depot['adm2adrCP'], - 'admadrVille' => $depot['adm2adrVille'], - ); - $tabDeja[] =$depot['adm2code']; - } - } - if (count($tabDepots)>0) { - $strTypes="IN ('J','K','H','V','N')"; - $forceRecherche=false; - $strDates="AND ABS(DATEDIFF(dateJugement, '".$depot['dateEffet']."'))<60 "; - } else { - $strTypes="<>''"; - $forceRecherche=true; - $strDates=''; - } - - $tabTmp=$this->iDb->select('jo.annonces', - 'id, siren, typeEven, dateJugement, dateCessationPaiement, inter1type, inter1id, inter1nom, inter2type, inter2id, inter2nom, inter3type, inter3id, inter3nom, inter4type, inter4id, inter4nom, dateSource, dateInsert, source, tribunal, raisonSociale', - "siren=$siren $strDates AND ( inter1type $strTypes OR inter2type $strTypes OR inter3type $strTypes OR inter4type $strTypes ) AND typeEven BETWEEN 1000 AND 2000 ORDER BY dateJugement DESC", false, MYSQL_ASSOC); - if (isset($tabTmp[0])) { - $depot=$tabTmp[0]; - $tabRet['dateCessationPaiement']=$depot['dateCessationPaiement']; - for ($i=1; $i<4; $i++) { - if (($forceRecherche && !in_array($tabTmp['inter'.$i.'type'], $tabDeja)) || - ($tabTmp['inter'.$i.'type']=='J' || $tabTmp['inter'.$i.'type']=='K' || - $tabTmp['inter'.$i.'type']=='H' || $tabTmp['inter'.$i.'type']=='V' || - $tabTmp['inter'.$i.'type']=='N')) { - $tabDepots[]=array( 'codEven' => $depot['typeEven'], - 'libEven' => $depot['typeEven'], - 'dateEffet' => $depot['dateJugement'], - 'admid' => $depot['inter'.$i.'id'], - 'admcode' => $depot['inter'.$i.'id'], - 'admtype' => $depot['inter'.$i.'type'], - 'admfonction' => $tabAdm[$depot['inter'.$i.'type']], - 'admnom' => $depot['inter'.$i.'nom'], - 'admadrNum' => '', - 'admadrInd' => '', - 'admadrType' => '', - 'admadrVoie' => '', - 'admadr2' => '', - 'admadrCP' => '', - 'admadrVille' => '', - ); - $tabDeja[]=$tabTmp['inter'.$i.'type']; + $sql = "SELECT siren, nic, `table`, champs, valeur, flux, dateInsert FROM jo.rncs_modifs + WHERE siren=:siren $strNic $strType $strDateDeb $strDateFin AND `table`='rncs_entrep' + ORDER BY flux DESC"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $codEve = array(); + switch ($result['champs']) { + case 'actif': + // Cessation + if ($result['valeur']*1 == 0) { + $codEve[] = '410'; + } + // Réactivation + elseif ($result['valeur']*1 == 1) { + $codEve[] = '120'; + } + break; + case 'raisonSociale': + $codEve[] = 'NOM'; + break; + case 'capitalMontant': + $codEve[] = 'CAP'; + break; + case 'capitalType': + $codEve[] = 'CAT'; + break; + case 'cj': + $codEve[] = 'CJ'; + break; + case 'dateImma': + $codEve[] = 'IMM'; + break; + case 'dateRad': + $codEve[] = 'RAD'; + break; + case 'numGreffe': + $codEve[] = 'NTR'; + break; + case 'numRC2': + $codEve[] = 'NRC'; + break; + } + foreach ($codEve as $even) { + $tabRet[] = array( + 'codeEven' => 'P'.$even, + 'nic' => 0, + 'siretAssocie' => 0, + 'typeSiretAss' => 0, + 'siege' => 1, + 'libEven' => $tabEven['p'.trim($even)], + 'libEvenDet' => '', + 'dateMAJ' => $result['dateInsert'], + 'dateEven' => $result['flux'], + ); } } } + + return $tabRet; + } + + /** + * Intervenants + * @param string $siren + * @return array + */ + public function getIntervenants($siren) + { + $tabJuge = $this->getListeJugements($siren); + $tabDepots = $tabDeja = array(); + $tabAdm = array( + 'A' => 'Administrateur judiciaire', + 'C' => 'Commissaire au plan', + 'D' => 'Commissaire au concordat', + 'H' => 'Huissier', + 'J' => 'Juge Commissaire', + 'K' => 'Juge Commissaire suppléant', + 'L' => 'Liquidateur', + 'M' => 'Mandataire judiciaire', + 'N' => 'Notaire', + 'O' => 'Opposition', + 'R' => 'Représentant des créanciers', + 'S' => 'Syndic', + 'T' => 'Conciliateur', + 'U' => 'Curateur', + 'V' => 'Avocat', + ); + foreach ($tabJuge as $iDepot => $depot) { + if ($depot['adm1code'] > 0 && !in_array($depot['adm1code'], $tabDeja)) { + $tabDepots[] = array( + 'codEven' => $depot['codEven'], + 'libEven' => $depot['libEven'], + 'dateEffet' => $depot['dateEffet'], + 'admid' => $depot['adm1id'], + 'admcode' => $depot['adm1code'], + 'admtype' => $depot['adm1type'], + 'admfonction' => $depot['adm1fonction'], + 'admnom' => $depot['adm1nom'], + 'admadrNum' => $depot['adm1adrNum'], + 'admadrInd' => $depot['adm1adrInd'], + 'admadrType' => $depot['adm1adrType'], + 'admadrVoie' => $depot['adm1adrVoie'], // @todo : adm1adr1, adm1adr2, adm1adr3, + 'admadr2' => $depot['adm1adr2'], + 'admadrCP' => $depot['adm1adrCP'], + 'admadrVille' => $depot['adm1adrVille'], + ); + $tabDeja[] = $depot['adm1code']; + } + if ($depot['adm2code'] > 0 && !in_array($depot['adm2code'], $tabDeja)) { + $tabDepots[] = array( + 'codEven' => $depot['codEven'], + 'libEven' => $depot['libEven'], + 'dateEffet' => $depot['dateEffet'], + 'admid' => $depot['adm2id'], + 'admcode' => $depot['adm2code'], + 'admtype' => $depot['adm2type'], + 'admfonction' => $depot['adm2fonction'], + 'admnom' => $depot['adm2nom'], + 'admadrNum' => $depot['adm2adrNum'], + 'admadrInd' => $depot['adm2adrInd'], + 'admadrType' => $depot['adm2adrType'], + 'admadrVoie' => $depot['adm2adrVoie'], // @todo : adm1adr1, adm1adr2, adm1adr3, + 'admadr2' => $depot['adm2adr2'], + 'admadrCP' => $depot['adm2adrCP'], + 'admadrVille' => $depot['adm2adrVille'], + ); + $tabDeja[] = $depot['adm2code']; + } + } + if (count($tabDepots) > 0) { + $strTypes = "IN ('J','K','H','V','N')"; + $forceRecherche = false; + $strDates = "AND ABS(DATEDIFF(dateJugement, '".$depot['dateEffet']."'))<60 "; + } else { + $strTypes = "!=''"; + $forceRecherche = true; + $strDates = ''; + } + + $sql = "SELECT id, siren, typeEven, dateJugement, dateCessationPaiement, inter1type, inter1id, + inter1nom, inter2type, inter2id, inter2nom, inter3type, inter3id, inter3nom, inter4type, + inter4id, inter4nom, dateSource, dateInsert, source, tribunal, raisonSociale + FROM jo.annonces WHERE siren=:siren $strDates + AND ( inter1type $strTypes OR inter2type $strTypes OR inter3type $strTypes OR inter4type $strTypes ) + AND typeEven BETWEEN 1000 AND 2000 ORDER BY dateJugement DESC"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + $tabRet['dateCessationPaiement'] = $depot['dateCessationPaiement']; + for ($i=1; $i<4; $i++) { + if (($forceRecherche && !in_array($result['inter'.$i.'type'], $tabDeja)) + || in_array($result['inter'.$i.'type'], array('J', 'K', 'H', 'V', 'N'))) { + $tabDepots[] = array( + 'codEven' => $result['typeEven'], + 'libEven' => $result['typeEven'], + 'dateEffet' => $result['dateJugement'], + 'admid' => $result['inter'.$i.'id'], + 'admcode' => $result['inter'.$i.'id'], + 'admtype' => $result['inter'.$i.'type'], + 'admfonction' => $tabAdm[$result['inter'.$i.'type']], + 'admnom' => $result['inter'.$i.'nom'], + 'admadrNum' => '', + 'admadrInd' => '', + 'admadrType' => '', + 'admadrVoie' => '', + 'admadr2' => '', + 'admadrCP' => '', + 'admadrVille' => '', + ); + $tabDeja[] = $result['inter'.$i.'type']; + } + } + } + return $tabDepots; } @@ -893,7 +1001,7 @@ class Metier_Partenaires_MRncs if ($origineDemande<>'') { $tabInsert['origineDemande']=$origineDemande; } - $this->iDb->insert('jo.rncs_demandes', $tabInsert, false); + $this->conn->insert('jo.rncs_demandes', $tabInsert); } } @@ -944,7 +1052,7 @@ class Metier_Partenaires_MRncs if ($origineDemande<>'') { $tabInsert['origineDemande']=$origineDemande; } - $this->iDb->insert('jo.rncs_demandes', $tabInsert, false); + $this->conn->insert('jo.rncs_demandes', $tabInsert); // Une erreur ? if ($this->infoIMR['validation-erreur']<>'') { @@ -959,93 +1067,109 @@ class Metier_Partenaires_MRncs return false; } - public function getDirigeantsPrin($siren, $nbDirs=2) + /** + * Dirigeants principaux + * @param string $siren + * @param number $nbDirs + * @return array + */ + public function getDirigeantsPrin($siren, $nbDirs = 2) { $siren = $siren*1; $tabRet = array(); - $dirs = $this->iDb->select( - 'jo.rncs_dirigeants', - 'siren, raisonSociale, dirRS, civilite, nom, prenom, naissance_nom, naissance_date, naissance_lieu, fonction_code, fonction_lib, cinf, dateFin, flux, dateInsert', - "siren=$siren AND actif%10=1 ORDER BY fonction_code DESC", true, MYSQL_ASSOC); + + $sql = "SELECT siren, raisonSociale, 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 ORDER BY fonction_code DESC"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); $numDir = 0; - foreach ($dirs as $k => $dir) { - $numDir++; - if ($dir['naissance_date']<>'0000-00-00') { - $dateNaiss = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $dir['naissance_date']); - } else { - $dateNaiss = ''; - } - if ($dir['flux']<>'0000-00-00') { - $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $dir['flux']); - } else { - $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $dir['dateInsert']); - } - $nom = trim($dir['nom']); - $nomUsage = ''; - if (trim($dir['naissance_nom']) != '') { - $nom = trim($dir['naissance_nom']); - $nomUsage = trim($dir['nom']); - } - $tabRet[] = array( - 'Fonction' => $dir['fonction_code'], - 'Titre' => $dir['fonction_lib'], - 'Societe' => $dir['dirRS'], - 'Civilite' => $dir['civilite'], - 'Nom' => $nom, - 'Prenom' => $dir['prenom'], - 'NomUsage' => $nomUsage, - 'NaissDate' => $dateNaiss, - 'NaissVille' => $dir['naissance_lieu'], - 'NaissDepPays' => '', // 25 - 'Ancien' => 0, - 'DateFct' => $dateModif, - 'Cinf' => $dir['cinf'], - ); - if ($numDir >= $nbDirs) { - break; - } - } - if ($numDir == 0) { - $dirs = $this->iDb->select( - 'jo.rncs_entrep', - "siren, raisonSociale, '' AS dirRS, IF(sexe='M', 'M', IF(sexe='F', 'MME', '')) AS civilite, nom, prenom, nomUsage AS naissance_nom, dateNaiss AS naissance_date, lieuNaiss AS naissance_lieu, 1050 AS fonction_code, 'Personne Physique' AS fonction_lib, 0 AS cinf, dateFer AS dateFin, flux, dateInsert", - "siren=$siren", true, MYSQL_ASSOC); - $numDir = 0; - foreach ($dirs as $k => $dir) { + if ($stmt->rowCount() > 0) { + while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { $numDir++; - if ($dir['naissance_date'] != '0000-00-00') { - $dateNaiss = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $dir['naissance_date']); + if ($result['naissance_date'] != '0000-00-00') { + $dateNaiss = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['naissance_date']); } else { $dateNaiss = ''; } - if ($dir['flux']<>'0000-00-00') { - $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $dir['flux']); + if ($result['flux'] != '0000-00-00') { + $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['flux']); } else { - $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $dir['dateInsert']); + $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['dateInsert']); } - $nom = trim($dir['nom']); + $nom = trim($result['nom']); $nomUsage = ''; - if (trim($dir['naissance_nom']) != '') { - $nom = trim($dir['naissance_nom']); - $nomUsage = trim($dir['nom']); + if (trim($result['naissance_nom']) != '') { + $nom = trim($result['naissance_nom']); + $nomUsage = trim($result['nom']); } $tabRet[] = array( - 'Fonction' => $dir['fonction_code'], - 'Titre' => $dir['fonction_lib'], - 'Societe' => $dir['dirRS'], - 'Civilite' => $dir['civilite'], - 'Nom' => $nom, - 'Prenom' => $dir['prenom'], - 'NomUsage' => $nomUsage, - 'NaissDate' => $dateNaiss, - 'NaissVille' => $dir['naissance_lieu'], - 'NaissDepPays' => '', // 25 + 'Fonction' => $result['fonction_code'], + 'Titre' => $result['fonction_lib'], + 'Societe' => $result['dirRS'], + 'Civilite' => $result['civilite'], + 'Nom' => $nom, + 'Prenom' => $result['prenom'], + 'NomUsage' => $nomUsage, + 'NaissDate' => $dateNaiss, + 'NaissVille' => $result['naissance_lieu'], + 'NaissDepPays' => '', 'Ancien' => 0, - 'DateFct' => $dateModif, - 'Cinf' => $dir['cinf'], + 'DateFct' => $dateModif, + 'Cinf' => $result['cinf'], ); + if ($numDir >= $nbDirs) { + break; + } + } + } else { + $sql = "SELECT siren, raisonSociale, '' AS dirRS, IF(sexe='M', 'M', IF(sexe='F', 'MME', '')) AS civilite, + nom, prenom, nomUsage AS naissance_nom, dateNaiss AS naissance_date, lieuNaiss AS naissance_lieu, + 1050 AS fonction_code, 'Personne Physique' AS fonction_lib, 0 AS cinf, dateFer AS dateFin, flux, dateInsert + FROM jo.rncs_entrep WHERE siren=:siren"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $numDir = 0; + while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $numDir++; + if ($result['naissance_date'] != '0000-00-00') { + $dateNaiss = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['naissance_date']); + } else { + $dateNaiss = ''; + } + if ($result['flux'] != '0000-00-00') { + $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['flux']); + } else { + $dateModif = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result['dateInsert']); + } + $nom = trim($result['nom']); + $nomUsage = ''; + if (trim($result['naissance_nom']) != '') { + $nom = trim($result['naissance_nom']); + $nomUsage = trim($result['nom']); + } + $tabRet[] = array( + 'Fonction' => $result['fonction_code'], + 'Titre' => $result['fonction_lib'], + 'Societe' => $result['dirRS'], + 'Civilite' => $result['civilite'], + 'Nom' => $nom, + 'Prenom' => $result['prenom'], + 'NomUsage' => $nomUsage, + 'NaissDate' => $dateNaiss, + 'NaissVille' => $result['naissance_lieu'], + 'NaissDepPays' => '', + 'Ancien' => 0, + 'DateFct' => $dateModif, + 'Cinf' => $result['cinf'], + ); + } } } + return $tabRet; } } diff --git a/library/Metier/Scores/MScores.php b/library/Metier/Scores/MScores.php index 64afcfa5..28eb010d 100644 --- a/library/Metier/Scores/MScores.php +++ b/library/Metier/Scores/MScores.php @@ -928,7 +928,7 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail /** * Différences INSEE/RNCS */ - $iRncs = new Metier_Partenaires_MRncs($iDb); + $iRncs = new Metier_Partenaires_MRncs(); $tabIdentiteRncs=$iRncs->getInfosEntrep($siren); $ACTIFRNCS = $tabIdentiteRncs['actif']; $ACTIFINSEE = $tabIdentite['Actif']; diff --git a/library/Metier/Scoring/Base.php b/library/Metier/Scoring/Base.php index 5863dbea..1423367c 100644 --- a/library/Metier/Scoring/Base.php +++ b/library/Metier/Scoring/Base.php @@ -873,7 +873,7 @@ class Metier_Scoring_Base extends Metier_Scoring_Vars /** * Différences INSEE/RNCS */ - $iRncs = new Metier_Partenaires_MRncs($this->db); + $iRncs = new Metier_Partenaires_MRncs(); $tabIdentiteRncs = $iRncs->getInfosEntrep($siren); $this->ACTIFRNCS = $tabIdentiteRncs['actif']; $this->ACTIFINSEE = $tabIdentite['Actif']; diff --git a/library/WsScore/Entreprise/v0.8/Service.php b/library/WsScore/Entreprise/v0.8/Service.php index 58bc6d68..ed42e475 100644 --- a/library/WsScore/Entreprise/v0.8/Service.php +++ b/library/WsScore/Entreprise/v0.8/Service.php @@ -294,7 +294,7 @@ class Entreprise extends Scores_Ws_Server $output = new AvisRncs(); $iDb = new Metier_Util_Db(); - $rncs = new Metier_Partenaires_MRncs($iDb); + $rncs = new Metier_Partenaires_MRncs(); //jo.etablissements => insee uniquement, rncs ? diff --git a/library/WsScore/Entreprise/v0.9/Service.php b/library/WsScore/Entreprise/v0.9/Service.php index f45ddb17..0038f97f 100644 --- a/library/WsScore/Entreprise/v0.9/Service.php +++ b/library/WsScore/Entreprise/v0.9/Service.php @@ -349,7 +349,7 @@ class Entreprise extends Scores_Ws_Server $output = new AvisRncs(); $iDb = new Metier_Util_Db(); - $rncs = new Metier_Partenaires_MRncs($iDb); + $rncs = new Metier_Partenaires_MRncs(); //jo.etablissements => insee uniquement, rncs ?