<?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 = 20;
    $adjacents  = 4; 
    $offset = ($page - 1) * $per_page;
    $count_query   = mysqli_query($con, "SELECT count(*) AS numrows FROM dian_documento_soporte ");
    $row= mysqli_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = './P_pos.php';
    $sql="SELECT * FROM dian_documento_soporte where empresa='$empresa' order by docs_id desc";
    $query = mysqli_query($con, $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="10%">N° DOC</th>
                <th width="10%">FECHA</th>
                <th>PROVEEDOR</th>
                <th>TOTAL</th>
                <th>ESTADO</th>
                <th width="15%"></th>
            </tr>
        </thead>
        <tbody  class="buscar">
        <?php 
        while ($reg=mysqli_fetch_array($query))
            {
                $docs_id=$reg["docs_id"];
                $docs_numero=$reg['docs_numero'];
                $docs_fecha=$reg['docs_fecha'];
                $docs_proveedor=$reg['docs_proveedor'];

                $can=mysqli_query($con,"SELECT * FROM proveedor where pro_id='$docs_proveedor'") or die(mysqli_error($con)); 
                $dato1=mysqli_fetch_array($can);
               
              ?>
            <tr>
                <td><?php echo $reg['docs_prefijo']; echo $docs_numero;?></td>
                <td><?php echo $docs_fecha;?></td>
                <td><?php echo $dato1['pro_nombre'];?></td>
                <td></td>
                <td><?php if ($reg['estado_dian']=="Aprobada") { ?>
                    <p class="pull-right"><span class="badgeazul"> <i class="btn-icon-only icon-ok"></i></span></p>
                    <?php } else { ?>
                    <p class="pull-right"><span class="badgerojo"> <i class="btn-icon-only icon-remove"></i></span></p>
                    <?php } ?>
                </td>
                <td>
                    <a href="libraries/tcpdf/documentos/documento_soporte.php?docs_id=<?php echo $docs_id;?>" target="_blank" class="btn btn-success btn-xs" ><span class="btn-icon-only icon-print"></span></a>
                    <?php if ($reg['estado_dian']=="Aprobada") { ?>

                    <?php } else { ?>
                    <a href="#" id="del-<?php echo $reg["docs_id"];?>" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>

                    <a data-id="<?php echo $reg['docs_id'];?>" title="Renviar" class="btn btn-xs btn-warning btn-dian" data-toggle="modal"><i class="btn-icon-only fa fa-upload"></i></a> 
                    <script>
                    $("#del-"+<?php echo $reg["docs_id"];?>).click(function(e){
                        e.preventDefault();
                        p = confirm("Estas seguro?");
                        if(p){
                            $.get("./php_doc_soporte/eliminar.php","docs_id="+<?php echo $reg["docs_id"];?>,function(data){
                                documentosoporte(1);
                            });
                        }
                    });
                    </script>
                    <?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>
    $(".btn-dian").click(function(){
        id = $(this).data("id");
        $.get("./php_doc_soporte/forms_dian_renviar.php","id="+id,function(data){
            $("#form-dian").html(data);
        });
        $('#dian').modal('show');
    });
</script>
