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

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

$fec1="$d-$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-xs-12">
		    <div class="card">
		        <div class="card-header">
    		<div class="row">
			
					
						<form name="for_fil_pro" id="for_fil_pro" method="POST" >							
				<div class="col-lg-12 col-xs-12" style="height:15px;" >
				</div>
				
				<div class="col-lg-12 col-xs-12">
								<input type="hidden" id="hdd_fil_pro_id" name="hdd_fil_pro_id"/>
								<label for="txt_com_pro_nom">Proveedor:</label>
								<input name="txt_com_pro_nom" type="text" id="txt_com_pro_nom" class="form-control"> 
				</div>	
				
				
				<div class="col-lg-12 col-xs-12" style="display:none;" id="div_fil">			
				
				
						<div class="col-lg-12 col-xs-12 " id="tr_feccom">
						<div class="row" >
						<div class=" col-lg-4 col-xs-12 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_com_fec1" type="text" id="txt_com_fec1" value="<?php echo $fec1?>" class="form-control" >
							</div>
						</div>
						
						
						<div class=" col-lg-4 col-xs-12 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_com_fec2" type="text" id="txt_com_fec2" value="<?php echo $fec2?>" class="form-control" >
							</div>
						</div>
						
						<div style="display: inline-block; white-space: nowrap;padding-top:30px;" id="div_btn"  class="col-lg-4 col-sm-3 col-xs-6">		
								<span style="cursor:pointer" onClick="compraconsolidadasproveedor_cst_tabla()" id="btn_filtrar" class="btn btn-primary"><i class="fas fa-search"></i></span>
								<span style="cursor:pointer" onClick="compraconsolidadasproveedor_cst_filtro()" id="btn_resfil"  class="btn btn-default ">Restablecer</span>			
						</div>
						
						</div>
						</div>
				
				
			</div>	
	
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script type="text/javascript">

$(function(){
	
	$("#div_btn").hide();
	
	
	});
	

var ordfec='c.tb_compra_fec';
var ordemp='';
var ordpro='';

var agrufec='1';
var agruemp='';
var agrupro='';


	$( "#txt_com_pro_nom" ).autocomplete({
			minLength: 1,
			source: "../proveedor/proveedor_complete_nom.php",
			select: function(event, ui){			
				$("#hdd_fil_pro_id").val(ui.item.id);
				proid = ui.item.id;
				
				$("#txt_com_pro_doc").val(ui.item.documento);
				$("#div_fil").show(100);	
				$("#div_btn").show(100);
			}
	});
		

function compraconsolidadasproveedor_cst_tabla()
{
		
			$.ajax({
				type: "POST",
				url: "../compraconsolidadasproveedor_cst/compraconsolidadasproveedor_cst_tabla.php",
				async:true,
				dataType: "html",                      
				data: ({
					proid:proid,
					ordfec :ordfec,
					ordemp :ordemp,
					ordpro :ordpro,
					fec1 :$("#txt_com_fec1").val(),
					fec2 :$("#txt_com_fec2").val(),
					agrufec :agrufec,
					agruemp :agruemp,
					agrupro :agrupro
				}), 
				beforeSend: function() {
					
					$('#div_compra_tabla').addClass("ui-state-disabled");
				},
				success: function(html){
					$('#div_compra_tabla').html(html);
				},
				complete: function(){			
					$('#div_compra_tabla').removeClass("ui-state-disabled");
				
				}
			});     
}

	
  
		$('#txt_let_fec1,#txt_let_fec2,#txt_com_fec1,#txt_com_fec2').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			//compra_tabla();
		}); 

		
$('#chk_ordfec').on('ifChecked', function(event){
	ordfec='c.tb_compra_fec';
});

$('#chk_ordfec').on('ifUnchecked', function(event){
	ordfec='';
});


$('#chk_ordemp').on('ifChecked', function(event){
	ordemp='c.tb_empresa_id';
});

$('#chk_ordemp').on('ifUnchecked', function(event){
	ordemp='';
});

$('#chk_ordpro').on('ifChecked', function(event){
	ordpro='c.tb_proveedor_id';
});

$('#chk_ordpro').on('ifUnchecked', function(event){
	ordpro='';
});




$('#chk_agrufec').on('ifChecked', function(event){
	$('#chk_agruemp').iCheck('uncheck');
	$('#chk_agrupro').iCheck('uncheck');
	agrufec='1';
});

$('#chk_agrufec').on('ifUnchecked', function(event){
	agrufec='';
});

$('#chk_agruemp').on('ifChecked', function(event){
	$('#chk_agrufec').iCheck('uncheck');
	$('#chk_agrupro').iCheck('uncheck');
	agruemp='1';
});

$('#chk_agruemp').on('ifUnchecked', function(event){
	agruemp='';
});

$('#chk_agrupro').on('ifChecked', function(event){
	$('#chk_agrufec').iCheck('uncheck');
	$('#chk_agruemp').iCheck('uncheck');
	agrupro='1';
});

$('#chk_agrupro').on('ifUnchecked', function(event){
	agrupro='';
});




$('#chk_agrufec').change(function(){
	if($('#chk_agrufec').is(':checked'))
	{
		$('#chk_agruemp').iCheck('uncheck');
		agrufec='1';
		agruemp = '';

	}else{
		agrufec='';
	}
});



$('#chk_agruemp').change(function(){
	if($('#chk_agruemp').is(':checked'))
	{
		$('#chk_agrufec').iCheck('uncheck');
		
		agrufec='';
		agruemp = '1';
	
	}else{
		agruemp='';
	}
});



</script>   