<?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=12; 
$adjacents=4; 
$offset=($page-1)*$per_page;
$count_query=mysqli_query($con,"SELECT count(*) AS numrows FROM trasladoe where tra_n_traslado 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 trasladoe where tra_n_traslado like '%$q%' order by tra_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="6%">HORA</th>
            <th width="30%">ENVIADO A</th>
            <th width="15%">ENVIO</th>
            <th width="15%">ACEPTA</th>
            <th width="8%">ESTADO</th>
             <th width="10%"></th>
        </tr>
    </thead>    
    <tbody class="buscar">
    <?php while ($reg=mysqli_fetch_array($sql)){ ?>
        <tr>
            <td><?php echo $reg['tra_n_traslado']; ?></td>
            <td><?php echo $reg['tra_fecha']; ?></td>
            <td><?php echo $reg['tra_hora']; ?></td>
            <td><?php  
                $sql_tar=mysqli_query($con,"SELECT * from empresa where emp_id='".$reg['tra_empresa_d']."'");
                $bo=mysqli_fetch_array($sql_tar);
                echo $nom=$bo['emp_nombre'];?></td>
            <td>
                <?php  
                $sql_tar=mysqli_query($con,"SELECT * from usuario where usu_id='".$reg['tra_usuario']."'");
                $bo=mysqli_fetch_array($sql_tar);
                echo $usu_n=$bo['usu_nombre'];?>
            </td>
            <td>
                <?php  
                $sql_tar=mysqli_query($con,"SELECT * from usuario where usu_id='".$reg['tra_usuario_acep']."'");
                if($bo=mysqli_fetch_array($sql_tar)){
                echo $usu_n=$bo['usu_nombre']; } ?>
            </td>
            <td>
                <?php   
                $tra_estado=$reg['tra_estado'];

                if ($tra_estado=='Pendiente')
                { ?>
                    <a title="" class=""><span class="badgerojo "><i class="btn-icon-only " style="color:white;">Pendiente</i></span></a>
                <?php } 
                else 
                { ?>
                     <a title="" class=""><span class="badgeazul "><i class="btn-icon-only " style="color:white;">Aceptado</i></span></a>
                <?php } ?>
            </td>
            <td>
                              
                <a data-id="<?php echo $reg["tra_id"];?>" class="btn btn-tras btn-xs btn-info"  title="Ver Traslado"> <i class="btn-icon-only icon-eye-open"></i></a>
                <a href="libraries/tcpdf/documentos/traslado_emp.php?tra_id=<?php echo $reg['tra_id'];?>" target="_blank" class="btn btn-success btn-xs" ><span class="btn-icon-only icon-print"></span></a>
            </td>
        </tr>
    <?php }?>
        <tr>
            <td colspan=7><span class="pull-right">
                <?php echo paginate($reload, $page, $total_pages, $adjacents); ?></span>
            </td>
        </tr>
    </tbody>
 </table>
<?php } } ?>

<script type="text/javascript">
//traslado
$(".btn-tras").click(function(){
      id = $(this).data("id");
      $.get("php_traslados_emp/form_detalle.php","id="+id,function(data){
        $("#form-tras").html(data);
      });
      $('#verdetalle').modal('show');
    });
</script>

<div class="modal fade" id="verdetalle" tabindex="-1" role="dialog"  >
   <div class="modal-dialog  modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Detalle del Traslado</h4>
            </div>
                <div class="modal-body">
                    <div id="form-tras"></div>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
</div><!-- /.modal -->

<script>
$(".btn-editras").click(function(){
    id = $(this).data("id");
    $.get("./php_traslados_emp/form_eliminar.php","id="+id,function(data){
        $("#form-eli").html(data);
    });
    $('#eliminar_art').modal('show');
});
</script>
<div class="modal fade" id="eliminar_art" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Eliminar Articulos</h4>
            </div>
            <div class="modal-body">
                <div id="form-eli"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="modal_editar_tras" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Editar Traslado</h4>
            </div>
            <div class="modal-body">
                <div id="form-edi"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->