<?php
session_start();
date_default_timezone_set('America/Lima');
$y=date('Y');
$m=date('m');
$d=date('d');
$fec1="01-$m-$y";
$fec2="$d-$m-$y";


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

?>
<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_pro" id="for_fil_pro" >
						
						<div class="row">
							
						<div class=" col-lg-2 col-sm-2 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_valven_fec1" type="text" id="txt_fil_valven_fec1" value="<?php echo $fec1; ?>" class="form-control" >
						  </div>
						</div>
						
						<div class=" col-lg-2 col-sm-2 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_valven_fec2" type="text" id="txt_fil_valven_fec2" value="<?php echo $fec2; ?>" class="form-control" >
						  </div>
						</div>
						
							<div class="col-lg-2 col-sm-2 col-6">
								<label for="txt_fil_pro_mar">Marca:</label>
								<input type="text" name="txt_fil_pro_mar" id="txt_fil_pro_mar" value="" class="form-control input-sm" > 							 	
							</div> 
						
							<div class="col-lg-3 col-sm-3 col-6">
								<label for="cmb_fil_cat_id">Categoría:</label>
								<select name="cmb_fil_cat_id" id="cmb_fil_cat_id" class="form-control  input-sm"></select>
							</div>
							
							<div class="col-lg-3 col-sm-3 col-6">
								<label for="txt_fil_pro_dat1">Busqueda:</label>
								<input name="txt_fil_pro_dat1" type="text" id="txt_fil_pro_dat1" class="form-control  input-sm">
							</div>
							
							<div class="col-lg-3 col-sm-3 col-6">
								<label for="txt_fil_pro_dat2">-</label>
								<input name="txt_fil_pro_dat2" type="text" id="txt_fil_pro_dat2" class="form-control  input-sm">
							</div>
							
							
							<div class="col-lg-2 col-sm-6 col-sm-3 col-6">				
								<label for="cmb_fil_puntoventa_id">Punto Venta:</label>
								<select name="cmb_fil_puntoventa_id" id="cmb_fil_puntoventa_id" class="form-control input-sm">
								</select>				
							</div>
							
						
							<div class="col-lg-2 col-sm-2 col-6" style="display: inline-block; white-space: nowrap;padding-top:30px;">
							<span onClick="stockvalorizadoventa_tabla()" class="btn btn-primary" ><i class="fa fa-search"></i></span>
							<span onClick="stockvalorizadoventa_filtro()" class="btn btn-default">Restablecer</span>
							</div>
					</div>
				</form>
		
						
					</div>
		</div>
	</div>
