<?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_loc.inc.php");
include_once("../inc/fic_prm.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"]);

$td = strip_tags(trim(@$_GET['td']));
$ibl= intval(strip_tags(trim(@$_GET['nbl'])));
$itc= intval(strip_tags(trim(@$_GET['ntc'])));
$nc= intval(strip_tags(trim(@$_GET['nc'])));
$nextmin = intval(strip_tags(trim(@$_GET['nm'])));
$pbm_tc=FALSE;
if (($nc<>1) AND ($nc<>2))
	$pbm_tc=TRUE;

if (($ibl > 0) AND ($pbm_tc==FALSE))
{
	// Récupération des données du barême
	$row = lit_enr_barloc_id($ibl,TRUE);
	if (is_array($row))
	{
		extract ($row);
		
		$row = lit_enr_pdtloc($barloc_codepdtloc);
		if (is_array($row))
			extract($row);

		if ($itc > 0)
		{
			if ($itc==last_id_tarcons_in_barloc($ibl,$nc,TRUE))
			{
				// Récupération des données du tarif consommable
				$row = lit_enr_tcons_id($itc);
				if (is_array($row))
					extract($row);
				else
					$pbm_tc=TRUE;
			}
			else
				$pbm_tc=TRUE;
		}
		else
		{
			if ($itc < 0)
				$pbm_tc=TRUE;
		}

		// Récupération des informations TVA
		$row = lit_enr_tva($barloc_tvacons1,TRUE);
		if (is_array($row))
			extract ($row);
		$txtva=$tva_tx/100;
		$puttc=round(($barloctc_pvht*(1+$txtva))*100)/100;
	}
	else
		$pbm_tc=TRUE;
}			
else
	$pbm_tc=TRUE;

switch ($td)
{
	case "add" :
		$titre = "AJOUT TARIF";
		if (exist_infini_tcons_id($ibl,$nc,TRUE)==FALSE)
		{
			$barloctc_idbarloc = $ibl;
			$barloctc_ncons = $nc;
			$barloctc_min = $nextmin;
			$barloctc_max = $nextmin+1;
		}
		else
			$pbm_tc=TRUE;
		break;
	case "edit" :
		$titre = "EDITION TARIF";
		break;
	case "del" :
		$titre = "SUPPRESSION TARIF";
		break;
	default :
		$pbm_tc=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; ?> : Tarif Consommable</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(
	"nom:mini; format:unsigned ; req:Y ; txt:Minimum ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:maxi; format:unsigned ; req:Y ; txt:Maximum ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:puht; format:reel_ns ; req:Y ; txt:PU HT ; lmx:10 ; vmn : 0.01; stok:frmok ; stbad:frmbad",
	"nom:pu; format:reel_ns ; req:Y ; txt:PU TTC ; lmx:10 ; vmn : 0.01; stok:frmok ; stbad:frmbad");
//-->
</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>

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

<?PHP cre_js_tarcons("edit",$barloc_id,"window.opener."); ?>

</head>

<body onLoad="metFocus();tbtarcons<?PHP echo $nc; ?>();">

<?PHP
if ($pbm_tc==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">Pour le bar&ecirc;me : <span class="titre_gras"><?php echo $barloc_des; ?></span><br />
Du Produit : <span class="titre_gras"><?php echo $pdtloc_des; ?> </span></p>

<form name="barloctc_maj" method="post" action="barloctc_enr.php" onSubmit="javascript:; return (verif_tcons(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="ncons" type="hidden" id="ncons" value="<?PHP echo $nc ?>">
    <input name="nbl" type="hidden" id="nbl" value="<?PHP echo $barloc_id; ?>">
    <input name="ntc" type="hidden" id="ntc" value="<?PHP echo $itc; ?>">
  <table width="100%"  border="0">
    <tr>
      <td width="25%" class="rubfrm" id="f_mini" align="right">Minimum</td>
      <td>
	  	<input name="mini" type="text" id="mini" style="text-align:right" value="<?PHP echo $barloctc_min; ?>" size="10" readonly="1">
	  </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_maxi" align="right">Maximum</td>
      <td>
	  	<input name="maxi" type="text" id="maxi" style="text-align:right" value="<?PHP echo $barloctc_max; ?>" size="10">
		<?PHP if ($td<>"del") { ?>
		 <span class="annot_petit_it">(Au moins <?PHP echo $barloctc_max;?>, ou '0' pour infini)</span>
		<?PHP } ?>
	  </td>
    </tr>
	<tr>
      <td class="rubfrm" id="f_pu" align="right">Tarif HT</td>
      <td>
      <?PHP 
	  if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="puht" type="text" id="puht" style="text-align:right" value="<?PHP echo format_num($barloctc_pvht,2); ?>" size="10" onChange="formatedeci(this.id,2);ttc_from_ht(this.value,'tva','pu',2);">
		<?PHP echo $lang['symbole_monnaie']; ?> <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"><br />
		<span class="annot_petit_it">(La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
	  <?PHP } else { ?>
		<input name="puht" type="text" id="puht" style="text-align:right" value="<?PHP echo format_num($barloctc_pvht,2); ?>" size="10" readonly="1">
	  <?PHP echo $lang['symbole_monnaie'];
	  } ?>
	  </td>
    </tr>
	<tr>
      <td class="rubfrm" id="f_tva" align="right">TVA</td>
	  <td>
      <?PHP 
		// Création des taux de TVA (champs cachés)
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBTVA." WHERE tva_actif=1 ORDER BY tva_desc");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<input name="'.$tva_code.'" type="hidden" id="'.$tva_code.'" value="'.$tva_tx.'">';
		}
		mysql_free_result($rs);
		mysql_close($conn);

		$row=lit_enr_tva($barloc_tvacons1,TRUE);
		if (is_array($row))
			extract($row);

	  ?>
		<input name="tva" type="hidden" id="tva" value="<?PHP echo $barloc_tvacons1 ?>"> 
		<input name="ntva" type="text" id="ntva" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1">
	  </td>
	</tr>
	<tr>
      <td class="rubfrm" id="f_puttc" align="right">Tarif TTC</td>
	  <td>
      <?PHP 
		$row=lit_enr_tva($barloc_codetva,TRUE);
		if (is_array($row))
			extract($row);
	
	  if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo  format_num($puttc,2); ?>" size="10"  onChange="formatedeci(this.id,2);ht_from_ttc(this.value,'tva','puht',2);"> 
		<?PHP echo $lang['symbole_monnaie']; ?> <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"><br />
		<span class="annot_petit_it">(La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
	<?PHP } else { ?>
		<input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo format_num($puttc,2); ?>" size="10" readonly="1"> 
	<?PHP } ?>
	  </td>
	</tr>
  </table>
  <p align="center">
    <?PHP if ($td == "add") { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
    <input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_add; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } if ($td == "edit") { ?>
    <input name="mod" type="submit" class="bton_std" id="mod" value="<?PHP echo $but_modif; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?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('fscomp');">
    <?PHP } ?>
  </p>
</form>
<?PHP
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp2');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
