<?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");
$utlisateur  = $_COOKIE ["cookie_civilite"];

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

$select = "SELECT * FROM decoupe WHERE num_lot_decoupe='$num_lot'";

$myart =new decoupe;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_decoupe=$myart->num_decoupe ;
	$num_client_decoupe=$myart->num_client ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$categorie_plu_decoupe=$myart->categorie_plu ;
}

$sql = "SELECT * FROM clients WHERE Num_Client='$num_client_decoupe'";  
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
        $Nom_Client = $row["Nom_Client"];
        $Let_Client = $row["Let_Client"];
    }  

$sql = "SELECT CategoriePlu FROM categorieplu WHERE Num_CatPlu='$categorie_plu_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $categorie_plu_decoupe = $row["CategoriePlu"];
    } 

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

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

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

echo "<center>";
echo "<table width='600' border='0' cellpadding='2' cellspacing='2'>";
echo "<tr>";
echo "<td height='80' width='100'><center><img src='images/$LogoSite' width='80'></center></td>";
echo "<td class='texthaut' width='500'>$SocieteSite<br>$RueSite<br>$CpostalSite $VilleSite
			<br>
			T&eacute;l : $TelephoneSite <br> $MailSite </td>";
echo "<td><center><img src='images/agrem_$IdNumClient.jpg' width='50'></center></td>";
echo "<td height='80' width='100'><center><div id='bcTarget'></center></td>";
echo "</tr>";
echo "</table>";

echo "<table class='t-text' width='600' border='0' cellpadding='0' cellspacing='0'>";
echo "<tr>";
echo "<td width='600' height='30' class='t-text-titre'><center>Fiche d&#233;tail lot N&#176;: $num_lot</center></td>";
echo "</tr>";
echo "</table>";


echo "<table class='t-text' width='600' border='0' cellpadding='0' cellspacing='0'>";
echo "<tr>";
echo "<td width='300' height='20'><center>Eleveur : $Let_Client | $Nom_Client</center></td>";
echo "<td width='300' height='20'><center>Categorie : $categorie_plu_decoupe</center></td>";
echo "</tr>";
echo "</table>";

echo "<table width='800' border='1' cellpadding='1' cellspacing='1'>";
echo "<tr>";
echo "<th class='titretableau' width='50' rowspan='2' >Date</th>";
echo "<th class='titretableau' width='50' rowspan='2' >Tracabilit&#233;</th>";
echo "<th class='titretableau' width='300' rowspan='2' >Objet</th>";
echo "<th class='titretableau' width='200' colspan='2' >Poids</th>";
echo "<th class='titretableau' width='200' rowspan='2' >Observations</th>";
echo "</tr>";
echo "<tr>";
echo "<th class='titretableau width='100'>Entre</th>";
echo "<th class='titretableau Width='100'>Sortie</th>";
echo "</tr>";

// Cate decoupe 4 =>entre

$select = "SELECT * FROM lot WHERE num_lot_decoupe='$num_lot'";
$select.=" AND `num_cate_decoupe`='4'";
$select.=" AND `IdNumClient`='".$IdNumClient."'";
$select.=" ORDER BY `lot`.`num_lot_tace_decoupe` ASC, `lot`.`num_cate_decoupe` ASC";
$existe='';
$search = mysqli_query($link, $select);
$row_cnt = mysqli_num_rows($search);

if ($row_cnt>=1) {
echo "<tr><td class='t-text' colspan=6 >Entr&eacute;e Abattoirs</td></tr>";
$myart =new lot;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_lot=$myart->num_ligne_lot ;
	$date_lot_decoupe=$myart->date_lot_decoupe ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$num_lot_tace_decoupe=$myart->num_lot_tace_decoupe ;
	$num_cate_decoupe=$myart->num_cate_decoupe ;
	$poid_decoupe=$myart->poid_decoupe ;
	$etat_decoupe=$myart->etat_decoupe ;
	$solde_decoupe=$myart->solde_decoupe ;
	$num_ligne_detail=$myart->num_ligne_detail ;
	$observations=$myart-> observations ; 

	$date_lot_decoupe = date("d/m/Y", strtotime($date_lot_decoupe));
	$poid_decoupe = number_format($poid_decoupe, 2, '.', ' ');
	$montant_total=0;

echo "<tr>";
echo "<td class='text' width='100' height='20'>$date_lot_decoupe</td>";
echo "<td class='text' width='100' height='20'>$num_lot_tace_decoupe</td>";

$sql = "SELECT cate_decoupe FROM categorie_decoupe WHERE num_cate_decoupe='$num_cate_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $cate_decoupe = $row["cate_decoupe"];
    } 

