Changement structure bdd

This commit is contained in:
Michael RICOIS 2009-05-12 16:57:43 +00:00
parent 4242d561b2
commit dfa2bbc33c
8 changed files with 200 additions and 138 deletions

View File

@ -8,6 +8,7 @@
* @property integer $id
* @property string $reference
* @property enum $servicespeed
* @property string $prix
* @property enum $orderstate
* @property date $dateordered
* @property date $datecompleted
@ -16,6 +17,7 @@
* @property string $sessionid
* @property string $transactionidentifier
* @property string $user
* @property string $mode
* @property timestamp $created_at
* @property timestamp $updated_at
* @property integer $country_id
@ -33,6 +35,7 @@ abstract class BaseCommandes extends Doctrine_Record
$this->hasColumn('id', 'integer', 4, array('type' => 'integer', 'length' => 4, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('reference', 'string', 100, array('type' => 'string', 'length' => 100, 'notnull' => true));
$this->hasColumn('servicespeed', 'enum', 19, array('type' => 'enum', 'length' => 19, 'values' => array(0 => 'Normal', 1 => 'Express', 2 => 'Superflash', 3 => 'Immediate', 4 => 'ImmediateWithUpdate', 5 => 'Unknown', 6 => 'Delayed'), 'notnull' => true));
$this->hasColumn('prix', 'string', 100, array('type' => 'string', 'length' => 100, 'notnull' => true));
$this->hasColumn('orderstate', 'enum', 11, array('type' => 'enum', 'length' => 11, 'values' => array(0 => 'Completed', 1 => 'Assigned', 2 => 'InError', 3 => 'Initialised', 4 => 'Delivered', 5 => 'Notified', 6 => 'ReCompleted'), 'notnull' => true));
$this->hasColumn('dateordered', 'date', null, array('type' => 'date', 'notnull' => true));
$this->hasColumn('datecompleted', 'date', null, array('type' => 'date', 'notnull' => true));
@ -46,4 +49,5 @@ abstract class BaseCommandes extends Doctrine_Record
$this->hasColumn('updated_at', 'timestamp', null, array('type' => 'timestamp', 'default' => '0000-00-00 00:00:00', 'notnull' => true));
$this->hasColumn('country_id', 'integer', 4, array('type' => 'integer', 'length' => 4, 'notnull' => true));
}
}

View File

@ -1,6 +1,5 @@
<?php
require_once 'dbbootstrap.php';
require_once 'dbgraydon.php';
require_once 'includes/path.php';
//On vérifie l'identité de la personne authentifier sur l'extranet

View File

