<?php
include("include/data.php");
Init_boutique();
global $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $A_NumArt,$i, $result, 
$NbLigne, $mygroupeart, $mysousgroupeart, $semaine, $limitesuivante, $Taux_Tva_Base,
$limiteprecedente, $limite, $total, $page, $Nom_Client, $semaine ;
// entete de la page

include 'menu/header.php';
?>
<html>
  <script type="text/javascript">
  -->
function calculer(){
                var a = document.getElementById("a").value;
				var b1 = document.getElementById("b1").value;
				var d1 = document.getElementById("d1").value;
				
				var options = {style: "currency", currency: "EUR"};
				var numberFormat = new Intl.NumberFormat("fr-FR", options);
				
				var b = a-(a/(1+(b1/100)));
				var c = a-b ;
				var d = c-(c/(1+(d1/100)));
				var e = c-d ;
				
				b = format (b,2," ") ;
				c = format (c,2," ") ;
				d = format (d,2," ") ;
				e = format (e,2," ") ;
				
				--> alert (b) ;			
				--> alert (c) ;
				
				document.getElementById("b").value = b ;
				document.getElementById("c").value = c ;
				document.getElementById("d").value = d ;
				document.getElementById("e").value = e ;             
						
				} 
 
  
function clearFields() {
				document.getElementById("a").value="";
				document.getElementById("b").value="";
				document.getElementById("c").value="";
				document.getElementById("d").value="";
				document.getElementById("e").value="";
}
    -->
  </script>
</html>
<?php
// Get ou Post existe ou pas ?
if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['num_plu'])) { $num_plu=$_POST['num_plu']; }  else {$num_plu=''; }
		if (isset($_POST['Num_Code_Tarifs'])) { $Num_Code_Tarifs=$_POST['Num_Code_Tarifs']; } else {$Num_Code_Tarifs=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['num_plu'])) { $num_plu=$_GET['num_plu']; }  else {$num_plu=''; }
		if (isset($_GET['Num_Code_Tarifs'])) { $Num_Code_Tarifs=$_GET['Num_Code_Tarifs']; } else {$Num_Code_Tarifs=''; }
		$valForm="GET" ;
}

echo "<center><HR size='1' width='500'>";
echo "<center><b>Base Tarifs</b></center>" ;
echo "<center><HR size='1' width='500'>";

Menu_CSD ($num_ordre) ;
echo "<br>";

// Corps de page
// echo "<form id='chglotdispo' name ='chglotdispo' method='GET' action='".$_SERVER['PHP_SELF']."'>";
// echo "<td><select name='num_plu' id='num_plu' STYLE='width:120' onchange='submit()'>";
echo "<br>";
echo "<table width='450' border='0' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<td width='150'>PLU :</td>";
echo "<form id='chglotdispo' name ='chglotdispo' method='GET' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<td width='150'><select name='num_plu' id='num_plu' onchange='submit()'>";
echo "<option value='0'>?</option>";

$myart =new plu;
$select = "SELECT * FROM `plu` ORDER BY `Num_PLU` ASC ";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_plu_base=$myart->Num_PLU ;
  $nom_plu=$myart->PLU ;
 
if  ($num_plu==$num_plu_base)  {
  echo "<option value='$num_plu_base' selected='selected' >$num_plu_base | $nom_plu</option>";

} else {
  echo "<option value='$num_plu_base' >$num_plu_base | $nom_plu</option>";
}
}
$Code_Tva = 0 ;
echo "</select></td>";
echo "</tr><tr>";
echo "</form>";

echo "<form id='chglotdispo1' name ='chglotdispo1' method='GET' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<input type='hidden' name='num_plu' value='$num_plu'/>";
echo "<td width='150'>Code Tarif : </td>";
echo "<td width='150'><select name='Num_Code_Tarifs' id='Num_Code_Tarifs' STYLE='width:120' onchange='submit()'>";
echo "<option value='0'>?</option>";
$myart =new Base_Tarifs ;
$sql = "SELECT categorie_tarif.Num_Code_Tarif, categorie_tarif.Code_Tarif, categorie_tarif.Code_Tva \n"

    . "					FROM categorie_tarif\n"

    . "					LEFT OUTER JOIN Base_Tarifs ON categorie_tarif.Num_Code_Tarif = Base_Tarifs.Num_Code_Tarif\n"

    . "    			AND Base_Tarifs.Num_PLU=".$num_plu."\n"

    . "					WHERE Base_Tarifs.Num_Code_Tarif is null";

    
		
