<?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='25' 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="";
$M_pedidos="";
$M_pos="";
$R_reportes="active";

$ventas="active";
$caja="";
$compra="";
$contactos="";
$inventario="";
$utilidad="";

include ('menu.php');

$desde=$_GET['desde'];
$hasta=$_GET['hasta'];
$empleadoo=$_GET['empleadoo'];
?> 
    
<div class="main">
   <div class="col-md-2">
        <?php include ('include/menu_reportes.php');?>
    </div>
    <div class="col-md-10">
        <div class="widget stacked">
            <div class="widget-content">
                <div class="widget stacked">
                    <div class="widget-content">
                        <?php include ('php_reportes/menu_ventas.php');?>  
                    </div>
                </div>
                <div class="widget stacked widget-table action-table">
                    <div class="widget-header" >
                        <h3>PEDIDOS  </h3>  
                    </div> <!-- /widget-header -->      
                    <div class="widget-content">
                        <div class="table-responsive">

<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <td style="width: 8%">N° PEDIDO</td>
            <td style="width: 15%">FECHA</td>
            <td style="width: 30%">CLIENTE </td>
            <td style="width: 25%">USUARIO</td>
            <td style="width: 10%">ESTADO</td>
            <td style="width: 20%">TOTAL </td>
            <td style="width: 10%"></td>
        </tr>
    </thead>
<?php
if($empleadoo==0)
{
    $registros=mysqli_query($con,"SELECT * FROM pedido where DATE(pen_fecha) between TIMESTAMP('$desde') and TIMESTAMP('$hasta') and sucursal='$sucursal' and empresa='$empresa' and pen_estado='Facturado' order by pen_n asc") or die(mysqli_error($con));
}
else
{
    $registros=mysqli_query($con,"SELECT * FROM pedido where usuario='$empleadoo' and TIMESTAMP(pen_fecha) between TIMESTAMP('$desde') and TIMESTAMP('$hasta') and sucursal='$sucursal' and empresa='$empresa' and pen_estado='Facturado' order by pen_n asc") or die(mysqli_error($con));
}


$total_pedido=0;
        while ($reg=mysqli_fetch_array($registros))
            {
                $pen_id=$reg['pen_id'];
    ?>
        <tr>
            <td><?php echo $reg['pen_n']; ?></td>
            <td><?php echo $reg['pen_fecha']; ?></td>
            <td><?php 
                $clie_id=$reg['clie_id']; 
                $sql_tar1=mysqli_query($con, "SELECT * from cliente where clie_id='$clie_id'");
                $bo1=mysqli_fetch_array($sql_tar1);
                echo $clie_nombre=$bo1['clie_nombre'];
            ?> </td>
            <td>
            <?php 
                $usuario=$reg['usuario']; 
                $sql_tar=mysqli_query($con, "SELECT * from usuario where usu_id='$usuario'");
                $bo=mysqli_fetch_array($sql_tar);
                echo $usu_n=$bo['usu_nombre'];
            ?>
            </td>
            <td><p class="pull-right"><?php echo $reg['pen_estado']; ?></p></td>
            <td>
                <?php 
                $total=0;
                $sumatotal=0;
                $sql_pend=mysqli_query($con, "SELECT * from pedido_detalle where pedido_pen_id='$pen_id'");
               while($det=mysqli_fetch_array($sql_pend))
               { 
                $pend_cantidad=$det['pend_cantidad'];
                $pend_precio=$det['pend_precio'];
                $total=$pend_precio*$pend_cantidad;
               
               
                 $sumatotal+=$total;
                }
                 echo number_format($sumatotal); 
                ?>
               
            </td>
            <td>
                <div class="btn-group pull-right">
                    <a href="#verdetalle<?php echo $reg['pen_id']; ?>" title="Ver Detalle" class="btn btn-xs btn-default" data-toggle="modal"><i class="btn-icon-only icon-eye-open"></i></a>  
                        <?php include ('php_pedidos/forms_detalle.php'); ?>
                </div> 
            </td>
        </tr>
            <?php 

             $total_pedido+=$sumatotal;
        }
           
            ?>
        <tr >
            <td colspan="4" ></td>
            <td style="width: 10%"><strong>TOTAL</strong></td>
            <td style=" color: green;font-size: 14px"><strong><?php echo number_format($total_pedido,0);?></strong></td>
           
        </tr>
    </table>
                        </div>
                    </div> <!-- /widget-content -->
                </div> <!-- /widget --></br></br></br>
            </div>
               </div> <!-- /widget-content -->
                </div> <!-- /widget -->
            </div>
        </form>
        </div>
   </div> <!-- /span6 -->
</div> <!-- /main -->
<script type="text/javascript">
function marcar(source) 
{
    checkboxes=document.getElementsByTagName('input'); //obtenemos todos los controles del tipo Input
    for(i=0;i<checkboxes.length;i++) //recoremos todos los controles
    {
      if(checkboxes[i].type == "checkbox") //solo si es un checkbox entramos
      {
        checkboxes[i].checked=source.checked; //si es un checkbox le damos el valor del checkbox que lo llamó (Marcar/Desmarcar Todos)
      }
    }
}
</script>
<?php
    include ('php_caja/caja_abrir.php');
    include ('script.php');
?>
</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>';
}
?>