<?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 ,$dlc_plu_intrant_sel, $num_unite_intrant_sel, $Poids_intrant, 
$observations, $cloture  ;
// entete de la page
include 'menu/header.php';

$date = date("d-m-Y");
/*
ordre=1
num_cate_intrant=4
Date_Entre_d=14
Date_Entre_m=02
Date_Entre_y=2016
Num_Plu=4
*/
if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['Date_Entre_y'])) { $Date_Entre_y=htmlentities($_POST['Date_Entre_y']); }  else {$Date_Entre_y=date("Y"); }
		if (isset($_POST['Date_Entre_m'])) { $Date_Entre_m=htmlentities($_POST['Date_Entre_m']); }  else {$Date_Entre_m=date("m"); }
		if (isset($_POST['Date_Entre_d'])) { $Date_Entre_d=htmlentities($_POST['Date_Entre_d']); }  else {$Date_Entre_d=date("d"); }
		if (isset($_POST['num_cate_intrant'])) { $num_cate_intrant_sel=$_POST['num_cate_intrant']; } else {$num_cate_intrant_sel=''; }
		if (isset($_POST['Num_Plu'])) { $Num_Plu_sel=$_POST['Num_Plu']; } else {$Num_Plu_sel=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['Date_Entre_y'])) { $Date_Entre_y=htmlentities($_GET['Date_Entre_y']); }  else {$Date_Entre_y=date("Y"); }
		if (isset($_GET['Date_Entre_m'])) { $Date_Entre_m=htmlentities($_GET['Date_Entre_m']); }  else {$Date_Entre_m=date("m"); }
		if (isset($_GET['Date_Entre_d'])) { $Date_Entre_d=htmlentities($_GET['Date_Entre_d']); }  else {$Date_Entre_d=date("d"); }
		if (isset($_GET['num_cate_intrant'])) { $num_cate_intrant_sel=$_GET['num_cate_intrant']; } else {$num_cate_intrant_sel=''; }
		if (isset($_GET['Num_Plu'])) { $Num_Plu_sel=$_GET['Num_Plu']; } else {$Num_Plu_sel=''; }
		$valForm="POST" ;
}

$Date_entre = date("d/m/y", mktime(0,0,0,$Date_Entre_m,$Date_Entre_d,$Date_Entre_y));
/*
echo "<HR size='2' width='500'>";
echo "De : $Date_entre | Ye : $Date_Entre_y | Me : $Date_Entre_m | De : $Date_Entre_d | plu sel : $Num_Plu_sel | ";
echo "NumCate: $num_cate_intrant_sel | Num ordre : $num_ordre | SERVER : ".$_SERVER['PHP_SELF']."<br>" ;
echo "<HR size='2' width='500'>";
*/
// menu haut new-supp-modif



echo "<center><HR size='1' width='500'>";
echo "<b>Cr&#233;ation d'une entr&#233;e d'intrant</b>";
echo "<center><HR size='1' width='500'>";

Menu_CSD ($num_ordre) ;

echo "<br>";
echo "<table width='650' id='tableauintrant'>";
echo "<tr>";
echo "<td width='100'>Cat&#233;gorie intrant :</td>";
echo "<form id='chglotdispo' name ='chglotdispo' method='GET' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<td><select name='num_cate_intrant' id='num_cate_intrant' STYLE='width:120' onchange='submit()'>";
echo "<option value='0'>*-*-*</option>";
$myart =new categorie_intrant;
$select = 'select * FROM categorie_intrant ORDER BY categorie_plu_intran ASC';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_cate_intrant=$myart->num_cate_plu_intran ;
  $categorie_plu_intran=$myart->categorie_plu_intran ;
  
if  ($num_cate_intrant_sel==$num_cate_intrant) {
    echo "<option value='$num_cate_intrant' selected='selected' >$categorie_plu_intran</option>";
   
} else {
  echo "<option value='$num_cate_intrant'>$categorie_plu_intran</option>";
}}
echo "</select></td>";


echo "<td width='100'>Date Entr&#233;e :</td>";
echo "<td width='190'>"; //.$Date_Entre;
  
  $class = '';
  $fyear='2010';
  $lyear='2050';
  $name = 'Date_Entre';

  $yr=$Date_Entre_y;
  $mo=$Date_Entre_m;
  $dy=$Date_Entre_d;
  
 // 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 "<td width='150'>Intant :</td>";

