This commit is contained in:
Michael RICOIS 2017-02-02 13:47:02 +01:00
parent a7f156df7c
commit d62a0c6426

View File

@ -58,6 +58,12 @@ class Metier_Partenaires_MRncs
*/
protected $conn;
/**
* Logger
* @var \Monolog\Logger
*/
protected $logger;
/**
* Flag to get remote data
* @var string
@ -71,6 +77,10 @@ class Metier_Partenaires_MRncs
{
$this->conn = Zend_Registry::get('doctrine');
if (Zend_Registry::isRegistered('logger')) {
$this->logger = Zend_Registry::get('logger');
}
$this->tabDevises = $this->getTabDevisesInpi();
$this->tabPays = $this->getTabPaysInpi();
$this->tabTribunaux = $this->getTabTribunaux();
@ -109,13 +119,24 @@ class Metier_Partenaires_MRncs
return include $cache;
} else {
$sql = "SELECT devInpi, devIso FROM jo.tabDevises WHERE devInpi>0 ORDER BY devInpi ASC";
$stmt = $conn->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$nb = 0;
try {
$stmt = $conn->prepare($sql);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$tabDevises[intval($item->devInpi)] = $item->devIso;
}
}
return $tabDevises;
}
}
@ -146,9 +167,19 @@ class Metier_Partenaires_MRncs
} else {
$tabJug = array();
$sql = "SELECT codJugement, codEven FROM jo.tabJugeRncs";
$stmt = $conn->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$nb = 0;
try {
$stmt = $conn->prepare($sql);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$tabJug[intval($item->codJugement)] = $item->codEven;
}
@ -178,9 +209,19 @@ class Metier_Partenaires_MRncs
} else {
$tabPays = array();
$sql = "SELECT codePaysInpi, codPays FROM jo.tabPays WHERE codePaysInpi>0 ORDER BY codePaysInpi ASC";
$stmt = $conn->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$nb = 0;
try {
$stmt = $conn->prepare($sql);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($item = $stmt->fetch(PDO::FETCH_OBJ)) {
$tabPays[$item->codePaysInpi*1] = $item->codPays;
}
@ -195,12 +236,24 @@ class Metier_Partenaires_MRncs
*/
protected function getTabMandataires()
{
$tabMandSD = array();
$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) {
$nb = 0;
try {
$stmt = $this->conn->executeQuery($sql);
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($mand = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$tabMandSD[] = array(
'id' => $mand['id'],
@ -246,13 +299,22 @@ class Metier_Partenaires_MRncs
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) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb == 1) {
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
$this->matching = $result['score'];
return $result['id'];
} elseif ($stmt->rowCount() > 1) {
} elseif ($nb > 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'].")\n";
@ -296,9 +358,19 @@ class Metier_Partenaires_MRncs
} else {
$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) {
$nb = 0;
try {
$stmt = $conn->prepare($sql);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$tabTribunaux[$item->triNumGreffe*1] = array(
'Id' => $item->triId,
@ -321,8 +393,20 @@ class Metier_Partenaires_MRncs
$fj = $code_forme_juridique*1;
$label = 'En instance de chiffrement';
if ($fj > 0 && $fj < 10000) {
$stmt = $this->conn->executeQuery("SELECT libelle AS LibFJ FROM jo.tabFJur WHERE code=$fj");
if ($stmt->rowCount() > 0) {
$sql = "SELECT libelle AS LibFJ FROM jo.tabFJur WHERE code=$fj";
$nb = 0;
try {
$stmt = $conn->prepare($sql);
$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_ASSOC);
$label = $result['LibFJ'];
}
@ -338,10 +422,22 @@ class Metier_Partenaires_MRncs
*/
private function getLibelleNaf($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'");
$sql = "SELECT libNaf700 AS LibNaf FROM jo.tabNaf4 WHERE codNaf700='$codeNaf'
UNION SELECT libNaf5 AS LibNaf FROM jo.tabNaf5 WHERE codNaf5='$codeNaf'";
$label = "Inconnu";
if ($stmt->rowCount() > 0) {
$nb = 0;
try {
$stmt = $conn->prepare($sql);
$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_ASSOC);
$label = $result['LibNaf'];
}
@ -412,10 +508,19 @@ class Metier_Partenaires_MRncs
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) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb == 0) {
return false;
}
@ -483,10 +588,20 @@ class Metier_Partenaires_MRncs
$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) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
$entrep = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($entrep['jourUpdate'] != '0000-00-00') {
$dateMaj = $entrep['jourUpdate'];
@ -539,6 +654,8 @@ class Metier_Partenaires_MRncs
*/
public function getListeDepots($siren, $dateDepot = null)
{
$tabDepots = array();
$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";
@ -546,10 +663,19 @@ class Metier_Partenaires_MRncs
$where = " e.siren=$siren AND e.dateDepot='$dateDepot'";
}
$sql.= " WHERE ".$where;
$stmt = $this->conn->prepare($sql);
$stmt->execute();
$tabDepots = array();
if ($stmt->rowCount() > 0) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$tabDepots[] = array(
'codDepot' => $result['codeEven'],
@ -579,10 +705,20 @@ class Metier_Partenaires_MRncs
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) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$tabDepots[] = array(
'codEven' => $result['codEven'],
@ -662,10 +798,20 @@ class Metier_Partenaires_MRncs
$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) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$codEve = array();
switch ($result['champs']) {
@ -807,10 +953,20 @@ class Metier_Partenaires_MRncs
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) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$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_ASSOC);
$tabRet['dateCessationPaiement'] = $depot['dateCessationPaiement'];
for ($i=1; $i<4; $i++) {
@ -1079,15 +1235,25 @@ class Metier_Partenaires_MRncs
{
$siren = $siren*1;
$tabRet = array();
$numDir = 0;
$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;
if ($stmt->rowCount() > 0) {
$nb = 0;
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
$nb = $stmt->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$numDir++;
if ($result['naissance_date'] != '0000-00-00') {
@ -1126,16 +1292,26 @@ class Metier_Partenaires_MRncs
}
}
} 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) {
$nb = 0;
try {
$stmt2 = $this->conn->prepare($sql);
$stmt2->bindValue('siren', $siren);
$stmt2->execute();
$nb = $stmt2->rowCount();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($nb > 0) {
$numDir = 0;
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
while ($result = $stmt2->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']);