<?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, $s, $ordre, $num_bl_complet,
$limiteprecedente, $limite, $total, $page, $Nom_Client, $semaine,$txt, $puht ;

// entete de la page

include 'menu/header.php';
$date = date("Y-m-d");
$Valid_ok=0;
$refere = $_SERVER['HTTP_REFERER'] ;

/*
http://192.168.1.200/horius/ajout_detail_fa.php?ordre=1&num_fa_ligne=1&facnumber=201900001&num_client_fa=10%20200
*/

if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		if (isset($_POST['ordre'])) { $num_ordre=$_POST['ordre']; }  else {$num_ordre=''; }
		if (isset($_POST['num_fa_ligne'])) { $num_fa_ligne=$_POST['num_fa_ligne']; }  else {$num_fa_ligne=''; }
		if (isset($_POST['facnumber'])) { $facnumber=$_POST['facnumber']; }  else {$facnumber=''; }
		if (isset($_POST['num_client_fa'])) { $num_client_fa=$_POST['num_client_fa']; }  else {$num_client_fa=''; }
		if (isset($_POST['num_eleveur'])) { $num_eleveur=$_POST['num_eleveur']; } else {$num_eleveur=''; }
		if (isset($_POST['date_bl'])) { $date_bl=$_POST['date_bl']; }  else {$date_bl=''; }
		if (isset($_POST['num_lot_entre'])) { $num_lot_entre=$_POST['num_lot_entre']; } else {$num_lot_entre=''; }
		if (isset($_POST['num_trace_entre'])) { $num_trace_entre=$_POST['num_trace_entre']; }  else {$num_trace_entre=''; }
		if (isset($_POST['Cbarre_entre']) ){$Cbarre_entre = $_POST['Cbarre_entre'];} else {$Cbarre_entre = '';}
		
		$valForm="POST" ;
} else {
		// Transmis en GET
		if (isset($_GET['ordre'])) { $num_ordre=$_GET['ordre']; }  else {$num_ordre=''; }
		if (isset($_GET['num_fa_ligne'])) { $num_fa_ligne=$_GET['num_fa_ligne']; }  else {$num_fa_ligne=''; }
		if (isset($_GET['facnumber'])) { $facnumber=$_GET['facnumber']; }  else {$facnumber=''; }
		if (isset($_GET['num_client_fa'])) { $num_client_fa=$_GET['num_client_fa']; }  else {$num_client_fa=''; }
		if (isset($_GET['num_eleveur'])) { $num_eleveur=$_GET['num_eleveur']; } else {$num_eleveur=''; }
		if (isset($_GET['date_bl'])) { $date_bl=$_GET['date_bl']; }  else {$date_bl=''; }
		if (isset($_GET['num_lot_entre'])) { $num_lot_entre=$_GET['num_lot_entre']; } else {$num_lot_entre=''; }
		if (isset($_GET['num_trace_entre'])) { $num_trace_entre=$_GET['num_trace_entre']; }  else {$num_trace_entre=''; }
		if (isset($_GET['Cbarre_entre']) ){$Cbarre_entre = $_GET['Cbarre_entre'];} else {$Cbarre_entre = '';}
		$valForm="GET" ;
}

$observations = htmlspecialchars($observations, ENT_QUOTES);

// formation du numéro de BL
$date_bl_e=date("d/m/Y", strtotime($date_bl));

