<style type="text/css"> /*codigo que permite la funcion autocompleta en modales*/
	.ui-autocomplete {
		z-index: 5000;
	}
</style>

<div class="content-header" >
      <div class="container-fluid">
        <div class="row mb-2">
		 <div class="col-sm-6">
			<h1>
			Egresos
			<small>modulo</small>
			</h1>
		</div>	
		
		<div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
				<li class="breadcrumb-item" >Inicio</li>
				<li class="breadcrumb-item" >Caja</li>
				<li class="breadcrumb-item active">Egresos</li>
            </ol>
          </div>
		</div>
	</div>
</div>
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0%;" >
		    <div class="card">
		        <div class="card-header">
					<button id="btn_agregar" onClick="egreso_form('insertar')" class="btn btn-primary">Agregar</button>
		          <button id="btn_actualizar" class="btn btn-default">Actualizar</button>		        
		        </div>
		    </div>
		</div>
	</div>
	</div>
</section>
	<!-- busqueda de registros -->
	<div id="div_egreso_filtro" > </div>
	<!-- formulario de registros -->
	<div class="modal fade" id="div_egreso_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px;">
			<div class="modal-dialog modal-lg"  role="document" >
			<div class="modal-content">
			<div class="modal-body div_egreso_form" style="padding:0%;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
	<!-- Form  impresion -->
	<div id="div_egreso_impresion"> </div>
	<!-- listado de registros  -->
	<div id="div_egreso_tabla"></div>
<script type="text/javascript">
	function egreso_filtro()
	{
		$.ajax({
			type: "POST",
			url: "../egreso/egreso_filtro.php",
			async:true,
			dataType: "html",                      
			data: ({
				
			}),
			beforeSend: function() {
				var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
				$('#div_egreso_filtro').html(div);
			},
			success: function(html){
				$('#div_egreso_filtro').html(html);
			},
			complete: function(){
				//egreso_tabla();
			}
		});
	}
	function egreso_tabla()
	{
		$.ajax({
			type: "POST",
			url: '../egreso/egreso_tabla.php',
			async:true,
			dataType: "html",                      
			data: $("#for_fil_egr").serialize(),
			beforeSend: function() {
				$('#div_egreso_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_egreso_tabla').html(html);
			},
			complete: function(){			
				$('#div_egreso_tabla').removeClass("ui-state-disabled");			
			}
		});     
	}
	
	function egreso_form(act,idf)
	{
		$('#div_egreso_form_dialog').modal(); 
		$.ajax({
			type: "POST",
			url: "../egreso/egreso_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				egr_id:	idf,
				vista: 'egreso_tabla'
			}),
			beforeSend: function() {
			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
			$('.div_egreso_form').html(div); 
				
			},
			success: function(html){
				$('.div_egreso_form').html(html);				
			}
		});
	}
	function egreso_eliminar(id)
	{      
		if(confirm("Realmente desea eliminar?")){
			$.ajax({
				type: "POST",
				url: "../egreso/egreso_reg.php",
				async:true,
				dataType: "html",
				data: ({
					action: "eliminar",
					egr_id:		id
				}),
				beforeSend: function() {
				},
				success: function(html){
					toastr["success"](html);
				},
				complete: function(){
					egreso_tabla();
				}
			});
		}
	}


 function egreso_ticket_datos(egr_id){	
		
		/* alert(id_ven); */
		
		$.ajax({
			type: "POST",
			url: "../egreso/egreso_ticket_datos.php",
			async:true,
			dataType: "json",                      
			data: ({ 
			egr_id: egr_id
			}),
			beforeSend: function() {
				
			},
			success: function(data){
				 //console.log(data); 
				
				if(data!=""){					
					egreso_ticket_impresion(data,data.imp_doc);	
				}else{
					
				}
			}
		});
	
}



function egreso_ticket_impresion(data,url){	

	$.ajax({
		type: "POST",
		url: url,
		async:true,
		dataType: "html",                      
		data: data,
		beforeSend: function()
		{
			//console.log(data);	
		},
		success: function(html){
				
			
		}
	});
}





	function egreso_impresion(idf){
		$.ajax({
			type: "POST",
			url: "../egreso/egreso_impresion.php",
			async:true,
			dataType: "html",                      
			data: ({
				egr_id:	idf
			}),
			beforeSend: function() {
				$('#div_egreso_impresion').dialog("open");
				$('#div_egreso_impresion').html('Cargando....');
			},
			success: function(html){
				$('#div_egreso_impresion').html(html);				
			}
		});
	}
	function egreso_reporte(url)
	{	
		$("#for_fil_egr").attr("action", url);
		$("#for_fil_egr").submit();
	}
	function egreso_reporte_xls(){
		$("#hdd_tabla").val( $("<div>").append( $("#tabla_egreso").eq(0).clone()).html()); 
		$("#for_rep_xls").submit();
	}
	function modo(url){
		$('#hdd_modo').val(url);
		egreso_tabla();
	};
	$(function() {
		$('#btn_actualizar').click(function() {
			$("#contenido").load("../egreso/egreso_vista.php");
		});
		egreso_filtro();
		setTitle("EGRESOS - "+nombreEmpresa);
		
	});
</script>