<?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  ;
// entete de la page
include 'menu/header.php';

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

$num_ordre=$_GET['ordre'];

if (isset($_GET['num_ligne_lot_decoupe'])){
  $num_ligne_lot_decoupe =$_GET['num_ligne_lot_decoupe'];
  $cloture ="";
  $poid_decoupe ="";
  $observations ="";
     
} else {
  $num_ligne_lot_decoupe ="";
  $num_lot_decoupe ="";
  $num_lot_decoupe ="";
  $Num_Client ="";
  $Num_categoriePlu ="";
  $CategoriePlu ="";
  $poid_entre ="";
  $cloture ="";
  $poid_decoupe ="";
  $observations =""; 
}

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

// titre page
echo "<center>"; 
echo "<div class='titre-text'><center>Cr&#233;atoin  d'une fiche de d&#233;coupe</div><br>" ;

echo "<table class='t-text' width='750' border='1' cellspacing='2' cellpadding='2'>";
echo "<tr>";
echo "<td width='150'>Num Lot Utilis&#233; :</td>";
echo "<form id='chglotdispo' name ='chglotdispo' method='GET' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<td width='200'><select name='num_ligne_lot_decoupe' id='num_ligne_lot_decoupe' STYLE='width:150' onchange='submit()'>";
echo "<OPTION VALUE='0' SELECTED>Tous les lots en cours</OPTION>\n";
$myart =new lot_dispo;
$select = "select * FROM lot_dispo WHERE `solde`='0'";
$select.=" AND IdNumClient='".$IdNumClient."'";
$select.=" ORDER BY num_lot_dispo ASC "; 

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

if  ($num_ligne_lot_decoupe==$num_ligne_lot_dispo)  {
  echo "<option value='$num_ligne_lot_dispo' selected='selected' >$num_lot_dispo | $num_lot_dispo_trac</option>";
  $num_lot_decoupe=$num_lot_dispo ;
  $num_ligne_lot_decoupe=$num_ligne_lot_decoupe ;
  
} else {
  echo "<option value='$num_ligne_lot_dispo' >$num_lot_dispo | $num_lot_dispo_trac</option>";
}
}
echo "</select></td>";
//

//
$myart =new entreabat;
$select = "select * FROM entreabat WHERE Num_Lot='$num_lot_decoupe' ";
$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 ;
		//$poid_entre=$myart->Poid_entre ;
		}

$select = "select * FROM lot_dispo WHERE num_ligne_lot_dispo='$num_ligne_lot_decoupe'";
// echo "<br>$select<br>" ;
$req = mysqli_query($link, $select);  
while ($row = mysqli_fetch_assoc($req)) {
        $num_lot_decoupe = $row["num_lot_dispo"];
        $num_lot_dispo_trac = $row["num_lot_dispo_trac"];
    }  

$myart =new lot;
$select = "select * FROM lot WHERE num_lot_decoupe='$num_lot_decoupe' " ;
$select.=" AND  num_lot_tace_decoupe='$num_lot_dispo_trac' " ;
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
$poid_entre=$myart->poid_decoupe ;
}
/*
echo "<br>$select<br>" ;
echo "Num Lot : $num_lot_decoupe | Num ligne lot : $num_ligne_lot_decoupe| Client : $Num_Client | Cateplu :$Num_categoriePlu " ;
*/

echo "</form>";
echo "<form id='form1' name='form1' method='POST' action='ajout_decoupe_check.php'>";
echo "<input type='hidden' name='num_ligne_lot_decoupe' value='$num_ligne_lot_decoupe'/>";
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='Num_CatPlu' value='$Num_categoriePlu'/>";

$myart =new categorieplu;
$select = "select * FROM categorieplu WHERE Num_CatPlu='$Num_categoriePlu'";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_CatPluf=$myart->Num_CatPlu ;
  $CategoriePlu=$myart->CategoriePlu ;
 } 
echo "<td width='150'>Categorie : </td>";
echo "<td width='200'>$CategoriePlu" ;
echo "</tr><tr>" ;
echo "<td>Client :</td>";
echo "";

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

echo "<td>$Let_Client | $Nom_Client</td>" ;

}

