<?php
  switch($Etape)
  {
    case 0:
      echo "<form name='formprint' method='post'>\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'>";
      echo "<input type='hidden' name='degre' value=''>\n";
      echo "<input type='hidden' name='type_commande' value=''>\n";
      echo "<input type='hidden' name='no_commande' value=''>\n";
      for($deg=0;$deg<5;$deg++)
      {
        $type_fact="FD";
        tableau_rappel($deg,$type_fact);
        $type_fact="FB";
        tableau_rappel($deg,$type_fact);
        $type_fact="FV";
        tableau_rappel($deg,$type_fact);
        $type_fact="FO";
        tableau_rappel($deg,$type_fact);
        $type_fact="FL";
        tableau_rappel($deg,$type_fact);
        $type_fact="GF";
        tableau_rappel($deg,$type_fact);
      }
      echo "<button type='button' onClick='imprime_tous();'>Imprimer tous</button><BR>\n";
      echo "PAYEMENTS PAR MENSUALITES<BR>\n";
      $requette="SELECT * FROM commande".ID_GARAGE." WHERE APayer!=0 AND Paye!='O' AND ModeDelaisPayement=2 ORDER BY DateDelaisPayement";
      $resultat=Connection::executeRawQueryWithfetchAll($requette);
      echo "<TABLE border='1'>";
      echo "<TR><TH>Facture</TH><TH>NoCommande</TH><TH>Client</TH><TH>Date facture</TH><TH>Date délais premier payement</TH><TH>Montant total</TH><TH>Montant à payer</TH><TH>Date dernier payement</TH><TH>Imprimer</TH><TH>PDF</TH></TR>\n";
      foreach($resultat as $ligne)
      {
        echo "<TR><TD><input type='checkbox' name='fac".$ligne["NoCommande"]."' checked></TD><TD>".Cree_Entree_Type("date",32,0,$ligne["NoCommande"],AFFICHAGE)."</TD><TD>".Cree_Entree_Type("date",14,0,$ligne["NoClient"],AFFICHAGE)."</TD><TD>".Cree_Entree_Type("date",2,0,$ligne["DateCommande"],AFFICHAGE)."</TD><TD>".Cree_Entree_Type("date",2,0,$ligne["DateDelaisPayement"],AFFICHAGE)."</TD><TD>".Cree_Entree_Type("date",19,0,$ligne["MontantTotal"],AFFICHAGE)."</TD><TD>".Cree_Entree_Type("date",19,0,$ligne["APayer"],AFFICHAGE)."</TD><TD>".Cree_Entree_Type("date",2,0,$ligne["DatePayement"],AFFICHAGE)."</TD><TD><input type='button' value='Imprimer' onClick='imprime_unique(".$ligne["NoCommande"].");'></TD><TD><input type='button' value='PDF' onClick='imprime_unique_pdf(".$ligne["NoCommande"].");'></TD></TR>\n";
      }
      echo "</TABLE><BR>\n";
      echo "<button type='button' onClick='imprime_fact();'>Imprimer groupe</button><BR>\n";
      echo "<input type='submit' value='valider'>";
      echo "</form>\n";
    break;
    case 1:
      echo "$degre $type_commande<BR>\n";
      if($type_commande!="")
      {
        $requette="SELECT * FROM commande".ID_GARAGE." WHERE DegreSommation=$degre AND APayer!=0 AND Paye!='O' AND DateDelaisPayement<'".date("Y-m-d")."' AND ModeDelaisPayement=0 AND Type='$type_commande' ORDER BY DateDelaisPayement";
        if($resultat=Connection::executeRawQueryWithfetchAll($requette))
        {
          echo "<script language='javascript'>\n";
          foreach($resultat as $ligne)
          {
            if(isset(${"let".$ligne["NoCommande"]}))
            {
              echo "window.open('print_rappel.php?nocommande=".$ligne["NoCommande"]."&Direct=1', '', 'top=0, left=0, width=800, height=600, resizable=yes, toolbar=no, scrollbars=yes, status=no');\n";
            }
            if(isset(${"fac".$ligne["NoCommande"]}))
            {
              echo "window.open('print.php?Type=1&Sous_Type=1&NoCommande=".$ligne["NoCommande"]."&NoArticle=0&NoClient=1&Direct=1', '', 'top=0, left=0, width=800, height=600, resizable=yes, toolbar=no, scrollbars=yes, status=no');\n";
            }
          }
          echo "</script>\n";
        }
        else
        {
          echo Connection::getConnection()->errorInfo();
        }
      }
      else if($no_commande!="")
      {
        echo "<script language='javascript'>\n";
        if(isset(${"let".$no_commande}))
        {
          echo "window.open('print_rappel.php?nocommande=".$no_commande."&Direct=1', '', 'top=0, left=0, width=800, height=600, resizable=yes, toolbar=no, scrollbars=yes, status=no');\n";
        }
        if(isset(${"fac".$no_commande}))
        {
          echo "window.open('print.php?Type=1&Sous_Type=1&NoCommande=".$no_commande."&NoArticle=0&NoClient=1&Direct=1', '', 'top=0, left=0, width=800, height=600, resizable=yes, toolbar=no, scrollbars=yes, status=no');\n";
        }
        echo "</script>\n";
      }
    break;
  }
?>
