<?php

// ini_set('display_errors', 1);

$total_qte = 0;


define("ADMIN", true);
require_once("../../../common/lib.php");
require_once("../../../common/define.php");
define("TITLE_ELEMENT", 'Statistiques articles');
if(!isset($_SESSION['user'])){
    header("Location: ../../login.php");
    exit();
}
require_once("../../includes/fn_module.php"); 

header('Content-Type: text/html; charset=utf-8');
ini_set('default_charset', 'utf-8');
setlocale(LC_ALL, 'fr_FR');
setlocale(LC_TIME, "fr_FR");

?>
<!DOCTYPE html>
<head>
    <?php include("../../includes/inc_header_common.php"); ?>
    <?php include("../../includes/functions.php"); ?>

</head>
<body>
    <div id="wrapper">
        <?php include("../../includes/inc_top.php"); ?>
        <div id="page-wrapper" >
            <div class="page-header">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-6">
                            <h1><i class="fa fa-registered"></i> Statistiques articles</h1>
                        </div>
						<div class="col-md-6 text-right" style="margin-top:15px;">
							<a href="#" target="_blank"><button class="btn btn-default" type="button" id="print_page"><i class="fa fa-print"></i> Imprimer</button></a>
						</div>

                    </div>
                </div>
            </div>
            <div class="container-fluid">

                <div class="row">	
				
				
<table cellspacing="10" cellpadding="10">				
				
				<td>* Source des données : </td><td><b><? 
				if($_GET["source"] <> "" ) {
					switch ($_GET["source"]) {
                       case "BF":
                         echo " Bon de Fabrication";
                         break;
                       case "BE":
                          echo " BE Achat";
                          break;
                       case "BS":
                         echo " BS Achat";
                         break;
                       case "BE_BS":
                         echo " BE & BS Achat";
                         break;
                       case "FA":
                         echo " Facture d’achat";
                         break;
                       case "BL_BR":
                         echo " BL & BR Vente";
                         break;

                    }
				}
				
				$cat_id = "";
				
				?></b></td></tr>
				<td valign="top">* Catégorie famille(s) : </td><td><b><? 

					if (!empty($_GET["cat_famille"])) {
						$cat_famille = $_GET["cat_famille"];
						for($i=0;$i<sizeof($cat_famille);$i++)
						{
							echo get_cat_famille($cat_famille[$i])."<br>";
							$cat_id = get_cat_famille($cat_famille[$i]);
						}
					}	

				?></b></td></tr>
				<tr><td valign="top">* Famille(s) : </td><td><b><? 

				if (!empty($_GET["famille"])) {
						$famille = $_GET["famille"];
						for($i=0;$i<sizeof($famille);$i++)
						{
							echo get_famille($famille[$i])."<br>";
						}
					}
				?></b></td>
				
				<tr><td valign="top">* Sous-famille(s) : </td><td><b><? 
				
					if (!empty($_GET["sous_famille"])) {
						$sous_famille = $_GET["sous_famille"];
						for($i=0;$i<sizeof($sous_famille);$i++)
						{
							echo get_sous_famille($sous_famille[$i])."<br>";
						}
					}
				?></b>
				</td>
				</tr>
				<tr><td valign="top">* Article(s) : </td><td><b><? 
				
					if (!empty($_GET["article"])) {
						$article = $_GET["article"];
						for($i=0;$i<sizeof($article);$i++)
						{
							echo get_article($article[$i])."<br>";
						}
					}
				?></b>
				</td>
				</tr>
				<tr><td valign="top">* Trier par : </td><td><b><? 
				
					echo $_GET["trier"]."<br>";

				?></b>
				</td>
				</tr>
				<tr><td valign="top">* Listage : </td><td><b><? 
				
					echo $_GET["listage"]."<br>";

				?></b>
				</td>
				</tr>
				<tr><td valign="top">* Quantité affichée : </td><td><b><? 
				
					echo $_GET["qte"]."<br>";

				?></b>
				</td>
				</tr>
								
