<?php
session_start();

date_default_timezone_set('America/Lima');
	$y=date('Y');
	$m=date('m');
	$d=date('d');

	$fec="$d-$m-$y";
?>
<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 id="for_fil_ordcom" action="POST">
			    <input type="hidden" id="hdd_fil_cli_id" name="hdd_fil_cli_id" />
	          
			  
			  <div class="row">
			  
			  <div class=" col-lg-2 col-sm-3 col-6 ">
						  <label>Fecha 1:</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_ordcom_fec1" type="text" id="txt_fil_ordcom_fec1" value="<?php echo $fec?>" class="form-control" >
						  </div>
			</div>  
			
			<div class=" col-lg-2 col-sm-3 col-6 ">
						  <label>Fecha 2:</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_ordcom_fec2" type="text" id="txt_fil_ordcom_fec2" value="<?php echo $fec?>" class="form-control" >
						  </div>
			</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>Serie/Numero:</label>
				<input type="text" id="txt_fil_docnum" name="txt_fil_docnum" class="form-control" /> 
			</div>
				
				<div class="col-lg-2 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" style="padding-top:30px;" >
				    <span  onClick="ordencompra_tabla()" class="btn btn-primary"><i class="fas fa-search"></i></span>
					<span  onClick="ordencompra_filtro()" class="btn btn-default">Restablecer</span>
				</div>
				
				</div>
				
				</form>
           
		   </div>
        </div>
      </div>
    </div>
  </div>
  </div>
</section> 

<script type="text/javascript">


	cmb_empresa_id('');

	 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);
							
			}
		});		
  
  }


		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);
				ordencompra_tabla();
			}
		});
	}
	
cmb_fil_mon_id('');

	$('#txt_fil_ordcom_fec1, #txt_fil_ordcom_fec2').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			
		}); 
	
	$('#txt_fil_docnum, #cmb_fil_mon_id, #cmb_fil_ordcom_est').change(function(){
		ordencompra_tabla();
	}); 
	
	
$("#txt_fil_pro").keyup(function(e){
			
				if($("#txt_fil_pro").val()==""){
					$("#hdd_fil_pro_id").val('');
				}	
		});
		
		$("#txt_fil_pro").keydown(function(e){
			if (e.which == 13){
				
			if($("#txt_fil_pro").val()==""){
			 compra_tabla();
			}
			
			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();													
			}
		});

ordencompra_tabla();	
</script>