<?php
session_start();
require 'script_php/conexao.php';
$id = filter_var( $_GET['id'], FILTER_SANITIZE_STRING);

require_once 'script_php/ConexaoSQL.php';
require_once 'gerador/Sqlserver.php';

$sql = new Sqlserver();

?>
<!DOCTYPE html>
<html>
  <head> <?php include_once 'head.html' ?> <title></title>
  </head>
  <body> <?php include_once 'header.php'; ?> 
<h3>

<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="bi bi-clipboard-minus-fill" viewBox="0 0 16 16">
  <path d="M6.5 0A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0zm3 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5z"/>
  <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1A2.5 2.5 0 0 1 9.5 5h-3A2.5 2.5 0 0 1 4 2.5zM6 9h4a.5.5 0 0 1 0 1H6a.5.5 0 0 1 0-1"/>
</svg>

Alterar Pedido </h3>
<form action="script_php/alterarpedido.php" method="post">

<?php
      $listagem2 = mysqli_query($conexao, "SELECT * FROM pedidos WHERE id = '$id' LIMIT 1");

      while ($linha = mysqli_fetch_array($listagem2))
      {

          $id = $linha['id'];
          $fornecedor = $linha['fornecedor'];
          $fabricante = $linha['fabricante'];
          $prazo = $linha['prazo'];
          $observacao = $linha['obs'];
          $data = $linha['datapedido'];
          //$data = date('Y-m-d');
          $loja = $linha['loja'];

         $valor = number_format($linha['valor'], 2, ',', '.' );
      ?>
           
      <div class="panel panel-default">
      <div class="panel-body">

      <input type="hidden"  value="<?php echo $loja ?>"  name="loja">
      <input type="hidden"  value="<?php echo $id ?>"  name="id">
      <input type="hidden"  value="<?php echo $fornecedor ?>"  name="fornecedoraltual">

       
  
     
      <select class="form-control form_forn" name="fornecedor">

      <?php
      //buscar fornecedor no softcom
      $listagem = $sql->BuscarFornecedor();
    
      
     foreach ($listagem AS $linha)
      {

        $selected = ($linha[1] == $fornecedor) ? 'selected' : '';

          $fornecedorNovo = $linha[1];
          $cnpj_fornecedor = $linha[1];


      ?>

        <option value="<?php echo htmlspecialchars($linha[1], ENT_QUOTES, 'UTF-8'); ?>" <?php echo $selected;?>>
        <?php echo htmlspecialchars($linha[1], ENT_QUOTES, 'UTF-8'); ?>
      
      <?php
      } ?>
    </select>
          Data Pedido:
          <input type="date" value=<?php echo $data;?> class="form-control form_data form_forn" name="datapedido">   
          Fabricante:
          <input type="text" value="<?php echo $fabricante; ?>" placeholder="Fabricante" class="form-control form_forn" name="fabricante">
          Prazo de entrega:
          <input type="number" value="<?php echo $prazo; ?>" placeholder="Prazo de entrega" class="form-control form_data form_forn" name="prazo"> 
          Valor:
          <input type="text" value="<?php echo $valor; ?>" placeholder="valor" class="form-control form_forn" name="valor">
          Observação:
          <textarea class="form-control form_forn" rows="3"  name="observacao"> <?= $observacao; ?></textarea>
          <p>
<?php } ?>
          <p>
          <button type="submit" class="btn btn-warning"> Avançar >>></button>
    </form>
  <?php include_once 'footer.php' ?>