<html>
<!--    cibl&eacute; par:  liste-contrat.php

		cible: toute les pages ajout...php
 -->

<!-- param&egrave;tre &eacute;mis:        -session_id         le num&eacute;ro de la session
						

	 param&egrave;tre re&ccedil;evable :  -session_id         le num&eacute;ro de la session
	 						-code_contrat
							-code_client
 -->
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../baseCSS.css" rel="stylesheet" type="text/css">
<title>Revenu d'op&eacute;ration</title>
<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);

//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!");

	
$date = date('Y-m-d H:i:s');
print("<h2><div align=right>".$date."</div>");
print("<center><h1>Liste des contrats n'ayant termin&eacute; d'&ecirc;tre pay&eacute;.</h1><br>");
print("<h2>La table est tri&eacute;e par date de d&eacute;but du contrat.</h2>");
print("<br><br>");
print ("<table border=1 cellpadding=0 cellspacing=0 width=630px");	

//debut
print("<tr><td width=80px>");
print("<b><h2>D&eacute;but<br><br>");
print("</td>");

//No contrat
print("<td width=50px>");
print("<b><h2>No contrat<br><br>"); 
print("</td>");
	
//organisme
print("<td width=260px>");
print("<b><h2>Organisme<br><br>");
print("</td>");
	
//total du contrat
print("<td width=120px>");
print("<b><h2>Total du contrat<br><br>");
print("</td>");

//montant &agrave; payer
print("<td width=120px>");
print("<b><h2>Montant &agrave; payer<br><br>");

//4010
print("<td width=90px>");
print("<b><h2>4010<br><br>");
print("</td>");

//4015
print("<td width=90px>");
print("<b><h2>4015<br><br>");
print("</td>");

//4020
print("<td width=90px>");
print("<b><h2>4020<br><br>");
print("</td>");

//4025
print("<td width=90px>");
print("<b><h2>4025<br><br>");
print("</td>");

//4030
print("<td width=90px>");
print("<b><h2>4030<br><br>");
print("</td>");

//4035
print("<td width=90px>");
print("<b><h2>4035<br><br>");
print("</td>");

//4040
print("<td width=90px>");
print("<b><h2>4040<br><br>");
print("</td>");

//4045
print("<td width=90px>");
print("<b><h2>4045<br><br>");
print("</td>");

//4050
print("<td width=90px>");
print("<b><h2>4050<br><br>");
print("</td>");

//4055
print("<td width=90px>");
print("<b><h2>4055<br><br>");
print("</td>");

//4060
print("<td width=90px>");
print("<b><h2>4060<br><br>");
print("</td>");

//4061
print("<td width=90px>");
print("<b><h2>4061<br><br>");
print("</td>");

//4205
print("<td width=90px>");
print("<b><h2>4205<br><br>");
print("</td>");

//2420
print("<td width=90px>");
print("<b><h2>2420<br><br>");
print("</td>");

print("</tr>");	
	

//////////////////////////////////////////////////////////////////////////////////////////////////////
// 1 - RECHERCHE TABLE CONTRAT																		//
//////////////////////////////////////////////////////////////////////////////////////////////////////
//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, depot_50
        FROM base_contrat
		WHERE etat <> 'annulé'
		AND etat <> 'passé'
		AND etat <> 'soumission'
		ORDER BY YEAR(date_debut), MONTH(date_debut);";
$result_contrat = mysql_query($sql_contrat)
	or die ("Ne peut lire dans la table des membres".$sql_contrat);
$num_contrat = mysql_numrows($result_contrat);

$mois_actuel=0;
$mois_total=0;
$mois_diff=0;
$tot_mois_total=0;
$tot_mois_diff=0;
$i = 0;
$tot_mois_4010=0;

