<?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, $mrs, $total_poids, $Let_Client, $num_client_decoupe, $categorie_plu, 
$categorie_plu_decoupe, $Date_Entreb, $DataAbatb  ;
// entete de la page

include 'menu/header_edition.php';


$date = date("d-m-Y");
$SelAnne_y_sel=date("y");
$Num_ligne_qtv=htmlentities($_GET['num_entre']);
$IdNumClient = $_COOKIE['cookie_IdNumClient'] ;

$myart =new quantitative_haut;
$select = "select * FROM quantitative_haut WHERE Num_ligne_qtv=$Num_ligne_qtv";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_ligne_qtv_diso=$myart->Num_ligne_qtv ;
  $date_decoupe=$myart->date_decoupe;
  $semaine_decoupe=$myart->semaine_decoupe;
  $num_client=$myart->num_client;
  $num_lot=$myart->num_lot ;
  $tracabilite=$myart->tracabilite ;
  $poid_decoupe=$myart->poid_decoupe ;
  $observations=$myart->observations;
}
$myart =new entreabat;
$select = "select * FROM entreabat WHERE `Num_Lot`='$num_lot' ";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
$Num_Client=$myart->Num_Client ;
$Num_categoriePlu=$myart->Num_categoriePlu ;
$Num_Lot=$myart->Num_Lot ;
$Date_decoupe_b=$myart-> DateDecoupe ;

}

$myart =new clients;
$select = "select * FROM clients WHERE Num_Client='$Num_Client'";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_Client=$myart->Num_Client ;
  $Let_Client=$myart->Let_Client ;
  $Nom_Client=$myart->Nom_Client ;
}

$sql = "SELECT CategoriePlu FROM categorieplu WHERE Num_CatPlu='$categorie_plu'";  
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $categorie_plu_decoupe = $row["CategoriePlu"];
    }    
	
$Date_Entre=date("d/m/Y", strtotime($Date_Entreb));
$DataAbat=date("d/m/Y", strtotime($DataAbatb));
$Date_decoupe=date("d/m/Y", strtotime($Date_decoupe_b));
/*
echo "<center><HR size='2' width='500'>";
echo " *-* Fiche d'entre *-*<br>" ;
echo " $SelAnne_y_sel | $date | $semaine | $semaine_decoupe | $Num_CatPlu | $Num_ligne_qtv<br>$select<br>" ;
*/
?>
<BODY onLoad='$("#bcTarget").barcode("<?php echo "10200".$Num_ligne_qtv."".$IdNumClient ; ?>", "code128",{barWidth:1 , barHeight:30}); window.print();' >

<!--div id="bcTarget"></div>-->
<?php

echo "<center>";
echo "<table width='600' border='0' cellpadding='1' cellspacing='1'>";
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 width='800' border='0' cellpadding='1' cellspacing='1'>";
echo "<tr>";
echo "<td class='texthaut'width='800'><h4>FICHE DETAIL QUANTITATIVE<br>Lot : $num_lot | $tracabilite</h4></td>";

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

echo "<center><HR size='2' width='600'></center>";

echo "<br>";
echo "<table width='800' border='2' cellpadding='2' cellspacing='2'>";
echo "<tr>";
echo "<td class='texttitre' width='150'>Semaine :</td><td class='texttitre' >$semaine_decoupe / $SelAnne_y_sel</td>";
echo "<td class='text' width='300' colspan='2'height='30' ><center><div id='bcTarget'></div></center></td>";
echo "</tr><tr>" ;
echo "<td class='texttitre' width='150'>Categorie : </td>";
echo "<td class='text' width='150'>$categorie_plu_decoupe" ;

echo "<td class='texttitre' width='150'>Client :</td>";


echo "<td class='text' width='150'>$Let_Client | $Nom_Client</td>" ;


echo "</tr><tr>" ;
echo "<td class='texttitre' width='150'>Date D&eacute;coupe :</td>";
echo "<td class='text' width='150'>$Date_decoupe</td>";
echo "<td class='texttitre' width='150'>Poids :</td>";
echo "<td class='text' width='150'>$poid_decoupe Kg</td>";
echo "</tr><tr>" ;
echo "<td class='texttitre' width='300' colspan='2'>Observations :</td>";
echo "<td class='text' width='300' colspan='2'>$observations</td>";
echo "</tr><tr>" ;
echo "</table><br>";


