<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Suivis locations bases SMM.</title>
<link href="../baseCSS.css" rel="stylesheet" type="text/css">
<body>

<?php 

//Fichiers contenant les fonctions utilis&eacute;es dans le script.
require("../outils/gui.php");
require("../outils/session.php");
require("../outils/mise_en_page.php");



//V&eacute;rifier si la session est valide.
$Bsession_id = $_GET["Bsession_id"];
verifierSession($Bsession_id);

$etape = $_GET["etape"];
$prevision_avril = $_GET["prevision_avril"];
$prevision_mai = $_GET["prevision_mai"];
$prevision_juin = $_GET["prevision_juin"];
$prevision_juillet = $_GET["prevision_juillet"];
$prevision_aout = $_GET["prevision_aout"];
$prevision_septembre = $_GET["prevision_septembre"];
$prevision_octobre = $_GET["prevision_octobre"];
$prevision_novembre = $_GET["prevision_novembre"];
$prevision_decembre = $_GET["prevision_decembre"];
$prevision_janvier = $_GET["prevision_janvier"];
$prevision_fevrier = $_GET["prevision_fevrier"];
$prevision_mars = $_GET["prevision_mars"];
$prevision_hebergement = $_GET["prevision_hebergement"];
$hebergement_reel = $_GET["hebergement_reel"];
$prevision_nourriture = $_GET["prevision_nourriture"];
$nourriture_reel = $_GET["nourriture_reel"];
$Valider = $_GET["Valider"];
$selection_annee = $_GET["selection_annee"];
$selection_base = $_GET["selection_base"];


//V&eacute;rifier les droits de l'utilisateur.
$privilege_base = lirePrivilege($Bsession_id);
if (($privilege_base != 2) and ($privilege_base != 1))
	die("Vous n'avez pas les droits!");

	
	
	
	
if($etape == 1)//SI IL Y A MODIFICATION DES DONNEES
{	
	$sql = "UPDATE base_ref1annuelles
	  	       SET base_ref1annuelles.actif = 'N',
			       base_ref1annuelles.mis_a_jour = now();";
	$result = mysql_query($sql)
	or die("ne peut faire la modification de la r&eacute;f&eacute;rence annuelle".$sql);


	$sql = "UPDATE base_ref1annuelles
	  	       SET base_ref1annuelles.actif = 'O',
			       base_ref1annuelles.mis_a_jour = now()
       	     WHERE base_ref1annuelles.annee_debut = '$selection_annee';";
	$result = mysql_query($sql)
	or die("ne peut faire la modification de la r&eacute;f&eacute;rence annuelle".$sql);
}