if ($etat_decoupe==0) {
echo "<td class='textgauche' width='200' height='20' >$cate_decoupe</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
echo "<td class='text' width='100' height='20' >*-*</td>";
$total_entre = $poid_decoupe + $total_entre ;
} else {
echo "<td class='textdroite' width='200' height='20' >$cate_decoupe</td>";	
echo "<td class='text' width='100' height='20' >*-*</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
$total_sortie = $poid_decoupe + $total_sortie ;
} 
echo "<td class='text' width='200' height='20' >$observations</td>";
echo "</td></tr>";
}

$solde_entre = $total_entre - $total_sortie ;
$solde_entre = number_format($solde_entre, 2, '.', ' ');
$total_entre = number_format($total_entre, 2, '.', ' ');
$total_sortie = number_format($total_sortie, 2, '.', ' ');

echo "<tr>";
echo "<td width='100' class='text' height='20' ></td>";
echo "<td class='textdroite' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoids' height='20' >$total_entre Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$total_sortie Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroite' height='20' colspan='3'>Solde : </td>";

if ($solde_entre>=0) {
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$solde_entre Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
} else {
$solde_entre = -$solde_entre ;
$solde_entre = number_format($solde_entre, 2, '.', ' ');
echo "<td width='100' class='textpoids' height='20' >$solde_entre Kg</td>";
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
}
echo "</tr>";
}

// Cate decoupe 1 => Casse

$select = "SELECT * FROM lot WHERE num_lot_decoupe='$num_lot'";
$select.=" AND `num_cate_decoupe`='1'";
$select.=" AND `IdNumClient`='".$IdNumClient."'";
$select.=" ORDER BY `lot`.`num_lot_tace_decoupe` ASC, `lot`.`num_cate_decoupe` ASC";
$existe='';
$search = mysqli_query($link, $select);
$row_cnt = mysqli_num_rows($search);

if ($row_cnt>=1) {
echo "<tr><td class='t-text' colspan=6 >Casse</td></tr>";

$myart =new lot;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_lot=$myart->num_ligne_lot ;
	$date_lot_decoupe=$myart->date_lot_decoupe ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$num_lot_tace_decoupe=$myart->num_lot_tace_decoupe ;
	$num_cate_decoupe=$myart->num_cate_decoupe ;
	$poid_decoupe=$myart->poid_decoupe ;
	$etat_decoupe=$myart->etat_decoupe ;
	$solde_decoupe=$myart->solde_decoupe ;
	$num_ligne_detail=$myart->num_ligne_detail ;
	$observations=$myart-> observations ; 

	$date_lot_decoupe = date("d/m/Y", strtotime($date_lot_decoupe));
	$poid_decoupe = number_format($poid_decoupe, 2, '.', ' ');
	$montant_total=0;

echo "<tr>";
echo "<td class='text' width='100' height='20'>$date_lot_decoupe</td>";
echo "<td class='text' width='100' height='20'>$num_lot_tace_decoupe</td>";

$sql = "SELECT cate_decoupe FROM categorie_decoupe WHERE num_cate_decoupe='$num_cate_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $cate_decoupe = $row["cate_decoupe"];
    } 

if ($etat_decoupe==0) {
echo "<td class='textgauche' width='200' height='20' >$cate_decoupe</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
echo "<td class='text' width='100' height='20' >*-*</td>";
$total_entre_cass = $poid_decoupe + $total_entre_cass ;
} else {
echo "<td class='textdroite' width='200' height='20' >$cate_decoupe</td>";	
echo "<td class='text' width='100' height='20' >*-*</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
$total_sortie_cass = $poid_decoupe + $total_sortie_cass ;
} 

echo "<td class='text' width='200' height='20' >$observations</td>";
echo "</td></tr>";

}
$solde_cass = $total_entre_cass - $total_sortie_cass ;
$solde_cass = number_format($solde_cass, 2, '.', ' ');
$total_entre_cass = number_format($total_entre_cass, 2, '.', ' ');
$total_sortie_cass = number_format($total_sortie_cass, 2, '.', ' ');

