<?php
include("include/data.php");
Init_boutique();
global $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $result, $Nom_untie_intrant , 
$NbLigne, $semaine, $limitesuivante, $limiteprecedente, $total, $page, $i ;
// entete de la page

include 'menu/header.php';

if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['Num_client_liv'])) { $Num_client_liv=$_POST['Num_client_liv']; }  else {$Num_client_liv=''; }
		if (isset($_POST['date_livr'])) { $date_livr=$_POST['date_livr']; } else {$date_livr=''; }
		if (isset($_POST['date_bl'])) { $date_bl=$_POST['date_bl']; } else {$date_bl=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['Num_client_liv'])) { $Num_client_liv=$_GET['Num_client_liv']; }  else {$Num_client_liv=''; }
		if (isset($_GET['date_livr'])) { $date_livr=$_GET['date_livr']; } else {$date_livr=''; }
		if (isset($_GET['date_bl'])) { $date_bl=$_GET['date_bl']; } else {$date_bl=''; }
		$valForm="GET" ;
}

/*
echo "<br>num entre : $num_entre | $select<br>" ;
echo "$Date_Fabric | $date_e | $DLC_Fabric | $date_dlc | $Num_Lot_Fabric | $Traca_Fabric<br>" ;
echo "$Client_Fabric | $Unite_Fabric | $Observation | $Etat | $Timestamp<br>" ;
echo "$num_plu_intant | $nom_plu_intrant | $num_cate_intrant | $num_unite_plu_intrant | $dlc_plu_intrants<br>" ;
//
//<a class='' href='consult_intrants.php?num_entre=$Num_entre_intrant&ordre=2'></a>
*/

echo "<br><center><b>Saisie d'un Bon de Retour</b></center>" ;
Menu_CSD ($num_ordre) ;
echo "<center><HR size='1' width='500'></center>";
echo "<form id='ChgCateFabric' id='thing-alerts' name ='ChgCateFabric' method='GET' action=''>";
//echo "<input type='hidden' name='num_entre' value='$num_entre'/>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<table class='t-text' width='750' border='1' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<th colspan=4>Date du Br : <input type='date' name='date_bl' value ='$aujourdhui_db' required></th>";
echo "</tr>";
echo "<th width='120' align='center' valign='middle'>Client : </th>
 	    <th width='120' align='left' valign='middle'>";
echo "<select name='Num_client_liv' id='Num_client_liv' onchange='submit()'>";
echo "<OPTION VALUE='0' SELECTED>Toutes</OPTION>\n";

$select = "SELECT * FROM clients_base WHERE `IdNumClient`='".$IdNumClient."'";
$req = mysqli_query($link, $select);
while ($row = mysqli_fetch_assoc($req)) {
        $Num_Client = $row["Num_Client"];
        $Nom_Client = $row["Nom_Client"];
       
    if ($Num_Client===$Num_client_liv) {
    echo "<option value='$Num_Client' Selected>$Nom_Client</option>";
    $CodeTrsp = $row["Code_trsp"];
		$CodePaiement = $row["Code_paiement"];
    $i=1 ;
    } else {
    echo "<option value='$Num_Client'>$Nom_Client</option>";
    }
}
echo "</select>";
echo "</form>";
if ($i==1) {

echo "<th align='center' valign='middle' scope='row'>Code Transport</th>";
echo "<td><select style=' width: 200px;' name='CodeTrsp' id='CodeTrsp' accesskey='13' tabindex='13'>";

$sql = 'SELECT * FROM categorie_trsp';
$sql.=" WHERE `IdNumClient`='".$IdNumClient."'";  
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
  $num_li_trsp = $row["Num_Ligne_Cate_Trsp"];
  $Code_Trsp = $row["Code_Trsp"];
//  echo "$num_li_bl | $num_bl_base <br>" ;
 
 if ($CodeTrsp==$num_li_trsp){
  echo "<option value='$num_li_trsp' selected>$num_li_trsp | $Code_Trsp</option>";
	} else {
	echo "<option value='$num_li_trsp'>$num_li_trsp | $Code_Trsp</option>";
	}
}

echo "</select></td>";	
	echo "<tr>";
echo "<th align='center' valign='middle' >Code Paiement</th>";
echo "<td><select style=' width: 200px;' name='CodePaiement' id='CodePaiement' accesskey='14' tabindex='14'>";

$sql1 = 'SELECT * FROM categorie_paiement';
$sql1.=" WHERE `IdNumClient`='".$IdNumClient."'";  
$req1 = mysqli_query($link, $sql1);
while ($row = mysqli_fetch_assoc($req1)) {
  $num_li_paiement = $row["Num_Ligne_Cate_Paiement"];
  $Code_paiement = $row["Code_Paiement"];
//  echo "$num_li_bl | $num_bl_base <br>" ;
	
	if ($CodePaiement==$num_li_paiement){
	echo "<option value='$num_li_paiement' selected>$num_li_paiement | $Code_paiement</option>";
	} else {
	echo "<option value='$num_li_paiement'>$num_li_paiement | $Code_paiement</option>";
		}
  
}

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


echo "<form id='ChgCateFabric' id='thing-alerts' name ='ChgCateFabric' method='GET' action='ajout_br_haut.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<input type='hidden' name='Num_client_liv' value='$Num_client_liv'/>";
echo "<input type='hidden' name='CodeTrsp' value='$CodeTrsp'/>";
echo "<input type='hidden' name='CodePaiement' value='$CodePaiement'/>";
echo "<input type='hidden' name='date_bl' value='$date_bl'/>";
echo "<th align='center' valign='middle'>Date du Retour :</th>";
echo "<th width='120' align='left' valign='middle'><input type='date' name='date_livr' required></th> ";
echo "</th></tr> ";
if ($i==1) {
echo "<tr><td colspan ='4'><center> Bon de livraison Associ&eacute; :";
echo "<select name='Num_bl_ref' id='Num_bl_ref'>";
echo "<OPTION VALUE='0' SELECTED>*-*</OPTION>\n";

$select = "SELECT * FROM `gestion_bl_haut` WHERE `IdNumClient`='".$IdNumClient."'";
$select.= " AND `num_client_bl`='".$Num_client_liv."' ORDER BY `gestion_bl_haut`.`num_li_bl` DESC";
$req = mysqli_query($link, $select);
while ($row = mysqli_fetch_assoc($req)) {
        $num_bl = $row["num_bl"];
        $date_livraison_bl = $row["date_livraison"];
       
    echo "<option value='$num_bl'>$date_livraison_bl | $num_bl</option>";
}
echo "</select>";


echo "</td>";
echo "<tr><td colspan ='4'><center> Observations :";
echo "<TEXTAREA name='observations' id='observations' accesskey='15' tabindex='15' value='$observations' rows='5' cols='50' ></TEXTAREA></td>";
        
}

echo "<tr>";
echo "<th colspan='4' align='center' valign='middle'>
	  <input type='submit' name='ok' id='ok' value='Valider' accesskey='11' tabindex='11'>
	  &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
	  <input name='an' type='button' id='an' accesskey='12' tabindex='12' value='Retour' onClick='history.back()'></th>";
echo " </tr></div>";
echo "</table>";
echo "</form>";
echo "</center><br>" ;


include 'menu/footer.php';
?>
