<?php $r="../";
require_once($r."inc/funciones.php");
validNotSession($r);
$spe=$_SESSION['perfil'];
if($spe!=$pru && $spe!=$psu){exit(header("Location:".$r."dashboard.php?error=Area  Restringida"));} 
$mysqli = connectDB($r);
$iduser=$_SESSION['userid'];

if($spe!=$psu){
?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body>
  <?php include "nav.php"; 
$row1 = $mysqli->query("SELECT * FROM z_pedidos WHERE estado='2' AND idrutero=$idrutero ORDER by codigopedido DESC");?>
  
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="card-header">
          <i class="fa fa-table"></i> MIS PEDIDOS</div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Nombre</th>
                  <th>Cliente</th>
                  <th>Direccion</th>
                  <th>Fecha de entrega</th>
                  <th>Codigo</th>
                  <th>Codigo</th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Nombre</th>
                  <th>Cliente</th>
                  <th>Direccion</th>
                  <th>Fecha de entrega</th>
                  <th>Codigo</th>
                  <th>Codigo</th>
                </tr>
              </tfoot>
              <tbody>
                    <?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr>
                        <td><?php $usuario = suser($row2["iduser"]); echo $usuario['nombre'];?></td>
                        <td><?php $cliente = sclien($row2["idcliente"]); echo $cliente['nombre'];?></td>
                        <td><?php echo $cliente['direccion'];?></td>
                        <td><?php echo $row2["fechaentrega"]; ?></td>
                        <td><?php echo $row2["codigopedido"]; ?></td>
                        <td>
                        <a class="btn_default text-warning h5"  href="editar.php?id=<?php echo $row2["codigopedido"] ?>" target="_blank"><i class="fa fa-pencil"></i></a>
                        <a class="btn_default text-primary h5"  href="imprimir8.php?code=<?php echo $row2["codigopedido"] ?>" target="_blank"><i class="fa fa-print"></i></a><a class="btn_default text-success h5"  href="my.bluetoothprint.scheme://https://practipastajj.com/dashboard/movil/a.php?code=<?php echo $row2["codigopedido"] ?>" target="_blank"><i class="fa fa-print"></i></a></td>
                   </td>
                        </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>            <a class="btn btn-primary btn-block" href="my.bluetoothprint.scheme://https://practipastajj.com/dashboard/movil/a.php?rutero=<? echo $idrutero;?>" target="_blank">imprimir ruta</a>
        </div>
      </div>
    </div>

<script>
    function popitup(url){
	    newwindow=window.open(url,'name','height=600,width=320'); 
	    if (window.focus) {newwindow.print();}
	    return false; 
    }
</script>
  <?php include "foot.php"; ?>
  
    
<script>
      $('#dataTable').DataTable( {
        "lengthMenu": [[ 50, 100, 500, -1], [ 50, 100, 500, "All"]],
         "order": [[ 2, "desc" ]]
    } );
  </script>
</body>
</html>    
 <? }else{ ?>  
 <!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body>
  <?php include "nav.php";  ?>
    
  
    <div class="container-fluid">
        <?  $row = $mysqli->query("SELECT * FROM z_ruteros WHERE eliminado='0' ");
                while($ruteros = $row->fetch_assoc()) {
                    $idrutero=$ruteros[id];
                $row1 = $mysqli->query("SELECT * FROM z_pedidos WHERE estado='2' AND idrutero=$idrutero ORDER by codigopedido DESC");?>
      <div class="card mb-3">
        <div class="card-header">
          <i class="fa fa-table"></i> RUTA DE <? echo $ruteros[nombre]; ?></div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable<? echo $ruteros[id]; ?>" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Nombre</th>
                  <th>Cliente</th>
                  <th>Direccion</th>
                  <th>Fecha de entrega</th>
                  <th>Codigo</th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Nombre</th>
                  <th>Cliente</th>
                  <th>Direccion</th>
                  <th>Fecha de entrega</th>
                  <th>Codigo</th>
                </tr>
              </tfoot>
              <tbody>
                    <?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr>
                        <td><?php $usuario = suser($row2["iduser"]); echo $usuario['nombre'];?></td>
                        <td><?php $cliente = sclien($row2["idcliente"]); echo $cliente['nombre'];?></td>
                        <td><?php echo $cliente['direccion'];?></td>
                        <td><?php echo $row2["fechaentrega"]; ?></td>
                        <td><?php echo $row2["codigopedido"]; ?></td>
                        </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>            <a class="btn btn-primary btn-block" href="my.bluetoothprint.scheme://https://practipastajj.com/dashboard/movil/a.php?rutero=<? echo $idrutero;?>" target="_blank">imprimir ruta</a>
        </div>
      </div>
      <script>
      $('#dataTable<? echo $ruteros[id]; ?>').DataTable( {
        "lengthMenu": [[ 50, 100, 500, -1], [ 50, 100, 500, "All"]],
         "order": [[ 2, "desc" ]]
    } );
  </script>
      <? } ?>
    </div>

<script>
    function popitup(url){
	    newwindow=window.open(url,'name','height=600,width=320'); 
	    if (window.focus) {newwindow.print();}
	    return false; 
    }
</script>
  <?php include "foot.php"; ?>
  
    

</body>
</html>   
 <? } ?>  