echo "<tr>";
echo "<td width='100' class='text' height='20' ></td>";
echo "<td class='textdroite' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoids' height='20' >$total_entre_cass Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$total_sortie_cass Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroite' height='20' colspan='3'>Solde : </td>";

if ($solde_cass>=0) {
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$solde_cass Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
} else {
$solde_cass = -$solde_cass ;
$solde_cass = number_format($solde_cass, 2, '.', ' ');
echo "<td width='100' class='textpoids' height='20' >$solde_cass Kg</td>";
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
}
echo "</tr>";
}
// Cate decoupe 2 => Decoupe

$select = "SELECT * FROM lot WHERE num_lot_decoupe='$num_lot'";
$select.=" AND `num_cate_decoupe`='2'";
$select.=" AND `IdNumClient`='".$IdNumClient."'";
$select.=" ORDER BY `lot`.`num_lot_tace_decoupe` ASC, `lot`.`num_cate_decoupe` ASC";
$existe='';
$search = mysqli_query($link, $select);
$row_cnt = mysqli_num_rows($search);

if ($row_cnt>=1) {
echo "<tr><td class='t-text' colspan=6 >D&eacute;coupe</td></tr>";
$myart =new lot;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_lot=$myart->num_ligne_lot ;
	$date_lot_decoupe=$myart->date_lot_decoupe ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$num_lot_tace_decoupe=$myart->num_lot_tace_decoupe ;
	$num_cate_decoupe=$myart->num_cate_decoupe ;
	$poid_decoupe=$myart->poid_decoupe ;
	$etat_decoupe=$myart->etat_decoupe ;
	$solde_decoupe=$myart->solde_decoupe ;
	$num_ligne_detail=$myart->num_ligne_detail ;
	$observations=$myart-> observations ; 

	$date_lot_decoupe = date("d/m/Y", strtotime($date_lot_decoupe));
	$poid_decoupe = number_format($poid_decoupe, 2, '.', ' ');
	$montant_total=0;

echo "<tr>";
echo "<td class='text' width='100' height='20'>$date_lot_decoupe</td>";
echo "<td class='text' width='100' height='20'>$num_lot_tace_decoupe</td>";

$sql = "SELECT cate_decoupe FROM categorie_decoupe WHERE num_cate_decoupe='$num_cate_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $cate_decoupe = $row["cate_decoupe"];
    } 

if ($etat_decoupe==0) {
echo "<td class='textgauche' width='200' height='20' >$cate_decoupe</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
echo "<td class='text' width='100' height='20' >*-*</td>";
$total_entre_decoupe = $poid_decoupe + $total_entre_decoupe ;
} else {
echo "<td class='textdroite' width='200' height='20' >$cate_decoupe</td>";	
echo "<td class='text' width='100' height='20' >*-*</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
$total_sortie_decoupe = $poid_decoupe + $total_sortie_decoupe ;
} 

echo "<td class='text' width='200' height='20' >$observations</td>";
echo "</td></tr>";

}
$solde_decoupe = $total_entre_decoupe - $total_sortie_decoupe ;
$solde_decoupe = number_format($solde_decoupe, 2, '.', ' ');
$total_entre_decoupe = number_format($total_entre_decoupe, 2, '.', ' ');
$total_sortie_decoupe = number_format($total_sortie_decoupe, 2, '.', ' ');

echo "<tr>";
echo "<td width='100' class='text' height='20' ></td>";
echo "<td class='textdroite' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoids' height='20' >$total_entre_decoupe Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$total_sortie_decoupe Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroite' height='20' colspan='3'>Solde : </td>";

if ($solde_decoupe>=0) {
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$solde_decoupe Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
} else {
$solde_decoupe = -$solde_decoupe ;
$solde_decoupe = number_format($solde_decoupe, 2, '.', ' ');
echo "<td width='100' class='textpoids' height='20' >$solde_decoupe Kg</td>";
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
}
echo "</tr>";
}
// Cate decoupe 3 => Transformations

$select = "SELECT * FROM lot WHERE num_lot_decoupe='$num_lot'";
$select.=" AND `num_cate_decoupe`='3'";
$select.=" AND `IdNumClient`='".$IdNumClient."'";
$select.=" ORDER BY `lot`.`num_lot_tace_decoupe` ASC, `lot`.`num_cate_decoupe` ASC";
$existe='';
$search = mysqli_query($link, $select);
$row_cnt = mysqli_num_rows($search);