$Anne_bl=date("y", strtotime($date_bl));
$num_bl_complet ="$Anne_bl-$num_bl-".$num_bl_base ;

		$sql = "SELECT * FROM clients_base WHERE Num_Client='$num_client_fa'"; 
		$sql.=" AND IdNumClient='".$IdNumClient."'";
		$req = mysqli_query($link, $sql);
		while ($row = mysqli_fetch_assoc($req)) {
		        $nom_Client = $row["Nom_Client"];
		        $Code_tarif_Client = $row["Code_tarif"];
		 }  
    
    $sql1 = "SELECT * FROM gestion_fa_haut WHERE rowid='$num_fa_ligne'"; 
		$req1 = mysqli_query($link, $sql1);
		while ($row = mysqli_fetch_assoc($req1)) {
        $date_livraison_bl = $row["date_livraison"];
        $CodeTrsp = $row["num_trsp"];
        $CodePaie = $row["num_paie"]; 
        $etat_bl = $row["etat"];
    }  
    $sql2 = "SELECT `Code_Trsp` FROM categorie_trsp WHERE `Num_Ligne_Cate_Trsp`=$CodeTrsp";  
		$req2 = mysqli_query($link, $sql2);  
		while ($row = mysqli_fetch_assoc($req2)) {$Code_Trsp_texte = $row["Code_Trsp"];} 
		
		$sql3 = "SELECT  `Code_Paiement` FROM categorie_paiement WHERE `Num_Ligne_Cate_Paiement`=$CodePaie";  
		$req3 = mysqli_query($link, $sql3);  
		while ($row = mysqli_fetch_assoc($req3)) {$Code_Paiement_texte = $row["Code_Paiement"];} 
		
$date_livraison_bl_e = date("d/m/Y", strtotime($date_livraison_bl));
/*
echo "$sql1 | $date_livraison_bl | $CodeTrsp | $CodePaie <br>";
echo "$sql2 <br> $sql3 <br>";
echo "$CodeTrsp | $Code_Trsp_texte //  | $Code_Paiement_texte<br>";
*/
// titre page
echo "<div class='titre-text'><center>Facture N&deg; $num_bl_complet </div>" ;
echo "<HR size='1' width='500'><center>";
echo "<table border='0' cellpadding='2' cellspacing='2' width='900'><tr>";
echo "<tr>";
echo "<td class='t-text12' width='30'><center><a href='$refere'><center><img src='images/up.png'></center></a></center></td>";
echo "<td class='t-text12' width='100'><center><label>Date BL : </label>$date_bl_e</label></center></td>";
echo "<td class='t-text12' width='150'><center><label>Client : </label>$nom_Client</label></center></td>";
echo "<td class='t-text12' width='150'><center><label>Date Livraison : </label>$date_livraison_bl_e</label></center></td>";
echo "<td class='t-text12' width='30'><center><a href='maj_haut_bl.php?ordre=3&num_bl=$num_bl_base&num_bl_ligne=$num_bl_ligne'><center><img src='images/redo.png'></center></a></td>";
echo "<td class='t-text12' width='30'><center><a href='ajout_detail_bl_valid_direct.php?ordre=3&num_bl_complet=$num_bl_complet&Code_tarif_Client=$Code_tarif_Client&num_bl=$num_bl_base&num_bl_ligne=$num_bl_ligne'><center><img src='images/sync.png'></center></a></td>";
echo "<td class='t-text12' width='30'><center><a href='edition_bl_nc_imp.php?num_entre=$num_bl_ligne' TARGET=_BLANK><img src='images/print.png' width='20' height='20'></a></center></td>";
echo "<td class='t-text12' width='30'><center><a href='edition_bl_imp.php?num_entre=$num_bl_ligne' TARGET=_BLANK><img src='images/money_bag.png' width='20' height='20'></a></center></td>";
echo "</tr>";
echo "<td class='t-text12' colspan='3'><center>Livraison : $CodeTrsp | $Code_Trsp_texte</center></a></center></td>";
echo "<td class='t-text12' colspan='5'><center>Paiement : $CodePaie | $Code_Paiement_texte</center></a></center></td>";
echo "</table><br>";

// detail bon de livraison