if($etape == 2)//SI IL Y A MODIFICATION DES DONNEES
{		
	$sql = "UPDATE base_ref1annuelles
	  	       SET base_ref1annuelles.avril = '$prevision_avril',
				   base_ref1annuelles.mai = '$prevision_mai',
				   base_ref1annuelles.juin = '$prevision_juin',
				   base_ref1annuelles.juillet = '$prevision_juillet',
				   base_ref1annuelles.aout = '$prevision_aout',
				   base_ref1annuelles.septembre = '$prevision_septembre',
				   base_ref1annuelles.octobre = '$prevision_octobre',
				   base_ref1annuelles.novembre = '$prevision_novembre',
				   base_ref1annuelles.decembre = '$prevision_decembre',
				   base_ref1annuelles.janvier = '$prevision_janvier',
				   base_ref1annuelles.fevrier = '$prevision_fevrier',
				   base_ref1annuelles.mars = '$prevision_mars',
				   base_ref1annuelles.hebergement_prevision = '$prevision_hebergement',
				   base_ref1annuelles.hebergement_reel = '$hebergement_reel',
				   base_ref1annuelles.nourriture_prevision = '$prevision_nourriture',
				   base_ref1annuelles.nourriture_reel = '$nourriture_reel',
				   
			       base_ref1annuelles.mis_a_jour = now()
       	     WHERE base_ref1annuelles.actif = 'O';";
	$result = mysql_query($sql)
	or die("ne peut faire la modification de la r&eacute;f&eacute;rence annuelle".$sql);

}	







	
	//TABLE REF1ANNUELLES***************************************************************************************
		$sql_annuelle = "SELECT annee_debut, annee_fin, actif, avril, mai, juin, juillet, aout, septembre, octobre, novembre,
						 decembre, janvier, fevrier, mars, hebergement_prevision, hebergement_reel, nourriture_prevision, nourriture_reel
		 	   		     FROM base_ref1annuelles
						 ORDER BY annee_debut;";
		$result_annuelle = mysql_query($sql_annuelle) or die ("Ne peut lire dans la table base_ref1annuelles<br><br>".$sql_annuelle);
		$result_annuelle2 = mysql_query($sql_annuelle) or die ("Ne peut lire dans la table base_ref1annuelles<br><br>".$sql_annuelle);
		$num_annuelle = mysql_numrows($result_annuelle);		
		
		//cherche l'enregistrement actif
		while ($row_annuelle = mysql_fetch_row ($result_annuelle2))
		{
			if ($row_annuelle[2] == 'O')
			{
				$annee_active_debut = $row_annuelle[0];
				$annee_active_fin = $row_annuelle[1];
				$prevision[0] = $row_annuelle[3];//avril
				$prevision[1] = $row_annuelle[4];//mai
				$prevision[2] = $row_annuelle[5];//juin
				$prevision[3] = $row_annuelle[6];//juillet
				$prevision[4] = $row_annuelle[7];//aout
				$prevision[5] = $row_annuelle[8];//septembre
				$prevision[6] = $row_annuelle[9];//octobre
				$prevision[7] = $row_annuelle[10];//novembre
				$prevision[8] = $row_annuelle[11];//decembre
				$prevision[9] = $row_annuelle[12];//janvier
				$prevision[10] = $row_annuelle[13];//fevrier
				$prevision[11] = $row_annuelle[14];//mars
				$prevision[12] = $row_annuelle[15];//hebergement
				$prevision[13] = $row_annuelle[17];//nourriture
				$montant[12] =  $row_annuelle[16];//hebergement_reel
				$montant[13] =  $row_annuelle[18];//nourriture_reel		
			}
		}
		$date = date('Y-m-d H:i:s');
		print("<h2><div align=right>".$date."</div>");
		print("<center><h1>SUIVIS LOCATIONS BASES SMM</h1><br>");
		print("<form action=\"prevision.php?Bsession_id=".$Bsession_id."\" method=get name=prevision>");
		print("<input type=hidden name=Bsession_id value=".$Bsession_id.">");
		print("<input type=hidden name=etape value=1>");
		print("<table cellspacing=0 cellpadding=0 border=0>");
		print("<tr><td valign=top  class=noprint>");
		print("<h2>Ann&eacute;e en cour : <select name=\"selection_annee\">");
		print("<option selected value=".$annee_active_debut.">".$annee_active_debut."/".$annee_active_fin."</option>");
		
		
		while ($row_annuelle = mysql_fetch_row ($result_annuelle))
		{	
			$annee_debut = $row_annuelle[0];
			$annee_fin = $row_annuelle[1];
			$actif = $row_annuelle[2];
			print("<option value=".$annee_debut.">".$annee_debut."/".$annee_fin."</option>");
		}
		print("</select>");
		
		print("<h2>base : <select name=\"selection_base\">");
		print("<option selected value=".$selection_base."></option>");
		print("<option value=V>V</option>");
		print("<option value=R>R</option>");
		print("<option value=VR>VR</option>");
		print("</select>");
		
		print("<input type=submit name=Valider value=Valider></form></td></tr></table><BR><BR>");
	
	
		


//////////////////////////////////////////////////////////////////////////////////////////////////////
//  - COLLECTE DES DONN&Eacute;ES																			//
//////////////////////////////////////////////////////////////////////////////////////////////////////
	
$x = 0;
$mois[0] = 4; $montant[0] = 0;
$mois[1] = 5; $montant[1] = 0;
$mois[2] = 6; $montant[2] = 0;
$mois[3] = 7; $montant[3] = 0;
$mois[4] = 8; $montant[4] = 0;
$mois[5] = 9; $montant[5] = 0;
$mois[6] = 10; $montant[6] = 0;
$mois[7] = 11; $montant[7] = 0;
$mois[8] = 12; $montant[8] = 0;
$mois[9] = 1; $montant[9] = 0;
$mois[10] = 2; $montant[10] = 0;
$mois[11] = 3; $montant[11] = 0;

