<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php'); 
?>
<div class="table-responsive">
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th width="15%">NOMBRE</th>
                <th width="5%">%</th>
                <th width="20%">TIPO</th>
                <th>DESCRIPCIÓN</th>
                <th width="12%"></th>
            </tr>
        </thead>
        <?php
            $registros=mysqli_query($con,"SELECT * from retencion where empresa='$empresa'") or die(mysqli_error($con));
            while ($reg=mysqli_fetch_array($registros)){
            $id=$reg["ret_id"];
        ?>
            <tr>
                <td><?php echo $reg['ret_nombre']; ?></td>
                <td><?php echo $reg['ret_porcentaje'];?></td>
                <td><?php echo $reg['ret_tipo']; ?></td>
                <td><?php echo $reg['ret_descripcion']; ?></td>
                <td>
                    <a data-id="<?php echo $id;?>" class="btn btn-edit btn-xs btn-warning"> <i class="btn-icon-only icon-edit"></i></a>
                    <a href="#" class='btn btn-xs btn-danger' title='Eliminar Retención' onclick="eliminar('<?php echo $reg['ret_id'];?>');" ><i class="btn-icon-only icon-remove"></i></a> 
                </td>
            </tr>
        <?php }?>
          <tr>
    </table>
</div>

<script>
    $(".btn-edit").click(function(){
      id = $(this).data("id");
      $.get("./php_configuraciones/form_editar_retencion.php","id="+id,function(data){
        $("#form-ret").html(data);
      });
      $('#edit_retencion').modal('show');
    });
</script>

<div class="modal fade" id="edit_retencion" 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">Actualizar Retencion</h4>
            </div>
            <div class="modal-body">
                <div id="form-ret"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script type="text/javascript">
function eliminar (id)
{
    var q= $("#q").val();
    if (confirm("Realmente deseas eliminar la retencion")){ 
    $.ajax({
        type: "GET",
        url: "php_configuraciones/eliminar_retencion.php",
        data: "id="+id,"q":q,
     beforeSend: function(objeto){
         $('#loader').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
      },
        success: function(datos){
    $("#loader").html(datos);
    loadretencion();
    }
      });
    }
}
</script>