</table>					
			
				
				<div class="table-responsive">
				
				
			    <table class="table table-bordered table-hover table-striped" id="listing_base">
                                    
									<thead>
										<tr>
											<th></th>
											<? if ($_GET["listage"] == "mensuel"){ 
												$colones = 14 ;
											?>
													<th><b>Janvier</b></th>
													<th><b>Février</b></th>
													<th><b>Mars</b></th>
													<th><b>Avril</b></th>
													<th><b>Mai</b></th>
													<th><b>Juin</b></th>
													<th><b>Juillet</b></th>
													<th><b>Août</b></th>
													<th><b>Septembre</b></th>
													<th><b>Octobre</b></th>
													<th><b>Novembre</b></th>
													<th><b>Décembre</b></th>
											<? }elseif( $_GET["listage"] == "trimestriel"){ 
												$colones = 6 ;
											?>
													<th><b>1er trimestre</b></th>
													<th><b>2eme trimestre</b></th>
													<th><b>3eme trimestre</b></th>
													<th><b>4eme trimestre</b></th>
											<? }else{ 
												$colones = 3 ;
											?>
													<th><b>Année</b></th>
											<? }?>
											<th><b>Total<br>de l'année</b></th>	
										<tr>										
									</thead>	
                                    <tbody>
									<tr>
									
									<?
									
									$source = $_GET["source"];						
									
									$annee = $_GET["annee"];
									switch ($source) {
										case "BF":
											if(isset($_GET["cat_famille"]) == 2){
												$type = "ACHAT/VENTE";
												$prod_table = "pm_produits";
												// $source = " type = 'BF' AND (type_product= 'VENTE' OR type_product= 'ACHAT') ";	
												$source = " type = 'BF' ";	
											}else{
												$type = "VENTE";
												$prod_table = "pm_produits";
												$source = " type = 'BF' ";				
											}
											break;
										case "BE_BS":
											$type = "ACHAT";
											$prod_table = "pm_produitsachat";
											$source = " (type = 'BE' OR type = 'BS') ";
											break;
										case "BE":
											$type = "ACHAT";
											$prod_table = "pm_produitsachat";
											$source = " type = 'BE' ";
											break;
										case "BS":
											$type = "ACHAT";
											$prod_table = "pm_produitsachat";
											$source = " type = 'BS' ";
											break;
										case "FA":
											$type = "ACHAT";
											$prod_table = "pm_produitsachat";
											$source = " type = 'FA' ";
											break;
										case "BL_BR":
											$type = "VENTE";
											$prod_table = "pm_produits";
											$source = " (type = 'BL' OR type = 'BR') ";
									}
									
									
									if (!empty($_GET["cat_famille"])) {
										$cat_famille = $_GET["cat_famille"];
										for($i=0;$i<sizeof($cat_famille);$i++)
										{						
											$query_cat = "select * from pm_famille_classe where famille_cat = ".$cat_famille[$i];
											// echo $query_cat."<br>";
											$result_cat = @$db->query($query_cat);
												foreach($result_cat as $row_cat){
													echo "<tr><td colspan='$colones' align='center' style='background-color: #ff9425;color:#000'><b>".$row_cat["nom"]."</b></td>";
													
													if($_GET["trier"] == "famille"){
														get_stat_famille($row_cat["id"],$source,$type,$annee[0],$_GET["qte"]);
													}else{
													
													$query_cat2 = "select * from pm_famille where famille_classe = ".$row_cat["id"];
													// echo $query_cat2."<br>";
													$result_cat2 = @$db->query($query_cat2);
														foreach($result_cat2 as $row_cat2){													
															
															echo "<tr><td colspan='$colones' align='center' style='background-color: #00a1af;color:#000'><b>".$row_cat2["nom"]."</b></td>";
															
															//===================================
															if($_GET["trier"] == "sous_famille"){
																// echo $source."<br>";
																// echo $type."<br>";
																// echo "ici";
																get_stat_sous_famille($row_cat2["id"],$source,$type,$annee[0],$_GET["qte"]);
																if($annee[1] <> ""){
																	get_stat_sous_famille($row_cat2["id"],$source,$type,$annee[1],$_GET["qte"]);
																}
															}elseif( $_GET["trier"] == "article"){																
																if($cat_id == "Matières Premières"){
																	$prod_table = "pm_produitsachat";
																}
																$query_cat3 = "select * from ".$prod_table." where famille = ".$row_cat2["id"];
																// $query_cat3 .= " GROUP BY a.code_produit";
																// echo $cat_id."<br>";
																// echo $query_cat3."<br>";
																$result_cat3 = @$db->query($query_cat3);
																	foreach($result_cat3 as $row_cat3){
																		// echo $row_cat3["id"] ."<br>";
																		get_stat_article($row_cat3["code_produit"],$source,$type,$annee[0],$_GET["qte"]);
																	}
															}	
															//==================================
															
														}
													}
												}
											
										}
										
									}elseif(!empty($_GET["famille"])) {
										$famille = $_GET["famille"];

										for($i=0;$i<sizeof($famille);$i++)
										{
											$query_cat2 = "select * from pm_famille where famille_classe = ".$famille[$i];
													// echo $query_cat2."<br>";
													$result_cat2 = @$db->query($query_cat2);
														foreach($result_cat2 as $row_cat2){
															echo "<tr><td colspan='$colones' align='center' style='background-color: #00a1af;color:#000'><b>".$row_cat2["nom"]."</b></td>";
															
															//===================================
															if($_GET["trier"] == "sous_famille"){
																// echo $row_cat2["id"]." >>>>>>><br>";
																get_stat_sous_famille($row_cat2["id"],$source,$type,$annee[0],$_GET["qte"]);
																if($annee[1] <> ""){
																	get_stat_sous_famille($row_cat2["id"],$source,$type,$annee[1],$_GET["qte"]);
																}
															}elseif( $_GET["trier"] == "article"){
															
															$query_cat3 = "SELECT code_produit  ,'pm_produitsachat' as title FROM pm_produitsachat WHERE famille=".$row_cat2["id"]; 
																	$query_cat3 .= " UNION ALL";
																	$query_cat3 .= " SELECT code_produit  ,'pm_produits' as title FROM pm_produits WHERE famille=".$row_cat2["id"];
																// $query_cat3 = "select * from ".$prod_table." where famille = ".$row_cat2["id"];
																// echo $query_cat3."<br>";
																$result_cat3 = @$db->query($query_cat3);
																	foreach($result_cat3 as $row_cat3){
																		// echo $row_cat3["code_produit"] ."<br>";
																		get_stat_article($row_cat3["code_produit"],$source,$type,$annee[0],$_GET["qte"]);
																	}
															}
															//===================================	
														}
										}				
										
									}elseif(!empty($_GET["sous_famille"])) {
										$sous_famille = $_GET["sous_famille"];
										for($i=0;$i<sizeof($sous_famille);$i++)
										{
											
											//===================================
												if($_GET["trier"] == "sous_famille"){
													// echo "ici";
													get_stat_sous_famille($sous_famille[$i],$source,$type,$annee[0],$_GET["qte"]);
													if($annee[1] <> ""){
														get_stat_sous_famille($sous_famille[$i],$source,$type,$annee[1],$_GET["qte"]);
													}
													
												}elseif( $_GET["trier"] == "article"){
													
													if($_GET["source"] == "BF"){
																	$query_cat3 = "SELECT code_produit  ,'pm_produitsachat' as title FROM pm_produitsachat WHERE famille=".$sous_famille[$i]; 
																	$query_cat3 .= " UNION ALL";
																	$query_cat3 .= " SELECT code_produit  ,'pm_produits' as title FROM pm_produits WHERE famille=".$sous_famille[$i];
																}else{
																	$query_cat3 = "select * from ".$prod_table." where famille = ".$sous_famille[$i];
																}
													// $query_cat3 = "select * from ".$prod_table." where famille = ".$sous_famille[$i];
													
															// echo $query_cat3."<br>";
															$result_cat3 = @$db->query($query_cat3);
																foreach($result_cat3 as $row_cat3){
																	// echo $row_cat3["code_produit"] ."<br>";
																	// if($row_cat3["title"] == "pm_produitsachat" ){
																		// $type = "ACHAT";
																	// }else{
																		// $type = "ACHAT";
																	// }																	
																	get_stat_article($row_cat3["code_produit"],$source,$type,$annee[0],$_GET["qte"]);
																}
												}
												//=================================		
										}				
										
									}elseif(!empty($_GET["article"])) {
										$article = $_GET["article"];
										for($i=0;$i<sizeof($article);$i++)
										{						
									
												get_stat_article($article[$i],$source,$type,$annee[0],$_GET["qte"]);
											
										}				
										
									}else{
										echo "<h3 style='text-align:center;color:red;'>Merci de choisir une catégorie famille / Famille / Sous-famille / Article(s)</h3>";
									}

									
									
									?>
									
                                    </tbody>
                                </table>
																
								
                </div>
				
				<br><br>
				
			
					
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<style>
@media print{

@page {size: landscape}
#wrapper {    margin-left: 0px;}
#page-wrapper{
	padding : 0px;
}
body {
	padding : 20px;
	
}
table{
	border-collapse:collapse !important;
	font-size: 7px;
	border-spacing: 2px !important;
}
h1{
	font-size: 14px;
	margin: 0;
}
table td, table th
{
    padding: 2px !important;
}
}
</style>

