<?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");

if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
include_once("../inc/config.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_pdt.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_taxes.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$pbm_pdt=FALSE;
$dureemini=0;
$nbs_couv=0;
$nbsc_barloc=0;

if (isset($_GET['td']))
	$td = strip_tags(trim(@$_GET['td']));
else
{
	if (isset($_POST['td']))
		$td = strip_tags(trim(@$_POST['td']));
	else
		$pbm_pdt=TRUE;
}
if (isset($_GET['cl']))
	$codecoloc = strip_tags(trim(@$_GET['cl']));
else
{
	if (isset($_POST['cl']))
		$codecoloc = strip_tags(trim(@$_POST['cl']));
	else
		$pbm_pdt=TRUE;
}
if (isset($_GET['ca']))
	$codeart = strip_tags(trim(@$_GET['ca']));
else
{
	if (isset($_POST['ca']))
		$codeart = strip_tags(trim(@$_POST['ca']));
	else
		$pbm_pdt=TRUE;
}
$dd="";
if (isset($_GET["dd"]))
	$dd=strip_tags(trim(@$_GET["dd"]));
else
{
	if (isset($_POST['dd']))
		$dd = strip_tags(trim(@$_POST['dd']));
	else
		$pbm_pdt=TRUE;
}
$hd="";
if (isset($_GET["hd"]))
	$hd=strip_tags(trim(@$_GET["hd"]));
else
{
	if (isset($_POST['hd']))
		$hd = strip_tags(trim(@$_POST['hd']));
	else
		$pbm_pdt=TRUE;
}
$df="";
if (isset($_GET["df"]))
	$df=strip_tags(trim(@$_GET["df"]));
else
{
	if (isset($_POST['df']))
		$df = strip_tags(trim(@$_POST['df']));
	else
		$pbm_pdt=TRUE;
}
$hf="";
if (isset($_GET["hf"]))
	$hf=strip_tags(trim(@$_GET["hf"]));
else
{
	if (isset($_POST['hf']))
		$hf = strip_tags(trim(@$_POST['hf']));
	else
		$pbm_pdt=TRUE;
}
if (isset($_GET["ibl"]))
{
	$ibl=intval(strip_tags(trim(@$_GET["ibl"])));
	if (($ibl==0) OR ($ibl<-1))
		$pbm_pdt=TRUE;
}
else
{
	if (isset($_POST['ibl']))
		$ibl = intval(strip_tags(trim(@$_POST['ibl'])));
	else
		$ibl=-2;
}
if ((datefrcorrecte($dd)==FALSE) OR (datefrcorrecte($df)==FALSE))
	$pbm_pdt=TRUE;

if ((heurecorrecte($hd.':00')==FALSE) OR (heurecorrecte($hf.':00')==FALSE))
	$pbm_pdt=TRUE;

if ($pbm_pdt==FALSE)
{
	$njour=njour_semaine(datefrang($dd));
	
	$nbjours=diff_date_jours(datefrang($dd),datefrang($df),FALSE);
	$dureemini= diff_dateheure_sec($dd.' '.$hd.':00',$df.' '.$hf.':00');

	if ($codecoloc <> "")
	{
		// Récupération des données du contrat de location
		$row=lit_enr_coloc($codecoloc);
		if (is_array($row))
		{
			extract ($row);
		
			if ($td <> "add")
			{
				// Contrôle qu'un client n'essaye pas de "hacker" un contrat
				if ((@$_SESSION["niv_log"] == 1) AND ($coloc_codecli <> @$_SESSION["code_log"]))
					$pbm_pdt = TRUE;
		
				// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
				if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($coloc_codeage <> @$_SESSION["code_age"]))
					$pbm_pdt = TRUE;
			}
	
			if ($pbm_pdt==FALSE)
			{
				switch ($coloc_typcli)
				{
					case 0 :
						$row=lit_enr_cli($coloc_codecli,TRUE);
						break;
					case 1 :
						$row=lit_enr_age($coloc_codecli,TRUE);
						break;
					case 3 :
						$row=lit_enr_st($coloc_codecli,TRUE);
						break;
				}
				if (is_array($row))
				{
					extract ($row);
					
					switch ($coloc_typcli)
					{
						case 0 :
							// Contrôle qu'une agence n'essaye pas de "hacker" un contrat
							switch(@$_SESSION["niv_log"])
							{
								case 3 :
								case 4 :
									if (client_age_ok($cli_code,@$_SESSION["code_age"],TRUE)==FALSE)
										$pbm_pdt = TRUE;
									break;
								default :
									break;
							}
							break;
					}
						
					if ($pbm_pdt==FALSE)
					{
						$udesc1="";
						$udesc2="";
						if ($td=="add")
						{
							// Récupération des données de la fiche article
							$row = lit_enr_pdtloc($codeart);
							if (is_array($row))
							{
								extract ($row);
						
								// Récupération des information unité consommable
								$pdtlbl_pdtuconsi1=$pdtloc_pdtucons1;
								$pdtlbl_pdtuconsi2=$pdtloc_pdtucons2;
								$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
								mysql_select_db(DBNAME);
								$rech = "SELECT * FROM ".TBPDTU." WHERE pdtu_code='".$pdtloc_pdtucons1."'";
								$rs = mysql_query($rech)or die(mysql_error());
								if ($resultat = mysql_fetch_array($rs)) 
								{
									extract($resultat);
									$udesc1=$pdtu_abr;
								}
								$rech = "SELECT * FROM ".TBPDTU." WHERE pdtu_code='".$pdtloc_pdtucons2."'";
								$rs = mysql_query($rech)or die(mysql_error());
								if ($resultat = mysql_fetch_array($rs)) 
								{
									extract($resultat);
									$udesc2=$pdtu_abr;
								}
								mysql_free_result($rs);
								mysql_close($conn);
							
								// Initialisation caution
								$pdtlbl_caution=$pdtloc_caution;
								// Initialisation code TVA
								if ($cli_modfact==2)
									$pdtlbl_tvacaut="TVA0";
								else
									$pdtlbl_tvacaut=$pdtloc_tvacaut;
								// Récupération des informations TVA caution
								$row = lit_enr_tva($pdtlbl_tvacaut,TRUE);
								if (is_array($row))
									extract ($row);
								$txtvacaut=$tva_tx/100;
								$cautionttc=round(($pdtlbl_caution*(1+$txtvacaut))*100)/100;
								
								$puht=0;
								$pdtlbl_codetva="TVA0";
						
								if ($ibl>0)
								{
									$row=lit_enr_barloc_id($ibl,TRUE);
									if (is_array($row))
									{
										extract($row);
										if ($barloc_actif==1)
										{
											// Initialisation tarif de vente
											$pdtlbl_pvht=$barloc_pvht;
											$pdtlbl_puconsi1=$barloc_puconsi1;
											$pdtlbl_puconsi2=$barloc_puconsi2;
											// Initialisation code TVA
											if ($cli_modfact==2)
												$pdtlbl_codetva="TVA0";
											else
												$pdtlbl_codetva=$barloc_codetva;
											// Récupération des informations TVA tarif
											$row = lit_enr_tva($pdtlbl_codetva,TRUE);
											if (is_array($row))
												extract ($row);
											$txtva=$tva_tx/100;
												
											$pvttc=round(($pdtlbl_pvht*(1+$txtva))*100)/100;
											$pvttcconsi1=round(($barloc_puconsi1*(1+$txtva))*100)/100;
											$pvttcconsi2=round(($barloc_puconsi2*(1+$txtva))*100)/100;
								
											// Initialisation tarif assurance
											$pdtlbl_mtass=$barloc_mtass;
											// Initialisation code TVA
											if ($cli_modfact==2)
												$pdtlbl_codetva="TVA0";
											else
												$pdtlbl_codetvaass=$barloc_codetvaass;
											// Récupération des informations TVA assurance
											$row = lit_enr_tva($pdtlbl_codetvaass,TRUE);
											if (is_array($row))
												extract ($row);
											$txtvaass=$tva_tx/100;
											$pvttcass=round(($pdtlbl_mtass*(1+$txtvaass))*100)/100;
		
											// Durée (secondes) couverte par ce barême pour une unité
											$nbsc_barloc=nbsc_in_barloc_barloc($ibl,TRUE);
										}
										else
											$pbm_pdt=TRUE;
									}
									else
										$pbm_pdt=TRUE;
								}
								else
								{
									if ($ibl==-1) 
										$nbsc_barloc=$dureemini;
								}
							}
							else
								$pbm_pdt=TRUE;
						}
						else
						{
							$ibl=$_SESSION["pdtlbl"][0]["idbarloc"];
							$pdtlbl_qte=$_SESSION["pdtlbl"][0]["qte"];
							$pdtlbl_pvht=$_SESSION["pdtlbl"][0]["pvht"];
							$pdtlbl_codetva=$_SESSION["pdtlbl"][0]["codetva"];
							$pdtlbl_caution=$_SESSION["pdtlbl"][0]["caution"];
							$pdtlbl_tvacaut=$_SESSION["pdtlbl"][0]["tvacaut"];
							$pdtlbl_avecass=$_SESSION["pdtlbl"][0]["avecass"];
							$pdtlbl_mtass=$_SESSION["pdtlbl"][0]["mtass"];
							$pdtlbl_tvaass=$_SESSION["pdtlbl"][0]["tvaass"];
							$pdtlbl_codetvaass=$_SESSION["pdtlbl"][0]["codetvaass"];
							$pdtlbl_qconsi1=$_SESSION["pdtlbl"][0]["qconsi1"];
							$pdtlbl_pdtuconsi1=$_SESSION["pdtlbl"][0]["pdtuconsi1"];
							$pdtlbl_puconsi1=$_SESSION["pdtlbl"][0]["puconsi1"];
							$pdtlbl_qconsi2=$_SESSION["pdtlbl"][0]["qconsi2"];
							$pdtlbl_pdtuconsi2=$_SESSION["pdtlbl"][0]["pdtuconsi2"];
							$pdtlbl_puconsi2=$_SESSION["pdtlbl"][0]["puconsi2"];

							// Récupération des informations TVA caution
							$row = lit_enr_tva($pdtlbl_tvacaut,TRUE);
							if (is_array($row))
								extract ($row);
							$txtvacaut=$tva_tx/100;
							$cautionttc=round(($pdtlbl_caution*(1+$txtvacaut))*100)/100;

							// Récupération des informations TVA tarif
							$row = lit_enr_tva($pdtlbl_codetva,TRUE);
							if (is_array($row))
								extract ($row);
							$txtva=$tva_tx/100;
							$pvttc=round(($pdtlbl_pvht*(1+$txtva))*100)/100;
							$pvttcconsi1=round(($pdtlbl_puconsi1*(1+$txtva))*100)/100;
							$pvttcconsi2=round(($pdtlbl_puconsi2*(1+$txtva))*100)/100;

							// Récupération des informations TVA assurance
							$row = lit_enr_tva($pdtlbl_codetvaass,TRUE);
							if (is_array($row))
								extract ($row);
							$txtvaass=$tva_tx/100;
							$pvttcass=round(($pdtlbl_mtass*(1+$txtvaass))*100)/100;

							$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
							mysql_select_db(DBNAME);
							$rech = "SELECT * FROM ".TBPDTU." WHERE pdtu_code='".$pdtlbl_pdtuconsi1."'";
							$rs = mysql_query($rech)or die(mysql_error());
							if ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
								$udesc1=$pdtu_abr;
							}
							$rech = "SELECT * FROM ".TBPDTU." WHERE pdtu_code='".$pdtlbl_pdtuconsi2."'";
							$rs = mysql_query($rech)or die(mysql_error());
							if ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
								$udesc2=$pdtu_abr;
							}
							mysql_free_result($rs);
							mysql_close($conn);
						}
					}
				}
			}
			else
				$pbm_pdt=TRUE;
		}
		else
			$pbm_pdt=TRUE;
	}			
	else
		$pbm_pdt=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "CHOIX BAREME";
		if (($ibl<>-2) && ($ibl<>0))
			$pdtlbl_qte=($dureemini/$nbsc_barloc);
		if ($ibl==0)
			$pdtlbl_qte=$nbjours;
		switch ($barloc_typarr)
		{
			case 1 :
				$pdtlbl_qte=floor($pdtlbl_qte);
				break;
			case 2 :
				$pdtlbl_qte=ceil($pdtlbl_qte);
				break;
			default :
				$pdtlbl_qte=round($pdtlbl_qte,2);
				break;
		}
		$pdtlbl_avecass	=1;
		break;
	case "edit" :
		$titre = "EDITION BAREME";
		if (isset($_SESSION["pdtlbl"]))
		{
			if (count($_SESSION["pdtlbl"])==0)
				$pbm_pdt==TRUE;
		}
		break;
	case "del" :
		$titre = "SUPPRESSION BAREME";
		if (isset($_SESSION["pdtlbl"]))
		{
			if (count($_SESSION["pdtlbl"])==0)
				$pbm_pdt==TRUE;
		}
		break;
	default :
		$pbm_pdt=TRUE;
		break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : Article (Bar&ecirc;me Location)</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->

