<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');
$ven_id=$_GET['ven_id'];
?>
<div class="table-responsive">
    <table class="table table-bordered table-hover table-striped">    
        <tr>
        <th width="5%">CODIGO</th>
        <th Width="5%">CANTIDAD</th>
        <th>DESCRIPCION</th>
        <th Width="5%"><span class="pull-right">PRECIO_UNITARIO</span></th>
        <th width="10%"></th>
        <th width="5%"></th>
    </tr>
    <?php
    $sql2=mysqli_query($con, "SELECT * from venta_detalle where ventas_ven_id='$ven_id'");
    while ($row2=mysqli_fetch_array($sql2))
    {
        $id=$row2["vend_id"];
        $vend_id=$row2["vend_id"];
        $vend_art_id=$row2["vend_art_id"];
        $vend_referencia=$row2["vend_referencia"];
        $vend_nombre=$row2['vend_nombre'];
        $vend_cantidad=$row2['vend_cantidad'];
        $vend_cantidad_dev=$row2['vend_cantidad_dev'];
        $vend_precio=$row2['vend_precio'];
        $vend_iva=$row2['vend_iva'];
        $vend_desc=$row2['vend_desc'];
        $descuento=($vend_desc/100)*$vend_precio;
    ?>
        <input type="hidden" id="ven_id" value="<?php echo $ven_id;?>">
        <input type="hidden" id="vend_art_id<?php echo $vend_id;?>" value="<?php echo $vend_art_id;?>">
        <input type="hidden" id="vend_referencia<?php echo $vend_id;?>" value="<?php echo $vend_referencia;?>">
        <input type="hidden" id="vend_nombre<?php echo $vend_id;?>" value="<?php echo $vend_nombre;?>">
        <input type="hidden" id="vend_precio<?php echo $vend_id;?>" value="<?php echo $vend_precio-$descuento;?>">
        <input type="hidden" id="vend_iva<?php echo $vend_id;?>" value="<?php echo $vend_iva;?>">
        <input type="hidden" id="vend_desc<?php echo $vend_id;?>" value="0">
        <input type="hidden" id="tipo<?php echo $vend_id;?>" value="articulo">
    <tr>
        <td><?php echo $vend_referencia;?></td>
        <td><?php echo $vend_cantidad;?></td>
        <td><?php echo $vend_nombre;?></td>
        <td><span class="pull-right"><?php echo number_format($vend_precio-$descuento,0);?></span></td>
        <td><input type="text" class="form-control input-sm" id="cantidad<?php echo $vend_id;?>" value="1" max="<?php echo $vend_cantidad;?>" ></td>
        <td><a onclick="agregar_nota('<?php echo $vend_id ?>')" class="btn btn-info btn-devo btn-xs"><i class="btn-icon-only icon-plus"></i></a></a></td>
    </tr>   
    <?php } ?>


    <?php
    $sql2=mysqli_query($con, "SELECT * from venta_detalle_combo where ven_id='$ven_id'");
    while ($row2=mysqli_fetch_array($sql2))
    {
        $id=$row2["vdc_id"];
        $vdc_id=$row2["vdc_id"];
        $combo_id=$row2["combo_id"];
        $combo_referencia=$row2["combo_referencia"];
        $combo_nombre=$row2['combo_nombre'];
        $combo_cantidad=$row2['combo_cantidad'];
        $combo_precio=$row2['combo_precio'];
        $combo_iva=$row2['combo_iva'];
        $combo_desc=$row2['combo_desc'];
        $descuento=($vend_desc/100)*$combo_precio;
    ?>
        <input type="hidden" id="ven_id" value="<?php echo $vdc_id;?>">
        <input type="hidden" id="vend_art_id<?php echo $vdc_id;?>" value="<?php echo $combo_id;?>">
        <input type="hidden" id="vend_referencia<?php echo $vdc_id;?>" value="<?php echo $combo_referencia;?>">
        <input type="hidden" id="vend_nombre<?php echo $vdc_id;?>" value="<?php echo $combo_nombre;?>">
        <input type="hidden" id="vend_precio<?php echo $vdc_id;?>" value="<?php echo $combo_precio-$descuento;?>">
        <input type="hidden" id="vend_iva<?php echo $vdc_id;?>" value="<?php echo $combo_iva;?>">
        <input type="hidden" id="vend_desc<?php echo $vdc_id;?>" value="0">
        <input type="hidden" id="tipo<?php echo $vdc_id;?>" value="combo">
    <tr>
        <td><?php echo $combo_referencia;?></td>
        <td><?php echo $combo_cantidad;?></td>
        <td><?php echo $combo_nombre;?></td>
        <td><span class="pull-right"><?php echo number_format($combo_precio-$descuento,0);?></span></td>
        <td><input type="text" class="form-control input-sm" id="cantidad<?php echo $vdc_id;?>" value="1" max="<?php echo $combo_cantidad;?>" ></td>
        <td><a onclick="agregar_nota('<?php echo $vdc_id ?>')" class="btn btn-info btn-devo btn-xs"><i class="btn-icon-only icon-plus"></i></a></a></td>
    </tr>   
    <?php } ?>



    </table>
</div>
<script>
function agregar_nota (vend_id)
{
    var ven_id=document.getElementById('ven_id').value;
    var vend_art_id=document.getElementById('vend_art_id'+vend_id).value;
    var vend_referencia=document.getElementById('vend_referencia'+vend_id).value;
    var vend_nombre=document.getElementById('vend_nombre'+vend_id).value;
    var vend_precio=document.getElementById('vend_precio'+vend_id).value;
    var vend_iva=document.getElementById('vend_iva'+vend_id).value;
    var vend_desc=document.getElementById('vend_desc'+vend_id).value;
    var cantidad=document.getElementById('cantidad'+vend_id).value;
    var tipo=document.getElementById('tipo'+vend_id).value;

    if (isNaN(cantidad))
    {
    alert('Esto no es un numero');
    document.getElementById('cantidad'+vend_id).focus();
    return false;
    }

    $.ajax({
    type: "POST",
    url: "./php_doc_nota_credito/nota_credito_agregar_temp.php",
    data: "vend_art_id="+vend_art_id+"&vend_referencia="+vend_referencia+"&vend_nombre="+vend_nombre+"&vend_precio="+vend_precio+"&vend_iva="+vend_iva+"&vend_desc="+vend_desc+"&cantidad="+cantidad+"&ven_id="+ven_id+"&tipo="+tipo,

    beforeSend: function(objeto){
    $("#resultados_temp").html("Mensaje: Cargando...");
    },
    success: function(datos){
    $("#resultados_temp").html(datos);
    loadtablanota();
    }
    });
}
</script>