while ($row_contrat = mysql_fetch_row ($result_contrat))
{
	if ($num_contrat)
	{
		
		
		

		$montant_reel=0;
		$montant_du_contrat=0;
		$diff=0;
		$tot_chalet_prix_plein=0;
		$cafe_prix_plein=0;
		$tot_activite_prix_plein=0;
		$tot_achat_prix_plein=0;
		$tot_loc_prix_plein=0;
		$tot_rabais_prix=0;
		$tot_chalet_prix_rabais=0;
		$cafe_prix_rabais=0;
		$tot_activite_prix_rabais=0;
		$tot_achat_prix_rabais=0;
		$tot_loc_prix_rabais=0;
		$p4010=0;
		$p4015=0;
		$p4020=0;
		$p4025=0;
		$p4030=0;
		$p4035=0;
		$p4040=0;
		$p4045=0;
		$p4050=0;
		$p4055=0;
		$p4060=0;
		$p4061=0;
		$poste_cafe=0;
		$tot_4010=0;
		$tot_4015=0;
		$tot_4020=0;
		$tot_4025=0;
		$tot_4030=0;
		$tot_4035=0;
		$tot_4040=0;
		$tot_4045=0;
		$tot_4050=0;
		$tot_4055=0;
		$tot_4060=0;
		$tot_4061=0;
		$tot_4205=0;
		
	
		$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++]);
		$depot_50 = ($row_contrat[$i++]);
		

		
		
	}
	else
	{
		die ("Il y a un probl&egrave;me dans la base de donn&eacute;es contrat !".$sql_contrat);
	}
	//TABLE CLIENT***************************************************************************************
	$sql_client = "SELECT organisme, type, code_client
		       	FROM base_clients
			    WHERE base_clients.code_client = '$num_client';";
	$result_client = mysql_query($sql_client) or die ("Ne peut lire dans la table des clients".$sql_client);
	$num_client = mysql_numrows($result_client);
	if ($num_client)
	{
		$c = 0;
		$row_client = mysql_fetch_row ($result_client);
		$client_organisme = ($row_client[$c++]);
		$client_type = ($row_client[$c++]);
		$code_client = ($row_client[$c++]);
	}
	else
	{
		die ("Il y a un probl&egrave;me dans la base de donn&eacute;es !".$sql_client);
	}


	//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
	   		  FROM base_ref1chalets, base_chalets
			 WHERE base_chalets.code_contrat = '$code_contrat'
	 			  AND base_chalets.actif = 'O'
				  AND base_chalets.reservation = 'N'
	              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);
	
	while ($row_chalet = mysql_fetch_row ($result_chalet))
	{	
		//MISE A ZERO DES VARIABLES
		$chalet_nom_tot = "";
		$chalet_prix_par_jour = 0;
		$chalet_prix_plein = 0;
		$chalet_prix_rabais = 0;
			
		if ($num_chalet)
		{
			$j = 0;
			$chalet_nom = ($row_chalet[$j++]);
			$chalet_nom_tot = ($chalet_nom_tot." ".$chalet_nom.",");		//INCR&Eacute;MENTATION DES NOMS DE CHALETS DANS UNE SEUL VARIABLE
			$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++]);
			
			if ($client_type == 'SMM'){
				$tot_4010 +=$chalet_prix_rabais; /*$tot_mois_4010 += $chalet_prix_rabais;*/}
			if ($client_type == 'Trio')
				$tot_4015 +=$chalet_prix_rabais;	
			if ($client_type == 'Ext')
				$tot_4020 +=$chalet_prix_rabais;	
			if ($client_type == 'District')
				$tot_4025 +=$chalet_prix_rabais;
			if ($client_type == 'Famille')
				$tot_4030 +=$chalet_prix_rabais;	
			if ($client_type == 'Autres')
				$tot_4035 +=$chalet_prix_rabais;
			
			
			
						
			
			
		}
		else
		{
			die ("Il y a un probl&egrave;me dans la base de donn&eacute;es chalet !".$sql_chalet);
		}	
	}
	
	//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++]);
		$tot_4060=$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++]);
			
			if ($activite_compte_budget == 4010)
				$tot_4010 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4015)
				$tot_4015 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4020)
				$tot_4020 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4025)
				$tot_4025 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4030)
				$tot_4030 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4035)
				$tot_4035 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4040)
				$tot_4040 +=$activite_prix_rabais;	
			if ($activite_compte_budget == 4045)
				$tot_4045 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4050)
				$tot_4050 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4055)
				$tot_4055 +=$activite_prix_rabais;
			if ($activite_compte_budget == 4060)
				$tot_4060 +=$activite_prix_rabais;		
			if ($activite_compte_budget == 4061)
				$tot_4061 +=$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++]);
			
			if ($loc_compte_budget == 4010)
				$tot_4010 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4015)
				$tot_4015 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4020)
				$tot_4020 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4025)
				$tot_4025 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4030)
				$tot_4030 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4035)
				$tot_4035 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4040)
				$tot_4040 +=$loc_prix_rabais;	
			if ($loc_compte_budget == 4045)
				$tot_4045 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4050)
				$tot_4050 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4055)
				$tot_4055 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4060)
				$tot_4060 +=$loc_prix_rabais;		
			if ($loc_compte_budget == 4061)
				$tot_4061 +=$loc_prix_rabais;
			if ($loc_compte_budget == 4205)
				$tot_4205 +=$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++]);
			
			if ($achat_compte_budget == 4010)
				$tot_4010 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4015)
				$tot_4015 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4020)
				$tot_4020 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4025)
				$tot_4025 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4030)
				$tot_4030 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4035)
				$tot_4035 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4040)
				$tot_4040 +=$achat_prix_rabais;	
			if ($achat_compte_budget == 4045)
				$tot_4045 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4050)
				$tot_4050 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4055)
				$tot_4055 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4060)
				$tot_4060 +=$achat_prix_rabais;		
			if ($achat_compte_budget == 4061)
				$tot_4061 +=$achat_prix_rabais;
			if ($achat_compte_budget == 4205)
				$tot_4205 +=$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++]);
			
			if ($rabais_compte_budget == 4010){
				$tot_4010 -=$rabais_prix; /*$tot_mois_4010 -= $chalet_prix_rabais;*/}
			if ($rabais_compte_budget == 4015)
				$tot_4015 -=$rabais_prix;
			if ($rabais_compte_budget == 4020)
				$tot_4020 -=$rabais_prix;
			if ($rabais_compte_budget == 4025)
				$tot_4025 -=$rabais_prix;
			if ($rabais_compte_budget == 4030)
				$tot_4030 -=$rabais_prix;
			if ($rabais_compte_budget == 4035)
				$tot_4035 -=$rabais_prix;
			if ($rabais_compte_budget == 4040)
				$tot_4040 -=$rabais_prix;
			if ($rabais_compte_budget == 4045)
				$tot_4045 -=$rabais_prix;
			if ($rabais_compte_budget == 4050)
				$tot_4050 -=$rabais_prix;
			if ($rabais_compte_budget == 4055)
				$tot_4055 -=$rabais_prix;
			if ($rabais_compte_budget == 4060)
				$tot_4060 -=$rabais_prix;
			if ($rabais_compte_budget == 4061)
				$tot_4061 -=$rabais_prix;
			
		}	
		else
		{
			die ("Il y a un probl&egrave;me dans la base de donn&eacute;es rabais !".$sql_rabais);
		}	
	}
	

