<?php
session_start();
include "../conexion.php";
$vend_id=$_GET['vend_id'];
$id=$_GET['vend_id']; 

$sql=mysqli_query($con, "SELECT * from venta_detalle where vend_id='$vend_id'");
$resul=mysqli_fetch_array($sql);
$vend_nombre=$resul['vend_nombre'];
$vend_art_id=$resul['vend_art_id'];
$vend_cantidad_dev=$resul['vend_cantidad_dev'];
$ven_id=$resul['ventas_ven_id'];

$sql4=mysqli_query($con, "SELECT * from seriales where venta_detalle_vend_id='$vend_id'");
$result4 = mysqli_num_rows($sql4);
$can_ser=$vend_cantidad_dev-$result4;
?>

<form role="form" method="POST" action="" id="ser_reg" name="ser_reg">
    <input type="hidden" name="ven_id" value="<?php  echo $ven_id; ?>">
    <input type="hidden" name="id" value="<?php  echo $vend_id; ?>">
    <input type="hidden" class="form-control" name="vend_art_id" id="vend_art_id" value="<?php echo $vend_art_id; ?>" >     
    <?php
        if ($result4<$vend_cantidad_dev) 
        {
            $can1=mysqli_query($con,"SELECT * from  seriales_articulos where  articulos_art_id='$vend_art_id' and  estado='sin vender'") or die(mysqli_error($con)); 
            $num=mysqli_num_rows($can1);
            if($num>0)
                {
                echo '<label>SERIALES(ES) </label><br>';
                while ($row=mysqli_fetch_array($can1))
                {
            ?>
            <input type="checkbox" id="<?php echo $row['se_codigo']; ?>" name="serial[]" value="<?php echo $row['se_codigo']; ?>" >
            <label class="lab" for="<?php echo $row['se_codigo']; ?>"><?php echo $row['se_codigo']; ?></label>
            <?php } }
            else
            {
            echo '<div class="alert alert-success alert-dismissable">
                    <strong>No Tiene Seriales Registrados!</strong>
            </div>'; 
            }
            ?>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
            <button type="submit" id="btn_serial" name="btn_serial" value="btn_serial" class="btn btn-success">Registrar</button>
        </div>
    <?php }
    else
        {
        echo '<div class="alert alert-warning alert-dismissable">
                <strong>No puede registrar mas seriales!</strong>
        </div>'; 
        }?>
</form>
<script>
$( "#ser_reg" ).submit(function( event ) {
$('#btn_serial').attr("disabled", true);

var parametros = $(this).serialize();
   $.ajax({
      type: "POST",
      url: "php_ventas/registrar_serial.php",
      data: parametros,
        beforeSend: function(objeto){
         $('#resultados_ser').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
        $("#resultados_ser").html(datos);
        $('#btn_serial').attr("disabled", false);

        $('#seriale').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
       load(1);
      }
  });
  event.preventDefault();
})
</script>