diff --git a/library/WsScore/Entreprise/v0.8/Entreprise.php b/library/WsScore/Entreprise/v0.8/Entreprise.php index 9dd92173..b1a96615 100644 --- a/library/WsScore/Entreprise/v0.8/Entreprise.php +++ b/library/WsScore/Entreprise/v0.8/Entreprise.php @@ -4515,61 +4515,58 @@ class Entreprise extends WsScore //Initialisation $iDb = new WDB('sdv1'); $tabRet = array(); - debugLog('I',"Liste des banques demandée pour siren $siren", - __LINE__,__FILE__, __FUNCTION__, __CLASS__); + debugLog('I',"Liste des banques demandée pour siren $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__); if (intval($siren)<=1000) { $this->sendError('1010'); } - $res=$iDb->select('banques', 'codeBanque, codeGuichet, libBanqueGuichet, precis, dateSource*1 AS dateSource', "siren=$siren", false, MYSQL_ASSOC); - $tmp=$iDb->select('fedRib', "codeBanque, codeGuichet, CONCAT(libBanque,' ',libGuichet) AS libBanqueGuichet, 0 AS precis, IF (dateInfo='0000-00-00', dateDispo*1, dateInfo*1) AS dateSource", "siren=$siren", false, MYSQL_ASSOC); + $res=$iDb->select('banques', 'codeBanque, codeGuichet, libBanqueGuichet, precis, dateSource*1 AS dateSource', "siren=$siren", true, MYSQL_ASSOC); + $tmp=$iDb->select('fedRib', "codeBanque, codeGuichet, CONCAT(libBanque,' ',libGuichet) AS libBanqueGuichet, 0 AS precis, IF (dateInfo='0000-00-00', dateDispo*1, dateInfo*1) AS dateSource", "siren=$siren", true, MYSQL_ASSOC); $res=array_merge($res, $tmp); - foreach ($res as $tabBanque){ - $dateSource=$tabBanque['dateSource']; - $codBanque=$tabBanque['codeBanque']; - $codGuichet=$tabBanque['codeGuichet']; - $libBanque=trim($tabBanque['libBanqueGuichet']); - $found=false; + foreach ($res as $tabBanque) + { + $dateSource = $tabBanque['dateSource']; + $codBanque = $tabBanque['codeBanque']; + $codGuichet = $tabBanque['codeGuichet']; + $libBanque = trim($tabBanque['libBanqueGuichet']); + $found = false; $adrBanque1=$adrBanque2=$adrBanqueCP=$adrBanqueVille=''; - if ($codBanque>0 && $codGuichet>0 && - $dateSource>(date('Y')-4)*10000+101 && - $dateSourceselect('insee.BDF_Etabs b, insee.BDF_Guichets g', - 'g.bdfFibCodeEtab AS banque, g.bdfFibCodeGuichet AS guichet, b.bdfFibDenom40 AS nomBanque, b.bdfFibDenom10 AS sigleBanque, g.bdfFibDenom20 AS nomGuichet, g.bdfFibAdresse1 AS adresse1, g.bdfFibAdresse2 AS adresse2, g.bdfFibAdresse3 AS adresse3, g.CP, g.Ville', "g.bdfFibCodeEtab=$codBanque AND g.bdfFibCodeGuichet=$codGuichet AND b.bdfFibCodeEtab=g.bdfFibCodeEtab", - false, MYSQL_ASSOC); - if (isset($tmp[0])){ - $libBanque=trim($tmp[0]['nomBanque'].' '.$tmp[0]['nomGuichet']); - $adrBanque1=$tmp[0]['adresse1']; - $adrBanque2=trim($tmp[0]['adresse2'].' '.$tmp[0]['adresse3']); - $adrBanqueCP=$tmp[0]['CP']; - $adrBanqueVille=$tmp[0]['Ville']; - $found=true; - }; - } - if (!$found && $codBanque>0 && - $dateSource>(date('Y')-4)*10000+101 && - $dateSourceselect('insee.BDF_Etabs', "bdfFibCodeEtab AS banque, '' AS guichet, bdfFibDenom40 AS nomBanque, '' AS nomGuichet, '' AS adresse1, '' AS adresse2, '' AS adresse3, '' AS CP, '' AS Ville", "bdfFibCodeEtab=$codBanque", false, MYSQL_ASSOC); - if (isset($tmp[0])){ - $libBanque=trim($tmp[0]['nomBanque'].' '.$tmp[0]['nomGuichet']); - $adrBanque1=$tmp[0]['adresse1']; - $adrBanque2=trim($tmp[0]['adresse2'].' '.$tmp[0]['adresse3']); - $adrBanqueCP=$tmp[0]['CP']; - $adrBanqueVille=$tmp[0]['Ville']; - } else continue; - } else continue; + if ( $codBanque>0 && $codGuichet>0 ) { + $tmp = $iDb->select('insee.BDF_Etabs b, insee.BDF_Guichets g', + 'g.bdfFibCodeEtab AS banque, g.bdfFibCodeGuichet AS guichet, b.bdfFibDenom40 AS nomBanque, b.bdfFibDenom10 AS sigleBanque, g.bdfFibDenom20 AS nomGuichet, g.bdfFibAdresse1 AS adresse1, g.bdfFibAdresse2 AS adresse2, g.bdfFibAdresse3 AS adresse3, g.CP, g.Ville', "g.bdfFibCodeEtab=$codBanque AND g.bdfFibCodeGuichet=$codGuichet AND b.bdfFibCodeEtab=g.bdfFibCodeEtab", + true, MYSQL_ASSOC); + if (count($tmp)>0) { + $found = true; + + $banque = new Banque(); + $banque->codeBanque = $codBanque; + $banque->codeGuichet = $codGuichet; + $banque->libBanque = trim($tmp[0]['nomBanque'].' '.$tmp[0]['nomGuichet']); + $banque->adresse1 = $tmp[0]['adresse1']; + $banque->adresse2 = trim($tmp[0]['adresse2'].' '.$tmp[0]['adresse3']); + $banque->cp = $tmp[0]['CP']; + $banque->ville = $tmp[0]['Ville']; + $tabRet[] = $banque; + } + } + + if ($found===false && $codBanque>0 ) { + $tmp = $iDb->select('insee.BDF_Etabs', "bdfFibCodeEtab AS banque, '' AS guichet, bdfFibDenom40 AS nomBanque, '' AS nomGuichet, '' AS adresse1, '' AS adresse2, '' AS adresse3, '' AS CP, '' AS Ville", "bdfFibCodeEtab=$codBanque", true, MYSQL_ASSOC); + if (count($tmp)>0) { + $banque = new Banque(); + $banque->codeBanque = $codBanque; + $banque->codeGuichet = $codGuichet; + $banque->libBanque = trim($tmp[0]['nomBanque'].' '.$tmp[0]['nomGuichet']); + $banque->adresse1 = $tmp[0]['adresse1']; + $banque->adresse2 = trim($tmp[0]['adresse2'].' '.$tmp[0]['adresse3']); + $banque->cp = $tmp[0]['CP']; + $banque->ville = $tmp[0]['Ville']; + $tabRet[] = $banque; + } + } - $banque = new Banque(); - $banque->codeBanque = $codBanque; - $banque->codeGuichet = $codGuichet; - $banque->libBanque = $libBanque; - $banque->adresse1 = $adrBanque1; - $banque->adresse2 = $adrBanque2; - $banque->cp = $adrBanqueCP; - $banque->ville = $adrBanqueVille; - $tabRet[] = $banque; } debugLog('I',"Liste des banques pour siren $siren : ".count($tabRet).' banques',__LINE__,__FILE__, __FUNCTION__, __CLASS__);