<?

function  get_stat_article($article,$source,$type,$annee,$unitee)
{
	global $db,$total_qte;
	
	if($type == "ACHAT"){
		$prod_table = "pm_produitsachat";
		$query_prod = "select * from ".$prod_table." where code_produit ='".$article."'";
	}elseif($type == "VENTE"){
		$prod_table = "pm_produits";
		$query_prod = "select * from ".$prod_table." where code_produit ='".$article."'";
	}else{
		$prod_table = "pm_produits";
		$query_prod = "select * from ".$prod_table." where code_produit ='".$article."'";
	}
		
	$name_prod = "" ;
	// echo $query_prod ."<br>";
	$result_prod = @$db->query($query_prod);
	
	$nb_rows_default = $db->last_row_count();
	// echo $nb_rows_default .">>>>>>>><br>";
	if($nb_rows_default>0){
	foreach($result_prod as $row_prod){
		$code_produit = $row_prod["code_produit"];
		$name_prod = $row_prod["desingnation"];
		$coulissage = $row_prod["coulissage"];
		$unite = $row_prod["unite"];
	}
	}else{
		$query_prod = "select * from pm_produitsachat where code_produit ='".$article."'";
		$result_prod = @$db->query($query_prod);
		foreach($result_prod as $row_prod){
		 $code_produit = $row_prod["code_produit"];
		 $name_prod = $row_prod["desingnation"];
		 $coulissage = $row_prod["coulissage"];
		 $unite = $row_prod["unite"];
	    }
	}
	$unite = get_unite($unite);
	echo "<tr><td colspan='14' align='center' style='background-color: #dadada;color:#000'><b>$code_produit - $name_prod - Colisage: $coulissage - unité: $unite</b></td>";
	// echo "<tr><td colspan='14' align='center' style='background-color: #dadada;color:#000'><b>$name_prod</b></td>";
	echo "<tr>";
	echo "<td><b>2018 / variation</b></td>";
									
									
	$mois = array(0,0,0,0,0,0,0,0,0,0,0,0,0) ;
	$coli = array(0,0,0,0,0,0,0,0,0,0,0,0,0) ;
	if($type == "ACHAT/VENTE"){
		$query = " select * from stat_article where code_produit = '".$article."' AND ".$source." AND annee = ".$annee;
	}else{		
		$query = " select * from stat_article where code_produit = '".$article."' AND ".$source." AND annee = ".$annee;
	}
	// echo $query."<br>" ;
	$result = @$db->query($query);
	if($result !== false){
		foreach($result as $row){
			$mois[$row["mois"]] += $row["qte"];
			$coli[$row["mois"]] = $row["coulissage"];
		}
	}
	
		$qte_val_trimestre = 0;
		for ($x = 1; $x <= 12; $x++) {
			// === Quantité affichée ===
			if($unitee == "unitaire"){
				$qte_val =  $mois[$x];
				$qte_val_trimestre += $qte_val;
				$qte_val =  number_format($qte_val, 0, '.', ' ') ;	
				// $qte_val_trimestre =  number_format($qte_val_trimestre, 0, '.', ' ');
			}else{
				if($mois[$x]){
					$qte_val = $mois[$x] / $coli[$x] ;
				}else{
					$qte_val = 0;
				}
				$qte_val_trimestre += $qte_val;
				$qte_val =  number_format($qte_val, 0, '.', ' ');		
				// $qte_val_trimestre =  number_format($qte_val_trimestre, 0, '.', ' ');
			}
			
			//====== listage =====
			if ($_GET["listage"] == "mensuel"){	
				echo "<td align='center'><b>$qte_val</b></td>";
			}elseif ($_GET["listage"] == "trimestriel"){
				if($x == 3){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 6){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 9){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 12){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}
				
			}else{
				if($x == 12){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
				}
			}
			//================	
		}

	
	if($unitee == "unitaire"){
		$all_qte = number_format(array_sum($mois), 0, '.', ' ');
	}else{
		$all_qte = array_sum($mois);
		if($all_qte){
			$all_qte = $all_qte / $row["coulissage"];
		}else{
			$all_qte = 0;
		}
		$all_qte = number_format($all_qte, 0, '.', ' ');
		$total_qte += $all_qte;
	}	
	echo "<td align='center'><b style='color:blue;'>".$all_qte."</b></td>";
	echo "</tr>";		
}


