<?php
session_start();
include "../conexion.php";
require_once('../include/sesiones.php');
$est=mysqli_query($con,"SELECT * FROM modulo_permiso WHERE mod_id='19' and modp_nombre='Modificar Precio' and usuario='$usu_id' ") or die(mysqli_error($con));
$est=mysqli_fetch_array($est);
if($est['estado']=='Activo')
{
    $readonly='';
}
else
{
    $readonly='readonly';
}

$cotd_id=$_GET['id'];   
$can=mysqli_query($con,"SELECT * from cotizacion_detalle where cotd_id ='$cotd_id' ") or die(mysqli_error($con)); 
$dato=mysqli_fetch_array($can);
$cotdd_id=$dato['cotd_id'];
$cotd_art_id=$dato['cotd_art_id'];
$cotd_referencia=$dato['cotd_referencia'];
$cotd_nombre=$dato['cotd_nombre'];
$cotd_precio=$dato['cotd_precio'];
$cotd_cantidad=$dato['cotd_cantidad'];
$cotd_desc=$dato['cotd_desc'];

$registros=mysqli_query($con,"SELECT * FROM articulos WHERE art_id='$cotd_art_id' and empresa='$empresa' ") or die(mysqli_error($con));
$art=mysqli_fetch_array($registros); 
$art_venta_min=$art['art_venta_min'];
?>
<form role="form" id="actualizar" >      
    <div id="resultado_edit"></div>
    <div class="row">
        <div class="col-md-8">
            <label for="codigo_item" class="control-label">Código</label>
            <input type="text" class="form-control" id="codigo_item" name="codigo_item" placeholder="" value="<?php echo $cotd_referencia; ?>" disabled required>
            <input type="hidden" name="id" value="<?php echo $cotdd_id; ?>">
        </div>
        <div class="col-md-4">
            <label for="cantidad_item" class="control-label">Cantidad</label>
            <input type="number" class="form-control" value="<?php echo $cotd_cantidad; ?>" name="cantidad" min="<?php echo $art_venta_min; ?>" required min="0">
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <label for="art_nombre" class="control-label">Descripción</label>
            <textarea class="form-control"  name="art_nombre" id="art_nombre" disabled> <?php echo $cotd_nombre; ?></textarea>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <label for="precio_item" class="control-label">Precio</label>
            <div class="input-group">
                <span class="input-group-addon">$</span>
                <input type="number" class="form-control" value="<?php echo $cotd_precio; ?>" name="precio" required <?php echo $readonly; ?> min="0" required>
                <span class="input-group-addon">.00</span>
            </div>
        </div>
        <div class="col-md-6">
            <label for="descuento_item" class="control-label">Descuento</label>
            <div class="input-group">
                <span class="input-group-addon">%</span>
                <input type="number" class="form-control" name="descuento" id="descuento" min="0" value="<?php echo $cotd_desc; ?>" <?php echo $readonly; ?> required>
            </div>  
        </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" id="btn_act">Actualizar datos</button>
    </div>
</form>

<script>
$( "#actualizar" ).submit(function( event ) {
    $('#btn_act').attr("disabled", true);
    var parametros = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "php_reservas/z_actualizar.php",
        data: parametros,
        beforeSend: function(objeto){
            $('#resultado_edit').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
            $("#resultado_edit").html(datos);
            $('#btn_act').attr("disabled", false);
            $('#editModal').modal('hide');
            $('body').removeClass('modal-open');
            $('.modal-backdrop').remove();
            loadTabla();
         }
    });
    event.preventDefault();
})
</script>