<?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 = 10; //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 abono_adelantado
    where empresa='$empresa' AND abo_adelantado='si' and (abo_numero like '%$q%' OR abo_clie_nombre like '%$q%')");
    $row= mysqli_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = './P_pos.php';
    $sql="SELECT * FROM  abono_adelantado
    where  empresa='$empresa' and abo_adelantado='si' and (abo_numero like '%$q%' OR abo_clie_nombre like '%$q%') order by abo_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>
            <td width="8%">N°</td>
            <th width="12%">FECHA</th>
            <th>CLIENTE</th>
            <th>CONCEPTO</th>
            <th width="10%">VALOR</th>
            <th width="5%"></th>
        </tr>
    </thead>
    <tbody class="buscar">
        <?php 
            while ($reg=mysqli_fetch_array($query))
            {
                $abo_numero=$reg['abo_numero'];
                $abo_fecha=$reg['abo_fecha'];
                $abo_concepto=$reg['abo_concepto'];
                $abo_clie_nombre=$reg['abo_clie_nombre'];
                $abo_valor=$reg['abo_valor'];
                $mov_id=$reg['movimientos_mov_id'];
        ?>
        <tr>
            <td><?php echo $abo_numero; ?></td>
            <td><?php echo $abo_fecha; ?></td>
            <td><?php echo  $abo_clie_nombre; ?></td>
            <td><?php echo $abo_concepto;?></td>
            <td><p class="pull-right"><?php echo number_format($abo_valor,0); ?></p></td>
            <td> 
                <a href="libraries/tcpdf/documentos/recibos_de_pago.php?mov_id=<?php echo $mov_id; ?>" title="Imprimir Recibo" class="btn btn-xs btn-success" target="_blank"> <i class="btn-icon-only icon-print"></i></a>
            </td>
        <?php }?>
        <tr>
            <td colspan=6><span class="pull-right">
                <?php echo paginate($reload, $page, $total_pages, $adjacents); ?></span>
            </td>
        </tr>
    </table>
<?php } } ?>