273 lines
7.7 KiB
PHP

<script language="javascript">
<!--
//exporter le rapport
function download(id, format) {
location.href = 'modules/graydon/export.php?id=' + id + '&format=' + format;
}
// exporter le tableau des commandes
function export_tableau(params) {
location.href = 'modules/graydon/export_tableau_xls.php?p=1' + params;
}
-->
</script>
<form name="tri" action="./index.php?q=graydon/commandes" method="post">
<input type="hidden" name="mode" value="search" />
<table border="0" width="50%" cellspacing="2" cellpadding="3">
<tr>
<td>
<select name="country">
<option value="">Tri par pays</option>
<?php echo affiche_pays();?>
</select>
</td>
<td>&nbsp;</td>
<td>Reference : <input type="text" name="reference" /></td>
</tr>
<tr>
<td>
<select name="servicespeed">
<option value="">Tri par type de commande</option>
<option value="immediate">Immediate</option>
<option value="normal">Normal</option>
<option value="Express">Rapide</option>
</select>
</td>
<td>&nbsp;</td>
<td>
<select name="status">
<option value="">Tri par état de la commande</option>
<option value="Completed">Completed</option>
<option value="Assigned">Assigned</option>
<option value="InError">InError</option>
<option value="Initialised">Initialised</option>
<option value="Delivered">Delivered</option>
<option value="Notified">Notified</option>
<option value="ReCompleted">ReCompleted</option>
<option value="SendError">SendError</option>
</select>
</td>
</tr>
<tr>
<td colspan="3">De <input type="text" name="dateFrom" />
à <input type="text" name="dateTo" /> (Format : AAAA-MM-JJ)
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" value="Rechercher" /></td>
</tr>
</table>
</form>
<table>
<tr>
<th>Date de la commande</th>
<th>Reference</th>
<th>Pays</th>
<th>Reference</th>
<th>Service commandé</th>
<th>Prix de la commande</th>
<th>Status de la commande</th>
<th>Date due</th>
<th>Actions</th>
</tr>
<?php
$mode = $_REQUEST['mode'];
switch ($mode) {
case "search" :
if (sizeof($_POST) > 0) {
$search = $_POST;
affiche_liste_commandes();
}
break;
default :
affiche_liste_commandes();
break;
}
/******************************************************************************
* FONCTIONS
*****************************************************************************/
/*
* Fonction affiche la liste des commandes
*/
function affiche_liste_commandes()
{
global $search;
require realpath(dirname(__FILE__)).'/mysql_inc.php';
$WHERE = "";
$params = "";
if(!empty($search['reference'])) {
$WHERE .= " AND cmd.reference = '".$search['reference']."'";
$_SESSION['params'] = "&reference=".$search['reference'];}
if(!empty($search['country'])) {
$WHERE .= " AND cmd.country_id = '".$search['country']."'";
$params .= "&country=".$search['country']; }
if(!empty($search['servicespeed'])) {
$WHERE .= " AND cmd.servicespeed = '".$search['servicespeed']."'";
$params .= "&servicespeed=".$search['servicespeed'];}
if(!empty($search['status'])) {
$WHERE .= " AND cmd.orderstate = '".$search['status']."'";
$params .= "&status=".$search['status'];}
if(!empty($search['dateFrom']) && !empty($search['dateTo'])) {
if (preg_match("#^([0-9]{4})(-[0-9]{2}){2}$#", $search['dateFrom']) &&
preg_match("#^([0-9]{4})(-[0-9]{2}){2}$#", $search['dateTo'])) {
$WHERE .= " AND cmd.dateordered BETWEEN '".$search['dateFrom']."' AND '".$search['dateTo']."'";
$params .= "&dateFrom=".$search['dateFrom'];
$params .= "&dateTo=".$search['dateTo'];
}
}
$result_commande = mysql_query("
SELECT cmd.*
, cntr.graydon_country
, cmdd.*
, rpt.id as id_rapport, rpt.content, rpt.format, rpt.order_id
FROM commandes cmd
LEFT JOIN country cntr
ON cntr.id = cmd.country_id
LEFT JOIN commandes_detail cmdd
ON cmdd.commandes_id = cmd.id
LEFT JOIN report rpt
ON rpt.order_id = cmd.id
WHERE 1 $WHERE
ORDER by dateordered
");
if(mysql_num_rows($result_commande) == 0) {
echo "<tr><td colspan=\"8\"><p>Aucune commande n'est enregistrée.</p></td></tr>";
}
while($commande = mysql_fetch_object($result_commande))
{
?>
<script type="text/javascript">
$(document).ready(function(){
$("a.detailsBtn<?=$commande->id;?>").click(function () {
$("a.detailsBtn<?=$commande->id;?>").toggle();
$("a.closeBtn<?=$commande->id;?>").toggle();
$("div#advanceBtn<?=$commande->id;?>").slideToggle("slow");
});
$("a.closeBtn<?=$commande->id;?>").click(function () {
$("a.detailsBtn<?=$commande->id;?>").toggle();
$("a.closeBtn<?=$commande->id;?>").toggle();
$("div#advanceBtn<?=$commande->id;?>").slideToggle("slow");
});
});
</script>
<style type="text/css">
.detailsBtn<?=$commande->id;?> {
margin-left: 10px;
}
.closeBtn<?=$commande->id;?> {
margin-left: 10px;
display:none;
}
#advanceBtn<?=$commande->id;?> {
display:none;
width:350px;
}
</style>
<tr>
<td><?=$commande->dateordered;?></td>
<td><?=$commande->reference;?></td>
<td><?=$commande->graydon_country;?></td>
<td><?=$commande->reference;?></td>
<td><?=$commande->servicespeed;?></td>
<td><?=$commande->prix;?></td>
<td><?=$commande->orderstate;?></td>
<td><?=$commande->datedue;?></td>
<td>
<?php
if(is_null($commande->commandes_id)) {
echo "&nbsp;&nbsp;<font color=\"gray\">Afficher Détails</font>";
}
else {
?>
<a href="Javascript:;" class="detailsBtn<?=$commande->id;?>">Afficher Détails</a>
<a href="Javascript:;" class="closeBtn<?=$commande->id;?>">Masquer Détails</a>
<?php } ?>
| <?php
if(is_null($commande->order_id)) {
echo "<font color=\"gray\">Rapport</font>";
}
else {
?>
<a href="Javascript:;" onclick="download('<?=$commande->id_rapport?>', '<?=$commande->format?>');">Rapport</a>
<?php } ?>
</td>
</tr>
<tr>
<td colspan="6">&nbsp;</td>
<td colspan="3">
<div id="advanceBtn<?=$commande->id;?>">
<?php
echo "<b>dIdentite :</b> ".$commande->dIdentite."<br />";
echo "<b>dTelephone :</b> ".$commande->dTelephone."<br />";
echo "<b>dEmail :</b> ".$commande->dEmail."<br />";
echo "<b>dFax :</b> ".$commande->dFax."<br />";
echo "<b>eLanguageCode :</b> ".$commande->eLanguageCode."<br />";
echo "<b>eName :</b> ".$commande->eName;
echo "<b>eIdentifiers :</b> ".$commande->eIdentifiers."<br />";
echo "<b>eAdresse :</b> ".$commande->eAdresse."<br />";
echo "<b>eTelephone :</b> ".$commande->eTelephone."<br />";
echo "<b>eCreditOpinionCurrency :</b> ".$commande->eCreditOpinionCurrency."<br />";
echo "<b>eCreditOpinionPeriod :</b> ".$commande->eCreditOpinionPeriod."<br />";
echo "<b>eBankers :</b> ".$commande->eBankers."<br />";
echo "<b>eAttentionOf :</b> ".$commande->eAttentionOf."<br />";
echo "<b>eSpecialRemarks :</b> ".$commande->eSpecialRemarks."<br />";
echo "<b>commandes_id :</b> ".$commande->commandes_id."<br />";
echo "<b>CreditOpinionPeriod :</b> ".$commande->eCreditOpinionPeriod."<br />";
echo "<b>Date de commande :</b> ".$commande->created_at;
?>
</div></td>
</tr>
<?php
} // Fin de la boucle
?>
<thead>
<tr>
<td colspan="6"><a href="Javascript:;" onclick="export_tableau('<?=$params;?>');" style="color:green;">Exporter le tableau<img src="http://<?=$_SERVER['HTTP_HOST'];?>/img/icones/xls.jpeg" width="20" border="0" align="absmiddle" /></a></td>
</tr>
</thead>
<?
mysql_free_result($result_commande);
mysql_close($connexion);
}
/*
* Fonction affiche la liste des pays qui ont un status actif
*/
function affiche_pays() {
require realpath(dirname(__FILE__)).'/mysql_inc.php';
$result_pays = mysql_query("SELECT id, graydon_country FROM country WHERE status = 'actif'");
while($pays = mysql_fetch_array($result_pays, MYSQL_ASSOC)) {
echo "<option value=\"".$pays['id']."\">".$pays['graydon_country']."</option>";
}
mysql_free_result($result_pays);
mysql_close($connexion);
}
?>
</table>