<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php'); 
$action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
if($action == 'ajax'){
    $q = mysqli_real_escape_string($con,(strip_tags($_REQUEST['q'], ENT_QUOTES)));
    include '../include/pagination.php'; //include pagination file
    $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
    $per_page = 20; //how much records you want to show
    $adjacents  = 4; //gap between pages after number of adjacents
    $offset = ($page - 1) * $per_page;
    $count_query   = mysqli_query($con, "SELECT count(*) AS numrows FROM pedido where  empresa='$empresa' and sucursal='$sucursal' ");
    $row= mysqli_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = './P_pedidos.php';
    $sql="SELECT * FROM pedido where empresa='$empresa' and sucursal='$sucursal' order by pen_id desc LIMIT $offset,$per_page";
    $query = mysqli_query($con, $sql);
    if ($numrows>0){
?>
<table class="table table-bordered table-hover table-striped" style="font-size: 9pt;">
    <thead>
        <tr>
            <th>N°</th>
            <th>FECHA</th>
            <th>CLIENTE</th>
            <th>REGISTRADO POR </th>            
            <th>ELIMINADO POR </th>
            <th>ESTADO</th>
            <th width="5%"></th>
        </tr>
    </thead>
    <tbody class="buscar">
    <?php 
        while ($reg=mysqli_fetch_array($query))
        {
            $pen_id=$reg['pen_id'];
    ?>
        <tr>
            <td><?php echo $reg['pen_n']; ?></td>
            <td><?php echo $reg['pen_fecha']; ?></td>
            <td><?php 
                $clie_id=$reg['clie_id']; 
                $sql_tar=mysqli_query($con, "SELECT * from cliente where clie_id='$clie_id'");
                $bo=mysqli_fetch_array($sql_tar);
                echo $clie_nombre=$bo['clie_nombre'];
            ?> </td>
            <td>
            <?php 
                $usuario=$reg['usuario']; 
                $sql_tar=mysqli_query($con, "SELECT * from usuario where usu_id='$usuario'");
                $bo=mysqli_fetch_array($sql_tar);
                echo $usu_n=$bo['usu_nombre'];
            ?>
            </td>
             <td>
            <?php 
                $usuario_eliminador=$reg['usuario_eliminador']; 
                $sql_tar=mysqli_query($con, "SELECT * from usuario where usu_id='$usuario_eliminador'");
                $bo=mysqli_fetch_array($sql_tar);
                echo $usuario_eliminador=$bo['usu_nombre'];
            ?>
            </td>
            <td><p class="pull-right"><?php echo $reg['pen_estado']; ?></p></td>
            <td>
                <div class="btn-group pull-right">
                    <a href="#verdetalle<?php echo $reg['pen_id']; ?>" title="Ver Detalle" class="btn btn-xs btn-default" data-toggle="modal"><i class="btn-icon-only icon-eye-open"></i></a>  
                        <?php include ('../php_pedidos/forms_detalle.php'); ?>
                </div> 
            </td>
        </tr>
            <?php }?>
        <tr>
            <td colspan=10><span class="pull-right">
                <?php echo paginate($reload, $page, $total_pages, $adjacents);?></span>
            </td>
        </tr>
    </table>
<?php } } ?>
