<?php
session_start();
require_once('conexion.php');
require_once('include/sesiones.php');
if (isset($_SESSION['usu_nombre']))
{
    $regis=mysqli_query($con,"SELECT * from permiso where modulo_mod_id='20' and usuario_usu_id='$usu_id'") or die(mysqli_error($con));
    $reg=mysqli_fetch_array($regis);
    if($reg['per_visualizar']=="Activo")
    {
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include ('head.php') ?>
</head>
<body >
<?php
$inicio="";
$M_inventario="";
$M_contactos="";
$M_compras="";
$M_ventas="active";
$M_pedidos="";
$M_pos="";
$R_reportes="";

$cotizacion="";
$ventas="active";
$periodica="";
$clientes="";
$cartera="";
$garantias="";
$abonos="";
$cotizacion_online="";


include ('menu.php');
?> 
<div class="main">
    <div class="col-md-2"> 
        <?php include ('include/menu_ventas.php');?>
    </div> <!-- /span6 -->
    <div class="col-md-10">  
        <div class="widget stacked">
            <div class="widget-content">
                <div id="resultados_ser"></div> 
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-striped">
                        <tr>
                            <th>CODIGO</th>
                            <th>CANT.</th>
                            <th>DESCRIPCION</th>
                            <th><span class="pull-right">PRECIO UNIT.</span></th>
                            <th><span class="pull-right">PRECIO TOTAL</span></th>
                            <th width="10%"></th>
                        </tr>
                        <?php
                        $ven_id=$_GET['ven_id'];
                        $sql=mysqli_query($con, "SELECT sum(veab_abono) as total from venta_abonos where ventas_ven_id='$ven_id' ");
                        $sql=mysqli_fetch_array($sql);
                        $total_abono=$sql['total'];
                        $total_real=0;
                        $sql=mysqli_query($con, "SELECT * from venta_detalle where ventas_ven_id='$ven_id'");
                        while ($row=mysqli_fetch_array($sql))
                        {
                            $vend_cantidad_dev=$row['vend_cantidad_dev'];
                            $vend_precio=$row['vend_precio'];
                            $vend_iva=$row['vend_iva'];
                            $vend_desc=$row['vend_desc'];
                            $precio_total_dev=$vend_precio*$vend_cantidad_dev;
                            $total_real+=$precio_total_dev;//Sumador
                        }

                        $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
                        ?>
                            <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,0);?></span></td>
                                <td><span class="pull-right"><?php echo number_format($precio_total,0);?></span></td>
                                <td>
                                  <a href="#" data-id="<?php echo $id;?>" class="btn btn-xs btn-info btn-serial">SERIALES</a>
                                </td>
                            </tr>   
                        <?php } ?>
                    </table>
                </div> <!-- /.table-responsive -->
            </div> <!-- /.widget-content -->
        </div> <!-- /widget --> 
    </div> <!-- /span9 -->
</div> <!-- /main -->

<script>
    $(".btn-serial").click(function(){
        id = $(this).data("id");
        $.get("php_ventas/form_registrar_serial.php","id="+id,function(data){
            $("#form-serial").html(data);
        });
        $('#seriale').modal('show');
    });
</script>
  
<div class="modal fade" id="seriale" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <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">MODIFICAR SERIALES</h4>
            </div>
            <div class="modal-body">
                <div id="form-serial"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
    include ('php_caja/caja_abrir.php');
    include ('script.php');
?>
<script type="text/javascript" src="php_ventas/ajax.js"></script>
<script>
function enviar_email(id_factura,email){
    VentanaCentrada('./pdf/documentos/archivo_temp_email_venta.php?id_factura='+id_factura+'&email='+email,'Factura','','800','600','true');
    }
</script>
  </body>
</html>
<?php
}
else
{
   echo '<script>alert("No tienes permiso para ver esta pagina")</script>';
   echo '<script> setTimeout("history.back(1)", 0); </script>';
}
}
else
{
    echo '<script>location.href = "index.php";</script>';
}
?>