if ($row_cnt>=1) {
echo "<tr><td class='t-text' colspan=6 >Transformations</td></tr>";
$myart =new lot;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_lot=$myart->num_ligne_lot ;
	$date_lot_decoupe=$myart->date_lot_decoupe ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$num_lot_tace_decoupe=$myart->num_lot_tace_decoupe ;
	$num_cate_decoupe=$myart->num_cate_decoupe ;
	$poid_decoupe=$myart->poid_decoupe ;
	$etat_decoupe=$myart->etat_decoupe ;
	$solde_decoupe=$myart->solde_decoupe ;
	$num_ligne_detail=$myart->num_ligne_detail ;
	$observations=$myart-> observations ; 

	$date_lot_decoupe = date("d/m/Y", strtotime($date_lot_decoupe));
	$poid_decoupe = number_format($poid_decoupe, 2, '.', ' ');
	$montant_total=0;

echo "<tr>";
echo "<td class='text' width='100' height='20'>$date_lot_decoupe</td>";
echo "<td class='text' width='100' height='20'>$num_lot_tace_decoupe</td>";

$sql = "SELECT cate_decoupe FROM categorie_decoupe WHERE num_cate_decoupe='$num_cate_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $cate_decoupe = $row["cate_decoupe"];
    } 

if ($etat_decoupe==0) {
echo "<td class='textgauche' width='200' height='20' >$cate_decoupe</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
echo "<td class='text' width='100' height='20' >*-*</td>";
$total_entre_transf = $poid_decoupe + $total_entre_transf ;
} else {
echo "<td class='textdroite' width='200' height='20' >$cate_decoupe</td>";	
echo "<td class='text' width='100' height='20' >*-*</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
$total_sortie_transf = $poid_decoupe + $total_sortie_transf ;
} 

echo "<td class='text' width='200' height='20' >$observations</td>";
echo "</td></tr>";

}
$solde_transf = $total_entre_transf - $total_sortie_transf ;
$solde_transf = number_format($solde_transf, 2, '.', ' ');
$total_entre_transf = number_format($total_entre_transf, 2, '.', ' ');
$total_sortie_transf = number_format($total_sortie_transf, 2, '.', ' ');

echo "<tr>";
echo "<td width='100' class='text' height='20' ></td>";
echo "<td class='textdroite' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoids' height='20' >$total_entre_transf Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$total_sortie_transf Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroite' height='20' colspan='3'>Solde : </td>";

if ($solde_transf>=0) {
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$solde_transf Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
} else {
$solde_transf = -$solde_transf ;
$solde_transf = number_format($solde_transf, 2, '.', ' ');
echo "<td width='100' class='textpoids' height='20' >$solde_transf Kg</td>";
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
}
echo "</tr>";
}
// Cate decoupe 5 => Congelation

$select = "SELECT * FROM lot WHERE num_lot_decoupe='$num_lot'";
$select.=" AND `num_cate_decoupe`='5'";
$select.=" AND `IdNumClient`='".$IdNumClient."'";
$select.=" ORDER BY `lot`.`num_lot_tace_decoupe` ASC, `lot`.`num_cate_decoupe` ASC";

$search = mysqli_query($link, $select);
$row_cnt = mysqli_num_rows($search);

if ($row_cnt>=1) {
echo "<tr><td class='t-text' colspan=6 >Cong&eacute;lation $existe </td></tr>";

$myart =new lot;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_lot=$myart->num_ligne_lot ;
	$date_lot_decoupe=$myart->date_lot_decoupe ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$num_lot_tace_decoupe=$myart->num_lot_tace_decoupe ;
	$num_cate_decoupe=$myart->num_cate_decoupe ;
	$poid_decoupe=$myart->poid_decoupe ;
	$etat_decoupe=$myart->etat_decoupe ;
	$solde_decoupe=$myart->solde_decoupe ;
	$num_ligne_detail=$myart->num_ligne_detail ;
	$observations=$myart-> observations ; 

	$date_lot_decoupe = date("d/m/Y", strtotime($date_lot_decoupe));
	$poid_decoupe = number_format($poid_decoupe, 2, '.', ' ');
	$montant_total=0;

echo "<tr>";
echo "<td class='text' width='100' height='20'>$date_lot_decoupe</td>";
echo "<td class='text' width='100' height='20'>$num_lot_tace_decoupe</td>";

$sql = "SELECT cate_decoupe FROM categorie_decoupe WHERE num_cate_decoupe='$num_cate_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $cate_decoupe = $row["cate_decoupe"];
    } 