echo "<center>" ;
echo "<table width='900' id='customers'>";
echo "<tr>";
echo "<th width='50'>Num ligne</th>" ;
echo "<th width='50'>Num PLu</th>" ;
echo "<th width='200'>Nom PLu</th>" ;
echo "<th width='180'>Num Lot</th>" ;
echo "<th width='100'>Nb Pi</th>" ;
echo "<th width='100'>Poids</th>" ;
echo "<th width='100'>Pu Ht</th>" ;
echo "<th width='100'>Montant Ht</th>" ;
echo "<th width='20'>D</th>" ;
echo "</tr>";

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

	$sql="select * FROM gestion_bl_detail" ;
	$sql.=" WHERE num_bl_ligne='".$num_bl_ligne."'";
	$sql.=" AND IdNumClient='".$IdNumClient."'";  
	$sql.=" ORDER BY `num_plu` ASC";

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

	        $num_plu_temp = $row["num_plu"];
	        $poids_temp = $row["poids"];
	        $nb_pi_temp = $row["nb_pi"];
	        $num_lot_plu = $row["num_lot"];
	        $num_traca_plu = $row["num_traca"];
	        $puht = $row["puht"];
	        $n_ligne = $row["num_ligne"];
	        $Nun_lot_bl = $row["num_lot"];
	        $Nun_traca_bl = $row["num_traca"];
	        
	
	$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"];
						} 
						
					$sql2="select Num_Base_Tarifs, Num_PLU, Prix_HT, Prix_TTC, Code_Tva, PrixPoid, Base_Tarifs.Num_Code_Tarif" ;
					$sql2.=" FROM `Base_Tarifs`";
					$sql2.=" INNER JOIN categorie_tarif";
					$sql2.=" ON categorie_tarif.Num_Code_Tarif = Base_Tarifs.Num_Code_Tarif AND categorie_tarif.IdNumClient = Base_Tarifs.IdNumClient";
					$sql2.=" WHERE Num_PLU='".$num_plu_temp."'";
					$sql2.=" AND Base_Tarifs.Num_Code_Tarif='".$Code_tarif_Client."'";
					$sql2.=" AND Base_Tarifs.IdNumClient='".$IdNumClient."'";  
					$req2=mysqli_query($link, $sql2);  
					while ($row = mysqli_fetch_assoc($req2)) { 
						$puht = $row["Prix_HT"];
						$PrixPoid= $row["PrixPoid"];
						} 	

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

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

switch ($PrixPoid) { 	
	case 0: 		  // Prix Piece 	
	$montantht = $totalPi*$puht ;
	$montantht = number_format($montantht, 2, '.', ' ')	;		
	break; 	
	
	case 1: 		  // Prix Poids 	
	$montantht = $poids_temp*$puht ;
	$montantht = number_format($montantht, 2, '.', ' ')	;	
	break; 	
	}
							

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

$totalmontant= $totalmontant + $montantht ;
$totalmontant = number_format($totalmontant, 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='200' style='text-align:left'>$nom_plu_temp</td>" ;
echo "<td width='180' style='text-align:left'>$Nun_lot_bl - $Nun_traca_bl </td>" ;
echo "<td width='100' style='text-align:right'>$nb_pi_temp Pi</td>" ;
echo "<td width='100' style='text-align:right'>$poids_temp Kg</td>" ;
echo "<td width='100' style='text-align:right'>$puht &euro;</td>" ;
echo "<td width='100' style='text-align:right'>$montantht &euro;</td>" ;
echo "<td width='20' style='text-align:center'><a href='delete_ligne_bl.php?ordre=1&ligne=$n_ligne&plu=$num_plu_temp&lot=$Nun_lot_bl&trac=$Nun_traca_bl&num_bl=$num_bl_complet'><img src='images/Erase.png'></a></td>" ;
echo "</tr>" ;
	}					 

$sql3 ="SELECT SUM(poids), SUM(nb_pi), SUM(montant_ht) FROM gestion_bl_detail";
	$sql3.=" WHERE num_bl_ligne='".$num_bl_ligne."'";
	$sql3.=" AND IdNumClient='".$IdNumClient."'";  
	$req=mysqli_query($link, $sql3);  
	while ($row = mysqli_fetch_assoc($req)) {

	        $poids_total_bl = $row["SUM(poids)"];
	        $nb_pi_total_bl = $row["SUM(nb_pi)"];
	        $montant_total_bl = $row["SUM(montant_ht)"];
	}
