<?php include_once "encabezado1.php"; ?>
<!DOCTYPE html>
<html lang="es">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Registro de uso de almacén</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
  <style>
    /* Fondo de la página con imagen y gradiente */
    body {
      font-family: 'Poppins', sans-serif;
      background: url('desk.jpg') no-repeat center center fixed;
      background-size: cover;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      margin: 0;
      color: #333;
    }

    /* Contenedor principal */
    .container {
      background-color: rgba(255, 255, 255, 0.85);
      padding: 30px;
      border-radius: 15px;
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
      max-width: 1000px;
      margin-top: 30px;
      overflow: hidden;
      animation: fadeIn 1s ease-in-out;
    }

    /* Animación de aparición */
    @keyframes fadeIn {
      from {
        opacity: 0;
        transform: translateY(20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    /* Estilos de la tabla */
    .table {
      background-color: rgba(255, 255, 255, 0.85);
    }

    .table thead {
      background-color: #b3e5fc;
      color: #0277bd;
    }

    .table tbody tr:hover {
      background-color: #e1f5fe;
      transition: background-color 0.3s ease;
      transform: scale(1.01);
    }

    .table td, .table th {
      padding: 12px;
      text-align: center;
      vertical-align: middle;
    }

    /* Botón con microinteracción */
    .btn-primary {
      background-color: #81d4fa;
      color: #ffffff;
      border: none;
      transition: background-color 0.3s ease, transform 0.2s ease;
      font-weight: 500;
      font-size: 16px;
      padding: 10px 20px;
    }

    .btn-primary:hover {
      background-color: #64b5f6;
      transform: translateY(-2px);
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    }

    /* Modal */
    .modal-content {
      background-color: rgba(255, 255, 255, 0.95);
      border-radius: 10px;
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    }

    /* Iconos en etiquetas */
    label::before {
      font-size: 18px;
      color: #01579b;
      margin-right: 5px;
    }

    label[for="codigo"]::before { content: "📦"; }
    label[for="uso"]::before { content: "⚙️"; }

    /* Inputs de formulario */
    .form-control {
      background-color: rgba(255, 255, 255, 0.8);
      border: 1px solid #cfd8dc;
      border-radius: 8px;
      transition: box-shadow 0.3s ease;
    }

    .form-control:focus {
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
      outline: none;
      border-color: #81d4fa;
    }
  </style>
</head>

<body>
  <div class="container">
    <h2 class="text-center mb-4">Registro de uso de almacén 💼</h2>
    <table class="table table-striped table-bordered table-hover">
      <thead>
        <tr>
          <th>ID</th>
          <th>Fecha Registro</th>
          <th>Hora Registro</th>
          <th>Código</th>
          <th>Medida</th>
          <th>Stock</th>
          <th>Descripción</th>
          <th>Restar Bien</th>
        </tr>
      </thead>
      <tbody>
        <?php
        include 'conexion1.php';
        $conectar = mysqli_connect($servidor, $nombre, $clave, $base);
        if (!$conectar) {
            die("Error en la conexión: " . mysqli_connect_error());
        }
        $sql = "SELECT * FROM almacen";
        $result = mysqli_query($conectar, $sql);
        while ($mostrar = mysqli_fetch_array($result)) {
        ?>
          <tr>
            <td><?php echo $mostrar["ID"] ?></td>
            <td><?php echo $mostrar["FECHA_REGISTRO"] ?></td>
            <td><?php echo $mostrar["HORA_REGISTRO"] ?></td>
            <td><?php echo $mostrar["CODIGO"] ?></td>
            <td><?php echo $mostrar["MEDIDA"] ?></td>
            <td><?php echo $mostrar["STOCK"] ?></td>
            <td><?php echo $mostrar["DESCRIPCION"] ?></td>
            <td>
              <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="<?php echo $mostrar["CODIGO"]; ?>">Uso</button>
            </td>
          </tr>
        <?php } ?>
      </tbody>
    </table>
  </div>

  <!-- Modal -->
  <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Uso de Producto/Servicio</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <form>
            <div class="form-group">
              <label for="codigo">Código</label>
              <input type="text" class="form-control" id="codigo" readonly>
            </div>
            <div class="form-group">
              <label for="uso">Uso</label>
              <input type="text" class="form-control" id="uso" required>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
          <button type="button" class="btn btn-primary" onclick="loadDoc()">Registrar Uso</button>
        </div>
      </div>
    </div>
  </div>

  <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
  <script>
    $('#exampleModal').on('show.bs.modal', function(event) {
      var button = $(event.relatedTarget);
      var recipient = button.data('whatever');
      var modal = $(this);
      modal.find('.modal-title').text('Uso producto/servicio ' + recipient);
      $("#codigo").val(recipient);
    });

    function loadDoc(event) {





 
      var formData = {
        codigo: $("#codigo").val(),
        uso: $("#uso").val(),
      };
      if (!formData.uso) {
        alert("Por favor, completa el campo de Uso");
        return;
      }
      $.ajax({
        type: "POST",
        url: "restarbien.php",
        data: formData,
        success: function() {
          alert("Registro de uso exitoso");
          window.location.href = "usoalmacen.php";
        }
      });

      
    }
  </script>
</body>

</html>