<?php
  switch($Etape)
  {
    case 0:
      echo "  <form>\n";
      echo "   <input type='hidden' name='Type' value=$Type>\n";
      echo "   <input type='hidden' name='Sous_Type' value=$Sous_Type>\n";
      echo "   <input type='hidden' name='Etape' value='1'>\n";
      $resultat=ModePayement::getModePayment();
      echo "<select name='source'>";
      foreach($resultat as $ligne)
      {
        echo "<option value='".$ligne['NoMode']."C".$ligne['NoCaisse']."'>".$ligne['Description']." Caisse".$ligne['NoCaisse']."</option>";
      }
      echo "</select>à<select name='destination'>";
      foreach($resultat as $ligne)
      {
        echo "<option value='".$ligne['NoMode']."C".$ligne['NoCaisse']."'>".$ligne['Description']." Caisse".$ligne['NoCaisse']."</option>";
      }
      echo "</select><br />";
      echo "Montant <input name='Montant' type='text' value='0.00'><br />";
      echo "Date ".Cree_Entree_Type("date",2,0,date("Y-m-d"),MODIFICATION)."<br />";
      echo "<button type='submit'>Transfert</button>\n";
      echo "  </form>\n";
    break;
    case 1:
	  $dateStr = substr(Decode_Entree_Type($date,2),0,10);
      $NoCommande=Trouve_No_Commande_Libre("TR");
      $requette="INSERT INTO commande".ID_GARAGE." (NoCommande,Type,Genre,PersonneModif,DatePayement,DateCommande,DateSaisie,DateModification, Paye) VALUES " .
                "($NoCommande, 'TR', 'T', '$lg_user', '$dateStr', '$dateStr', '$dateStr', '$dateStr', 'O')";
      $resultat=Connection::executeRawQuery($requette);
      $resultat=Article::getArticleByNoArticle('Sortie'.$source);
      if($ligne=$resultat[0])
      {
        $nom_source=$ligne['Description'];
        $gm_source=$ligne['GroupeMarchandise'];
      }
      else
      {
        $nom_source="inconnu";
        $gm_source=0;
      }
      $requette="INSERT INTO commandearticles".ID_GARAGE." (NoCommande, Position, TypeData, NoArticle, Description, TVA, GM, Quantite, PrixBase, PrixMulti) VALUES " .
                "($NoCommande, 1, 0, 'Sortie$source', '$nom_source', 0, $gm_source, -1, $Montant, -$Montant)";
      $resultat=Connection::executeRawQuery($requette);
      $resultat=Article::getArticleByNoArticle('Entree'.$destination);
      if($ligne=$resultat[0])
      {
        $nom_destination=$ligne['Description'];
        $gm_destination=$ligne['GroupeMarchandise'];
      }
      else
      {
        $nom_destination="inconnu";
        $gm_destination=0;
      }
      $requette="INSERT INTO commandearticles".ID_GARAGE." (NoCommande, Position, TypeData, NoArticle, Description, TVA, GM, Quantite, PrixBase, PrixMulti) VALUES " .
                "($NoCommande, 2, 0, 'Entree$destination', '$nom_destination', 0, $gm_destination, 1, $Montant, $Montant)";
      $resultat=Connection::executeRawQuery($requette);
      $tab_source=explode("C",$source);
      $requette="INSERT INTO dbcash".ID_GARAGE." (NoFacture, PersonneEncaissement, Date, Somme, TVA, ModePayement, NoCaisse) VALUES".
                " ($NoCommande, '$lg_user', '$dateStr', ".(-$Montant).", 0, ".$tab_source[0].", ".$tab_source[1].")";
      $resultat=Connection::executeRawQuery($requette);
      $tab_destination=explode("C",$destination);
      $requette="INSERT INTO dbcash".ID_GARAGE." (NoFacture, PersonneEncaissement, Date, Somme, TVA, ModePayement, NoCaisse) VALUES".
                " ($NoCommande, '$lg_user', '$dateStr', $Montant, 0, ".$tab_destination[0].", ".$tab_destination[1].")";
      $resultat=Connection::executeRawQuery($requette);

    break;
  }
?>
