<?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

/*
http://192.168.1.200/horius/modif_fa_haut.php?ordre=1&num_fa_ligne=1&facnumber=201900001&num_client_fa=10%20200
*/

include 'menu/header.php';

if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['num_fa_ligne'])) { $num_fa_ligne=$_POST['num_fa_ligne']; }  else {$num_fa_ligne=''; }
    if (isset($_POST['facnumber'])) { $facnumber=$_POST['facnumber']; }  else {$facnumber=''; }
    if (isset($_POST['num_client_fa'])) { $num_client_fa=$_POST['num_client_fa']; }  else {$num_client_fa=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['num_fa_ligne'])) { $num_fa_ligne=$_GET['num_fa_ligne']; }  else {$num_fa_ligne=''; }
    if (isset($_GET['facnumber'])) { $facnumber=$_GET['facnumber']; }  else {$facnumber=''; }
    if (isset($_GET['num_client_fa'])) { $num_client_fa=$_GET['num_client_fa']; }  else {$num_client_fa=''; }
		$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>
*/


//Menu_CSD ($num_ordre) ;

$sql ="SELECT * FROM gestion_fa_haut";
$sql.=" WHERE rowid='".$num_fa_ligne."'";
$sql.=" AND IdNumClient='".$IdNumClient."'";  
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
  $num_client_fa = $row["num_client_fa"];
  $date_fa = $row["date_fa"];
  $date_bl = $row["date_bl"];
  $type = $row["type"];
  $ref_int = $row["ref_int"];
  $ref_ext = $row["ref_ext"];
  $ref_client = $row["ref_client"];
  $semaine_fa = $row["semaine_fa"]; 
  $facnumber = $row["facnumber"];
  $total_ht = $row["total_ht"];
  $total_ttc = $row["total_ttc"];
  $total_tva = $row["total_tva"];
  $acompte = $row["acompte"];
  $Solde_ttc = $row["Solde_ttc"];
  $fa_etat = $row["fa_etat"];
  $fa_paie = $row["fa_paie"];
  $fa_cpt = $row["fa_cpt"];
  $fa_ed = $row["fa_ed"];
  $date_ech = $row["date_ech"];
  $fa_cond_reglement = $row["fa_cond_reglement"]; 
  $fa_cond_transport = $row["fa_cond_transport"];
  $note_private = $row["note_private"]; 
  $note_public = $row["note_public"]; 
  $situation_final = $row["situation_final"]; 
  $Timestamp = $row["Timestamp"];

$sqlb = "SELECT * FROM clients_base WHERE Num_Client='$num_client_fa'"; 
$reqb = mysqli_query($link, $sqlb);
while ($row = mysqli_fetch_assoc($reqb)) {
        $Nom_Client = $row["Nom_Client"];
    }  
}

switch ($type) {
  case 0:
 echo "<br><center><b>Modification de la Facture N&deg; $facnumber </b>" ;
 $num_fa_type="Facture" ;
  break;
 
  case 1:
  echo "<br><center><b>Modification de l'Avoir N&deg; $facnumber </b>" ;
  $num_fa_type="Avoir" ;
  break;
}

echo "<center><HR size='1' width='800'></center>";
echo "<form id='ChgCateFabric' id='thing-alerts' name ='ChgCateFabric' method='GET' action='traitement_modif_fa_haut.php'>";
echo "<input type='hidden' name='ordre' value='$num_ordre'/>";
echo "<input type='hidden' name='num_fa_ligne' value='$num_fa_ligne'/>";
echo "<input type='hidden' name='facnumber' value='$facnumber'/>";
echo "<input type='hidden' name='num_client_fa' value='$num_client_fa'/>";
echo "<table class='t-text' width='900' border='1' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<th width='120' align='center' valign='middle'>Date $num_fa_type : </th>
      <th width='120' align='center' valign='middle'><input type='date' name='date_fa' value ='$date_fa' required></th>";
echo "<th width='120' align='center' valign='middle'>Client : </th>
 	    <th width='120' align='center' valign='middle'>";
echo "<select name='Num_client_liv' id='Num_client_liv' style='width:150px' 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_fa) {
    echo "<option value='$Num_Client' Selected>$Nom_Client</option>";
    } else {
    echo "<option value='$Num_Client'>$Nom_Client</option>";
    }
}
echo "</select></th>";

echo "<th width='120' align='center' valign='middle'>Date de livaison :</th>";
echo "<th width='120' align='left' valign='middle'><input type='date' name='date_bl' value='$date_bl' required></th> ";
echo "</tr> ";
echo "<tr>";
echo "<th align='center' valign='middle' scope='row'>Code Transport</th>";
echo "<td><select style='width:150px' name='fa_cond_transport' id='fa_cond_transport' 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 ($num_trsp==$fa_cond_transport){
  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 "<th align='center' valign='middle' >Code Paiement</th>";
echo "<td><select style='width:200px' name='fa_cond_reglement' id='fa_cond_reglement' 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 ($num_paie==$fa_cond_reglement){
	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 "<th align='center' valign='middle'>Date de Echéance :</th>";
echo "<th width='120' align='left' valign='middle'><input type='date' name='date_ech' value='$date_ech' required></th> ";
echo "</th></tr> ";

$sqlb = "SELECT * FROM gestion_bl_haut WHERE num_li_bl='$ref_ext'"; 
$reqb = mysqli_query($link, $sqlb);
while ($row = mysqli_fetch_assoc($reqb)) { $ref_ext_val = $row["num_bl"];} 

$sqlb = "SELECT * FROM gestion_br_haut WHERE num_li_br='$ref_int'"; 
$reqb = mysqli_query($link, $sqlb);
while ($row = mysqli_fetch_assoc($reqb)) { $ref_int_val = $row["num_br"];}  

echo "<th width='120' align='center' valign='middle'>Refs int BR:</th>
      <th width='120' align='center' valign='middle'colspan ='2'><input type='ref_int' name='ref_int' value ='$ref_int_val' disabled></th>";
echo "<th width='120' align='center' valign='middle'>Refs Ext BL: </th>
      <th width='120' align='center' valign='middle'colspan ='2'><input type='ref_ext' name='ref_ext' value ='$ref_ext_val' disabled></th>";
echo "<tr><th align='center' valign='middle'><center> Reference Client :</th>";
echo "<th width='120' align='center' valign='middle'colspan ='5'><input type='ref_client' name='ref_client' value ='$ref_client' size=100></th>";

echo "<tr><th align='center' valign='middle' colspan ='3'><center> Observations Privée :";
echo "<TEXTAREA name='note_private' id='note_private' accesskey='15' tabindex='15' rows='5' cols='50' >$note_private</TEXTAREA></th>";

echo "<th align='center' valign='middle' colspan ='3'><center> Observations Public / $num_fa_type:";
echo "<TEXTAREA name='note_public' id='note_public' accesskey='15' tabindex='15' rows='5' cols='50' >$note_public</TEXTAREA></th>";       

echo "<tr>";
echo "<th colspan='6' 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';
?>
