<?php
session_start();
date_default_timezone_set('America/Lima');
require_once ("../../config/Cado.php");
$y=date('Y');
$m=date('m');
$d=date('d');
$fec1="$d-$m-$y";
$fec2="$d-$m-$y";
$caja_id=$_SESSION['caja_id'];
?>
<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_egr" id="for_fil_egr" action="" method="post">
							
							<div class="row">
		
							<div class=" col-lg-2 col-xs-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_egre_fec1" type="text" id="txt_fil_egre_fec1" value="<?php echo $fec1?>" class="form-control" >
								</div>
							</div>
							
							<div class=" col-lg-2 col-xs-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_egre_fec2" type="text" id="txt_fil_egre_fec2" value="<?php echo $fec1?>" class="form-control" >
								</div>
							</div>
		 
							<div class="col-lg-4 col-xs-6">
								<label for="cmb_fil_caj_id">Caja:</label>
								<select name="cmb_fil_caj_id" id="cmb_fil_caj_id" class="form-control input-sm">
								</select>
							</div>
							<div class="col-lg-2 col-xs-6">
								<input type="hidden" id="hdd_fil_pro_id" name="hdd_fil_pro_id" />
								<label for="txt_fil_pro_id">Proveedor:</label>
								<input type="text" id="txt_fil_pro" name="txt_fil_pro" class="form-control input-sm" /> 
							</div>
							<div class="col-lg-2 col-xs-6">
								<label for="cmb_fil_egr_est">Estado:</label>
								<select name="cmb_fil_egr_est" id="cmb_fil_egr_est" class="form-control input-sm">
									<option value="">-</option>
									<option value="1" <?php if($est==1)echo 'selected'?>>REGISTRADO</option>
									<option value="2" <?php if($est==2)echo 'selected'?>>ANULADO</option>
								</select>
							</div>
							
							<div class="col-lg-2 col-xs-6">
								<label for="cmb_fil_doc_id">Documento:</label>
								<select name="cmb_fil_doc_id" id="cmb_fil_doc_id" class="form-control input-sm"></select>
							</div>
							
							<div class="col-lg-2 col-xs-6">
								<label for="txt_fil_egr_numdoc">N° Doc:</label>
								<input name="txt_fil_egr_numdoc" type="text" id="txt_fil_egr_numdoc" class="form-control input-sm" maxlength="15">
							</div> 
							<div class="col-lg-2 col-xs-6">
								<label for="cmb_fil_cue_id">Cuenta:</label>
								<select name="cmb_fil_cue_id" id="cmb_fil_cue_id" class="form-control input-sm"> </select>
							</div>
							<div class="col-lg-2 col-xs-6">
								<label for="cmb_fil_subcue_id">Sub Cuenta:</label>
								<select name="cmb_fil_subcue_id" id="cmb_fil_subcue_id" class="form-control input-sm">
								</select>
							</div>
							<div class="col-lg-3 col-xs-12" style="padding-top:30px;"> 
								<span onClick="egreso_tabla()" style="cursor:pointer" class="btn btn-primary"><i class="fas fa-search"></i></span>
								<span onClick="egreso_filtro()" style="cursor:pointer" class="btn btn-default">Restablecer</span>
							</div>	
							
							</div>	
						</form>
						
					</div>
				</div>
			</div>
		</div>
	</div>
	</div>
</section>
<script type="text/javascript">
	function cmb_fil_caj_id(ids)
	{	
		$.ajax({
			type: "POST",
			url: "../caja/cmb_caj_id.php",
			async:false,
			dataType: "html",                      
			data: ({
				caj_id: ids
			}),
			beforeSend: function() {
				$('#cmb_fil_caj_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_fil_caj_id').html(html);
			}
		});
	}	
	function cmb_fil_doc_id(docid,vis)
	{	
		$.ajax({
			type: "POST",
			url: "../documento/cmb_doc_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mod_id: 12,
				doc_id: 	docid,
				vista:		vis
			}),
			beforeSend: function() {
				$('#cmb_fil_doc_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_fil_doc_id').html(html);
			},
			complete: function(){
			}
		});
	}
	function cmb_fil_cue_id()
	{	
		$.ajax({
			type: "POST",
			url: "../cuentas/cmb_cue_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				cuetip_id:"2",
				orden: "ord",
				cue_id: "<?php echo $cue_id?>"
			}),
			beforeSend: function() {
				$('#cmb_fil_cue_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_fil_cue_id').html(html);
			}
		});
	}
	function cmb_fil_subcue_id(cuenta_id)
	{	
		$.ajax({
			type: "POST",
			url: "../cuentas/cmb_subcue_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				cue_id: cuenta_id,
				subcue_id: "<?php echo $subcue_id?>"
			}),
			beforeSend: function() {
				$('#cmb_fil_subcue_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_fil_subcue_id').html(html);
			}
		});
	}
	function cmb_moneda_id(ids)
	{	
		$.ajax({
			type: "POST",
			url: "../moneda/cmb_mon_id.php",
			async:false,
			dataType: "html",                      
			data: ({
				mon_id: ids
			}),
			beforeSend: function() {
				$('#cmb_moneda_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_moneda_id').html(html);
			}
		});
	}
	$(function() {
	
		$('#txt_fil_egre_fec1, #txt_fil_egre_fec2').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			egreso_tabla();
		}); 
		
		
	cmb_fil_caj_id('<?php echo $caja_id?>');
	$( "#txt_fil_pro" ).autocomplete({
		minLength: 1,
		source: "../proveedor/proveedor_complete_nom.php",
		select: function(event, ui){
		$("#hdd_fil_pro_id").val(ui.item.id);
			egreso_tabla();													
		}
	});	
	
	
	$("#txt_fil_pro").change(function(){
		var cli=$("#txt_fil_pro").val();
		if(cli=="")$("#hdd_fil_pro_id").val('');
	});
	cmb_fil_doc_id('7','doc_id','vista');
	cmb_fil_cue_id();
	$('#cmb_fil_cue_id').change(function(){
		cmb_fil_subcue_id($('#cmb_fil_cue_id').val());
	});	
	$("#txt_fil_pro,#cmb_fil_caj_id,#cmb_fil_doc_id,#txt_fil_egr_numdoc,#cmb_fil_cue_id, #cmb_fil_subcue_id, #cmb_fil_egr_est, #cmb_moneda_id").change(function()
	{
		egreso_tabla();
	});
	egreso_tabla();
});
</script>