<?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_pdt.inc.php");
include_once("../inc/fic_taxes.inc.php");
include_once("../inc/func.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']));
$codeint = strip_tags(trim(@$_GET['ci']));
$codetpf = strip_tags(trim(@$_GET['tpf']));
	
$pbm_tpf=FALSE;

if ($codeint <> "")
{
	// Récupération des données de la fiche taxe
	$row = lit_enr_tpf($codetpf);
	if (is_array($row))
	{
		extract ($row);
	
		if ($td == "add")
		{
			$tpfi_codeint = $codeint;
			$tpfi_codetpf = $tpf_code;
			$tpfi_valeur = $tpf_valeur;
			$tpfi_codetva = $tpf_codetva;
			$tpfi_qte = 1;
			$tpfi_texte = "";
		}

		if ($td == "edit")
		{
			$row = lit_enr_tpf_in_int($codetpf,$codeint);
			if (is_array($row))
				extract ($row);
			else
				$pbm_tpf=TRUE;
		}

		if ($td == "del")
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM `" .TBTPFI. "` WHERE `tpfi_codetpf` = '$codetpf' AND `tpfi_codeint` = '$codeint'";
			$rs = mysql_query($rech)or die(mysql_error());
			if (mysql_num_rows($rs) == 0)
				$pbm_tpf=TRUE;
			else
			{
				if ($row = mysql_fetch_array($rs))
					extract ($row);
				else
					$pbm_tpf=TRUE;
			}
			mysql_free_result($rs);
			mysql_close($conn);
		}


		// Récupération information TVA par client
		$cliexo=FALSE;
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT int_codecli FROM `" .TBINT. "` WHERE `int_code` = '$codeint'";
		$rs = mysql_query($rech)or die(mysql_error());
		if (mysql_num_rows($rs) > 0)
		{
			if ($row = mysql_fetch_array($rs))
			{
				extract($row);

				$rech2 = "SELECT cli_modfact FROM `" .TBCLI. "` WHERE `cli_code` = '$int_codecli'";
				$rs2 = mysql_query($rech2)or die(mysql_error());
				if ($row2 = mysql_fetch_array($rs2))
				{
					extract($row2);
					
					if ($cli_modfact==2)
					{
						$cliexo=TRUE;
						$tpfi_codetva="TVA0";
					}
				}
				mysql_free_result($rs2);
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);

		// Récupération des informations TVA
		$row = lit_enr_tva($tpfi_codetva,TRUE);
		if (is_array($row))
			extract ($row);
		$txtva=$tva_tx/100;
			
		$puht=round(($tpfi_valeur/(1+$txtva))*100)/100;

	}
}			
else
{
	if ($td == "add")
	{
		$tpfi_codeint = $codeint;
		$tpfi_codetpf = $tpf_code;
		$tpfi_valeur = $tpf_valeur;
		$tpfi_qte = 1;
		$tpfi_texte = "";
	}
	else
		$pbm_tpf=TRUE;
}

switch ($td)
{
	case "add" :
		$titre = "SAISIE TAXE";
		break;
	case "edit" :
		$titre = "EDITION TAXE";
		break;
	case "del" :
		$titre = "SUPPRESSION TAXE";
		break;
	default :
		$pbm_tpf=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; ?> : Taxe Intervention</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:qte ; format:reel_ns ; req:Y ; txt:Quantité ; vmn : 0.01 ; lmx:10 ; stok:frmok ; stbad:frmbad",
<?PHP if ($tpf_pour==FALSE) { ?>
	"nom:puht; format:reel_ns ; req:Y ; txt:PU HT; vmn : 0.01 ; lmx:10 ; stok:frmok ; stbad:frmbad",
<?PHP } ?>
	"nom:pu; format:reel_ns ; req:Y ; txt:PU TTC ; vmn : 0.01 ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:texte; format:txt ; req:N ; txt:Commentaire ; 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>

</head>

<body onLoad="metFocus();">

<?PHP
if ($pbm_tpf==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour l'intervention : <?php echo $tpfi_codeint; ?> </span></p>

<form name="tpfi_maj" method="post" action="tpfi_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="codeint" type="hidden" id="codeint" value="<?PHP echo $tpfi_codeint ?>">
  <table width="100%"  border="0">
    <tr>
      <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo $txt_chp_code; ?></td>
      <td>
		  <input name="code" type="text" id="code" value="<?PHP echo $tpfi_codetpf ?>" size="50" maxlength="50" readonly="1">
	  </td> 
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_des" align="right"><?PHP echo $txt_chp_lib; ?></td>
      <td>
	  	<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($tpf_desc); ?>" size="50" maxlength="50" readonly="1">
	  </td>
    </tr>
    <tr>
      <td width="30%" class="rubfrm" id="f_qte" align="right">Quantit&eacute;</td>
      <td>
	  	<input name="qte" type="text" id="qte" style="text-align:right" value="<?PHP echo format_num($tpfi_qte,2) ?>" size="10" onChange="formatedeci(this.id,2);">
      	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	  </td>
    </tr>
	<?PHP if ($tpf_pour==FALSE) { ?>
    <tr>
      <td width="160" class="rubfrm" id="f_puht" align="right">PU HT</td>
      <td>
	  	<input name="puht" type="text" id="puht" style="text-align:right" value="<?PHP echo format_num($puht,2) ?>" size="10" <?PHP if ($tpf_asaisir==TRUE) echo "onChange=\"formatedeci(this.id,2);ttc_from_ht(this.value,'tva','pu',2);\""; else echo "readonly=\"1\""; ?>>
        <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>
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_tva" align="right">TVA</td>
      <td>
		<input name="tva" type="hidden" id="tva" value="<?PHP echo $tpfi_codetva ?>"> 
		<input name="ntva" type="text" id="ntva" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1"> 
	  <?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);

		if ($cliexo==TRUE) {
	  ?>
		<br><span class="annot_petit_it">Ce client est exon&eacute;r&eacute; de TVA</span>
	  <?PHP } ?>
      </td>
    </tr>
	<?PHP } ?>
    <tr>
      <td width="160" class="rubfrm" id="f_pu" align="right"><?PHP if ($tpf_pour==FALSE) echo "PU TTC"; else echo "Pourcentage"; ?></td>
      <td>
	  	<input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo format_num($tpfi_valeur,2) ?>" size="10"  <?PHP if ($tpf_asaisir==TRUE) { if ($tpf_pour==FALSE) echo "onChange=\"formatedeci(this.id,2);ht_from_ttc(this.value,'tva','puht',2);\""; else echo "onChange=\"formatedeci(this.id,2);\""; } else echo "readonly=\"1\""; ?>>
		<?PHP if ($tpf_pour==TRUE) echo "%"; ?>
        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"><br>
		<span class="annot_petit_it">Du montant total des articles. (La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_texte" align="right">Commentaire</td>
      <td>
	  	<textarea name="texte" id="texte" rows="4"><?PHP echo htmlspecialchars($tpfi_texte); ?></textarea>
	  </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('fscomp');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
