<?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="otro_ser" name="otro_ser">  
    <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) 
        {
            $i = 1;
            while ($i <= $can_ser) {
    ?>
    <label for="art_nombre" class="control-label">Serial <?php echo $i++; ?> </label>
    <input type="text" class="form-control" name="serial[]" value="" autocomplete="off" required>
    <?php } ?>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
        <button type="submit" id="btn_otro" name="btn_otro" value="btn_otro" 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>
$("#otro_ser").submit(function(event) {
$('#btn_otro').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_otro').attr("disabled", false);

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