<?php

session_start();
require_once ("../../config/Cado.php");
require_once ("../cajagestion/cCajagestion.php");
$oCajagestion = new cCajagestion();
require_once("../formatos/formato.php");
$fec=date('d-m-Y');

$dts1 =$oCajagestion->mostrarUno2($_SESSION['usuario_id'],'1',fecha_mysql($fec));
$numrows1 = mysqli_num_rows($dts1);
//echo $numrows1.'---';

$dts2 =$oCajagestion->mostrarUno2($_SESSION['usuario_id'],'2',fecha_mysql($fec));
$numerows2 = mysqli_num_rows($dts2);
//echo $numrows2.'---';





?>



<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>
			Caja gestion
			<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">Caja Gestion</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">
		          
				  <?php 
				  if($numrows1>0){
					  
				  }else{
				  ?>
				  <button id="btn_agregar" onClick="cajagestion_form('insertar','','1')" class="btn btn-success">Apertura</button>
				  <?php }?>
				  
				  
				  <?php
				  if($numerows2>0){
					  
					 
				  }else{
				  ?>
				 <button id="btn_agregar" onClick="cajagestion_form('insertar','','2')" class="btn btn-warning">Cierre caja</button>
				  <?php }?>
				  
				  
				  
		          <button id="btn_actualizar" class="btn btn-default">Actualizar</button>		        
		        </div>
		    </div>
		</div>
	</div>
	</div>
</section>
	
	
	
	<!-- busqueda de registros -->
	<div id="div_cajagestion_filtro" > </div>
	 
	<!-- formulario de registro -->
			<div class="modal fade" id="div_cajagestion_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px;">
			<div class="modal-dialog modal-md"  role="document" >
			<div class="modal-content">
			<div class="modal-body div_cajagestion_form" style="padding:0%;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
	<!-- Form  impresion -->
	<div id="div_cajagestion_impresion"> </div>
	<!-- lista de registros  -->
	<div id="div_cajagestion_tabla"></div>
<script type="text/javascript">
function cajagestion_filtro()
	{
		$.ajax({
			type: "POST",
			url: "../cajagestion/cajagestion_filtro.php",
			async:true,
			dataType: "html",                      
			data: ({
			
			}),
			beforeSend: function() {
				
			},
			success: function(html){
				$('#div_cajagestion_filtro').html(html);
			},
			complete: function(){
				
			}
		});
	}
	function cajagestion_tabla()
	{
		$.ajax({
			type: "POST",
			url: '../cajagestion/cajagestion_tabla.php',
			async:true,
			dataType: "html",                      
			data: $("#for_fil_cajges").serialize(),
			beforeSend: function() {
				$('#div_cajagestion_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_cajagestion_tabla').html(html);
			},
			complete: function(){			
				$('#div_cajagestion_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	function cajagestion_form(act,idf,tip)
	{
		$('#div_cajagestion_form_dialog').modal(); 
		$.ajax({
			type: "POST",
			url: "../cajagestion/cajagestion_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				cajges_id:	idf,
				tip:tip,
				vista: 'cajagestion_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_cajagestion_form').html(div);
			},
			success: function(html){
			$('.div_cajagestion_form').html(html);				
			}
		});
	}
	
	
	function cajagestion_eliminar(id)
	{      
		if(confirm("Realmente desea eliminar?")){
			$.ajax({
				type: "POST",
				url: "../cajagestion/cajagestion_reg.php",
				async:true,
				dataType: "html",
				data: ({
					action: "eliminar",
					ing_id:		id
				}),
				beforeSend: function() {
				},
				success: function(html){
					toastr["success"](html);	
				},
				complete: function(){
					cajagestion_tabla();
				}
			});
		}
	}
	function cajagestion_impresion(idf){
		$.ajax({
			type: "POST",
			url: "../cajagestion/cajagestion_impresion.php",
			async:true,
			dataType: "html",                      
			data: ({
				ing_id:	idf
			}),
			beforeSend: function() {
				$('#div_cajagestion_impresion').dialog("open");
				$('#div_cajagestion_impresion').html('Cargando...');
			},
			success: function(html){
				$('#div_cajagestion_impresion').html(html);				
			}
		});
	}
	function cajagestion_reporte(url)
	{	
		$("#for_fil_ing").attr("action", url);
		$("#for_fil_ing").submit();
	}
	function cajagestion_reporte_xls(){
		$("#hdd_tabla").val( $("<div>").append( $("#tabla_cajagestion").eq(0).clone()).html()); 
		$("#for_rep_xls").submit();
	}
	function modo(url){
		$('#hdd_modo').val(url);
		cajagestion_tabla();
	};
 
 $(function() {
	
	$('#btn_actualizar').click(function() {
		$("#contenido").load("../cajagestion/cajagestion_vista.php");
	});
	cajagestion_filtro();
	setTitle("CAJA GESTION - "+nombreEmpresa);
});
 
</script> 