function  get_stat_sous_famille($famille,$source,$type,$annee,$unitee)
{
	global $db,$total_qte;
	
	if($type == "ACHAT"){
		$prod_table = "pm_produitsachat";
	
	}elseif($type == "VENTE"){
		$prod_table = "pm_produits";
	}else{
		$prod_table = "pm_produitsachat,pm_produits";
	}

	$query_prod = "select * from pm_famille where id =".$famille;
	// echo $query_prod ."<br>";
	$result_prod = @$db->query($query_prod);
	foreach($result_prod as $row_prod){

		$name_famille = $row_prod["nom"];

	}	
	
	echo "<tr><td colspan='14' align='center' style='background-color: #dadada;color:#000'><b>$name_famille</b></td>";
	echo "<tr>";
	echo "<td><b>".$annee." / variation</b></td>";
									
									
	$mois = array(0,0,0,0,0,0,0,0,0,0,0,0,0) ;
	
	if($type == "ACHAT/VENTE"){
		$query = " select * from stat_article where sous_famille = ".$famille." AND ".$source." AND annee = ".$annee;
	}else{	
		$query = " select * from stat_article where sous_famille = ".$famille." AND ".$source." AND type_product = '".$type."' AND annee = ".$annee;
	}
	// echo $query."<br>" ;
	$result = @$db->query($query);
	if($result !== false){
		foreach($result as $row){
			$mois[$row["mois"]] += $row["qte"] / $row["coulissage"];
			
		}
	}
	
										
		$qte_val_trimestre = 0;
		for ($x = 1; $x <= 12; $x++) {
			// === Quantité affichée ===
			if($unitee == "unitaire"){
				$qte_val =  $mois[$x];
				$qte_val_trimestre += $qte_val;
				$qte_val =  number_format($qte_val, 0, '.', ' ') ;	
				// $qte_val_trimestre =  number_format($qte_val_trimestre, 0, '.', ' ');
			}else{
				if($mois[$x]){
					$qte_val = $mois[$x] ;
				}else{
					$qte_val = 0;
				}
				$qte_val_trimestre += $qte_val;
				$qte_val =  number_format($qte_val, 0, '.', ' ');		
				// $qte_val_trimestre =  number_format($qte_val_trimestre, 0, '.', ' ');
			}
			
			//====== listage =====
			if ($_GET["listage"] == "mensuel"){	
				echo "<td align='center'><b>$qte_val</b></td>";
			}elseif ($_GET["listage"] == "trimestriel"){
				if($x == 3){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 6){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 9){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 12){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}
				
			}else{
				if($x == 12){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
				}
			}
			//================	
		}
	if($unitee == "unitaire"){
		$all_qte = number_format(array_sum($mois), 0, '.', ' ');
	}else{
		$all_qte = array_sum($mois);
		if($all_qte){
			$all_qte = $all_qte / $row["coulissage"];
		}
		$all_qte = number_format($all_qte, 0, '.', ' ');
		$total_qte += $all_qte;
	}
	echo "<td align='center'><b style='color:blue;'>".$all_qte."</b></td>";
	echo "</tr>";		
}

