<?php
  switch($Etape)
  {
    case 0:
	  $annee=date("Y");
      echo "<form name='info'>";
      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 "<select name=\"mois\"><option value=\"01\">Janvier</option><option value=\"02\">Février</option><option value=\"03\">Mars</option><option value=\"04\">Avril</option><option value=\"05\">Mai</option><option value=\"06\">Juin</option><option value=\"07\">Juillet</option><option value=\"08\">Août</option><option value=\"09\">Septembre</option><option value=\"10\">Octobre</option><option value=\"11\">Novembre</option><option value=\"12\">Décembre</option></select>";
	  echo "&nbsp;<select name=\"annee\">";
	  for ($cpt = $annee; $cpt>=$annee-2; $cpt--)
	  {
	    echo "<option value=\"$cpt\">$cpt</option>";
	  }
	  echo "</select>";
      echo "&nbsp;<button type='submit'>Générer</button>";
      echo "</form>";
    break;
    case 1:
	  $startDate = "$annee-$mois-01";
	  if ($mois == 12)
	  {
	    $endAnnee = $annee + 1;
	    $endDate = "$endAnnee-01-01";
	  }
	  else
	  {
	    $EndMois = $mois + 1;
		if (strlen($EndMois) == 1) $EndMois = "0".$EndMois;
	    $endDate = "$annee-$EndMois-01";
	  }
	  $requette1 = "SELECT COUNT(*) FROM atelier".ID_GARAGE." as a, commande".ID_GARAGE." as c WHERE a.Date >= '$startDate' AND a.Date < '$endDate' AND a.NoCommande <> 0 AND a.NoCommande = c.NoCommande AND c.Type in ('FD', 'GF', 'GG')";
	  $resultat1 = Connection::executeRawQueryWithfetchAll($requette1);
	  if ($ligne1 = $resultat1[0])
	  {
	    echo "<h2>Nb rdv : ".$ligne1[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb rdv : 0</h2>";
	  }

	  $requette2 = "SELECT SUM(ca.Quantite) FROM atelier".ID_GARAGE." as a, commande".ID_GARAGE." as c, commandearticles".ID_GARAGE." as ca WHERE a.Date >= '$startDate' AND a.Date < '$endDate' AND a.NoCommande <> 0 AND a.NoCommande = c.NoCommande AND c.Type = 'FD' AND c.NoCommande = ca.NoCommande AND ca.GM = 10";
	  $resultat2 = Connection::executeRawQueryWithfetchAll($requette2);
	  if ($ligne2 = $resultat2[0])
	  {
	    echo "<h2>Nb heures facturées avec rdv : ".$ligne2[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb heures facturées avec rdv (date atelier) : 0</h2>";
	  }

	  $requette21 = "SELECT SUM(ca.Quantite) FROM commande".ID_GARAGE." as c, commandearticles".ID_GARAGE." as ca WHERE c.DateCommande >= '$startDate' AND c.DateCommande < '$endDate' AND c.Type = 'FD' AND c.NoCommande = ca.NoCommande AND ca.GM = 10";
	  $resultat21 = Connection::executeRawQueryWithfetchAll($requette21);
	  if ($ligne21 = $resultat21[0])
	  {
	    echo "<h2>Nb heures facturées sans rdv (date facture) : ".$ligne21[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb heures facturées sans rdv: 0</h2>";
	  }

	  $requette3 = "SELECT SUM(ca.Quantite) FROM atelier".ID_GARAGE." as a, commande".ID_GARAGE." as c, commandearticles".ID_GARAGE." as ca WHERE a.Date >= '$startDate' AND a.Date < '$endDate' AND a.NoCommande <> 0 AND a.NoCommande = c.NoCommande AND c.Type = 'GF' AND c.NoCommande = ca.NoCommande AND ca.GM = 10";
	  $resultat3 = Connection::executeRawQueryWithfetchAll($requette3);
	  if ($ligne3 = $resultat3[0])
	  {
	    echo "<h2>Nb heures garanties avec rdv : ".$ligne3[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb heures garanties avec rdv : 0</h2>";
	  }

	  $requette31 = "SELECT SUM(ca.Quantite) FROM commande".ID_GARAGE." as c, commandearticles".ID_GARAGE." as ca WHERE c.DateCommande >= '$startDate' AND c.DateCommande < '$endDate' AND c.Type = 'GF' AND c.NoCommande = ca.NoCommande AND ca.GM = 10";
	  $resultat31 = Connection::executeRawQueryWithfetchAll($requette31);
	  if ($ligne31 = $resultat31[0])
	  {
	    echo "<h2>Nb heures garanties sans rdv : ".$ligne31[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb heures garanties sans rdv: 0</h2>";
	  }


	  $requette4 = "SELECT SUM(ca.Quantite) FROM atelier".ID_GARAGE." as a, commande".ID_GARAGE." as c, commandearticles".ID_GARAGE." as ca WHERE a.Date >= '$startDate' AND a.Date < '$endDate' AND a.NoCommande <> 0 AND a.NoCommande = c.NoCommande AND c.Type = 'FI' AND c.NoCommande = ca.NoCommande AND ca.GM = 10";
	  $resultat4 = Connection::executeRawQueryWithfetchAll($requette4);
	  if ($ligne4 = $resultat4[0])
	  {
	    echo "<h2>Nb heures internes avec rdv : ".$ligne4[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb heures internes avec rdv : 0</h2>";
	  }

	  $requette41 = "SELECT SUM(ca.Quantite) FROM commande".ID_GARAGE." as c, commandearticles".ID_GARAGE." as ca WHERE c.DateCommande >= '$startDate' AND c.DateCommande < '$endDate' AND c.Type = 'FI' AND c.NoCommande = ca.NoCommande AND ca.GM = 10";
	  $resultat41 = Connection::executeRawQueryWithfetchAll($requette41);
	  if ($ligne41 = $resultat41[0])
	  {
	    echo "<h2>Nb heures internes sans rdv : ".$ligne41[0]."</h2>";
	  }
	  else
	  {
	    echo "<h2>Nb heures internes sans rdv: 0</h2>";
	  }
    break;
  }
?>