if ($etat_decoupe==0) {
echo "<td class='textgauche' width='200' height='20' >$cate_decoupe</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
echo "<td class='text' width='100' height='20' >*-*</td>";
$total_entre_congel = $poid_decoupe + $total_entre_congel ;
} else {
echo "<td class='textdroite' width='200' height='20' >$cate_decoupe</td>";	
echo "<td class='text' width='100' height='20' >*-*</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
$total_sortie_congel = $poid_decoupe + $total_sortie_congel ;
} 

echo "<td class='text' width='200' height='20' >$observations</td>";
echo "</td></tr>";

}
$solde_congel = $total_entre_congel - $total_sortie_congel ;
$solde_congel = number_format($solde_congel, 2, '.', ' ');
$total_entre_congel = number_format($total_entre_congel, 2, '.', ' ');
$total_sortie_congel = number_format($total_sortie_congel, 2, '.', ' ');

echo "<tr>";
echo "<td width='100' class='text' height='20' ></td>";
echo "<td class='textdroite' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoids' height='20' >$total_entre_congel Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$total_sortie_congel Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroite' height='20' colspan='3'>Solde : </td>";

if ($solde_congel>=0) {
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$solde_congel Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
} else {
$solde_congel = -$solde_congel ;
$solde_congel = number_format($solde_congel, 2, '.', ' ');
echo "<td width='100' class='textpoids' height='20' >$solde_congel Kg</td>";
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
}
echo "</tr>";

} ELSE {
$total_entre_congel = 0;
$total_sortie_congel = 0;	
} 


// Cate decoupe 6 => Entree Stock

$select = "SELECT * FROM lot WHERE num_lot_decoupe='$num_lot'";
$select.=" AND `num_cate_decoupe`='6'";
$select.=" AND `IdNumClient`='".$IdNumClient."'";
$select.=" ORDER BY `lot`.`num_lot_tace_decoupe` ASC, `lot`.`num_cate_decoupe` ASC";

$search = mysqli_query($link, $select);
$row_cnt = mysqli_num_rows($search);

if ($row_cnt>=1) {
echo "<tr><td class='t-text' colspan=6 >Entree stock produit fini sous vide</td></tr>";

$myart =new lot;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
	$myart->readrow($result);
	$num_ligne_lot=$myart->num_ligne_lot ;
	$date_lot_decoupe=$myart->date_lot_decoupe ;
	$num_lot_decoupe=$myart->num_lot_decoupe ;
	$num_lot_tace_decoupe=$myart->num_lot_tace_decoupe ;
	$num_cate_decoupe=$myart->num_cate_decoupe ;
	$poid_decoupe=$myart->poid_decoupe ;
	$etat_decoupe=$myart->etat_decoupe ;
	$solde_decoupe=$myart->solde_decoupe ;
	$num_ligne_detail=$myart->num_ligne_detail ;
	$observations=$myart-> observations ; 

	$date_lot_decoupe = date("d/m/Y", strtotime($date_lot_decoupe));
	$poid_decoupe = number_format($poid_decoupe, 2, '.', ' ');
	$montant_total=0;

echo "<tr>";
echo "<td class='text' width='100' height='20'>$date_lot_decoupe</td>";
echo "<td class='text' width='100' height='20'>$num_lot_tace_decoupe</td>";

$sql = "SELECT cate_decoupe FROM categorie_decoupe WHERE num_cate_decoupe='$num_cate_decoupe'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $cate_decoupe = $row["cate_decoupe"];
    } 

if ($etat_decoupe==0) {
echo "<td class='textgauche' width='200' height='20' >$observations</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
echo "<td class='text' width='100' height='20' >*-*</td>";
$total_entre_stockPf = $poid_decoupe + $total_entre_stockPf ;
} else {
echo "<td class='textdroite' width='200' height='20' >$observations</td>";	
echo "<td class='text' width='100' height='20' >*-*</td>";
echo "<td class='textpoids' width='100' height='20' >$poid_decoupe Kg</td>";
$total_sortie_stockPf = $poid_decoupe + $total_sortie_stockPf ;
} 

