<?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_import.php?ordre=1&num_clt=99%20100&Rsi=0&Rsl=0&Rss=0
*/
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['Rsi'])) { $Rsi=$_POST['Rsi']; }  else {$Rsi=''; }
		if (isset($_POST['Rsl'])) { $Rsl=$_POST['Rsl']; }  else {$Rsl=''; }
		if (isset($_POST['Rss'])) { $Rss=$_POST['Rss']; }  else {$Rss=''; }
				if (isset($_POST['Sel_w'])) { $Sel_w=$_POST['Sel_w']; } else {$Sel_w=''; }
		$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['Rsi'])) { $Rsi=$_GET['Rsi']; }  else {$Rsi=''; }
		if (isset($_GET['Rsl'])) { $Rsl=$_GET['Rsl']; }  else {$Rsl=''; }
		if (isset($_GET['Rss'])) { $Rss=$_GET['Rss']; }  else {$Rss=''; }
			if (isset($_GET['Sel_w'])) { $Sel_w=$_GET['Sel_w']; } else {$Sel_w=''; }
		$valForm="GET" ;
}
include 'menu/header_lt.php';
// 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"];
		 }  

	$sql1="select num_plu, num_lot, num_lot_trace, SUM(poids) , COUNT(poids) FROM temp_import_csv" ;
	$sql1.=" WHERE num_client='".$num_clt."'";
	if (!empty($Sel_w)){ $sql1.=" AND Num_semaine='".$Sel_w."'";}
	$sql1.=" AND IdNumClient='".$IdNumClient."'"; 
	$sql1.=" AND RsltImport=".$Rsi ;
	$sql1.=" AND RsltLot=".$Rsl ;
	$sql1.=" AND RsltStock=".$Rss ;
	
	$sql1.=" GROUP BY num_lot, num_plu, num_lot_trace ASC";
	$sql1.=" ORDER BY `temp_import_csv`.`num_plu` ASC";
	
		$Testsivide = mysqli_query($link, $sql1);
	$row = mysqli_fetch_row($Testsivide);
	if (!empty($row)) {

echo "<center>Detail du bon  $num_clt - $nom_Client<br><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'>Nb Pi</th>" ;
echo "<th width='50'>Poids</th>" ;

if ($num_ordre==2) {
	echo "<th width='50'>*-*</th>" ;
	echo "<th width='50'>*-*</th>" ;
	echo "</tr>";
	} else {
	echo "</tr>";		
	}


$totalPoids=0;
$totalPi=0;
$totalmontant=0;
$li=0;


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

	        $num_plu_temp = $row["num_plu"];
	        $poids_temp = $row["SUM(poids)"];
	        $nb_pi_temp = $row["COUNT(poids)"];
	        $num_lot_temp = $row["num_lot"];
	        $num_traca_temp = $row["num_lot_trace"];
					$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, '.', ' ')	;

$totalPi = $totalPi + $nb_pi_temp ;						
$totalPi = number_format($totalPi, 0, '.', ' ')	;

							

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

		
$TotalPoids = $poids_temp + $TotalPoids ;
$TotalPi = $TotalPi + $nb_pi_temp ;
		
$poids_temp = number_format($poids_temp, 2, '.', ' ')	;
$nb_pi_temp = number_format($nb_pi_temp, 0, '.', ' ')	;
		

		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'><a href='detail_bl_temp_liste_detail_import.php?ordre=1&num_plu=$num_plu_temp&num_lot=$num_lot_temp&num_traca=$num_traca_temp&num_clt=$num_clt&Rsi=$Rsi&Rsl=$Rsl&Rss=$Rss' target=_self>$nom_plu_temp</a></td>" ;
		echo "<td width='150' style='text-align:center'>$num_lot_temp | $num_traca_temp </td>" ;
		echo "<td width='50' style='text-align:right'>$nb_pi_temp Pi</td>" ;
		echo "<td width='50' style='text-align:right'>$poids_temp Kg</td>" ;
		if ($num_ordre==2) {
		echo "<td width='50' style='text-align:center'><a href='modif_ligne_bl_temps_import.php?ordre=$num_ordre&num_plu=$num_plu_temp&num_lot=$num_lot_temp&num_traca=$num_traca_temp&num_clt=$num_clt&Rsi=$Rsi&Rsl=$Rsl&Rss=$Rss'><img src='images/clerouge.png'></a></td>" ;
		echo "<td width='50' style='text-align:center'><a href='delete_ligne_bl_temps_import.php?ordre=$num_ordre&num_plu=$num_plu_temp&num_lot=$num_lot_temp&num_traca=$num_traca_temp&num_clt=$num_clt&Rsi=$Rsi&Rsl=$Rsl&Rss=$Rss'><img src='images/trash.png'></a></td>" ;
		echo "</tr>";
		} else {
		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'>$TotalPi Pi</td>" ;
		echo "<td width='50' style='text-align:right'>$TotalPoids Kg</td>" ;
		if ($num_ordre==2) {
		echo "<td width='50' style='text-align:right'></p></td>" ;		
		echo "<td width='50'></p></td>" ;
		echo "</tr>";
		} else {
		echo "</tr>";		
		}

		echo "</table>" ;
		echo "<a href='#' onclick='window.close()'>Fermer</a>";
		
		//echo "<br>$sql<br>";
} else {
echo "<center>Detail du bon  $num_clt - $nom_Client<br><br>";
echo "<br>";
echo "Bon Vide <br><br> <a href='#' onclick='window.close()'>Fermer</a>";

}

?>
