<?php

ini_set('display_errors', 1);
define("ADMIN", true);
require_once("../../../common/lib.php");
require_once("../../../common/define.php");
define("TITLE_ELEMENT", 'Statistiques articles');
if(!isset($_SESSION['user'])){
    header("Location: /admin/login.php");
    exit();
}
require_once("../../includes/fn_module.php"); ?>
<!DOCTYPE html>
<head>
    <?php include("../../includes/inc_header_common.php"); ?>

</head>

<script>
									$(document).ready(function() {
										//==========================================
											$("#synchroniser").click(function() {
												$("#synchro-msg").show();
												$("#form").hide();
												var url_get = "/admin/synchro/product.php"
														
													$.ajax({
														url: url_get,
														type: "POST",
														dataType: "JSON",
														complete: function (jsonStr) { 
															   // alert("ok");
															$("#form").show();						
															$("#synchro-msg").hide();						
														}
													});		  
											});
															
									});
								</script>

<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-random"></i> Statistiques articles</h1>
                        </div>
						<div class="col-md-6 text-right" >
						<button type="submit" class="btn btn-default mt15" id="synchroniser" data-toggle="tooltip" data-placement="bottom" title="Synchroniser" style="background-color:#0bb300;">
							<i class="fa fa-refresh"></i><span class="hidden-sm hidden-xs"> Synchroniser</span>
						</button>	
						<br><span style="font-size:12px;">Dernière synchronisation le 
						<?
						$queryo = "SELECT * from synchro where id = 1 ";
						$resulto = @$db->query($queryo);
						if($resulto !== false){
							foreach($resulto as $rowo){
								echo date('d-m-Y H:i:s',$rowo["date_synchro"]);
							}
						}	
						?>						
						</div>
                    </div>
                </div>
            </div>
            <div class="container-fluid">
                <div class="alert-container">
                    <div class="alert alert-success alert-dismissable"></div>
                    <div class="alert alert-warning alert-dismissable"></div>
                    <div class="alert alert-danger alert-dismissable"></div>
                </div>
                <div class="row" >	
