extranet/includes/scoresws/scoresws.php

538 lines
14 KiB
PHP

<?php
require_once 'cache/cache.php';
require_once realpath(dirname(__FILE__)).'/functions.php';
function scoresws_identite($siret, $siren, $idEntreprise)
{
global $client, $firephp;
if (($siret*1)==0 || ($siren*1)<100){ $fileName = 'identite-'.$idEntreprise;
}else{ $fileName = 'identite-'.$siret; }
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) )
{
$return = cache_get('etab');
}else{
$return = null;
try {
$O = $client->getIdentite($siret, $idEntreprise);
$return = $O['result'];
cache_delete();
cache_add('etab', $return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_identitelight($siret, $siren, $idEntreprise)
{
global $client, $firephp;
if (($siret*1)==0 || ($siren*1)<100)
{
$fileName = 'identitelight-'.$idEntreprise;
}
else
{
$fileName = 'identitelight-'.$siret;
}
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) )
{
$return = cache_get('etab');
}
else
{
$return = null;
try {
$O = $client->getIdentite($siret, $idEntreprise, false);
$return = $O['result'];
cache_delete();
cache_add('etab', $return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_identite_ags($siret, $siren, $idEntreprise)
{
global $client, $firephp;
if (($siret*1)==0 || ($siren*1)<100){ $fileName = 'identite-'.$idEntreprise;
}else{ $fileName = 'identiteags-'.$siret; }
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) )
{
$return = cache_get('etab');
}else{
$return = null;
try {
$O = $client->getIdentiteAGS($siret, $idEntreprise);
$return = $O['result'];
cache_delete();
cache_add('etab', $return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
$firephp->log($return, 'return');
return $return;
}
function scoresws_annonces($siret, $siren, $idEntreprise, $vue, $idan)
{
global $client, $firephp;
//Générer un nom de fichier pour le cache et l'export des fichiers
if (($siret*1)==0 || ($siren*1)<100){ $fileName = 'annonces-'.$idEntreprise;
}else{ $fileName = 'annonces-'.$siren; }
if($vue!=''){$fileName.= '-'.$idan;}
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) ){
$annonces = cache_get('annonces');
$return = $annonces;
}else{
if ($vue=='bodacc' || $_REQUEST['source']==1) $filtre=1;
elseif ($vue=='balo' || $_REQUEST['source']==2) $filtre=2;
elseif ($vue=='asso' || $_REQUEST['source']==3) $filtre=3;
else $filtre=0;
if ($_SESSION['tabInfo']['entrep']['fj']>9000 &&
$_SESSION['tabInfo']['entrep']['fj']<9999 &&
$siren==0){
$filtre=3;
}
FB::info('Annonces');
FB::log($siren, 'siren');
FB::log($filtre, 'filtre');
FB::log($idan, 'idan');
try {
$O = $client->getAnnonces($siren, $filtre, $idan);
$annonces = $O['result'];
cache_delete();
cache_add('annonces', $annonces);
$return = $annonces;
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_ratios($siret, $siren, $idEntreprise)
{
global $client, $page;
$fileName = 'ratios-';
if (($siret*1) == 0 || ($siren*1) < 100) {
$fileName .= $idEntreprise;
} else {
$fileName .= $siren;
}
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) )
{
$bilansInfos = cache_get('bilansInfos');
$ratiosEntrep = cache_get('ratiosEntrep');
$ratiosEntrepEvol = cache_get('ratiosEntrepEvol');
$ratiosInfos = cache_get('ratiosInfos');
$ratiosSecteur = cache_get('ratiosSecteur');
$nbEntNaf = cache_get('nbEntNaf');
$dataActif = cache_get('dataActif');
$dataPassif = cache_get('dataPassif');
$dataSIG = cache_get('dataSIG');
$return = array(
'bilansInfos'=>$bilansInfos,
'ratiosEntrep'=>$ratiosEntrep,
'ratiosEntrepEvol'=>$ratiosEntrepEvol,
'ratiosInfos'=>$ratiosInfos,
'ratiosSecteur'=>$ratiosSecteur,
'nbEntNaf' => $nbEntNaf,
'dataActif'=>$dataActif,
'dataPassif'=>$dataPassif,
'dataSIG'=>$dataSIG
);
}else{
try {
$O = $client->getRatios($siren, $page);
$bilansInfos = $O['result']['BilansInfos'];
$ratiosInfos = $O['result']['RatiosInfos'];
$ratiosEntrep = $O['result']['RatiosEntrep'];
$ratiosEntrepEvol = $O['result']['RatiosEntrepEvol'];
$ratiosSecteur = $O['result']['RatiosSecteur'];
$nbEntNaf = $O['result']['NbEntNaf'];
if(count($bilansInfos)>0)
{
$format = formatRatios(
$bilansInfos,
$ratiosEntrep,
$ratiosEntrepEvol,
$ratiosInfos,
$ratiosSecteur
);
while ( list($key, $val) = each( $format ) )
{
${$key} = $val;
}
}
cache_delete();
cache_add('bilansInfos', $bilansInfos);
cache_add('ratiosEntrep', $ratiosEntrep);
cache_add('ratiosEntrepEvol', $ratiosEntrepEvol);
cache_add('ratiosInfos', $ratiosInfos);
cache_add('ratiosSecteur', $ratiosSecteur);
cache_add('nbEntNaf', $nbEntNaf);
cache_add('dataActif', $dataActif);
cache_add('dataPassif', $dataPassif);
cache_add('dataSIG', $dataSIG);
$return = array(
'bilansInfos'=>$bilansInfos,
'ratiosEntrep'=>$ratiosEntrep,
'ratiosEntrepEvol'=>$ratiosEntrepEvol,
'ratiosInfos'=>$ratiosInfos,
'ratiosSecteur'=>$ratiosSecteur,
'nbEntNaf' => $nbEntNaf,
'dataActif'=>$dataActif,
'dataPassif'=>$dataPassif,
'dataSIG'=>$dataSIG
);
}catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_indiscore($siret, $siren, $idEntreprise, $niveau = 0)
{
global $client;
if (($siret*1)==0 || ($siren*1)<100){
$fileName = 'indiscore-'.$idEntreprise.'-'.$niveau;
} else {
$fileName = 'indiscore-'.$siren.'-'.$niveau;
}
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) ){
$etab = cache_get('etab');
$return = $etab;
}else{
try {
$plus = false;
if (hasPerm('INDISCOREP') || hasPerm('INDISCORE2P') || hasPerm('INDISCORE3P')){
$plus = true;
}
$O = $client->getIndiscore($siren, 0, true, $niveau, $plus);
$etab = $O['result'];
cache_delete();
cache_add('etab', $etab);
$return = $etab;
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_dirigeants($siret, $siren, $idEntreprise)
{
global $client, $firephp;
if (($siret*1)==0 && ($siren*1)<100) { $fileName = 'dirigeants-'.$idEntreprise;
}else{ $fileName = 'dirigeants-'.$siret; }
$histo = false;
if ( isset($_REQUEST['vue']) && $_REQUEST['vue']=='histo' ){
$fileName .= '-histo'; $histo=true;
}
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) ){
$dirs = cache_get('dirs');
$return = $dirs;
}else{
try {
$O = $client->getDirigeants($siren, $histo);
$dirs = $O['result'];
cache_delete();
cache_add('dirs', $dirs);
$return = $dirs;
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_liens($siret, $siren, $idEntreprise)
{
global $client, $firephp;
if (($siret*1)==0 || ($siren*1)<100){
$fileName = 'liens-'.$idEntreprise;
}else{
$fileName = 'liens-'.$siret;
}
cache_filename($fileName);
if( cache_exist() && !( hasPerm('saisie') || hasModeEdition() ) ){
$liens = cache_get('liens');
$return = $liens;
}else{
try {
$O = $client->getLiens($siren, true);
$liens = $O['result'];
cache_delete();
cache_add('liens', $liens);
$return = $liens;
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
// --------------------------------------------------------------------------- //
// scoresws_banques
// --------------------------------------------------------------------------- //
function scoresws_banques($siret, $siren, $idEntreprise)
{
global $client, $firephp;
if ($siret * 1 == 0 ||
$siren * 1 < 100) {
$fileName = 'banque-'.$idEntreprise;
} else {
$fileName = 'banque-'.$siret;
}
cache_filename($fileName);
if (cache_exist() && hasModeEdition() == false) {
$return = cache_get('rbanque');
} else {
$return = null;
try {
$O = $client->getBanques($siren);
$return = $O['results'];
cache_delete();
cache_add('rbanque', $return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client, $fault, $_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
// --------------------------------------------------------------------------- //
// scoresws_etablissements
// --------------------------------------------------------------------------- //
function scoresws_etablissements($siret, $siren, $idEntreprise, $dep = 0, $actif = -1)
{
global $client, $firephp;
if ($siret * 1 == 0 || $siren * 1 < 100) {
$fileName = 'etablissements-'.$idEntreprise;
} else {
$fileName = 'etablissements-'.$siret;
}
$fileName.= '-'.$dep;
if ($actif > 0){
$fileName.= '-'.$actif;
}
cache_filename($fileName);
if (cache_exist() && hasModeEdition() == false) {
$return = cache_get('etabs');
} else {
$return = null;
try {
$O = $client->getListeEtablissements($siren, $dep, $actif);
$return = $O['result'];
cache_delete();
cache_add('etabs', $return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client, $fault, $_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scorews_privileges($siret, $siren, $detail, $vue){
global $client;
$fileName = 'privileges-'.$siret;
if (!empty($vue)){
$fileName.= '-'.$vue;
}
cache_filename($fileName);
if (cache_exist() && hasModeEdition() == false) {
$return = cache_get('privileges');
} else {
$return = null;
try {
$O = $client->getPrivileges($siren, $detail, array($vue) );
$return = $O;
cache_delete();
cache_add('privileges',$return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_evenements($siren, $nic = 0, $idEntreprise = 0, $vue = '') {
global $client;
if ($nic==0) {
$siret = $siren;
} else {
$siret = $siren.$nic;
}
if ( intval($siren) == 0 && intval($siren) < 100) {
$fileName = 'evenements-'.$idEntreprise;
} else {
$fileName = 'evenements-'.$siret;
}
if (!empty($vue)) { $fileName.= '-'.$vue; }
cache_filename($fileName);
if( cache_exist() && !hasModeEdition() ) {
$return = cache_get('evens');
} else {
$return = null;
try {
$O = $client->getListeEvenements($siren, $nic, 0, 200);
$return = $O['result'];
cache_delete();
cache_add('evens', $return);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}
function scoresws_rapport($siren, $idEntreprise, $niveau = 3) {
global $client;
if ( intval($siren) == 0 && intval($siren) < 100) {
$fileName = 'rapport-'.$idEntreprise;
} else {
$fileName = 'rapport-'.$siren;
}
if (!empty($niveau)) { $fileName.= '-'.$niveau; }
cache_filename($fileName);
if( cache_exist() && !hasModeEdition() ) {
$return['Identite'] = cache_get('Identite');
$return['Dirigeants'] = cache_get('Dirigeants');
$return['Liens'] = cache_get('Liens');
$return['Ratios'] = cache_get('Ratios');
$return['IndiScore'] = cache_get('IndiScore');
$return['Annonces'] = cache_get('Annonces');
} else {
$return = null;
try {
$O = $client->getRapport($siren, $niveau, $idEntreprise);
$elements = array(
'Identite',
'Dirigeants',
'Liens',
'IndiScore',
'Annonces'
);
$return = array();
cache_delete();
foreach ($elements as $elem){
if (array_key_exists('get'.$elem, $O['results'])) {
$return[$elem] = $O['results']['get'.$elem]['result'];
} else {
$return[$elem] = null;
}
cache_add($elem, $return[$elem]);
}
if (array_key_exists('getRatios', $O['results'])) {
$result = $O['results']['getRatios']['result'];
$bilansInfos = $result['BilansInfos'];
$ratiosInfos = $result['RatiosInfos'];
$ratiosEntrep = $result['RatiosEntrep'];
$ratiosEntrepEvol = $result['RatiosEntrepEvol'];
$ratiosSecteur = $result['RatiosSecteur'];
$nbEntNaf = $result['NbEntNaf'];
if(count($bilansInfos)>0)
{
$format = formatRatios(
$bilansInfos,
$ratiosEntrep,
$ratiosEntrepEvol,
$ratiosInfos,
$ratiosSecteur
);
while ( list($key, $val) = each( $format ) )
{
${$key} = $val;
}
}
$return['Ratios'] = array(
'bilansInfos' => $bilansInfos,
'ratiosEntrep' => $ratiosEntrep,
'ratiosEntrepEvol' => $ratiosEntrepEvol,
'ratiosInfos' => $ratiosInfos,
'ratiosSecteur' => $ratiosSecteur,
'nbEntNaf' => $nbEntNaf,
'dataActif' => $dataActif,
'dataPassif' => $dataPassif,
'dataSIG' => $dataSIG
);
} else {
$return['Ratios'] = null;
}
cache_add('Ratios', $return['Ratios']);
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
$return = false;
}
}
return $return;
}