<script language="javascript">
jQuery(document).ready(function($) { 
  jQuery('.wbdatepicker').datepicker($.datepicker.regional[ "fr-CH" ]); 
  jQuery('input').blur();
});
</script>
<?php
  echo "<big>Pièces non vendues</big><br>\n";
  switch($Etape)
  {
    case 0:
      echo "<form name='info'>\n";
      echo "<input type='hidden' name='Type' value=$Type>";
      echo "<input type='hidden' name='Sous_Type' value=$Sous_Type>";
      echo "<input type='hidden' name='Etape' value='1'>\n";
      echo "<TABLE border=1>";
      echo "<TR><TH>Date</TH><TD><input type='text' class='wbdatepicker' name='DateDebut' size='10'> au <input type='text' class='wbdatepicker' name='DateFin' size='10'></TD></TR>";
      echo "</TABLE>";
      echo "<input type='submit' value='Recherche'>\n";
      echo "</form>\n";
      unset($_SESSION['commande']);
    break;
    case 1:
      echo "<TABLE border=1>";
 	  echo "<TR><TH>No article</TH><TH>Description</TH><TH>Prix base</TH><TH>Quantité</TH><TH>Destinataire</TH><TH>No commande</TH><TH>Date commande</TH></TR>";
	  $DateDebutQuery = substr($DateDebut,6,4)."-".substr($DateDebut,3,2)."-".substr($DateDebut,0,2);
	  $DateFinQuery = substr($DateFin,6,4)."-".substr($DateFin,3,2)."-".substr($DateFin,0,2);
	  //echo $requette1."<br>\n";
	  $resultat1 = Commande::getCommandeByDateCommande($DateDebutQuery, $DateFinQuery);
	  foreach ($resultat1 as $ligne1)
	  {
		//echo $ligne1["NoArticle"]."<br>\n";
		$NoArticle = $ligne1["NoArticle"];
		$DateDebutQuery2 = date("Y-m-d", strtotime($ligne1["DateCommande"]."- 30 days")); 
		$DateFinQuery2 = date("Y-m-d", strtotime($ligne1["DateCommande"]."+ 60 days"));
	    $requette2 = "SELECT ca.NoArticle, c.NoCommande, c.DateCommande FROM `commande1` AS c, `commandearticles1` AS ca WHERE c.NoCommande = ca.NoCommande AND (c.Genre = 'F' OR c.Genre = 'G') AND c.DateCommande >= '$DateDebutQuery2' AND c.DateCommande < '$DateFinQuery2' AND ca.NoArticle = '$NoArticle'";
		//echo $requette2."<br>\n";
	    $resultat2 = Commande::getCommandeByDateCommandeAndNoArticle($DateDebutQuery2, $DateFinQuery2, $NoArticle);
	    if ($ligne2 = $resultat2[0])
	    {
			
		}
		else
		{
		  $link = "default.php?intervalle%5B0%5D=01.01.2000&intervalle%5B1%5D=31.12.2080&DOFD=1&DOBP=1&DOFB=1&DOFV=1&DOFO=1&DOFL=1&DOFI=1&DOCP=1&DOOP=1&DOOV=1&DODP=1&DOGF=1&DOGG=1&DORV=1&DOND=1&DONB=1&DONV=1&DONO=1&DONL=1&DOAM=1&DOVV=1&Type=1&Sous_Type=8&Etape=3&NoArticle=".urlencode($NoArticle);
		  echo "<TR><TD><a href=\"$link\" target=\"_blank\" rel='opener'>".$ligne1["NoArticle"]."</a></TD><TD>".$ligne1["Description"]."</TD><TD>".$ligne1["PrixBase"]."</TD><TD>".$ligne1["Quantite"]."</TD><TD>".$ligne1["Dest"]."</TD><TD>".$ligne1["NoCommande"]."</TD><TD>".$ligne1["DateCommande"]."</TD></TR>";
		}
	  }
      echo "</TABLE>";
      break;
  }  
?>