@ -1,7 +1,6 @@
<?php
require_once 'dbgraydon.php';
$view = arg(1,$_REQUEST['q']);
switch($view){
case 'pays':
require_once realpath(dirname(__FILE__)).'/pays.php';

View File

@ -1,18 +1,17 @@
<?php
$q = Doctrine_Query::create()
->select('*')
->from('Country')
->where('status="actif"');
$result = $q->execute();
$tabPays = $result->toArray();
$results = $q->execute();
$tabPays = $results->toArray();
$q = Doctrine_Query::create()
->from('Commandes c')
->leftJoin('c.Country p, c.CommandesDetail cd')
->orderBy('c.dateordered');
$tabCommandes = $q->Execute();
$tabCommandes = $q->execute();
?>
<form>
@ -22,7 +21,7 @@ $tabCommandes = $q->Execute();
<?php
foreach($tabPays as $pays){
?>
<option value="<?php print $pays['country']; ?>"><?php print $pays['country']; ?></option>
<option value="<?php print $pays['graydon_country']; ?>"><?php print $pays['graydon_country']; ?></option>
<?php
}
?>
@ -54,6 +53,7 @@ De <input type="text" name="dateFrom" />
<th>Pays</th>
<th>Reference</th>
<th>Service commandé</th>
<th>Prix à la commande</th>
<th>Status de la commande</th>
<th>Date de la commande</th>
<th>Date due</th>
@ -63,9 +63,10 @@ De <input type="text" name="dateFrom" />
foreach($tabCommandes as $commande){
?>
<tr>
<td><?php print $commande->Country->country; ?></td>
<td><?php print $commande->Country->graydon_country; ?></td>
<td><?php print $commande->reference; ?></td>
<td><?php print $commande->servicespeed; ?></td>
<td><?php print $commande->prix; ?></td>
<td><?php print $commande->orderstate; ?></td>
<td><?php print $commande->dateordered; ?></td>
<td><?php print $commande->datedue; ?></td>

View File

@ -12,6 +12,9 @@ if($_REQUEST['submit']){
print_r($_REQUEST['InfoUser']);
print_r($_REQUEST['InfoEnq']);
print '</pre>';
//Envoi d'un mail pour informé de la commande
}else{
@ -81,7 +84,6 @@ div.submit p.required-note span{color:#4B911C;_color:#666;font-size:170%;vertica
<div class="field"><input type="text" name="InfoEnq[Name]"/></div>
</div>
<?php
/** Recherche des identifiants et mise en cache **/
$q = Doctrine_Query::create()
@ -97,6 +99,7 @@ if($nbResult == 0){
//matchidentifiers
$request = new StdClass();
$request->Authentication_Parameters = $authentication;
$request->Country = $pays;
try
{
$result = $graydon->getCompanyMatchIdentifiers($request);
@ -127,29 +130,44 @@ if($nbResult == 0){
$matchidentifiers->country = $item->Country;
$matchidentifiers->identifiers = serialize($tabIdentifiers);
$matchidentifiers->replace();
$identifiers = $tabIdentifiers;
}
}catch( SoapFault $fault ){
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
$firephp->log($text,'texterror');
require_once 'graydon/graydon_error.php';
if(graydon_error($code, $text)==FALSE){
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
}else{
$identifiers = unserialize($matchidentifiers->identifiers);
}
//Affichage des identifiants
//Ne pas afficher l'identifiant Internal
if(isset($identifiers)){
$firephp->log($identifiers,'identifiers');
$count = 0;
foreach($identifiers as $identifier){
if($identifier->Type != 'Internal'){
?>
<div class="fieldgrp">
<input type="hidden" name="method" value="identifier" />
<label><?php print $identifier->Description ?></label>
<input type="text" name="InfoEnq[Identifier][<?php print $identifier->Type ?>]" value="" />
</div>
<?php
}
}
}else{
?>
<div class="fieldgrp">
<label>&nbsp;</label>
<div class="field">Pas d'indentifiant.</div>
</div>
<?php
}
?>

View File

@ -337,12 +337,11 @@ if(isset($company)){
if ($identifierDescription==FALSE){
print $identifier->Type;
}
//@TODO : Tester si la condition à bien été remplie
?>
</td>
<td width="350" class="StyleInfoData">
<?php print $identifier->Identifier; ?></td>
<?php print "1".$identifier->Identifier; ?></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
@ -362,7 +361,7 @@ if(isset($company)){
<td width="200" class="StyleInfoLib">Raison Sociale</td>
<td width="350" class="StyleInfoData">
<?php
$_SESSION['graydon']['name'] = $company->name;
$_SESSION['graydon']['name'] = $company->Name;
print cleanutf8($company->Name);
?>
</td>

View File

@ -25,144 +25,93 @@ function dVal($value){
?>
<div id="center">
<?php
//Vérification si le rapport en ligne à déjà été demandé
$q = Doctrine_Query::create()
->from('Commandes')
->where('companyproductidentifier = ?', $CompanyProductIdentifier);
$commandes = new Commandes();
$commandes = $q->fetchOne();
$nbReport = $q->count();
$report = new Report();
$report = $commandes->Report;
$path = PATH_DATA.'/graydon';
$fileName = strtolower(str_replace( array(':',' '), '-', $identifier).'.xml');
//Vérifier si le rapport n'est pas disponible en base depuis une autre commandes
$q = Doctrine_Query::create()
->from('Report')
->where('identifier = ?', $_REQUEST['identifier']);
$nbReports = $q->count();
$report = new Report();
$report = $q->fetchOne();
if($nbReport==0){
/*
placeOrder
CompanyProductIdentifier
Language
CreditOpinionCurrency
Country
//@TODO : si le rapport existe déjà ou que la date n'est pas très éloigné
if($nbReports==0){
getCompanyReport
OrderReference
MimeType
*/
//placeOrder
$request = new StdClass();
$request->Authentication_Parameters = $authentication;
$request->OrderCreatorEmail = 'mricois@scores-decisions.com';
$request->CompanyProductIdentifier = $CompanyProductIdentifier;
$request->PartnerData = '';
try
{
$placeOrderResult = $graydon->placeOrder($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $placeOrderResult->Service_Log->TransactionIdentifier;
$sessionID = $placeOrderResult->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'placeOrder', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'placeOrder';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = $mode;
$log->save();
//Enregistrement des commandes dans la bdd
$commandes = new Commandes();
$commandes->reference = $placeOrderResult->OrderStatus->OrderReference;
$commandes->orderstate = $placeOrderResult->OrderStatus->OrderState;
$commandes->dateordered = $placeOrderResult->OrderStatus->DateOrdered;
$commandes->datecompleted = $placeOrderResult->OrderStatus->DateCompleted;
$commandes->datedue = $placeOrderResult->OrderStatus->DateDue;
$commandes->servicespeed = $placeOrderResult->OrderStatus->Order->ServiceSpeed;
$commandes->companyproductidentifier = $CompanyProductIdentifier;
$commandes->sessionid = $sessionID;
$commandes->transactionidentifier = $transactionIdentifier;
$commandes->user = $tabInfo['login'];
$commandes->mode = $_SESSION['graydon']['mode'];
$country = Doctrine_Query::create()
->from('Country')
->where('country = ?', $pays)
->fetchOne();
$commandes->Country = $country;
$commandes->save();
$firephp->log($commandes->toArray(),'dataCommandes');
$commandes_id = $commandes->id;
//Pas d'enregistrement des détails de la commande car elle est immédiate
//$firephp->log($placeOrderResult,'placeOrder');
}catch( SoapFault $fault ){
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
$firephp->log($text,'texterror');
require_once 'graydon/graydon_error.php';
if(graydon_error($code, $text)==FALSE){
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
//On vérifie l'état de le demande
if (isset($placeOrderResult) && $placeOrderResult->OrderStatus->OrderState == 'Completed'){
//getCompanyReport
//Vérifier si le rapport en ligne à déjà été demandé
$q = Doctrine_Query::create()
->from('Commandes')
->where('companyproductidentifier = ?', $CompanyProductIdentifier);
$commandes = new Commandes();
$commandes = $q->fetchOne();
$nbCommandes = $q->count();
$report = new Report();
$report = $commandes->Report;
if($nbCommandes == 0 && !isset($report->id)){
//placeOrder
$request = new StdClass();
$request->Authentication_Parameters = $authentication;
$request->LanguageCode = 'E'; //Spécifier la langue du rapport
$request->OrderReference = $placeOrderResult->OrderStatus->OrderReference;
$request->MimeType = 'xml';
$firephp->log($request,'requete');
$request->OrderCreatorEmail = 'mricois@scores-decisions.com';
$request->CompanyProductIdentifier = $CompanyProductIdentifier;
$request->PartnerData = '';
try
{
$reportResult = $graydon->getCompanyReport($request);
$placeOrderResult = $graydon->placeOrder($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $reportResult->Service_Log->TransactionIdentifier;
$sessionID = $reportResult->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyReport', $transactionIdentifier, $sessionID);
$transactionIdentifier = $placeOrderResult->Service_Log->TransactionIdentifier;
$sessionID = $placeOrderResult->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'placeOrder', $transactionIdentifier, $sessionID);
//Enregistrement dans la bdd
//Log de la requete dans la bdd
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyReport';
$log->action = 'placeOrder';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = $mode;
$log->save();
$firephp->log($reportResult,'reportResult');
$xml = $reportResult->ReportXML->any;
//Optention du prix du service
$prix = Doctrine_Query::create($conn)
->select('p.immediate')
->from('Price p')
->leftJoin('p.Country c')
->where('c.graydon_country = ?', $pays)
->fetchOne();
//Enregistrement du fichier xml
file_put_contents($path.'/'.$fileName, $xml);
//Enregistrement des commandes dans la bdd
$commandes = new Commandes();
$commandes->reference = $placeOrderResult->OrderStatus->OrderReference;
$commandes->servicespeed = $placeOrderResult->OrderStatus->Order->ServiceSpeed;
$commandes->prix = $prix->immediate;
$commandes->orderstate = $placeOrderResult->OrderStatus->OrderState;
$commandes->dateordered = $placeOrderResult->OrderStatus->DateOrdered;
$commandes->datecompleted = $placeOrderResult->OrderStatus->DateCompleted;
$commandes->datedue = $placeOrderResult->OrderStatus->DateDue;
$commandes->companyproductidentifier = $CompanyProductIdentifier;
$commandes->sessionid = $sessionID;
$commandes->transactionidentifier = $transactionIdentifier;
$commandes->user = $tabInfo['login'];
$commandes->mode = $_SESSION['graydon']['mode'];
//Mise en cache dans la bdd
$report = new Report();
$report->identifier = $identifier;
$report->name= $_SESSION['graydon']['name'];
$report->content = $xml;
$report->format = 'xml';
$report->order_id = $commandes_id;
$report->save();
$country = Doctrine_Query::create()
->from('Country')
->where('graydon_country = ?', $pays)
->fetchOne();
$commandes->Country = $country;
$commandes->save();
$firephp->log($commandes->toArray(),'dataCommandes');
$commandes_id = $commandes->id;
//Pas d'enregistrement des détails de la commande car elle est immédiate
//$firephp->log($placeOrderResult,'placeOrder');
}catch( SoapFault $fault ){
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
@ -172,10 +121,99 @@ if($nbReport==0){
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
}
}else{
if($nbReport>0){
//On vérifie l'état de le demande
if (isset($placeOrderResult) && $placeOrderResult->OrderStatus->OrderState == 'Completed'){
//getCompanyReport
$request = new StdClass();
$request->Authentication_Parameters = $authentication;
$request->LanguageCode = 'E'; //Spécifier la langue du rapport
$request->OrderReference = $placeOrderResult->OrderStatus->OrderReference;
$request->MimeType = 'xml';
$firephp->log($request,'requete');
try
{
$reportResult = $graydon->getCompanyReport($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $reportResult->Service_Log->TransactionIdentifier;
$sessionID = $reportResult->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyReport', $transactionIdentifier, $sessionID);
//Enregistrement dans la bdd
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyReport';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = $mode;
$log->save();
$firephp->log($reportResult,'reportResult');
$xml = $reportResult->ReportXML->any;
//Enregistrement du fichier xml
file_put_contents($path.'/'.$fileName, $xml);
//Mise en cache dans la bdd
$report = new Report();
$report->identifier = $identifier;
$report->name = $_SESSION['graydon']['name'];
$report->content = $xml;
$report->format = 'xml';
$report->order_id = $commandes_id;
$report->save();
}catch( SoapFault $fault ){
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
$firephp->log($text,'texterror');
require_once 'graydon/graydon_error.php';
if(graydon_error($code, $text)==FALSE){
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
}
//La commande à déjà été demandé
}else{
//Assignation du contenu
$xml = $report->content;
}
//Le rapport est disponible
}else{
if($nbReports>0){
/*
//Enregistrement du fausse commandes dans la bdd
$commandes = new Commandes();
$commandes->reference = $placeOrderResult->OrderStatus->OrderReference;
$commandes->servicespeed = $placeOrderResult->OrderStatus->Order->ServiceSpeed;
$commandes->prix = $prix->immediate;
$commandes->orderstate = $placeOrderResult->OrderStatus->OrderState;
$commandes->dateordered = $placeOrderResult->OrderStatus->DateOrdered;
$commandes->datecompleted = $placeOrderResult->OrderStatus->DateCompleted;
$commandes->datedue = $placeOrderResult->OrderStatus->DateDue;
$commandes->companyproductidentifier = $CompanyProductIdentifier;
$commandes->sessionid = $sessionID;
$commandes->transactionidentifier = $transactionIdentifier;
$commandes->user = $tabInfo['login'];
$commandes->mode = $_SESSION['graydon']['mode'];
$country = Doctrine_Query::create()
->from('Country')
->where('graydon_country = ?', $pays)
->fetchOne();
$commandes->Country = $country;
$commandes->save();
$firephp->log($commandes->toArray(),'dataCommandes');
$commandes_id = $commandes->id;
*/
//Assignation du contenu
$xml = $report->content;
}else{
$firephp->log('Data depuis fichier XML');
$xml = file_get_contents($path.'/'.$fileName);

View File

@ -16,9 +16,13 @@ if($mode=='normal'){
<select id="pays" name="frmRecherche[Country]" size="10">
<?php
//lecture des pays dans la bdd
$stmt = $conn->prepare('SELECT * FROM country WHERE status="actif" ORDER BY lib ASC');
$stmt->execute();
$tabPays = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
$q = Doctrine_Query::Create()
->from('Country')
->where('status = "actif"')
->orderBy('lib ASC');
$tabPays = $q->execute();
foreach($tabPays as $kPays ){
$selected = '';
if( isset($pays) && $pays==$kPays ){ $selected = ' selected'; }