<?php
date_default_timezone_set('America/Lima');
session_start();

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

$fec1="01-$m-$y";
$fec2="$d-$m-$y";


require_once("../formatos/formato.php");

?>


<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-12">
		    <div class="card">
		        <div class="card-header">
					<div id="filtroregistros">
			
						<form name="for_fil_com" id="for_fil_com" target="_blank" >
							
							<div class="row">		
							
							<div class="col-lg-2 col-sm-3 col-6">
													<label for="cmb_fil_per_mes">Mes:</label>
												
													<select name="cmb_fil_per_mes" id="cmb_fil_per_mes" class="form-control">
													<option value="">----</option>
												
														<option value="01" >Enero</option>
													    <option value="02" >Febrero</option>
														<option value="03" >Marzo</option>
														<option value="04" >Abril</option>
													    <option value="05" >Mayo</option>
														<option value="06" >Junio</option>
														<option value="07" >Julio</option>
													    <option value="08" >Agosto</option>
														<option value="09" >Septiembre</option>
														<option value="10" >Octubre</option>
													    <option value="11" >Noviembre</option>
														<option value="12" >Diciembre</option>
																
													</select>
																									
							</div>
												
												
						<div class="col-lg-2 col-sm-3 col-6">
								<label for="cmb_fil_per_anio">Año:</label>
												
								<select name="cmb_fil_per_anio" id="cmb_fil_per_anio" class="form-control">
									<option value="">----</option>
										<?php  
										for($i=2017;$i<= $y ;$i++){				
										?>
									<option value="<?php echo $i;?>"  <?php if($i==$y) echo ''; ?> ><?php echo $i;?></option>
										<?php
										}
										?>
								</select>
												
						</div>					
								
						<div class=" col-lg-2 col-sm-3 col-6 ">
						  <label>Desde:</label>

						  <div class="input-group">
							<div class="input-group-prepend">
							  <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
							</div>
							<input name="txt_fil_com_fec1" type="text" id="txt_fil_com_fec1"  class="form-control" >
						  </div>
						</div>
						
						<div class=" col-lg-2 col-sm-3 col-6 ">
						  <label>Hasta:</label>

						  <div class="input-group">
							<div class="input-group-prepend">
							  <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
							</div>
							<input name="txt_fil_com_fec2" type="text" id="txt_fil_com_fec2"  class="form-control" >
						  </div>
						</div>
						
						<div class="col-lg-3 col-sm-3 col-6">
								<label for="txt_fil_numdoc">Numero Doc.:</label>
								<input type="text" id="txt_fil_numdoc" name="txt_fil_numdoc" autocomplete="off" class="form-control"  /> 
						</div>
									
							<div class="col-lg-5 col-sm-3 col-6">
								<input type="hidden" id="hdd_fil_pro_id" name="hdd_fil_pro_id" />
								<label for="txt_fil_pro">Proveedor:</label>
								<input type="text" id="txt_fil_pro" name="txt_fil_pro" class="form-control"  /> 
							</div>
							
							<div class="col-lg-2  col-sm-3 col-6">
								<label for="cmb_fil_empresa_id">Empresa:</label>
								<select name="cmb_fil_empresa_id" id="cmb_fil_empresa_id" class="form-control"></select>
							</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="cmb_fil_mon_id">Moneda:</label>
								<select name="cmb_fil_mon_id" id="cmb_fil_mon_id" class="form-control">
								</select>    
							</div>
							
							<div class="col-lg-2  col-sm-3 col-6">
								<label for="cmb_fil_tipdoc_id">Tipo Documento:</label>
								<select name="cmb_fil_tipdoc_id" id="cmb_fil_tipdoc_id" class="form-control">
								<option value="">----</option>
								<option value="1">FACTURA</option>
								<option value="2">NOTA DE CREDITO</option>
								<option value="3">NOTA DE DEBITO</option>
								<option value="9">OTRO</option>
								</select>
							</div>
						    
						<div class="col-lg-3 col-sm-3 col-6">
								<label for="cmb_campo_order">Ordenar datos por:</label>
								<select name="cmb_campo_order" id="cmb_campo_order" class="form-control">
								<option value="d.tb_documento_id">TIPO DOCUMENTO</option>
								<option value="tb_compra_numdoc">NUMERO DOCUMENTO</option>
								<option value="tb_compra_fec">FECHA</option>
								<option value="tb_proveedor_doc">RUC</option>
								<option value="tb_proveedor_nom">PROVEEDOR</option>
								<option value="tb_empresa_razsoc">EMPRESA</option>
								<option value="tb_compra_tot">TOTAL</option>
								</select>    
						</div>
						
						<div class="col-lg-3 col-sm-3 col-6">
								<label for="cmb_opc_order">De forma:</label>
								<select name="cmb_opc_order" id="cmb_opc_order" class="form-control">
								<option value="asc">ASCENDENTE</option>
								<option value="desc">DESCENDENTE</option>
								
								</select>    
						</div>
							
							<div style="display: inline-block; white-space: nowrap;padding-top:30px;" class="col-lg-2 col-sm-3 col-6">		
								<span style="cursor:pointer" onClick="compra_tabla()" id="btn_filtrar" class="btn btn-primary"><i class="fas fa-search"></i></span>
								<span style="cursor:pointer" onClick="compra_filtro()" id="btn_resfil"  class="btn btn-default ">Restablecer</span>
							</div> 
							
							</div>   
						</form>	
						
					</div>
					
					<div  style="display:none;" id="filtrograficos">
					
						<form name="for_fil_comgra" id="for_fil_comgra" target="_blank" action="" method="post">
							<div class="row">	
							
							<div class="col-lg-2 col-sm-3 col-6" style="display:none">
													<label for="cmb_fil_per_mesgra">Mes:</label>
												
													<select name="cmb_fil_per_mesgra" id="cmb_fil_per_mesgra" class="form-control">
													<option value="">----</option>
												
														<option value="01" >Enero</option>
													    <option value="02" >Febrero</option>
														<option value="03" >Marzo</option>
														<option value="04" >Abril</option>
													    <option value="05" >Mayo</option>
														<option value="06" >Junio</option>
														<option value="07" >Julio</option>
													    <option value="08" >Agosto</option>
														<option value="09" >Septiembre</option>
														<option value="10" >Octubre</option>
													    <option value="11" >Noviembre</option>
														<option value="12" >Diciembre</option>
																
													</select>
																									
							</div>
												
												
							<div class="col-lg-2 col-sm-3 col-6" style="display:none">
													<label for="cmb_fil_per_aniogra">Año:</label>
												
													<select name="cmb_fil_per_aniogra" id="cmb_fil_per_aniogra" class="form-control">
													<option value="">----</option>
													<?php  
													for($i=2017;$i<= $y ;$i++){
														
														?>
														<option value="<?php echo $i;?>"  <?php if($i==$y) echo ''; ?> ><?php echo $i;?></option>
														<?php
													}
													?>
													</select>
												
							</div>					
								
				<div class=" col-lg-2 col-sm-3 col-6 form-group">
                  <label>Desde:</label>

                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input name="txt_fil_com_fec1gra" type="text" id="txt_fil_com_fec1gra" value="<?php echo $fec1 ?>"  class="form-control" >
                  </div>
                </div>
				
				
				
				<div class=" col-lg-2 col-sm-3 col-6 form-group">
                  <label>Hasta:</label>

                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input name="txt_fil_com_fec2gra" type="text" id="txt_fil_com_fec2gra" value="<?php echo $fec2 ?>"  class="form-control" >
                  </div>
                </div>
									
							<div class="col-lg-4 col-sm-3 col-6">
								<input type="hidden" id="hdd_fil_pro_idgra" name="hdd_fil_pro_idgra" />
								<label for="txt_fil_progra">Proveedor:</label>
								<input type="text" id="txt_fil_progra" name="txt_fil_progra" class="form-control"  /> 
							</div>
							
							<div class="col-lg-2 col-sm-3  col-sm-3 col-6">
								<label for="cmb_fil_empresa_idgra">Empresa:</label>
								<select name="cmb_fil_empresa_idgra" id="cmb_fil_empresa_idgra" class="form-control"></select>
							</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="cmb_fil_mon_idgra">Moneda:</label>
								<select name="cmb_fil_mon_idgra" id="cmb_fil_mon_idgra" class="form-control">
								<option selected value="1">SOLES</option>
								<option value="2">DOLARES AMERICANOS</option>
								</select>    
							</div>
							
							<div class="col-lg-2  col-sm-3 col-6">
								<label for="cmb_fil_tipdoc_idgra">Tipo Documento:</label>
								<select name="cmb_fil_tipdoc_idgra" id="cmb_fil_tipdoc_idgra" class="form-control">
								<option value="">----</option>
								<option value="1">FACTURA</option>
								<option value="2">NOTA DE CREDITO</option>
								<option value="3">NOTA DE DEBITO</option>
								<option value="9">OTRO</option>
								</select>
							</div>
						    
							<div style="display: inline-block; white-space: nowrap;padding-top:30px;" class="col-lg-2 col-sm-3 col-6">		
								<span style="cursor:pointer" onClick="compra_grafica()" id="btn_filtrar" class="btn btn-primary"><i class="fas fa-search"></i></span>
								<span style="cursor:pointer" onClick="compra_filtro()" id="btn_resfil"  class="btn btn-default ">Restablecer</span>
							</div> 
							
							</div>   
						</form>	
					
					
					</div>
				
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script type="text/javascript">

	cmb_empresa_id('');
	cmb_empresa_idgra('');

	 function cmb_empresa_id(empid){
	
	  	$.ajax({
			type: "POST",
			url: "../empresa/cmb_emp_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				emp_id:empid
			}),
			beforeSend: function() {
				$('#cmb_fil_empresa_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){	
			
				$('#cmb_fil_empresa_id').html(html);
				//alert($('#cmb_empresa_id').val());
				cmb_punven_id($('#cmb_fil_empresa_id').val());
				
			}
		});		
  
  }
  
	 function cmb_empresa_idgra(empid){
	
	  	$.ajax({
			type: "POST",
			url: "../empresa/cmb_emp_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				emp_id:empid
			}),
			beforeSend: function() {
				$('#cmb_fil_empresa_idgra').html('<option value="">Cargando...</option>');
			},
			success: function(html){	
			
				$('#cmb_fil_empresa_idgra').html(html);
				//alert($('#cmb_empresa_id').val());
				
				
			}
		});		
  
  }

 function cmb_punven_id(empid){
	
	if(empid==""){
		$('#cmb_fil_punven_id').html('<option value="">-- Seleccione Empresa --</option>');
		cmb_piso_id($('#cmb_fil_punven_id').val());
	}else
	{	
	  	$.ajax({
			type: "POST",
			url: "../puntoventa/cmb_punven_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				emp_id:empid
			}),
			beforeSend: function(){
				$('#cmb_fil_punven_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){		
				$('#cmb_fil_punven_id').html(html);
				cmb_piso_id($('#cmb_fil_punven_id').val());
			}
		});		
	} 
  }

   function cmb_piso_id(punven_id){
	
		if(punven_id==""){
			$('#cmb_fil_piso_id').html('<option value="">Usuario no encontrado.</option>');
		}else{	
	  	$.ajax({
			type: "POST",
			url: "../piso/cmb_pisopunven_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				punven_id:punven_id
			}),
			beforeSend: function(){
				$('#cmb_fil_piso_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){		
				$('#cmb_fil_piso_id').html(html);
				
			},
			complete: function(){
			compra_tabla();
			
		}
		});		
		}
  }


	function cmb_fil_mon_id(moneid)
	{	
		$.ajax({
			type: "POST",
			url: "../moneda/cmb_mon_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mon_id: moneid
			}),
			beforeSend: function(){
				$('#cmb_fil_mon_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_fil_mon_id').html(html);
			}
		});
	}
	



	
	$(function(){

		$('#cmb_fil_empresa_id').change(function(){
		//cmb_punven_id($('#cmb_fil_empresa_id').val());
		});
		
		$('#cmb_fil_punven_id').change(function(){
		//cmb_piso_id($('#cmb_fil_punven_id').val());
		});
		
		$('#cmb_fil_tipdoc_id,#cmb_campo_order,#cmb_opc_order,#txt_fil_numdoc').change(function(){
		compra_tabla();
		});
		
		$('#cmb_fil_tipdoc_idgra').change(function(){
		compra_grafica();
		});
		
		
		cmb_fil_mon_id('');
		
		
		$('#txt_fil_com_fec1, #txt_fil_com_fec2, #txt_fil_com_fec1gra ,#txt_fil_com_fec1gra').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			//compra_tabla();
		}); 

		$("#txt_fil_pro").keyup(function(e){
			
				if($("#txt_fil_pro").val()==""){
					$("#hdd_fil_pro_id").val('');
				}	
		});
		
		$("#txt_fil_progra").keyup(function(e){
			
				if($("#txt_fil_progra").val()==""){
					$("#hdd_fil_pro_idgra").val('');
				}	
		});
		
		$("#txt_fil_pro").keydown(function(e){
			if (e.which == 13){
				
			if($("#txt_fil_pro").val()==""){
			 compra_tabla();
			}
			
			return false;
			}
		});
		
		$("#txt_fil_progra").keydown(function(e){
			if (e.which == 13){
				
			if($("#txt_fil_progra").val()==""){
			 compra_grafica();
			}
			
			return false;
			}
		});

		$( "#txt_fil_pro" ).autocomplete({
			minLength: 1,
			source: "../proveedor/proveedor_complete_nom.php",
			select: function(event, ui){
				$("#hdd_fil_pro_id").val(ui.item.id);	
				//compra_tabla();													
			}
		});
		
	$( "#txt_fil_progra" ).autocomplete({
			minLength: 1,
			source: "../proveedor/proveedor_complete_nom.php",
			select: function(event, ui){
				$("#hdd_fil_pro_idgra").val(ui.item.id);	
				//compra_tabla();													
			}
		});

		//compra_tabla();
		$("#cmb_fil_mon_id").change(function(){
			compra_tabla();
		});
		
		$("#cmb_fil_mon_idgra").change(function(){
			compra_grafica();
		});
		
	
		
	});	
</script> 