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

$sql=mysqli_query($con, "SELECT * from compra_detalle where  comd_id='$comd_id'");
$resul = mysqli_fetch_array($sql);
$comd_art_id=$resul['comd_art_id'];
$comd_nombre=$resul['comd_nombre'];
$comd_cantidad=$resul['comd_cantidad'];
$com_id=$resul['compras_com_id'];

$sql4=mysqli_query($con, "SELECT * from seriales_compra where  compra_detalle_comd_id='$comd_id'  ");
$result4 = mysqli_num_rows($sql4);
$can_ser=$comd_cantidad-$result4;

?>
<form role="form" method="POST" action="" id="otro_ser" name="otro_ser">  
    <input type="hidden" name="com_id" value="<?php  echo $com_id; ?>">
    <input type="hidden" name="id" value="<?php  echo $comd_id; ?>">
    <input type="hidden" class="form-control" name="comd_art_id" id="comd_art_id" value="<?php echo $comd_art_id; ?>" >
    <?php 
        if ($result4<$comd_cantidad) 
        {
            $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="" required=""  autocomplete="off">
    <?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_compras/registrar_serial_m.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>