<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php'); 
$action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
if($action == 'ajax')
{
    include '../include/pagination.php'; 
    $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
    $per_page = 20;
    $adjacents  = 4; 
    $offset = ($page - 1) * $per_page;
    $count_query   = mysqli_query($api, "SELECT count(*) AS numrows FROM received_documents where customer='$identification_number'");
    $row= mysqli_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = './P_pos.php';
    $sql="SELECT * FROM received_documents where customer='$identification_number' order by id desc LIMIT $offset,$per_page ";
    $query = mysqli_query($api, $sql);
    if ($numrows>0)
       {
?>
<div class="table-responsive">
    <table class="table table-bordered table-hover table-striped" id="datos" style="font-size: 9pt;">
        <thead>
            <tr>
                <th width="20%">FECHA</th>
                <th width="10%">N° DOC</th>
                <th>PROVEEDOR</th>
                <th>TOTAL</th>
                <th>Acuse Recibo</th>
                <th>Recepcion Bienes</th>
                <th>Aceptacion Expresa</th>
                <th>Rechazo</th>
            </tr>
        </thead>
        <tbody  class="buscar">
        <?php 
        while ($reg=mysqli_fetch_array($query))
        {
          ?>
            <tr>
                <td><?php echo $reg['date_issue'];?></td>
                <td><?php echo $reg['number']; ?></td>
                <td><?php echo $reg['name_seller']; ?></td>
                <td align="right"><?php echo number_format($reg['total'],0);?></td>
                <td>
                	<?php if($reg['acu_recibo']=='0') { ?>
                		<a href="#" data-id="<?php echo $reg['id'];?>" class="acu_recibo"><i class="fa-regular fa-circle fa-xl"></i></a>
                	<?php } else { ?>
                		<i class="fa-solid fa-circle-check fa-xl" style="color: #0F39D2;"></i>

                	<?php } ?>
                </td>
                <td>
                	<?php if($reg['rec_bienes']=='0') { ?>
                		<a href="#" data-id="<?php echo $reg['id'];?>" class="acu_recepcion"><i class="fa-regular fa-circle fa-xl"></i></a>
                	<?php } else { ?>
                		<i class="fa-solid fa-circle-check fa-xl" style="color: #FFD43B;"></i>
                	<?php } ?>
                </td>
                <td>
                	<?php if($reg['aceptacion']=='0') { ?>
                		<a href="#" data-id="<?php echo $reg['id'];?>" class="acu_aceptacion"><i class="fa-regular fa-circle fa-xl"></i></a>
                	<?php } else { ?>
                		<i class="fa-solid fa-circle-check fa-xl" style="color: #23E73A;"></i>
                	<?php } ?>
                </td>
                <td>
                	<?php if($reg['rechazo']=='0') { ?>
                		<a href="#" data-id="<?php echo $reg['id'];?>" class="acu_rechazo"><i class="fa-regular fa-circle fa-xl"></i></a>
                	<?php } else { ?>
                		<i class="fa-solid fa-circle fa-xl"></i>
                	<?php } ?>
                </td>
            </tr>
           <?php }?>

            <tr>
                <td colspan=12>
                    <span class="pull-right">
                        <?php echo paginate($reload, $page, $total_pages, $adjacents); ?>
                    </span>
                </td>
            </tr>
        </table>
    </div>
<?php } } ?>

<script>
    $(".acu_recibo").click(function(){
        id = $(this).data("id");
       	var event = '1';
        $.get("./php_eventos_radian/form_acuse.php","id="+id+"&event="+event,function(data){
            $("#form-acuse").html(data);
        });
        $('#acuse').modal('show');
    });
</script>


<script>
    $(".acu_recepcion").click(function(){
        id = $(this).data("id");
       	var event = '3';
        $.get("./php_eventos_radian/form_acuse.php","id="+id+"&event="+event,function(data){
            $("#form-acuse").html(data);
        });
        $('#acuse').modal('show');
    });
</script>


<script>
    $(".acu_aceptacion").click(function(){
        id = $(this).data("id");
       	var event = '4';
        $.get("./php_eventos_radian/form_acuse.php","id="+id+"&event="+event,function(data){
            $("#form-acuse").html(data);
        });
        $('#acuse').modal('show');
    });
</script>


  