echo "<table width='800' border='1' cellpadding='1' cellspacing='1'>";
echo "<thead>";
echo "<tr>";
echo "<th width='50' rowspan='2'><div align='center'>PLU</div></th>";
echo "<th width='150' rowspan='2'><div align='center'>Designation</div></th>";
echo "<th width='150' colspan='2'><div align='center'>*-*</div></th>";
echo "<th width='150' colspan='2' ><div align='center'>Declass&eacute;</div></th>";
echo "<th width='100' rowspan='2'><div align='center'>Moyenne</div></th>";
echo "<tr class='text'>";
echo "<th width='75'><div align='center'>Poid</div></th>";
echo "<th width='75'><div align='center'>Nb Pi</div></th>";
echo "<th width='75'><div align='center'>Poid</div></th>";
echo "<th width='75'><div align='center'>Nb Pi</div></th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><tr>" ;

$total_poids = 0;
$total_p_n = 0;
$total_p_d = 0;
$myart =new quantitative_detail ;
$select = "SELECT
  `plu`,
  SUM(poids_qtv) AS Tpoid,
  SUM(qte_qtv)AS TQte,
  `decl`
FROM
  quantitative_detail
WHERE
  `Num_ligne_qtv` = $Num_ligne_qtv
GROUP BY
  `plu`,
  `decl`
ORDER BY
  `quantitative_detail`.`plu` ASC";

$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);

  $num_plu=$myart->plu ;
  $poids_qtv=$myart->Tpoid ;
  $qte_qtv=$myart->TQte ;
  $decl=$myart->decl ;


	$sql = "SELECT PLU FROM plu WHERE `Num_PLU`=$num_plu ";
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
        $PLU = $row["PLU"];
    } 

$total_poids = $total_poids + $poids_qtv;

$Moyenne_qtv = $poids_qtv/$qte_qtv ;
$Moyenne_qtv = number_format($Moyenne_qtv, 3, ',', ' ')	;
$poids_qtv = number_format($poids_qtv, 3, ',', ' ')	;

echo "<tr class='text'>";
echo "<td width='50' height='30' ><div align='center'>$num_plu</div></td>";
echo "<td width='150'><div align='left'>$PLU</div></td>";

if ($decl=='0') {

echo "<td width='75'><div align='right'>$poids_qtv Kg</div></td>";
echo "<td width='75'><div align='right'>$qte_qtv Pi</div></td>";
 echo "<td width='75'><div align='right'></div></td>";
echo "<td width='75'><div align='right'></div></td>";
echo "<td width='100'><div align='center'>$Moyenne_qtv kg</div></td>";
echo "</tr>";
} else {
echo "<td width='75'><div align='right'></div></td>";
echo "<td width='75'><div align='right'></div></td>";
echo "<td width='75'><div align='right'>$poids_qtv Kg</div></td>";
echo "<td width='75'><div align='right'>$qte_qtv Pi</div></td>";
echo "<td width='100'><div align='center'>$Moyenne_qtv kg</div></td>";
echo "</tr>";
}

}
$total_poids = number_format($total_poids, 3, ',', ' ')	;

echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><tr>" ;
$myart =new quantitative_detail ;
$select = "SELECT
   SUM(poids_qtv) AS Ptotal,
   `decl`
FROM
  quantitative_detail
WHERE
  `Num_ligne_qtv` = $Num_ligne_qtv
GROUP BY
   `decl`
";

$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);

  $Ptotal=$myart->Ptotal ;
  $decl=$myart->decl ;

if ($decl=='0')
    $total_p_n = $Ptotal;
    $total_p_n = number_format( $total_p_n, 3, '.', ' ')	;
if ($decl=='1')
    $total_p_d = $Ptotal;
    $total_p_d = number_format( $total_p_d, 3, '.', ' ')	;
}
echo "</tbody>";
echo "<tfoot>";
echo "<tr class='text'>";
echo "<th width='200' colspan='2'><div align='center'>Total</div></th>";
echo "<th width='75' ><div align='center'></div>$total_p_n Kg</th>";
echo "<th width='75' ><div align='center'></div></th>";
echo "<th width='75' ><div align='center'></div>$total_p_d Kg</th>";
echo "<th width='75' ><div align='center'></div></th>";
echo "<th width='100' ><div align='center'></div></th>";
echo "<tr>";
echo "<tfoot>";
echo "</table>";
echo "<br>";



include 'menu/footer_edition.php';
?>