<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');
$vent_id=$_GET['vent_id']; 

$sql=mysqli_query($con,"SELECT * FROM venta_detalle_temp where vent_id='$vent_id'");
$row=mysqli_fetch_array($sql);
$art_art_id=$row['art_art_id'];
$vent_art_id=$row['vent_art_id'];
$vent_cantidad=$row['vent_cantidad'];

?>
<div id="div_registro_lote"></div>
<form role="form" id="registro_lote" >      
	<input type="hidden" name="vent_id" value="<?php echo $vent_id; ?>">
	<input type="hidden" name="art_art_id" value="<?php echo $art_art_id; ?>">
	
	<div class="">
	    <label>Lotes Disponible</label>
	    <select id="lote" name="lote" class="form-control input-sm" onchange="miFuncion($(this).val());" required>
	   	<option value=""> - - </option>
			<?php
				$datos = mysqli_query($con,"SELECT * FROM kardex_compra where art_id_bod='$art_art_id' and lote<>'' and kar_cantidad_v>0") ;
				while( $fila = mysqli_fetch_array( $datos ) )
				{
				echo' <option value="'.$fila['kar_id'].'">'.$fila['lote'].'</option>';
				}
			?>
	   </select>
	</div> <!-- /.form-group -->
	<div id="div_cantidad"></div>
	<div class="">
	    <label>Cantidad a Vender</label>
	    <input type="hidden" name="cantidad_temp" class="form-control input-sm" autocomplete="off" value="<?php echo $vent_cantidad; ?>" autofocus="autofocus" required>
	    <input type="text" name="cantidad" class="form-control input-sm" autocomplete="off" value="<?php echo $vent_cantidad; ?>" autofocus="autofocus" required>
	</div> <!-- /.form-group -->
	          
	<div class="modal-footer">
	    <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
        <button type="submit" id="btn_registrar_Lote" class="btn btn-success"><i class="icon-ok"> Registrar</i></button>
	</div>
</form>
<script>
$("#registro_lote").submit(function( event ) {
$('#btn_registrar_Lote').attr("disabled", true);
var parametros = $(this).serialize();
   	$.ajax({
   	    type: "POST",
        url: "php_facturar/registrar_lote.php",
        data: parametros,
        beforeSend: function(objeto){
           $('#div_registro_lote').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
       success: function(datos){
       $("#div_registro_lote").html(datos);
       $('#btn_registrar_Lote').attr("disabled", false);
      }
  	});
  	event.preventDefault();
})


function miFuncion(lote){
$("#lote").val(lote);
    $.get("./php_buscador/cantidad_lotes_ventas.php?lote="+lote,function(data){
    $("#div_cantidad").html(data);
  })
}
</script>