<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.9

Copyright (C) 2006-2009  Sylvain FATOME
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_co.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ope.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_taxes.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
Archivelog(@$_SESSION["code_log"]);

$cc = strip_tags(trim($_GET['cc']));	// Récupération code client
$tco = strip_tags(trim($_GET['tco']));	// Récupération type contrat ("a" : actifs, "c" : clots, rien : tous)

$pbm_cocl = FALSE;
$tab_cli=array();

// Niveau 1
if (@$_SESSION["niv_log"] == 1)
{
	$tab_cli=give_tab_rcli($_SESSION["code_log"],TRUE);
	if (in_array($cc,$tab_cli)==FALSE)
		$pbm_cocl=TRUE;
}
else
	$tab_cli[]=$cc;
	
if ($cc == "")
	$pbm_cocl = TRUE;
else
{
	$row = lit_enr_cli($cc,TRUE);
	if (is_array($row))
	{
		extract($row);
		// Contrôle qu'une agence n'essaye pas de "hacker" un client
		if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		{
			if (client_age_ok($cli_code,@$_SESSION["code_age"],TRUE)==FALSE)
				$pbm_cocl = TRUE;
		}
	}
	else
		$pbm_cocl=TRUE;
}

// Niveau 2 = interdit
if (@$_SESSION["niv_log"] == 2)
	$pbm_cocl = TRUE;

if (($tco<>"") AND ($tco<>"o") AND ($tco<>"c"))
	$pbm_cocl = TRUE;

