<?php
  switch($Etape)
  {
    case 0:
      $requette = "SELECT commande".ID_GARAGE.".*, vehicules.MarqueModel, vehicules.Model FROM commande".ID_GARAGE.", vehicules WHERE commande".ID_GARAGE.".Type = 'RV' AND commande".ID_GARAGE.".NoCommandeAssocie = 0 AND commande".ID_GARAGE.".Vehicule != '' AND commande".ID_GARAGE.".NoCommande > 100000 AND commande".ID_GARAGE.".Vehicule = vehicules.NoChasis ORDER BY NoCommande";
      $resultat = mysql_query($requette);
      echo "<TABLE><TR><TH>No Reprise</TH><TH>Date reprise</TH><TH>Vehicule</TH><TH>Marque</TH><TH>Model</TH></TR>\n";
      foreach($resultat as $ligne)
      {
        echo "<TR><TD>".$ligne["NoCommande"]."</TD><TD>".$ligne["DateCommande"]."</TD><TD>".$ligne["Vehicule"]."</TD><TD>".$ligne["MarqueModel"]."</TD><TD>".$ligne["Model"]."</TD></TR>\n";
      }
      echo "</TABLE>\n";
      $requette = "SELECT commande".ID_GARAGE.".*, vehicules.MarqueModel, vehicules.Model FROM commande".ID_GARAGE.", vehicules WHERE commande".ID_GARAGE.".Type = 'FO' AND commande".ID_GARAGE.".NoCommandeAssocie = 0 AND commande".ID_GARAGE.".Vehicule != '' AND commande".ID_GARAGE.".NoCommande > 100000 AND commande".ID_GARAGE.".Vehicule = vehicules.NoChasis ORDER BY NoCommande";
      $resultat = mysql_query($requette);
      echo "<TABLE><TR><TH>No Facture occass</TH><TH>Date facture</TH><TH>Vehicule</TH><TH>Marque</TH><TH>Model</TH></TR>\n";
      foreach($resultat as $ligne)
      {
        echo "<TR><TD>".$ligne["NoCommande"]."</TD><TD>".$ligne["DateCommande"]."</TD><TD>".$ligne["Vehicule"]."</TD><TD>".$ligne["MarqueModel"]."</TD><TD>".$ligne["Model"]."</TD></TR>\n";
      }
      echo "</TABLE>\n";
/*      echo "<form name='formtvadesmarges' method='post'>\n";
      echo "<TABLE border=1><TR><TH>Date</TH><TD>".Cree_Entree_Type("intervalle",2,0,"",RECHERCHE)."</TD></TR></TABLE>";
      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'>";
      echo "<input type='submit' value='valider'>";
      echo "</form>\n";*/
    break;
    case 1:
      if($intervalle[5]!=0)
      {
        $tmp_int[0]=$intervalle[3];
        $tmp_int[1]=$intervalle[4];
        $tmp_int[2]=$intervalle[5];
        $requette="SELECT * FROM commande".ID_GARAGE." WHERE ".Requette_Recherche("DateCommande",18,$intervalle)." AND Genre = 'R' ORDER BY DateCommande";
        $resultat=Connection::executeRawQueryWithfetchAll($requette);
        echo "<TABLE border=1>\n";
        echo "<TR><TH>No Châssis</TH><TH>Marque-Model</TH><TH>No facture vente</TH><TH>Acheteur</TH><TH>Date achat</TH><TH>Montant achat</TH><TH>No bon reprise</TH><TH>Vendeur</TH><TH>date reprise</TH><TH>Montant reprise</TH><TH>Marge</TH></TR>\n";
/*        foreach($resultat as $ligne)
        {
          $requette2="SELECT * FROM commande".ID_GARAGE." WHERE Vehicule = '".$ligne["Vehicule"]."' AND Type='FO'";
          $resultat2=mysql_query($requette2);
        }*/
        echo "</TABLE>\n";
      }
    break;
  }
?>
