<?
$r = "../";
$code=$_GET['code'];
require_once($r."inc/funciones.php");
$titlepage = 'Pedidos Imprimir';
validNotSession($r);

$spe=$_SESSION['perfil'];
$mysqli = connectDB($r);
roleaccess(1440);
$row1 = $mysqli->query("SELECT * FROM z_pedidos WHERE z_pedidos.estado!='0' AND tipopedido!='RV' ORDER BY id DESC LIMIT 300");
?>

  <?php include $r."inc/head.php"; ?>
<body class="fixed-nav sticky-footer sidenav-toggled bg-dark" id="page-top">
  <?php include $r."inc/nav.php"; ?>
 
  <div class="content-wrapper">
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="card-header h3">
          <i class="fa fa-table"></i> IMPRIMIR</div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered table-" id="dataTable" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Cliente</th>
                  <th>Codigo de Pedido</th>
                  <th>fecha de entrega</th>
                  <th>acciones</th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Cliente</th>
                  <th>Codigo de Pedido</th>
                  <th>fecha de entrega</th>
                  <th>acciones</th>
                </tr>
              </tfoot>
              <tbody><?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr <? if($code==$row2['codigopedido']){echo 'class="text-danger"';} ?>>
                    <td><? $clien=sclien($row2['idcliente']); echo $clien['nombre']; ?></td>
                    <td><? echo "<b>".$row2["tipopedido"]." </b>".$row2["codigopedido"]; ?></td>
                    <td><? echo $row2['fechaentrega']; ?></td>
                    
                    <td width="20px">
                        <?php if($row2['tipopedido']!='F'){ ?>
                        
                        <a class="btn_default text-primary h5" title="IMPRESION NOTA DE PEDIDO"  onClick="return popitup('imprimir-1.php?code=<?php echo $row2["codigopedido"] ?>')" href="imprimir-1.php?code=<?php echo $row2["codigopedido"] ?>" target="_blank"><i class="fa fa-print"></i></a>
                        <?php } else{ ?>
                        
                        <a class="btn_default text-primary h5" title="IMPRESION FACTURA"  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>
                        <?php } ?>
                        <!--<a class="btn_default <? if($row2['print']==0){ ?> text-muted<? }else{?>text-warning<? } ?> h5" title="IMPRESION BODEGA"  onclick="printbod(this,<?php echo $row2["id"] ?>)" style="cursor:pointer"><i class="fa fa-print"></i></a>-->
                        <a class="btn_default text-success h5"  title="IMPRESION BLUETHOOD" 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>
                        </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>
        </div>
        <a class="btn btn-success" href="/admin/pedido/consultar.php">Consultar Pedidos antiguos</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 $r."inc/foot.php"; ?>
  
    
<script>
      $('#dataTable').DataTable( {
        "lengthMenu": [[10,20,50,100,500, -1], [10,20,50,100,500, "Todos"]],
         "order": [[ 2, "desc" ]]
    } );
    function printbod(element,idpedido){
        
        $.post( "printbod.php", { idpedido: idpedido })
          .done(function( data ) {
              if(data == 1){
                  $(element).removeClass('text-muted');
                  $(element).addClass('text-warning');
              }
              if(data == 0){
                  $(element).removeClass('text-warning');
                  $(element).addClass('text-muted');
              }
        });
    }
  </script>
</body>
</html>