function  get_stat_famille($famille,$source,$type,$annee,$unitee)
{
	global $db,$total_qte;
	
	if($type == "ACHAT"){
		$prod_table = "pm_produitsachat";
	
	}elseif($type == "VENTE"){
		$prod_table = "pm_produits";
	}else{
		$prod_table = "pm_produitsachat,pm_produits";
	}


	
	// echo "<tr><td colspan='14' align='center' style='background-color: #dadada;color:#000'><b>$name_famille</b></td>";
	echo "<tr>";
	echo "<td><b>2018 / variation</b></td>";
									
									
	$mois = array(0,0,0,0,0,0,0,0,0,0,0,0,0) ;
		

	if($type == "ACHAT/VENTE"){
		$query = " select * from stat_article where famille = ".$famille." AND ".$source." AND annee = ".$annee;
	}else{		
		$query = " select * from stat_article where famille = ".$famille." AND ".$source." AND type_product = '".$type."' AND annee = ".$annee;
	}
	// echo $query."<br>" ;
	$result = @$db->query($query);
	if($result !== false){
		foreach($result as $row){
			$mois[$row["mois"]] += $row["qte"] / $row["coulissage"];
		}
	}
										
		$qte_val_trimestre = 0;
		for ($x = 1; $x <= 12; $x++) {
			// === Quantité affichée ===
			if($unitee == "unitaire"){
				$qte_val =  $mois[$x];
				$qte_val_trimestre += $qte_val;
				$qte_val =  number_format($qte_val, 0, '.', ' ') ;	
				// $qte_val_trimestre =  number_format($qte_val_trimestre, 0, '.', ' ');
			}else{
				if($mois[$x]){
					$qte_val = $mois[$x] ;
				}else{
					$qte_val = 0;
				}
				$qte_val_trimestre += $qte_val;
				$qte_val =  number_format($qte_val, 0, '.', ' ');		
				// $qte_val_trimestre =  number_format($qte_val_trimestre, 0, '.', ' ');
			}
			
			//====== listage =====
			if ($_GET["listage"] == "mensuel"){	
				echo "<td align='center'><b>$qte_val</b></td>";
			}elseif ($_GET["listage"] == "trimestriel"){
				if($x == 3){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 6){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 9){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}elseif($x == 12){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
					$qte_val_trimestre = 0;
				}
				
			}else{
				if($x == 12){
					echo "<td align='center'><b>".number_format($qte_val_trimestre, 0, '.', ' ')."</b></td>";
				}
			}
			//================	
		}
	if($unitee == "unitaire"){
		$all_qte = number_format(array_sum($mois), 0, '.', ' ');
	}else{
		$all_qte = array_sum($mois);
		if($all_qte){
			$all_qte = $all_qte / $row["coulissage"];
		}
		$all_qte = number_format($all_qte, 0, '.', ' ');
		
		$total_qte += $all_qte;
	}
	echo "<td align='center'><b style='color:blue;'>".$all_qte."</b></td>";
	echo "</tr>";		
}

?>


<?php
$_SESSION['msg_error'] = "";
$_SESSION['msg_success'] = "";
$_SESSION['msg_notice'] = ""; ?>