$result = mysqli_query($link, $sql);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_Code_Tarifs_base=$myart->Num_Code_Tarif ;
  $Code_Tarif=$myart->Code_Tarif ;
  $Code_Tva_base=$myart->Code_Tva ;
  
if  ($Num_Code_Tarifs==$Num_Code_Tarifs_base)  {
  echo "<option value='$Num_Code_Tarifs_base' selected='selected' >$Num_Code_Tarifs_base | $Code_Tarif</option>";
  $Code_Tva=$Code_Tva_base ;
 } else {
  echo "<option value='$Num_Code_Tarifs_base' >$Num_Code_Tarifs_base | $Code_Tarif</option>";

}
}

echo "</select></td>";
echo "</tr><tr>" ;
echo "</form>";

echo "</table>";
echo "<br>";

echo "<table width='800' border='1' cellspacing='2' cellpadding='2'>";

echo "<form id='form1' name='form1' method='get' action='traitement_ajout_base_tarif.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<input type='hidden' name='num_plu' value='$num_plu'/>";
echo "<input type='hidden' name='Num_Code_Tarifs' value='$Num_Code_Tarifs'/>";
echo "<input type='hidden' name='Code_Tva' value='$Code_Tva'/>";
$sql = "SELECT Taux_Tva FROM TVA WHERE Code_Tva='$Code_Tva'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $Taux_Tva_Base = $row["Taux_Tva"];
    }     
$TauxTva = number_format($Taux_Tva_Base, 3, '.', ' ')	;
//echo "Code TVA : $Code_Tva | Code Tarif : $Code_Tarif | Taux Tva : $TauxTva" ; //
echo "<input type='hidden' id='TauxTva' value='$TauxTva'/>";

echo "<tr>
<td height='20' valign='center'><center>Prix TTC Client : </td>
<td height='20' valign='center'><center><input type='text' id='a' name='TTCClt' onkeyup='calculer()' size='5'></center></td>";
echo "<tr>
<td><center>Tva : <input type='text' id='b1' size='4' name='TTTVA' value=$TauxTva onkeyup='calculer()'>%</td>
<td><center><input type='text' id='b' name='MTTVA' size='5'></center></td>"; 
echo "<tr>
<td><center>Prix HT Client : </td>
<td><center><input type='text' id='c' name='HTCClt' size='5'></center></td>";
echo "<tr>
<td><center>Taux Mge Vendeur :<input type='text' id='d1'size  ='4' name='MGEVD' value='25' onkeyup='calculer()'>%</td>
<td><center><input type='text' id='d' name='TXMGE' size='5'></center></td>";
echo "<tr>
<td><center>Prix HT : </td>
<td><center><input type='text' name='PVHT' id='e' size='5'></center></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center' valign='middle'>Compte Compta : </td>
	  <th align='left' valign='middle'>";
echo "<select name='cpt_plu' id='cpt_plu' accesskey='7' tabindex='7'>";


$sql1 = "SELECT * FROM `Plan_Comptable` WHERE `Compte_Cpta` BETWEEN 70000000 AND 71000000";
$sql1.= " AND IdNumClient='".$IdNumClient."'";
$sql1.= " ORDER BY `Compte_Cpta` ASC";

$req = mysqli_query($link, $sql1);  
while ($row = mysqli_fetch_assoc($req)) {
        $cpt_plu_sel = $row["Compte_Cpta"];
        $cpt_plu_nom = $row["Nom_Compte_Cpta"];
      

 if ($cpt_plu_sel==$Cpt_plu) {
	echo "<option value='$cpt_plu_sel' selected='selected'>$cpt_plu_sel | $cpt_plu_nom</option>";
 } else {
	echo "<option value='$cpt_plu_sel'>$cpt_plu_sel | $cpt_plu_nom</option>";
}}
echo "</select>";

echo "</td></tr> ";
echo "<tr>
<td colspan=2><center><input type='button' value='Effacer Saisie' onclick='clearFields()' ></center></td>"; 
echo "</tr>";
echo "</table>";
echo "<br><br><center><input type='submit' value='* Envoyer *'></center>";      

echo "</form>";
// Pied de Page


include 'menu/footer.php';
?>
