<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');
$prefijo=$_POST['prefijo'];
$venta_n=$_POST['venta_n'];
$can=mysqli_query($con,"SELECT * FROM ventas where ven_prefijo='$prefijo' and ven_n_venta='$venta_n'  and empresa='$empresa' order by ven_id desc") or die(mysqli_error($con)); 
$reg=mysqli_fetch_array($can); 
$ven_id=$reg['ven_id'];
if ($reg<='0')
{
?>
<div id="seleccion" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Seleccion de Producto</h4>
            </div>
            <div class="modal-body">
                <div class="alert alert-danger alert-dismissable">
                    <strong>Venta</strong> No Encontrada
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$(document).ready(function()
{
  $("#seleccion").modal("show");
});
</script>

<?php } else { ?>
<div id="seleccion" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Seleccion de Producto</h4>
            </div>
            <div class="modal-body">
            <?php
                $query=mysqli_query($con,"SELECT * from venta_detalle where ventas_ven_id='$ven_id'") or die(mysqli_error($con));
                $numero = mysqli_num_rows($query);
                if($numero>0)
                    {
                        echo "<table id='table' class='table table-striped table-bordered'>
                                <tr>
                                    <th>Referencia</th>
                                    <th>Nombre</th>
                                    <th>Precio</th>
                                    <th></th>
                                </tr>";
                    while($rowb=mysqli_fetch_array($query))
                        { ?>
                                <tr>
                                    <td ><?php echo $rowb["vend_referencia"]?></td>
                                    <td ><?php echo $rowb["vend_nombre"]?></td>
                                    <td ><?php echo $rowb["vend_precio"]?></td>
                                    <td >
                                        <a href="V_garantias_registrar.php?vend_id=<?php echo $rowb['vend_id']; ?>&&ven_id=<?php echo $ven_id; ?>" title="Agregar" class="btn btn-xs btn-info"><i class="btn-icon-only icon-plus"></i></a>
                                    </td>
                                </tr>
            <?php       }
                    echo "</table>";
                    }
            ?>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>        
<script>
$(document).ready(function()
{
  $("#seleccion").modal("show");
});
</script>
<?php }  ?>