Suppression Zend_Db

This commit is contained in:
Michael RICOIS 2017-02-06 15:34:18 +01:00
parent c5186ab16d
commit 264fb038ec

View File

@ -1798,33 +1798,37 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
$date = $this->companyEvenDateStop;
}
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$sql = $db->select()
->from(array('e'=>'insee_even'), array(
'CONCAT(LPAD(e.insSIREN,9,0), LPAD(e.insNIC,5,0)) AS Siret',
'LPAD(e.insSIREN,9,0) AS Siren',
'LPAD(e.insNIC,5,0) AS Nic',
'insSIEGE AS Siege',
'insNOMEN AS Nom',
'insCODPOS AS CP',
'insCJ AS FJ',
'insAPEN700 AS NafEnt',
'insAPEN700 AS NafEtab',
'insTEFEN AS EffEnTr',
'insEFENCENT AS Effectif',
'insDCRET AS DateCreaEt',
'insDCREN AS DateCreaEn',
'insEVE',
), 'insee')
->joinLeft(array('i'=>'insee_notices'), 'i.insSIREN=e.insSIREN AND i.insNIC=e.insNIC', array(
'insRECME AS RECME',
), 'insee')
->where('e.insSIREN = ?', $siren)
->where('idFlux < ?', $date)
->order('idFlux DESC')->order('insSIEGE DESC')->limit(1);
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_ASSOC);
if ($result !== null) {
$identite = $result;
$sql = "SELECT CONCAT(LPAD(e.insSIREN,9,0), LPAD(e.insNIC,5,0)) AS Siret,
LPAD(e.insSIREN,9,0) AS Siren,
LPAD(e.insNIC,5,0) AS Nic,
e.insSIEGE AS Siege,
e.insNOMEN AS Nom,
e.insCODPOS AS CP,
e.insCJ AS FJ,
e.insAPEN700 AS NafEnt,
e.insAPEN700 AS NafEtab,
e.insTEFEN AS EffEnTr,
e.insEFENCENT AS Effectif,
e.insDCRET AS DateCreaEt,
e.insDCREN AS DateCreaEn,
e.insEVE,
i.insRECME AS RECME
FROM insee.insee_even e
LEFT OUTER JOIN insee.insee_notices i ON (i.insSIREN=e.insSIREN AND i.insNIC=e.insNIC)
WHERE e.insSIREN=:siren AND idFlux<:date ORDER BY idFlux DESC, insSIEGE DESC LIMIT 0,1";
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->bindValue('date', $date);
$stmt->execute();
} catch (\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($stmt->rowCount() > 0) {
$identite = $stmt->fetch(\PDO::FETCH_ASSOC);
}
// --- Recherche dans le stock
else {
@ -1834,31 +1838,37 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
break;
}
}
$sql = $db->select()
->from(array('e'=>$notice), array(
'CONCAT(LPAD(SIREN,9,0), LPAD(NIC,5,0)) AS Siret',
'LPAD(SIREN,9,0) AS Siren',
'LPAD(NIC,5,0) AS Nic',
'SIEGE AS Siege',
'NOMEN_LONG AS Nom',
'CODPOS AS CP',
'CJ AS FJ',
'APEN700 AS NafEnt',
'APEN700 AS NafEtab',
'TEFEN AS EffEnTr',
'EFENCENT AS Effectif',
'DCRET AS DateCreaEt',
'insDCREN AS DateCreaEn',
), 'historiques')
->joinLeft(array('i'=>'insee_notices'), 'i.insSIREN=e.SIREN AND i.insNIC=e.NIC', array(
'insRECME AS RECME',
), 'insee')
->where('e.insSIREN = ?', $siren)
->where('idFlux < ?', $date)
->order('idFlux DESC')->order('insSIEGE DESC')->limit(1);
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_ASSOC);
if ($result !== null) {
$identite = $result;
$sql = "SELECT CONCAT(LPAD(e.SIREN,9,0), LPAD(e.NIC,5,0)) AS Siret,
LPAD(e.SIREN,9,0) AS Siren,
LPAD(e.NIC,5,0) AS Nic,
e.SIEGE AS Siege,
e.NOMEN_LONG AS Nom,
e.CODPOS AS CP,
e.CJ AS FJ,
e.APEN700 AS NafEnt,
e.APEN700 AS NafEtab,
e.TEFEN AS EffEnTr,
e.EFENCENT AS Effectif,
e.DCRET AS DateCreaEt,
insDCREN AS DateCreaEn
i.insRECME AS RECME
FROM insee.$notice e
LEFT OUTER JOIN insee.insee_notices i ON (i.insSIREN=e.SIREN AND i.insNIC=e.NIC)
WHERE e.insSIREN=:siren AND idFlux<:date ORDER BY idFlux DESC, insSIEGE DESC LIMIT 0,1";
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->bindValue('date', $date);
$stmt->execute();
} catch (\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($stmt->rowCount() > 0) {
$identite = $stmt->fetch(\PDO::FETCH_ASSOC);
}
}
if (count($identite) > 0) {
@ -1881,15 +1891,22 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
}
// --- Capital
$sql = $db->select()
->from('rncs_modifs', array('valeur'), 'jo')
->where('champs = ?', 'capitalMontant')
->where('siren = ? ', $siren)
->where('flux < ?', $date)
->order('flux DESC')->limit(1);
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_OBJ);
$sql = "SELECT valeur FROM jo.rncs_modifs
WHERE champs='capitalMontant' AND siren=:siren AND flux<:date
ORDER BY flux DESC LIMIT 0,1";
try {
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->bindValue('date', $date);
$stmt->execute();
} catch (\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
$identite['Capital'] = '';
if ($result !== null) {
if ($stmt->rowCount() > 0) {
$result = $stmt->fetch(\PDO::FETCH_OBJ);
$identite['Capital'] = $result->valeur;
}