$poids_total_bl = number_format($poids_total_bl, 3, '.', '')	;	
$montant_total_bl = number_format($montant_total_bl, 2, '.', '')	;
$nb_pi_total_bl = number_format($nb_pi_total_bl, 0, '.', '')	;	

echo "<tr style='background-color:lightgrey;'>" ;
echo "<td colspan=4 style='text-align:right'>Total :</td>" ;
echo "<td width='100' style='text-align:right'>$nb_pi_total_bl Pi</td>" ;
echo "<td width='100' style='text-align:right'>$poids_total_bl Kg</td>" ;
echo "<td width='100' style='text-align:left'>&nbsp;</td>" ;
echo "<td width='100' style='text-align:right'>$montant_total_bl &euro;</td>" ;
echo "<td width='50' style='text-align:left'>&nbsp;</td>" ;        
echo "</tr>" ;
echo "</table>";  

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

if ($etat_bl == 0 || $etat_bl == 2) {
// detail page
echo "<form id='interolot' name ='interolot' method='GET' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>"; 
echo "<input type='hidden' name='num_bl_ligne' value='$num_bl_ligne'/>"; 
echo "<input type='hidden' name='num_bl' value='$num_bl_base'/>"; 
echo "<input type='hidden' name='num_client_entre' value='$num_client_entre'/>"; 
echo "<input type='hidden' name='date_bl' value='$date_bl'/>"; 

echo "<center>" ;
echo "<table border='0' cellpadding='1' cellspacing='1' width='800'><tr>";
echo "<tr>";
// selection eleveur
echo "<td class='t-text' width='220'><center><label>Eleveur :</label><select name='num_eleveur' required onchange='submit()'></span>";
echo "<option value=''>??</option>";
	$sql = "SELECT Num_Client, count(Num_Client) FROM `stock`  ";
	$sql.=" WHERE EtatES=0";
	$sql.=" AND IdNumClient='".$IdNumClient."'";
	$sql.=" GROUP BY Num_Client ";  
	$req = mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
				$num_client_eleveur = $row["Num_Client"];

				$sql1 = "SELECT * FROM clients WHERE Num_Client='$num_client_eleveur'"; 
				$req1 = mysqli_query($link, $sql1);
				while ($row = mysqli_fetch_assoc($req1)) {
				        $Nom_eleveur = $row["Nom_Client"];
				        $Let_eleveur = $row["Let_Client"];
				   }  


       if ($num_eleveur==$num_client_eleveur) {
       echo "<option value='$num_client_eleveur' selected>$Let_eleveur | $Nom_eleveur</option> ";
     
			 $Valid_ok=2;
    }  else {
       echo "<option value='$num_client_eleveur'>$Let_eleveur | $Nom_eleveur</option> "; 
          
    }     
  }  
 echo "</select>";
 // Selection Num Lot
if ($Valid_ok==2) {echo"&nbsp;&nbsp;&nbsp;<img src='images/Apply.png'>";} else {echo"&nbsp;&nbsp;&nbsp;<img src='images/Alert.png'>";}
echo "</div></td>" ;
echo "<td class='t-text' width='200'><center><label>N&deg; Lot :</label><select name='num_lot_entre' required onchange='submit()'></center>";
for ($i=1; $i<=10; $i++) {$txt.="&nbsp;"; }
$txt.="&nbsp;&nbsp;*-*-*&nbsp;&nbsp;" ;
for ($i=1; $i<=10; $i++) {$txt.="&nbsp;"; }
echo "<option value=''>$txt</option>";
			
			$dated  = mktime(0, 0, 0, date("m"),   date("d"),   date("Y")-1);
			
			$SelAnne_D = date("Y", strtotime($dated));
			$SelAnne_F = date("Y", strtotime($date));
			
			$SelDeb = date("Y-m-d", mktime(0,0,0,01,01,$SelAnne_D));
			$SelFin = date("Y-m-d", mktime(0,0,0,12,31,$SelAnne_F));

	$sql = "SELECT Num_Lot, count(Num_Lot) FROM `stock`  ";
	$sql.=" WHERE EtatES=0 AND Num_Client='".$num_eleveur."'" ;
	$sql.=" AND Solde=1";
	$sql.=" AND IdNumClient='".$IdNumClient."'";
	$sql.=" AND Date BETWEEN '".$SelDeb."' AND '".$SelFin."'";
	$sql.=" GROUP BY Num_Lot DESC";  
	
	$req = mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
        $num_lot = $row["Num_Lot"];
       
       if ($num_lot_entre==$num_lot) {
       echo "<option value='$num_lot' selected>$num_lot</option> ";  
       $Valid_ok=3;     
    }  else {
       echo "<option value='$num_lot'>$num_lot</option> ";     
    }     
  }  
 echo "</select>";
 $txt="";
 // Selected Num Trace
