<?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, $Moyenne_qtv, $total_poids ;

// entete de la page
include 'menu/header.php';

$date = date("d-m-Y");
/*
consult_detail_qtv.php?
num_entre=3&
ordre=2
*/

$num_ordre=$_GET['ordre'];
$Num_ligne_qtv =$_GET['num_entre'];

/*
$date_decoupe_sql=date("Y-m-d", mktime(0,0,0,$date_decoupe_m,$date_decoupe_d,$date_decoupe_y));
$date_decoupe_qtv=date("d/m/y", mktime(0,0,0,$date_decoupe_m,$date_decoupe_d,$date_decoupe_y));
*/

$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=$myart->Num_ligne_qtv ;
	$date_decoupe=$myart->date_decoupe ;
	$semaine_decoupe=$myart->semaine_decoupe ;
	$num_client_decoupe=$myart->num_client ;
	$num_lot_decoupe=$myart->num_lot ;
	$tracabilite=$myart->tracabilite ;
	$poid_decoupe=$myart->poid_decoupe ;
	$cloture=$myart->cloture ;
	$observations=$myart->observations ;
}

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

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

    

$date_e=date("d/m/Y", strtotime($date_decoupe));
$date_jours=date("z", strtotime($date_decoupe));


echo "<center><HR size='1' width='500'>";
echo "<b>Fiche de d&#233;coupe Quantitatve detail</b>";
echo "<center><HR size='1' width='500'>";

Menu_CSD ($num_ordre) ;

echo "<br>";
echo "<table width='500' border='0' cellspacing='2' cellpadding='2'>";
echo "<tr class='t-text'>";
echo "<td width='250'>Num Lot Utilis&#233; : ".$num_lot_decoupe."|".$tracabilite."</td>";
echo "<td width='250'>Nom Client : ".$Let_Client." | ".$Nom_Client."</td>";
echo "</tr><tr>";
echo "<td width='250'>Date D&#233;coupe : ".$date_e."</td>";
echo "<td width='250'>Poids : ".$poid_decoupe." Kg</td>";
echo "</tr><tr>";
echo "<td colspan=2>Observations : ".$observations."</td>";
echo "</tr></table>";
echo "<br><br>";

echo "<table width='600' border='1' cellspacing='2' cellpadding='2'>";
echo "<tr>";
echo "<td width='50'><span class='t-text'><div align='center'>PLU</td>";
echo "<td width='175'><span class='t-text'><div align='center'>Designation</td>";
echo "<td width='75'><span class='t-text'><div align='center'>Poids</td>";
echo "<td width='75'><span class='t-text'><div align='center'>Qte</td>";
echo "<td width='75'><span class='t-text'><div align='center'>Moy</td>";
echo "<td width='75'><span class='t-text'><div align='center'>Decl</td>";
echo "<td width='75'><span class='t-text'><div align='center'>Clot</td>";


echo "</tr>";
$total_poids=0;
$myart =new quantitative_detail ;
$select = "SELECT
  `plu`,
  SUM(poids_qtv) AS Tpoid,
  SUM(qte_qtv)AS TQte,
  `decl`,
  `cloture`
FROM
  quantitative_detail
WHERE
  `Num_ligne_qtv` = $Num_ligne_qtv
GROUP BY
  `plu`,
  `decl`
ORDER BY
  `quantitative_detail`.`plu` ASC";
$result = mysql_query($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 ;
  $cloture=$myart->cloture ;

	$sql = "SELECT PLU FROM plu WHERE `Num_PLU`=$num_plu ";
	$req = mysql_query($sql);
	$PLU = mysql_result($req,0);

$Moyenne_qtv = $poids_qtv/$qte_qtv ;
$Moyenne_qtv = number_format($Moyenne_qtv, 3, ',', ' ')	;
echo "<tr>";
echo "<td width='50'><div align='center'>$num_plu</div></td>";
echo "<td width='175'><div align='center'>$PLU</div></td>";
echo "<td width='75'><div align='center'>$poids_qtv Kg</div></td>";
echo "<td width='75'><div align='center'>$qte_qtv Pi</div></td>";
echo "<td width='75'><div align='center'>$Moyenne_qtv kg</div></td>";

	if ($decl==1) {
		echo "<td width='75'><div align='center'>
			<img src='images/redpin.png' width='20' height='20'>
		      </div></td></span>";
	} else {
		echo "<td width='75' height='20' ><div align='center'>

			  </div></td></span>";
	}

    if ($cloture==1) {
		echo "<td width='75'><div align='center'>
			<img src='images/coche.gif' width='20' height='20'>
		      </div></td></span>";
	} else {
		echo "<td width='75'><div align='center'>
			  <img src='images/croix.gif' width='20' height='20'>
			  </div></td></span>";
	}


echo "</tr>"; 
$total_poids = $total_poids + $poids_qtv ;
}
$total_poids = number_format($total_poids, 3, ',', ' ')	;
echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>";
echo "<td colspan='2'><span class='t-text'><div align='center'>Total</div></td>";
echo "<td width='50'><span class='t-text'><div align='center'>$total_poids Kg</div></td>";
echo "<td colspan='6'><span class='t-text'><div align='center'></div></td>";
echo "</tr>";
echo "</table>";
echo "<br><br>";

echo "";



include 'menu/footer.php';
?>
