From 7abb183e7a401ad7f20a414f2b1d3a92ed0d1110 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 23 Jan 2017 16:23:03 +0100 Subject: [PATCH] Library Update --- library/Metier/Insee/MInsee.php | 6 +- library/Metier/Partenaires/MAmabis.php | 213 ++++++++++++--------- library/Metier/Partenaires/MBanques.php | 180 ++++++++++------- library/Metier/Partenaires/MBourse.php | 167 +++++++++------- library/Metier/Partenaires/MMap.php | 109 ++++++----- library/Metier/Partenaires/MMarques.php | 115 +++++++---- library/Metier/Partenaires/MPrivileges.php | 79 +++++--- library/Metier/Partenaires/MRncs.php | 6 +- library/Metier/Partenaires/MTel.php | 5 +- library/Metier/Partenaires/MTva.php | 28 +-- library/Metier/Scores/ICotation.php | 19 +- library/Metier/Scores/MRatios.php | 10 +- library/Metier/Scores/MScores.php | 9 +- library/Metier/Scores/MSolvabilite.php | 13 +- library/Metier/Scoring/Base.php | 10 +- scripts/jobs/enrichissement.php | 6 +- 16 files changed, 562 insertions(+), 413 deletions(-) diff --git a/library/Metier/Insee/MInsee.php b/library/Metier/Insee/MInsee.php index 88abffb9..1a6728b3 100644 --- a/library/Metier/Insee/MInsee.php +++ b/library/Metier/Insee/MInsee.php @@ -2001,7 +2001,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } // Géocodage de l'adresse - $mMap = new Metier_Partenaires_MMap(false, $this->iDb); + $mMap = new Metier_Partenaires_MMap(); $mMap->geoCodeAdresse($etab['adr_num'], '', $etab['adr_typeVoie'], $this->getCodeVoie($etab['adr_typeVoie']), $etab['adr_libVoie'], $etab['adr_cp'], $etab['adr_ville'], 'France', trim($tabInsee['ADR_DEP'].$tabInsee['ADR_COM'].$tabInsee['CODEVOIE'])); @@ -2019,7 +2019,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table $tdeb = microtime(1); } - $iAmabis = new Metier_Partenaires_MAmabis($this->iDb); + $iAmabis = new Metier_Partenaires_MAmabis(); $repAmabis = $iAmabis->getZonage($etab['adr_num'], $etab['adr_btq'], $etab['adr_typeVoie'], $etab['adr_libVoie'], $etab['adr_cp'], $etab['adr_ville'], trim($tabInsee['ADR_DEP'].$tabInsee['ADR_COM'].$tabInsee['CODEVOIE']), false, 'TEST', false); @@ -3494,7 +3494,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table } // Recherche des infos boursières - $iBourse = new Metier_Partenaires_MBourse($siren, $this->iDb); + $iBourse = new Metier_Partenaires_MBourse(); $bourse = $iBourse->getInfosBourse($siren); $tabRet['Bourse'] = array( 'placeCotation' => $bourse['placeCotation'], diff --git a/library/Metier/Partenaires/MAmabis.php b/library/Metier/Partenaires/MAmabis.php index 75ed54ea..b0b9be4f 100644 --- a/library/Metier/Partenaires/MAmabis.php +++ b/library/Metier/Partenaires/MAmabis.php @@ -5,23 +5,24 @@ ini_set('default_socket_timeout', 30); class Metier_Partenaires_MAmabis { protected $client; - protected $iDb; - public function __construct($db = null) + /** + * PDO Connection with Doctrine + * @var \Doctrine\DBAL\Connection + */ + protected $conn; + + public function __construct() { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } + $this->conn = Zend_Registry::get('doctrine'); $this->client = new SoapClient(null, array( - 'location' => 'http://sw2.amabis.com:5100/', - 'uri' => 'http://www.amabis.com/ns.xsd', + 'location' => 'http://sw2.amabis.com:5100/', + 'uri' => 'http://www.amabis.com/ns.xsd', 'connection_timeout' => 2, - 'soap_version' => SOAP_1_1, - 'trace' => 1, - 'style' => SOAP_RPC, + 'soap_version' => SOAP_1_1, + 'trace' => 1, + 'style' => SOAP_RPC, 'use' => SOAP_ENCODED, )); } @@ -51,14 +52,16 @@ class Metier_Partenaires_MAmabis $ville = addslashes($ville); $majForcee = false; - $ret = $this->iDb->select( - 'jo.zonage', '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', - "address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'", false, MYSQL_ASSOC); + $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 (count($ret) > 0) { - $zones = $ret[0]; + if ($stmt->rowCount() > 0) { + $zones = $stmt->fetch(\PDO::FETCH_ASSOC); if ($zones['rnvpStatut'] === null && $rnvp) { $majForcee = true; } @@ -110,7 +113,7 @@ class Metier_Partenaires_MAmabis } } - if (count($ret) == 0 || $majForcee) { + if ($stmt->rowCount() == 0 || $majForcee) { try { // Le RNVP ne fonctionne pas sans la Raison Sociale qui est la 1ère ligne d'adresse if (trim($raisonSociale) == '') { @@ -169,88 +172,99 @@ class Metier_Partenaires_MAmabis if (strtoupper(@trim($tabZones['ADR7']))=='FRANCE') { $tabZones['ADR7']=''; } - $tabTmp=explode('|', $tabZones['VOIEA']); - $typeVoieAcourt=@trim($tabTmp[1]); - $tabInsert=array( - 'address'=>$adresse, - 'adr_cp'=>$cp, - 'adr_ville'=>$ville, - 'zus'=>@$tabRep['NZUS'], - 'zru'=>@$tabRep['NZRU'], - 'zfu'=>@$tabRep['NZFU'], - 'cucs'=>@$tabRep['NCUCS'], + $tabTmp = explode('|', $tabZones['VOIEA']); + $typeVoieAcourt = @trim($tabTmp[1]); + $tabInsert = array( + 'address' => $adresse, + 'adr_cp' => $cp, + 'adr_ville' => $ville, + 'zus' => @$tabRep['NZUS'], + 'zru' => @$tabRep['NZRU'], + 'zfu' => @$tabRep['NZFU'], + 'cucs' => @$tabRep['NCUCS'], ); $tabUpdate=array( - 'adrNum'=>$adrNum, - 'adrIndRep'=>$adrIndRep, - 'adrTypeVoie'=>$adrTypeVoie, - 'adrLibVoie'=>$adrLibVoie, - 'rivoli'=>$codeRivoli, + 'adrNum' => $adrNum, + 'adrIndRep' => $adrIndRep, + 'adrTypeVoie' => $adrTypeVoie, + 'adrLibVoie' => $adrLibVoie, + 'rivoli' => $codeRivoli, // Ajouté le 16/12/2013 'rnvpStatut' => substr($tabZones['STATUTC'], 0, 2), - 'rnvpCorr' => substr($tabZones['STATUTC'], 2, 1), - 'rnvpTrt' => trim(substr($tabZones['STATUTC'], 3, 2)), - 'adr3' => @trim($tabZones['ADR3']), - 'adr4' => @trim($tabZones['ADR4']), - 'adr5' => @trim($tabZones['ADR5']), - 'adr6' => @trim($tabZones['ADR6']), - 'adr7' => trim($tabZones['ADR7']), - 'numVoieA' => @trim($tabZones['NUM1']), - 'indRepA' => @trim($tabZones['BTQC1']), - 'typeVoieAlong' => @trim($tabZones['TYPVOIEL']), + 'rnvpCorr' => substr($tabZones['STATUTC'], 2, 1), + 'rnvpTrt' => trim(substr($tabZones['STATUTC'], 3, 2)), + 'adr3' => @trim($tabZones['ADR3']), + 'adr4' => @trim($tabZones['ADR4']), + 'adr5' => @trim($tabZones['ADR5']), + 'adr6' => @trim($tabZones['ADR6']), + 'adr7' => trim($tabZones['ADR7']), + 'numVoieA' => @trim($tabZones['NUM1']), + 'indRepA' => @trim($tabZones['BTQC1']), + 'typeVoieAlong' => @trim($tabZones['TYPVOIEL']), 'typeVoieAcourt' => $typeVoieAcourt, - 'corpVoie' => @trim($tabZones['CORPSVOIE']), + 'corpVoie' => @trim($tabZones['CORPSVOIE']), 'motDir' => @trim($tabZones['MOTDIR']), - 'motDirD' => @trim($tabZones['MOTDIRD']), + 'motDirD' => @trim($tabZones['MOTDIRD']), 'libVoieSec' => @trim($tabZones['VOIREFLIBS']), - 'adr4n32' => @trim($tabZones['VOIREFLIBPOS']), - 'adr4n38' => @trim($tabZones['VOIREFLIBPOS2']), + 'adr4n32' => @trim($tabZones['VOIREFLIBPOS']), + 'adr4n38' => @trim($tabZones['VOIREFLIBPOS2']), 'clePostaleVoie' => @trim($tabZones['VOIREFCLEPOST']), - 'secteur' => @trim($tabZones['SECTEUR']), + 'secteur' => @trim($tabZones['SECTEUR']), 'cleRoutage' => @trim($tabZones['CLER']), - 'cpx' => @trim($tabZones['CPX']), - 'cleAd' => @trim($tabZones['CLEAD']), - 'codPaysIso2' => @trim($tabZones['NATREFISO2']), - 'codPaysIso3' => @trim($tabZones['NATREFISO3']), - 'libPays' => @trim($tabZones['NATREFLIB']), - 'codeInsee' => @trim($tabZones['LOCREFCLEO']), + 'cpx' => @trim($tabZones['CPX']), + 'cleAd' => @trim($tabZones['CLEAD']), + 'codPaysIso2' => @trim($tabZones['NATREFISO2']), + 'codPaysIso3' => @trim($tabZones['NATREFISO3']), + 'libPays' => @trim($tabZones['NATREFLIB']), + 'codeInsee' => @trim($tabZones['LOCREFCLEO']), 'source' => 'Amabis', ); - $dateInsert=0; + $dateInsert = 0; if ($majForcee) { - $adresseL=addslashes($adresse); - $villeL=addslashes($ville); - - $ret = $this->iDb->select('jo.zonage', 'dateInsert*1 as dateInsert', "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false); - $dateInsert=@$ret[0]['dateInsert']*1; - $this->iDb->update('jo.zonage', array_merge($tabUpdate, array('dateInsert'=>$dateInsert)), "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false); - //echo "Mise à jour de l'adresse du $dateInsert pour address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'".PHP_EOL; + $adresseL = addslashes($adresse); + $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) { + $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, + )); + } + } } - if ($dateInsert==0) { - $this->iDb->insert('jo.zonage', array_merge($tabInsert, $tabUpdate), false); - //echo "Insertion de l'adresse (".$zones['rnvpStatut'].")!".PHP_EOL; + if ($dateInsert == 0) { + $this->conn->insert('jo.zonage', array_merge($tabInsert, $tabUpdate)); } - $tabTmp[0]=explode(',', $tabZones['LOCREFCLEP']); - $tabTmp[1]=explode(',', $tabZones['LOCREFCP']); - $tabTmp[2]=explode(',', $tabZones['LOCREFTYPP']); - $tabTmp[3]=explode(',', $tabZones['LOCREFLIBD']); - $tabTmp[4]=explode(',', $tabZones['LOCREFLIBD2']); + $tabTmp[0] = explode(',', $tabZones['LOCREFCLEP']); + $tabTmp[1] = explode(',', $tabZones['LOCREFCP']); + $tabTmp[2] = explode(',', $tabZones['LOCREFTYPP']); + $tabTmp[3] = explode(',', $tabZones['LOCREFLIBD']); + $tabTmp[4] = explode(',', $tabZones['LOCREFLIBD2']); foreach ($tabTmp[0] as $iCleP=>$cleP) { $tabInsert = array( - 'codeInsee' => @trim($tabZones['LOCREFCLEO']), - 'villeLib' => @trim($tabZones['LOCREFLIBP']), - 'villePopu' => @trim($tabZones['LOCREFPOP']), - 'cleAchPost'=> $cleP, - 'codePostal'=> $tabTmp[1][$iCleP], - 'typePostal'=> $tabTmp[2][$iCleP], - 'libAchP32' => @preg_replace('/^\//', '', $tabTmp[3][$iCleP]), - 'libAchP38' => @preg_replace('/^\//', '', $tabTmp[4][$iCleP]), - 'source' => 'Amabis', - 'dateInsert'=> date('YmdHis'), + 'codeInsee' => @trim($tabZones['LOCREFCLEO']), + 'villeLib' => @trim($tabZones['LOCREFLIBP']), + 'villePopu' => @trim($tabZones['LOCREFPOP']), + 'cleAchPost' => $cleP, + 'codePostal' => $tabTmp[1][$iCleP], + 'typePostal' => $tabTmp[2][$iCleP], + 'libAchP32' => @preg_replace('/^\//', '', $tabTmp[3][$iCleP]), + 'libAchP38' => @preg_replace('/^\//', '', $tabTmp[4][$iCleP]), + 'source' => 'Amabis', + 'dateInsert' => date('YmdHis'), ); - $this->iDb->insert('jo.villesCP', $tabInsert, false); + $this->conn->insert('jo.villesCP', $tabInsert); } /** Autres Informations de la RNVP **/ @@ -266,19 +280,30 @@ class Metier_Partenaires_MAmabis fwrite($fp, date('d-m-Y H:i:s').' - ERREUR SOAP : Requete = '.$this->client->__getLastRequest()."\n Reponse = ".$this->client->__getLastResponse()."\n============================================================================\n"); fclose($fp); } - //return $tabRep; } - /** Zonages AFR et ZRR - **/ - $codeInsee=substr($codeRivoli, 0, 5); - $ret = $this->iDb->select('jo.zonageInsee', 'typeZone, arreteDate, decretDate, decretNum, decretModifieDate, decretModifieNum, dateDebut, dateFin', "codeInsee='$codeInsee'", false, MYSQL_ASSOC); - $tabRep['ZRR']=$tabRep['AFR']='NON'; - foreach ($ret as $zones) { - switch ($zones['typeZone']) { - case 'ZRR': $tabRep['ZRR']='OUI'; $tabRep['NZRR']=$codeInsee; break; - case 'ZAFR': $tabRep['AFR']='OUI'; $tabRep['NAFR']=$codeInsee; break; - default: break; + /** Zonages AFR et ZRR **/ + $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(); + $tabRep['ZRR'] = $tabRep['AFR'] = 'NON'; + if ($stmt->rowCount() > 0) { + while ($zones = $stmt->fetch(\PDO::FETCH_ASSOC)) { + switch ($zones['typeZone']) { + case 'ZRR': + $tabRep['ZRR'] = 'OUI'; + $tabRep['NZRR'] = $codeInsee; + break; + case 'ZAFR': + $tabRep['AFR']='OUI'; + $tabRep['NAFR']=$codeInsee; + break; + default: + break; + } } } diff --git a/library/Metier/Partenaires/MBanques.php b/library/Metier/Partenaires/MBanques.php index 36e5d31e..48dae0ef 100644 --- a/library/Metier/Partenaires/MBanques.php +++ b/library/Metier/Partenaires/MBanques.php @@ -1,98 +1,144 @@ 'établissements et services autorisés à effectuer des opérations de banque', - 1=>'banques', - 2=>'banques mutualistes ou coopératives', - 4=>'caisses de crédit municipal', - 5=>'sociétés financières 5', // la distinction entre les codes 5 et 6 ne concerne que les - 6=>'sociétés financières 6', // applications internes à la Banque de France - 7=>'institutions financières spécialisées', - 9=>'entreprises d\'investissement' + 0 => 'établissements et services autorisés à effectuer des opérations de banque', + 1 => 'banques', + 2 => 'banques mutualistes ou coopératives', + 4 => 'caisses de crédit municipal', + 5 => 'sociétés financières 5', // la distinction entre les codes 5 et 6 ne concerne que les + 6 => 'sociétés financières 6', // applications internes à la Banque de France + 7 => 'institutions financières spécialisées', + 9 => 'entreprises d\'investissement' ); + /** + * + * @var array + */ public $tabNatureGuichet = array( - 1=>'Guichet permanent de plein exercice domiciliataire (ouvert au public)', - 2=>'Identifiant de domiciliation (adresse active 5 jours par semaine)', - 3=>'Guichet permanent non domiciliataire (ouvert au public)', - 4=>'Libre Prestation de services (LPS)', - 'A'=>'Guichet fictif', - 'P'=>'Guichet fictif' + 1 => 'Guichet permanent de plein exercice domiciliataire (ouvert au public)', + 2 => 'Identifiant de domiciliation (adresse active 5 jours par semaine)', + 3 => 'Guichet permanent non domiciliataire (ouvert au public)', + 4 => 'Libre Prestation de services (LPS)', + 'A' => 'Guichet fictif', + 'P' => 'Guichet fictif' ); + /** + * + * @var array + */ public $tabOrgane = array( - 0=>'Association française des établissements de crédit et des entreprises d\'investissement', - 11=>'Association française des sociétés financières', - 12=>'Groupement des institutions financières spécialisées', - 13=>'Conférence permanente des caisses de crédit municipal', - 14=>'Association française des entreprises d\'investissement', - 15=>'Association française des entreprises d\'investissement-courtiers', - 16=>'Association française des fonds et sociétés d\'investissements et de gestion d\'actifs financiers', - 17=>'Association française des intermédiaires transmetteurs d\'ordres ', - 18=>'Fédération bancaire française', - 19=>'Ass Franc Marchés Financiers', - 20=>'Caisse nationale de crédit agricole', - 21=>'Chambre syndicale des banques populaires', - 22=>'Confédération nationale du crédit mutuel', - 23=>'Caisse centrale de crédit coopératif', - 25=>'Caisse nationale des caisses d\'épargne et de prévoyance', - 27=>'Chambre syndicale des SACI', - 28=>'Double affiliation CNCE-BFBP', - 29=>'Crédit Immobilier France Développement', - 30=>'BPCE', - 98=>'non concerné', - 99=>'en instance d\'adhésion' + 0 => 'Association française des établissements de crédit et des entreprises d\'investissement', + 11 => 'Association française des sociétés financières', + 12 => 'Groupement des institutions financières spécialisées', + 13 => 'Conférence permanente des caisses de crédit municipal', + 14 => 'Association française des entreprises d\'investissement', + 15 => 'Association française des entreprises d\'investissement-courtiers', + 16 => 'Association française des fonds et sociétés d\'investissements et de gestion d\'actifs financiers', + 17 => 'Association française des intermédiaires transmetteurs d\'ordres ', + 18 => 'Fédération bancaire française', + 19 => 'Ass Franc Marchés Financiers', + 20 => 'Caisse nationale de crédit agricole', + 21 => 'Chambre syndicale des banques populaires', + 22 => 'Confédération nationale du crédit mutuel', + 23 => 'Caisse centrale de crédit coopératif', + 25 => 'Caisse nationale des caisses d\'épargne et de prévoyance', + 27 => 'Chambre syndicale des SACI', + 28 => 'Double affiliation CNCE-BFBP', + 29 => 'Crédit Immobilier France Développement', + 30 => 'BPCE', + 98 => 'non concerné', + 99 => 'en instance d\'adhésion' ); - protected $iDb; + /** + * PDO Connection with Doctrine + * @var \Doctrine\DBAL\Connection + */ + protected $conn; - public function __construct($db = null) + public function __construct() { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } + $this->conn = Zend_Registry::get('doctrine'); } + /** + * Banque + * @param unknown $codeBanque + * @return mixed + */ public function getInfoBanque($codeBanque) { - $ret = $this->iDb->select( - 'insee.BDF_Etabs', - 'bdfFibCodeEtab, bdfFibCodeSituation, bdfFibDenom40, bdfFibDenom10, bdfFibCodeActivite, bdfFibCodeOrganeRepr, bdfFibDateAgrement, bdfFibDateRetraitAgr, bdfFibDateFinDiffus, bdfFibAdresse1, bdfFibAdresse2, bdfFibAdresse3, CP, Ville, bdfFibCodeEtabAbsorb, bdfFibOptionIdInvar, bdfFibDateOptIdInvar', - "bdfFibCodeEtab=$codeBanque", false, MYSQL_ASSOC); - //echo mysql_error(); - $tabRet=$ret[0]; - return $tabRet; + $result = array(); + $sql = "SELECT bdfFibCodeEtab, bdfFibCodeSituation, bdfFibDenom40, + bdfFibDenom10, bdfFibCodeActivite, bdfFibCodeOrganeRepr, bdfFibDateAgrement, * + bdfFibDateRetraitAgr, bdfFibDateFinDiffus, bdfFibAdresse1, bdfFibAdresse2, + bdfFibAdresse3, CP, Ville, bdfFibCodeEtabAbsorb, bdfFibOptionIdInvar, + bdfFibDateOptIdInvar FROM insee.BDF_Etabs WHERE bdfFibCodeEtab=:code LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('code', $codeBanque); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + } + + return $result; } + /** + * Guichet + * @param unknown $codeBanque + * @param unknown $codeGuichet + */ public function getInfoGuichet($codeBanque, $codeGuichet) { - $tabBanque=$this->getInfoBanque($codeBanque); - $tabTel=$this->getTelGuichet($codeBanque, $codeGuichet); - $ret = $this->iDb->select( - 'insee.BDF_Guichets', - 'bdfFibCodeEtab, bdfFibCodeGuichet, bdfFibCodeSituation AS guichetCodeSituation, bdfFibDenom40 AS guichetDenom40, bdfFibDenom20 AS guichetDenom20, bdfFibCodeEtabCible, bdfFibCodeGuichetRepr, bdfFibCodeGeoInsee, bdfFibCodeLocalite1, bdfFibCodeLocalite2, bdfFibComptoirBDF, bdfFibAdresse1 AS guichetAdresse1, bdfFibAdresse2 AS guichetAdresse2, bdfFibAdresse3 AS guichetAdresse3, CP AS guichetCP, Ville AS guichetVille, bdfFibAdresseSWIFT, bdfFibDateOuverture, bdfFibDateFermeture, bdfFibDateFinDiffus, bdfFibCodeRoutage, bdfFibLibelleRIB, bdfFibNatureGuichet, bdfFibCodeAchOperBDF, bdfFibNomComptoirBDF', - "bdfFibCodeEtab=$codeBanque AND bdfFibCodeGuichet=$codeGuichet", false, MYSQL_ASSOC); - //echo mysql_error(); - if (isset($ret[0])) { - $tabRet=@$ret[0]; - } else { - $tabRet=array(); + $result = array(); + + $tabBanque = $this->getInfoBanque($codeBanque); + $tabTel = $this->getTelGuichet($codeBanque, $codeGuichet); + + $sql = "SELECT bdfFibCodeEtab, bdfFibCodeGuichet, bdfFibCodeSituation AS guichetCodeSituation, + bdfFibDenom40 AS guichetDenom40, bdfFibDenom20 AS guichetDenom20, bdfFibCodeEtabCible, + bdfFibCodeGuichetRepr, bdfFibCodeGeoInsee, bdfFibCodeLocalite1, bdfFibCodeLocalite2, + bdfFibComptoirBDF, bdfFibAdresse1 AS guichetAdresse1, bdfFibAdresse2 AS guichetAdresse2, + bdfFibAdresse3 AS guichetAdresse3, CP AS guichetCP, Ville AS guichetVille, + bdfFibAdresseSWIFT, bdfFibDateOuverture, bdfFibDateFermeture, bdfFibDateFinDiffus, + bdfFibCodeRoutage, bdfFibLibelleRIB, bdfFibNatureGuichet, bdfFibCodeAchOperBDF, + bdfFibNomComptoirBDF FROM WHERE bdfFibCodeEtab=:banque AND bdfFibCodeGuichet=:guichet LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('banque', $codeBanque); + $stmt->bindValue('guichet', $codeGuichet); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); } - return array_merge($tabRet, $tabBanque, $tabTel); + return array_merge($result, $tabBanque, $tabTel); } + /** + * Téléphone guichet + * @param unknown $codeBanque + * @param unknown $codeGuichet + */ public function getTelGuichet($codeBanque, $codeGuichet) { - $ret = $this->iDb->select('insee.Mandel_banques', 'Tel, Fax', - "CodeB=$codeBanque AND CodeG=$codeGuichet", false, MYSQL_ASSOC); - if (isset($ret[0])) { - return $ret[0]; - } else { - return array(); + $result = array(); + $sql = "SELECT Tel, Fax FROM insee.Mandel_banques WHERE CodeB=:banque AND CodeG=:guichet LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('banque', $codeBanque); + $stmt->bindValue('guichet', $codeGuichet); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); } + + return $result; } } diff --git a/library/Metier/Partenaires/MBourse.php b/library/Metier/Partenaires/MBourse.php index 18aece21..4e63963a 100644 --- a/library/Metier/Partenaires/MBourse.php +++ b/library/Metier/Partenaires/MBourse.php @@ -1,18 +1,30 @@ siren = $siren; + $this->conn = Zend_Registry::get('doctrine'); + } - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } + /** + * Set SIREN + * @param string $id + */ + public function setCompany($id) + { + $this->siren = $id; } /** @@ -92,14 +104,22 @@ class Metier_Partenaires_MBourse * @param string $siren * @return string */ - public function getCodeIsin($siren=false) + public function getCodeIsin($siren = false) { if (!$siren) { $siren = $this->siren; } - $tabTmp = $this->iDb->select('jo.infos_entrep', 'isin', "siren=$siren AND isin!=''", false, MYSQL_ASSOC); - return trim(@$tabTmp[0]['isin']); + $sql = "SELECT isin FROM jo.infos_entrep WHERE siren=:siren AND isin!='' LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + return trim($result['isin']); + } + + return ''; } /** @@ -109,8 +129,16 @@ class Metier_Partenaires_MBourse */ public function getCodeSiren($isin) { - $tabTmp = $this->iDb->select('jo.infos_entrep', 'siren', "isin='$isin' AND siren!=0", false, MYSQL_ASSOC); - return trim($tabTmp[0]['siren']); + $sql = "SELECT siren FROM jo.infos_entrep WHERE isin=:isin AND siren!=0 LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('isin', $isin); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + return trim($result['siren']); + } + + return ''; } /** @@ -119,56 +147,51 @@ class Metier_Partenaires_MBourse * @param integer $id * @return array */ - public function getInfosReg($siren=false, $id=null) + public function getInfosReg($siren = false, $id = null) { if (!$siren) { $siren = $this->siren; } $isin = $this->getCodeIsin($siren); - $tabRet = array(); - if ($isin!='') { + $result = array(); + if ($isin != '') { $sqlID = ''; if (null !== $id) { - $sqlID=" AND id=$id "; + $sqlID =" AND id=$id"; } + $bodaccSql = "SELECT id, companyName, companyIsin, companySiren, companyWebSite, + pressReleaseDate, pressReleaseTitle, pressReleaseText, pressReleaseHtml, + pressReleaseAttachments, pressReleaseUrl, source, dateInsert + FROM presse.articles + WHERE companyIsin=:isin $sqlID ORDER BY pressReleaseDate DESC"; + $bodaccStmt = $this->conn->prepare($bodaccSql); + $bodaccStmt->bindValue('isin', $isin); + $bodaccStmt->execute(); - $bodacc = $this->iDb->select( - 'presse.articles', - 'id, companyName, companyIsin, companySiren, companyWebSite, pressReleaseDate, pressReleaseTitle, '. - 'pressReleaseText, pressReleaseHtml, pressReleaseAttachments, pressReleaseUrl, source, dateInsert', - "companyIsin='$isin' $sqlID ORDER BY pressReleaseDate DESC", true, MYSQL_ASSOC); - if (count($bodacc)>0) { - foreach ($bodacc as $k=>$ann) { - if ($id) { - $tabRet[$k]=array( - 'id'=>$ann['id'], - 'source'=>$this->getLibSource($ann['source']), - 'DateParution'=>$ann['pressReleaseDate'], - 'raisonSociale'=>$ann['companyName'], - 'titre'=>$ann['pressReleaseTitle'], - 'communique'=>$ann['pressReleaseText'], - 'communiqueHtml'=>$ann['pressReleaseHtml'], - 'pj'=>$ann['pressReleaseAttachments'], - 'url'=>$ann['pressReleaseUrl'], - 'dateInsertionSD'=>$ann['dateInsert'], - ); - } else { - $tabRet[$k]=array( - 'id'=>$ann['id'], - 'source'=>$this->getLibSource($ann['source']), - 'DateParution'=>$ann['pressReleaseDate'], - 'raisonSociale'=>$ann['companyName'], - 'titre'=>$ann['pressReleaseTitle'], - 'pj'=>$ann['pressReleaseAttachments'], - 'url'=>$ann['pressReleaseUrl'], - 'dateInsertionSD'=>$ann['dateInsert'], - ); + if ($bodaccStmt->rowCount() > 0) { + while($ann = $bodaccStmt->fetch(\PDO::FETCH_ASSOC)) { + $format = array( + 'id' => $ann['id'], + 'source' => $this->getLibSource($ann['source']), + 'DateParution' => $ann['pressReleaseDate'], + 'raisonSociale' => $ann['companyName'], + 'titre' => $ann['pressReleaseTitle'], + 'pj' => $ann['pressReleaseAttachments'], + 'url' => $ann['pressReleaseUrl'], + 'dateInsertionSD' => $ann['dateInsert'], + ); + if (null != $id) { + $format['communique'] = $ann['pressReleaseText']; + $format['communiqueHtml'] = $ann['pressReleaseHtml']; } + + $result[] = $format; } } } - return $tabRet; + + return $result; } /** @@ -185,29 +208,37 @@ class Metier_Partenaires_MBourse $isin = $this->getCodeIsin($siren); - $tabRet = array(); + $result = array(); if ($isin != '') { - $tabRes = $this->iDb->select( - 'sdv1.bourse_isin b, sdv1.bourse_cours c', - 'siren, raisonSociale, adresse, effectif, code_sicovam, code_mnemo, code_bloomberg, code_datastream, code_isin, logo, code_ric, '. - 'dateIntroduction, dateDerAG, dateRadiation, autre_isin, eligibleSRD, eligiblePEA, nombreTitres, tel1, tel2, fax1, fax2, web, mail, '. - 'marche, placeCotation, description, secteur, activite, activiteDet, dirigeants, actionnaires, chiffresTrim, '. - 'c.autre, c.`date`, c.`heure`, c.`open` , c.`high` , c.`low` , c.`close` , c.`volume`', - "code_isin='$isin' /*OR siren=$siren)*/ AND b.code_isin=c.isin AND c.autre IN('','e','f','g','m','s','u') ORDER BY c.`date` DESC, c.`heure` DESC LIMIT 0,1", false, MYSQL_ASSOC); - if (count($tabRes) > 0) { - $tabRet = $tabRes[0]; - $tabRes = $this->iDb->select('sdv1.bourse_cours', - 'min(close) AS coursMin, avg(close) AS coursMoy, max(close) AS coursMax', - "isin='$isin' GROUP BY isin", false, MYSQL_ASSOC); - if (count($tabRes) > 0) { - $tabTmp = $tabRes[0]; - $tabRet['coursMin'] = $tabTmp['coursMin']; - $tabRet['coursMoy'] = $tabTmp['coursMoy']; - $tabRet['coursMax'] = $tabTmp['coursMax']; + $sql = "SELECT siren, raisonSociale, adresse, effectif, code_sicovam, code_mnemo, + code_bloomberg, code_datastream, code_isin, logo, code_ric, dateIntroduction, + dateDerAG, dateRadiation, autre_isin, eligibleSRD, eligiblePEA, nombreTitres, + tel1, tel2, fax1, fax2, web, mail, marche, placeCotation, description, secteur, + activite, activiteDet, dirigeants, actionnaires, chiffresTrim, c.autre, + c.`date`, c.`heure`, c.`open` , c.`high` , c.`low` , c.`close` , c.`volume` + FROM sdv1.bourse_isin b, sdv1.bourse_cours c + WHERE code_isin=:isin AND b.code_isin=c.isin AND c.autre IN('','e','f','g','m','s','u') + ORDER BY c.`date` DESC, c.`heure` DESC LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('isin', $isin); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + $courSql = "SELECT min(close) AS coursMin, avg(close) AS coursMoy, + max(close) AS coursMax FROM sdv1.bourse_cours + WHERE isin=:isin GROUP BY isin"; + $courStmt = $this->conn->prepare($courSql); + $courStmt->bindValue('isin', $isin); + $courStmt->execute(); + if ($courStmt->rowCount() > 0) { + $cour = $courStmt->fetch(\PDO::FETCH_ASSOC); + $result['coursMin'] = $cour['coursMin']; + $result['coursMoy'] = $cour['coursMoy']; + $result['coursMax'] = $cour['coursMax']; } } } - return $tabRet; + return $result; } } diff --git a/library/Metier/Partenaires/MMap.php b/library/Metier/Partenaires/MMap.php index 88d357ec..6088d9ab 100644 --- a/library/Metier/Partenaires/MMap.php +++ b/library/Metier/Partenaires/MMap.php @@ -4,8 +4,6 @@ require_once __DIR__ . '/MMapFunctions.php'; class Metier_Partenaires_MMap { - protected $iDb; - private $accesDist = true; private $referer =''; private $body = ''; private $header = ''; @@ -36,14 +34,29 @@ class Metier_Partenaires_MMap private $apiKeyY='klII0gzV34Ho2TCsN3XiXeh4No033AifxMeDXfFXj8TDCXO3WAtOLj9c74VsV45HcII-'; private $apiKeyC='ae5216123e414fcd84b8ca9a0f43a68c'; - public function __construct($accesDist=true, $db = null) + /** + * Flag to get remote data + * @var string + */ + protected $remote = false; + + /** + * PDO Connection with Doctrine + * @var \Doctrine\DBAL\Connection + */ + protected $conn; + + public function __construct() { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } - $this->accesDist=$accesDist; + $this->conn = Zend_Registry::get('doctrine'); + } + + /** + * Active la récupération des données distantes + */ + public function setRemote() + { + $this->remote = true; } /* @@ -334,12 +347,12 @@ class Metier_Partenaires_MMap $this->codeRetourY='INVALID_REQUEST'; } } - + if ($this->latitudeDec==0 && ($this->longitudeDec==0 || $this->precision==0)) { //die('Réponse Yahoo = '.$this->body.PHP_EOL); return false; } - + return true;//array("lat"=>$lat,"lng"=>$lng,"address"=>$address); } else { $this->codeRetourY='INVALID_REQUEST'; @@ -459,13 +472,17 @@ class Metier_Partenaires_MMap $adresse = addslashes(trim(preg_replace('/ +/', ' ', "$adrNum $adrIndRep $adrTypeVoieLong $adrLibVoie"))); $adresseCourt = addslashes(trim(preg_replace('/ +/', ' ', "$adrNum $adrIndRep $adrTypeVoieCourt $adrLibVoie"))); $ville = addslashes($ville); - $ret = $this->iDb->select('jo.zonageXY', 'lat, lon, l93_x, l93_y, alt, precis, adresseValidee, IF(dateUpdate>dateInsert, dateUpdate, dateInsert) AS dateInsert ', - "(address='$adresse' OR address='$adresseCourt') AND adr_cp='$cp' AND adr_ville='$ville' ORDER BY dateInsert DESC LIMIT 1", - false, MYSQL_ASSOC); - //Existe dans la base - if (count($ret)>0) { - $zonage=$ret[0]; + + $sql = "SELECT lat, lon, l93_x, l93_y, alt, precis, adresseValidee, IF(dateUpdate>dateInsert, dateUpdate, dateInsert) AS dateInsert + FROM jo.zonageXY WHERE (address='$adresse' OR address='$adresseCourt') AND adr_cp='$cp' AND adr_ville='$ville' + ORDER BY dateInsert DESC LIMIT 1"; + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + + // Existe dans la base + if ($stmt->rowCount() > 0) { + $zonage = $stmt->fetch(\PDO::FETCH_ASSOC); $this->precision=$zonage['precis']*1; $this->adresseValidee=strtoupper($zonage['adresseValidee']); $this->latitudeDec=$zonage['lat']*1; @@ -474,7 +491,7 @@ class Metier_Partenaires_MMap $this->l93y=$zonage['l93_y']; $this->altitude=$zonage['alt']; if ($this->altitude==null && $this->precision>5) { - if ($this->accesDist) { + if ($this->remote) { $alt=$this->getAltitude($this->latitudeDec, $this->longitudeDec); $this->altitude=$alt['alt']; } @@ -490,7 +507,11 @@ class Metier_Partenaires_MMap 'l93_x'=>$this->l93x, 'l93_y'=>$this->l93y ); - $this->iDb->update('jo.zonageXY', $tabUpdate, "address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'"); + $this->conn->update('jo.zonageXY', $tabUpdate, array( + 'address' => $adresse, + 'adr_cp' => $cp, + 'adr_ville' => $ville, + )); } $this->latitudeDeg = dec2dms($this->latitudeDec); @@ -500,7 +521,7 @@ class Metier_Partenaires_MMap } //Acces Distant - elseif ($this->accesDist) { + elseif ($this->remote) { $this->enCache=false; $retG=$retY=$retC=$retM=false; if (substr($codeRivoli, 0, 3)*1==971) { @@ -556,37 +577,31 @@ class Metier_Partenaires_MMap $this->l93x=$tmp['x_93']; $this->l93y=$tmp['y_93']; - //echo ('$retG='.$retG.PHP_EOL.'$retY='.$retY.PHP_EOL.'$retC='.$retC.PHP_EOL.'$retM='.$retM.PHP_EOL); - if ($retG || $retY || $retM || $retC) { $adresse=stripslashes(strtoupper(trim(preg_replace('/ +/', ' ', "$adrNum $adrIndRep $adrTypeVoieLong $adrLibVoie")))); $ville=stripslashes($ville); - $tabInsert=array( 'address'=>$adresse, - 'adr_cp'=>$cp, - 'adr_ville'=>$ville, - 'adrNum'=>$adrNum, - 'adrIndRep'=>$adrIndRep, - 'adrTypeVoie'=>$adrTypeVoieCourt, - 'adrLibVoie'=>$adrLibVoie, - 'rivoli'=>$codeRivoli, - 'adresseValidee'=>$this->adresseValidee, - 'lat'=>$this->latitudeDec, - 'lon'=>$this->longitudeDec, - 'l93_x'=>$this->l93x, - 'l93_y'=>$this->l93y, - 'alt'=>$this->altitude, - 'precis'=>$this->precision, - 'source'=>$this->geocodeur, - 'dateInsert'=>date('YmdHis'), - ); - /** Insertion de l'adresse que si elle est possible - **/ - //echo ('Avant Insert '.$this->latitudeDec.PHP_EOL.$this->longitudeDec.PHP_EOL); + $tabInsert = array( + 'address' => $adresse, + 'adr_cp' => $cp, + 'adr_ville' => $ville, + 'adrNum' => $adrNum, + 'adrIndRep' => $adrIndRep, + 'adrTypeVoie' => $adrTypeVoieCourt, + 'adrLibVoie' => $adrLibVoie, + 'rivoli' => $codeRivoli, + 'adresseValidee'=> $this->adresseValidee, + 'lat' => $this->latitudeDec, + 'lon' => $this->longitudeDec, + 'l93_x' => $this->l93x, + 'l93_y' => $this->l93y, + 'alt' => $this->altitude, + 'precis' => $this->precision, + 'source' => $this->geocodeur, + 'dateInsert' => date('YmdHis'), + ); + /** Insertion de l'adresse que si elle est possible **/ if ($this->latitudeDec<>0 && $this->longitudeDec<>0 && $this->precision>0) { - // print_r($tabInsert); - //echo ($this->latitudeDec.PHP_EOL.$this->longitudeDec.PHP_EOL); - $this->iDb->insert('jo.zonageXY', $tabInsert); - /*if (mysql_errno()>0) echo mysql_error().die(PHP_EOL);*/ + $this->conn->insert('jo.zonageXY', $tabInsert); } else { $this->precision=$this->latitudeDec=$this->longitudeDec=0; $this->adresseValidee=''; diff --git a/library/Metier/Partenaires/MMarques.php b/library/Metier/Partenaires/MMarques.php index 39f0eac8..e73d9ccc 100644 --- a/library/Metier/Partenaires/MMarques.php +++ b/library/Metier/Partenaires/MMarques.php @@ -3,13 +3,15 @@ class Metier_Partenaires_MMarques { private $iDb; - public function __construct($db = null) + /** + * PDO Connection with Doctrine + * @var \Doctrine\DBAL\Connection + */ + protected $conn; + + public function __construct() { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } + $this->conn = Zend_Registry::get('doctrine'); } @@ -21,25 +23,81 @@ class Metier_Partenaires_MMarques public function getMarques($siren, $idDepot=0) { $marques = array(); - $strSql = "1 "; + $sql = "SELECT nomMarque, rayonMarque, detailDeposant, sirenDeposant, dateDepot, lieuDepot, + numeroMarque, classesMarque, periMarque, detailDeposant, detailMandataire, detailStatut, + dateExpir, idObjetImg, idObjetPdf FROM bopi.marques WHERE"; if ($siren > 0) { - $strSql.= "AND sirenDeposant=$siren "; + if (substr($sql, -5) != "WHERE") { + $sql.= " AND "; + } + $sql.= "sirenDeposant=$siren"; } if ($idDepot > 0) { - $strSql.= "AND numeroMarque=$idDepot "; + if (substr($sql, -5) != "WHERE") { + $sql.= " AND "; + } + $sql.= "numeroMarque=$idDepot"; } - $res = $this->iDb->select('bopi.marques', - 'nomMarque, rayonMarque, detailDeposant, sirenDeposant, dateDepot, lieuDepot, numeroMarque, classesMarque, periMarque, detailDeposant, detailMandataire, detailStatut, dateExpir, idObjetImg, idObjetPdf', - "$strSql ORDER BY dateDepot DESC"); - if (count($res) > 0) { - foreach ($res as $i => $marque) { + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($marque = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($marque['nomMarque'] == ' ') { $nomMarque = '(figurative)'; } else { $nomMarque = $marque['nomMarque']; } - $marques[$i] = array( + if ($idDepot != 0) { + if ($marque['numeroMarque'] == $idDepot) { + //Produits et Services + $psSql = "SELECT remarque FROM bopi.marques_classes WHERE numeroMarque=:id"; + $psStmt = $this->conn->prepare($psSql); + $psStmt->bindValue('id', $idDepot); + $psStmt->execute(); + $txt = array(); + if ($psStmt->rowCount() > 0) { + while ($ps = $psStmt->fetch(\PDO::FETCH_ASSOC)) { + $txt[] = $ps['remarque']; + } + } + $marque['PS'] = $txt; + + //Historique + $hSql = "SELECT histo2 FROM bopi.marques_histo WHERE numeroMarque=:id ORDER BY dat DESC"; + $hStmt = $this->conn->prepare($psSql); + $hStmt->bindValue('id', $idDepot); + $hStmt->execute(); + $txt = array(); + if ($hStmt->rowCount() > 0) { + while ($h = $hStmt->fetch(\PDO::FETCH_ASSOC)) { + $txt[] = $h['histo2']; + } + } + $marque['histo'] = $txt; + + return array( + 'nomMarque' => $nomMarque, + 'rayonMarque' => $marque['rayonMarque'], + 'detailDeposant' => $marque['detailDeposant'], + 'detailMandataire' => $marque['detailMandataire'], + 'detailStatut' => $marque['detailStatut'], + 'sirenDeposant' => $marque['sirenDeposant'], + 'dateDepot' => $marque['dateDepot'], + 'lieuDepot' => $marque['lieuDepot'], + 'classesMarque' => $marque['classesMarque'], + 'periMarque' => $marque['periMarque'], + 'dateExpir' => $marque['dateExpir'], + 'numeroMarque' => $marque['numeroMarque'], + 'imgLink' => $marque['idObjetImg'], + 'pdfLink' => $marque['idObjetPdf'], + 'PS' => $marque['PS'], + 'histo' => $marque['histo'], + ); + } + } + + $marques[] = array( 'nomMarque' => $nomMarque, 'rayonMarque' => $marque['rayonMarque'], 'detailDeposant' => $marque['detailDeposant'], @@ -55,33 +113,8 @@ class Metier_Partenaires_MMarques 'imgLink' => $marque['idObjetImg'], 'pdfLink' => $marque['idObjetPdf'], ); - - if ($idDepot != 0) { - if ($marque['numeroMarque'] == $idDepot) { - //Produits et Services - $resPS = $this->iDb->select('bopi.marques_classes', 'remarque', "numeroMarque=$idDepot"); - if (count($resPS)>0) { - $txt = array(); - foreach ($resPS as $item) { - $txt[] = $item['remarque']; - } - $marques[$i]['PS'] = $txt; - } - - //Historique - $resHisto = $this->iDb->select('bopi.marques_histo', 'histo2', "numeroMarque=$idDepot ORDER BY dat DESC"); - if (count($resHisto) > 0) { - $txt = array(); - foreach ($resHisto as $item) { - $txt[] = $item['histo2']; - } - $marques[$i]['histo'] = $txt; - } - - return array($marques[$i]); - } - } } + return $marques; } diff --git a/library/Metier/Partenaires/MPrivileges.php b/library/Metier/Partenaires/MPrivileges.php index 4b7fdfb2..010b8e79 100644 --- a/library/Metier/Partenaires/MPrivileges.php +++ b/library/Metier/Partenaires/MPrivileges.php @@ -68,13 +68,15 @@ class Metier_Partenaires_MPrivileges protected $iDb; - public function __construct($db = null) + /** + * PDO Connection with Doctrine + * @var \Doctrine\DBAL\Connection + */ + protected $conn; + + public function __construct() { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } + $this->conn = Zend_Registry::get('doctrine'); } /** @@ -90,49 +92,66 @@ class Metier_Partenaires_MPrivileges if ($strTypes != '') { $strTypes=" AND i.insType IN ('$strTypes') "; } - $fields = "i.id, i.dateEven, i.greffe , i.numDebiteur, i.sirenage, i.typeEven, i.dateFraiche, i.codeRev , i.debRaisonSociale , i.debSigle , i.debCiv , i.debNom , i.debPrenom , i.debConjoint , i.debUsage , i.debEnseigne , i.debActivite , i.debFj , i.debFjLib , i.debResidence , i.debNumVoie , i.debTypVoie , i.debLibVoie , i.debAdrComp , i.debCP , i.debVille , i.debPays , i.insType , i.insLib , i.insNum , i.insDate , i.insObjet , i.insMontant , i.insDev , i.insDateEch , i.insDateFin , i.insNanTx , i.insNanTitre , i.insNanOppo , i.insProNat , i.insProHui , i.insProRep , i.insNSCA , i.insNSCParts , i.insNSCSigni , i.creNom , i.creNumVoi, i.creTypVoi, i.creLibVoi, i.creAdrComp1, i.creAdrComp2, i.creCP, i.creVille, i.crePays, i.creAutres, i.radDate, i.radMention, i.radPartiel, i.radPartMt, i.radDev, i.radDiv, i.idFichier, i.dateInsert"; - $where = "i.siren=$siren $strTypes AND ( (i.insType='03' AND DATEDIFF(NOW(),i.insDate)<=900) /** Durée de vie PRIV Sécu **/ OR (i.insType='04' AND DATEDIFF(NOW(),i.insDate)<=1460) /** Durée de vie PRIV Trésor **/ )"; - $where.= " ORDER BY i.dateFraiche DESC, i.insType ASC, i.insDate ASC;"; - $tables = "jo.greffes_privileges i"; $iRncs = new Metier_Partenaires_MRncs(); $tabRet = array(); - $tabPriv = $this->iDb->select($tables, $fields, $where, true, MYSQL_ASSOC); - if (count($tabPriv) > 0) { - foreach ($tabPriv as $i => $priv) { - if ($i >0 && $priv['dateFraiche'] != $dateFraiche) { + + $sql = "SELECT i.id, i.dateEven, i.greffe , i.numDebiteur, i.sirenage, i.typeEven, i.dateFraiche, + i.codeRev , i.debRaisonSociale , i.debSigle , i.debCiv , i.debNom , i.debPrenom , + i.debConjoint , i.debUsage , i.debEnseigne , i.debActivite , i.debFj , i.debFjLib , + i.debResidence , i.debNumVoie , i.debTypVoie , i.debLibVoie , i.debAdrComp , i.debCP , + i.debVille , i.debPays , i.insType , i.insLib , i.insNum , i.insDate , i.insObjet , + i.insMontant , i.insDev , i.insDateEch , i.insDateFin , i.insNanTx , i.insNanTitre , + i.insNanOppo , i.insProNat , i.insProHui , i.insProRep , i.insNSCA , i.insNSCParts , + i.insNSCSigni , i.creNom , i.creNumVoi, i.creTypVoi, i.creLibVoi, i.creAdrComp1, + i.creAdrComp2, i.creCP, i.creVille, i.crePays, i.creAutres, i.radDate, i.radMention, + i.radPartiel, i.radPartMt, i.radDev, i.radDiv, i.idFichier, i.dateInsert + FROM jo.greffes_privileges i + WHERE i.siren=$siren $strTypes AND ( (i.insType='03' AND DATEDIFF(NOW(),i.insDate)<=900) /** Durée de vie PRIV Sécu **/ + OR (i.insType='04' AND DATEDIFF(NOW(),i.insDate)<=1460) /** Durée de vie PRIV Trésor **/ ) + ORDER BY i.dateFraiche DESC, i.insType ASC, i.insDate ASC"; + $stmt = $this->conn->prepare($sql); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $i = 0; + while ($priv = $stmt->fetch(\PDO::FETCH_ASSOC)) { + if ($i > 0 && $priv['datefaiche'] != $dateFraiche) { break; } + $tabRet[] = array( - 'numDebiteur' => $priv['numDebiteur'], + 'numDebiteur' => $priv['numDebiteur'], 'greffe' => $priv['greffe'], - 'greffeLib' => $iRncs->getLibTribunal($priv['greffe']), - 'dateEven' => $priv['dateEven'], - 'dateFraiche' => $priv['dateFraiche'], + 'greffeLib' => $iRncs->getLibTribunal($priv['greffe']), + 'dateEven' => $priv['dateEven'], + 'dateFraiche' => $priv['dateFraiche'], 'dateSD' => $priv['dateInsert'], - 'insType' => $priv['insType'], + 'insType' => $priv['insType'], 'insTypeLib' => $this->tabTypePriv[$priv['insType']], 'insNum' => $priv['insNum'], - 'insDate' => $priv['insDate'], + 'insDate' => $priv['insDate'], 'insDateEch' => $priv['insDateEch'], - 'insObjet' => $priv['insObjet'], + 'insObjet' => $priv['insObjet'], 'insMontant' => $priv['insMontant'], 'insDev' => $priv['insDev'], 'insDateFin' => $priv['insDateFin'], - 'radDate' => $priv['radDate'], + 'radDate' => $priv['radDate'], 'radMention' => $priv['radMention'], 'radPartiel' => $priv['radPartiel'], - 'radPartMt' => $priv['radPartMt'], + 'radPartMt' => $priv['radPartMt'], 'radDev' => $priv['radDev'], 'creNom' => $priv['creNom'], - 'creAdresse1' => trim(preg_replace('/ +/', ' ', $priv['creNumVoi'].' '.$priv['creTypVoi'].' '.$priv['creLibVoi'])), - 'creAdresse2' => $priv['creAdrComp1'], - 'creAdresse3' => $priv['creAdrComp2'], - 'creCP' => $priv['creCP'], - 'creVille' => $priv['creVille'], - 'crePays' => $priv['crePays'], - 'creAutres' => $priv['creAutres'], + 'creAdresse1' => trim(preg_replace('/ +/', ' ', $priv['creNumVoi'].' '. + $priv['creTypVoi'].' '.$priv['creLibVoi'])), + 'creAdresse2' => $priv['creAdrComp1'], + 'creAdresse3' => $priv['creAdrComp2'], + 'creCP' => $priv['creCP'], + 'creVille' => $priv['creVille'], + 'crePays' => $priv['crePays'], + 'creAutres' => $priv['creAutres'], ); + + $i++; $dateFraiche = $priv['dateFraiche']; } } diff --git a/library/Metier/Partenaires/MRncs.php b/library/Metier/Partenaires/MRncs.php index dff85032..7e816309 100644 --- a/library/Metier/Partenaires/MRncs.php +++ b/library/Metier/Partenaires/MRncs.php @@ -323,7 +323,8 @@ class Metier_Partenaires_MRncs if ($fj > 0 && $fj < 10000) { $stmt = $this->conn->executeQuery("SELECT libelle AS LibFJ FROM jo.tabFJur WHERE code=$fj"); if ($stmt->rowCount() > 0) { - $label = $stmt->fetchColumn('LibFJ'); + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + $label = $result['LibFJ']; } } @@ -341,7 +342,8 @@ class Metier_Partenaires_MRncs UNION SELECT libNaf5 AS LibNaf FROM jo.tabNaf5 WHERE codNaf5='$codeNaf'"); $label = "Inconnu"; if ($stmt->rowCount() > 0) { - $label = $stmt->fetchColumn('LibNaf'); + $result = $stmt->fetch(\PDO::FETCH_ASSOC); + $label = $result['LibNaf']; } return $label; diff --git a/library/Metier/Partenaires/MTel.php b/library/Metier/Partenaires/MTel.php index d36cff6f..32a5ed70 100644 --- a/library/Metier/Partenaires/MTel.php +++ b/library/Metier/Partenaires/MTel.php @@ -22,7 +22,7 @@ class Metier_Partenaires_MTel */ public function getTel($siret, $nic=0, $last=false, $actif=null) { - $tabRet=array(); + $tabRet = array(); if (strlen($siret) > 9) { $nic = substr($siret, -5)*1; @@ -75,7 +75,8 @@ class Metier_Partenaires_MTel $an8Stmt = $this->conn->executeQuery($sql); $infoTel = ''; if ($an8Stmt->rowCount() > 0) { - $label = $an8Stmt->fetchColumn('libAn8'); + $result = $an8Stmt->fetch(\PDO::FETCH_ASSOC); + $label = $result['libAn8']; $infoTel = ucfirst(strtolower($label)); } } else { diff --git a/library/Metier/Partenaires/MTva.php b/library/Metier/Partenaires/MTva.php index 178996d2..509adcfb 100644 --- a/library/Metier/Partenaires/MTva.php +++ b/library/Metier/Partenaires/MTva.php @@ -79,11 +79,11 @@ class Metier_Partenaires_MTva $stmt->execute(); if ($stmt->rowCount() > 0) { $exist = true; - $tab = $stmt->fetch(\PDO::FETCH_ASSOC); - $cle = $tab['cle']; + $result = $stmt->fetch(\PDO::FETCH_OBJ); + $cle = $result->cle; $dateRef = new DateTime(); $dateRef->sub(new DateInterval('P6M')); - $dateMaj = DateTime::createFromFormat('Ymd', $tab['DateMAJ']); + $dateMaj = DateTime::createFromFormat('Ymd', $result->DateMAJ); $this->vatNumber = "FR".$this->cle.$this->siren; if ($cle !== null | $cle != 0) { $this->vatDefined = true; @@ -158,18 +158,18 @@ class Metier_Partenaires_MTva if ($response->getStatusCode() == 200) { $body = $response->getBody(); 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), - 'duree' => $time), array('siren' => $this->siren)); - } else { - $this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren, - 'cle' => intval($this->cle), 'duree' => $time)); - } - $this->vatNumber = "FR".$this->cle.$this->siren; - $this->vatDefined = true; - return true; + || preg_match('/Oui, numéro de TVA valide/i', $body)) { + if ($exist) { + $this->conn->update('sdv1.siren_tva', array('cle' => intval($this->cle), + 'duree' => $time), array('siren' => $this->siren)); + } else { + $this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren, + 'cle' => intval($this->cle), 'duree' => $time)); } + $this->vatNumber = "FR".$this->cle.$this->siren; + $this->vatDefined = true; + return true; + } } } catch (RequestException $e) { Metier_Util_Log::write('I', "TVA ".$e->getMessage(), __LINE__, __FILE__, __FUNCTION__, __CLASS__); diff --git a/library/Metier/Scores/ICotation.php b/library/Metier/Scores/ICotation.php index 7a4bb5da..272377db 100644 --- a/library/Metier/Scores/ICotation.php +++ b/library/Metier/Scores/ICotation.php @@ -2190,16 +2190,9 @@ class Metier_Scores_ICotation public $societeEnBourse = false; public $valeurCCF = 0; - protected $iDb; - public function __construct($tabBilan, $retraitementAutomatique = true, $db = null) + public function __construct($tabBilan, $retraitementAutomatique = true) { - if ($db === null) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } - $this->reTrtAuto = $retraitementAutomatique; $this->tabBilan = $tabBilan; @@ -3151,7 +3144,7 @@ class Metier_Scores_ICotation public function scoreAltman($enBourse=true) { - $iBourse = new Metier_Partenaires_MBourse(@$this->tabBilan['SIREN'], $this->iDb); + $iBourse = new Metier_Partenaires_MBourse(); $bourse = $iBourse->getInfosBourse(@$this->tabBilan['SIREN']); if (count($bourse)>0) { $this->societeEnBourse=true; @@ -3690,15 +3683,15 @@ class Metier_Scores_ICotation for ($i=1; $i<$nbSecteurs; $i++) { for ($j=0; isset($this->tabActivite[$i][$j]); $j++) { if ($this->tabActivite[$i][$j]==$naf) { - // echo 'NAF '.$naf.' TROUV� !
'; + // echo 'NAF '.$naf.' TROUVé !
'; return $i; } } } - // echo 'NAF '.$naf.' non trouv� !
'; + // echo 'NAF '.$naf.' non trouvé !
'; $naf=substr($naf, 0, strlen($naf)-1); } - return 17; // Secteur d'activit� par d�faut si non trouv� + return 17; // Secteur d'activité par défaut si non trouvé } public function getBorne($note, $borne, $secteur) @@ -3726,7 +3719,7 @@ class Metier_Scores_ICotation } } } - return 3; // On retourne la plus basse note par d�faut + return 3; // On retourne la plus basse note par défaut } diff --git a/library/Metier/Scores/MRatios.php b/library/Metier/Scores/MRatios.php index 04b7f1e4..2d8da31b 100644 --- a/library/Metier/Scores/MRatios.php +++ b/library/Metier/Scores/MRatios.php @@ -1,8 +1,7 @@ 'Rs[841]', ); - public function __construct($db = null) + public function __construct() { - if ( $db === null ) { - $this->iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } } /** diff --git a/library/Metier/Scores/MScores.php b/library/Metier/Scores/MScores.php index 28eb010d..f43cd23f 100644 --- a/library/Metier/Scores/MScores.php +++ b/library/Metier/Scores/MScores.php @@ -2130,8 +2130,7 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail $tabIdentite['DateCreaEn'], $tabIdentite['DateCreaEt'], '', - $RECME, - $iDb + $RECME ); $noteStructure=$isolv->getSolvabilite(); $timer['solv']=microtime(true); @@ -2298,7 +2297,7 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail break; } - $icotation = new Metier_Scores_ICotation($item, true, $iDb); + $icotation = new Metier_Scores_ICotation($item, true); $secteur=$icotation->getSecteurActivite($isolv->getNaf4($naf)); $libSecteur=$icotation->tabLibActivite[$secteur]; $chiffeAffaire=$icotation->calculChiffreAffaires($isolv->getNaf4($naf)); @@ -2835,7 +2834,7 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail // Présence de Privilèges $PRIVILEGESECU=$PRIVILEGESECU_MT=$PRIVILEGETRES=$PRIVILEGETRES_MT=0; - $iPriv = new Metier_Partenaires_MPrivileges($iDb); + $iPriv = new Metier_Partenaires_MPrivileges(); $tabPriv = $iPriv->getPrivilegesCumul($siren); $noteSolvMax=100; if (isset($tabPriv['03']['nb'])) { @@ -3662,7 +3661,7 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail $MARQUENB_EUR=0; // Nombre de marques déposées en EUROPE $MARQUENB_FR=0; // Nombre de marques déposées en FRANCE $tabMarques['WW']=$tabMarques['EU']=$tabMarques['FR']=array(); - $iMarque = new Metier_Partenaires_MMarques($iDb); + $iMarque = new Metier_Partenaires_MMarques(); $ret = $iMarque->getMarques($siren); if ($ret!==false && count($ret)>0) { foreach ($ret as $i=>$marque) { diff --git a/library/Metier/Scores/MSolvabilite.php b/library/Metier/Scores/MSolvabilite.php index a858dc20..f7ad275d 100644 --- a/library/Metier/Scores/MSolvabilite.php +++ b/library/Metier/Scores/MSolvabilite.php @@ -1,7 +1,6 @@ iDb = new Metier_Util_Db(); - } else { - $this->iDb = $db; - } - $this->naf=$naf; $this->trEff=$trancheEff; if ($this->trEff=='NN' || $this->trEff=='00' || ($this->trEff*1)==0) { @@ -1133,7 +1126,7 @@ class Metier_Scores_MSolvabilite $nbPoints = 5; } } elseif (strlen($this->naf) == 5) { - $iCotation = new Metier_Scores_ICotation(array(), true, $this->iDb); + $iCotation = new Metier_Scores_ICotation(array(), true); if (isset($iCotation->tabNaf21[$this->naf])) { $naf4 = $iCotation->tabNaf21[$this->naf]; if (isset($this->tabPtNaf[$naf4])) { @@ -1163,7 +1156,7 @@ class Metier_Scores_MSolvabilite } if (strlen($naf5)==5) { - $iCotation = new Metier_Scores_ICotation(array(), true, $this->iDb); + $iCotation = new Metier_Scores_ICotation(array(), true); return $iCotation->tabNaf21[$naf5]; } return $naf5; diff --git a/library/Metier/Scoring/Base.php b/library/Metier/Scoring/Base.php index 1423367c..abf295a0 100644 --- a/library/Metier/Scoring/Base.php +++ b/library/Metier/Scoring/Base.php @@ -2073,9 +2073,7 @@ class Metier_Scoring_Base extends Metier_Scoring_Vars $tabIdentite['DateCreaEn'], $tabIdentite['DateCreaEt'], '', - $this->RECME, - $this->db - ); + $this->RECME); $noteStructure = $isolv->getSolvabilite(); $timer['solv'] = microtime(true); @@ -2241,7 +2239,7 @@ class Metier_Scoring_Base extends Metier_Scoring_Vars break; } - $icotation = new Metier_Scores_ICotation($item, true, $this->db); + $icotation = new Metier_Scores_ICotation($item, true); $secteur=$icotation->getSecteurActivite($isolv->getNaf4($naf)); $libSecteur=$icotation->tabLibActivite[$secteur]; $chiffeAffaire=$icotation->calculChiffreAffaires($isolv->getNaf4($naf)); @@ -2779,7 +2777,7 @@ class Metier_Scoring_Base extends Metier_Scoring_Vars // Présence de Privilèges $this->PRIVILEGESECU=$this->PRIVILEGESECU_MT=$this->PRIVILEGETRES=$this->PRIVILEGETRES_MT=0; - $iPriv = new Metier_Partenaires_MPrivileges($this->db); + $iPriv = new Metier_Partenaires_MPrivileges(); $tabPriv = $iPriv->getPrivilegesCumul($siren); $noteSolvMax=100; if (isset($tabPriv['03']['nb'])) { @@ -3605,7 +3603,7 @@ class Metier_Scoring_Base extends Metier_Scoring_Vars $this->MARQUENB_EUR=0; // Nombre de marques déposées en EUROPE $this->MARQUENB_FR=0; // Nombre de marques déposées en FRANCE $tabMarques['WW']=$tabMarques['EU']=$tabMarques['FR']=array(); - $iMarque = new Metier_Partenaires_MMarques($this->db); + $iMarque = new Metier_Partenaires_MMarques(); $ret = $iMarque->getMarques($siren); if ($ret!==false && count($ret)>0) { foreach ($ret as $i=>$marque) { diff --git a/scripts/jobs/enrichissement.php b/scripts/jobs/enrichissement.php index 5a1a6df1..f84b04a2 100644 --- a/scripts/jobs/enrichissement.php +++ b/scripts/jobs/enrichissement.php @@ -1481,7 +1481,7 @@ function GPSData($siren, $nic, $values = false) if (count($result)>0) { $MInsee = new Metier_Insee_MInsee($iDb); $etab = $result[0]; - $mMap=new Metier_Partenaires_MMap(false, $iDb); + $mMap=new Metier_Partenaires_MMap(); $mMap->geoCodeAdresse( $etab['adr_num'] ,'', @@ -1561,7 +1561,7 @@ function TelOrderEntete() function TelOrderData($siren, $nic, $values) { global $iDb; - $c = new Metier_Partenaires_MTel($iDb); + $c = new Metier_Partenaires_MTel(); $result = $c->getTel($siren, $nic, true, 1); $tabData = array(); if ( count($result)>0 ) { @@ -1688,7 +1688,7 @@ function ZonePrioritaireData($siren, $nic, $value) { "i.SIREN=e.siren AND i.NIC=e.nic AND e.siren=$siren AND e.nic=$nic", false, MYSQL_ASSOC); if (count($result) > 0) { $r = $result[0]; - $iAmabis = new Metier_Partenaires_MAmabis($iDb); + $iAmabis = new Metier_Partenaires_MAmabis(); $tabData = $iAmabis->getZonage($r['adr_num'], $r['adr_btq'], $r['adr_typeVoie'], $r['adr_libVoie'], $r['adr_cp'], $r['adr_ville'], trim($r['ADR_DEP'].$r['ADR_COM'].$r['CODEVOIE']), false, 'TEST', false);