extranet/includes/giant/RapportGiant.php
2011-08-26 16:30:40 +00:00

89 lines
3.6 KiB
PHP

<?php
/**
* Controller pour les rapport
* Prépares les données pour le Template .
*/
require_once (realpath(dirname(__FILE__)).'/Config.php');
require_once (realpath(dirname(__FILE__)).'/Client.php');
require_once (realpath(dirname(__FILE__)).'/modulesGiants/Functions.php');
require_once ('dbbootstrap.php');
setDbConn('giantclient');
$OrderExists = Doctrine_Query::create()
->select('CompanyId, OrderDateTime, InternalOrderId')
->from('commandes')
->where('CompanyId = "'. $_GET['company'].'"')
->andWhere('User ="'.$_SESSION['tabInfo']['login'].'"')
->andWhere('DataSetType="'.$_GET['type'].'"')
->andWhere('TO_DAYS(NOW())')
->fetchOne();
$InternalOrderId = $OrderExists->InternalOrderId;
if (isset($OrderExists->CompanyId)) {
$DateHeure = explode(' ', $OrderExists->OrderDateTime);
$date = explode('-', $DateHeure[0]);
}
if (!isset($OrderExists->CompanyId))
{
/**
* Le SetLog
* @var unknown_type
*/
$soap_client = getClient($_GET['pays'], 'OrderDataSet', SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS);
$OrderDataSet = new CreditDataPortType();
$params = $OrderDataSet->OrderDataSet();
$params->OrderDataSet->CompanyId = $_GET['company'];
$params->OrderDataSet->DataSetType = new stdClass();
$params->OrderDataSet->DataSetType->_ = $_GET['type'];
$params->OrderDataSet->LanguageCode = $_GET['lang'];
$params->OrderDataSet->DataSetVersion = "1.0";
$informations = SwitchWSDLFunction('OrderDataSet', $params->OrderDataSet, $soap_client);
$request = new commandes();
$request->User = $_SESSION['tabInfo']['login'];
$request->ProviderOrderId = $informations->Order->ProviderOrderId;
$request->InternalOrderId = $informations->Order->InternalOrderId;
$request->CompanyName = $_GET['name'];
$request->ProviderId = $informations->Order->ProviderId;
$request->CountryCode = $informations->Order->CountryCode;
$request->CompanyId = $_GET['company'];
$request->DataSetType = $informations->Order->DataSetType->_;
$request->save();
$InternalOrderId = $informations->Order->InternalOrderId;
}
$rapportExists = Doctrine_Query::create()
->select('CompanyId, UrlObjectRapportFile, DateTimeSave')
->from('rapport')
->where('CompanyId = "'. $_GET['company'].'"')
->andWhere('DataSetType = "'. $_GET['type'].'"')
->fetchOne();
if (!isset($rapportExists->CompanyId) or (!file_exists(PATH_DATA.$rapportExists->UrlObjectRapportFile)))
{
$nameFileRapport = 'rapport-'.$_GET['company'].'-'.date('Ymd').'-'.$_GET['pays'].'-'.$_GET['type'];
$soap_client2 = getClient($_GET['pays'], 'RetrieveDataSet', SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS);
$RetrieveDataSet = new CreditDataPortType();
$params = $RetrieveDataSet->RetrieveDataSet();
$params->RetrieveDataSet->InternalOrderId = $InternalOrderId;
$rapport = SwitchWSDLFunction('RetrieveDataSet', $params->RetrieveDataSet, $soap_client2);
$directory = _ifDirectoryExist('/giant/'.$_GET['company'].'/');
$saveRapport = new rapport();
$saveRapport->CompanyId = $_GET['company'];
$saveRapport->DataSetType = $_GET['type'];
$saveRapport->UrlObjectRapportFile = $directory.$nameFileRapport;
(file_put_contents(PATH_DATA.$directory.$nameFileRapport, serialize($rapport->DataSet))) ?
$saveRapport->Delivred = true : $saveRapport->Delivred = EXIT_FAILURE;
$saveRapport->DateTimeSave = date('Y-m-d');
$saveRapport->save();
$rapport = $rapport->DataSet;
} else {
($rapport = unserialize(file_get_contents(PATH_DATA.$rapportExists->UrlObjectRapportFile))) ? true : EXIT_FAILURE;
}
?>