<?php
//ini_set('display_error',1);
date_default_timezone_set('America/Lima');
session_start();
if($_SESSION["sistema"]!= "1"){ header("location: ../login/index.php"); exit();}


require_once ("../../config/Cado.php");
require_once ("../formatos/formato.php");
require_once ("../formatos/fechas.php");
require_once ("../grafica/cGrafica.php");
$oGrafica = new cGrafica();


$y=date('Y');
$m=date('m');
$d=date('d');

if($_SESSION['usuariogrupo_id']==1 || $_SESSION['usuariogrupo_id']==2){
		
	}
	else{
 	$punven_id = $_SESSION['puntoventa_id'];
 	}
	
	


?>
<style type="text/css">
select{
	cursor:pointer;
}

</style>


  
  
  
<div class="col-lg-12 col-md-12 col-sm-12 col-12 ml-1" >

	
	<div class="col-sm-6">
		<h5 class="m-2">Escritorio
		<small>Panel de Graficas</small>
		<?php echo ' | '.fechaActual(1); ?></h5>
	</div> 


<div class="row">
	
	<div class="col-lg-12 col-sm-12 col-12 ">

	<div class="row ml-1">
							
			<div class="col-lg-4 col-sm-4 col-6">
					<label for="cmb_fil_valo_mes">Mes:</label>
					<select name="cmb_fil_valo_mes" id="cmb_fil_valo_mes" class="form-control">
					<option value="">-- Seleccionar --</option>
					<option value="01" <?php if($m=='01') echo 'selected'; ?> >Enero</option>
					<option value="02" <?php if($m=='02') echo 'selected'; ?> >Febrero</option>
					<option value="03" <?php if($m=='03') echo 'selected'; ?> >Marzo</option>
					<option value="04" <?php if($m=='04') echo 'selected'; ?> >Abril</option>
					<option value="05" <?php if($m=='05') echo 'selected'; ?> >Mayo</option>
					<option value="06" <?php if($m=='06') echo 'selected'; ?> >Junio</option>
					<option value="07" <?php if($m=='07') echo 'selected'; ?> >Julio</option>
					<option value="08" <?php if($m=='08') echo 'selected'; ?> >Agosto</option>
					<option value="09" <?php if($m=='09') echo 'selected'; ?> >Septiembre</option>
					<option value="10" <?php if($m=='10') echo 'selected'; ?> >Octubre</option>
					<option value="11" <?php if($m=='11') echo 'selected'; ?> >Noviembre</option>
					<option value="12" <?php if($m=='12') echo 'selected'; ?> >Diciembre</option>																							
					</select>
			</div>
												
												
			<div class="col-lg-4 col-sm-4 col-6">
				<label for="cmb_fil_valo_anio">Año:</label>
																
				<select name="cmb_fil_valo_anio" id="cmb_fil_valo_anio" class="form-control">
				<?php  
				for($i=2017;$i<= $y ;$i++){				
				?>
				<option value="<?php echo $i;?>"  <?php if($i==$y) echo 'selected'; ?> ><?php echo $i;?></option>
				<?php
				}
				?>
				</select>
			</div>
			
			<div class="col-lg-4 col-sm-4 col-6">
				<label for="cmb_fil_valo_punven">Punto Venta:</label>
																
				<select name="cmb_fil_valo_punven" id="cmb_fil_valo_punven" class="form-control"></select>
			</div>
			
			
			
		</div>
	
	<div id="container_valorizado" ></div>
	</div>

	<div class="col-lg-6 col-sm-6 col-12 ">
	
	<div class="col-lg-12 col-sm-12 col-12">
			<label for="cmb_fil_anio">Año:</label>									
			<select name="cmb_fil_anio" id="cmb_fil_anio" class="form-control">
			<?php  
			for($i=2017;$i<= $y ;$i++){				
			?>
			<option value="<?php echo $i;?>"  <?php if($i==$y) echo 'selected'; ?> ><?php echo $i;?></option>
			<?php
			}
			?>
		</select>										
	</div>
	
	<div id="container_ventascompras" ></div>
	
		</div>
	
	</div>
	
	<div class="row">
	
	<div class="col-lg-6 col-sm-6 col-12 ">
	
	
	<div class="col-sm-6">
		<h4 class="m-2">
			<small>DIFERENCIAS IGV</small>
		</h4>
	</div>
	
	
	<div class="col-lg-3 col-sm-3 col-6">
			<label for="cmb_fil_cvd_anio">Año:</label>									
			<select name="cmb_fil_cvd_anio" id="cmb_fil_cvd_anio" class="form-control">
			<?php  
			for($i=2017;$i<= $y ;$i++){				
			?>
			<option value="<?php echo $i;?>"  <?php if($i==$y) echo 'selected'; ?> ><?php echo $i;?></option>
			<?php
			}
			?>
		</select>										
	</div>
	
	<div class="col-lg-12 col-sm-12 col-12" style="height:5px;"> </div>
	
	<div id="container_ventascomprasdiferencias" ></div>
	
	</div>


	<div class="col-lg-6 col-sm-6 col-12">
	
	<div class="col-sm-12 col-lg-12">
		<h4 class="m-2">
			<small>TOP
			<select name="cmb_fil_prosto_topval" id="cmb_fil_prosto_topval" style="form-control-sm" >
			<option value="5"  selected >5</option>
			<option value="10"   >10</option>
			<option value="15"   >15</option>
			<option value="20"   >20</option>
			<option value="25"   >25</option>
			</select>
			PRODUCTOS CON MENOS STOCK</small>
		</h4>
	</div>
	
	<div class="row">
	
		<div class="col-lg-4 col-sm-3 col-6">
				<label for="cmb_fil_procat">Categoria:</label>									
				<select name="cmb_fil_procat" id="cmb_fil_procat" class="form-control"></select>										
		</div>
	
		<div class="col-lg-4 col-sm-3 col-6">
			<label for="cmb_fil_promar">Marca:</label>									
			<select name="cmb_fil_promar" id="cmb_fil_promar" class="form-control"></select>										
		</div>
	</div>
	
	<div class="col-lg-12 col-sm-12 col-12" style="height:5px;"> </div>
	
	<div id="container_productostock" ></div>
	
	</div>
	
	</div>




	<div class="col-sm-6">
		<h4 class="m-2">
			<small>TOP 
			<select name="cmb_fil_toppro_val" id="cmb_fil_toppro_val" style="form-control-sm" >
			<option value="5"  selected >5</option>
			<option value="10"   >10</option>
			<option value="15"   >15</option>
			<option value="20"   >20</option>
			<option value="25"   >25</option>
			</select>
			
			PRODUCTOS</small>
		</h4>
	</div>
	

	<div class="row ml-1">
							
			<div class="col-lg-2 col-sm-3 col-6">
					<label for="cmb_fil_toppro_mes">Mes:</label>
					<select name="cmb_fil_toppro_mes" id="cmb_fil_toppro_mes" class="form-control">
					<option value="">-- Seleccionar --</option>
					<option value="01" <?php if($m=='01') echo 'selected'; ?> >Enero</option>
					<option value="02" <?php if($m=='02') echo 'selected'; ?> >Febrero</option>
					<option value="03" <?php if($m=='03') echo 'selected'; ?> >Marzo</option>
					<option value="04" <?php if($m=='04') echo 'selected'; ?> >Abril</option>
					<option value="05" <?php if($m=='05') echo 'selected'; ?> >Mayo</option>
					<option value="06" <?php if($m=='06') echo 'selected'; ?> >Junio</option>
					<option value="07" <?php if($m=='07') echo 'selected'; ?> >Julio</option>
					<option value="08" <?php if($m=='08') echo 'selected'; ?> >Agosto</option>
					<option value="09" <?php if($m=='09') echo 'selected'; ?> >Septiembre</option>
					<option value="10" <?php if($m=='10') echo 'selected'; ?> >Octubre</option>
					<option value="11" <?php if($m=='11') echo 'selected'; ?> >Noviembre</option>
					<option value="12" <?php if($m=='12') echo 'selected'; ?> >Diciembre</option>																							
					</select>
			</div>
												
												
			<div class="col-lg-2 col-sm-3 col-6">
				<label for="cmb_fil_toppro_anio">Año:</label>
																
				<select name="cmb_fil_toppro_anio" id="cmb_fil_toppro_anio" class="form-control">
				<?php  
				for($i=2017;$i<= $y ;$i++){				
				?>
				<option value="<?php echo $i;?>"  <?php if($i==$y) echo 'selected'; ?> ><?php echo $i;?></option>
				<?php
				}
				?>
				</select>
			</div>
			
		</div>
		
	<div class="col-lg-12 col-sm-12 col-12" style="height:5px;"> </div>
	
	<div id="container_topproductos" ></div>
	
	


