<?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, $limiteprecedente, $limite, $total, 
$page, $Nom_Client, $NumAbat;
// entete de la page

$date = date("Y/m/d");
$timestamp = date('Y-m-d G:i:s');
//$semaine = date("w");
// menu haut new-supp-modif

echo "<center><br>";

/*
ajout_detail_bl_valid.php?
ordre=1
num_bl_ligne=1
num_bl=1
Code_tarif_Client=1
*/

	$sql="Select * FROM gestion_bl_haut WHERE  `date_bl` >= '2017-10-03' ORDER BY `num_li_bl` ASC";

$i=1;
	$req=mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
$i++;
	        $observations = $row["Observations"];
			$date_bl = $row["date_bl"];
			$NumLignStock = $row["num_li_bl"];
			$Numblbase = $row["num_bl"];
	
					$mois_bl= date("m", strtotime($date_bl));
								
					$new_num_bl = $mois_bl."-".$i ;
					
					
echo "$i| $NumLignStock | $date_bl | $mois_bl | $observations | $Numblbase | $new_num_bl | ";

$sql_1 = "UPDATE temp_detail_bl  SET 
`num_bl` = '$Numblbase' 
WHERE `num_bl_ligne` = '$NumLignStock'";

$Req_1 = mysqli_query($link, $sql_1); 
echo "$sql_1 | $Req_1 <br>";

}



/*
	$sql="Select * FROM gestion_bl_haut WHERE  `date_bl` >= '2017-10-03' ORDER BY `num_li_bl` ASC";

$i=1;
	$req=mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
$i++;
	        $observations = $row["Observations"];
			$date_bl = $row["date_bl"];
			$NumLignStock = $row["num_li_bl"];
			$Numblbase = $row["num_bl"];
	
					$mois_bl= date("m", strtotime($date_bl));
								
					$new_num_bl = $mois_bl."-".$i ;
					
					
echo "$i| $NumLignStock | $date_bl | $mois_bl | $observations | $Numblbase | $new_num_bl | ";

$sql_1 = "UPDATE gestion_bl_haut  SET 
`message_bl` = '$Numblbase' , 
`num_bl` = '$new_num_bl' 
WHERE `num_li_bl` = '$NumLignStock'";

$Req_1 = mysqli_query($link, $sql_1); 
echo "$sql_1 | $Req_1 <br>";

}
/*
	$sql="Select * FROM stock WHERE `Observations`>1 AND `Date` <= '2017-09-20' ORDER BY `Observations` DESC";

$i=0;
	$req=mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
$i++;
	        $observations = $row["Observations"];
					$date_bl = $row["Date"];
					$NumLignStock = $row["IdNumStock"];
	
					$mois_bl= date("m", strtotime($date_bl));
					$nbcar=strlen($observations);
					$nbarrestant=$nbcar-9;
					
					$RacineNumBl = substr ($observations,0 ,-5);
					
					$numbl = substr ($observations, -$nbarrestant);
					$numblv = intval($numbl);
					$new_num_bl = $RacineNumBl."-".$mois_bl."-".$numblv ;
					
					
//echo "$i| $NumLignStock | $date_bl | $mois_bl | $observations | $numbl - $numblv | $RacineNumBl | $new_num_bl<br>";

$sql_1 = "UPDATE stock  SET 
`Observations` = '$new_num_bl' 
WHERE `IdNumStock` = '$NumLignStock'";

//$Req_1 = mysqli_query($link, $sql_1); 
echo "$i | $sql_1 | $Req_1 <br>";

}
/*
	$sql="Select * FROM gestion_bl_haut 
	INNER JOIN gestion_bl_detail 
	WHERE gestion_bl_haut.num_li_bl = gestion_bl_detail.num_bl_ligne" ;
$i=0;
	$req=mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
$i++;
	        $num_bl_temp = $row["num_li_bl"];
					$date_bl = $row["date_bl"];
		
		$mois_bl= date("m", strtotime($date_bl));
					
    echo "<br> Num bl en cours : $num_bl_temp | Date Bl : $date_bl <br>";
    $new_num_bl = $mois_bl."-".$num_bl_temp ;
    echo "Nouveau numero de bl : $new_num_bl <br>" ;    
    
$sql_1 = "UPDATE gestion_bl_detail  SET 
`num_bl` = '$new_num_bl' 
WHERE `num_bl` = '$num_bl_temp'";

$Req_1 = mysqli_query($link, $sql_1); 
echo "$i | $sql_1 | $Req_1 <br>";
}
*/
//Header("Location: bon_de_livraison.php?limite=0");
?>