<?php $r="../";
require_once($r."inc/funciones.php");
validNotSession($r);
$mysqli = connectDB($r);
$iduser=$_SESSION['userid'];
$row1 = $mysqli->query("SELECT * FROM z_pedidos WHERE estado='2' AND iduser='$iduser' ORDER by codigopedido DESC");

?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body>
  <?php include "nav.php"; ?>
  
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="card-header">
          <i class="fa fa-table"></i> MIS PEDIDOS <? echo $iduser;?></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>fecha de creacion</th>
                  <th>Fecha de entrega</th>
                  <th>Codigo</th>
                  <th></th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Nombre</th>
                  <th>Cliente</th>
                  <th>fecha de creacion</th>
                  <th>Fecha de entrega</th>
                  <th>Codigo</th>
                  <th></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 $row2["fecha"]; ?></td>
                        <td><?php echo $row2["fechaentrega"]; ?></td>
                        <td><?php echo $row2["codigopedido"]; ?></td>
                        <td width="100px"><a class="btn_default text-primary h5" href="editar.php?id=<?php echo $row2["codigopedido"] ?>"><i class="fa fa-pencil"></i></a>
                        <a class="btn_default text-primary h5" href="ver.php?id=<?php echo $row2["codigopedido"] ?>"><i class="fa fa-eye"></i></a>
                        <a class="btn_default text-primary h5"  onClick="return popitup('imprimir.php?code=<?php echo $row2["codigopedido"] ?>')" href="imprimir.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://quimiforen.com/admin/movil/a.php?code=<?php echo $row2["codigopedido"] ?>" target="_blank"><i class="fa fa-print"></i></a></td>
                        </td>
                    </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>
        </div>
      </div><a class="btn btn-primary btn-block" href="index.php" title="Nuevo Pedido"><i class="fa fa-plus h3"></i> Nuevo Pedido</a>
    </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": [[25, 50, 100, 500, -1], [25, 50, 100, 500, "All"]],
         "order": [[ 2, "desc" ]]
    } );
  </script>
</body>
</html>    
    