//////////////////////////////////////////////////////////////////////////////////////////////////////
// 4 - COLLECTE DES D&Eacute;POTS RECU																		//
//////////////////////////////////////////////////////////////////////////////////////////////////////	
	$sql_depot = "select base_depot.recu_le, base_depot.montant, base_depot.commentaire, base_depot.poste, base_depot.code_depot
		  FROM base_depot
		 WHERE base_depot.code_contrat = '$code_contrat';";
	$result_depot = mysql_query($sql_depot) or die("Probl&egrave;me de recherche dans les paiements<br>".$sql_depot);
	$num_depot = mysql_numrows($result_depot);	

	//MISE A ZERO DES VARIABLES
		$depot_montant = 0;
		$depot_total_du_contrat = 0;
		$depot_poste = 0;
			$p4010=0;
			$p4015=0;
			$p4020=0;
			$p4025=0;
			$p4030=0;
			$p4035=0;
			$p4040=0;
			$p4045=0;
			$p4050=0;
			$p4055=0;
			$p4060=0;
			$p4061=0;

	while ($row_depot = mysql_fetch_row ($result_depot))
	{
		//MISE A ZERO DES VARIABLES
		$depot_montant = 0;
			$depot_poste = 0;
		
		if ($num_depot)
		{
			$w = 0;
			$depot_recu_le = ($row_depot[$w++]);
			$depot_montant = ($row_depot[$w++]);
			$depot_commentaire = ($row_depot[$w++]);
			$depot_poste = ($row_depot[$w++]);
			$depot_code_depot = ($row_depot[$w++]);
			
			if ($depot_poste == '4010'){	$p4010 = $p4010 + $depot_montant; $mois_4010 = $mois_4010 + $depot_montant; $grand_tot_p4010+=$depot_montant; }
			if ($depot_poste == '4015'){	$p4015 = $p4015 + $depot_montant; $mois_4015 = $mois_4015 + $depot_montant; $grand_tot_p4015+=$depot_montant; }
			if ($depot_poste == '4020'){	$p4020 = $p4020 + $depot_montant; $mois_4020 = $mois_4020 + $depot_montant; $grand_tot_p4020+=$depot_montant; }
			if ($depot_poste == '4025'){	$p4025 = $p4025 + $depot_montant; $mois_4025 = $mois_4025 + $depot_montant; $grand_tot_p4025+=$depot_montant; }
			if ($depot_poste == '4030'){	$p4030 = $p4030 + $depot_montant; $mois_4030 = $mois_4030 + $depot_montant; $grand_tot_p4030+=$depot_montant; }
			if ($depot_poste == '4035'){	$p4035 = $p4035 + $depot_montant; $mois_4035 = $mois_4035 + $depot_montant; $grand_tot_p4035+=$depot_montant; }
			if ($depot_poste == '4040'){	$p4040 = $p4040 + $depot_montant; $mois_4040 = $mois_4040 + $depot_montant; $grand_tot_p4040+=$depot_montant; }
			if ($depot_poste == '4045'){	$p4045 = $p4045 + $depot_montant; $mois_4045 = $mois_4045 + $depot_montant; $grand_tot_p4045+=$depot_montant; }
			if ($depot_poste == '4050'){	$p4050 = $p4050 + $depot_montant; $mois_4050 = $mois_4050 + $depot_montant; $grand_tot_p4050+=$depot_montant; }
			if ($depot_poste == '4055'){	$p4055 = $p4055 + $depot_montant; $mois_4055 = $mois_4055 + $depot_montant; $grand_tot_p4055+=$depot_montant; }
			if ($depot_poste == '4060'){	$p4060 = $p4060 + $depot_montant; $mois_4060 = $mois_4060 + $depot_montant; $grand_tot_p4060+=$depot_montant; }
			if ($depot_poste == '4061'){	$p4061 = $p4061 + $depot_montant; $mois_4061 = $mois_4061 + $depot_montant; $grand_tot_p4061+=$depot_montant; }
	
	
			$mois_montant_recu = $mois_montant_recu + $depot_montant;
			$grand_tot_montant_recu+=$depot_montant;
			$depot_total_du_contrat += $depot_montant;		

					
		}
		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);

	//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);
	
	
	//DIFFERENCE ENTRE LE MONTANT TOTAL ET LE MONTANT RECU
	$diff = $montant_du_contrat-$depot_total_du_contrat;




