<?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";
$alm_id=$_SESSION['almacen_id'];
?>
<script type="text/javascript">
	
	function cmb_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_almacen').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_almacen').html(html);
			},
			complete: function(){
			/*var alm_id = $("#cmb_almacen").val();
			var cat_id = $("#hdd_cat_sel_id").val();
			kardex_tabla(cat_id, alm_id);*/
		}
	});
	}
function traer_marca(catid)
	{	
	$.ajax({
		type: "POST",
		url: "../marca/cmb_mar_id.php",
		async:false,
		dataType: "html",                      
		data: ({
			cat_id: catid
		}),
		beforeSend: function() {
			$('#cmb_fil_mar_id').html('<option value="">Cargando...</option>');
		},
		success: function(html){
			$('#cmb_fil_mar_id').html(html);
		}
	});
	}
	$(function() {
	$('#txt_fil_notcre_fec1, #txt_fil_notcre_fec2').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			//venta_tabla();
		}); 
		
	
		cmb_alm_id();
		$("#txt_fil_pro_cod").focus();
		$("#txt_fil_pro_nom").focus();
		$("#cmb_almacen,#cmb_fil_mar_id").change(function() { kardex_datos() });
		$( "#txt_bus_pro_nom" ).autocomplete({
			minLength: 1,
			delay: 12,
			source: "../kardex/catalogo_buscar_nom.php",
			select: function( event, ui )
			{
				$("#txt_fil_pro_cod").val("");
				$("#txt_bus_pro_nom").val(ui.item.label);
				$("#txt_fil_pro_cod").val(ui.item.codbar);
				$("#idcodbar_oculto").val(ui.item.codbar);
				$("#idcat_oculto").val(ui.item.catid);
				traer_marca(ui.item.catid);
				
				//kardex_datos(ui.item.catid,ui.item.codbar);		
			//catalogo_buscar();			
			}
		});
		
		
		$("#btn_restablecer").click(function(){
			
				$("#contenido").load("../kardex/kardex_vista.php");
			
		});
		$("#txt_fil_pro_cod").keydown(function(e){
			if (e.which == 13){				
				$("#txt_bus_pro_nom").val('');
				$.ajax({
					type: "POST",
					url: "../kardex/kardex_reg.php",
					async:true,
					dataType: "json",                      
					data: ({
						action:'buscar_idcat',
						codbar: $("#txt_fil_pro_cod").val(),
					}),
					beforeSend: function() {
					},
					success: function(data){
						var catid = data.id_cat;
						if (catid>0){
							kardex_datos(catid,$("#txt_fil_pro_cod").val(),$('#cmb_fil_mar_id').val());
						}else{
							$("#txt_fil_pro_cod").val('');
							showAlert('Codigo Incorrecto',false,3000);
						}
					},
					complete: function(){
						$("#txt_fil_pro_cod").val('');
						$("#txt_bus_pro_nom").val('');
						$("#idcodbar_oculto").val('');
						$("#idcat_oculto").val('');
						$("#txt_fil_pro_cod").focus();
					}
				});
			}
		});
		
	});
</script>
<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 class="row">
			
			<form id="for_fil_kardex" action="POST">
    		<div class="row">
					
						<input type="hidden" name="idcat_oculto" id="idcat_oculto" value="">
						<input type="hidden" id="idcodbar_oculto" value="">
						
						
					<div class=" col-lg-2 col-6 form-group">
                  <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_notcre_fec1" type="text" id="txt_fil_notcre_fec1" value="<?php echo $fec1?>" class="form-control" >
                  </div>
                </div>
				
				<div class=" col-lg-2 col-6 form-group">
                  <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_notcre_fec2" type="text" id="txt_fil_notcre_fec2" value="<?php echo $fec2 ?>" class="form-control" >
                  </div>
                </div>
						
				<!--		
                     <div class="col-lg-1 col-sm-3 col-4">
						<label>Cod. Bar:</label>
						<input name="txt_fil_pro_cod" type="text" id="txt_fil_pro_cod"  class="form-control">
                     </div>
					--> 
                     <div class="col-lg-2 col-sm-3 col-6">
						<label>Nombre:</label>
						<input name="txt_bus_pro_nom" type="text" id="txt_bus_pro_nom" class="form-control">
                     </div>
                      <div class="col-lg-2 col-sm-3 col-6">
						<label>Laboratorio:</label>
						<select name="cmb_fil_mar_id" id="cmb_fil_mar_id" style="cursor:pointer;" class="form-control">
						</select> 
					  </div>
                     <div class="col-lg-2 col-sm-3 col-6">
						<label>Almacen:</label>
						<select name="cmb_almacen" id="cmb_almacen" style="cursor:pointer;"  class="form-control">
						<option value="">-</option>              
						</select>
                     </div>
					 
                     <div class="col-lg-2 col-sm-3 col-6" style="display: inline-block; white-space: nowrap;padding-top: 30px;" >
						<span onClick="kardex_datos()" style="cursor:pointer" class="btn btn-primary"><i class="fas fa-search"></i></span>
						<span onClick="kardex_filtro()" style="cursor:pointer" id="btn_restablecer" class="btn btn-default">Restablecer</span>
					</div>
					
					
					
					</div>	
	</form>						
				</div>
			</div>
		</div>
	</div>
</div>
</section>