<?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");
/*
ordre=1
num_ligne_lot_decoupe=3
num_lot_decoupe=JR31CAN16
num_client_decoupe=55
Num_CatPlu=10
poid_decoupe=505
date_decoupe_d=04
date_decoupe_m=07
date_decoupe_y=2016
cloture=0
*/

$num_ordre=$_GET['ordre'];
$Num_ligne_qtv =$_GET['num_ligne_lot_decoupe'];
$num_lot_decoupe =$_GET['num_lot_decoupe'];
$num_client_decoupe =$_GET['num_client_decoupe'];
$date_decoupe_d=$_GET['date_decoupe_d'];
$date_decoupe_m=$_GET['date_decoupe_m'];
$date_decoupe_y=$_GET['date_decoupe_y'];
$poid_decoupe=$_GET['poid_decoupe'];

$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));

/*
echo "<br>date : $date_decoupe_qtv | $date_decoupe_sql | Num : $Num_ligne_qtv | Num ordre : $num_ordre | SERVER : ".$_SERVER['PHP_SELF']."<br>" ;
*/

// menu haut new-supp-modif

$myart =new clients;
$select = "select * FROM clients WHERE Num_Client='$num_client_decoupe'";
$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 ;
}

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

Menu_CSD ($num_ordre) ;

echo "<br>";

echo "<table width='600' border='0' cellspacing='2' cellpadding='2'>";
echo "<tr>";
echo "<td width='100'>Num Lot Utilis&#233; : ".$num_lot_decoupe."</td>";
echo "<td rowspan='2' width='100'><div align='center'><a class='' href='edition_qtv_imp.php?num_entre=$Num_ligne_qtv' TARGET=_BLANK><img src='images/print.png' width='20' height='20'></a></div></td>";
echo "<td width='100'>Nom Client : ".$Let_Client." | ".$Nom_Client."</td>";
echo "</tr><tr>";
echo "<td width='250'>Date D&#233;coupe : ".$date_decoupe_qtv."</td>";
echo "<td width='250'>Poids : ".$poid_decoupe." Kg</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 "<td colspan='2'></td>";

echo "</tr>";
$total_poids=0;
$myart =new quantitative_detail ;
$select = "select * FROM quantitative_detail  WHERE `Num_ligne_qtv`=$Num_ligne_qtv ORDER BY `quantitative_detail`.`plu` ASC";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_ligne_qtv_detv=$myart->Num_ligne_qtv_det ;
  $Num_ligne_qtv=$myart->Num_ligne_qtv ;
  $num_plu=$myart->plu ;
  $poids_qtv=$myart->poids_qtv ;
  $qte_qtv=$myart->qte_qtv ;
  $decl=$myart->decl ;
  $cloture=$myart->cloture ;

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

$Moyenne_qtv = $poids_qtv/$qte_qtv ;
$Moyenne_qtv = number_format($Moyenne_qtv, 3, ',', ' ')	;
$poids_qtv = number_format($poids_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 "<td width='50'><div align='center'>
<form id='form3' name='form3' method='get' action='modif_d_qtv_ligne.php'>
<input type='hidden' name='Num_ligne_qtv_detv' value='$Num_ligne_qtv_detv'/>
<input type='hidden' name='Num_plu_sel' value='$num_plu'/>
<input type='hidden' name='ordre' value='4'/>
<input type='hidden' name='num_ligne_lot_decoupe' value='$Num_ligne_qtv'/>
<input type='hidden' name='num_lot_decoupe' value='$num_lot_decoupe'/>
<input type='hidden' name='num_client_decoupe' value='$Num_Client'/>
<input type='hidden' name='poid_decoupe' value='$poid_decoupe'/>
<input type='submit' value='+'></form></td>";

echo "<td width='50'><div align='center'>
<form id='form4' name='form4' method='get' action='delete_d_qtv_lign.php'>
<input type='hidden' name='Num_ligne_qtv_detv' value='$Num_ligne_qtv_detv'/>
<input type='hidden' name='Num_plu_sel' value='$num_plu'/>
<input type='hidden' name='ordre' value='$num_ordre'/>
<input type='hidden' name='num_ligne_lot_decoupe' value='$Num_ligne_qtv'/>
<input type='hidden' name='num_lot_decoupe' value='$num_lot_decoupe'/>
<input type='hidden' name='num_client_decoupe' value='$Num_Client'/>
<input type='hidden' name='poid_decoupe' value='$poid_decoupe'/>
<input type='submit' value='-'></form></td>";

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><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 "<form id='form1' name='form1' method='get' action='ajout_d_qtv_lign.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<input type='hidden' name='num_ligne_lot_decoupe' value='$Num_ligne_qtv'/>";
echo "<input type='hidden' name='num_lot_decoupe' value='$num_lot_decoupe'/>";
echo "<input type='hidden' name='num_client_decoupe' value='$Num_Client'/>";
echo "<input type='hidden' name='poid_decoupe' value='$poid_decoupe'/>";

$qtv_clos="false";
$qtv_decl="false";
echo "<table width='600' border='1' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<td width='150'><select style='width:150px' name='id_plu' id='id_plu'>";

$myart =new plu;
$select = "SELECT * FROM `plu` WHERE `Num_PLU` BETWEEN 900 AND 999 ORDER BY `Num_PLU` ASC";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_PLU=$myart->Num_PLU ;
  $PLU=$myart->PLU ;

echo "<option value='$Num_PLU'>$PLU</option>";
}
echo "</select>";
echo "</td>";

echo "<td width='100'><div align='center'>
	  <input name='poids_qtv' type='text' id='poids_qtv' accesskey='2' tabindex='2' size='5' maxlength='5'> Kg	
	  </div></td>";
echo "<td width='100'><div align='center'>
	  <input name='qte_qtv' type='text' id='qte_qtv' accesskey='2' tabindex='2' size='5' maxlength='5'> Pi
	  </div></td>";
echo "<td width='100'>Decl ? <input name='qtv_decl' type='checkbox' id='qtv_decl' accesskey='2' tabindex='2' value='true'></td>";
echo "<td width='100'>Clot : <input name='qtv_clos' type='checkbox' id='qtv_clos' accesskey='2' tabindex='2' value='true'></td>";
echo "<td colspan='2'><div align='center'><input type='submit' value='+'></td>";
echo "</form>";
echo "";
echo "</tr></table>";



include 'menu/footer.php';
?>
