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

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

// menu haut new-supp-modif

echo "<center><br>";

/*
modif_fabrications_haut_check.php?
num_entre=1
Num_plu_Fabric=829
Cate_Fabric=3
Num_Client_Fabric=8
Date_Fabric=2016-02-01
Etat_Fabric=0
DLC_Fabric=2016-04-01
Num_Lot_Fabric=H16BLVE07
Traca_Fabric=377
Poid_Fabric=15.50
num_unitee_plu_intran=1
Observation_Fabric=31+barquettes
ok=Valider
*/

if (!isset($_GET['num_entre']))
{
    $Num_entre=($_POST['num_entre']);
	$Num_entre.=" Post";
   } else {
    $Num_entre=($_GET['num_entre']);
	$Num_entre.=" Get";
    }

echo "<br>Num Entre : ".$Num_entre."<br>" ;
$num_ligne=htmlentities($_POST['num_entre']);
$Num_plu_Fabric= $_POST['Num_plu_Fabric'];
$Cate_Fabric=htmlentities($_POST['Cate_Fabric']);
$Num_Client_Fabric=htmlentities($_POST['Num_Client_Fabric']);
$Date_Fabric=htmlentities($_POST['Date_Fabric']);
$DLC_Fabric=htmlentities($_POST['DLC_Fabric']);
$Etat_Fabric=htmlentities($_POST['Etat_Fabric']);
$Num_Lot_Fabric=htmlentities($_POST['Num_Lot_Fabric']);
$Traca_Fabric=htmlentities($_POST['Traca_Fabric']);
$Poid_Fabric=htmlentities($_POST['Poid_Fabric']);
$num_unitee_plu_intran=htmlentities($_POST['num_unitee_plu_intran']);
$Observation_Fabric=htmlentities($_POST['Observation_Fabric']);

$Num_Lot_Fabric =strtoupper($Num_Lot_Fabric) ;
$Semaine_Fabric =date("W", strtotime($Date_Fabric));


$sql = "SELECT Let_Client FROM clients WHERE Num_Client='$Num_Client_Fabric'";  
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
        $Let_Client_Fabric = $row["Let_Client"];
} 

$sql = "SELECT attribu_plu FROM plu WHERE Num_PLU='$Num_plu_Fabric'";   
$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
        $Let_Plu_Fabric = $row["attribu_plu"];
}

$Anne_Fabric=date("y", strtotime($Date_Fabric));
$Traca_Fabric_Cal=date("z", strtotime($Date_Fabric));

$Num_Lot_Calc=$Let_Client_Fabric.$Semaine_Fabric.$Let_Plu_Fabric.$Anne_Fabric ;

//$Car_Traca=trim ($Traca_Fabric);
$Car_Traca=strlen (trim ($Traca_Fabric));
// selectionne les 3 premier caracteres
$Car_dep = substr($Traca_Fabric, 0, 3); 
$nbcar_fin = $Car_Traca - 3 ;
// selectionne les caracteres finaux
$Car_fin = substr($Traca_Fabric, 3, $nbcar_fin);
// mise des 3 car si 1 2 3
$Car_traca_cal = strlen (trim ($Traca_Fabric_Cal));
switch ($Car_traca_cal) {
    case 1:
        $car_trac_deb="00".$Traca_Fabric_Cal ;
        break;
    case 2:
        $car_trac_deb="0".$Traca_Fabric_Cal ;
        break;
    case 3:
        $car_trac_deb=$Traca_Fabric_Cal ;
        break;
}
$Tracabilite_final_cal=$car_trac_deb.$Car_fin ;
echo "<br> extraction 3 : $Car_dep | $nbcar_fin | $Car_fin <br>" ;
echo "Traca calculer :$Car_traca_cal |  $Traca_Fabric_Cal | $car_trac_deb | $Tracabilite_final_cal<br>" ;

Echo "<center><font color='red'>Enregistrement</font></center>";

echo "<br>";
echo "num_ligne : ".$num_ligne." <br>";
echo "Nom Plu: ".$Num_plu_Fabric." | ".$Let_Plu_Fabric." <br>";
echo "Num_Categorie PLu : ".$Cate_Fabric." | ".$Etat_Fabric." <br>";
echo "Client : ".$Num_Client_Fabric." | ".$Let_Client_Fabric." <br>";
echo "DATE : ".$Date_Fabric." | ".$DLC_Fabric." | ".$Semaine_Fabric." | ".$Anne_Fabric."<br>";
echo "Lot : ".$Num_Lot_Fabric." | $Num_Lot_Calc   $Traca_Fabric_Cal | ".$Traca_Fabric."<br>";
echo "Prix Kg : ".$Poid_Fabric." | ".$num_unitee_plu_intran." <br>";
echo "obs : ".$Observation_Fabric." <br>";
echo "traca : $Traca_Fabric : $Car_Traca | $Tracabilite_final_cal <br>";

$sql = "UPDATE fabrications_haut SET 
`Num_plu_Fabric` = '$Num_plu_Fabric', 
`Cate_Fabric` = '$Cate_Fabric', 
`Client_Fabric` = '$Num_Client_Fabric', 
`Date_Fabric` = '$Date_Fabric', 
`DLC_Fabric` = '$DLC_Fabric',
`Num_Lot_Fabric` = '$Num_Lot_Calc', 
`Traca_Fabric` = '$Tracabilite_final_cal', 
`Poid_Fabric` = '$Poid_Fabric', 
`Observation` = '$Observation_Fabric', 
`Etat` = '$Etat_Fabric',  
`Semaine_Fabric` = '$Semaine_Fabric' 
WHERE `Num_Fabric` = '$num_ligne'";

echo "requet : ".$sql." <br>";

$res = mysqli_query($link, $sql);

echo "resultat requet : ".$res." <br>";


Header("Location: fabrications.php?limite=0");
?>