<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Rentabilise</title>
</head>

<body>
<?php
if(isset($_REQUEST['s_anneeDebut']))$s_anneeDebut=$_REQUEST['s_anneeDebut']; else $s_anneeDebut=date('Y');
if(isset($_REQUEST['s_moisDebut']))$s_moisDebut=$_REQUEST['s_moisDebut']; else $s_moisDebut=date('m');
if(isset($_REQUEST['s_jourDebut']))$s_jourDebut=$_REQUEST['s_jourDebut']; else $s_jourDebut=date('d');
if(isset($_REQUEST['s_anneeFin']))$s_anneeFin=$_REQUEST['s_anneeFin']; else $s_anneeFin=date('Y');
if(isset($_REQUEST['s_moisFin']))$s_moisFin=$_REQUEST['s_moisFin']; else $s_moisFin=date('m');
if(isset($_REQUEST['s_jourFin']))$s_jourFin=$_REQUEST['s_jourFin']; else $s_jourFin=date('d');
if(isset($_POST['v_action']))$v_action=($_POST['v_action']);else $v_action='';
if(isset($_REQUEST['s_annee']))$s_annee=$_REQUEST['s_annee']; else $s_annee=date('Y');
if(isset($_POST['s_type']))$s_type=($_POST['s_type']);else $s_type='';

require_once("../../config/constant.inc.php");
include ("include/functions.php");
include ("select-date.php") ;

if ($v_action='showRent'){

		echo '<table bgcolor="#FFFFFF">';
		echo '<tr>';
		echo '<td bgcolor="#669999"><b>NoCommande</b></td>';
		echo '<td bgcolor="#669999"><b>NoArticle</b></td>';
		echo '<td bgcolor="#669999"><b>Prix Multi</b></td>';
		echo '<td bgcolor="#669999"><b>Quantite</b></td>';
		echo '</tr>'."\n";

		if(isset($_REQUEST['s_searchStartDate']))$s_searchStartDate=$_REQUEST['s_searchStartDate']; else $s_searchStartDate=$s_anneeDebut.'-'.$s_moisDebut.'-'.$s_jourDebut;
		if(isset($_REQUEST['s_searchEndDate']))$s_searchEndDate=$_REQUEST['s_searchEndDate']; else $s_searchEndDate=$s_anneeFin.'-'.$s_moisFin.'-'.$s_jourFin;
		
		connect(); // Need to be defined by fred if : DateCommande OR DateSaisie
		//$request1="SELECT DISTINCT NoCommande FROM commande".ID_GARAGE." WHERE DateCommande BETWEEN '$s_searchStartDate' AND '$s_searchEndDate' ORDER BY 'DateCommande ASC'";
		$request1="SELECT DISTINCT commande".ID_GARAGE.".NoCommande,commandearticles".ID_GARAGE.".NoArticle,articles.Description FROM commande".ID_GARAGE.",commandearticles".ID_GARAGE.",articles WHERE ";
		$request1.="(commande".ID_GARAGE.".DateCommande BETWEEN '$s_searchStartDate' AND '$s_searchEndDate') ";
		$request1.="AND commandearticles".ID_GARAGE.".NoArticle=articles.NoArticle ";
		$request1.="AND commandearticles".ID_GARAGE.".GM='10' GROUP BY commande".ID_GARAGE.".NoCommande ORDER BY articles.Description DESC ";
		
		$result1 = mysql_query($request1) or die('Erreur SQL !<br>'.$request1.'<BR>'.Connection::getConnection()->errorInfo()); error_log("$request1");
		$nblignes1=mysql_num_rows($result1);
		$background=0;
	
		for ($i=0; $i < $nblignes1; $i++){
			$ligne = mysql_fetch_assoc($result1);
			$NoCom=$ligne['NoCommande'];
			if ($NoCom != ''){
				
				connect();
				$sqlreq = "SELECT NoCommande,NoArticle,PrixMulti,Quantite FROM commandearticles".ID_GARAGE." WHERE NoCommande='$NoCom' AND GM='10' ORDER BY NoArticle ASC";
				$result = mysql_query($sqlreq) or die('Erreur SQL !<br>'.$sqlreq.'<BR>'.Connection::getConnection()->errorInfo()); error_log("$sqlreq");
				$nblignesL=mysql_num_rows($result);
				//error_log($sqlreq);
				$TotalPrixMulti=0;
				$TotalQuant=0;
				for ($j=0; $j < $nblignesL; $j++){
					$lignes = mysql_fetch_assoc($result);
					
					$NoArticle = $lignes['NoArticle'];
					$NoArt = get_NoArt($NoArticle);
					$nocmd = $lignes['NoCommande'];
					$PrixMulti = Sum_TotMulti($nocmd,$NoArticle);
					$Quant = Sum_Quant($nocmd,$NoArticle);
					$NoArt = get_NoArt($NoArticle);
					
					$background++;
					if ($background%2) $l_hexa = "#E4E8E9";
					else $l_hexa = "#CCCCCC";
					echo '<tr bgcolor='.$l_hexa.'>';
					
					echo '<td><a href="http://admin:rcf@192.168.1.2/webbike/default.php?NoCommande='.$nocmd.'&Type=4&Sous_Type=1&Etape=3&NoVisu=0" target=_new>'.$nocmd.'</a></td>';
					echo '<td>'.$NoArticle.'</td>';
					echo '<td>'.$PrixMulti.'</td>';
					echo '<td>'.$Quant.'</td>';
					echo '</tr>';
					
				}
					
			}	
			
		}
		//print "<td>Total Prix Multi ".$NoArticle." = ".$ArticleS1."</td>";
		//print "<td>Total Quantité = ".$TotalQuant."</td>";
	print '</tables>';
}
?>

</body>
</html>
