 <?php  
	session_start();
	include "conexion.php";
	include "mysql_Valida_permiso.php";

	if(!isset($_SESSION['id_usuario']))
	{
		header('location: index.php');
		return;
	}
	$reporte =  validaPermiso('Facturas','ReporteFacturas',$_SESSION['id_usuario']);

	$saldo = 0;
	$razon_social = "";

	$sql = "select ";
	$sql .= "razon_social, ";
	$sql .= "format(saldo,2) as saldo ";
	$sql .= "from ";
	$sql .= "clientes ";
	$sql .= "where ";
	$sql .= "id_cliente = " . $_SESSION['id_cliente'];	
	
	$resultado = $conexion->query($sql); 

	if (!$resultado) 
	{
		echo "Error: No se pudo realizar la consulta de los vehiculos.";
		return;
	}

	while($fila = $resultado->fetch_assoc()) 
	{
		$saldo = $fila['saldo'];
		$razon_social = $fila['razon_social'];
	}

?>

<!DOCTYPE html>
<html lang="en" translate="no">
	<head>
		<link rel="stylesheet" href="css/bootstrap.css">
		<link rel="stylesheet" href="css/sweetalert2.min.css">
		<link rel="stylesheet" href="css/datepicker.css">
		<link rel="shortcut icon" href="images/Logo.jpg" type="image/jpeg"/>
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
		<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
		<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
		<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
		<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
		<meta name="google" content="notranslate" />
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<meta charset="utf8">
		<meta http-equiv="Expires" content="0">
		<meta http-equiv="Last-Modified" content="0">
		<meta http-equiv="Cache-Control" content="no-cache, mustrevalidate">
		<meta http-equiv="Pragma" content="no-cache">
		<title>Facturas</title>	
	</head>
	<body onload="">
	<?php include "menu.php"; ?>
	<div id= "contenidoPrincipal" class="col-lg-10 offset-lg-1 col-sm-12 col-md-12">
		<div id="encabezado">
			<h1>Facturas</h1>
		</div>
		<hr></hr>
		
		<div id="cuerpo">
			<div class="row form-group">	
				<div class="col-lg-6">			
					<div class="col-lg-12">
						<label><strong>Cliente:</strong></label>
						<label><strong><?php echo $_SESSION['id_cliente'];  ?> </strong></label>
					</div>
					<div class="col-lg-12">
						<label><strong>Razon Social:</strong></label>
						<label><strong><?php echo $razon_social;  ?></strong></label>
					</div>
					<div class="col-lg-12">
						<label><strong>Saldo:</strong></label>
						<label><strong>$<?php echo $saldo;  ?></strong></label>
					</div>
				</div>
			<div class="col-lg-1 offset-lg-3 ">
				<button class="btn btn-success btn-block" onclick="buscar();">Buscar</button>
			</div>	
			<div class="col-lg-1 ">				
				<button class="btn btn-success btn-block" onclick="detalle();">Detalle</button>
			</div>		
			<div class="col-lg-1 ">	
				<?php
					if($reporte==1){			
						echo '<button class="btn btn-success btn-block" onclick="seleccionar_tipo_reporte();">Reporte</button>';
					}
				?>
			</div>				
		</div>		
		<div class="row form-group">	
			<div class="col-lg-2 col-md-2 form-group">
				<div class="form-check" style="text-align: right;">
					<input type="checkbox" class="form-check-input"  id="cbxFecha" onchange="habilita_fecha();">
		    		<label  class="form-check-label" for="cbxFecha">Fecha Contable</label>
				</div>
			</div>	
			<div class="col-lg-2 col-md-3 form-group">
				<input type=""  name="txtFechaInicio"  class="form-control" id="txtFechaInicio" placeholder="fecha" onchange="" value="<?php echo date("Y-m-d"); ?>" disabled> 						
			</div>
			<div class="col-lg-2 col-md-3 form-group">
				<input type=""  name="txtFechaFin"  class="form-control" id="txtFechaFin" placeholder="fecha" onchange="" value="<?php echo date("Y-m-d"); ?>" disabled> 
			</div>
			<div class="col-lg-2 col-md-2 form-group">
				<div class="form-check" style="text-align: right;">
					<input type="checkbox" class="form-check-input"  id="cbxFecha2" onchange="habilita_fecha2();">
					<label class="form-check-label" for="cbxFecha2">Fecha Registro</label>
				</div>
			</div>	
			<div class="col-lg-2 col-md-3 form-group">
				<input type=""  name="txtFechaInicio2"  class="form-control" id="txtFechaInicio2" placeholder="fecha" onchange="" value="<?php echo date("Y-m-d"); ?>" disabled> 
			</div>
			<div class="col-lg-2 col-md-3 form-group">
				<input type=""  name="txtFechaFin2"  class="form-control" id="txtFechaFin2" placeholder="fecha" onchange="" value="<?php echo date("Y-m-d"); ?>" disabled> 
			</div>
		</div>
		<div class="row form-group">
			<div class="col-lg-10 col-md-12">
				<div class="row form-group">
					<div class="col-lg-1 col-md-2 col-sm-12 form-group offset-lg-1">
						<div class="form-check">
							<input type="checkbox" class="form-check-input" id="cbxSerie" onchange="habilita_serie();">
							<label class="form-check-label" for="cbxSerie">Serie</label>
						</div>
					</div>
					<div class="col-lg-1 col-md-4 col-sm-12 form-group form-group">
						<input type="text" id ="txtSerie" class="form-control" disabled  maxlength="11">
					</div>
					<div class="col-lg-1 col-md-2 col-sm-12 form-group">
						<div class="form-check" style="text-align: right;">
							<input type="checkbox" class="form-check-input" id="cbxFolio" onchange="habilita_folio();">
							<label class="form-check-label" for="cbxFolio">Folio</label>
						</div>
					</div>
					<div class="col-lg-1 col-md-4 col-sm-12 form-group">
						<input type="text" id ="txtFolio" class="form-control" disabled onkeypress="return numeros(event)" maxlength="11">
					</div>
					<div class="col-md-3"></div>
					<div class="col-md-1">
						<div class="form-check" style="text-align: right;">
							<input type="checkbox" class="form-check-input" id="cbxActiva">
			    			<label class="form-check-label" for="cbxActiva">Activa</label>
						</div>
					</div>
					<div class="col-md-1">
						<div class="form-check">
							<input type="checkbox" class="form-check-input" id="cbxCancelada" >
							<label class="form-check-label" for="cbxCancelada">Cancelada</label>
						</div>
					</div>
					<div class="col-md-1">
						<div class="form-check">
							<input type="checkbox" class="form-check-input" id="cbxReproceso" >
			    			<label class="form-check-label" for="cbxReproceso">Reproceso</label>
						</div>
					</div>
					<div class="col-md-1">
						<div class="form-check">
							<input type="checkbox" class="form-check-input" id="cbxLimit" checked>
			    			<label class="form-check-label" for="cbxLimit">Limit</label>
						</div>
					</div>	
				</div>			
			</div>
		</div>
		<div class="table-responsive" id ="tablaContenido"></div>
		<div id="pie"></div>
	</div>
	<div class="col-md-10 offset-md-1" id="contenedorOperacion"></div>
	<div class="col-md-10 offset-md-1" id="contenedorOperacion2"></div>
	<div class="col-md-10 offset-md-1" id="contenedorOperacion3"></div>
</body>

<script src="./js/funciones_facturas.js"></script>
<script src="./js/funciones_generales.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/bootstrap-datepicker.js"></script>
<script src="js/sweetalert2.min.js"></script>
<script src="js/moments.js"></script>
<script src="./js/bootstrap-datepicker.js"></script>
<script>

$(document).on('click', '.borrar', function(event) {
  event.preventDefault();
  $(this).closest('tr').remove();
 	Actualizar_totales();
});

$(document).on('click', '.borrar_cfdi', function(event) {
  event.preventDefault();
 
  //Remove_cfdi(Dato);
  $(this).closest('tr').remove();
 	
});

</script>

<script>
    $(function()
    {
        $("#txtFechaInicio").datepicker({
            format:'yyyy-mm-dd'
        });
        $("#txtFechaFin").datepicker({
            format:'yyyy-mm-dd'
        });           
    });


     $(function()
    {
        $("#txtFechaInicio2").datepicker({
            format:'yyyy-mm-dd'
        });
        $("#txtFechaFin2").datepicker({
            format:'yyyy-mm-dd'
        });           
    });
</script>
</html>
