<?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, $rendement, 
$page, $Nom_Client, $NumAbat, $mrs, $total_entre, $total_sortie, $total_entre_cass, $total_sortie_cass, 
$total_entre_cass, $total_sortie_cass, $total_entre_decoupe, $total_sortie_decoupe, $total_entre_stockPf, $total_sortie_stockPf,
$total_entre_transf, $total_sortie_transf, $total_entre_congel, $total_sortie_congel ;
// entete de la page

include 'menu/header_edition.php';

$date = date("d-m-Y");


if (!isset($_GET['num_entre']))
{
    $num_lot=0;
    $num_lot_sel=0;
} else {
    $num_bl_ligne=($_GET['num_entre']);
    $num_bl_ligne=($_GET['num_entre']);
}

    $sql = "SELECT * FROM gestion_bl_haut WHERE num_li_bl='$num_bl_ligne'"; 
		$req = mysqli_query($link, $sql);
		while ($row = mysqli_fetch_assoc($req)) {
        $num_bl_base = $row["num_bl"];
        $date_bl = $row["date_bl"];
        $date_livraison_bl = $row["date_livraison"];
        $num_client_entre = $row["num_client_bl"];
        $CodeTrsp = $row["num_trsp"];
        $CodePaie = $row["num_paie"]; 
    }  
		
		$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"];} 


$sql1 = "SELECT * FROM clients_base WHERE Num_Client='$num_client_entre'"; 
$req1 = mysqli_query($link, $sql1);
while ($row = mysqli_fetch_assoc($req1)) {
        $nom_Client = $row["Nom_Client"];
        $Adresse_1 = $row["Adresse_1"];
        $Adresse_2 = $row["Adresse_2"];
        $Adresse_3 = $row["Adresse_3"];
        $Code_Postal = $row["Code_Postal"];
        $Ville = $row["Ville"];
        $CodeTarifs = $row["Code_tarif"];
      } 

$date_bl_e=date("d/m/Y", strtotime($date_bl));
$date_livraison_bl_e = date("d/m/Y", strtotime($date_livraison_bl));
$Anne_bl=date("y", strtotime($date_bl));

$num_bl_complet ="$Anne_bl-$num_bl-".$num_bl_base ;

$date_livraison_bl_e = date("d/m/Y", strtotime($date_livraison_bl));

/*
echo "<center><HR size='2' width='500'>";
echo "<HR size='2' width='500'>";
echo " *-* Fiche detail Decoupe *-*<br>" ;
echo "$nbcarbl| $num_lot_decoupe | $num_lot | $semaine | $Num_CatPlu | $Num_Client | $date <br>" ;
*/

?>
<BODY onLoad='$("#bcTarget").barcode("<?php echo "19010".$num_bl_complet."".$IdNumClient ; ?>", "code128",{barWidth:1 , barHeight:30}); 
	' >
<!--<div id="bcTarget"></div> window.print(); -->
<?php

echo "<center>";
echo "<table width='800' border='0' cellpadding='0' cellspacing='0'>";
echo "<tr>";
echo "<td width='100'><center><img src='images/$LogoSite' width='80'></center></td>";
echo "<td class='texthaut' width='250'>$SocieteSite<br>$RueSite<br>$CpostalSite $VilleSite
			<br>
			T&eacute;l : $TelephoneSite <br> $MailSite </td>";
echo "<td width='50'><center><img src='images/agrem_$IdNumClient.jpg' width='50'></center></td>";
echo "<td width='50'><center>&nbsp;</center></td>";
echo "<td width='350'>
<table width='350' border='1' cellpadding='1' cellspacing='1'>
<tr>
<td colspan=3 class='t-text12'><center>BON DE LIVRAISON</center></td>
</tr><tr>
<td class='texthaut'>Date</td>
<td class='texthaut'>N&deg; Bon</td>
<td class='texthaut'>Date Livraison</td>
</tr><tr>
<td class='texthaut'>$date_bl_e </td>
<td class='texthaut'>$num_bl_complet </td>
<td class='texthaut'>$date_livraison_bl_e </td>
</tr><tr>
</table>
</td>";
echo "</tr>";
echo "</table><br><br>";

echo "<table class='t-text' width='800' border='0' cellpadding='1' cellspacing='1'>";
echo "<tr>";
echo "<td width='400'>
			<table width='350' border='1' cellpadding='1' cellspacing='1'>
			<tr>
			<td class='t-text'><center>Livraison</center></td>
			</tr><tr>
			<td class='texthaut'>$CodeTrsp | $Code_Trsp_texte</td>
			</tr></table><br><br>
			<table width='350' border='1' cellpadding='1' cellspacing='1'>
			<tr>
			<td class='t-text'><center>Code Tarifs</center></td>
			<td class='t-text'><center>Paiement - Ech&eacute;ance</center></td>
			</tr><tr>
			<td class='texthaut'>$CodeTarifs</td>
			<td class='texthaut'>$CodePaie | $Code_Paiement_texte</td>
			</tr></table>
			</td>";
