<?php
   
include("include/data.php");
Init_boutique();

// entete de la page

include 'menu/header.php';

// TITRE Page //
echo "<div class='titre-text'><center>Correction des Imports</div></center><HR size='2' width='500'><br>" ;


	$Nb_etiq_import = 0 ;
	$sql1 = "SELECT count(num_etiq_ligne) FROM temp_import_csv";  
	$sql1.=" WHERE `IdNumClient`='".$IdNumClient."'";
	$sql1.=" AND RsltImport ='0'";
	$sql1.=" AND RsltLot='1'";
	$sql1.=" AND RsltStock='1'";
	$req1 = mysqli_query($link, $sql1); 
	$row = mysqli_fetch_row($req1);
	$Nb_etiq_import = $row[0];
	
	$Nb_clients_import = 0 ;
	$sql1 = "SELECT COUNT(DISTINCT num_client) FROM temp_import_csv";  
	$sql1.=" WHERE `IdNumClient`='".$IdNumClient."'";
	$sql1.=" AND RsltImport ='0'";
	$sql1.=" AND RsltLot='1'";
	$sql1.=" AND RsltStock='1'";
	$req1 = mysqli_query($link, $sql1); 
	$row = mysqli_fetch_row($req1);
	$Nb_clients_import = $row[0];
echo "<center>";	
echo "<div class='t-text12'>Lecture base importation ...... <br> Nombre d'&#233;tiquettes a traiter : $Nb_etiq_import - Pour : $Nb_clients_import clients</div>"; 
echo "<br><center>";

//
echo "<form id='ImportBl' id='thing-alerts' name ='ImportBl' method='GET' action='correction_bl_temp.php'>";
echo "<input type='hidden' name='ordre' value='1'/>";
echo "<table class='t-text' width='750' border='1' cellspacing='2' cellpadding='2'>";

$sql1 = "SELECT * FROM categorie_Clients";
$sql1.= " WHERE `IdNumClient`='".$IdNumClient."'";
$sql1.= " ORDER BY `categorie_Clients`.`num_cate_clt` ASC";
$req1 = mysqli_query($link, $sql1);
while ($row = mysqli_fetch_assoc($req1)) {
	$num_cate_clt = $row["num_cate_clt"]; 
	$Nom_cate_clt = $row["categorie_clt"]; 

echo "<tr><td colspan=2>$num_cate_clt | $Nom_cate_clt</td></tr>";
echo "<tr><td>";
	$sql2 ="SELECT COUNT(DISTINCT temp_import_csv.num_client, clients_base.Code_categorie) FROM temp_import_csv";  
	$sql2.=" INNER JOIN clients_base ON temp_import_csv.num_client = clients_base.Num_Client";
	$sql2.=" WHERE temp_import_csv.IdNumClient='".$IdNumClient."'";
	$sql2.=" AND Code_categorie='".$num_cate_clt."'";
	$sql2.=" AND RsltImport ='0'";
	$sql2.=" AND RsltLot='1'";
	$sql2.=" AND RsltStock='1'";
		$req2 = mysqli_query($link, $sql2); 
		$row = mysqli_fetch_row($req2);
		$nb_enrg = $row[0];
		$nb_enrg_col = floor ($nb_enrg/2);
		$i=0;

	$sql ="SELECT DISTINCT temp_import_csv.num_client, clients_base.Nom_Client, clients_base.Code_categorie FROM temp_import_csv";  
	$sql.=" INNER JOIN clients_base ON temp_import_csv.num_client = clients_base.Num_Client";
	$sql.=" WHERE temp_import_csv.IdNumClient='".$IdNumClient."'";
	$sql.=" AND temp_import_csv.RsltImport ='0'";
	$sql.=" AND temp_import_csv.RsltLot='1'";
	$sql.=" AND temp_import_csv.RsltStock='1'";  
	$sql.=" AND Code_categorie='".$num_cate_clt."'";
	$sql.=" ORDER BY `clients_base`.`Code_categorie` ASC, `temp_import_csv`.`num_client` ASC";

	$req = mysqli_query($link, $sql); 
	while ($row = mysqli_fetch_assoc($req)) {
	$Num_Client_import = $row["num_client"];
	$Nom_ClientSel = $row["Nom_Client"];
	$Cate_ClientSel = $row["Code_categorie"];
	
	$NumClientSelect=substr($Num_Client_import, 0, 2);
  $NumClientSelect.=substr($Num_Client_import, -3);
	
	$i=$i+1;
				if (($i-1)==$nb_enrg_col) {
				echo "<td>";
				} else {
				
				}

echo "<input type='checkbox' name='CltSelBL[]' value=".$NumClientSelect."/>".$Num_Client_import." - <a href='#' onclick='javascript:Popup(\"detail_bl_temp_liste_import.php?ordre=2&num_clt=$Num_Client_import&Rsi=0&Rsl=1&Rss=1\",1000,500,\"location=0,menubar=0,scrollbars=0,statusbar=0\")'>".$Nom_ClientSel."</a><br>";
   
	
} 
echo "</td>";
}
echo "</tr>";

echo "<td colspan =2 align='center' valign='middle'>
	    <input type='submit' name='ok' id='ok' value='Valider' accesskey='11' tabindex='11'>
	    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
	    <input name='an' type='button' id='an' accesskey='12' tabindex='12' value='Retour' onClick='history.back()'>
	    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
	    <input type='submit' name='ok' id='ok' value='Tout' text='Tout Importer' accesskey='11' tabindex='11'></td>";
echo " </tr></div>";
echo "</table>";
echo "</form>";


include 'menu/footer.php';

?>
