<?php //create_cache(); ?>
<div class="div_atelier">
<?php
  function get_potentiel_atelier_tous($jour, $mois, $annee)
  {
    $date=mktime(0,0,0,$mois,$jour,$annee);
    $a_jour = date("d",$date);
    $a_mois = date("m",$date);
    $a_annee = date("Y",$date);
  	if (jour_ferie($jour, $mois, $annee, 2)==0)
  	{
  		return "0.00";
  	}
    $pot=Employee::getSumByActifEmployee();
    //$tab_debug[$tmp_date]["tous"]=$lign[0];
    $pot2="0.00";
    $pot3="0.00";
    $tous=0;
    $date = $a_annee."-".Chiffre_2_Car($a_mois)."-".Chiffre_2_Car($a_jour);
    if($result=AbsenceEmploye::getAbsencePeriod($date, $date))
    {
      foreach($result as $lign)
      {
        if($lign['NoClient']==0)
        {
          $tous=1;
          $Debut=$lign['Debut'];
          $Fin=$lign['Fin'];
          $Actual=$a_annee."-".$a_mois."-".$a_jour;
          if(($Debut<$Actual)&&($Fin>$Actual))
          {
            $pot3+=$pot;
          }
          else if($Debut==$Actual)
          {
            if($Fin==$Actual)
            {
              if($lign['DebutMA']<$lign['FinMA'])
              {
                $pot3+=$pot;
              }
              else
              {
                $pot3+=$pot/2;
              }
            }
            else
            {
              if($lign['DebutMA']==0)
              {
                $pot3+=$pot;
              }
              else
              {
                $pot3+=$pot/2;
              }
            }
          }
          else if($Fin==$Actual)
          {
            if($lign['FinMA']==1)
            {
              $pot3+=$pot;
            }
            else
            {
              $pot3+=$pot/2;
            }
          }
          //$tab_debug[$tmp_date]["0"]=$pot3;
        }
        else
        {
          if($result2=Employee::getActifEmployeeByClient($lign['NoClient']))
          {
            if($lign2=$result2[0])
            {
              $Debut=$lign['Debut'];
              $Fin=$lign['Fin'];
              $Actual=$a_annee."-".$a_mois."-".$a_jour;
              if(($Debut<$Actual)&&($Fin>$Actual))
              {
                $pot2+=$lign2['HeureAtelier'];
              }
              else if($Debut==$Actual)
              {
                if($Fin==$Actual)
                {
                  if($lign['DebutMA']<$lign['FinMA'])
                  {
                    $pot2+=$lign2['HeureAtelier'];
                  }
                  else
                  {
                    $pot2+=$lign2['HeureAtelier']/2;
                  }
                }
                else
                {
                  if($lign['DebutMA']==0)
                  {
                    $pot2+=$lign2['HeureAtelier'];
                  }
                  else
                  {
                    $pot2+=$lign2['HeureAtelier']/2;
                  }
                }
              }
              else if($Fin==$Actual)
              {
                if($lign['FinMA']==1)
                {
                  $pot2+=$lign2['HeureAtelier'];
                }
                else
                {
                  $pot2+=$lign2['HeureAtelier']/2;
                }
              }
              //$tab_debug[$tmp_date][$lign["NoClient"]]=$lign2['HeureAtelier'];
            }
          }
        }
      }
    }
    if($tous==1)
    {
      $pot4=$pot-$pot3;
    }
    else
    {
      $pot4=$pot-$pot2;
    }
    $pot4=Arrondi_1_ct($pot4);
    return $pot4;  	
  }
  function get_potentiel_atelier($jour, $mois, $annee, $no_client)
  {
    $date=mktime(0,0,0,$mois,$jour,$annee);
    $a_jour = date("d",$date);
    $a_mois = date("m",$date);
    $a_annee = date("Y",$date);
  	if (jour_ferie($jour, $mois, $annee, 2)==0)
  	{
  		return "0.00";
  	}
  	$pot="0.00";
      if($result=Employee::getHeureEmployeeByClient($no_client))
        if($lign=$result[0])
          $pot=$lign[0];
      if(empty($pot))
        $pot="0.00";
      $pot2="0.00";
      $pot3="0.00";
      $tous=0;
      $date = $a_annee."-".Chiffre_2_Car($a_mois)."-".Chiffre_2_Car($a_jour);
      if($result=AbsenceEmploye::getAbsenceByNoClientAndPeriod($no_client, $date, $date))
      {
        foreach($result as $lign)
        {
          if($lign['NoClient']==0)
          {
            $tous=1;
            $Debut=$lign['Debut'];
            $Fin=$lign['Fin'];
            $Actual=$a_annee."-".$a_mois."-".$a_jour;
            if(($Debut<$Actual)&&($Fin>$Actual))
            {
              $pot3+=$pot;
            }
            else if($Debut==$Actual)
            {
              if($Fin==$Actual)
              {
                if($lign['DebutMA']<$lign['FinMA'])
                {
                  $pot3+=$pot;
                }
                else
                {
                  $pot3+=$pot/2;
                }
              }
              else
              {
                if($lign['DebutMA']==0)
                {
                  $pot3+=$pot;
                }
                else
                {
                  $pot3+=$pot/2;
                }
              }
            }
            else if($Fin==$Actual)
            {
              if($lign['FinMA']==1)
              {
                $pot3+=$pot;
              }
              else
              {
                $pot3+=$pot/2;
              }
            }
          }
          else
          {
            $Debut=$lign['Debut'];
            $Fin=$lign['Fin'];
            $Actual=$a_annee."-".$a_mois."-".$a_jour;
            if(($Debut<$Actual)&&($Fin>$Actual))
            {
              $pot2+=$pot;
            }
            else if($Debut==$Actual)
            {
              if($Fin==$Actual)
              {
                if($lign['DebutMA']<$lign['FinMA'])
                {
                  $pot2+=$pot;
                }
                else
                {
                  $pot2+=$pot/2;
                }
              }
              else
              {
                if($lign['DebutMA']==0)
                {
                  $pot2+=$pot;
                }
                else
                {
                  $pot2+=$pot/2;
                }
              }
            }
            else if($Fin==$Actual)
            {
              if($lign['FinMA']==1)
              {
                $pot2+=$pot;
              }
              else
              {
                $pot2+=$pot/2;
              }
            }
          }
        }
      }
      if($tous==1)
      {
        $pot4=$pot-$pot3;
      }
      else
      {
        $pot4=$pot-$pot2;
      }
      $pot4=Arrondi_1_ct($pot4);
  	  return $pot4;
  }
  //$tab_debug = array();
  $max=22;
  if(isset($jourmoisannee))
  {
    $jour=substr($jourmoisannee,8,2);
    $mois=substr($jourmoisannee,5,2);
    $annee=substr($jourmoisannee,0,4);
  }
  if(!isset($jour))
  {
    $jour=date("d");
    $mois=date("m");
    $annee=date("Y");
  }
  echo "<TABLE class='table_av_ap'><TR><TD><form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='2'>";
  $date=mktime(0,0,0,$mois,$jour-7,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  echo "<SCRIPT language=JavaScript>\ntype=$Type;\nsous_type=$Sous_Type;\nmemnoform=5;\njour_down=$a_jour;\nmois_down=$a_mois;\nannee_down=$a_annee;\n</SCRIPT>\n";
  echo "<INPUT type='hidden' name='jour' value='$a_jour'><INPUT type='hidden' name='mois' value='$a_mois'><INPUT type='hidden' name='annee' value='$a_annee'>";
  echo "<INPUT type='submit' class='button bt_av' value='' /></form></TD>";
  echo "<TD><form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='2'>";
  $date=mktime(0,0,0,$mois,$jour+7,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  echo "<SCRIPT language=JavaScript>\njour_up=$a_jour;\nmois_up=$a_mois;\nannee_up=$a_annee;\n</SCRIPT>\n";
  echo "<INPUT type='hidden' name='jour' value='$a_jour'><INPUT type='hidden' name='mois' value='$a_mois'><INPUT type='hidden' name='annee' value='$a_annee'>";
  echo "<INPUT type='submit' class='button bt_ap' value='' /></form></TD>\n";
  echo "<form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='2'>";
  echo "<TH>Jour</TH><TD><INPUT type='text' name='jour' value='$jour' size=2></TD>";
  echo "<TH>Mois</TH><TD><INPUT type='text' name='mois' value='$mois' size=2></TD>";
  echo "<TH>Annee</TH><TD><INPUT type='text' name='annee' value='$annee' size=4></TD><TD><INPUT type='submit' class='button' value='GO' /></TD></TR>";
  echo "</TABLE>";
  echo "</form>";
  echo "<TABLE cellspacing='0' class='tab_atelier'>\n";
  $tab_pret=array();
  $nb_pret=0;
  $resultat=CatLoc::getCatlocByPret();
  foreach($resultat as $ligne)
  {
    $resultat2=VehiculesLocation::getVehiculeLocationByCatLoc($ligne['NoCatLoc']);
    foreach($resultat2 as $ligne2)
    {
      $tab_pret[$nb_pret]=$ligne2['NoChasis'];
      $nb_pret++;
    }
  }
  for($cpt=-1;$cpt<$max;$cpt++)
  {
    $nb_lignes = 1;
    $tmp_str = "";
    $date=mktime(0,0,0,$mois,$jour+$cpt,$annee);
    $a_jour = date("d",$date);
    $a_mois = date("m",$date);
    $a_annee = date("Y",$date);
    $a_semaine = date("w",$date);
    //$tmp_date=$a_jour.".".$a_mois.".".$a_annee;
    //$tab_debug[$tmp_date] = array();
    $tmp_str .= "<TR";
    if (jour_ferie($a_jour,$a_mois,$a_annee,2)==0)
    {
      $tmp_str .= " class='tr_jour jour_ferie ";
    }
    else
    {
      $tmp_str .= " class='tr_jour jour_ouvert ";
    }
    $date = $a_annee."-".Chiffre_2_Car($a_mois)."-".Chiffre_2_Car($a_jour);
    $tot=Atelier::getSumTempByDate($date);
    $fact=0;
    $req="SELECT atelier".ID_GARAGE.".NoCommande FROM atelier".ID_GARAGE.", commande".ID_GARAGE." WHERE atelier".ID_GARAGE.".Date='$a_annee-".Chiffre_2_Car($a_mois)."-".Chiffre_2_Car($a_jour)."' AND atelier".ID_GARAGE.".NoCommande>0 AND atelier".ID_GARAGE.".NoCommande = commande".ID_GARAGE.".NoCommande AND (commande".ID_GARAGE.".Genre = 'F' OR commande".ID_GARAGE.".Genre = 'G') AND atelier".ID_GARAGE.".Etape > 1";
    if($result=Atelier::getNoCommandeByDate($date))
    {
      foreach($result as $lign)
      {
        $fact+=CommandeArticle::getSumQuantiteByNoCommande($lign[0]);
      }
    }
    $fact=arrondi_1_ct($fact);
    $nb_rdv=Atelier::getNbRdv($date);
    $rest=Atelier::getSumTempByDate($date, 2);
    $pot4=get_potentiel_atelier_tous($a_jour, $a_mois, $a_annee);
    if($pot4==0)
    {
      $pourcent=100;
    }
    else
    {
      $pourcent=100*$tot/$pot4;
    }
    if($pourcent<=66)
    {
      $occupation="occupation_faible";
    }
    else if ($pourcent<=80)
    {
      $occupation="occupation_moyenne";
    }
    else
    {
      $occupation="occupation_elevee";
    }
	$ordre = array();
	$pos = 1;
	$resultat=Atelier::getAtelierByDate($date);
	foreach ($resultat as $ligne)
	{
	  $ordre[$ligne["NoAtelier"]] = $pos;
	  $pos++;
	}
    $tmp_str .= $occupation."'><TH class='th_date' COLSPAN=2><TABLE cellspacing='0' class='table_occup'><TR class='tr_occup'><TD class='td_occup'></TD><TD class='td_info'>" . nom_jour($a_semaine) . " $a_jour " . nom_mois($a_mois) . " $a_annee</TD></TR></TABLE></TH><TD class='td_occupation' COLSPAN=2>Prévu $tot Potentiel $pot4 Reste $rest Facturé $fact</TD><TD class='td_nouveau_rdv'><A HREF='atelier.php?new=1&jour=$a_jour&mois=$a_mois&annee=$a_annee&mecano=0' TARGET='_blank' rel='opener'>nouveau rdv</A></TD>";
    $tmp_str2 = "";
    if ($resultat = Atelier::getAtelierByDate($date, 0))
    {
      $nb_rdv = count($resultat);
      for($cpt2=0;$cpt2<$nb_rdv;$cpt2+=5)
      {
        $nb_lignes++;
        $tmp_str2 .= "<TR class='tr_ligne_rdv rdv_communs'>";
        for($cpt3=$cpt2;($cpt3<$nb_rdv)&&($cpt3<$cpt2+5);$cpt3++)
        {
          if($ligne = $resultat[0])
          {
            $tmp_str2 .= "<TD class='td_rdv ";
            $tmp_heures_fact = "";
            switch ($ligne['Etape'])
            {
              case 0:
                if ($annee>$a_annee||($mois>$a_mois&&$annee==$a_annee)||($jour>$a_jour&&$mois==$a_mois&&$annee==$a_annee))
                  $tmp_str2 .= "rdv_passe'";
                else
                  $tmp_str2 .= "rdv_pris'";
              break;
              case 1:
                $tmp_str2 .= "rdv_vhc_recu'";
              break;
              case 2:
                if($ligne['NoCommande']!=0)
                {
                  $tmp_heures_fact = "(".CommandeArticle::getSumQuantiteByNoCommande($ligne['NoCommande']).")";
                  $ligne_s=Commande::getCommandeByNoCommande($ligne['NoCommande']);
                  if($ligne_s['Paye']=="O")
                  {
                    $tmp_str2 .= "rdv_paye'";
                  }
                  else if($ligne_s['Type']!="FD") 
                  {
                    $tmp_str2 .= "rdv_non_fd'";
                  }
                  else
                  {
                    $tmp_str2 .= "rdv_facture'";
                  }
                }
                else
                {
                  $tmp_str2 .= "rdv_pas_encore_facture'";
                }
              break;
              case 3:
                $tmp_str2 .= "rdv_sans_facture'";
              break;
            }
			$desc=htmlspecialchars($ligne['Description'],  ENT_QUOTES);
            $tmp_str2 .= ">";
            $tmp_str2 .= "<A TITLE='$desc' HREF='atelier.php?NoAtelier=".$ligne['NoAtelier']."&new=0' TARGET='_blank' rel='opener'>";
			$tmp_str2 .= "<div style=\"text-align:right;\">".$ordre[$ligne["NoAtelier"]]."</div>";
            if ($ligne['Sms']!=0)
            {
              $tmp_str2 .= "<img border=\"0\" src='images/icon_sms_sent.gif' />";
            }
            $arr_desc = explode("\n",$desc);
            $desc=$arr_desc[0];
            $desc=substr($desc,0,30);
            $tmp_str2 .= $ligne['Nom']." ".$ligne['Prenom']." ".$ligne['Temps'].$tmp_heures_fact."<BR>".$ligne['Vehicule']."<BR>";
            if ($ligne['Id_Service']!=0)
            {
              if ($ligne_s = ServiceVHC::getServiceVHCByID($ligne['Id_Service']))
              {
                $tmp_str2 .= "Service ".$ligne_s["Km"]." Km";
              }
            }
            else 
            {
              $tmp_str2 .= $desc;
            }
            $tmp_str2 .= "</A></TD>";
          }
        }
        for(;($cpt3%5)!=0;$cpt3++)
        {
          $tmp_str2 .= "<TD class='td_rdv rdv_vide'>&nbsp;</TD>";
        }
        $tmp_str2 .= "</TR>";
      }
    }
    else
    {
      $tmp_str2 .= "KO $requette";
    }
    $resultat_mecano=Employee::getMecano();
	  foreach($resultat_mecano as $ligne_mecano)
    {
      $tot=Atelier::getSumTempByDate($date, null, $ligne_mecano["NoClient"]);
      $fact=0;
      if($result=Atelier::getNoCommandeByDateAndMecano($date,$ligne_mecano["NoClient"]))
      {
        foreach($result as $lign)
        {
          $fact+=CommandeArticle::getSumQuantiteByNoCommande($lign[0]);
        }
      }
      $fact=arrondi_1_ct($fact);
      $nb_rdv=Atelier::getNbRdv($date,null, $ligne_mecano["NoClient"]);
      $rest=Atelier::getSumTempByDate($date, null, $ligne_mecano["NoClient"]);
      $pot4 = get_potentiel_atelier($a_jour, $a_mois, $a_annee, $ligne_mecano["NoClient"]);
      if($pot4==0)
      {
        $pourcent=100;
      }
      else
      {
        $pourcent=100*$tot/$pot4;
      }
      if($pourcent<=66)
      {
        $occupation="occupation_faible";
      }
      else if ($pourcent<=80)
      {
        $occupation="occupation_moyenne";
      }
      else
      {
        $occupation="occupation_elevee";
      }
       if ($resultat = Atelier::getAtelierByDate($date, $ligne_mecano["NoClient"]))
      {
        $nb_rdv = count($resultat);
        if ($nb_rdv || (($pot4!=0)&&(jour_ferie($a_jour,$a_mois,$a_annee,2))))
        {
          $nb_lignes++;
          //$tmp_str2 .= "<TR class='tr_mecano $occupation'><TH class='th_mecano_nom' COLSPAN=2><TABLE cellspacing='0' class='table_occup'><TR class='tr_occup'><TD class='td_occup'></TD><TD class='td_info'>".$ligne_mecano["Prenom"]."</TD></TR></TABLE></TH><TD class='td_occupation' COLSPAN=2>Prévu $tot Potentiel $pot4 Reste $rest Facturé $fact</TD><TD class='td_nouveau_rdv'><A HREF='atelier.php?new=1&jour=$a_jour&mois=$a_mois&annee=$a_annee&mecano=".$ligne_mecano["NoClient"]."' TARGET='_blank' rel='opener'>nouveau rdv</A></TD></TR>\n";
          $tmp_str2 .= "<TR class='tr_mecano $occupation'><TH class='th_mecano_nom' COLSPAN=2><TABLE cellspacing='0' class='table_occup'><TR class='tr_occup'><TD class='td_occup'></TD><TD class='td_info'>".$ligne_mecano["Prenom"]."</TD></TR></TABLE></TH><TD class='td_occupation' COLSPAN=2>Prévu $tot Potentiel $pot4 Reste $rest Facturé $fact</TD><TD class='td_nouveau_rdv'><A HREF='atelier.php?new=1&jour=$a_jour&mois=$a_mois&annee=$a_annee&mecano=".$ligne_mecano["NoClient"]."' TARGET='_blank' rel='opener'>nouveau rdv</A></TD></TR>\n";
          for($cpt2=0;$cpt2<$nb_rdv;$cpt2+=5)
          {
            $nb_lignes++;
            $tmp_str2 .= "<TR class='tr_ligne_rdv rdv_mecano'>";
            for($cpt3=$cpt2;($cpt3<$nb_rdv)&&($cpt3<$cpt2+5);$cpt3++)
            {
              if($ligne = $resultat[0])
              {
                $tmp_str2 .= "<TD class='td_rdv ";
                $tmp_heures_fact = "";
                switch ($ligne['Etape'])
                {
                  case 0:
                    if ($annee>$a_annee||($mois>$a_mois&&$annee==$a_annee)||($jour>$a_jour&&$mois==$a_mois&&$annee==$a_annee))
                      $tmp_str2 .= "rdv_passe'";
                    else
                      $tmp_str2 .= "rdv_pris'";
                  break;
                  case 1:
                    $tmp_str2 .= "rdv_vhc_recu'";
                  break;
                  case 2:
                    if($ligne['NoCommande']!=0)
                    {
                      $tmp_heures_fact = "(".CommandeArticle::getSumQuantiteByNoCommande($ligne['NoCommande']).")";
                      $ligne_s=Commande::getCommandeByNoCommande($ligne['NoCommande']);
                      if($ligne_s['Paye']=="O")
                      {
                        $tmp_str2 .= "rdv_paye'";
                      }
                      else if($ligne_s['Type']!="FD") 
                      {
                        $tmp_str2 .= "rdv_non_fd'";
                      }
                      else
                      {
                        $tmp_str2 .= "rdv_facture'";
                      }
                    }
                    else
                    {
                      $tmp_str2 .= "rdv_pas_encore_facture'";
                    }
                  break;
                  case 3:
                    $tmp_str2 .= "rdv_sans_facture'";
                  break;
                }
				$desc=htmlspecialchars($ligne['Description'],  ENT_QUOTES);
                $tmp_str2 .= ">";
                $tmp_str2 .= "<A TITLE='$desc' HREF='atelier.php?NoAtelier=".$ligne['NoAtelier']."&new=0' TARGET='_blank' rel='opener'>";
			    $tmp_str2 .= "<div style=\"text-align:right;\">".$ordre[$ligne["NoAtelier"]]."</div>";
                if ($ligne['Sms']!=0)
                {
                  $tmp_str2 .= "<img border=\"0\" src='images/icon_sms_sent.gif' />";
                }
                $arr_desc = explode("\n",$desc);
                $desc=$arr_desc[0];
                $desc=substr($desc,0,30);
            $tmp_str2 .= $ligne['Nom']." ".$ligne['Prenom']." ".$ligne['Temps'].$tmp_heures_fact."<BR>".$ligne['Vehicule']."<BR>";
            if ($ligne['Id_Service']!=0)
            {
              if ($ligne_s = ServiceVHC::getServiceVHCByID($ligne['Id_Service']))
              {
                $tmp_str2 .= "Service ".$ligne_s["Km"]." Km";
              }
            }
            else 
            {
              $tmp_str2 .= $desc;
            }
            $tmp_str2 .= "</A></TD>";
                //$tmp_str2 .= $ligne['Nom']." ".$ligne['Prenom']." ".$ligne['Temps'].$tmp_heures_fact."<BR>".$ligne['Vehicule']."<BR>$desc</A></TD>";
              }
            }
            for(;($cpt3%5)!=0;$cpt3++)
            {
              $tmp_str2 .= "<TD class='td_rdv rdv_vide'>&nbsp;</TD>";
            }
            $tmp_str2 .= "</TR>";
          }
        }
      }
      else
      {
        $tmp_str2 .= "KO $requette";
      }
    }
    echo $tmp_str;
    $texte="";
    $resultat=Note::getNoteByDate($date);
    if ($ligne=$resultat[0])
    {
      $texte=$ligne["Texte"];
      $texte=str_replace(array("\n\r","\r\n"), "<BR />", $texte);
      $texte=str_replace(array("\n","\r"), "<BR />", $texte);
    }
    $nb_vhc_libres = 0;
    for ($cpt_pret=0;$cpt_pret<$nb_pret;$cpt_pret++)
    {
      $date_debut="$date 00:00:00";
      $date_fin="$date 23:59:59";
      $is_pret=(Location::getNbPretByNoChassisAndDate(addslashes($tab_pret[$cpt_pret]), $date_debut, $date_fin)!=0);
      //echo "<TD rowspan=$nb_lignes class='td_vhc_loc ";
      $ligne=Vehicule::getVehiculeByNoChassis(addslashes($tab_pret[$cpt_pret]));
      $v=$ligne['Model'];
      if($is_pret)
      {
        //echo "vhc_loc_occupe'>";
        if (jour_ferie($a_jour,$a_mois,$a_annee,2)==1)
        {
          //echo $v;
        }
        else
        {
          //echo "&nbsp;";
        }
      }
      else
      {
        $nb_vhc_libres++;
        if($resultat=Location::getByNoChassisAndDateDebut(addslashes($tab_pret[$cpt_pret]), $date))
          if($ligne=$resultat[0])
          {
            $prem=mktime(0,0,0,substr($ligne["Debut"],5,2),substr($ligne["Debut"],8,2),substr($ligne["Debut"],0,4));
            $actu=mktime(0,0,0,$a_mois,$a_jour,$a_annee);
            $j=(round(($prem-$actu)/(60*60*24)))." jours";
          }
          else
          {
            $j="";
          }
        //echo "vhc_loc_libre'>";
        if (jour_ferie($a_jour,$a_mois,$a_annee,2)==1)
        {
          //echo $v." ".$j;
        }
        else
        {
          //echo "&nbsp;";
        }
      }
      //echo "</TD>";
    }
    echo "<TD rowspan=$nb_lignes class='texte_libre'><a target='_blank' rel='opener' href='note.php?jour=$a_jour&mois=$a_mois&annee=$a_annee'><img src='images/b_edit.png' border='0'></a><br />$texte</TD>\n";
    echo "<TD rowspan='$nb_lignes' class='vhc_pret_";
    if ($nb_vhc_libres == 0)
    {
      echo "occupe";
    }
    else 
    {
      echo "libre";
    }
    echo "'>$nb_vhc_libres</TD>";
    echo "</TR>";
    echo $tmp_str2;
    echo "<TR class='tr_sep_jour'><TD class='td_sep_jour' COLSPAN='".(5+$nb_pret)."'></TD></TR>\n";
	$montant_total_factures=0;
    if ($a_semaine == 0)
    {
    	echo "<TR><TD COLSPAN='2'>Rapport hebdo</TD><TD COLSPAN='2'><TABLE><TR><TH>Mecano</TH><TH>Prévu</TH><TH>Potientiel</TH><TH>Reste</TH><TH>Facturé</TH><TH>Taux</TH></TR>";
    	$d_date=mktime(0,0,0,$a_mois,$a_jour-6,$a_annee);
        $d_jour = date("d",$d_date);
        $d_mois = date("m",$d_date);
        $d_annee = date("Y",$d_date);
    	//$c_dates = "";
        $requette_mecano="SELECT employes".ID_GARAGE.".NoClient, clients.Prenom FROM employes".ID_GARAGE.", clients WHERE employes".ID_GARAGE.".Actif = 1 AND employes".ID_GARAGE.".HeureAtelier > 0 AND employes".ID_GARAGE.".NoClient = clients.NoClient ORDER BY clients.Prenom";
        $resultat_mecano=Employee::getMecano();
        foreach ($resultat_mecano as $ligne_mecano)
        {
          $tot=Atelier::getSumTempByDate($date, null, $ligne_mecano["NoClient"]);
          $fact=0;
		  
          if($result=Atelier::getNoCommandeByDateAndMecano($date, $ligne_mecano["NoClient"]))
          {
            foreach($result as $lign)
            {
              if ($lign[1]=="FD")
              {
              //$montant_total_factures+=$lign[2];
              }
              $fact+=CommandeArticle::getSumQuantiteByNoCommande($lign[0]);
            }
          }
          $fact=arrondi_1_ct($fact);
          $nb_rdv=Atelier::getNbRdv($date, null, $ligne_mecano["NoClient"]);
          $rest=Atelier::getSumTempByDate($date, 2, $ligne_mecano["NoClient"]);
          $rest=Arrondi_1_ct($rest);
          $pot = 0;
          for ($c_cpt=-6; $c_cpt <= 0; $c_cpt++)
    	  {
            $c_date=mktime(0,0,0,$a_mois,$a_jour+$c_cpt,$a_annee);
            $c_jour = date("d",$c_date);
            $c_mois = date("m",$c_date);
            $c_annee = date("Y",$c_date);
            $pot += get_potentiel_atelier($c_jour, $c_mois, $c_annee, $ligne_mecano["NoClient"]);
    	  }
    	  $pot=Arrondi_1_ct($pot);
    	  if ($pot != 0)
    	  {
    	    echo "<TR><TD>".$ligne_mecano["Prenom"]."</TD><TD>$tot</TD><TD>$pot</TD><TD>$rest</TD><TD>$fact</TD><TD>".round(100*$fact/$pot)."</TD></TR>\n";
    	  }
        }
        $tot=Atelier::getSumTempByDate($date);
        $fact=0;
        if($result=Atelier::getNoCommandeByDate($date))
        {
          foreach($result as $lign)
          {
            if ($lign[1]=="FD" || $lign[1]=="GF" || $lign[1]=="FV" || $lign[1]=="FO")
            {
              $montant_total_factures+=$lign[2];
            }
            $fact+=CommandeArticle::getSumQuantiteByNoCommande($lign[0]);
          }
        }
        $fact=arrondi_1_ct($fact);
        $rest=Atelier::getSumTempByDate($date, 2);
        $pot = 0;
        for ($c_cpt=-6; $c_cpt <= 0; $c_cpt++)
    	{
          $c_date=mktime(0,0,0,$a_mois,$a_jour+$c_cpt,$a_annee);
          $c_jour = date("d",$c_date);
          $c_mois = date("m",$c_date);
          $c_annee = date("Y",$c_date);
          $pot += get_potentiel_atelier_tous($c_jour, $c_mois, $c_annee);
          //$c_dates .= $c_jour . "." . $c_mois . "." . $c_annee . " ";
    	}
    	$pot=Arrondi_1_ct($pot);
    	if ($pot != 0)
    	{
    	  echo "<TR><TH>Total</TH><TH>$tot</TH><TH>$pot</TH><TH>$rest</TH><TH>$fact</TH><TH>".round(100*$fact/$pot)."</TH></TR>\n";
    	}
        echo "</TABLE></TD><TD COLSPAN='".(1+$nb_pret)."'>";
		if (As_Right_Groupe(6))
		{
			echo "Montant facturé ".Arrondi_5_ct($montant_total_factures);
		}
		echo "</TD></TR>\n";
    	echo "<TR class='tr_sep_jour'><TD class='td_sep_jour' COLSPAN='2".(5+$nb_pret)."'></TD></TR>\n";
    }
  }
  echo "</TABLE>\n";
  //$firephp->log($tab_debug, "array");
  echo "<TABLE class='table_av_ap'><TR><TD><form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='2'>";
  $date=mktime(0,0,0,$mois,$jour-7,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  echo "<INPUT type='hidden' name='jour' value='$a_jour'><INPUT type='hidden' name='mois' value='$a_mois'><INPUT type='hidden' name='annee' value='$a_annee'>";
  echo "<INPUT type='submit' class='button bt_av' value='' /></form></TD>";
  echo "<TD><form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='2'>";
  $date=mktime(0,0,0,$mois,$jour+7,$annee);
  $a_jour = date("d",$date);
  $a_mois = date("m",$date);
  $a_annee = date("Y",$date);
  echo "<INPUT type='hidden' name='jour' value='$a_jour'><INPUT type='hidden' name='mois' value='$a_mois'><INPUT type='hidden' name='annee' value='$a_annee'>";
  echo "<INPUT type='submit' class='button bt_ap' value='' /></form></TD>\n";
  echo "<form><INPUT type='hidden' name='Type' value='5'><INPUT type='hidden' name='Sous_Type' value='2'>";
  echo "<TH>Jour</TH><TD><INPUT type='text' name='jour' value='$jour' size=2></TD>";
  echo "<TH>Mois</TH><TD><INPUT type='text' name='mois' value='$mois' size=2></TD>";
  echo "<TH>Annee</TH><TD><INPUT type='text' name='annee' value='$annee' size=4></TD><TD><INPUT type='submit' class='button' value='GO' /></TD></TR>";
  echo "</TABLE>";
  echo "</form>";
?>
</div>