echo "<td width='400'><center>
<table width='350' border='1' cellpadding='1' cellspacing='1'>
<tr>
<td><center><h3>$nom_Client <br> $Adresse_1 <br> $Adresse_2 <br> $Adresse_3 <br> $Code_Postal - $Ville</h3></center></td>
</tr></table>
</td>";
echo "</tr>";
echo "</table>";
echo "<br>Nos viandes sont 100% origine Fran&ccedil;e<br>N&eacute;es, &eacute;lev&eacute;es, abattues, et transform&eacute;es en France<br><br>";


echo "<table width='800' border='1' cellpadding='1' cellspacing='1'>";
echo "<tr height='40'>";
echo "<th height='40' class='titretableau' width='30' >N&deg;</th>";
echo "<th class='titretableau' width='30' >Plu</th>";
echo "<th class='titretableau' width='50' >Nb Pi</th>";
echo "<th class='titretableau' width='400' >D&eacute;signation</th>";
echo "<th class='titretableau' width='100' >Poids</th>";
echo "<th class='titretableau' width='100' >PU.ht/Kg</th>";
echo "<th class='titretableau' width='100' >Montant ht.</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"];
	        $num_eleveur = $row["num_eleveur"];
	        $puht = $row["puht"];
	        $montant_ht= $row["montant_ht"];
	
	$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"];
						$nom_plu_comp_temp = $row["Plu_complement"];
						} 
					
					$sql2="select * FROM plu_textes" ;
					$sql2.=" WHERE Num_PLU='".$num_plu_temp."'";
					$sql2.=" AND IdNumClient='".$IdNumClient."'";  
					$req2=mysqli_query($link, $sql2);  
					while ($row = mysqli_fetch_assoc($req2)) { 
						$ingredients = $row["ingredients"];
						$mlegal_1 = $row["mlegal_1"];
						$mlegal_2 = $row["mlegal_2"];
						$Tmin = $row["Tmin"];
						$Tmax = $row["Tmax"];
						} 			
						
					$sql3="select * FROM clients" ;
					$sql3.=" WHERE `Num_Client`='".$num_eleveur."'";
					$sql3.=" AND IdNumClient='".$IdNumClient."'";  
					$req3=mysqli_query($link, $sql3);  
					while ($row = mysqli_fetch_assoc($req3)) { 
						$nom_eleveur = $row["Nom_Client"];
						}		

					$sql4="select * FROM stock" ;
					$sql4.=" WHERE Num_Lot='".$num_lot_plu."'";
					$sql4.=" AND Num_Traca='".$num_traca_plu."'";  
					$sql4.=" AND IdNumClient='".$IdNumClient."'";  
					$req4=mysqli_query($link, $sql4);  
					while ($row = mysqli_fetch_assoc($req4)) { 
						$DLC_Etiq = $row["DLC_Etiq"];
						}	
if (!empty($nom_plu_comp_temp)) {
	$nom_plu_temp = $nom_plu_temp." - ".$nom_plu_comp_temp ;
	} else {
	$nom_plu_temp = $nom_plu_temp ;	
	} 

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

$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, '.', ' ')	;

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

$DLC_Etiq=date("d/m/Y", strtotime($DLC_Etiq));

echo "<tr>";
echo "<td width='30'  class='text'>$li</td>";
echo "<td width='30'  class='text'>$num_plu_temp</td>";
echo "<td width='50'  class='text'>$nb_pi_temp </td>";
echo "<td width='400' class='textgauche'><b>$nom_plu_temp</b><br>Lot N&deg; $num_lot_plu-$num_traca_plu | Eleveur : <i>$nom_eleveur</i><br>";

if (strlen($mlegal_1)>2) {
echo "$mlegal_1<br>";	
}
if (strlen($mlegal_2)>2) {
echo "$mlegal_2<br>";	
}
echo "Produit &agrave; Conserver entre <b>$Tmin&deg;C</b> et <b>$Tmax&deg;C</b> , &agrave; consommer avant le <b>$DLC_Etiq</b></td>";
echo "<td width='80' class='textdroite'>$poids_temp Kg</td>";
echo "<td width='80' class='textdroite'>$puht &euro;</td>";
echo "<td width='80' class='textdroite'>$montant_ht &euro;</td>";
echo "</tr>";

}
echo "<tr>";
echo "<td colspan=2 class='textdroite14'>TOTAL :</td>";
echo "<td width='50'class='text14' >$totalPi </td>";
echo "<td width='400' class='titretableau14'>&nbsp;</td>";
echo "<td width='100' class='textdroite14'>$totalPoids Kg</td>";
echo "<td width='100' class='titretableau14'>&nbsp;</td>";
echo "<td width='100' class='textdroite14'>$totalmontant &euro;</td>";
echo "</tr>";
echo "</table><br><br>";

echo "<table width='800' border='0' cellpadding='1' cellspacing='1'>";
echo "<tr>";
echo '<td width="400"><center><div id="bcTarget"></div></center></td>';
echo "<td width='400'><center>
<table width='350' border='1' cellpadding='1' cellspacing='1'>
<tr>
<td class='texttop14' height='100'>Date et Signature</td>
</tr></table>
</td>";
echo "</tr>";
echo "</table>";

?>