<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<script language="javascript">
<!--
var tab1_champ=new Array(
<?PHP if ($td=="add") { ?>
	"nom:ibl ; format:liste ; req:Y ; txt:Barême ; vmn : 1 ; stok:frmok ; stbad:frmbad");
<?PHP } else { ?>
	"nom:qte ; format:reel ; req:Y ; txt:Quantité ; vmn : 0.01 ; stok:frmok ; stbad:frmbad");
<?PHP } ?>
//-->
</script>

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

<!-- Scripts Javascript sur les champs -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

</head>

<body onLoad="metFocus();">

<?PHP
if ($pbm_pdt==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour la location du produit <?php echo $pdtloc_des; ?></span><br />
<span class="annot_petit_gras">Du <?php echo $dd." ".$hd; ?> au <?php echo $df." ".$hf; ?></span></p>

<form name="pdtlbl_maj" method="post" action="<?PHP if ($ibl==-2) echo "pdtlbl_maj.php"; else echo "pdtlbl_enr.php"; ?>" onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
	<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
    <input name="cl" type="hidden" id="cl" value="<?PHP echo $codecoloc ?>">
    <input name="ca" type="hidden" id="ca" value="<?PHP echo $codeart ?>">
    <input name="dd" type="hidden" id="dd" value="<?PHP echo $dd ?>">
    <input name="hd" type="hidden" id="dd" value="<?PHP echo $hd ?>">
    <input name="df" type="hidden" id="df" value="<?PHP echo $df ?>">
    <input name="hf" type="hidden" id="df" value="<?PHP echo $hf ?>">
    <input name="dmini" type="hidden" id="dmini" value="<?PHP echo $dureemini; ?>">
    <input name="nbsc" type="hidden" id="nbsc" value="<?PHP echo $nbs_couv; ?>">
    <input name="nbscbl" type="hidden" id="nbscbl" value="<?PHP echo $nbsc_barloc; ?>">
    <input name="cpen" type="hidden" id="cpen" value="<?PHP echo $barloc_codepen; ?>">
  <table width="100%"  border="0">
    <tr>
      <td width="160" class="rubfrm" id="f_ibl" align="right">
	  <?PHP if ($ibl == -2) echo "Bar&ecirc;mes possibles"; else echo "Bar&ecirc;me"; ?>
	  </td>
      <td >
		<?PHP
		if ($ibl == -2)
		{ 
			// Création de la liste des barêmes actifs et pouvant être choisis
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			// Filtre sur barêmes actifs
			$rech = "SELECT * FROM ".TBBARLOC.", ".TBPERLOC." WHERE ".TBBARLOC.".barloc_actif = '1'";
			$rech.= " AND ".TBBARLOC.".barloc_codepdtloc = '".$codeart."'";
			$rech.= " AND (".TBBARLOC.".barloc_dateval1 <= '".datefrang($dd)."' AND (".TBBARLOC.".barloc_dateval2 >= '".datefrang($dd)."' OR ".TBBARLOC.".barloc_dateval2 = '0000-00-00')";
			$rech.= " AND (".TBBARLOC.".barloc_dateval2 >= '".datefrang($df)."' OR ".TBBARLOC.".barloc_dateval2 = '0000-00-00'))";
			$rech.= " AND ((".TBPERLOC.".perloc_jourd1 <= '".$njour."' AND ".TBPERLOC.".perloc_jourd2 >= '".$njour."') OR ".TBPERLOC.".perloc_jourd1 = '-1')";
			$rech.= " AND ((".TBPERLOC.".perloc_nduree * ".TBPERLOC.".perloc_tduree) <= ".$dureemini.")";
			$rech.= " AND ".TBBARLOC.".barloc_codeperloc = ".TBPERLOC.".perloc_code";
			$rech.= " ORDER BY ".TBBARLOC.".barloc_des";
			$rs = mysql_query($rech) or die(mysql_error());
			?>
			<select name="ibl" id="ibl">
			<?PHP
				echo '<option>-- Choisissez un barême --</option>';
				echo '<option value="0"';
				if ($ibl==-1)
					echo ' selected';
				echo '>Prêt de matériel (Gratuit)</option>';

				if (mysql_num_rows($rs) > 0)
				{
					while ($resultat = mysql_fetch_array($rs)) 
					{
						extract($resultat);
						$dureebl=$perloc_nduree*$perloc_tduree;
						$affopt=TRUE;
						
						// On vérifie dans le cas où "multiple" est à non
						if ($barloc_mult==FALSE)
						{
							if ($dureebl<>$dureemini)
								$affopt=FALSE;
						}
						if ($affopt==TRUE)
						{
							echo '<option value="'.$barloc_id.'">';
							if ($ibl==$barloc_id)
								echo ' selected';
							echo $barloc_des.' ('.$perloc_nduree.' '.$lng_tduree[$perloc_tduree].')</option>';
						}
					}
				}
			?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP
			mysql_free_result($rs);
			mysql_close($conn);
		} 
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			$txtbarloc="";
			if ($ibl<>0)
			{
				$row = lit_enr_barloc_id($ibl,TRUE);
				if (is_array($row))
				{
					extract($row);
					$txtbarloc=$barloc_des;
				}
			}
			else
				$txtbarloc="Prêt de matériel (Gratuit)";
		?>
		<input name="ibl" type="hidden" id="ibl" value="<?PHP echo $ibl; ?>" readonly="1">
		<input name="nibl" type="text" id="nibl" value="<?PHP echo $txtbarloc; ?>" size="50" readonly="1">
		<?PHP 
		} 
		?>
	  </td> 
    </tr>
	<?PHP
	if ($ibl<>-2)
	{
	?>
    <tr>
      <td class="rubfrm" id="f_qte" align="right">Quantit&eacute;<?PHP if ($ibl==-1) echo " (jours)"; ?></td>
      <td>
	  	<input name="qte" type="text" id="qte" style="text-align:right" value="<?PHP echo format_num($pdtlbl_qte,2); ?>" size="10"  readonly="1">
	  </td>
	</tr>
    <tr>
      <td class="rubfrm" id="f_assobl" align="right">Assurance</td>
      <td>
	<?PHP
	if ($ibl<>0)
	{
		if ($barloc_assobl==FALSE)
		{
			echo '<select name="assobl" size="1" id="assobl" onChange="calcul_location('.$cli_modfact.',\''.$lang["symbole_monnaie"].'\');">';
			foreach ($non_oui as $key=>$value)
			{
				echo '<option value="'.$key.'"'; 
				if ($pdtlbl_avecass==$key)
					echo ' selected';
				echo '>';
				echo $value."</option>";
			}
			echo "</select>";
		} else { ?>
	  	<input name="assobl" type="hidden" id="assobl" value="<?PHP echo $barcloc_assobl; ?>" readonly="readonly">
		<span class="annot_gras_it">Obligatoire</span>
	<?PHP } 
	}
	else
		echo '<span class="annot_gras_it">Sans assurance (pr&ecirc;t)</span>';
	?>
	  </td>
	</tr>
	<tr>
		<td class="annot_gras_it" align="center" colspan="2">D&eacute;tail montant :</td>
	</tr>
	<tr>
		<td colspan="2">
		<table width="100%"  border="0" class="MtableD">
		<th>
		Type
		</th>
		<th>
		Quantit&eacute;
		</th>
		<th>
		PU <?PHP if ($cli_modfact==1) echo " TTC"; else echo " HT"; ?>
		</th>
		<th>
		Total <?PHP if ($cli_modfact==1) echo " TTC"; else echo " HT"; ?>
		</th>
		<th>
		TVA
		</th>
		<tr>
			<td>
			<span class="annot_petit_gras">Co&ucirc;t de location</span>
			</td>
			<td class="TDnumberD">
			<span id="affqteloc"><?PHP echo $pdtlbl_qte; ?></span>
			</td>
			<td class="TDnumberD">
			<input name="pvht" type="hidden" id="pvht" value="<?PHP echo $pdtlbl_pvht; ?>" readonly="readonly">
			<input name="pvttc" type="hidden" id="pvttc" value="<?PHP echo $pvttc; ?>" readonly="readonly">
			<?PHP if ($cli_modfact==1) echo format_num($pvttc,2); else echo format_num($pdtlbl_pvht,2); echo $lang['symbole_monnaie']; ?>
			</td>
			<td class="TDnumberD">
			<span id="afftotloc">
			<?PHP 
			$totlocht=round($pdtlbl_pvht*$pdtlbl_qte*100)/100;
			$totlocttc=round($pvttc*$pdtlbl_qte*100)/100;
			$totloctva=$totlocttc-$totlocht;
			if ($cli_modfact==1) 
			echo format_num($totlocttc,2); else echo format_num($totlocht,2); echo $lang['symbole_monnaie']; ?></span>
			</td>
			<td class="TDnumberD">
			<input name="tva" type="hidden" id="tva" value="<?PHP echo $pdtlbl_codetva; ?>"> 
			<input name="txtva" type="hidden" id="txtva" value="<?PHP echo $txtva; ?>" readonly="readonly"> 
			<?PHP echo format_num($txtva*100,2)."%"; ?>
			</td>
		</tr>
		<tr>
			<td>
			<span class="annot_petit_gras">Caution</span>
			</td>
			<td class="TDnumberD">1</td>
			<td class="TDnumberD">
			<input name="caution" type="hidden" id="caution" value="<?PHP echo $pdtlbl_caution; ?>" readonly="readonly">
			<input name="cautionttc" type="hidden" id="cautionttc" value="<?PHP echo $cautionttc; ?>" readonly="readonly">
			<?PHP if ($cli_modfact==1) echo format_num($cautionttc,2); else echo format_num($pdtlbl_caution,2); echo $lang['symbole_monnaie']; ?>
			</td>
			<td class="TDnumberD">
			<span id="afftotcaut">
			<?PHP
			$totcautht=round($pdtlbl_caution*100)/100;
			$totcautttc=round($cautionttc*100)/100;
			$totcauttva=$totcautttc-$totcautht;
			if ($cli_modfact==1) echo format_num($cautionttc,2); else echo format_num($pdtlbl_caution,2); echo $lang['symbole_monnaie']; ?></span>
			</td>
			<td class="TDnumberD">
			<input name="tvacaut" type="hidden" id="tvacaut" value="<?PHP echo $pdtlbl_tvacaut; ?>"> 
			<input name="txtvacaut" type="hidden" id="txtvacaut" value="<?PHP echo $txtvacaut; ?>" readonly="readonly"> 
			<?PHP echo format_num($txtvacaut*100,2)."%"; ?>
			</td>
		</tr>
		<tr>
			<td>
			<span class="annot_petit_gras">Assurance</span>
			</td>
			<td class="TDnumberD">
			<span id="affqteass"><?PHP echo $pdtlbl_qte; ?></span>
			</td>
			<td class="TDnumberD">
			<input name="mtass" type="hidden" id="mtass" value="<?PHP echo $pdtlbl_mtass; ?>" readonly="readonly">
			<input name="mtassttc" type="hidden" id="mtassttc" value="<?PHP echo $pvttcass; ?>" readonly="readonly">
			<span id="affpuass">
			<?PHP 
			if ($pdtlbl_avecass==1)
			{
				if ($cli_modfact==1) echo format_num($pvttcass,2); else echo format_num($pdtlbl_mtass,2); echo $lang['symbole_monnaie'];
			} else echo "-"; ?>
			</span>
			</td>
			<td class="TDnumberD">
			<span id="afftotass">
			<?PHP 
			$totassht=0;
			$totassttc=0;
			$totasstva=0;
			if ($pdtlbl_avecass==1)
			{
				$totassht=round($pdtlbl_mtass*$pdtlbl_qte*100)/100;
				$totassttc=round($pvttcass*$pdtlbl_qte*100)/100;
				$totasstva=$totassttc-$totassht;
				if ($cli_modfact==1) echo format_num($totassttc,2); else echo format_num($totassht,2); echo $lang['symbole_monnaie'];
			} else echo "-"; ?>
			</span>
			</td>
			<td class="TDnumberD">
			<input name="tvaass" type="hidden" id="tvaass" value="<?PHP echo $pdtlbl_codetvaass; ?>"> 
			<input name="txtvaass" type="hidden" id="txtvaass" value="<?PHP echo $txtvaass; ?>" readonly="readonly"> 
			<span id="afftvaass"><?PHP if ($pdtlbl_avecass==1) echo format_num($txtvaass*100,2)."%"; else echo "-";?></span>
			</td>
		</tr>
		<?PHP if (trim($udesc1)<>"") { ?>
		<tr>
			<td>
			<span class="annot_petit_gras">Forfait <?PHP echo $barloc_qconsi1." ".strtolower($udesc1); ?></span>
			</td>
			<td class="TDnumberD">
			<span id="affqtecons1"><?PHP echo $pdtlbl_qte; ?></span>
			</td>
			<td class="TDnumberD">
			<input name="qcons1" type="hidden" id="qcons1" value="<?PHP echo $barloc_qconsi1; ?>" readonly="readonly">
			<input name="pdtucons1" type="hidden" id="pdtucons1" value="<?PHP echo $pdtlbl_pdtuconsi1; ?>" readonly="readonly">
			<input name="mtcons1" type="hidden" id="mtcons1" value="<?PHP echo $pdtlbl_puconsi1; ?>" readonly="readonly">
			<input name="mtconsttc1" type="hidden" id="mtconsttc1" value="<?PHP echo $pvttcconsi1; ?>" readonly="readonly">
			<span id="affpuconsi1">
			<?PHP if ($cli_modfact==1) echo format_num($pvttcconsi1,2); else echo format_num($pdtlbl_puconsi1,2); echo $lang['symbole_monnaie']; ?>
			</span>
			</td>
			<td class="TDnumberD">
			<span id="afftotconsi1">
			<?PHP 
			$totcons1ht=round($pdtlbl_puconsi1*$pdtlbl_qte*100)/100;
			$totcons1ttc=round($pvttcconsi1*$pdtlbl_qte*100)/100;
			$totcons1tva=$totcons1ttc-$totcons1ht;
			if ($cli_modfact==1) echo format_num($totcons1ttc,2); else echo format_num($totcons1ht,2); echo $lang['symbole_monnaie']; ?></span>
			</td>
			<td class="TDnumberD">
			<?PHP echo format_num($txtva*100,2)."%"; ?>
			</td>
		</tr>
		<?PHP }
		if (trim($udesc2)<>"") { ?>
		<tr>
			<td>
			<span class="annot_petit_gras">Forfait <?PHP echo $barloc_qconsi2." ".strtolower($udesc2); ?></span>
			</td>
			<td class="TDnumberD">
			<span id="affqtecons2"><?PHP echo $pdtlbl_qte; ?></span>
			</td>
			<td class="TDnumberD">
			<input name="qcons2" type="hidden" id="qcons2" value="<?PHP echo $barloc_qconsi2; ?>" readonly="readonly">
			<input name="pdtucons2" type="hidden" id="pdtucons2" value="<?PHP echo $pdtlbl_pdtuconsi2; ?>" readonly="readonly">
			<input name="mtcons2" type="hidden" id="mtcons2" value="<?PHP echo $pdtlbl_puconsi2; ?>" readonly="readonly">
			<input name="mtconsttc2" type="hidden" id="mtconsttc2" value="<?PHP echo $pvttcconsi2; ?>" readonly="readonly">
			<span id="affpuconsi2">
			<?PHP if ($cli_modfact==1) echo format_num($pvttcconsi2,2); else echo format_num($pdtlbl_puconsi2,2); echo $lang['symbole_monnaie']; ?>
			</span>
			</td>
			<td class="TDnumberD">
			<span id="afftotconsi2">
			<?PHP
			$totcons2ht=round($pdtlbl_puconsi2*$pdtlbl_qte*100)/100;
			$totcons2ttc=round($pvttcconsi2*$pdtlbl_qte*100)/100;
			$totcons2tva=$totcons2ttc-$totcons2ht;
			if ($cli_modfact==1) echo format_num($totcons2ttc,2); else echo format_num($totcons2ht,2); echo $lang['symbole_monnaie']; ?></span>
			</td>
			<td class="TDnumberD">
			<?PHP echo format_num($txtva*100,2)."%"; ?>
			</td>
		</tr>
		<?PHP } ?>
		<tr>
			<td colspan="5">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="3" align="right">
			Total HT
			</td>
			<td class="TDnumberD">
			<?PHP 
			$totalgenHT = $totlocht+$totcautht+$totassht+$totcons1ht+$totcons2ht;
			$totalgenTTC = $totlocttc+$totcautttc+$totassttc+$totcons1ttc+$totcons2ttc;
			$totalgenTVA = $totloctva+$totcauttva+$totasstva+$totcons1tva+$totcons2tva;
			?>
			<span id="afftotalgenht"><?PHP echo format_num($totalgenHT,2).$lang['symbole_monnaie']; ?>
			</td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td colspan="3" align="right">
			Total TVA
			</td>
			<td class="TDnumberD">
			<span id="afftotalgentva"><?PHP echo format_num($totalgenTVA,2).$lang['symbole_monnaie']; ?>
			</td>
			<td>&nbsp;</td>
			</tr>
			<tr>
			<td colspan="3" align="right">
			<span class="annot_petit_gras">Total TTC</span>
			</td>
			<td class="TDnumberD">
			<span class="annot_petit_gras"><span id="afftotalgenttc"><?PHP echo format_num($totalgenTTC,2).$lang['symbole_monnaie']; ?></span>
			</td>
			<td>&nbsp;</td>
		</tr>
		</table>
	  </td>
    </tr>
	<?PHP
	}
	?>
  </table>
  <?PHP if ($cli_modfact==2) echo '<span class="annot_petit_it">NOTA : Client exon&eacute;r&eacute; de TVA</span>';?>
  <p align="center">
    <?PHP if ($td == "add") { ?>
    <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
    <input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_valider; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp2');">
    <?PHP } if ($td == "edit") { ?>
    <input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_valider; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp2');">
    <?PHP } if ($td == "del") { ?>
    <input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp2');">
    <?PHP } ?>
  </p>
</form>
<?PHP
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
