<?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';
    $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
    $per_page = 13;
    $adjacents  = 4; 
    $offset = ($page - 1) * $per_page;
    
    $count_query=mysqli_query($con, "SELECT count(*) AS numrows FROM ajuste_inventario  
      where sucursal='$sucursal' and empresa='$empresa' and (aju_n_ajuste like '%$q%' or aju_detalle like '%$q%') ");
    $row= mysqli_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = '../I_bodegas.php';
    $sql = mysqli_query($con,"SELECT * FROM ajuste_inventario 
      where sucursal='$sucursal' and empresa='$empresa' and (aju_n_ajuste like '%$q%' or aju_detalle like '%$q%' )
      order by aju_id desc LIMIT $offset,$per_page");
    
    if ($numrows>0){
?>
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th width="4%"></th>
                <th width="10%">FECHA</th>
                <th width="8%">HORA</th>
                <th >DETALLE</th>
                <th width="20%">USUARIO</th>
                <th width="8%"></th>
            </tr>
        </thead>
        <tbody  class="buscar">
            <?php  while ($reg=mysqli_fetch_array($sql)){
             ?>
            <tr>
                <td><?php echo $reg['aju_n_ajuste']; ?></td>
                <td><?php echo $reg['aju_fecha']; ?></td>
                <td><?php echo $reg['aju_hora']; ?></td>
                <td><?php echo $reg['aju_detalle']; ?></td>
                <td>
                <?php  
                    $sql_tar=mysqli_query($con, "SELECT * from usuario where usu_id='".$reg['aju_usuario']."'");
                    $bo=mysqli_fetch_array($sql_tar);
                    echo $usu_n=$bo['usu_nombre'];?>
                </td>
                <td>
                    <a href="#verdetalle<?php echo $reg["aju_id"];?>" data-toggle="modal" title="Ver Ajuste" class="btn btn-xs btn-info"><i class="btn-icon-only icon-eye-open"></i></a>
                    <?php include ('form_detalle.php'); ?>
                     <a href="libraries/tcpdf/documentos/ajuste.php?aju_id=<?php echo $reg['aju_id'];?>" target="_blank" class="btn btn-xs btn-success"> <i class="btn-icon-only icon-print"></i></a>
                    <!--<a href="#" id="del-<?php echo $reg["aju_id"];?>" title="Eliminar" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>-->
                    <script>
                        $("#del-"+<?php echo $reg["aju_id"];?>).click(function(e){
                          e.preventDefault();
                          p = confirm("Estas seguro?");
                          if(p){
                            $.get("./php_ajustes/eliminar_ajustes.php","aju_id="+<?php echo $reg["aju_id"];?>,function(data){
                            load(1);
                            });
                            }
                          });
                    </script>
                </td>
            </tr>
            <?php }?>
            <tr>
                <td colspan=6><span class="pull-right">
                    <?php echo paginate($reload, $page, $total_pages, $adjacents);?></span>
                </td>
            </tr>
        </tbody>
    </table>
<?php } } ?> 