if ($Valid_ok==3) {echo"&nbsp;&nbsp;&nbsp;<img src='images/Apply.png'>";} else {echo"&nbsp;&nbsp;&nbsp;<img src='images/Alert.png'>";}
echo "</div></td>" ;
echo "<td class='t-text' width='200'><center><label>N&deg; Tra&ccedil;abilit&eacute;e:</label><select name='num_trace_entre' required onchange='submit()'></center>";
for ($i=1; $i<=10; $i++) {$txt.="&nbsp;"; }
$txt.="&nbsp;&nbsp;*-*-*&nbsp;&nbsp;" ;
for ($i=1; $i<=10; $i++) {$txt.="&nbsp;"; }
echo "<option value=''>$txt</option>";
	$sql = "SELECT Num_Traca, count(Num_Traca) FROM `stock`  ";
	$sql.=" WHERE EtatES=0 AND Num_Client='".$num_eleveur."'" ;
	$sql.=" AND Num_Lot='".$num_lot_entre ."'";
	$sql.=" AND IdNumClient='".$IdNumClient."'";
	$sql.=" GROUP BY Num_Traca ";  
	$req = mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
        $num_trace = $row["Num_Traca"];
        
       if ($num_trace==$num_trace_entre) {
       echo "<option value='$num_trace' selected>$num_trace</option> "; 
       $Valid_ok=4;      
    }  else {
       echo "<option value='$num_trace'>$num_trace</option> ";     
    }     
  }  
echo "</select>";

if ($Valid_ok==4) {
		echo"&nbsp;&nbsp;&nbsp;<img src='images/Apply.png'>";
		echo "</div></td>" ;		
		echo "<td width='17' class='t-text'><img src='images/Apply.png'></td>";
		} else {
		echo"&nbsp;&nbsp;&nbsp;<img src='images/Alert.png'>";
		echo "</div></td>" ;		
		echo "<td width='17' class='t-text'><img src='images/Erase.png'></td>";
		}
echo "</div></td>" ;
echo "</tr></form>";
echo "</table><br>";
// Affichage détail de saisie

