<?php
include("include/data.php");
Init_boutique();
global $link, $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $result, $NbLigne, $semaine, $limitesuivante, $limiteprecedente, $total, $page ;
// entete de la page
/*
http://192.168.1.200/horius/traitement_ajout_base_tarif.php?
ordre=1
num_plu=120
Num_Code_Tarifs=1
Code_Tva=2
TTCClt=11.80
TTTVA=5.500
MTTVA=0.62
HTCClt=11.18
MGEVD=25
TXMGE=2.24
PVHT=8.50
cpt_plu=70120000
*/

if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$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=''; }
		if (isset($_POST['PVHT'])) { $PVHT=$_POST['PVHT']; } else {$PVHT=''; }
		if (isset($_POST['TTCClt'])) { $TTCClt=$_POST['TTCClt']; } else {$TTCClt=''; }
		if (isset($_POST['cpt_plu'])) { $cpt_plu=$_POST['cpt_plu']; } else {$cpt_plu=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$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=''; }
		if (isset($_GET['PVHT'])) { $PVHT=$_GET['PVHT']; } else {$PVHT=''; }
		if (isset($_GET['TTCClt'])) { $TTCClt=$_GET['TTCClt']; } else {$TTCClt=''; }
		if (isset($_GET['cpt_plu'])) { $cpt_plu=$_GET['cpt_plu']; } else {$cpt_plu=''; }
		$valForm="GET" ;
}




//include 'menu/header.php';

$last_num_entre = 0 ;
$sql = 'SELECT max(Num_Base_Tarifs) FROM Base_Tarifs';
$req = mysqli_query($link, $sql); 
$row = mysqli_fetch_row($req);
$last_num_entre = $row[0];
$last_num_entre = $last_num_entre + 1 ;

/*
echo " Num ordre : ".$ordre." | ident plu : ".$num_plu."<br> 
num tarifs : ".$Num_Code_Tarifs."<br> pvttc :".$TTCClt."<br>
pvht : ".$PVHT."<br> LastNum :".$last_num_entre."<br>
Cpta :".$cpt_plu."<br>";
*/

if (empty($num_plu)) {
	$str = 1 ;	} 
else {
	$sql  = "SELECT EXISTS (SELECT Num_Base_Tarifs FROM Base_Tarifs WHERE Num_PLU = '".$num_plu."' AND Num_Code_Tarif= '".$Num_Code_Tarifs."')";
$req = mysqli_query($link, $sql);
$row = mysqli_fetch_row($req);
echo "Requette : $sql | $row[0] <BR>" ;
$str = $row[0] ;
}


$sql = "INSERT INTO Base_Tarifs VALUES ('".$last_num_entre."',
 '".$IdNumClient."',  
'".$Num_Code_Tarifs."', 
'".$num_plu."', 
'".$PVHT."', 
'".$TTCClt."', 
'".$cpt_plu."',  
'".$timestamp."')";


echo $sql;
 
$res = mysqli_query($link, $sql);

echo "<br>Requette : ".$res ;

Header("Location: base_tarifs.php?limite=0");

?>
