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

$sql=mysqli_query($con,"SELECT * FROM cotizacion_detalle where cotd_id='$cotd_id'");
$row=mysqli_fetch_array($sql);
$art_art_id=$row['art_id_bod'];
$vent_art_id=$row['cotd_art_id'];
$vent_cantidad=$row['cotd_cantidad'];



?>
<div id="div_registro_lote"></div>
<form role="form" id="registro_lote" >      
	<input type="hidden" name="cotd_id" value="<?php echo $cotd_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_reservas/z_agregar_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>