<?
$r = "../";
require_once($r."inc/funciones.php");
validNotSession($r);
$mysqli = connectDB($r);
$code=$_GET['id'];
$row1 = $mysqli->query("SELECT * FROM z_pedidos WHERE codigopedido='$code'");
$pedidos = $row1->fetch_assoc();
$estado=$pedidos['estado'];
//if($estado!=0){exit(header("Location:".$r."dashboard.php?error=El PEDIDO NO PUEDE SER EDITADO"));}
$iduser=$pedidos['iduser'];
$spe=$_SESSION['perfil'];
$sid=$_SESSION['userid'];
//if($spe!=$pad && $spe!=$psu && $sid!=$iduser){ exit(header("Location:".$r."dashboard.php?error=NO TIENES PERMISO PARA ESTA SECCION"));}
$row1 = $mysqli->query("SELECT * FROM z_pedido WHERE codigopedido=$code");
$proid = array();
$canid = array();
while($producto = $row1->fetch_assoc()) {
    array_push($proid,$producto['idproducto']);
    array_push($canid,$producto['cantidad']);
    $estado=$pedidos['estado'];
}

$row10 = $mysqli->query("SELECT * FROM z_pedidoseliminados WHERE codigopedido=$code");
$num1 = $row10->num_rows;
?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body class="fixed-nav sidenav-toggled sticky-footer 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> DESCRIPCIÓN PEDIDO N°<? echo $code?></div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Nombre del Producto</th>
                  <th>Cantidad</th>
                  <th>Devuelto</th>
                  <th>total Unds</th>
                </tr>
              </thead>
              <?php if($num1>0){ $eliminado = $row10->fetch_assoc();?>
              <tfoot>
                <tr>
                  <th COLSPAN="5" style="font-weight:normal"><b>Motivo:</b> <?php echo strtolower($eliminado["motivo"]); ?></th>
                </tr>
              </tfoot>
              <?php } ?>
                  <tbody>
                    <? $productos = $mysqli->query("SELECT * FROM z_productos"); 
                      while ($pro = $productos->fetch_assoc()){
                      if (in_array($pro["id"], $proid)) {
                          $name='id'.$pro["id"];
                          $name2='can'.$pro["id"];
                          $row4 = $mysqli->query("SELECT * FROM z_pedido WHERE codigopedido=$code AND idproducto='".$pro["id"]."'");
                          $row5 = $row4->fetch_assoc();
                          $value=$row5['cantidad'];
                          $value2=$row5['devolucion'];
                        }else{
                          $name='id'.$pro["id"];
                          $name2='cann'.$pro["id"];
                          $value="";
                        }
                        if($value!=0){
                      ?>
                      <tr>
                        <td><? echo $pro["producto"]; ?></td>
                        <td><? echo $value; ?></td>
                        <td><? echo $value2; ?></td>
                        <td><? echo $value-$value2;$value =""; $value2 =""?></td>
                      </tr>
                    <? }} ?>
              <tbody>
            </table>
          </div>
        </div>
      </div>
      <input type="button" class="btn btn-primary float-left" value="Atras" name="Back2" onclick="history.back()" />
    </div>
  </div>
  <?php include $r."inc/foot.php"; ?>
</body>
</html>   