extranet/www/pages/international_commandes.php

267 lines
9.2 KiB
PHP

<?php
// --------------------------------------------------------------------------- //
// international_commandes.php
// --------------------------------------------------------------------------- //
if (isset($_POST['action']) == true) {
$action = $_POST['action'];
$commande_id = $_POST['commande_id'];
} else {
$action = '';
}
if (isset($_REQUEST['etat_enq']) == false) {
$etat_enq = 'Delivered';
} else {
$etat_enq = $_REQUEST['etat_enq'];
}
require_once 'dbbootstrap.php';
setDbConn('graydon');
// --------------------------------------------------------------------------- //
// Affichage du document
// --------------------------------------------------------------------------- //
if ($action == 'xml' ||
$action == 'pdf' ||
$action == 'doc') {
switch ($action) {
case 'xml': header('Content-type: text/xml'); break;
case 'pdf': header('Content-type: application/pdf'); break;
case 'doc': header('Content-type: application/msword'); break;
}
$nom = Doctrine_Query::create()
->from('CommandesDetail')
->where('commandes_id = ?', $commande_id)
->fetchOne()->eName.'.'.$action;
header('Content-Disposition: attachment; filename="'.$nom.'"');
$report = Doctrine_Query::create()
->from('Report')
->where('order_id = ? and format = ?', array($commande_id, $action))
->fetchOne();
print $report->content;
exit;
}
?>
<div id="center" style="width:625px">
<h1>Commandes Internationales</h1>
<?php
// --------------------------------------------------------------------------- //
// Affichage du document HTML
// --------------------------------------------------------------------------- //
if ($action == 'html') {
$rapport = Doctrine_Query::create()
->from('Report')
->where('order_id = ? and format = "html"', $commande_id)
->fetchOne();
print $rapport->content;
exit;
}
// --------------------------------------------------------------------------- //
// Suppression
// --------------------------------------------------------------------------- //
if ($action == 'Supprimer') {
Doctrine_Query::create()
->update('Commandes')
->set('orderstate', '?', 'Unlinked')
->where('id = ?', $commande_id)
->execute();
}
$etatsEnq = array('Toutes' => 'Toutes',
'Initialised' => 'Initialis&eacute;es',
'Assigned' => 'Assign&eacute;es',
'Completed' => 'Complet&eacute;es',
'Delivered' => 'D&eacute;livr&eacute;es',
'NonD' => 'Non d&eacute;livr&eacute;es');
// --------------------------------------------------------------------------- //
// Mise à jour
// --------------------------------------------------------------------------- //
if (isset($_GET['maj'])) {
require_once 'graydon/graydon.php';
$commande = Doctrine_Query::create()
->from('Commandes')
->where('id = ?', $_GET['maj'])
->fetchOne();
$requete = new StdClass();
$requete->Authentication_Parameters = $authentication;
$requete->OrderReference = $commande->reference;
try {
$checkOrderResult = $graydon->checkOrders($requete);
} catch (SoapFault $e) {
print 'erreur soap</div>';
exit;
}
$orderstate =
$checkOrderResult->CheckOrders->OrderStatus[0]->OrderState;
if ($orderstate != $commande->orderstate) {
Doctrine_Query::create()
->update('Commandes')
->set('orderstate', '?', $orderstate)
->where('id = ?', $commande->id)
->execute();
}
if (isset($checkOrderResult->CheckOrders->OrderStatus[0]->DateDue)) {
$datedue =
$checkOrderResult->CheckOrders->OrderStatus[0]->DateDue;
if ($datedue != $commande->datedue) {
Doctrine_Query::create()
->update('Commandes')
->set('datedue', '?', $datedue)
->where('id = ?', $commande->id)
->execute();
}
}
}
// --------------------------------------------------------------------------- //
// Choix de l'etat des commandes a afficher
// --------------------------------------------------------------------------- //
if (isset($_GET['id']) == false) {
print '<form method="post" action="?page=international_commandes">';
print '<label>&nbsp;&nbsp;&nbsp;&nbsp;Enqu&ecirc;tes:</label>';
print '<select name="etat_enq" onchange="this.form.submit();">';
foreach ($etatsEnq as $index => $valeur) {
print '<option value="'.$index.'"';
if ($etat_enq == $index) {
print ' selected';
}
print '>'.$etatsEnq[$index].'</option>';
}
print '</select>';
print '</form>';
print '<br/>';
}
// --------------------------------------------------------------------------- //
// tableDebut
// --------------------------------------------------------------------------- //
function tableDebut() {
print '<table>';
}
// --------------------------------------------------------------------------- //
// tableLigne
// --------------------------------------------------------------------------- //
function tableLigne($c1, $c2) {
print '<tr><td>'.$c1.'</td><td>'.$c2.'</td></tr>';
}
// --------------------------------------------------------------------------- //
// tableFin
// --------------------------------------------------------------------------- //
function tableFin() {
print '</table>';
}
// --------------------------------------------------------------------------- //
// boutonPost
// --------------------------------------------------------------------------- //
function boutonPost($action, $nom, $valeur, $etat_enq) {
if ($action == 'html') {
$extra = 'target="_blank" ';
} else {
$extra = '';
}
print '<form method="post" action="./?page=international_commandes&ajax=true" '.
$extra.'style="float:left">'.
'<input type="hidden" name="action" value="'.$action.'" />'.
'<input type="hidden" name="'.$nom.'" value="'.$valeur.'" />'.
'<input type="hidden" name="etat_enq" value="'.$etat_enq.'" />'.
'<input type="submit" value="'.
((ctype_lower($action)) ? strtoupper($action) : $action).'" />'.
'</form>';
}
// --------------------------------------------------------------------------- //
// Affichage des commandes
// --------------------------------------------------------------------------- //
if (isset($_GET['id']) == true) {
$tabCommandes = Doctrine_Query::create()
->from('Commandes')
->where('user = ?', $_SESSION['tabInfo']['login'])
->andWhere('id = ?', $_GET['id'])
->execute();
} else {
$tabCommandes = Doctrine_Query::create()
->from('Commandes')
->where('user = ?', $_SESSION['tabInfo']['login'])
->orderby('id')
->execute();
}
foreach ($tabCommandes as $commande) {
if (($etat_enq != 'Toutes' &&
$etat_enq != 'NonD' &&
$etat_enq != $commande->orderstate) ||
($etat_enq == 'NonD' &&
$commande->orderstate == 'Delivered') ||
$commande->orderstate == 'Unlinked') {
continue;
}
if ($commande->orderstate == 'Completed' ||
$commande->orderstate == 'CompletedwithUpdate' ||
$commande->orderstate == 'ReCompleted' ||
$commande->orderstate == 'Delivered') {
$delivree = true;
} else {
$delivree = false;
}
$detail = Doctrine_Query::create()
->from('CommandesDetail')
->where('commandes_id = ?', $commande->id)
->fetchOne();
print '<table border="1" cellspacing="0"'.
' style="margin:10px;background-color:#E7EFF8">'.
'<td width="390px" valign="top">';
if ($delivree == true) {
print '<font color="#000000"><b>';
}
print $detail->eName;
if ($delivree == true) {
print '</b></font>';
}
print '<br/>Type d\'enqu&ecirc;te: '.$commande->servicespeed.'<br/>'.
'&Eacute;tat: ';
if ($delivree == true) {
print '<font color="#31659C"><b>';
}
print substr($etatsEnq[$commande->orderstate], 0, -1);
if ($delivree == true) {
print '</b></font><br/>';
$reports = Doctrine_Query::create()
->from('Report')
->where('order_id = ?', $commande->id)
->orderby('id')
->execute();
foreach ($reports as $report) {
boutonPost($report->format, 'commande_id', $commande->id, $etat_enq);
}
if (count($reports) > 0) {
boutonPost('Supprimer', 'commande_id', $commande->id, $etat_enq);
} else {
$delivree = false;
}
}
print '</td><td valign="top">';
tableDebut();
tableLigne('Date de commande:', $commande->dateordered);
if ($commande->datedue == '0000-00-00' &&
$commande->servicespeed != 'Immediate') {
$datedue = '<a href="?page=international_commandes&maj='.
$commande->id.'&etat_enq='.$etat_enq.'">M&agrave;J</a>';
} else {
$datedue = $commande->datedue;
}
tableLigne('Date de r&eacute;ception pr&eacute;vue:', $datedue);
if ($delivree == true) {
tableLigne('Date de mise &agrave; jour:', $commande->datecompleted);
}
tableFin();
print '</td></table>';
}
?>
</div>