<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');
$ven_id=$_GET['ven_id'];
?>
<div class="widget-header">
    <i class="icon-file-text"></i>
    <h3>HISTORIAL </h3>
</div> <!-- /.widget-header -->
<table class="table table-bordered table-hover table-striped">
     <tr>
        <th width="8%">FECHA</th>
        <th width="5%">CODIGO</th>
        <th Width="5%">CANTIDAD</th>
        <th>DESCRIPCION</th>
        <th Width="10%"><span class="pull-right">TOTAL</span></th>
        <th width="5%"></th>
    </tr>
    </tr>
    <?php
    $sumador_total=0;
    $sql=mysqli_query($con, "SELECT * from venta_detalle where ventas_ven_id='$ven_id'");
    while ($row=mysqli_fetch_array($sql))
    {
        $id=$row["vend_id"];
        $vend_id=$row["vend_id"];
        $vend_art_id=$row["vend_art_id"];
        $vend_referencia=$row["vend_referencia"];
        $vend_nombre=$row['vend_nombre'];
        $vend_cantidad=$row['vend_cantidad'];
        $vend_cantidad_dev=$row['vend_cantidad_dev'];
        $vend_precio=$row['vend_precio'];
        $vend_iva=$row['vend_iva'];
        $vend_desc=$row['vend_desc'];
        $descuento=($vend_desc/100)*$vend_precio;

        $precio_total=$vend_precio*$vend_cantidad;
        $sumador_total+=$precio_total;//Sumador
    }

   
    $total_dev=0;
    $sql3=mysqli_query($con, "SELECT * from devolucion where ventas_ven_id='$ven_id'");
    while ($row3=mysqli_fetch_array($sql3))
    {
        $dev_id=$row3["dev_id"];
        $dev_fecha=$row3["dev_fecha"];
        $dev_art_id=$row3["dev_art_id"];
        $dev_referencia=$row3["dev_referencia"];
        $dev_nombre=$row3['dev_nombre'];
        $dev_cantidad=$row3['dev_cantidad'];
        $dev_precio=$row3['dev_precio'];
        $total_dev+=$dev_precio;//Sumador

    ?>
    <tr>
        <td><?php echo $dev_fecha;?></td>
        <td><?php echo $dev_referencia;?></td>
        <td><?php echo $dev_cantidad;?></td>
        <td><?php echo $dev_nombre;?></td>
        <td><span class="pull-right"><?php echo number_format($dev_precio,0);?></span></td>
        <td> 
            <a href="#" onclick="eliminar('<?php echo $dev_id;?>')" title="Eliminar Devolucion" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>
        </td>
    </tr>
<?php } ?>

 <tr>
        <td colspan=4><span class="pull-right">DEVOLUCIONES $</span></td>
        <td><span class="pull-right"><strong><p style="color: red"><?php echo number_format($total_dev,0);?></p></strong></span></td>
        <td></td>
    </tr>
   <!--  <tr>
        <td colspan=6><span class="pull-right">ABONOS $</span></td>
        <td><span class="pull-right"><strong><?php echo number_format($total_abono,0);?></strong></span></td>
        <td></td>
    </tr>-->
    <tr>
        <td colspan=4><span class="pull-right">TOTAL $</span></td>
        <td><span class="pull-right"><strong><?php echo number_format($sumador_total-$total_dev,0);?></strong></span></td>
        <td></td>
    </tr>
</table>

<script>
function eliminar (dev_id)
{
    if (confirm("Realmente deseas eliminar la devolucion")){ 
    $.ajax({
        type: "POST",
        url: "php_pos/eliminar_devolucion.php",
        data: "dev_id="+dev_id,

        beforeSend: function(objeto){
         $('#resultados').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
        $("#resultados").html(datos);
        loadtabla();
        }
        });
    }
} 
</script>