<div id="synchro-msg" style="color:#2F9DF2;text-align:center;display:none;" >
<h2  >Synchronisation en cours ...</h2>
<img src="/admin/images/loding.gif" width="120"   />
</div>				
				
	<form method="GET" action="rapport.php" id="form">				

		<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Source des données &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 <select id="source" name="source" class="form-control">							 
						<option value="BF">Bon de Fabrication</option>					 
						<option value="BE">BE Achat</option>						
						<option value="BS">BS Achat</option>						
						<option value="BE_BS">BE & BS Achat</option>						
						<option value="FA">Facture d’achat</option>												
						<option value="BL_BR">BL & BR Vente</option>												
					 </select>
				  </div>
			   </div>
		 </div>
	</div> 	
	



		<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Catégorie famille(s)&nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 						
						<?php
						if($db !== false){
							$query = "SELECT * FROM `pm_category` order by nom ASC";
							$result = @$db->query($query);
                            if($result !== false){
								foreach($result as $row){
									echo '<input type="checkbox" name="cat_famille[]" value="'.$row['id'].'"> '.$row['nom'].'<br>';
								}	
							}	
							
						} ?>
					 
				  </div>
			   </div>
		 </div>
	</div> 	
	
	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Famille(s) &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 					
						<?php
						if($db !== false){
							$query = "SELECT * FROM `pm_famille_classe` order by nom ASC";
							$result = @$db->query($query);
                            if($result !== false){
								foreach($result as $row){
									echo '<input type="checkbox" name="famille[]" value="'.$row['id'].'"> '.$row['nom'].'<br>';
									
								}	
							}	
							
						} ?>
					
				  </div>
			   </div>
		 </div>
	</div> 
	
	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Sous-famille(s)&nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 					
						<?php
						if($db !== false){
							$query = "SELECT * FROM `pm_famille` order by nom ASC";
							$result = @$db->query($query);
                            if($result !== false){
								foreach($result as $row){							
									echo '<input type="checkbox" name="sous_famille[]" value="'.$row['id'].'"> '.$row['nom'].'<br>';
								}	
							}	
							
						} ?>
					
				  </div>
			   </div>
		 </div>
	</div> 	

	
		<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-2 control-label text-right">Article(s) &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-5 achat_prod"> 
				  <div class=" form-inline">
					 	<h3>ACHAT</h3>				
						<?php
						if($db !== false){
							$query = "SELECT * FROM `pm_produitsachat` order by desingnation ASC";
							$result = @$db->query($query);
                            if($result !== false){
								foreach($result as $row){
									
									echo '<input type="checkbox" name="article[]" value="'.$row['code_produit'].'"> '.$row['desingnation'].'<br>';
								}	
							}	
							
						} ?>
				</div>		
				</div>		
				<div class="col-lg-5 vente_prod"  >
				  <div class=" form-inline">
						<h3>VENTE</h3>
						<?php
						if($db !== false){
							$query = "SELECT * FROM `pm_produits` order by desingnation ASC";
							$result = @$db->query($query);
                            if($result !== false){
								foreach($result as $row){
									echo '<input type="checkbox" name="article[]" value="'.$row['id'].'"> '.$row['desingnation'].'<br>';
								}	
							}	
							
						} ?>
					
				  </div>
			   </div>
		 </div>
	</div> 


		<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Trier par &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 <select id="trier" name="trier" class="form-control">	
						<option value="sous_famille">Sous-famille</option>	
						<option value="article">Article</option>			 											
						<option value="famille">Famille</option>																					
					 </select>
				  </div>
			   </div>
		 </div>
	</div> 	
	

	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Listage &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 <select id="listage" name="listage" class="form-control">	
						<option value="mensuel">Mensuel</option>	
						<option value="trimestriel">Trimestriel</option>			 											
						<option value="annuel">Annuel</option>																					
					 </select>
				  </div>
			   </div>
		 </div>
	</div>


	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Quantité affichée &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
					 <select id="qte" name="qte" class="form-control">	
						<option value="unitaire">Unitaire</option>	
						<option value="emballée">Emballée</option>			 																															
					 </select>
				  </div>
			   </div>
		 </div>
	</div>
	
	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label text-right">Année(s) &nbsp;<span class="red">*</span></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
				  <input type="checkbox" name="annee[]" value="2018" checked="checked"> 2018<br>
				  <? for ($x = 2019; $x <= date("Y"); $x++) { ?>
					<input type="checkbox" name="annee[]" value="<? echo $x; ?>" > <? echo $x; ?><br>
				  <? } ?>	
					<!--<input type="checkbox" name="annee[]" value="All" checked="checked"> Tous<br>-->
				  </div>
			   </div>
		 </div>
	</div>	
	
	
	
	
	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label " ></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
						<button type="submit" class="btn btn-default mt15" data-toggle="tooltip" data-placement="bottom" title="Rchercher">
							<i class="fa fa-search"></i><span class="hidden-sm hidden-xs"> Rchercher</span>
						</button>
				  </div>
			   </div>
		 </div>
	</div> 


</form>	
									
                    <?php
                    if($db !== false){
                        
                    } ?>
					
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
$( document ).ready(function() {
    $("#source").change(function() {
	var val = $(this).val() ;
	// alert(val);
	  if( val == "BL_BR"){
		 $(".achat_prod").hide();
		 $(".vente_prod").show();
	  }else if( val == "BF"){
		 $(".achat_prod").show();
		 $(".vente_prod").show();
	  }else{
		 $(".achat_prod").show();
		 $(".vente_prod").hide();  
	  }
	});
});
</script>
<?php
$_SESSION['msg_error'] = "";
$_SESSION['msg_success'] = "";
$_SESSION['msg_notice'] = ""; ?>
