2012-10-16 10:08:03 +02:00
< ?
include_once ( FWK_PATH . 'common/curl.php' );
class MBourse {
var $siren = false ;
public function __construct ( $siren = 0 ) {
$this -> siren = $siren ;
}
public function getLibSource ( $source ) {
switch ( $source ) {
case 'B' : return 'Business Wire' ; break ;
case 'H' : return 'Hugin' ; break ;
case 'A' : return 'ActusNews' ; break ;
case 'D' : return 'DiRelease' ; break ;
case 'E' : return 'Les Echos' ; break ;
default : return 'N/C' ; break ;
}
}
/** V<EFBFBD> rifie la validit<EFBFBD> de la structure d ' un code ISIN
**
** @ param string $isin
** @ return bool
**/
function isIsin ( $isin ) {
2015-07-20 10:17:28 +02:00
if ( strlen ( trim ( $isin )) == 12 ) {
2012-10-16 10:08:03 +02:00
$cle = substr ( $isin , - 1 );
$isinLeft = substr ( $isin , 0 , strlen ( $isin ) - 1 );
$letter2number = array ( 'A' => 10 , 'B' => 11 , 'C' => 12 , 'D' => 13 , 'E' => 14 , 'F' => 15 , 'G' => 16 , 'H' => 17 , 'I' => 18 , 'J' => 19 , 'K' => 20 , 'L' => 21 , 'M' => 22 , 'N' => 23 , 'O' => 24 , 'P' => 25 , 'Q' => 26 , 'R' => 27 , 'S' => 28 , 'T' => 29 , 'U' => 30 , 'V' => 31 , 'W' => 32 , 'X' => 33 , 'Y' => 34 , 'Z' => 35 );
$isinConvertion = strtr ( $isinLeft , $letter2number );
$sum = '' ;
$sumFinal = 0 ;
for ( $i = 0 ; $i < strlen ( $isinConvertion ); ++ $i ) $sum .= (( $i % 2 ) ? 1 : 2 ) * $isinConvertion [ $i ];
for ( $i = 0 ; $i < strlen ( $sum ); ++ $i ) $sumFinal += $sum [ $i ];
if ( $sumFinal % 10 ){
$cleVerif = (( int )( $sumFinal / 10 ) + 1 ) * 10 - $sumFinal ;
} else {
$cleVerif = 0 ;
}
if ( $cle == $cleVerif ) {
return true ;
} else
return false ;
} else return false ;
}
/** Obtenir le code ISIN <EFBFBD> partir d ' un siren
**
** @ param integer $siren
** @ return string
**/
function getCodeIsin ( $siren = false ) {
$iDb = new WDB ();
if ( ! $siren )
$siren = $this -> siren ;
$tabTmp = $iDb -> select ( 'infos_entrep' , 'isin' , " siren= $siren AND isin<>'' " , false , MYSQL_ASSOC );
return trim ( @ $tabTmp [ 0 ][ 'isin' ]);
}
/** Obtenir le SIREN <EFBFBD> partir d ' un code ISIN
**
** @ param string $isin Code ISIN
** @ return integer
**/
function getCodeSiren ( $isin ) {
$iDb = new WDB ();
$tabTmp = $iDb -> select ( 'infos_entrep' , 'siren' , " isin=' $isin ' AND siren<>0 " , false , MYSQL_ASSOC );
return trim ( $tabTmp [ 0 ][ 'siren' ]);
}
/** A partir d ' un siren , r<EFBFBD> cup<EFBFBD> re les informations r<EFBFBD> glement<EFBFBD> s
**
** @ param integer $siren
** @ param integer $id
** @ return unknown
**/
function getInfosReg ( $siren = false , $id = false ) {
if ( ! $siren )
$siren = $this -> siren ;
$isin = $this -> getCodeIsin ( $siren );
unset ( $iDb );
$tabRet = array ();
if ( $isin <> '' ) {
$iDb = new WDB ( 'presse' );
if ( $id ) $sqlID = " AND id= $id " ;
else $sqlID = '' ;
$bodacc = $iDb -> select ( 'articles' ,
'id, companyName, companyIsin, companySiren, companyWebSite, pressReleaseDate, pressReleaseTitle, ' .
'pressReleaseText, pressReleaseHtml, pressReleaseAttachments, pressReleaseUrl, source, dateInsert' ,
" companyIsin=' $isin ' $sqlID ORDER BY pressReleaseDate DESC " , false , 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' ],
);
}
}
}
return $tabRet ;
}
/** A partir d ' un siren , r<EFBFBD> cup<EFBFBD> re les informations boursi<EFBFBD> res
**
** @ param integer $siren
** @ return unknown
**/
function getInfosBourse ( $siren = false ) {
global $timer ;
$iDb = new WDB ( 'sdv1' );
if ( ! $siren )
$siren = $this -> siren ;
$isin = $this -> getCodeIsin ( $siren );
$timer [ 'infosBoursieres-getCodeIsin' ] = microtime ( true );
$tabRet = array ();
if ( $isin <> '' ) {
2015-07-20 10:17:28 +02:00
//$datePre=date('Y-m').'-01';
2012-10-16 10:08:03 +02:00
$tabRes = $iDb -> select ( 'bourse_isin b, 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`' ,
2015-07-20 10:17:28 +02:00
" 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 );
2012-10-16 10:08:03 +02:00
$tabRet = $tabRes [ 0 ];
$timer [ 'infosBoursieres-infosIsin' ] = microtime ( true );
$tabRes = $iDb -> select ( 'bourse_cours' ,
'min(close) AS coursMin, avg(close) AS coursMoy, max(close) AS coursMax' ,
" isin=' $isin ' GROUP BY isin " , false , MYSQL_ASSOC );
$tabTmp = $tabRes [ 0 ];
$tabRet [ 'coursMin' ] = $tabTmp [ 'coursMin' ];
$tabRet [ 'coursMoy' ] = $tabTmp [ 'coursMoy' ];
$tabRet [ 'coursMax' ] = $tabTmp [ 'coursMax' ];
$timer [ 'infosBoursieres-derniersCours' ] = microtime ( true );
/*
$tabRes = $iDb -> select ( 'bourse_cours' ,
'`date`, close' ,
" isin=' $isin ' AND autre IN('','e','f','g','m','s','u') AND heure=9999 AND ( " .
" `date`=DATE_SUB(CURDATE(), INTERVAL 6 DAY) OR " .
" `date`=DATE_SUB(CURDATE(), INTERVAL 7 DAY) OR " .
" `date`=DATE_SUB(CURDATE(), INTERVAL 8 DAY) OR " .
" `date`=' " . date ( 'Y' ) . " -01-02' OR " .
" `date`=' " . date ( 'Y' ) . " -01-03' OR " .
" `date`=' " . date ( 'Y' ) . " -01-04' OR " .
" `date`=DATE_SUB(CURDATE(), INTERVAL 365 DAY) OR " .
" `date`=DATE_SUB(CURDATE(), INTERVAL 366 DAY) OR " .
" `date`=DATE_SUB(CURDATE(), INTERVAL 367 DAY) OR " .
" `date`=MIN(`date`) ) GROUP BY `date` ORDER BY `date` DESC " , false , MYSQL_ASSOC );
$tabTmp = $tabRes [ 0 ];
print_r ( $tabTmp );
*/
/* Variations en cl<EFBFBD> ture du 07 / 03 / 2008
Variation 5 jours - 2.03 %
Variation au 1 janvier + 9.36 %
Variation 1 an + 13.84 %
Variation 10 ans NC
Volumes
Volume s<EFBFBD> ance 2 253
Volume moy . 20 s<EFBFBD> ances 16 326
Ratio volumes 13.80 %
Nombre de titres 113 03 8 156
Capital <EFBFBD> chang<EFBFBD> s<EFBFBD> ance 0.00 %
Extr<EFBFBD> mes
Plus haut 10 ans ( 14 / 02 / 2008 ) 78.5
Plus bas 10 ans ( 18 / 04 / 2005 ) 41.12 */
/* $tabRet [] = array ( 'siren' => $tabBourse ,
'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'
); */
}
return $tabRet ;
}
}
?>