if ($pbm_cocl == FALSE)
{
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	$rech = " SELECT * FROM ".TBCOCL;
	if(!stristr($rech,"WHERE "))
	 $rech .= " WHERE ";
	else
	 $rech .= " AND ";
	if (count($tab_cli)>1)
		$rech .= "(";
	foreach($tab_cli as $key=>$value)
	{
		$rech .= " ".TBCOCL.".cocl_codecli='".$value."' OR";
	}
	// Suppression du dernier 'OR'
	$rech = substr($rech,0,strlen($rech)-3);

	if (count($tab_cli)>1)
		$rech .=")";
	if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		$rech .= " AND cocl_codeage='".@$_SESSION["code_age"]."'";
	if ($tco=="o")
		$rech .= " AND cocl_datefin='0000-00-00'";
	if ($tco=="c")
		$rech .= " AND cocl_datefin<>'0000-00-00'";
	$rech .= " ORDER BY cocl_code";

	$rs = mysql_query($rech) or die(mysql_error());

	include_once('../classes/fpdf/fpdf.php');
	include_once('../inc/fpdf_ext.inc.php');

	$pdf=new PDF();
	$pdf->FPDF('P','mm','A4');
	$pdf->SetDisplayMode('real');
	$pdf->AliasNbPages();
	$pdf->SetTitle('Synthèse de contrat');
	$pdf->SetSubject('Synthèse de Contrat');
	$pdf->settheader("coclsm");

	if (mysql_num_rows($rs) > 0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{         
			$pdf->AddPage();

			extract ($row);

			$cocl_datecreaf = formatedate($cocl_datecrea);
			$cocl_datesigf = formatedate($cocl_datesig);
			$cocl_datefinf = formatedate($cocl_datefin);
		
			$rech2 = "SELECT * FROM `" .TBCO. "` WHERE `co_code` = '$cocl_codeco'";
			$rs2 = mysql_query($rech2)or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
				extract ($row2);
			mysql_free_result($rs2);
			
			$pv_det_cli = $pv_ent_age; // Récupération de la position sous l'entête agence pour le pointeur détail client
		
			$pdf->SetLineWidth(0.4);
		
			// Impression du détail client
			$pdf->SetY($pv_det_cli); // Renvoie le pointeur SOUS l'entête agence
		
			$pdf->SetFont('Arial','BU',12); // Titre
			$pdf->Cell(190,5,'CLIENT','LTR',1,'C');
			
			$ent_cli = ""; // Détail
			$row = lit_enr_cli($cocl_codecli,FALSE);
			if (is_array($row))
			{
				extract($row);
				if ($cli_ste <>"") 
				{
					$ent_cli.=$cli_ste."\n";
					$ent_cli.= $cli_civilite." ".$cli_prenom." ".$cli_nom."\n";
				}
				else
				{
					$ent_cli.= $cli_civilite." ".$cli_prenom." ".$cli_nom."\n\n"; // Double saut pour compenser le manque de la société
				}
				$pdf->SetFont('Arial','B',10);
				$pdf->MultiCell(190,4,$ent_cli,'LR','L');
			
				$ent_cli = $cli_adr1."\n"; // Suite...
				if (trim($cli_adr2)<>"")
					$ent_cli.= $cli_adr2."\n";
				$ent_cli.= Retournecp_openId($cli_ville,FALSE)." ".Retourneville_openId($cli_ville,FALSE)."\n";
				$ent_cli.= "Tel : ".$cli_telf."\n";
				$ent_cli.= "Fax : ".$cli_fax;
				if (trim($cli_tvai)<>"")
					$ent_cli.= "\nTVA : ".$cli_tvai;
				$pdf->SetFont('Arial','',10);
				$pdf->MultiCell(190,4,$ent_cli,'LRB','L');
			}
		
			/**********************************/
			/* Impression de la fiche contrat */
			/**********************************/
		
			$pdf->Ln(1);
			$pdf->SetFont('Arial','',10);
			$pdf->SetFillColor(0);
			$pdf->SetTextColor(255);
			$pdf->Cell(80,5,'Contrat : '.$cocl_code,1,0,'C',1);
			$pdf->SetFillColor(255);
			$pdf->SetTextColor(0);

			$echeance_ok = TRUE;
			$txterr="";
			if (formatedate($cocl_datef) <> "")
			{
				if (echeance_depassee_date($datea,$cocl_datef) == TRUE)
					$echeance_ok = FALSE;
			}
			if ((formatedate($cocl_datesig) == "") OR (formatedate($cocl_datefin) <> "") OR ($echeance_ok == FALSE))
			{
				if (formatedate($cocl_datesig) == "")
				{
					$txterr.="Non Signé";
					if ((formatedate($cocl_datefin) <> "") OR ($echeance_ok == FALSE))
						$txterr.=" / ";
				}
				if ((formatedate($cocl_datefin) <> "") OR ($echeance_ok == FALSE))
					$txterr.="Terminé";
			}
			if ($txterr<>"")
			{
				$pdf->Cell(40,5,'Créé le '.formatedate($cocl_datecrea),0,0,'C',0);
				$pdf->SetFont('Arial','BI',10);
				$pdf->Cell(70,5,$txterr,0,1,'C',0);
			}
			else
				$pdf->Cell(40,5,'Créé le '.formatedate($cocl_datecrea),0,1,'C',0);

			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Site Principal : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			if ($cocl_sitep==1)
				$pdf->Cell(30,4,'Oui',0,1,'L',0);
			else
				$pdf->Cell(30,4,'Non',0,1,'L',0);
			$lstsites = cree_str_lstsites_cocl($cocl_code,FALSE);
			if ($lstsites<>"")
			{
				$pdf->SetFont('Arial','B',8);
				$pdf->Cell(30,4,'Sites Secondaires : ',0,0,'R',0);
				$pdf->SetFont('Arial','',8);
				$tab_scli=explode("-",$lstsites);
				foreach ($tab_scli as $key=>$value)
				{
					if ($key<>0)
						$pdf->Cell(30);
					$nom_site="";
					$rech2 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_id` = '$value'";
					$rs2 = mysql_query($rech2)or die(mysql_error());
					if ($row2 = mysql_fetch_array($rs2))
					{
						extract($row2);
						$nom_site.= $scli_ste;
						$nom_site.=", ";
						$nom_site.= $scli_adr1;
						$nom_site.=", ";
						if ($scli_adr2<>"")
						{
							$nom_site.= $scli_adr2;
							$nom_site.=", ";
						}
						$nom_site.= Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE);
					}
					mysql_free_result($rs2);
					$pdf->Cell(30,4,$nom_site,0,1,'L',0);
				}
			}
			// Agence
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Agence : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$rech2 = "SELECT * FROM " .TBAGE. " WHERE age_code = '$cocl_codeage'";
			$rs2 = mysql_query($rech2)or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
				extract($row2);
			mysql_free_result($rs2);
			$age_nomcode = $age_nom." (".$age_code.")";
			$pdf->Cell(95,4,$age_nomcode,0,1,'L',0);
			// Contrat type
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Contrat type : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$co_nom,0,1,'L',0);
			// Fréquence
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Fréquence : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$rech2 = "SELECT * FROM ".TBPER." WHERE `per_code` = '".$cocl_codeper."'";
			$rs2 = mysql_query($rech2) or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
				extract ($row2);
			mysql_free_result($rs2);
			$pdf->Cell(160,4,$per_desc,0,1,'L',0);
			// Délai
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Délai : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$cocl_delai." heures ouvrées",0,1,'L',0);
			// Temps / Type
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Temps / Type : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,heure_to_hhmm(sec_heure($cocl_nbs,3,TRUE))." / ".$typ_horaire[$cocl_typh],0,1,'L',0);
			if ($cocl_typh==1)
			{
				$pdf->Cell(30);
				$pdf->SetFont('Arial','I',7);
				$pdf->Cell(160,4,"Solde : ".heure_to_hhmm(sec_heure(soldes_reel_contrat($cocl_code,FALSE),3,TRUE))." (Heures à sortir : ".heure_to_hhmm(sec_heure(tps_trav_non_clot($cocl_code,FALSE),3,TRUE)).")",0,1,'L',0);
			}
			// Création de la liste des reports affectés à ce contrat (s'il y en a)
			$rech2 = "SELECT * FROM ".TBCOCLR." WHERE coclr_cocldest = '".$cocl_code."' ORDER BY coclr_codeint";
			$rs2 = mysql_query($rech2) or die(mysql_error());
			
			if (mysql_num_rows($rs2) <> 0)
			{
				$totalreport=0;
			
				// Titres
				$pdf->SetLineWidth(0.1);
				$pdf->SetFont('Arial','IU',7);
				$pdf->Cell(30,4,'',0,0,'R',0);
				$pdf->Cell(120,4,'Détails des reports affectés à ce contrat',1,0,'C');
				$pdf->Cell(30,4,'Durée',1,1,'C');
				$pdf->SetFont('Arial','I',8);
				
				while ($row2 = mysql_fetch_assoc($rs2)) 
				{         
					extract($row2);
					$pdf->Cell(30,4,'',0,0,'R',0);
					if ($coclr_nbsrep>0)
						$txt="Report non ";
					else
						$txt="Déduction sur-";
					$txt.="consommé du contrat ".$coclr_coclori;
					if ($coclr_codeint<>'')
						$txt.=" (Intervention ".$coclr_codeint.")";
					else
						$txt.=" (Clôture manuelle)";
					$pdf->Cell(120,4,$txt,1,0,'L');
			
					$pdf->Cell(30,4,heure_to_hhmm(sec_heure($coclr_nbsrep,3,TRUE)),1,1,'C');
					$totalreport=$totalreport+$coclr_nbsrep;
				}
				$PosY = $pdf->GetY();
				$pdf->Line(40,$PosY,150,$PosY); // On "ferme" le tableau
				$pdf->SetLineWidth(0.2);
				$pdf->Cell(150,4,'Total général : ',0,0,'R',0);
				$pdf->Cell(30,4,heure_to_hhmm(sec_heure($totalreport,3,TRUE)),0,1,'C');
			}
			mysql_free_result($rs2);
			// Report heures non consommées
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Report heures non cons. : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$non_oui[$cocl_nbsnc],0,1,'L',0);
			// Report heures dépassées
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Report heures dépassées : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$non_oui[$cocl_nbsdep],0,1,'L',0);
			// Validité
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Validité : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$txtval=formatedate($cocl_dated).$txt_div_to;
			if (formatedate($cocl_datef)<>"")
				$txtval.=formatedate($cocl_datef);
			else
				$txtval.=" --- ";
			$pdf->Cell(160,4,$txtval.", avec préavis de ".$cocl_preavis." jours.",0,1,'L',0);
			// Renouvellement automatique
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Renouvellement auto. : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$non_oui[$cocl_renauto],0,1,'L',0);
			// Matériel
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Matériel : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->MultiCell(160,4,htmlspecialchars($cocl_matos,ENT_QUOTES),0,'L');
			// Date Signature
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Signé le : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,formatedate($cocl_datesig),0,1,'L',0);
			// Signé par
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Signé par : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$cocl_signe,0,1,'L',0);
			// Relancé
			if (formatedate($cocl_daterel) <> "")
			{
				$pdf->SetFont('Arial','B',8);
				$pdf->Cell(30,4,'Relancé : ',0,0,'R',0);
				$pdf->SetFont('Arial','',8);
				$pdf->Cell(160,4,formatedate($cocl_daterel)."(".$cocl_nivrel." fois)",0,1,'L',0);
			}

			if (formatedate($cocl_datesig) <> "")
			{
				// Renouvelé
				$pdf->SetFont('Arial','B',8);
				$pdf->Cell(30,4,'Renouvelé : ',0,0,'R',0);
				$pdf->SetFont('Arial','',8);
				$txtrnum=$non_oui[$cocl_renouv];
				if ($cocl_rnum<>"")
					$txtrnum.=" (Nouveau contrat : ".$cocl_rnum.")";
				$pdf->Cell(160,4,$txtrnum,0,1,'L',0);
				
				// Clôt
				$pdf->SetFont('Arial','B',8);
				$pdf->Cell(30,4,'Clôt le : ',0,0,'R',0);
				$pdf->SetFont('Arial','',8);
				$pdf->Cell(160,4,formatedate($cocl_datefin),0,1,'L',0);
			}
			// Prix HT
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'PV HT : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(160,4,$cocl_pvht." ".$lang['symbole_monnaie_txt'],0,1,'L',0);

			// TVA
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'TVA : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$row=lit_enr_tva($cocl_codetva,FALSE);
			if (is_array($row))
				extract($row);
			$pdf->Cell(160,4,$tva_desc." (".format_num($tva_tx,2)."%)",0,1,'L',0);

			// Prix TTC
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'PV TTC : ',0,0,'R',0);
			$pdf->SetFont('Arial','',8);
			$txtva=$tva_tx/100;
			$pvttc=round(($cocl_pvht*(1+$txtva))*100)/100;
			$pdf->Cell(160,4,format_num($pvttc,2)." ".$lang['symbole_monnaie_txt'],0,1,'L',0);

			/**************/
			/* Historique */
			/**************/
			$pdf->Ln(2);
			$pdf->SetFont('Arial','BU',10);
			$pdf->Cell(190,5,'HISTORIQUE','',1,'C');
			$pdf->Ln(2);

			$rech2 = "SELECT ".TBINT.".int_code, ".TBINT.".int_datedde, ".TBINT.".int_codecli, ".TBINT.".int_codecocl, ";
			$rech2.= TBINT.".int_codeage, ".TBINT.".int_daterdv, ".TBINT.".int_durees, ".TBINT.".int_codestatut, ";
			$rech2.= TBINT.".int_datefin, ".TBCOCLH.".coclh_codecli, ".TBCOCLH.".coclh_codecocl, ".TBCOCLH.".coclh_codeint ";
			$rech2.= "FROM ".TBINT.", ".TBCOCLH;
			$rech2.= " WHERE ".TBINT.".int_codecocl = '".$cocl_code."'";
			$rech2.= " AND ".TBINT.".int_code = ".TBCOCLH.".coclh_codeint";
			$rs2 = mysql_query($rech2) or die(mysql_error());

			if (mysql_num_rows($rs2) <> 0)
			{
				// Titres
				$pdf->SetFont('Arial','IU',7);
				$pdf->Cell(30,4,'Intervention',1,0,'C');
				$pdf->Cell(14,4,'Début',1,0,'C');
				$pdf->Cell(14,4,'RDV',1,0,'C');
				$pdf->Cell(14,4,'Fin',1,0,'C');
				$pdf->Cell(30,4,'Agence',1,0,'C');
				$pdf->Cell(40,4,'Durée',1,0,'C');
				$pdf->Cell(45,4,'Statut',1,1,'C');
				$pdf->SetFont('Arial','I',8);
				
				$totalgen=0;
				$totalgenoff=0;

				while ($row2 = mysql_fetch_assoc($rs2)) 
				{         
					extract($row2);
					$pdf->SetFont('Arial','',7);
					$pdf->Cell(30,4,$int_code,'LR',0,'L');
					$pdf->Cell(14,4,formatedate($int_datedde),'LR',0,'C');
					if (formatedate($int_daterdv) <> "")
						$pdf->Cell(14,4,formatedate($int_daterdv),'LR',0,'C');
					else
						$pdf->Cell(14,4,"-",'LR',0,'C');
					if (formatedate($int_datefin) <> "")
						$pdf->Cell(14,4,formatedate($int_datefin),'LR',0,'C');
					else
						$pdf->Cell(14,4,"-",'LR',0,'C');
					$pdf->Cell(30,4,$int_codeage,'LR',0,'C');

					// Récupération du total travaillé
					$nbtotalsec = 0;
					$nbtotalsecoff = 0;
				
					// Récupération total travaillé
					$rech3 = "SELECT * FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$int_code."'";
					$rs3 = mysql_query($rech3) or die(mysql_error());
					if (mysql_num_rows($rs3) <> 0)
					{
						while ($row3 = mysql_fetch_assoc($rs3)) 
						{         
							$nbtotalsec = $nbtotalsec + diff_time_sec($row3["inth_heurea"],$row3["inth_heured"]);
							if ($row3["inth_offert"] == 1)
								$nbtotalsecoff = $nbtotalsecoff + diff_time_sec($row3["inth_heurea"],$row3["inth_heured"]);
						}
					}
					
					$totalgen+=$nbtotalsec;
					$totalgenoff+=$nbtotalsecoff;
		
					// Si un utilisateur a quitté avant de sauver (bien qu'ayant modifié le détail horaire,
					// on remet en état car seul le détail horaire et technicien enregistré est valable
					if ($int_durees <> $nbtotalsec)
					{
						$rech3 = "UPDATE `" .TBINT. "` SET `int_datemod`='".$datea."', `int_codemod`='".$codeuser."',`int_durees`='".$nbtotalsec."'";
						$rech3 .=" WHERE `int_code` = '".$int_code."'";
						$rs3 = mysql_query($rech3) or die(mysql_error());
						$int_durees = $nbtotalsec;
					}
		
					 $txttps="";
					 if ($int_durees <> 0)
						$txttps.=heure_to_hhmm(sec_heure($int_durees,3,TRUE));
					 else
						$txttps.="-";
					if ($nbtotalsecoff<>0)
						$txttps.=" (Offert : ".heure_to_hhmm(sec_heure($nbtotalsecoff,3,TRUE)).")";
					if ($txttps<>"")
						$pdf->Cell(40,4,$txttps,'LR',0,'C');
					else
						$pdf->Cell(40,4,"-",'LR',0,'C');

					// Statut
					 $rechico = "SELECT * FROM ".TBSTA." WHERE statut_code = '$int_codestatut'";
					 
					 $rsico = mysql_query($rechico) or die(mysql_error());
					 $txtstatut="";
					 
					if (mysql_num_rows($rsico) <> 0)
					{
						if ($rowico = mysql_fetch_array($rsico))
						{
							extract ($rowico);
							$txtstatut=$statut_desc;
						}
					}
					mysql_free_result($rsico);
					if ($txtstatut<>"")
						$pdf->Cell(45,4,$txtstatut,'LR',1,'C');
					else
						$pdf->Cell(45,4,$int_codestatut,'LR',1,'C');
					
				}
				$PosY = $pdf->GetY();
				$pdf->Line(10,$PosY,197,$PosY); // On "ferme" le tableau

				// Totaux
				$pdf->SetFont('Arial','I',7);
				$pdf->Cell(72,4,'',0,0,'C');
				$pdf->Cell(30,4,'Total général : ',0,0,'R');
				 if ($totalgen <> 0)
					$pdf->Cell(40,4,heure_to_hhmm(sec_heure($totalgen,3,TRUE)),0,1,'C');
				 else
					$pdf->Cell(40,4,"-",0,1,'C');

				if ($totalgenoff <> 0)
				{
					$pdf->SetFont('Arial','I',7);
					$pdf->Cell(72,4,'',0,0,'C');
					$pdf->Cell(30,4,'Dont offert : ',0,0,'R');
					$pdf->Cell(40,4,heure_to_hhlmm(sec_heure($totalgenoff,3,TRUE)),0,1,'C');
				}
			}
			else
			{
				$pdf->SetFont('Arial','BI',8);
				$pdf->Cell(190,4,'Aucun historique pour ce contrat',0,1,'C',0);
				$pdf->SetFont('Arial','',8);
			}
		}
	}
	else
	{
		$pdf->AddPage();
		$pv_det_cli = $pv_ent_age; // Récupération de la position sous l'entête agence pour le pointeur détail client
		$pdf->SetLineWidth(0.4);
		$pdf->SetY($pv_det_cli); // Renvoie le pointeur SOUS l'entête agence
		$pdf->SetFont('Arial','BI',8);
		switch ($tco)
		{
			case "o" :
				$pdf->Cell(190,4,'Aucun contrat ouvert pour ce client',0,1,'C',0);
				break;
			case "c" :
				$pdf->Cell(190,4,'Aucun contrat clot pour ce client',0,1,'C',0);
				break;
			default :
				$pdf->Cell(190,4,'Aucun contrat pour ce client',0,1,'C',0);
				break;
		}
		$pdf->SetFont('Arial','',8);
	}
	$pdf->Output('Contrat_'.$cocl_code,'I');

	mysql_free_result($rs);
	mysql_close($conn);
}
?>