echo "<td width='150'><select style='width:120px' name='Num_Plu' id='Num_Plu' onchange='submit()'>";
echo "<option value='0'>*-*-*</option>";
$myart =new plu_intrant;
$select = "select * FROM plu_intrant WHERE `num_cate_intrant` = $num_cate_intrant_sel ";
$select.=" AND IdNumClient='".$IdNumClient."'";
$select.=" ORDER BY `plu_intrant`.`nom_plu_intrant` ASC";
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_plu_intrant=$myart->num_plu_intrant ;
  $nom_plu_intrant=$myart->nom_plu_intrant ;
  $dlc_plu_intrant=$myart->dlc_plu_intrant ;
  $num_unite_intrant=$myart->num_unite ;
  
if  ($Num_Plu_sel==$num_plu_intrant) {  
  echo "<option value='$num_plu_intrant' selected='selected' >$nom_plu_intrant</option>";
$dlc_plu_intrant_sel=$dlc_plu_intrant ;
$num_unite_intrant_sel=$num_unite_intrant ;
} else {
  echo "<option value='$num_plu_intrant'>$nom_plu_intrant</option>";
}}
echo "</select></td>";

echo "</form>";
/*
ordre=1
num_cate_intrant=4
Date_Entre_d=17
Date_Entre_m=02
Date_Entre_y=2016
Num_Plu=4

$num_ordre=$_GET['ordre'];
$num_cate_intrant_sel =$_GET['num_cate_intrant'];
$Num_Plu_sel =$_GET['Num_Plu'];

*/

echo "<form id='form2' name='form2' method='POST' action='saisie_entre_intrants_check.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<input type='hidden' name='num_cate_intrant' value='$num_cate_intrant_sel'/>";
echo "<input type='hidden' name='Date_Entre_d' value='$Date_Entre_d'/>";
echo "<input type='hidden' name='Date_Entre_m' value='$Date_Entre_m'/>";
echo "<input type='hidden' name='Date_Entre_y' value='$Date_Entre_y'/>";
echo "<input type='hidden' name='Num_Plu' value='$Num_Plu_sel'/>";

echo "<td width='100'>Date DLC :<br>(+$dlc_plu_intrant_sel jours)</td>";

$Date_dlc_calc = date("m/d/Y", mktime(0,0,0,$Date_Entre_m,$Date_Entre_d+$dlc_plu_intrant_sel,$Date_Entre_y));

echo "<td width='190'>";
  
  $class = '';
  $fyear='2010';
  $lyear='2050';
  $name = 'Date_DLC';

  $yr=date("Y", strtotime($Date_dlc_calc));
  $mo=date("m", strtotime($Date_dlc_calc));
  $dy=date("d", strtotime($Date_dlc_calc));
  
 // 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><tr>" ;
echo "<td width='150'>Fournisseur  Intrant :</td>";
echo "<td width='150'><select style='width:120px' name='id_presta' id='id_presta'>";
echo "<option value='0'>*-*-*</option>";
$myart =new fournisseurs;
$select = 'select * FROM fournisseurs WHERE `num_cate_four`>1';
$select.=" AND IdNumClient='".$IdNumClient."'";
$result = mysqli_query($link, $select);
$myart->getnum($result);
  while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $id_presta=$myart->Num_fournisseur ;
  $Ident_four=$myart->Ident_four ;
  
  echo "<option value='$id_presta'>$Ident_four</option>";

}

echo "</select></td>";


echo "<td width='100'>Num Bl : </td>";
echo "<td width='190'><input name='Num_Bl' type='text' id='Num_Bl' accesskey='11' tabindex='11' size='20' maxlength='30'>";
echo "</td></tr>";
echo "<tr>";

echo "<td width='100' >Poids : $num_unite_intrant_sel </td>";

echo "<td colspan='2'><input type='text' name='Poids_intrant' id='Poids_intrant' accesskey='10' tabindex='10' size='10' maxlength='10' value='$Poids_intrant' placeholder='5.50'>";

echo "  <select style='width:100px' name='num_unite' id='num_unite' accesskey='7' tabindex='7'>";

$myart =new unitee;
$select = 'select * FROM unitee';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_unite=$myart->num_unite ;
  $nom_unite_ini=$myart->nom_unite_ini ;

 if  ($num_unite==$num_unite_intrant_sel)   
  echo "<option value='$num_unite' selected='selected' >$nom_unite_ini</option>";
else
  echo "<option value='$num_unite' >$nom_unite_ini</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>Cl&#244;turer ? : ";
if ($cloture==1) {
echo "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 "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 "<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' placeholder='Blanquette' </td>";
echo "</tr>";
echo "<td colspan='4'><div align='center'>";
echo "<input type='submit' value='* OK *'>
      </div></td>";
echo "<tr>";
echo "</table>";
echo "</form>";


include 'menu/footer.php';
?>