</div>





<script type="text/javascript">




function cmb_fil_puntoventa_id(punven){
		$.ajax({
 					type: "POST",
 					url: "../puntoventa/cmb_punven_id.php",
 					async:true,
 					dataType: "html",                      
 					data: ({						
 						emp_id:'',
						punven_id :punven,
 						vista:	''
 					}),
 					beforeSend: function() {
 						$('#cmb_fil_valo_punven').html('<option value="">Cargando...</option>');
 					},
 					success: function(html){			
 						$('#cmb_fil_valo_punven').html(html);
 					},
 					complete: function(){
 						
 						}
 					});
}



		function cargar_ventascomprasdiferencias(){
		
			/* $('#div_mensaje_dialog').modal('show');
			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
				
			$('.div_mensaje').html(div); */
				
			$.ajax({
				type: "POST",
				url: "../grafica/grafica_ventacompradiferencia.php",
				async:true,
				dataType: "html",                      
				data: ({
					anio : $("#cmb_fil_cvd_anio").val()
				}),
				beforeSend: function() {
					//var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
					//$('#contenedor_base_venta').html(div);
				},
				success: function(html){
					$('#container_ventascomprasdiferencias').html(html);				
				}
			});
		}
			
			
		function cargar_ventascompras(){
		
			/* $('#div_mensaje_dialog').modal('show');
			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
				
			$('.div_mensaje').html(div); */
				
			$.ajax({
				type: "POST",
				url: "../grafica/grafica_ventacompra.php",
				async:true,
				dataType: "html",                      
				data: ({
					anio : $("#cmb_fil_anio").val()
				}),
				beforeSend: function() {
					//var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
					//$('#contenedor_base_venta').html(div);
				},
				success: function(html){
					$('#container_ventascompras').html(html);				
				}
			});
		}
		
		function cargar_topproductos(){
		
			/* $('#div_mensaje_dialog').modal('show');
			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
				
			$('.div_mensaje').html(div); */
				
			$.ajax({
				type: "POST",
				url: "../grafica/grafica_topproductos.php",
				async:true,
				dataType: "html",                      
				data: ({
					top : $("#cmb_fil_toppro_val").val(),
					mes : $("#cmb_fil_toppro_mes").val(),
					anio : $("#cmb_fil_toppro_anio").val()
				}),
				beforeSend: function() {
					//var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
					//$('#contenedor_base_venta').html(div);
				},
				success: function(html){
					$('#container_topproductos').html(html);				
				}
			});
		}
		
		function cargar_productostock(){
		
			
			$.ajax({
				type: "POST",
				url: "../grafica/grafica_productostock.php",
				async:true,
				dataType: "html",                      
				data: ({
					top : $("#cmb_fil_prosto_topval").val(),
					cat_id : $("#cmb_fil_procat").val(),
					mar_id : $("#cmb_fil_promar").val()
				}),
				beforeSend: function() {
					
				},
				success: function(html){
					$('#container_productostock').html(html);				
				}
			});
		}


		function cargar_valorizado(){
		
			
			$.ajax({
				type: "POST",
				url: "../grafica/grafica_valorizado.php",
				async:true,
				dataType: "html",                      
				data: ({
					mes : $("#cmb_fil_valo_mes").val(),
					anio : $("#cmb_fil_valo_anio").val(),
					punven_id : $("#cmb_fil_valo_punven").val()
				}),
				beforeSend: function() {
					var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
					$('#container_valorizado').html(div);		
				},
				success: function(html){
					$('#container_valorizado').html(html);				
				}
			});
		}
		

		

		
		
		function cmb_fil_cat_id(){	
			$.ajax({
				type: "POST",
				url: "../categoria/cmb_cat_id.php",
				async:true,
				dataType: "html",                      
				data: ({
				
			}),
				beforeSend: function() {
					$('#cmb_fil_procat').html('<option value="">Cargando...</option>');
				},
				success: function(html){
					$('#cmb_fil_procat').html(html);
				}
			});
		}
		
		function cmb_fil_mar_id(){	
			$.ajax({
				type: "POST",
				url: "../grafica/cmb_mar_id.php",
				async:true,
				dataType: "html",                      
				data: ({
				
			}),
				beforeSend: function() {
					$('#cmb_fil_promar').html('<option value="">Cargando...</option>');
				},
				success: function(html){
					$('#cmb_fil_promar').html(html);
				}
			});
		}
	
	

		$(function() {
			


			$('#cmb_fil_valo_mes,#cmb_fil_valo_anio,#cmb_fil_valo_punven').change(function(e) {
				cargar_valorizado();
			});


			
			
			$('#cmb_fil_prosto_topval,#cmb_fil_procat,#cmb_fil_promar').change(function(e) {
				cargar_productostock();
			});
			
			$('#cmb_fil_anio').change(function(e) {
				cargar_ventascompras();
			});
			
			$('#cmb_fil_cvd_anio').change(function(e) {
				cargar_ventascomprasdiferencias();
			});
			
			$('#cmb_fil_toppro_val,#cmb_fil_toppro_mes,#cmb_fil_toppro_anio').change(function(e) {
				cargar_topproductos();
			});
	
	
			cmb_fil_puntoventa_id('<?php echo $punven_id; ?>');

			cmb_fil_cat_id();
			cmb_fil_mar_id();
			cargar_valorizado();
			cargar_ventascompras();
			cargar_ventascomprasdiferencias();
			cargar_topproductos();
			cargar_productostock();
		}); 

</script>