echo "<td class='text' width='200' height='20' >$cate_decoupe</td>";
echo "</td></tr>";

}
$solde_stockPf = $total_entre_stockPf - $total_sortie_stockPf ;
$solde_stockPf = number_format($solde_stockPf, 2, '.', ' ');
$total_entre_stockPf = number_format($total_entre_stockPf, 2, '.', ' ');
$total_sortie_stockPf = number_format($total_sortie_stockPf, 2, '.', ' ');

echo "<tr>";
echo "<td width='100' class='text' height='20' ></td>";
echo "<td class='textdroite' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoids' height='20' >$total_entre_stockPf Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$total_sortie_stockPf Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroite' height='20' colspan='3'>Solde : </td>";

if ($solde_stockPf>=0) {
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoids' height='20' >$solde_stockPf Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
} else {
$solde_stockPf = -$solde_stockPf ;
$solde_stockPf = number_format($solde_stockPf, 2, '.', ' ');
echo "<td width='100' class='textpoids' height='20' >$solde_stockPf Kg</td>";
echo "<td width='100' class='textpoids' height='20' >0.00 Kg</td>";
echo "<td width='200' class='text' height='20'></td>";
}
echo "</tr>";
}

// Total Bas de Page Final
$total_final_entre = ($total_entre_decoupe+$total_entre_transf+$total_entre_congel+$total_entre_stockPf  ) ;
$total_final_sortie = ($total_sortie_decoupe+$total_sortie_transf+$total_sortie_congel+$total_sortie_stockPf) ;
$solde_total = $total_final_entre-$total_final_sortie ;
 
$solde_total = number_format($solde_total, 2, '.', ' ');
$total_final_sortie = number_format($total_final_sortie, 2, '.', ' ');
$total_final_entre = number_format($total_final_entre, 2, '.', ' ');

$rendement= (($total_final_sortie / $total_final_entre ))*100;
$rendement = number_format($rendement, 2, '.', ' ');
/*
echo "TOTAL ENTRE : $total_final_entre = ($total_entre_decoupe+$total_entre_transf+$total_entre_congel+$total_entre_stockPf)<br>";
echo "TOTAL SORTIE : $total_final_sortie = ($total_sortie_decoupe+$total_sortie_transf+$total_sortie_congel+$total_sortie_stockPf)<br>";
echo "Solde  : $solde_total = $total_final_entre-$total_final_sortie<br>";
echo "rendement  : $rendement= ($total_final_sortie / $total_final_entre ))*100;<br>";
*/
echo "<tr><td class='t-text' colspan=6 >*-*-* TOTAL LOT $num_lot_decoupe *-*-*</td></tr>";
echo "<tr>";
echo "<td width='100' class='textbas' height='20' ></td>";
echo "<td class='textdroitebas' height='20' colspan='2' >Total : </td>";
echo "<td width='100' class='textpoidsbas' height='20' >$total_final_entre Kg</td>";
echo "<td width='100' class='textpoidsbas' height='20' >$total_final_sortie Kg</td>";
echo "<td width='200' class='textbas' height='20'></td>";
echo "</td></tr>";
echo "<tr>";
echo "<td class='textdroitebas' height='20' colspan='3'>Solde : </td>";

if ($solde_total>=0) {
echo "<td width='100' class='textpoidsbas' height='20' >0.00 Kg</td>";
echo "<td width='100' class='textpoidsbas' height='20' >$solde_total Kg</td>";
echo "<td width='200' class='textbas' height='20'>soit un rendement de $rendement %</td>";
} else {
$solde_total = -$solde_total ;
$solde_total = number_format($solde_total, 2, '.', ' ');
echo "<td width='100' class='textpoidsbas' height='20' >$solde_total Kg</td>";
echo "<td width='100' class='textpoidsbas' height='20' >0.00 Kg</td>";
echo "<td width='200' class='textbas' height='20'>soit un rendement de $rendement %</td>";
}
echo "</tr>";

echo "</table>";

echo "<table class='t-text' width='800' border='0' cellpadding='0' cellspacing='0'>";
echo "<tr>";
echo "<td width='200' height='20'><center>Utilisateur : $utlisateur</center></td>";
echo "<td width='200' height='20'><center>Edition du : $date</center></td>";
echo "</td></tr>";
echo "</table>";
?>