//////////////////////////////////////////////////////////////////////////////////////////////////////
// X - AFFICHER LES R&Eacute;SULTATS DANS LE TABLEAU														//
//////////////////////////////////////////////////////////////////////////////////////////////////////

	if($montant_du_contrat > $depot_total_du_contrat)
	{	
	
			$old_mois = $mois_actuel;
			//Decoupe les dates
			$debut_aryDateMaintenant = explode("-",$date_debut);
			$mois_actuel = $debut_aryDateMaintenant[1];
	
			
			
			//SI CEST LA FIN DU MOIS, AFFICHER LES TOTAUX
			if (($old_mois <> 0) and ($old_mois <> $mois_actuel))
			{
				if ($old_mois == 1) $mois = 'janvier';
				if ($old_mois == 2) $mois = 'f&eacute;vrier';
				if ($old_mois == 3) $mois = 'mars';
				if ($old_mois == 4) $mois = 'avril';
				if ($old_mois == 5) $mois = 'mai';
				if ($old_mois == 6) $mois = 'juin';
				if ($old_mois == 7) $mois = 'juillet';
				if ($old_mois == 8) $mois = 'ao&ucirc;t';
				if ($old_mois == 9) $mois = 'septembre';
				if ($old_mois == 10) $mois = 'octobre';
				if ($old_mois == 11) $mois = 'novembre';
				if ($old_mois == 12) $mois = 'd&eacute;cembre';
				print("<td colspan=3 bgcolor=#D6D6D6><H2><B>mois ".$mois."</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$mois_total); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$mois_diff); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4010); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4015); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4020); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4025); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4030); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4035); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4040); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4045); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4050); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4055); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4060); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4061); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4205); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>-");
				printf('%01.2f',$tot_mois_2420); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("</tr><tr>");
				$tot_mois_total += $mois_total;
				$tot_mois_diff += $mois_diff;
				$mois_total = 0;
				$mois_diff = 0;
				$tot_mois_4010=0;
				$tot_mois_4015=0;
				$tot_mois_4020=0;
				$tot_mois_4025=0;
				$tot_mois_4030=0;
				$tot_mois_4035=0;
				$tot_mois_4040=0;
				$tot_mois_4045=0;
				$tot_mois_4050=0;
				$tot_mois_4055=0;
				$tot_mois_4060=0;
				$tot_mois_4061=0;
				$tot_mois_4205=0;
				$tot_mois_2420=0;
			}
			
		$tot_poste = ($tot_4010-$p4010)+($tot_4015-$p4015)+($tot_4020-$p4020)+($tot_4025-$p4025)+($tot_4030-$p4030)+($tot_4035-$p4035)+($tot_4040-$p4040)+($tot_4045-$p4045)+($tot_4050-$p4050)+($tot_4055-$p4055)+($tot_4060-$p4060)+($tot_4061-$p4061)+($tot_4205-$p4205);
		$diff = round($diff,2);		$tot_poste = round($tot_poste,2);
		$error = $diff - $tot_poste;
		
		$tot_mois_4010 +=$tot_4010-$p4010;
		$tot_mois_4015 +=$tot_4015-$p4015;
		$tot_mois_4020 +=$tot_4020-$p4020;
		$tot_mois_4025 +=$tot_4025-$p4025;
		$tot_mois_4030 +=$tot_4030-$p4030;
		$tot_mois_4035 +=$tot_4035-$p4035;
		$tot_mois_4040 +=$tot_4040-$p4040;
		$tot_mois_4045 +=$tot_4045-$p4045;
		$tot_mois_4050 +=$tot_4050-$p4050;
		$tot_mois_4055 +=$tot_4055-$p4055;
		$tot_mois_4060 +=$tot_4060-$p4060;
		$tot_mois_4061 +=$tot_4061-$p4061;
		$tot_mois_4205 +=$tot_4205-$p4205;
		$tot_mois_2420 +=$tot_2420+$depot_50;
		$mois_total +=$montant_du_contrat;
		$mois_diff +=$diff;
		
		$grand_tot_mois_4010 += $tot_4010-$p4010;
		$grand_tot_mois_4015 += $tot_4015-$p4015;
		$grand_tot_mois_4020 += $tot_4020-$p4020;
		$grand_tot_mois_4025 += $tot_4025-$p4025;
		$grand_tot_mois_4030 += $tot_4030-$p4030;
		$grand_tot_mois_4035 += $tot_4035-$p4035;
		$grand_tot_mois_4040 += $tot_4040-$p4040;
		$grand_tot_mois_4045 += $tot_4045-$p4045;
		$grand_tot_mois_4050 += $tot_4050-$p4050;
		$grand_tot_mois_4055 += $tot_4055-$p4055;
		$grand_tot_mois_4060 += $tot_4060-$p4060;
		$grand_tot_mois_4061 += $tot_4061-$p4061;
		$grand_tot_mois_4205 += $tot_4205-$p4205;
		$grand_tot_mois_2420 += $tot_2420+$depot_50;
		$grand_tot_total += ($tot_4010)+($tot_4015)+($tot_4020)+($tot_4025)+($tot_4030)+($tot_4035)+($tot_4040)+($tot_4045)+($tot_4050)+($tot_4055)+($tot_4060)+($tot_4061)+($tot_4205)+($tot_2420);
		$grand_tot_diff += ($tot_4010-$p4010)+($tot_4015-$p4015)+($tot_4020-$p4020)+($tot_4025-$p4025)+($tot_4030-$p4030)+($tot_4035-$p4035)+($tot_4040-$p4040)+($tot_4045-$p4045)+($tot_4050-$p4050)+($tot_4055-$p4055)+($tot_4060-$p4060)+($tot_4061-$p4061)+($tot_4205-$p4205)+($tot_2420-$depot_50);
		
		
		// affiche la date de d&eacute;but
		if (($error < 0.00) or ($error > 0.00)) 
			print("<td bgcolor=red><h2>");
		else
			print("<td><h2>");
		print($date_debut);
		print("</td>");
	
		// affiche le code du contrat
		print("<td><h2><center><a href=../contract/gestion-contract.php?Bsession_id=$Bsession_id&code_contrat=$code_contrat&code_client=$code_client\">$numero_contrat</a></td>");						//CONT
	
		// affiche l'organisme
		print("<td><h2>");
		print($client_organisme);			
		print("</td>");
		
		// montant total
		print("<td align=right bgcolor=#D6D6D6><h2>&nbsp;");
		if(!empty($montant_du_contrat)){		
		printf('%01.2f',$montant_du_contrat); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		// montant a payer
		print("<td align=right bgcolor=#D6D6D6><h2>&nbsp;");
		if(!empty($diff)){		
		printf('%01.2f',$diff); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
		
		//poste
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4010)){								//4010
			printf('%01.2f',$tot_4010-$p4010); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4015)){								//4015
			printf('%01.2f',$tot_4015-$p4015); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4020)){								//4020
			printf('%01.2f',$tot_4020-$p4020); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4025)){								//4025
			printf('%01.2f',$tot_4025-$p4025); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4030)){								//4030
			printf('%01.2f',$tot_4030-$p4030); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4035)){								//4035
			printf('%01.2f',$tot_4035-$p4035); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4040)){								//4040
			printf('%01.2f',$tot_4040-$p4040); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4045)){								//4045
			printf('%01.2f',$tot_4045-$p4045); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4050)){								//4050
			printf('%01.2f',$tot_4050-$p4050); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4055)){								//4055
			printf('%01.2f',$tot_4055-$p4055); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4060)){								//4060
			printf('%01.2f',$tot_4060-$p4060); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4061)){								//4061
			printf('%01.2f',$tot_4061-$p4061); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
	
		print("<td align=right><h2>&nbsp;");
		if(!empty($tot_4205)){								//4205
			printf('%01.2f',$tot_4205-$p4205); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td>");
		
		print("<td align=right><h2>&nbsp;");
		if((!empty($depot_50)) and ($depot_50 > 0)){								//4050
			print("-");
			printf('%01.2f',$depot_50); print("$&nbsp;&nbsp;&nbsp;");}
		print("</td></tr>");
		
		
		
		
		
		
	}
	
	
	
}
	
	
	
	
	

				if ($mois_actuel == 1) $mois = 'janvier';
				if ($mois_actuel == 2) $mois = 'f&eacute;vrier';
				if ($mois_actuel == 3) $mois = 'mars';
				if ($mois_actuel == 4) $mois = 'avril';
				if ($mois_actuel == 5) $mois = 'mai';
				if ($mois_actuel == 6) $mois = 'juin';
				if ($mois_actuel == 7) $mois = 'juillet';
				if ($mois_actuel == 8) $mois = 'ao&ucirc;t';
				if ($mois_actuel == 9) $mois = 'septembre';
				if ($mois_actuel == 10) $mois = 'octobre';
				if ($mois_actuel == 11) $mois = 'novembre';
				if ($mois_actuel == 12) $mois = 'd&eacute;cembre';
				print("<td colspan=3 bgcolor=#D6D6D6><H2><B>mois ".$mois."</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$mois_total); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$mois_diff); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4010); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4015); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4020); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4025); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4030); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4035); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4040); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4045); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4050); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4055); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4060); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4061); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>");
				printf('%01.2f',$tot_mois_4205); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("<td align=right bgcolor=#D6D6D6><h2><b>-");
				printf('%01.2f',$tot_mois_2420); print("$&nbsp;&nbsp;&nbsp;");
				print("</td>");
				print("</tr><tr>");
				$mois_total = 0;
				$mois_diff = 0;
	
	
	
	
	
	
	
print("<tr><td colspan=3 bgcolor=#D6D6D6><H2><B>TOTAL</td>");
print("<td align=right bgcolor=#D6D6D6><h2><b>");
printf('%01.2f',$tot_mois_total); print("$&nbsp;&nbsp;&nbsp;");
print("</td>");
print("<td align=right bgcolor=#D6D6D6><h2><b>");
printf('%01.2f',$tot_mois_diff); print("$&nbsp;&nbsp;&nbsp;");
print("</td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4010); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4015); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4020); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4025); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4030); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4035); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4040); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4045); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4050); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4055); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4060); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4061); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>");
printf('%01.2f',$grand_tot_mois_4205); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("<td align=right bgcolor=#D6D6D6><h2><B>-");
printf('%01.2f',$grand_tot_mois_2420); print("$&nbsp;&nbsp;&nbsp;");
print("</B></td>");
print("</tr>");	
	
print("</table>");








//BAS DE PAGE**********************************************************************
	
print("<hr><table width=100%><tr><td width=50%><center>");
	//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>");
	//Fin du formulaire.

	
	





	
?>

</body>
</html>	
	
	
	
	