if ($Valid_ok==4) {

echo "<center>" ;
echo "<table width='800' id='customers'>";
echo "<tr>";
echo "<th width='50'>Num PLu</th>" ;
echo "<th width='150'>Nom PLu</th>" ;
echo "<th width='150'>Num Lot</th>" ;
echo "<th width='100'>Nb Pi</th>" ;
echo "<th width='100'>Poids</th>" ;
echo "<th width='100'>Pu Ht</th>" ;
echo "<th width='100'>Montant Ht</th>" ;
echo "<th width='50'>D</th>" ;
echo "</tr>";

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

	$sql="select num_plu, num_lot, num_traca, SUM(poids), SUM(nb_pi)  FROM temp_detail_bl" ;
	$sql.=" WHERE num_bl_ligne='".$num_bl_ligne."'";
	$sql.=" AND IdNumClient='".$IdNumClient."'";  
	$sql.=" GROUP BY num_lot, num_plu, num_traca ASC";
	$sql.=" ORDER BY `temp_detail_bl`.`num_plu` ASC";

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

	        $num_plu_temp = $row["num_plu"];
	        $poids_temp = $row["SUM(poids)"];
	        $nb_pi_temp = $row["SUM(nb_pi)"];
	        $num_lot_temp = $row["num_lot"];
	        $num_traca_temp = $row["num_traca"];
		
					$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"];
						} 
						
					$sql2="SELECT Num_Base_Tarifs, Num_PLU, Prix_HT, Prix_TTC, Code_Tva, PrixPoid, Base_Tarifs.Num_Code_Tarif" ;
					$sql2.=" FROM `Base_Tarifs`";
					$sql2.=" INNER JOIN categorie_tarif";
					$sql2.=" ON categorie_tarif.Num_Code_Tarif = Base_Tarifs.Num_Code_Tarif AND categorie_tarif.IdNumClient = Base_Tarifs.IdNumClient";
					$sql2.=" WHERE Num_PLU='".$num_plu_temp."'";
					$sql2.=" AND Base_Tarifs.Num_Code_Tarif='".$Code_tarif_Client."'";
					$sql2.=" AND Base_Tarifs.IdNumClient='".$IdNumClient."'";  
					$req2=mysqli_query($link, $sql2);  
					while ($row = mysqli_fetch_assoc($req2)) { 
						$puht = $row["Prix_HT"];
						$PrixPoid= $row["PrixPoid"];
						} 	

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

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

switch ($PrixPoid) { 	
	case 0: 		  // Prix Piece 	
	$montantht = $nb_pi_temp*$puht ;
	$montantht = number_format($montantht, 2, '.', ' ')	;		
	break; 	
	
	case 1: 		  // Prix Poids 	
	$montantht = $poids_temp*$puht ;
	$montantht = number_format($montantht, 2, '.', ' ')	;	
	break; 	
	}
							

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

$totalmontant= $totalmontant + $montantht ;
$totalmontant = number_format($totalmontant, 2, '.', ' ')	;


echo "<tr>";
echo "<td width='50' style='text-align:center'>$num_plu_temp</td>" ;
echo "<td width='150' style='text-align:left'><a href='#' onclick='javascript:Popup(\"detail_bl_temp_liste.php?ordre=1&plu=$num_plu_temp&num_bl_ligne=$num_bl_base&lot=$num_lot_temp&traca=$num_traca_temp\",900,400,\"location=0,menubar=0,scrollbars=0,statusbar=0\")'>$nom_plu_temp</a></td>" ;
echo "<td width='150' style='text-align:right'><a href='#'>$num_lot_temp | $num_traca_temp</a></td>" ;
echo "<td width='100' style='text-align:right'>$nb_pi_temp Pi</td>" ;
echo "<td width='100' style='text-align:right'>$poids_temp Kg</td>" ;
echo "<td width='100' style='text-align:right'>$puht &euro;</td>" ;
echo "<td width='100' style='text-align:right'>$montantht &euro;</td>" ;
echo "<td width='50' style='text-align:center'><a href='delete_ligne_bl_temps.php?ordre=1&plu=$num_plu_temp&num_bl_ligne=$num_bl_ligne'><img src='images/Erase.png'></td>" ;
echo "</tr>" ;
	}					 

echo "<tr style='background-color:lightgrey;'>" ;
echo "<td colspan=4 align='right'>Total :</td>" ;
echo "<td width='100' align='right'>$totalPoids Kg</td>" ;
echo "<td width='100' align='right'>&nbsp;</td>" ;
echo "<td width='100' align='right'>$totalmontant &euro;</td>" ;
echo "<td width='50' align='center'>&nbsp;</td>" ;        
echo "</tr>" ;
echo "</table>";        
echo "<br>";        
// ajout_detail_bl.php?ordre=1&num_bl_ligne=1&num_bl=1&num_client_entre=10+100&date_bl=2017-07-16&
// num_eleveur=8&num_lot_entre=H27233917&num_trace_entre=196D
echo "<form id='ajoutLigne' name ='ajoutLigne' method='GET' action='ajout_entre_bl_temp.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>"; 
echo "<input type='hidden' name='num_bl_ligne' value='$num_bl_ligne'/>"; 
echo "<input type='hidden' name='num_bl' value='$num_bl_base'/>";
echo "<input type='hidden' name='date_bl' value='$date_bl'/>";  
echo "<input type='hidden' name='num_client_entre' value='$num_client_entre'/>"; 
echo "<input type='hidden' name='num_eleveur' value='$num_eleveur'/>";
echo "<input type='hidden' name='num_lot_entre' value='$num_lot_entre'/>";
echo "<input type='hidden' name='num_trace_entre' value='$num_trace_entre'/>";
echo "<input type='hidden' name='puht' value='$puht'/>";

