<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');

if (isset($_POST['art_id'])){ $art_id=$_POST['art_id'];}
if (isset($_POST['art_id_bod'])){ $art_id_bod=$_POST['art_id_bod'];}
$datoos=mysqli_query($con,"SELECT * FROM articulos where art_id='$art_id' and empresa='$empresa' ") ;
$dato=mysqli_fetch_array($datoos);

$atri1=mysqli_query($con,"SELECT * FROM articulos_has_bodegas where art_id='$art_id_bod'");
$atri1 = mysqli_fetch_array($atri1);
$atributo1=$atri1['atributo1'];

$atri11=mysqli_query($con,"SELECT * FROM atributos1 where atri_id='$atributo1'");
$atri11 = mysqli_fetch_array($atri11);
if (isset($atri11)) 
{                    
    $atri_nombre=$atri11['atri_nombre'];
}
else
{
    $atri_nombre='';
}

$atributo2=$atri1['atributo2'];
$atri2=mysqli_query($con,"SELECT * FROM atributos2 where atri_id2='$atributo2'");
$atri2 = mysqli_fetch_array($atri2);
if (isset($atri2)) 
{                    
    $atri_nombre2=' - '.$atri2['atri_nombre2'];
}
else
{
    $atri_nombre2='';
}

$atributos=$atri_nombre .$atri_nombre2;

?>
<script>
$(document).ready(function()
{
  	$("#modal").modal("show");
});
</script>
<form method="post" action="" id="form_info" name="form_info" >
    <div id="modal" class="modal fade" tabindex="-1" role="dialog" style="z-index: 10000;">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">INFORMACIÓN </h4>
                </div>
                <div class="modal-body">
                    <div class="row" style="padding:10px">
                    	<div class="col-md-12">
                    	  	<div id="resul"></div>
                    	</div>
                         <div class="col-md-12">
                            <textarea class="form-control" name="art_nombre" rows="3" readonly><?php echo $dato['art_nombre'];echo ' '; echo $atributos;?></textarea>
                        </div>
                        <div class="col-md-3">
                            <label for="codigo_item" class="control-label">Codigo</label>
                            <input type="text" class="form-control" name="art_referencia" value="<?php echo $dato['art_referencia']; ?>" readonly>
                            <input type="hidden" name="art_id" value="<?php echo $dato['art_id']; ?>">
                            <input type="hidden" name="art_id_bod" value="<?php echo $art_id_bod; ?>">
                        </div>
                        <div class="col-md-3">
                            <label for="cantidad_item" class="control-label">Precio</label>
                            <input type="number" class="form-control" value="<?php echo $dato['art_precio_costo']; ?>" name="precio" required>
                        </div>
                        <div class="col-md-3">
                            <label for="cantidad_item" class="control-label">Cantidad</label>
                            <input type="number" class="form-control" value="1" name="cantidad" required>
                        </div>
                        <div class="col-md-3">
                            <label for="" class="control-label">Estado</label>
                            <select  name="estado"  class="form-control name_list" required>
                                <option value=""></option>
                                <option value="Sin Vender">Sin Vender</option>
                                <option value="Vendido">Vendido</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label for="precio_item" class="control-label">Problema</label>
                            <textarea class="form-control input-sm"  name="problema" rows="4" ></textarea>
                        </div>
                        <div class="col-md-6">
                            <label for="descuento_item" class="control-label">Accesorios</label>
                            <textarea class="form-control input-sm" id="accesorios" name="accesorios" rows="4" ></textarea>
                        </div>
                    </div>      
                    <div class="modal-footer">
                      	<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                       	<button type="submit" class="btn btn-success" value="agregar" id="agregar" name="agregar" ><i class="btn-icon-only icon-ok"></i>Agregar</button>
                    </div>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->  
</form> 
<script >
$("#form_info" ).submit(function( event ) {
    $('#agregar').attr("disabled", true);
    var parametros = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "php_garantias_proveedor/agregrar_temp.php",
        data: parametros,
        beforeSend: function(objeto){
            $('#resul').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
            $("#resul").html(datos);
            $('#agregar').attr("disabled", false);
            document.form_info.cantidad.value="1";
        	document.form_info.estado.value="Sin Vender";
        	document.form_info.problema.value="";
        	document.form_info.accesorios.value="";
            $('#modal').modal('hide')
            loadTabla();
         }
    });
    event.preventDefault();
})
</script>