echo "<td width='150'>Date D&eacute;coupe</td>";
echo "<td width='200'>"; //.$Date_Entre;
  
  $class = '';
  $fyear='2010';
  $lyear='2050';
  $name = 'date_decoupe';

  $yr=date("Y", strtotime($date));
  $mo=date("m", strtotime($date));
  $dy=date("d", strtotime($date));
  
 // Jour 
  
  $s="<SELECT NAME=\"${name}_d\" class='$class'>\n"; 
  $s.="<OPTION VALUE=$dy>$dy</OPTION>\n";
  $sclt=""; 
  for ($i=1;$i<=31;$i++) 
  { 
  $i2="0$i"; 
  $i2=substr($i2, -2); 
  if ($i2==$dy) 
  $sclt=" SELECTED"; 
  else 
  $sclt=""; 
  $s.="<OPTION VALUE=\"$i2\"$sclt>$i</OPTION>\n";
  } 
  $s.="</SELECT> / "; 

 // Mois 
  
  $s.="<SELECT NAME=\"${name}_m\" class='$class'>\n"; 
  $s.="<OPTION VALUE=$mo>$mo</OPTION>\n";
  $sclt=""; 
  for ($i=1;$i<=12;$i++) 
  { 
  $i2="0$i"; 
  $i2=substr($i2, -2); 
  if ($i2==$mo) 
  $sclt=" SELECTED"; 
  else 
  $sclt=""; 
  $mon2=date("M", mktime(0, 0, 0, $i, 1, 2001));
  $s.="<OPTION VALUE=\"$i2\"$sclt>$mon2</OPTION>\n";
  } 
  $s.="</SELECT> / "; 

 // Année 
  
  $s.="<SELECT NAME=\"${name}_y\" class='$class'>\n"; 
  $s.="<OPTION VALUE=$yr>$yr</OPTION>\n";
  $sclt=""; 
  for ($i=$fyear;$i<=$lyear;$i++)
  { 
  $i2="$i"; 
  if ($i2==$yr) 
  $sclt=" SELECTED"; 
  else 
  $sclt=""; 
  $s.="<OPTION VALUE=\"$i\"$sclt>$i</OPTION>\n"; 
  } 
  $s.="</SELECT>\n"; 
    echo"$s";
echo "</td></tr>";
echo "<tr>";

echo "<td width='150'>Cat&#233;gorie d&#233;coupe</td>";
// echo "categorie decoupe : $categorie_decoupe" ; //
echo "<td width='200'><select style='width:100px' name='num_nat_decoupe' id='num_cate_decoupe' accesskey='7' tabindex='7'>";
echo "<OPTION VALUE='0' SELECTED>Toutes</OPTION>\n";
$myart =new categorie_decoupe;
$select = 'select * FROM categorie_decoupe';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_cate_decoupe=$myart->num_cate_decoupe ;
  $cate_decoupe=$myart->cate_decoupe ;
  $lettre_trace=$myart->lettre_trace ;
  
if  ($categorie_decoupe==$num_cate_decoupe)   

  echo "<option value='$num_cate_decoupe' selected='selected' >$num_cate_decoupe | $cate_decoupe</option>";
else
  echo "<option value='$num_cate_decoupe'>$num_cate_decoupe | $cate_decoupe</option>";
}
echo "</select></td>";

//echo "<input type='hidden' name='num_entre' value='$num_entre'/>";
//echo "<input type='hidden' name='semaine_decoupe' value='$semaine_decoupe'/>";
//echo "NumEntre : $num_entre | semaine decoupe : $semaine_decoupe" ;

echo "<td>Poids : </td>";
echo "<td>$poid_entre Kg</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Cl&#244;turer ? : </td>";
if ($cloture==1) {
echo "<td colspan='1'>oui <input name='cloture' type='radio' id='cloture' accesskey='9' tabindex='9' value='1' checked>
non <input name='cloture' type='radio' id='cloture' accesskey='9' tabindex='9' value='0'></td>";
} else {
echo "<td colspan='1'>oui <input name='cloture' type='radio' id='cloture' accesskey='9' tabindex='9' value='1'>
non <input name='cloture' type='radio' id='cloture' accesskey='9' tabindex='9' value='0' checked></td>";
}
// echo "</tr>";
// echo "<tr>";
echo "<td>Quantitative ? : </td>";
echo "<td colspan='1'>oui <input name='qtv' type='radio' id='qtv' accesskey='9' tabindex='9' value='1'>
non <input name='qtv' type='radio' id='qtv' accesskey='9' tabindex='9' value='0' checked></td>";
echo "</tr>";
echo "<tr>";

echo "<td>Poids : </td>";
echo "<td colspan='1'><input name='poid_decoupe' type='text' id='poid_decoupe' accesskey='10' tabindex='10' size='10' maxlength='10' value='$poid_decoupe'> Kg</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Observations</td>";
echo "<td colspan='4'><input name='observations' type='text' id='observations' accesskey='11' tabindex='11' size='50' maxlength='50' value='$observations'></td>";
echo "</tr>";
echo "<td colspan='4'><div align='center'>";
echo "<input type='submit' value='* OK *'>
      </div></td>";
echo "<tr>";
echo "</table></form><br>";



include 'menu/footer.php';
?>
