<?php
session_start();
require_once('conexion.php');
require_once('include/sesiones.php');
if (isset($_SESSION['usu_nombre']))
{
    $regis=mysqli_query($con,"SELECT * from permiso where modulo_mod_id='26' and usuario_usu_id='$usu_id'") or die(mysqli_error($con));
    $reg=mysqli_fetch_array($regis);
    if($reg['per_visualizar']=="Activo")
    {
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include ('head.php'); ?>
</head>
<body>
<?php
$inicio="";
$M_inventario="";
$M_contactos="";
$M_compras="";
$M_ventas="";
$M_pedidos="";
$M_pos="";
$R_reportes="active";

$ventas="";
$caja="active";
$compra="";
$contactos="";
$inventario="";
$utilidad="";

include ('menu.php');
?> 
<div class="main">
    <div class="col-md-2">
        <?php include ('include/menu_reportes.php');?>
    </div>
    <div class="col-md-10">
        <div class="widget-content">
            <div class="widget stacked">
                <div class="widget-content">
                    <div class="widget stacked">
                        <div class="widget-content">
                           <div class="parent-list">
                                <div class="col-md-3" >
                                    <a href="#cierre" class="icon-btn" data-toggle="modal">
                                        <p style="padding: 10px; text-align: left;"><i class="shortcut-icon fas fa-file-export" style="color: red;"></i><strong> CIERRES DE CAJA</strong></p>
                                    </a>
                                </div>
                                <div class="col-md-3" >
                                    <a href="#detalles" class="icon-btn" data-toggle="modal">
                                        <p style="padding: 10px; text-align: left;"><i class="shortcut-icon fas fa-file-export" style="color: red;"></i><strong> DETALLE POR MEDIO DE PAGO</strong></p>
                                    </a>
                                </div>
                                <div class="col-md-3" >
                                    <a href="#egresos" class="icon-btn" data-toggle="modal">
                                        <p style="padding: 10px; text-align: left;"><i class="shortcut-icon fas fa-file-export" style="color: red;"></i><strong> EGRESOS</strong></p>
                                    </a>
                                </div>
                                <div class="col-md-3" >
                                    <a href="#abono_adelantado" class="icon-btn" data-toggle="modal">
                                        <p style="padding: 10px; text-align: left;"><i class="shortcut-icon fas fa-file-export" style="color: red;"></i><strong> HISTORIAL ABONOS ADELANTADOS</strong></p>
                                    </a>
                                </div>
                            </div>
                            <?php include ('php_reportes/form_caja.php');?>
                        </div>
                    </div>
                    
                    <div class="pull-right" style="padding-bottom: 5px;">
                        <form method="get" action="" id="reporteForm" target="_blank">
                            <input type="hidden" name="desde" value="<?php echo $_GET['desde']; ?>">
                            <input type="hidden" name="hasta" value="<?php echo $_GET['hasta']; ?>">
                            <button type="submit" class="btn btn-danger" data-action="libraries/pdf/pdf_reportes/caja_egresos.php"><i class="fa-solid fa-file-pdf"> </i> PDF</button>
                            <button type="submit" class="btn btn-success" data-action="libraries/php_excel/excel_caja_egresos.php"><i class="fa-solid fa-file-excel"> </i> EXCEL</button>
                        </form>
                    </div>
                       
                    
                    
                <div class="widget stacked widget-table action-table">
                    <div class="widget-header" > </div> <!-- /widget-header -->      
                    <div class="widget-content">
                        <div class="table-responsive">
                            <?php
                                $desde=$_GET['desde'];
                                $hasta=$_GET['hasta'];

                                $sql=mysqli_query($con,"SELECT * FROM egresos where fecha BETWEEN '$desde' AND '$hasta' and sucursal='$sucursal' and empresa='$empresa' order by fecha desc ");
                                ?>

                                <table class="table table-striped table-bordered">
                                    <thead>
                                        <tr>
                                            <th width="20%">USUARIO</th>
                                            <th width="">CONCEPTO</th>
                                            <th width="10%">BANCO</th>
                                            <th width="10%">PAGO</th>
                                            <th width="12%">TOTAL</th>
                                            <th width="12%">FECHA</th>
                                            <th width="1%"></th>
                                        </tr>
                                    </thead>
                                    <tbody class="buscara">
                                        <?php  
                                            while ($reg=mysqli_fetch_array($sql)){
                                            $id=$reg['id'];
                                        ?>
                                        <input type="hidden" value="<?php echo $reg['fecha'];?>" id="fecha1<?php echo $reg['id'];?>">
                                        <input type="hidden" value="<?php echo $reg['concepto'];?>" id="concepto1<?php echo $reg['id'];?>">
                                        <input type="hidden" value="<?php echo $reg['total'];?>" id="total1<?php echo $reg['id'];?>">

                                        <tr>
                                            <td>
                                            <?php 
                                            $usua_id=$reg['usuario']; 
                                            $usua = mysqli_query($con,"SELECT * FROM usuario where  usu_id='$usua_id' and empresa_emp_id='$empresa'");
                                            $usu1=mysqli_fetch_array($usua);
                                            echo $usu_nombre=$usu1['usu_nombre'];
                                            ?>
                                            </td>
                                            <td><?php echo $reg['concepto']; ?></td>
                                            <td><?php echo $reg['banco']; ?></td>
                                            <td><?php echo $reg['metodo_pago']; ?></td>
                                            <td><p class="pull-right"><?php echo number_format($reg['total'],0); ?></p></td>
                                            <td><?php echo $reg['fecha']; ?></td>
                                            <td> 
                                            <?php  if($fac_tamano=='Carta') { ?>
                                                <a href="libraries/tcpdf/documentos/egresos.php?id=<?php echo $reg['id']; ?>" title="Imprimir Recibo" class="btn btn-xs btn-success" target="_blank"> <i class="btn-icon-only icon-print"></i></a>
                                            <?php  } else { ?>
                                                <a href="tirillas/tirilla_egresos.php?id=<?php echo $reg['id']; ?>" class="btn btn-success btn-xs" target="_blank" title="Imprimir"><i class="btn-icon-only icon-print"></i></a>
                                            <?php }  ?>
                                            </td>         
                                        </tr>  
                                    <?php } ?>
                                    </table>
                                </div>
                            </div> <!-- /widget -->
                        </div>
                    </form>
                </div>
            </div>
        </div> </br></br></br>
    </div>
</div>
<script type="text/javascript">
$(document).ready(function() {
  $("button[type=submit]").click(function() {
    var accion = $(this).data('action'); // <-- más semántico
    $(this).closest('form').attr('action', accion);
  });
});
</script>
<?php
    include ('php_caja/caja_abrir.php');
    include ('script.php');
?>
</body>
</html>
<?php
}
else
{
   echo '<script>alert("No tienes permiso para ver esta pagina")</script>';
   echo '<script> setTimeout("history.back(1)", 0); </script>';
}
}
else
{
    echo '<script>location.href = "index.php";</script>';
}
?>