<?php
  CheckAlertCommande($NoCommande);
  if(isset($Move))
  {
    switch($Move)
    {
      case "UP":
        $resultat=Connection::executeRawQueryWithfetchAll($_SESSION["memres4"]);
        $up=$NoCommande;
        foreach($resultat as $ligne)
        {
          if($NoCommande==$ligne['NoCommande'])
          {
            break;
          }
          else
          {
             $up=$ligne['NoCommande'];
          }
        }
        $NoCommande=$up;
      break;
      case "DOWN":
        $resultat=Connection::executeRawQueryWithfetchAll($_SESSION["memres4"]);
        $down=$NoCommande;
        for ($i=0; $i < count($resultat); $i++)
        {
          $ligne =$resultat[$i];
          $down=$ligne['NoCommande'];
          if($NoCommande==$ligne['NoCommande'])
          {
            if($ligne=$resultat[$i+1])
            {
                $down=$ligne['NoCommande'];
            }
            break;
          }
        }
        $NoCommande=$down;
      break;
    }
  }
  $ligne=Commande::getCommandeByNoCommande($NoCommande);
  switch($ligne['Type'])
  {
    case "FD":
      Valide_Encaissement($NoCommande,0);
      entete_commande("FD","Facture detaillée");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande);
    break;
    case "BP":
      entete_commande("BP","Bulletin de livraison");
    break;
    case "FB":
      Valide_Encaissement($NoCommande,0);
      entete_commande("FB","Facture bulletin de livraison");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande);
    break;
    case "FV":
      Valide_Encaissement($NoCommande,0);
      entete_commande("FV","Facture vehicule neuf");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande);
    break;
    case "FO":
      Valide_Encaissement($NoCommande,0);
      entete_commande("FO","Facture vehicule occasion");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande);
    break;
    case "FL":
      Valide_Encaissement($NoCommande,0);
      entete_commande("FL","Facture location vehicule");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande);
    break;
    case "FI":
      entete_commande("FI","Facture interne");
    break;
    case "DP":
      entete_commande("DP","Devis");
    break;
    case "OP":
      entete_commande("OP","Offre pièces");
    break;
    case "OV":
      $Devis=1;
      entete_commande("OV","Offre vehicule");
    break;
    case "CP":
      entete_commande("CP","Commande",1);
    break;
    case "AM":
      Valide_Encaissement($NoCommande,1);
      entete_commande("AM","Achat");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "GF":
      Valide_Encaissement($NoCommande,0);
      entete_commande("GF","Garantie fourniseur");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande);
    break;
    case "GG":
      entete_commande("GG","Garantie garage");
    break;
    case "RV":
      Valide_Encaissement($NoCommande,1);
      entete_commande("RV","Reprise véhicule");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "ND":
      Valide_Encaissement($NoCommande,1);
      entete_commande("ND","Note de credit facture détaillée");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "NB":
      Valide_Encaissement($NoCommande,1);
      entete_commande("NB","Note de credit facture bulletins");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "NV":
      Valide_Encaissement($NoCommande,1);
      entete_commande("NV","Note de credit facture vehicule neuf");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "NO":
      Valide_Encaissement($NoCommande,1);
      entete_commande("NO","Note de credit facture occasion");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "NL":
      Valide_Encaissement($NoCommande,1);
      entete_commande("NL","Note de credit facture location");
      Select_Etape_Facture($NoCommande,$NoClient,$NoClient2,M_CLI+M_FAC+M_PRI+M_ENC);
      Gestion_Encaissement($NoCommande,1);
    break;
    case "TR":
      entete_commande("TR","Transfert");
    break;
    default:
      echo $ligne['Type']."<BR>\n";
    break;
  }
?>