echo "<center>" ;
echo "<table border='1' cellpadding='1' cellspacing='1' width='800'><tr>";
echo "<tr>";
echo "<td class='t-text' align='center' width='30'><label>-</label><input type='radio' name='position' value='m'></td>";
echo "<td class='t-text' align='center' width='30'><label>+</label><input type='radio' name='position' value='p' checked></td>";
if ($Cbarre_entre>0){
echo "<td class='t-text' align='center' width='200'><label>Code Barre :</label><input type='text' name='Cbarre_entre' value='$Cbarre_entre'></td>";
} else {
echo "<td class='t-text' align='center' width='200'><label>Code Barre :</label><input type='text' name='Cbarre_entre' value='$Cbarre_entre' autofocus onchange='submit()'></td>";	
}

$Cb_plu = CodeBarrePlu ($Cbarre_entre) ;
$Cb_Poids = CodeBarrePoids ($Cbarre_entre) ;

echo "<td class='t-text' align='center' width='150'><label>Plu :</label><select name='num_plu_saisie' style='width:200px;' required>";
echo "<option value=''>*-*</option>";
					$sql="select * FROM plu" ;
					$sql.=" WHERE IdNumClient='".$IdNumClient."'"; 
					$sql.=" GROUP BY Num_PLU "; 
					$req=mysqli_query($link, $sql);  
					while ($row = mysqli_fetch_assoc($req)) {
									$Num_plu_saisi = $row["Num_PLU"];						
					        $Nom_plu_saisi = $row["PLU"];
			
			 if ($Cb_plu ==$Num_plu_saisi) {
       echo "<option value='$Num_plu_saisi' selected>$Num_plu_saisi | $Nom_plu_saisi</option> "; 
       $Valid_ok=4;      
    	}  else {
       echo "<option value='$Num_plu_saisi'>$Num_plu_saisi | $Nom_plu_saisi</option> ";      
    	}		             
					} 			
 echo "</select></td>";
echo "<td class='t-text' align='center' width='200'><label>Poids</label><input type='text' name='poids_saisie' value='$Cb_Poids' size='5' required>&nbsp;&nbsp;Kg</td>";
echo "<td class='t-text' align='center' width='100'><label>Nb Pi</label><input type='text' name='pi_saisie' autofocus required onchange='submit()'></td>";
echo "<td class='t-text' align='center' width='20'><input type='submit' value='+'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
echo "<form id='IcrStock' name ='IcrStock' method='GET' action='ajout_detail_bl_valid.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>"; 
echo "<input type='hidden' name='num_bl_ligne' value='$num_bl_ligne'/>"; 
echo "<input type='hidden' name='num_bl' value='$num_bl_base'/>";
echo "<input type='hidden' name='num_lot_entre' value='$num_lot_entre'/>";
echo "<input type='hidden' name='num_trace_entre' value='$num_trace_entre'/>";
echo "<input type='hidden' name='num_eleveur' value='$num_eleveur'/>";
echo "<input type='hidden' name='Code_tarif_Client' value='$Code_tarif_Client'/>";
echo "<input type='hidden' name='num_bl_complet' value='$num_bl_complet'/>";
echo "<br><br><input type='submit' value='Cr&eacute;ation du Bon de livraison'><br><br>";
echo "</form>";
include 'menu/footer.php';
	} else {include 'menu/footer.php';} 
}else {include 'menu/footer.php';}
?>
