<?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

/*
http://192.168.1.200/horius/detail_bl_temp_liste_detail_import.php?ordre=1
num_plu=18
num_lot=CO02HACH19
num_traca=008T
num_clt=10%20910
Rsi=0
Rsl=1
Rss=1
*/
if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['num_clt'])) { $num_clt=$_POST['num_clt']; }  else {$num_clt=''; }
		if (isset($_POST['num_plu'])) { $num_plu=$_POST['num_plu']; }  else {$num_plu=''; }
		if (isset($_POST['num_lot'])) { $num_lot=$_POST['num_lot']; }  else {$num_lot=''; }
		if (isset($_POST['num_traca'])) { $num_traca=$_POST['num_traca']; }  else {$num_traca=''; }
		if (isset($_POST['Rsi'])) { $Rsi=$_POST['Rsi']; }  else {$Rsi=''; }
		if (isset($_POST['Rsl'])) { $Rsl=$_POST['Rsl']; }  else {$Rsl=''; }
		if (isset($_POST['Rss'])) { $Rss=$_POST['Rss']; }  else {$Rss=''; }

		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['num_clt'])) { $num_clt=$_GET['num_clt']; }  else {$num_clt=''; }
		if (isset($_GET['num_plu'])) { $num_plu=$_GET['num_plu']; }  else {$num_plu=''; }
		if (isset($_GET['num_lot'])) { $num_lot=$_GET['num_lot']; }  else {$num_lot=''; }
		if (isset($_GET['num_traca'])) { $num_traca=$_GET['num_traca']; }  else {$num_traca=''; }
		if (isset($_GET['Rsi'])) { $Rsi=$_GET['Rsi']; }  else {$Rsi=''; }
		if (isset($_GET['Rsl'])) { $Rsl=$_GET['Rsl']; }  else {$Rsl=''; }
		if (isset($_GET['Rss'])) { $Rss=$_GET['Rss']; }  else {$Rss=''; }

		$valForm="GET" ;
}
include 'menu/header_lt.php';
$refere = $_SERVER['HTTP_REFERER'] ;

$sql1="select * FROM temp_import_csv" ;
	$sql1.=" WHERE num_client='".$num_clt."'";
	$sql1.=" AND num_plu='".$num_plu."'";
	$sql1.=" AND num_lot LIKE '".$num_lot."%'";
	$sql1.=" AND num_lot_trace LIKE '".$num_traca."%'";
	$sql1.=" AND IdNumClient='".$IdNumClient."'";  
	$sql1.=" AND RsltImport=".$Rsi ;
	$sql1.=" AND RsltLot=".$Rsl ;
	$sql1.=" AND RsltStock=".$Rss ;
	
	$Testsivide = mysqli_query($link, $sql1);
	$row = mysqli_fetch_row($Testsivide);
	
	if (!empty($row)) {

// menu haut new-supp-modif

		$sql = "SELECT * FROM clients_base WHERE Num_Client='".$num_clt."'"; 
		$sql.=" AND IdNumClient='".$IdNumClient."'";
		$req = mysqli_query($link, $sql);
		while ($row = mysqli_fetch_assoc($req)) {
		        $nom_Client = $row["Nom_Client"];
		 }  
		
		$sql = "SELECT * FROM plu WHERE Num_PLU='".$num_plu."'"; 
		$sql.=" AND IdNumClient='".$IdNumClient."'";
		$req = mysqli_query($link, $sql);
		while ($row = mysqli_fetch_assoc($req)) {
		        $nom_plu = $row["PLU"];
		 }  


echo "<center><a href='#' onclick='history.go(-1);'><img src='images/up.png'></a>&nbsp;&nbsp;&nbsp;&nbsp;D&eacute;tail Ligne Plu : $num_plu /$nom_plu | $num_clt - $nom_Client<a href='#' onclick='window.location.reload();'>&nbsp;&nbsp;&nbsp;&nbsp;<img src='images/refresh.png'></a><br>";

echo "<center>" ;
echo "<table width='750' id='customers'>";
echo "<tr>";
echo "<th width='50'>Num ligne</th>" ;
echo "<th width='50'>Num PLu</th>" ;
echo "<th width='150'>Nom PLu</th>" ;
echo "<th width='150'>Num Lot</th>" ;
echo "<th width='50'>Poids</th>" ;
echo "<th width='50'>M</th>" ;
echo "<th width='20'>D</th>" ;
echo "</tr>";

$totalPoids=0;
$li=0;

	$req=mysqli_query($link, $sql1);  
	while ($row = mysqli_fetch_assoc($req)) {

	        $num_plu_temp = $row["num_plu"];
	        $poids_temp = $row["poids"];
	        $num_lot_temp = $row["num_lot"];
	        $num_traca_temp = $row["num_lot_trace"];
	        $num_ligne_temp = $row["num_ligne_import"];
					$li=$li+1 ;
				
					
					$sql1="select * FROM plu" ;
					$sql1.=" WHERE Num_PLU='".$num_plu_temp."'";
					$sql1.=" AND IdNumClient='".$IdNumClient."'";  
					$req1=mysqli_query($link, $sql1);  
					while ($row = mysqli_fetch_assoc($req1)) { 
						$nom_plu_temp = $row["PLU"];
						} 
				
				

$totalPoids = $totalPoids + $poids_temp ;
$totalPoids = number_format($totalPoids, 3, '.', ' ')	;

	

$poids_temp = number_format($poids_temp, 3, '.', ' ')	;


		
$TotalPoids = $poids_temp + $TotalPoids ;

		
$poids_temp = number_format($poids_temp, 2, '.', ' ')	;

		

		echo "<tr>";
		echo "<td width='50' style='text-align:center'>$li</td>" ;
		echo "<td width='50' style='text-align:center'>$num_plu_temp </td>" ;
		echo "<td width='150' style='text-align:left'>$nom_plu_temp </td>" ;
		echo "<td width='150' style='text-align:center'>$num_lot_temp | $num_traca_temp </td>" ;
		echo "<td width='50' style='text-align:right'>$poids_temp Kg</td>" ;
		echo "<td width='50' style='text-align:center'><a href='modif_art_bl_temps_import.php?ordre=$num_ordre&num_clt=$num_clt&num_ligne_import=$num_ligne_temp&num_plu=$num_plu_temp&num_lot=$num_lot_temp&num_traca=$num_traca_temp&Rsi=$Rsi&Rsl=$Rsl&Rss=$Rss'><img src='images/transfert.png'></a></td>" ;
		echo "<td width='50' style='text-align:center'><a href='delete_laligne_bl_temps_import.php?ordre=1&num_ligne=$num_ligne_temp'><img src='images/trash.png'></td>" ;
		echo "</tr>" ;
				 }  
		$TotalPoids = number_format($TotalPoids, 2, '.', ' ')	;
		$TotalPi = number_format($TotalPi, 0, '.', ' ')	;
		
		echo "<tr style='background-color:lightgrey;'>" ;
		echo "<td colspan=4 style='text-align:center'>Total</td>" ;
		echo "<td width='50' style='text-align:right'>$TotalPoids Kg</td>" ;
		echo "<td colspan=2 style='text-align:right'></td>" ;
		echo "</tr>" ;
		echo "</table>" ;
		echo "<a href='#' onclick='window.close()'>Fermer</a>";
//
} else {
Header("Location: detail_bl_temp_liste_import.php?ordre=2&num_clt=$num_clt&&num_lot=$num_lot&num_traca=$num_traca&num_plu=$num_plu&Rsi=$Rsi&Rsl=$Rsl&Rss=$Rss") ;
}
?>
