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

// entete de la page
/*
http://192.168.1.200/horius/traitement_modif_fa_haut.php?ordre=4
num_fa_ligne=1
facnumber=201900001
num_client_fa=10+200
date_fa=2019-01-20
Num_client_liv=10+200
date_bl=2019-01-10
fa_cond_transport=1
fa_cond_reglement=1
date_ech=2019-02-17
ref_client=Cde+du+17.01.2019
note_private=Retour+trop+important
note_public=Merci+de+nous+envoyer+votre+reglement+au+plus+vite
ok=Valider
*/

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=''; }
		if (isset($_POST['date_fa'])) { $date_fa=$_POST['date_fa']; } else {$date_fa=''; }
		if (isset($_POST['date_bl'])) { $date_bl=$_POST['date_bl']; } else {$date_bl=''; }
		if (isset($_POST['fa_cond_transport'])) { $fa_cond_transport=$_POST['fa_cond_transport']; } else {$fa_cond_transport=''; }
		if (isset($_POST['fa_cond_reglement'])) { $fa_cond_reglement=$_POST['fa_cond_reglement']; } else {$fa_cond_reglement=''; }
		if (isset($_POST['ref_client'])) { $ref_client=$_POST['ref_client']; } else {$ref_client=''; }
		if (isset($_POST['note_private'])) { $note_private=$_POST['note_private']; } else {$note_private=''; }
		if (isset($_POST['note_public'])) { $note_public=$_POST['note_public']; } else {$note_public=''; }
		if (isset($_POST['date_ech'])) { $date_ech=$_POST['date_ech']; } else {$date_ech=''; }


	
		$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=''; }
		if (isset($_GET['date_fa'])) { $date_fa=$_GET['date_fa']; } else {$date_fa=''; }
		if (isset($_GET['date_bl'])) { $date_bl=$_GET['date_bl']; } else {$date_bl=''; }
		if (isset($_GET['fa_cond_transport'])) { $fa_cond_transport=$_GET['fa_cond_transport']; } else {$fa_cond_transport=''; }
		if (isset($_GET['fa_cond_reglement'])) { $fa_cond_reglement=$_GET['fa_cond_reglement']; } else {$fa_cond_reglement=''; }
		if (isset($_GET['ref_client'])) { $ref_client=$_GET['ref_client']; } else {$ref_client=''; }
		if (isset($_GET['note_private'])) { $note_private=$_GET['note_private']; } else {$note_private=''; }
		if (isset($_GET['note_public'])) { $note_public=$_GET['note_public']; } else {$note_public=''; }
		if (isset($_GET['date_ech'])) { $date_ech=$_GET['date_ech']; } else {$date_ech=''; }
			$valForm="GET" ;
}

//include 'menu/header.php';

$last_num_entre = 0 ;
$sql = 'SELECT max(rowid) FROM gestion_fa_haut';
$req = mysqli_query($link, $sql); 
$row = mysqli_fetch_row($req);
$last_num_entre = $row[0];
$last_num_entre = $last_num_entre + 1 ;

echo "<center>";
echo "Form : ".$valForm." | Num ordre : ".$num_ordre."<br>" ;
echo "facnumber : ".$facnumber." | num_fa_ligne : ".$num_fa_ligne." | num_client_fa : ".$num_client_fa."<br>" ;
echo "date_fa : ".$date_fa." fa_cond_transport : ".$fa_cond_transport."<br>" ;
echo "fa_cond_reglement : ".$fa_cond_reglement." date_ech : ".$date_ech."<br>" ;
echo "ref_client : ".$ref_client." note_private : ".$note_private."<br>" ;
echo "note_public : ".$note_public." date_bl : ".$date_bl."<br>" ;
echo "LastNum :".$last_num_entre."<br>" ;

// calcul date echeance










//$date_d = date_create($date_fa);
$now = new DateTime($date_fa);
$now->modify('+30 days');
$now->modify('last day of this month');
$now->modify('+15 days');
$now->format('Ymd');
$date_d=$now ;

//date_add($date_d, date_interval_create_from_date_string('30 days'));
echo "<br> date facture : $date_fa| date echeance: ".date_format($date_d, 'd-m-Y');
echo "<br>";


$note_private = htmlspecialchars($note_private, ENT_QUOTES);
$note_public = htmlspecialchars($note_public, ENT_QUOTES);

$sql = "UPDATE gestion_fa_haut SET 
`IdNumClient` = '$IdNumClient', 
`date_fa` = '$date_fa', 
`date_bl` = '$date_bl', 
`facnumber` = '$facnumber', 
`num_client_fa` = '$num_client_fa', 
`fa_cond_transport` = '$fa_cond_transport', 
`fa_cond_reglement` = '$fa_cond_reglement',
`date_ech` = '$date_ech', 
`ref_client` = '$ref_client', 
`note_private` = '$note_private', 
`note_public` = '$note_public', 
`Timestamp` = '$timestamp' 
 WHERE `rowid` = '$num_fa_ligne'";


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

echo "<br>Requette : ".$res ;

//Header("Location: facturation.php?limite=0")

?>
