<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>
			Ingresos
			<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">Ingresos</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="ingreso_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_ingreso_filtro" > </div>
	 
	<!-- formulario de registro -->
			<div class="modal fade" id="div_ingreso_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_ingreso_form" style="padding:0%;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
	<!-- Form  impresion -->
	<div id="div_ingreso_impresion"> </div>
	<!-- lista de registros  -->
	<div id="div_ingreso_tabla"></div>
<script type="text/javascript">
function ingreso_filtro()
	{
		$.ajax({
			type: "POST",
			url: "../ingreso/ingreso_filtro.php",
			async:true,
			dataType: "html",                      
			data: ({
			
			}),
			beforeSend: function() {
				
			},
			success: function(html){
				$('#div_ingreso_filtro').html(html);
			},
			complete: function(){
				
			}
		});
	}
	function ingreso_tabla()
	{
		$.ajax({
			type: "POST",
			url: '../ingreso/ingreso_tabla.php',
			async:true,
			dataType: "html",                      
			data: $("#for_fil_ing").serialize(),
			beforeSend: function() {
				$('#div_ingreso_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_ingreso_tabla').html(html);
			},
			complete: function(){			
				$('#div_ingreso_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	function ingreso_form(act,idf)
	{
		$('#div_ingreso_form_dialog').modal(); 
		$.ajax({
			type: "POST",
			url: "../ingreso/ingreso_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				ing_id:	idf,
				vista: 'ingreso_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_ingreso_form').html(div);
			},
			success: function(html){
			$('.div_ingreso_form').html(html);				
			}
		});
	}
	function ingreso_eliminar(id)
	{      
		if(confirm("Realmente desea eliminar?")){
			$.ajax({
				type: "POST",
				url: "../ingreso/ingreso_reg.php",
				async:true,
				dataType: "html",
				data: ({
					action: "eliminar",
					ing_id:		id
				}),
				beforeSend: function() {
				},
				success: function(html){
					toastr["success"](html);	
				},
				complete: function(){
					ingreso_tabla();
				}
			});
		}
	}

	
 function ingreso_ticket_datos(ing_id){	
		
		/* alert(id_ven); */
		
		$.ajax({
			type: "POST",
			url: "../ingreso/ingreso_ticket_datos.php",
			async:true,
			dataType: "json",                      
			data: ({ 
			ing_id: ing_id
			}),
			beforeSend: function() {
				
			},
			success: function(data){
				 console.log(data); 		
					ingreso_ticket_impresion(data,data.imp_doc);	
			
			}
		});
	
}



function ingreso_ticket_impresion(data,url){	

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



	function ingreso_reporte(url)
	{	
		$("#for_fil_ing").attr("action", url);
		$("#for_fil_ing").submit();
	}
	function ingreso_reporte_xls(){
		$("#hdd_tabla").val( $("<div>").append( $("#tabla_ingreso").eq(0).clone()).html()); 
		$("#for_rep_xls").submit();
	}
	function modo(url){
		$('#hdd_modo').val(url);
		ingreso_tabla();
	};
 
 $(function() {
	
	$('#btn_actualizar').click(function() {
		$("#contenido").load("../ingreso/ingreso_vista.php");
	});
	ingreso_filtro();
	setTitle("INGRESOS - "+nombreEmpresa);
});
 
</script> 