2010-05-21 13:15:25 +00:00

1286 lines
48 KiB
PHP

<?php
// --------------------------------------------------------------------------- //
// internationalCompanyCreditDataService
// --------------------------------------------------------------------------- //
if (defined('NDEBUG') == false) {
define( 'NDEBUG', '1'); // Ne pas changer cette valeur, voir le client
define('VERSION', '1.0');
}
require_once realpath(dirname(__FILE__).'/../../../../config/prepend.php');
require_once 'user/permissions.php';
require_once 'user/override.php';
require_once 'scoresws/scoresws.php';
require_once 'ratios/ratios.php';
require_once 'dbbootstrap.php';
setDbConn('giant');
if (NDEBUG) {
$gServiceHeader = readSoapHeader();
}
$gDataSetTypes = array('Full', 'Compact', 'CreditRecommendation', 'Flex');
$gLanguageCodes = array('EN', 'FR');
$gServiceLevels = array('Normal', 'Urgent', 'Flash');
$gLevelDurations = array('Normal' => 7, 'Urgent' => 5, 'Flash' => 3);
$gTestCompanies = array('55214450300018',
'47997411500012',
'49496793800031');
// client pour scoresws_identite
$client =
new SoapClient(null,
array('trace' => 1,
'soap_version' => SOAP_1_1,
'location' => WEBSERVICE_URL,
'uri' => WEBSERVICE_URI,
'login' => 'sbeaugrand',
'password' => 'seb2010'));
// --------------------------------------------------------------------------- //
// modeTestUniquement
// --------------------------------------------------------------------------- //
function modeTestUniquement()
{
global $gServiceHeader;
if ($gServiceHeader->TestIndication != 'true') {
throw new SoapFault('FunctionalError',
functionalError(1003,
'TestIndication must be set'.
' for the moment'));
}
}
// --------------------------------------------------------------------------- //
// Serveur
// --------------------------------------------------------------------------- //
abstract class DataSetType { }
class FullDataSet extends DataSetType { }
class CompactDataSet extends DataSetType { }
class CreditRecommendation extends DataSetType { }
abstract class AccountItem { }
class AmountAccountItem extends AccountItem { }
class NumberAccountItem extends AccountItem { }
if (NDEBUG) {
$serveur =
new SoapServer('http://extranet.devlocal.com/services/'.
'wsdl/credit-data-service-provider-api-1.0.wsdl',
array('soap_version' => SOAP_1_1,
'trace' => true,
'classmap' => array('FullDataSet' =>
'FullDataSet',
'CompactDataSet' =>
'CompactDataSet',
'CreditRecommendation' =>
'CreditRecommendation',
'AmountAccountItem' =>
'AmountAccountItem',
'NumberAccountItem' =>
'NumberAccountItem')));
$serveur->addFunction('Ping');
$serveur->addFunction('RetrieveOptions');
$serveur->addFunction('OrderDataSet');
$serveur->addFunction('RetrieveOrderStatus');
$serveur->addFunction('RetrieveDataSet');
$serveur->addFunction('StartInvestigation');
$serveur->addFunction('StartMonitoring');
$serveur->addFunction('StopMonitoring');
$serveur->addFunction('UpdateMonitoringOptions');
$serveur->handle();
}
// --------------------------------------------------------------------------- //
// getDomElement
// --------------------------------------------------------------------------- //
function getDomElement(&$node, &$obj)
{
foreach ($node->childNodes as $n) {
if ($n->childNodes->length > 1) {
$o = new StdClass;
getDomElement($n, $o);
$name = $n->nodeName;
$obj->$name = $o;
} else {
$name = $n->nodeName;
$obj->$name = $n->firstChild->nodeValue;
}
}
}
// --------------------------------------------------------------------------- //
// readSoapHeader
// --------------------------------------------------------------------------- //
// Dans php.ini : always_populate_raw_post_data = On
// --------------------------------------------------------------------------- //
function readSoapHeader()
{
$header = new StdClass;
$xml = new XmlReader;
$xml->xml($GLOBALS['HTTP_RAW_POST_DATA']);
while ($xml->read()) {
if ($xml->namespaceURI == 'http://extranet.devlocal.com/services/'.
'schema/services/shared/1.0' &&
$xml->nodeType == XMLReader::ELEMENT) {
$node = $xml->expand();
getDomElement($node, $header);
} else if ($xml->nodeType == XMLReader::ELEMENT &&
$xml->localName == 'Body') {
break;
}
}
$xml->close();
return $header;
}
// --------------------------------------------------------------------------- //
// enregistrement
// --------------------------------------------------------------------------- //
function enregistrement($table, $id)
{
global $gServiceHeader;
if (isset($gServiceHeader->CustomerId) == true) {
$consumer_id = $gServiceHeader->CustomerId;
} else {
$consumer_id = $gServiceHeader->ConsumerId;
}
return Doctrine_Query::create()
->from($table)
->andWhere('ConsumerId = ?', $consumer_id)
->andWhere('ProviderOrderId = ?', $id)
->fetchOne();
}
// --------------------------------------------------------------------------- //
// functionalError
// --------------------------------------------------------------------------- //
function functionalError($n, $details = '')
{
$r = new StdClass;
$r->version = VERSION;
if ($n >= 1000) {
$r->ErrorCode = $n;
} else {
$r->ErrorCode = 5000 + $n;
}
switch ($n) {
case 1: $m = 'Order is not completed'; break;
case 1003: $m = 'Authorization failed'; break;
case 3000: $m = 'Invalid CompanyId'; break;
case 3002: $m = 'Invalid LanguageCode requested'; break;
case 3003: $m = 'Invalid DataSetType requested'; break;
case 3004: $m = 'Invalid ServiceLevel requested'; break;
case 3021: $m = 'Invalid OrderId / Consumer combination'; break;
}
$r->ErrorMessage = $m.'.';
if (empty($details) == false) {
$r->ErrorDetails = $details.'.';
}
return print_r($r, true);
}
// --------------------------------------------------------------------------- //
// technicalError
// --------------------------------------------------------------------------- //
function technicalError($n, $details = '')
{
$r = new StdClass;
$r->version = VERSION;
$r->ErrorCode = 9000 + $n;
switch ($n) {
case 1: $m = 'Internal web service error'; break;
}
$r->ErrorMessage = $m.'.';
if (empty($details) == false) {
$r->ErrorDetails = $details.'.';
}
return print_r($r, true);
}
// --------------------------------------------------------------------------- //
// orderResponse
// --------------------------------------------------------------------------- //
function orderResponse(&$o, &$q)
{
global $gServiceHeader;
$order = new StdClass;
$order->ProviderOrderId = $q->ProviderOrderId;
$order->ConsumerId = $gServiceHeader->ConsumerId;
if (empty($gServiceHeader->CustomerId) == false) {
$order->CustomerId = $gServiceHeader->CustomerId;
}
$order->ProviderId = $gServiceHeader->Provider->ProviderId;
$order->CountryCode = $gServiceHeader->Provider->CountryCode;
$order->CompanyId = $q->CompanyId;
$order->Version = '1.0';
$order->LanguageCode = $q->LanguageCode;
if (isset($q->OrderType) == true) {
$order->OrderType = $q->OrderType;
$order->DataSetType = $q->DataSetType;
if ($order->OrderType == 'Investigation') {
$order->ServiceLevelName = $q->ServiceLevelName;
}
$order->OrderStatus = $q->OrderStatus;
$order->OrderDateTime = str_replace(' ', 'T',$q->OrderDateTime);
$order->DueDateTime = str_replace(' ', 'T',$q->DueDateTime);
if ($q->DateTimeCompleted != '0000-00-00 00:00:00') {
$order->DateTimeCompleted =
str_replace(' ', 'T', $q->DateTimeCompleted);
}
if ($q->DateTimeRetrieved != '0000-00-00 00:00:00') {
$order->DateTimeRetrieved =
str_replace(' ', 'T', $q->DateTimeRetrieved);
}
if (empty($q->Remark) == false) {
$order->Remark = $q->Remark;
}
} else if (isset($q->EventType) == true) {
$datetime = date('Y-m-d\TH:i:s');
$order->CategoryName = $q->CategoryName;
$order->OrderType = 'Monitoring';
$order->EventType = $q->EventType;
$order->OrderStatus = 'Completed';
$order->OrderDateTime = $datetime;
$order->DateTimeCompleted = $datetime;
if (isset($o->PreferredStartDate) == true) {
$order->PreferredStartDate = $o->PreferredStartDate;
}
$order->ActualStartDate = $q->ActualStartDate;
if (isset($o->PreferredEndDate) == true) {
$order->PreferredEndDate = $o->PreferredEndDate;
}
$order->ActualEndDate = $q->ActualEndDate;
//$order->Remark = ;
}
return $order;
}
// --------------------------------------------------------------------------- //
// envoieCourriel
// --------------------------------------------------------------------------- //
function envoieCourriel($sujet, $texte)
{
require_once 'mail/mail.php';
sendMail("[Giant] ".$sujet , $texte,
// From
array('email' => 'contact@scores-decisions.com',
'name' => 'Commande Giant'),
// To
array(0 => array('email' => EMAIL_SUPPORTDEV,
'name' => 'Support')));
}
// --------------------------------------------------------------------------- //
// ajouteJoursOuvrables
// --------------------------------------------------------------------------- //
function ajouteJoursOuvrables($jours)
{
$annee = date('Y');
$pm = $annee % 19;
$pi = ($pm * 19 + 24) % 30;
$pt = intval(29 / ($pi + 1)) * intval((21 - $pm) / 11);
$pu = intval($pi / 28);
$pi = $pi + ($pt * $pu - 1) * $pu;
$pj = ($annee + intval($annee / 4) + $pi - 13) % 7;
$pi = $pi - $pj + 1;
$paques_mois = intval(($pi + 40) / 44) + 3;
$paques_jour = $pi - intval($paques_mois / 4) * 31 + 28;
if ($paques_mois == 4 &&
$paques_jour > 25) {
$paques_jour -= 7;
}
if ($paques_mois == 3 &&
$paques_jour == 32) {
$paques_mois = 4;
$paques_jour = 1;
}
$ascens_mois = $paques_mois + 1;
$ascens_jour = $paques_jour + $paques_mois + 4;
if ($ascens_jour > $ascens_mois + 26) {
$ascens_jour -= $ascens_mois + 26;
$ascens_mois++;
}
$pentec_mois = $ascens_mois;
$pentec_jour = $ascens_jour + 11;
if ($pentec_jour > $pentec_mois + 26) {
$pentec_jour -= $pentec_mois + 26;
$pentec_mois++;
}
$jours_feries =
array(0,
date('z', mktime(0, 0, 0, 5, 1)),
date('z', mktime(0, 0, 0, 5, 8)),
date('z', mktime(0, 0, 0, 7, 14)),
date('z', mktime(0, 0, 0, 8, 15)),
date('z', mktime(0, 0, 0, 11, 1)),
date('z', mktime(0, 0, 0, 11, 11)),
date('z', mktime(0, 0, 0, 12, 25)),
date('z', mktime(0, 0, 0, $paques_mois, $paques_jour)),
date('z', mktime(0, 0, 0, $ascens_mois, $ascens_jour)),
date('z', mktime(0, 0, 0, $pentec_mois, $pentec_jour)));
for ($i = 0; $i < $jours; ++$i) {
$time = strtotime('+'.$i.' day');
if (date('N', $time) >= 6 ||
in_array(date('z', $time), $jours_feries) == true) {
++$jours;
}
}
return strtotime('+'.$jours.' day');
}
// --------------------------------------------------------------------------- //
// company
// --------------------------------------------------------------------------- //
function company(&$i)
{
$c = new StdClass;
$c->CompanyId = $i['Siret'];
//$c->OldCompanyId = ;
if ($i['TvaAttribue'] == 1) {
$c->Vat = new StdClass;
$c->Vat->VatNumber = $i['TvaNumero'];
}
$c->CompanyStatus = $i['Actif'];
$c->CompanyName = $i['Nom'];
$c->EmailAddress = $i['Mail'];
$c->WebAddress = str_replace('http://', '', $i['Web']);
$c->IncorporationDate =
preg_replace('/^([0-9]{4})([0-9]{2})/', '$1-$2-', $i['DateCreaEt']);
if (strtotime($c->IncorporationDate) == false) {
$c->IncorporationDate =
preg_replace('/^([0-9]{4})([0-9]{2})/', '$1-$2-', $i['DateCreaEn']);
}
if (strtotime($c->IncorporationDate) == false) {
unset($c->IncorporationDate);
}
$c->IsUltimateParent = $i['Siege'];
$country_legal_form = new StdClass;
$country_legal_form->_ = $i['FJ_lib'];
$country_legal_form->code = $i['FJ'];
$country_legal_form->lang = 'FR';
$c->LegalForm = new StdClass;
$c->LegalForm->CountryLegalForm = $country_legal_form;
$c->LegalForm->UnifiedLegalForm = 'Unknown'; // TODO
//$c->LegalForm->FoundedAsLegalForm = ;
$c->LegalForm->Country = 'FR';
//$c->LegalForm->IsSocial = ;
//$c->LegalForm->IsCivil = ;
$c->Telefax = '+33'.str_replace('.', '', $i['Fax']);
$c->TelephoneNumber = '+33'.str_replace('.', '', $i['Tel']);
if (empty($i['Enseigne']) == false) {
$c->TradeName = $i['Enseigne'];
}
//$c->SocialSecurityNumber = ;
//$c->CompanyRegistry = ;
$address = new StdClass;
$address->Street = $i['Adresse'];
$address->HouseNumber = $i['AdresseNum'];
//$address->HouseNumberAddition = ;
//$address->Building = ;
//$address->PoBox = ;
$address->PostCode = $i['CP'];
$address->City = $i['Ville'];
//$address->State = ;
$address->Country = $i['PaysIso2'];
//$address->Period = ;
//$address->FlexibleAddress = ;
$c->CompanyAddress = $address;
//$c->StockExchange = ;
//$c->Division = ;
$op = new StdClass;
$product_name = new StdClass;
$product_name->_ = $i['NafEtabLib'];
//$product_name->source = ;
//$product_name->isPrimary = ;
$product_name->lang = 'FR';
$op->ProductName[] = $product_name;
$product_name = new StdClass;
$product_name->_ = $i['Activite'];
$product_name->lang = 'FR';
$op->ProductName[] = $product_name;
$op->IndustryCode = new StdClass;
$op->IndustryCode->NaceCode = substr($i['NaceEtab'], 1);
//$op->IndustryCode->Description = ;
//$op->IndustryCode->version = ;
//$op->IndustryCode->source = ;
//$op->Certifications = ;
//$op->ExportCountry = ;
//$op->ImportCountry = ;
//$op->ExportRegion = ;
//$op->ImportRegion = ;
//$op->ExportGood = ;
//$op->ImportGood = ;
$c->Operations = $op;
//$c->ShareCapital = ;
$position = dirigeants($i);
if (count($position) > 0) {
$c->Position = $position;
}
$c->Employees = new StdClass;
$c->Employees->TotalNrFulltime = $i['Effectif'];
//$c->RealEstate = ;
//$c->PeerGroup = ;
//$c->Event = ;
$company = new StdClass;
$company->Company = $c;
return $company;
}
// --------------------------------------------------------------------------- //
// bilans
// --------------------------------------------------------------------------- //
function bilans(&$ratios)
{
$bilans = array();
$actif = array(59, 51, 52, 53, 69, 60, 61, 62, 63);
$passif = array(79, 70, 71, 72, 90, 83, 84, 85, 86, 87);
foreach ($ratios['bilansInfos'] as $bilan_num => $b) {
$balance = new StdClass;
$balance->Assets = new StdClass;
$balance->Liabilities = new StdClass;
foreach ($actif as $code) {
$description = new StdClass;
$description->_ = $ratios['ratiosInfos']['r'.$code]['libelle'];
$description->code = 'r'.$code;
$description->lang = 'FR';
$item = new NumberAccountItem;
$item->Description = $description;
//$item->level = ;
$item->Value = $ratios['ratiosEntrep'][$bilan_num]['r'.$code];
if (empty($description->_) == true) {
throw new SoapFault('TechnicalError',
technicalError(1, 'Assets'));
}
$balance->Assets->AccountItem[] = $item;
}
foreach ($passif as $code) {
$description = new StdClass;
$description->_ = $ratios['ratiosInfos']['r'.$code]['libelle'];
$description->code = 'r'.$code;
$description->lang = 'FR';
$item = new NumberAccountItem;
$item->Description = $description;
//$item->level = ;
$item->Value = $ratios['ratiosEntrep'][$bilan_num]['r'.$code];
if (empty($description->_) == true) {
throw new SoapFault('TechnicalError',
technicalError(1, 'Liabilities'));
}
$balance->Liabilities->AccountItem[] = $item;
}
//$balance->ExplanatoryNotes = ;
$profit_and_loss = new StdClass;
foreach ($ratios['ratiosEntrep'][$bilan_num] as $code => $valeur) {
$code_num = substr($code, 1);
if (in_array($code_num, $actif) ||
in_array($code_num, $passif)) {
continue;
}
$description = new StdClass;
$description->_ = $ratios['ratiosInfos'][$code]['libelle'];
$description->code = $code;
$description->lang = 'FR';
$item = new NumberAccountItem;
$item->Description = $description;
//$item->level = ;
$item->Value = $valeur;
if (empty($description->_) == true) {
throw new SoapFault('TechnicalError',
technicalError(1, 'ProfitAndLoss'));
}
$profit_and_loss->AccountItem[] = $item;
}
$accounts = new StdClass;
$accounts->BalanceSheet = $balance;
$accounts->ProfitAndLoss = $profit_and_loss;
//$accounts->KeyCreditRatios = ;
//$accounts->ExplanatoryNotes = ;
$bilan = new StdClass;
//$bilan->Description = ;
//$bilan->AccountsFileDate = ;
$bilan->AccountsDate = $b['dateCloture'];
$bilan->AccountsStatus = 'AtClosingStage';
//$bilan->AccountsFormat = ;
switch ($b['typeBilan']) {
case 'N': $bilan->AccountsType = 'Not-consolidated'; break;
case 'C': $bilan->AccountsType = 'Consolidated'; break;
default : $bilan->AccountsType = 'Unspecified';
}
$bilan->BaseCurrency = $b['devise'];
switch (strtoupper($b['unite'])) {
case 'K': $bilan->Unit = 1000; break;
case 'M': $bilan->Unit = 1000000; break;
//default : $bilan->Unit = 1;
}
//$bilan->DateOfGeneralMeeting = ;
//$bilan->AuditorOpinion = ;
//$bilan->AccountsQualityLabel = ;
//$bilan->HarmonizedAnnualAccounts = ;
$bilan->OriginalAnnualAccounts = $accounts;
$bilans[] = $bilan;
}
return $bilans;
}
// --------------------------------------------------------------------------- //
// synthese
// --------------------------------------------------------------------------- //
function synthese(&$ratios)
{
$synthese = array();
foreach ($ratios['bilansInfos'] as $bilan_num => $b) {
$s = new StdClass;
//$s->Description = ;
//$s->Source = ;
$s->AccountStatus = 'AtClosingStage';
switch ($b['typeBilan']) {
case 'N': $s->AccountsType = 'Not-consolidated'; break;
case 'C': $s->AccountsType = 'Consolidated'; break;
default : $s->AccountsType = 'Unspecified';
}
$s->SummaryDate = $b['dateCloture'];;
switch (strtoupper($b['unite'])) {
case 'K': $s->Unit = 1000; break;
case 'M': $s->Unit = 1000000; break;
default : $s->Unit = 1;
}
$s->Revenue = $ratios['ratiosEntrep'][$bilan_num]['r5'];;
//$s->TotalEquity = $ratios['ratiosEntrep'][$bilan_num]['r231'];
$s->ProfitLossBeforeTax = $ratios['ratiosEntrep'][$bilan_num]['r7'];
$s->ProfitLoss = $ratios['ratiosEntrep'][$bilan_num]['r10'];
$s->WorkingCapital = $ratios['ratiosEntrep'][$bilan_num]['r231'];
//$s->AuthorizedCapital = ;
$s->IssuedCapital = $ratios['ratiosEntrep'][$bilan_num]['r232'];
//$s->PaidUpCapital = ;
//$s->VariableCapital = ;
//$s->VariablePaidUpCapital = ;
$synthese[] = $s;
}
return $synthese;
}
// --------------------------------------------------------------------------- //
// paiement
// --------------------------------------------------------------------------- //
function paiement(&$ratios)
{
if (empty($ratios['bilansInfos']) == true) {
return false;
}
$r = new StdClass;
$r->Period = new StdClass;
$r->Period->EndDate = $ratios['bilansInfos' ][0]['dateCloture'];
$r->DebtorDays = intval($ratios['ratiosEntrep'][0]['r278']);
$r->CreditorDays = intval($ratios['ratiosEntrep'][0]['r279']);
//$r->LiquidityAssessment = ;
//$r->PaymentQualification = ;
//$r->FreeText = ;
//$r->TradePaymentExperience = ;
//$r->ProtestsAndNonPayments = ;
//$r->DebtCollection = ;
//$r->AnalysisByPeriod = ;
//$r->AnalysisByAmount = ;
return $r;
}
// --------------------------------------------------------------------------- //
// banques
// --------------------------------------------------------------------------- //
function banques(&$sd_banques)
{
$banques = array();
foreach ($sd_banques as $b) {
$banque = new StdClass;
$banque->BankName = $b['libBanque'];
//$banque->BankIdentifierCode = ;
//$banque->BankAccount = ;
//$banque->BankAddress = ;
//$banque->SortCode = ;
$banques[] = $banque;
}
return $banques;
}
// --------------------------------------------------------------------------- //
// creditRecommendation
// --------------------------------------------------------------------------- //
function creditRecommendation(&$indiscore)
{
$e = new StdClass;
$e->Date = date('Y-m-d');
$e->AmountAdvised = $indiscore['encours'];
//$e->Description = ;
//$e->ParameterizedDescription = ;
//$e->Trend = ;
//$e->ReasonNoAmountAdvised = ;
//$e->FreeText = ;
if (isset($indiscore['tabInfosNotations']) == true) {
$e->RiskClasses = new StdClass;
$risk_class = new StdClass;
$risk_class->RatingName = 'IndiScore';
$risk_class->RatingValue =
$indiscore['tabInfosNotations']['ProbabiliteDefaut'];
//$risk_class->Description = ;
//$risk_class->ParameterizedDescription = ;
//$risk_class->FreeText = ;
$e->RiskClasses->ProviderRiskClass[] = $risk_class;
$risk_class = new StdClass;
$risk_class->RatingName = 'Conan & Holder';
$risk_class->RatingValue = $indiscore['scores']['ConanH'];
$e->RiskClasses->ProviderRiskClass[] = $risk_class;
$risk_class = new StdClass;
$risk_class->RatingName = 'Afdcc2';
$risk_class->RatingValue = $indiscore['scores']['Afdcc2'];
$e->RiskClasses->ProviderRiskClass[] = $risk_class;
$risk_class = new StdClass;
$risk_class->RatingName = 'Score Z';
$risk_class->RatingValue = $indiscore['scores']['Z'];
$e->RiskClasses->ProviderRiskClass[] = $risk_class;
}
return $e;
}
// --------------------------------------------------------------------------- //
// auditor
// --------------------------------------------------------------------------- //
function auditor()
{
$auditor = new StdClass;
return $auditor;
}
// --------------------------------------------------------------------------- //
// dirigeants
// --------------------------------------------------------------------------- //
function dirigeants(&$i)
{
$d = array();
if (empty($i['dir2NomPrenom']) == false) {
$pos = new StdClass;
//$pos->Authorization = ;
//$pos->Description = ;
//$pos->MandateEndEvent = ;
if (empty($i['dir1DateFct']) == false) {
$pos->Period = new StdClass;
$pos->Period->StartDate = $i['dir1DateFct'];
}
//$pos->PositionChangeReason = ;
$pos->PositionTitle = new StdClass;
$pos->PositionTitle->_ = $i['dir1Titre'];
//$pos->PositionTitle->code = ;
$pos->PositionTitle->lang = 'FR';
$pos->Type = 'Management';
//$pos->OtherPositions = ;
//$pos->OtherDirectorShips = ;
$pos->Person = new StdClass;
//$pos->Person->FirstName = ;
//$pos->Person->MiddleName = ;
//$pos->Person->LastName = ;
//$pos->Person->Initials = ;
//$pos->Person->Prefix = ;
//$pos->Person->Title = ;
//$pos->Person->FlexibleName = ;
$pos->Person->DateOfBirth = $i['dir1DateNaiss'];
$pos->Person->PlaceOfBirth = $i['dir1LieuNaiss'];
//$pos->Person->CountryOfBirth = ;
//$pos->Person->PersonalAddress = ;
//$pos->Person->TelephoneNumber = ;
//$pos->Person->PersonalCalamity = ;
//$pos->Person->Gender = ;
//$pos->Company = ;
//$pos->source = ;
$d[] = $pos;
}
if (empty($i['dir2NomPrenom']) == false) {
$pos = new StdClass;
if (empty($i['dir2DateFct']) == false) {
$pos->Period = new StdClass;
$pos->Period->StartDate = $i['dir2DateFct'];
}
$pos->PositionTitle = new StdClass;
$pos->PositionTitle->_ = $i['dir2Titre'];
$pos->PositionTitle->lang = 'FR';
$pos->Type = 'Management';
$pos->Person = new StdClass;
$pos->Person->DateOfBirth = $i['dir2DateNaiss'];
$pos->Person->PlaceOfBirth = $i['dir2LieuNaiss'];
$d[] = $pos;
}
return $d;
}
// --------------------------------------------------------------------------- //
// etablissements
// --------------------------------------------------------------------------- //
function etablissements(&$etablissements)
{
$r = array();
foreach ($etablissements as $e) {
$branch = new StdClass;
$branch->BranchId = $e['id'];
if (empty($e['Enseigne']) == false) {
$branch->BranchName = $e['Enseigne'];
}
//$branch->FreeText = ;
//$branch->FoundingDate = ;
//$branch->SourceDate = ;
//$branch->NrOfBranches = ;
$address = new StdClass;
$address->Street = $e['Adresse'];
//$address->HouseNumber = ;
//$address->HouseNumberAddition = ;
//$address->Building = ;
//$address->PoBox = ;
$address->PostCode = $e['CP'];
$address->City = $e['Ville'];
//$address->State = ;
//$address->Country = ;
//$address->Period = ;
//$address->FlexibleAddress = ;
$branch->BranchAddress = $address;
$r[] = $branch;
}
return $r;
}
// --------------------------------------------------------------------------- //
// liens
// --------------------------------------------------------------------------- //
function liens(&$liens)
{
$r = array();
foreach ($liens['actionnaires'] as $l) {
$assoc = new StdClass;
$assoc->RelationShip = 'Shareholder';
//$assoc->Description = ;
//$assoc->FreeText = ;
//$assoc->Period = ;
if (empty($l['Pmin']) == true &&
empty($l['MajMin']) == false) {
$assoc->IsMajorityStake = $l['MajMin'] == '+';
}
//$assoc->Source = ;
$assoc->IsPrincipalStakeHolder = $l['Pmin'] > 50;
$assoc->Shares = new StdClass;
//$assoc->Shares->NominalValue = ;
//$assoc->Shares->NrOfShares = ;
$assoc->Shares->Percentage = str_replace(',', '.', $l['Pmin']);
//$assoc->Shares->ShareType = ;
//$assoc->Person = ;
$assoc->Company = new StdClass;
$assoc->Company->CompanyId = $l['Siren'];
$assoc->Company->CompanyName = $l['RaisonSociale'];
//$assoc->Company->RepresentedBy = ;
//$assoc->Company->CompanyAddress = ;
//$assoc->Company->ExceptionEvent = ;
$r[] = $assoc;
}
foreach ($liens['participations'] as $l) {
$assoc = new StdClass;
$assoc->RelationShip = 'Participation';
$assoc->Shares = new StdClass;
$assoc->Shares->Percentage = str_replace(',', '.', $l['Pmin']);
$assoc->Company = new StdClass;
$assoc->Company->CompanyId = $l['Siren'];
$assoc->Company->CompanyName = $l['RaisonSociale'];
$r[] = $assoc;
}
return $r;
}
// --------------------------------------------------------------------------- //
// Ping
// --------------------------------------------------------------------------- //
function Ping($o)
{
$r = new StdClass;
$addr = explode(':', WEBSERVICE_URI);
$hote = str_replace('/', '', $addr[1]);
if (isset($addr[2]) == true) {
$port = str_replace('/', '', $addr[2]);
} else {
$port = -1;
}
$fp = fsockopen($hote, $port);
if ($fp != false) {
fclose($fp);
$r->ResponseCode = 'OK';
} else {
$r->ResponseCode = 'ServiceNotAvailable';
$r->Remark = 'Some services are not available.';
}
//$r->version = ;
return $r;
}
// --------------------------------------------------------------------------- //
// RetrieveOptions
// --------------------------------------------------------------------------- //
function RetrieveOptions($o)
{
global $gDataSetTypes;
global $gLanguageCodes;
global $gServiceLevels;
global $gLevelDurations;
$r = new StdClass;
$r->DateOfLastUpdate = '0000-00-00';
$i = scoresws_identite($o->CompanyId,
substr($o->CompanyId, 0, 9), 0);
if ($i == false) {
throw new SoapFault('TechnicalError', technicalError(1));
}
if (empty($i['Bilan']['Cloture']) == false) {
$r->DateOfLastAnnualAccount =
preg_replace('/^([0-9]{4})([0-9]{2})/', '$1-$2-',
$i['Bilan']['Cloture']);
}
if (isset($r->DateOfLastAnnualAccount) == true &&
$r->DateOfLastUpdate < $r->DateOfLastAnnualAccount) {
$r->DateOfLastUpdate = $r->DateOfLastAnnualAccount;
}
if (empty($i['DateMajINSEE']) == false &&
$r->DateOfLastUpdate < $i['DateMajINSEE']) {
$r->DateOfLastUpdate = $i['DateMajINSEE'];
}
if (empty($i['DateMajRCS']) == false &&
$r->DateOfLastUpdate < $i['DateMajRCS']) {
$r->DateOfLastUpdate = $i['DateMajRCS'];
}
if (empty($i['DateMajANN']) == false &&
$r->DateOfLastUpdate < $i['DateMajANN']) {
$r->DateOfLastUpdate = $i['DateMajANN'];
}
if (empty($i['DateMajID']) == false &&
$r->DateOfLastUpdate < $i['DateMajID']) {
$r->DateOfLastUpdate = $i['DateMajID'];
}
if ($r->DateOfLastUpdate == '0000-00-00') {
unset($r->DateOfLastUpdate);
}
for ($i = 0; $i < count($gDataSetTypes); ++$i) {
$r->DataSetOptions[$i] =
array('Version' => VERSION,
'LanguageCodes' => $gLanguageCodes,
'DataSetType' => $gDataSetTypes[$i]);
}
$service_levels = array();
for ($i = 0; $i < count($gServiceLevels); ++$i) {
$service_levels[$i] =
array('Name' => $gServiceLevels[$i],
'Duration' => $gLevelDurations[$gServiceLevels[$i]],
'DurationMetric' => 'day');
}
$r->InvestigationOptions =
array(array('Version' => VERSION,
'LanguageCodes' => $gLanguageCodes,
'DataSetType' => 'Full',
'ServiceLevels' => $service_levels));
$r->MonitoringOptions =
array(array('Version' => VERSION,
'LanguageCodes' => $gLanguageCodes,
'Categories' =>
array(array('Name' => 'CreditRecommendation',
'EventCodes' =>
array('FINANCIAL.CREDIT_RECOMMENDATION_CHANGE')),
array('Name' => 'All',
'EventCodes' =>
array('GENERAL.ADDRESS_CHANGE',
'GENERAL.COMPANY_NAME_CHANGE',
'GENERAL.LEGALFORM_CHANGE',
'GENERAL.ACQUISITION',
'GENERAL.NEWS',
'FINANCIAL.ANNUAL_ACCOUNT_FILED',
'FINANCIAL.CAPITAL_CHANGE',
'FINANCIAL.CREDIT_RECOMMENDATION_CHANGE',
'EXCEPTION.BANKRUPTCY_OR_LIQUIDATION')))));
$r->version = VERSION;
return $r;
}
// --------------------------------------------------------------------------- //
// getDataSet
// --------------------------------------------------------------------------- //
function getDataSet($company_id, $data_set_type)
{
$siren = substr($company_id, 0, 9);
switch ($data_set_type) {
case 'Full':
$identite = scoresws_identite($company_id, $siren, 0);
break;
case 'Compact':
case 'CreditRecommendation':
$identite = scoresws_identitelight($company_id, $siren, 0);
break;
case 'Flex':
default:
throw new SoapFault('FunctionalError',
functionalError(3003, $data_set_type));
}
if ($identite == false) {
throw new SoapFault('TechnicalError',
technicalError(1, 'scoresws_identite'));
}
$ratios = scoresws_ratios($company_id, $siren, 0);
if ($ratios == false) {
throw new SoapFault('TechnicalError',
technicalError(1, 'scoresws_ratios'));
}
$banques = scoresws_banques($company_id, $siren, 0);
if ($banques == false) {
throw new SoapFault('TechnicalError',
technicalError(1, 'scoresws_banques'));
}
$indiscore = scoresws_indiscore($company_id, $siren, 0);
if ($indiscore == false) {
throw new SoapFault('TechnicalError',
technicalError(1, 'scoresws_indiscore'));
}
$etablissements = scoresws_etablissements($company_id, $siren, 0);
if ($etablissements == false) {
throw new SoapFault('TechnicalError',
technicalError(1, '$scoresws_etablissements'));
}
$liens = scoresws_liens($company_id, $siren, 0);
if ($liens == false) {
throw new SoapFault('TechnicalError',
technicalError(1, '$scoresws_liens'));
}
$company = company($identite);
$company->Company->CreditRecommendation = creditRecommendation($indiscore);
$company->Company->AnnualAccounts = bilans($ratios);
$company->Company->Bank = banques($banques);
//$company->Company->Auditor = auditor();
$company->Company->Branch = etablissements($etablissements);
$company->Company->Associated = liens($liens);
$company->Company->FinancialSummary = synthese($ratios);
$p = paiement($ratios);
if ($p != false) {
$company->Company->PaymentBehaviour = $p;
}
return $company;
}
// --------------------------------------------------------------------------- //
// OrderDataSet
// --------------------------------------------------------------------------- //
function OrderDataSet($o)
{
global $gServiceHeader;
global $gLanguageCodes;
global $gTestCompanies;
if (in_array($o->LanguageCode, $gLanguageCodes) == false) {
throw new SoapFault('FunctionalError',
functionalError(3002, $o->LanguageCode));
}
if ($gServiceHeader->TestIndication == 'true' &&
in_array($o->CompanyId, $gTestCompanies) == false) {
throw new SoapFault('FunctionalError',
functionalError(3000, $o->CompanyId.
' is not in test mode'));
}
modeTestUniquement();
$date = date('Y-m-d\TH:i:s');
$q = new Orders;
$q->TestIndication = $gServiceHeader->TestIndication == 'true';
$q->ConsumerId = $gServiceHeader->ConsumerId;
if (empty($gServiceHeader->CustomerId) == false) {
$q->CustomerId = $gServiceHeader->CustomerId;
}
$q->CompanyId = $o->CompanyId;
$q->OrderType = 'DataSet';
$q->DataSetType = $o->DataSetType->_;
$q->ServiceLevelName = 'Immediate';
$q->LanguageCode = $o->LanguageCode;
$q->OrderStatus = 'Pending';
$q->OrderDateTime = $date;
$q->DueDateTime = $date;
$q->save();
$q->DataSet = serialize(getDataSet($o->CompanyId,
$o->DataSetType->_));
$q->OrderStatus = 'Completed';
$q->DateTimeCompleted = $date;
$q->save();
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
return $r;
}
// --------------------------------------------------------------------------- //
// RetrieveOrderStatus
// --------------------------------------------------------------------------- //
function RetrieveOrderStatus($o)
{
$q = enregistrement('Orders', $o->ProviderOrderId);
if ($q == false) {
throw new SoapFault('FunctionalError', functionalError(3021));
}
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
return $r;
}
// --------------------------------------------------------------------------- //
// RetrieveDataSet
// --------------------------------------------------------------------------- //
function RetrieveDataSet($o)
{
$q = enregistrement('Orders', $o->ProviderOrderId);
if ($q == false) {
throw new SoapFault('FunctionalError', functionalError(3021));
}
if ($q->OrderStatus != 'Completed' &&
$q->OrderStatus != 'Delivered') {
throw new SoapFault('FunctionalError',
functionalError(3021, 'Order status is '.
$q->OrderStatus));
}
if ($q->OrderStatus != 'Delivered') {
$q->OrderStatus = 'Delivered';
$q->DateTimeRetrieved = date('Y-m-d\TH:i:s');
$q->save();
}
switch ($q->DataSetType) {
case 'Full':
$data_set = new FullDataSet;
break;
case 'Compact':
$data_set = new CompactDataSet;
break;
case 'CreditRecommendation':
$data_set = new CreditRecommendation;
break;
default:
throw new SoapFault('TechnicalError',
technicalalError(9000, $q->DataSetType.
' non-implemented'));
}
$data_set->Company = unserialize($q->DataSet)->Company;
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
$r->DataSet = $data_set;
return $r;
}
// --------------------------------------------------------------------------- //
// StartInvestigation
// --------------------------------------------------------------------------- //
function StartInvestigation($o)
{
global $gServiceHeader;
global $gDataSetTypes;
global $gLanguageCodes;
global $gServiceLevels;
global $gLevelDurations;
global $gTestCompanies;
if (in_array($o->LanguageCode, $gLanguageCodes) == false) {
throw new SoapFault('FunctionalError',
functionalError(3002, $o->LanguageCode));
}
if (in_array($o->DataSetType->_, $gDataSetTypes) == false) {
throw new SoapFault('FunctionalError',
functionalError(3003, $o->DataSetType->_));
}
if (in_array($o->ServiceLevelName, $gServiceLevels) == false) {
throw new SoapFault('FunctionalError',
functionalError(3004, $o->ServiceLevelName));
}
if ($o->TestIndication == 'true' &&
in_array($o->CompanyId, $gTestCompanies) == false) {
throw new SoapFault('FunctionalError',
functionalError(3000, $o->CompanyId.
' is not in test mode'));
}
modeTestUniquement();
$date = date('Y-m-d\TH:i:s');
$q = new Orders;
$q->TestIndication = $gServiceHeader->TestIndication == 'true';
$q->ConsumerId = $gServiceHeader->ConsumerId;
if (empty($gServiceHeader->CustomerId) == false) {
$q->CustomerId = $gServiceHeader->CustomerId;
}
$q->CompanyId = $o->CompanyId;
$q->OrderType = 'Investigation';
$q->DataSetType = $o->DataSetType->_;
$q->ServiceLevelName = $o->ServiceLevelName;
$q->LanguageCode = $o->LanguageCode;
$q->OrderStatus = 'Pending';
$q->OrderDateTime = $date;
$q->DueDateTime =
date('Y-m-d\TH:i:s',
ajouteJoursOuvrables($gLevelDurations[$q->ServiceLevelName]));
$q->save();
//if ($o->TestIndication == false) {
envoieCourriel('Commande', 'ProviderOrderId='.$q->ProviderOrderId);
//}
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
return $r;
}
// --------------------------------------------------------------------------- //
// StartMonitoring
// --------------------------------------------------------------------------- //
function StartMonitoring($o)
{
global $gServiceHeader;
global $gLanguageCodes;
global $gTestCompanies;
if (in_array($o->LanguageCode, $gLanguageCodes) == false) {
throw new SoapFault('FunctionalError',
functionalError(3002, $o->LanguageCode));
}
if ($gServiceHeader->TestIndication == 'true' &&
in_array($o->CompanyId, $gTestCompanies) == false) {
throw new SoapFault('FunctionalError',
functionalError(3000, $o->CompanyId.
' is not in test mode'));
}
modeTestUniquement($o->CompanyId);
$i = scoresws_identitelight($o->CompanyId,
substr($o->CompanyId, 0, 9), 0);
$q = new Monitors;
$q->TestIndication = $gServiceHeader->TestIndication == 'true';
$q->ConsumerId = $gServiceHeader->ConsumerId;
if (empty($gServiceHeader->CustomerId) == false) {
$q->CustomerId = $gServiceHeader->CustomerId;
}
$q->CompanyId = $o->CompanyId;
$q->CompanyName = $i['Nom'];
$q->CategoryName = $o->CategoryName;
$q->EventType = $o->EventType;
$q->LanguageCode = $o->LanguageCode;
if (isset($o->PreferredStartDate) == true) {
$q->ActualStartDate = $o->PreferredStartDate;
} else {
$q->ActualStartDate = date('Y-m-d');
}
if (isset($o->PreferredEndDate) == true) {
$q->ActualEndDate = $o->PreferredEndDate;
} else {
$q->ActualEndDate = date('Y-m-d', strtotime('+6 month'));
}
$q->save();
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
return $r;
}
// --------------------------------------------------------------------------- //
// StopMonitoring
// --------------------------------------------------------------------------- //
function StopMonitoring($o)
{
$q = enregistrement('Monitors', $o->ProviderOrderId);
if ($q == false) {
throw new SoapFault('FunctionalError', functionalError(3021));
}
if (isset($o->PreferredEndDate) == true) {
$q->ActualEndDate = $o->PreferredEndDate;
} else {
$q->ActualEndDate = date('Y-m-d');
}
$q->save();
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
return $r;
}
// --------------------------------------------------------------------------- //
// UpdateMonitoringOptions
// --------------------------------------------------------------------------- //
function UpdateMonitoringOptions($o)
{
$q = enregistrement('Monitors', $o->ProviderOrderId);
if ($q == false) {
throw new SoapFault('FunctionalError', functionalError(3021));
}
if (isset($o->NewCategoryName) == true) {
$q->CategoryName = $o->NewCategoryName;
}
if (isset($o->NewEventType) == true) {
$q->EventType = $o->NewEventType;
}
if (isset($o->NewMonitoringVersion) == true) {
$q->MonitoringVersion = $o->NewMonitoringVersion;
}
if (isset($o->NewLanguageCode) == true) {
$q->LanguageCode = $o->NewLanguageCode;
}
if (isset($o->PreferredStartDate) == true) {
$q->ActualStartDate = $o->PreferredStartDate;
}
$q->save();
$r = new StdClass;
$r->version = VERSION;
$r->Order = orderResponse($o, $q);
return $r;
}
?>