</div>
</div>
</div>
</section>
<script type="text/javascript">
function cmb_fil_cat_id()
	{	
		$.ajax({
			type: "POST",
			url: "../categoria/cmb_cat_id.php",
			async:true,
			dataType: "html",                      
			data: ({
			//cat_id: "<?php //echo $cat_id?>"
		}),
			beforeSend: function() {
				$('#cmb_fil_cat_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_fil_cat_id').html(html);
			}
		});
	}
	
	
	
 function cmb_punven_id(punvenid){
	
	  	$.ajax({
			type: "POST",
			url: "../puntoventa/cmb_punven_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				punven_id:punvenid
			}),
			beforeSend: function() {
				$('#cmb_fil_puntoventa_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){	
			
				$('#cmb_fil_puntoventa_id').html(html);
				//alert($('#cmb_empresa_id').val());
				
				
			}
		});		
  
  }
  
  
  
	function cmb_fil_alm_id()
	{	
		$.ajax({
			type: "POST",
			url: "../almacen/cmb_alm_id.php",
			async:false,
			dataType: "html",                      
			data: ({
				alm_id: '<?php echo $alm_id?>'
			}),
			beforeSend: function() {
			//$('#cmb_fil_pro_alm').html('<option value="">Cargando...</option>');
		},
		success: function(html){
			$('#cmb_fil_alm_id').html(html);
			$('#cmb_fil_alm_id').val(1);
		},
		complete: function(){
		}
	});
	}
	
	
	$(function() {
	
	$('#txt_fil_valven_fec1, #txt_fil_valven_fec2').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			
		}); 
	
	$( "#txt_fil_pro_nom" ).autocomplete({
			minLength: 1,
			source: "../producto/producto_complete_nom.php",
			select: function() {
				stockvalorizadoventa_tabla();
			}
		});
		
		$( "#txt_fil_pro_fam" ).keydown(function(e){
			if(e.which==13)
			{
				stockvalorizadoventa_tabla();
				e.preventDefault();
			}
		});
		
		$( "#txt_fil_pro_mar" ).keydown(function(e){
			if(e.which==13)
			{stockvalorizadoventa_tabla();
				e.preventDefault();
			}
		});
		$( "#txt_fil_pro_dat1" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat2" ).focus();
				//producto_tabla();
				e.preventDefault();
			}
		});
		$( "#txt_fil_pro_dat2" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat3" ).focus();
				//producto_tabla();
			e.preventDefault();
			}
		});
		$( "#txt_fil_pro_dat3" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat4" ).focus();
				//producto_tabla();
				e.preventDefault();
			}
		});
		
		$( "#txt_fil_pro_dat1" ).keydown(function(e){
			if(e.which==13)
			{
				
				stockvalorizadoventa_tabla();
				e.preventDefault();
			
			}
		});
		
			$( "#txt_fil_pro_dat2" ).keydown(function(e){
			if(e.which==13)
			{
				
				stockvalorizadoventa_tabla();
				e.preventDefault();
			
			}
		});
		
		
			$( "#txt_fil_pro_dat3" ).keydown(function(e){
			if(e.which==13)
			{
				
				stockvalorizadoventa_tabla();
				e.preventDefault();
			
			}
		});
		
		$( "#txt_fil_pro_dat4" ).keydown(function(e){
			if(e.which==13)
			{
				
				stockvalorizadoventa_tabla();
				e.preventDefault();
			
			}
		});
		
		
		
		$("#txt_fil_pro_dat4").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat4").val()==""){
					$("#txt_fil_pro_dat3").focus();
				}	
				//e.preventDefault();	
			}
		});
		
		
		$("#txt_fil_pro_dat3").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat3").val()==""){
					$("#txt_fil_pro_dat2").focus();
				}	
			//	e.preventDefault();	
			}
		});
		
		
		$("#txt_fil_pro_dat2").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat2").val()==""){
					$("#txt_fil_pro_dat1").focus();
				}	
			//	e.preventDefault();	
			}
		});
		
	
		cmb_fil_cat_id();
		cmb_punven_id(<?php echo $punven_id; ?>);
		stockvalorizadoventa_tabla();
		$("#txt_fil_pro_codbar").focus();
		$( "#txt_fil_pro_nom" ).autocomplete({
			minLength: 1,
			source: "../producto/producto_complete_nom.php",
			select: function() {
				stockvalorizadoventa_tabla();
			}
		});
		$( "#txt_fil_pro_nom" ).keydown(function(e){
			if(e.which==13)
			{
				stockvalorizadoventa_tabla();
				e.preventDefault();
			}
		});
		$( "#chk_fil_stockvacio" ).click(function(event) {
			stockvalorizadoventa_tabla();
		});
		
		$("#txt_fil_pro_codbar").keydown(function(e)
		{
			if(e.which==13)
			{
				$("#txt_fil_pro_nom").val('');				
				stockvalorizadoventa_tabla();
				$(this).val('');
			//$(this).focus();
			e.preventDefault();
		}
	});
		$('#cmb_fil_cat_id, #cmb_fil_mar_id,#cmb_fil_alm_id,#cmb_fil_mon_id').change(function(){
			stockvalorizadoventa_tabla();
		});
	});
</script>