while ( $x < 12)//LOOP POUR CHAQUE MOIS
{
	
	if ($x < 9)
		$annee_recherche = $annee_active_debut;
	if ($x > 8)
		$annee_recherche = $annee_active_fin;
		
	//TABLE CONTRAT***************************************************************************************	
	$sql_contrat = "SELECT code_contrat, numero_contrat, num_client, date_emission, date_debut, date_fin, cal_debut, cal_fin, nuite, etat, depot, depot_lock, mois_du_contrat 
	        FROM base_contrat
			WHERE etat <> 'annulé'
			AND etat <> 'soumission'
			AND mois_du_contrat = '$mois[$x]'
			AND YEAR(date_debut) = $annee_recherche
			ORDER BY YEAR(date_debut), mois_du_contrat;";	

	$result_contrat = mysql_query($sql_contrat)
	or die ("Ne peut lire dans la table des contrats".$sql_contrat);
	$num_contrat = mysql_numrows($result_contrat);
	
	while ($row_contrat = mysql_fetch_row ($result_contrat))//LOOP POUR CHAQUE CONTRAT
	{
		$compteur_contrat++;
		$p4010=0;
		$p4015=0;
		$p4020=0;
		$p4025=0;
		$p4030=0;
		$p4035=0;
		$p4040=0;
		$p4045=0;
		$p4050=0;
		$p4055=0;
		$p4060=0;
		$p4061=0;
		$tot_chalet_prix_plein = 0;	
		$tot_chalet_prix_rabais = 0;
		$tot_activite_prix_plein = 0;
		$tot_activite_prix_rabais = 0;
		$tot_loc_prix_plein =0;
		$tot_loc_prix_rabais = 0;
		$tot_achat_prix_plein = 0;
		$tot_achat_prix_rabais = 0;
		$tot_rabais_prix = 0;
		$tot_depot_montant = 0;
		$tot_r = 0;
		$tot_v = 0;
		$tot_else = 0;
		
		
		//DONNEE DES CONTRATS
		if ($num_contrat)
		{
			$i = 0;
			$code_contrat = ($row_contrat[$i++]);
			$numero_contrat = ($row_contrat[$i++]);
			$num_client = ($row_contrat[$i++]);
			$date_emission = ($row_contrat[$i++]);
			$date_debut = ($row_contrat[$i++]);
			$date_fin = ($row_contrat[$i++]);
			$cal_debut = ($row_contrat[$i++]);
			$cal_fin = ($row_contrat[$i++]);
			$nuitees = ($row_contrat[$i++]);
			$etat = ($row_contrat[$i++]);
			$depot = ($row_contrat[$i++]);
			$depot_lock = ($row_contrat[$i++]);
			$mois_du_contrat = ($row_contrat[$i++]);
		}
	
		//TABLE CHALET***************************************************************************************
		$sql_chalet = "SELECT base_ref1chalets.nom, base_chalets.num_chalet, base_chalets.prix_par_jour, base_chalets.prix_plein, base_chalets.prix_rabais, base_chalets.actif, base_chalets.date_modif, base_ref1chalets.base
		   		  FROM base_ref1chalets, base_chalets
				 WHERE base_chalets.code_contrat = '$code_contrat'
		 			  AND base_chalets.actif = 'O'
					  AND base_ref1chalets.num_chalet = base_chalets.num_chalet;";
		$result_chalet = mysql_query($sql_chalet) or die ("Ne peut lire dans la table base_ref1chalets<br><br>".$sql_chalet);
		$num_chalet = mysql_numrows($result_chalet);
		
		$base = 'E';
		
		while ($row_chalet = mysql_fetch_row ($result_chalet))
		{	
			//MISE A ZERO DES VARIABLES
			$chalet_prix_par_jour = 0;
			$chalet_prix_plein = 0;
			$chalet_prix_rabais = 0;
			
				
			if ($num_chalet)
			{
				$j = 0;
				$chalet_nom = ($row_chalet[$j++]);
				$chalet_num_chalet = ($row_chalet[$j++]);
				$chalet_prix_par_jour = ($row_chalet[$j++]);
				$chalet_prix_plein = ($row_chalet[$j++]);
				$tot_chalet_prix_plein = ($tot_chalet_prix_plein + $chalet_prix_plein);
				$chalet_prix_rabais = ($row_chalet[$j++]);
				$tot_chalet_prix_rabais = ($tot_chalet_prix_rabais + $chalet_prix_rabais);
				$chalet_actif = ($row_chalet[$j++]);
				$chalet_date_modif = ($row_chalet[$j++]);
				$base = ($row_chalet[$j++]);
				//calcul pour les deux bases
				if($base == 'R')
					$tot_r++;
				if($base == 'V')
					$tot_v++;
				if($base == 'E')
					$tot_v++;
			}
			else
			{
				die ("Il y a un probl&egrave;me dans la base de donn&eacute;es chalet !".$sql_chalet);
			}	
		}
		if($tot_r > $tot_v)
			$base = 'R';
		else
			$base = 'V';
		
		
		
		//TABLE CAFETERIA***************************************************************************************
		$sql_cafe = "SELECT nb_pers, nb_repas, prix_par_repas, lunchpm, prix_lunchpm, prix_plein, prix_rabais, date_modif
		   	    FROM base_cafeteria
	    	   WHERE code_contrat ='$code_contrat'
			   AND actif ='O';";
		$result_cafe = mysql_query($sql_cafe) or die ("Ne peut lire dans la table cafeteria".$sql_cafe);
		$num_cafe = mysql_numrows($result_cafe);		
	
		//MISE A ZERO DES VARIABLES
		$cafe_nb_pers = 0;
		$cafe_nb_repas = 0;
		$cafe_prix_par_repas = 0;
		$cafe_lunchpm = 0;
		$cafe_prix_lunchpm = 0;
		$cafe_prix_plein = 0;
		$cafe_prix_rabais = 0;
			
		if ($num_cafe)
		{
			$k = 0;
			$row_cafe = mysql_fetch_row ($result_cafe);
			$cafe_nb_pers = ($row_cafe[$k++]);
			$cafe_nb_repas = ($row_cafe[$k++]);
			$cafe_prix_par_repas = ($row_cafe[$k++]);
			$cafe_lunchpm = ($row_cafe[$k++]);
			$cafe_prix_lunchpm = ($row_cafe[$k++]);
			$cafe_prix_plein = ($row_cafe[$k++]);
			$cafe_prix_rabais = ($row_cafe[$k++]);
			$cafe_date_modif = ($row_cafe[$k++]);
			//calcul pour les deux bases
				if($base == 'R')
					$tot_r += ($cafe_prix_rabais);
				if($base == 'V')
					$tot_v += ($cafe_prix_rabais);
				if($base == 'E')
					$tot_else += ($cafe_prix_rabais);
		}
	
	


	
		//TABLE ACTIVIT&Eacute;***************************************************************************************
		$sql_activite = "SELECT base_ref1activites.nom, base_activites.prix_plein, base_activites.prix_rabais,
		                base_activites.num_activite, base_activites.inclu, base_activites.date_modif, base_ref1activites.compte_budget
		   		  FROM base_ref1activites, base_activites
				 WHERE base_activites.code_contrat = '$code_contrat'	   
	               AND base_ref1activites.num_activite = base_activites.num_activite
				   AND base_activites.actif = 'O';";
		$result_activite = mysql_query($sql_activite) or die ("Ne peut lire dans la table base_activites<br><br>".$sql_activite);
		$num_activite = mysql_numrows($result_activite);	
	
		while ($row_activite = mysql_fetch_row ($result_activite))
		{
			//MISE A ZERO DES VARIABLES
			$activite_prix_plein = 0;
			$activite_prix_rabais = 0;
					
			if ($num_activite)
			{
				$l = 0;
				$activite_nom = ($row_activite[$l++]);
				$activite_prix_plein = ($row_activite[$l++]);
				$tot_activite_prix_plein = ($tot_activite_prix_plein + $activite_prix_plein); 
				$activite_prix_rabais = ($row_activite[$l++]);
				$tot_activite_prix_rabais = ($tot_activite_prix_rabais + $activite_prix_rabais);			
				$activite_num_activite = ($row_activite[$l++]);
				$activite_inclu = ($row_activite[$l++]);
				$activite_date_modif = ($row_activite[$l++]);
				$activite_compte_budget = ($row_activite[$l++]);
				//calcul pour les deux bases
				if($base == 'R')
					$tot_r = ($tot_r + $activite_prix_rabais);
				if($base == 'V')
					$tot_v = ($tot_v + $activite_prix_rabais);
				if($base == 'E')
					$tot_else = ($tot_else + $activite_prix_rabais);
			}
			else
			{
				die ("Il y a un probl&egrave;me dans la base de donn&eacute;es activit&eacute; !".$sql_activite);
			}	
		}
	
	
	
	
	
	
		//TABLE LOCATION***************************************************************************************
		$sql_loc = "SELECT base_ref1materiels.nom, base_loc_materiels.num_materiel, base_loc_materiels.quantite, base_loc_materiels.prix_plein, base_loc_materiels.prix_rabais,
		               base_loc_materiels.inclu,base_loc_materiels.date_modif, base_ref1materiels.compte_budget
		   		  FROM base_ref1materiels, base_loc_materiels
				 WHERE base_loc_materiels.code_contrat = '$code_contrat'
				   AND base_loc_materiels.actif = 'O'	   
	               AND base_ref1materiels.num_materiel = base_loc_materiels.num_materiel;";
		$result_loc = mysql_query($sql_loc) or die ("Ne peut lire dans la table base_loc_materiels<br><br>".$sql_loc);
		$num_loc = mysql_numrows($result_loc);		
	
		while ($row_loc = mysql_fetch_row ($result_loc))
		{	
			//MISE A ZERO DES VARIABLES
			$loc_quantite = 0;
			$loc_prix_plein = 0;
			$loc_prix_rabais = 0;
					
			if ($num_loc)
			{
				$m = 0;
				$loc_nom = ($row_loc[$m++]);
				$loc_num_materiel = ($row_loc[$m++]);
				$loc_quantite = ($row_loc[$m++]);
				$loc_prix_plein = ($row_loc[$m++]);
				$tot_loc_prix_plein = ($tot_loc_prix_plein + $loc_prix_plein);
				$loc_prix_rabais = ($row_loc[$m++]);
				$tot_loc_prix_rabais = ($tot_loc_prix_rabais + $loc_prix_rabais);			
				$loc_inclu = ($row_loc[$m++]);
				$loc_date_modif = ($row_loc[$m++]);
				$loc_compte_budget = ($row_loc[$m++]);
				//calcul pour les deux bases
				if($base == 'R')
					$tot_r = ($tot_r + $loc_prix_rabais);
				if($base == 'V')
					$tot_v = ($tot_v + $loc_prix_rabais);
				if($base == 'E')
					$tot_else = ($tot_else + $loc_prix_rabais);
			}
			else
			{
				die ("Il y a un probl&egrave;me dans la base de donn&eacute;es location !".$sql_loc);
			}	
		}	
	
	
	
	
	
		//TABLE ACHAT***************************************************************************************	
		$sql_achat = "SELECT base_ref1materiels.nom, base_vente_materiels.num_materiel, base_vente_materiels.quantite, base_vente_materiels.prix_plein, base_vente_materiels.prix_rabais,
		               base_vente_materiels.inclu, base_vente_materiels.date_modif, base_ref1materiels.compte_budget
	   			  FROM base_ref1materiels, base_vente_materiels
				 WHERE base_vente_materiels.code_contrat = '$code_contrat'	
				   AND base_vente_materiels.actif = 'O'   
    	           AND base_ref1materiels.num_materiel = base_vente_materiels.num_materiel;";
		$result_achat = mysql_query($sql_achat) or die ("Ne peut lire dans la table base_loc_materiels<br><br>".$sql_achat);
		$num_achat = mysql_numrows($result_achat);		
	
		while ($row_achat = mysql_fetch_row ($result_achat))
		{	
			//MISE A ZERO DES VARIABLES
			$achat_quantite = 0;
			$achat_prix_plein = 0;
			$achat_prix_rabais = 0;
						
			if ($num_achat)
			{
				$n = 0;
				$achat_nom = ($row_achat[$n++]);
				$achat_num_materiel = ($row_achat[$n++]);
				$achat_quantite = ($row_achat[$n++]);
				$achat_prix_plein = ($row_achat[$n++]);
				$tot_achat_prix_plein = ($tot_achat_prix_plein + $achat_prix_plein);
				$achat_prix_rabais = ($row_achat[$n++]);
				$tot_achat_prix_rabais = ($tot_achat_prix_rabais + $achat_prix_rabais);			
				$achat_inclu = ($row_achat[$n++]);
				$achat_date_motif = ($row_achat[$n++]);		
				$achat_compte_budget = ($row_achat[$n++]);
				//calcul pour les deux bases
				if($base == 'R')
					$tot_r = ($tot_r + $achat_prix_rabais);
				if($base == 'V')
					$tot_v = ($tot_v + $achat_prix_rabais);
				if($base == 'E')
					$tot_else = ($tot_else + $achat_prix_rabais);
			}
			else
			{
				die ("Il y a un probl&egrave;me dans la base de donn&eacute;es achat !".$sql_achat);
			}	
		}	
	
	

	
		//TABLE RABAIS***************************************************************************************
		$sql_rabais = "SELECT code_rabais, code_contrat, prix_rabais, poste_budget, actif
		 	   		     FROM base_rabais
				        WHERE base_rabais.code_contrat = '$code_contrat'	
				          AND base_rabais.actif = 'O';";
		$result_rabais = mysql_query($sql_rabais) or die ("Ne peut lire dans la table base_rabais<br><br>".$sql_rabais);
		$num_rabais = mysql_numrows($result_rabais);		
		
		while ($row_rabais = mysql_fetch_row ($result_rabais))
		{	
			//MISE A ZERO DES VARIABLES
			$rabais_prix = 0;
			$rabais_compte_budget = 0;
		
			if ($num_rabais)
			{
				$n = 0;
				$rabais_code = ($row_rabais[$n++]);
				$rabais_code_contrat = ($row_rabais[$n++]);
				$rabais_prix = ($row_rabais[$n++]);
				$tot_rabais_prix = ($tot_rabais_prix + $rabais_prix);
				$rabais_compte_budget = ($row_rabais[$n++]);
				$rabais_actif = ($row_rabais[$n++]);
				//calcul pour les deux bases
				if($base == 'R')
					$tot_r = ($tot_r + $rabais_prix);
				if($base == 'V')
					$tot_v = ($tot_r + $rabais_prix);
				if($base == 'E')
					$tot_else = ($tot_else + $rabais_prix);
			}	
			else
			{
				die ("Il y a un probl&egrave;me dans la base de donn&eacute;es rabais !".$sql_rabais);
			}	
		}
		
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
	// 5 - CALCUL DES TOTAUX																			//
	//////////////////////////////////////////////////////////////////////////////////////////////////////	
	
		//MONTANT REEL DUN CONTRAT
		$montant_reel = ($tot_chalet_prix_plein+$cafe_prix_plein+$tot_activite_prix_plein+$tot_achat_prix_plein+$tot_loc_prix_plein-$tot_rabais_prix);
		$grand_tot_montant_reel+=$montant_reel;
		
		//MONTANT AVEC RABAIS DUN CONTRAT
		$montant_du_contrat = ($tot_chalet_prix_rabais+$cafe_prix_rabais+$tot_activite_prix_rabais+$tot_achat_prix_rabais+$tot_loc_prix_rabais-$tot_rabais_prix);
		$grand_tot_montant_du_contrat+=$montant_du_contrat;
		
		if($base=='R')
			$grand_tot_r += $montant_du_contrat;
		if($base=='V')
			$grand_tot_v += $montant_du_contrat;
		if($base=='E')
			$grand_tot_v += $montant_du_contrat;		
		
		
		//$grand_tot_r += $tot_r;
		//$grand_tot_v += $tot_v;
		//$grand_tot_else += $tot_else;

	}//FIN LOOP POUR CHAQUE CONTRAT
	
	$montant[$x] = $grand_tot_montant_du_contrat;
	$total_montant += $grand_tot_montant_du_contrat;
	
	$y = $x-1;
	$cumul[$x] = $cumul[$y] + $grand_tot_montant_du_contrat;
	$cumul_montant[$x] = $cumul_montant[$y] + $prevision[$x]; 
	
	$pourcentage[$x] = (($montant[$x] / $prevision[$x])*100);
	$cumul_pourcentage[$x] = (($cumul[$x] / $cumul_montant[$x])*100);
	
	
	//print(" TOTAL DU MOIS = ".$montant[$x]."<br><br>");
	
	$grand_tot_montant_du_contrat = 0;
	$grand_tot_montant_reel = 0;
	$x++;
	
	
	
	
	
}//FIN LOOP POUR CHAQUE MOIS	
	
	
	
	
	

	
	
	
	
	
	
	
$date_actuelle = date("d-m-Y");	
?>
	
	<form action="\base\rapport\prevision.php?Bsession_id=".$Bsession_id."\" method=get name=prevision>
	<?php  print("<input type=hidden name=Bsession_id value=".$Bsession_id.">"); ?>
	<input type=hidden name=etape value=2>
	
	
	<table cellspacing=1 cellpadding=0 border=1>
	<tr>
		<td valign=top width=100px bgcolor=#D6D6D6><h2><center><B>Description<br>Mois</B></td>
		<td valign=top width=70px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>11-12</B></td>
		<td valign=top width=70px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>12-13</B></td>
    <td valign=top width=70px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>13-14</B></td>
    <td valign=top width=70px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>14-15</B></td>
		<td valign=top width=70px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>15-16</B></td>
    <td valign=top width=70px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>16-17</B></td>
		<td valign=top width=100px bgcolor=#D6D6D6><h2><center><B>Ann&eacute;e<br>pr&eacute;visions</B></td>
		<td valign=top width=100px bgcolor=#D6D6D6><h2><center><B>R&eacute;el en date;<br><?php  print($date_actuelle); ?></B></td>
		<td valign=top width=80px bgcolor=#D6D6D6><h2><center><B>% du r&eacute;el vs<br>pr&eacute;visions</B></td>
		<td valign=top width=80px bgcolor=#D6D6D6><h2><center><B>Cumulatif</B></td>
	</tr>
	<tr>
		<td valign=top><h2><B>Avril</B></td>
		<td valign=top align=right><h2>3234.00</td>
		<td valign=top align=right><h2>2245.24</td>
    <td valign=top align=right><h2>650.00</td>
    <td valign=top align=right><h2>1856.00</td>
		<td valign=top align=right><h2>1157.31</td>      
    <td valign=top align=right><h2>2402.28</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_avril\" value=\"".$prevision[0]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[0]);
		   print("</td>"); 
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[0]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[0]);
		   print("%</td>"); ?>
		   
	</tr>
	<tr>
		<td valign=top><h2><B>Mai</B></td>
		<td valign=top align=right><h2>5235.30</td>
		<td valign=top align=right><h2>13971.87</td>
    <td valign=top align=right><h2>16592.00</td>
    <td valign=top align=right><h2>8720.00</td>
    <td valign=top align=right><h2>5908.09</td>      
    <td valign=top align=right><h2>13072.65</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_mai\" value=\"".$prevision[1]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[1]);
		   print("</td>");
		
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[1]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[1]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Juin</B></td>
		<td valign=top align=right><h2>39359.53</td>
		<td valign=top align=right><h2>60826.28</td>
    <td valign=top align=right><h2>81902.13</td>
    <td valign=top align=right><h2>83568.00</td>
		<td valign=top align=right><h2>58837.78</td>      
    <td valign=top align=right><h2>54988.84</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_juin\" value=\"".$prevision[2]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[2]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[2]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[2]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Juillet</B></td>
		<td valign=top align=right><h2>112514.56</td>
		<td valign=top align=right><h2>114023.57</td>
    <td valign=top align=right><h2>122896.17</td>
    <td valign=top align=right><h2>73565.00</td>
		<td valign=top align=right><h2>85592.39</td>      
    <td valign=top align=right><h2>96791.15</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_juillet\" value=\"".$prevision[3]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[3]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[3]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[3]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Ao&ucirc;t</B></td>
		<td valign=top align=right><h2>60203.79</td>
		<td valign=top align=right><h2>48789.41</td>
    <td valign=top align=right><h2>62164.75</td>
    <td valign=top align=right><h2>49067.00</td>
		<td valign=top align=right><h2>56167.08</td>      
    <td valign=top align=right><h2>51346.71</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_aout\" value=\"".$prevision[4]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[4]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[4]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[4]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Septembre</B></td>
		<td valign=top align=right><h2>14708.89</td>
		<td valign=top align=right><h2>12290.69</td>
    <td valign=top align=right><h2>8824.36</td>
    <td valign=top align=right><h2>5231.00</td>
		<td valign=top align=right><h2>14830.97</td>      
    <td valign=top align=right><h2>18022.16</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_septembre\" value=\"".$prevision[5]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[5]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[5]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[5]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Octobre</B></td>
		<td valign=top align=right><h2>13863.99</td>
		<td valign=top align=right><h2>19472.24</td>
    <td valign=top align=right><h2>22367.05</td>
    <td valign=top align=right><h2>24745.00</td>
		<td valign=top align=right><h2>16026.33</td>      
    <td valign=top align=right><h2>12166.00</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_octobre\" value=\"".$prevision[6]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[6]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[6]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[6]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Novembre</B></td>
		<td valign=top align=right><h2>17658.51</td>
		<td valign=top align=right><h2>17082.57</td>
    <td valign=top align=right><h2>12259.00</td>
    <td valign=top align=right><h2>16712.00</td>
		<td valign=top align=right><h2>9676.71</td>      
    <td valign=top align=right><h2>11767.80</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_novembre\" value=\"".$prevision[7]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[7]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[7]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[7]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>D&eacute;cembre</B></td>
		<td valign=top align=right><h2>19197.40</td>
		<td valign=top align=right><h2>23098.88</td>
    <td valign=top align=right><h2>21701.83</td>
    <td valign=top align=right><h2>13205.00</td>
		<td valign=top align=right><h2>16776.27</td>      
    <td valign=top align=right><h2>11454.81</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_decembre\" value=\"".$prevision[8]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[8]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[8]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[8]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Janvier</B></td>
		<td valign=top align=right><h2>27471.34</td>
		<td valign=top align=right><h2>35949.24</td>
    <td valign=top align=right><h2>35208.04</td>
    <td valign=top align=right><h2>31782.00</td>
		<td valign=top align=right><h2>25443.72</td>      
    <td valign=top align=right><h2>25742.40</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_janvier\" value=\"".$prevision[9]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[9]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[9]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[9]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>F&eacute;vrier</B></td>
		<td valign=top align=right><h2>65645.70</td>
		<td valign=top align=right><h2>67189.59</td>
    <td valign=top align=right><h2>69735.79</td>
    <td valign=top align=right><h2>64882.00</td>
		<td valign=top align=right><h2>39795.59</td>      
    <td valign=top align=right><h2>52593.66</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_fevrier\" value=\"".$prevision[10]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[10]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[10]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[10]);
		   print("%</td>"); ?>
	</tr>
	<tr>
		<td valign=top><h2><B>Mars</B></td>
		<td valign=top align=right><h2>80824.09</td>
		<td valign=top align=right><h2>64683.94</td>
    <td valign=top align=right><h2>43458.65</td>
    <td valign=top align=right><h2>40795.00</td>
		<td valign=top align=right><h2>40322.15</td>      
    <td valign=top align=right><h2>43365.47</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_mars\" value=\"".$prevision[11]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2>");
		   printf('%01.2f',$montant[11]);
		   print("</td>");
		   
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[11]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$cumul_pourcentage[11]);
		   print("%</td>"); ?>
	</tr>
	<?php //HEBERGEMENT?>
	<tr>
		<td valign=top><h2><B>H&eacute;bergement</B></td>
		<td valign=top align=right><h2>6256.00</td>
		<td valign=top align=right><h2>2768.00</td>
    <td valign=top align=right><h2>2238.00</td>
    <td valign=top align=right><h2>5359.00</td>
		<td valign=top align=right><h2>4510.10</td>      
    <td valign=top align=right><h2>3535.10</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_hebergement\" value=\"".$prevision[12]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"hebergement_reel\" value=\"".$montant[12]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   
		  $pourcentage[12] = (($montant[12] / $prevision[12])*100);
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[12]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   print("</td>"); ?>
	</tr>
	<?php //NOURRITURE?>
	<tr>
		<td valign=top><h2><B>Nourriture</B></td>
		<td valign=top align=right><h2>7027.00</td>
		<td valign=top align=right><h2>3688.00</td>
    <td valign=top align=right><h2>2598.00</td>
    <td valign=top align=right><h2>6210.00</td>
		<td valign=top align=right><h2>5559.40</td>      
    <td valign=top align=right><h2>4431.64</td>
		<?php  print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"prevision_nourriture\" value=\"".$prevision[13]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   print("<td valign=top align=right><h2><input type=\"text\" align=right name=\"nourriture_reel\" value=\"".$montant[13]."\" align=\"top\" maxlength=\"10\" size=\"13\"></td>");
		   
		  $pourcentage[13] = (($montant[13] / $prevision[13])*100);
		   print("<td valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[13]);
		   print("%</td>"); 
		   print("<td valign=top align=right><h2>");
		   print("</td>"); ?>
	</tr>
	<tr>
		<td valign=top bgcolor=#D6D6D6><h2><B>TOTAL</B></td>
		<td valign=top bgcolor=#D6D6D6 align=right><h2>473200.10</td>
		<td valign=top bgcolor=#D6D6D6 align=right><h2>486079.52</td>
    <td valign=top bgcolor=#D6D6D6 align=right><h2>502595.77</td>
    <td valign=top bgcolor=#D6D6D6 align=right><h2>426662.12</td>  
    <td valign=top bgcolor=#D6D6D6 align=right><h2>380604.20</td>  
    <td valign=top bgcolor=#D6D6D6 align=right><h2>401680.67</td>  
		<?php 
		   $total_prevision = ($prevision[0]+$prevision[1]+$prevision[2]+$prevision[3]+$prevision[4]+$prevision[5]+$prevision[6]+$prevision[7]+$prevision[8]+$prevision[9]+$prevision[10]+$prevision[11]+$prevision[12]+$prevision[13]);
		   print("<td bgcolor=#D6D6D6 valign=top align=right><h2>");
		   printf('%01.2f',$total_prevision);
		   print("</td>");
		   
		   print("<td bgcolor=#D6D6D6 valign=top align=right><h2>");
		   printf('%01.2f',$total_montant+$montant[12]+$montant[13]);
		   print("</td>");

		   $pourcentage[12] = (($total_montant / $total_prevision)*100);
		   print("<td bgcolor=#D6D6D6 valign=top align=right><h2>");
		   printf('%01.0f',$pourcentage[12]);
		   print("%</td>"); 
		   print("<td  bgcolor=#D6D6D6 valign=top align=right><h2>");
		   print("</td>"); ?>
	</tr>
	
	
	</table>

	<table width=720px cellspacing=0 cellpadding=0 border=0>
	<tr>
		<td width=330px>
		</td>
		<td valign=top class=noprint>
			<input type=submit name=Valider value="-----Valider-----">
		</td>
	</tr>
	</table>
	<?php 	
    $pourcentage_r = (($montant[12]+$montant[13])*0.35);
    $pourcentage_v = (($montant[12]+$montant[13])*0.65);
    $grand_tot_r += $pourcentage_r;
    $grand_tot_v += $pourcentage_v;
	?>
    
    
	tot Ville-Marie = <?php  print($grand_tot_v); ?>
    <br>
    tot Richelieu = <?php  print($grand_tot_r); ?>
    <br>
	tot Autre = <?php  print($grand_tot_else); ?>
	
	
	</form>
	<BR><BR>
	</center>

	
		
<?php 
//BAS DE PAGE**********************************************************************
	
print("<BR><BR><table width=100%><tr><td width=50% class=noprint><center><hr>");
	//Afficher le bouton de retour au menu principal.

	print("<a href='rapport.php?Bsession_id=".$Bsession_id."'><img src=bouton2.gif border=0></a>");
	
	print("<a href='../menu-base.php?Bsession_id=".$Bsession_id."'><img src=bouton1.gif border=0></a>");

print("</td><tr></table>");
?>	
<BR><BR>
	
	

</body>
</html>	
	
	
	
	
