File "facturas.php"

Full Path: C:/wamp64/www/AVIDOTAPP/views/invenconsul/facturas.php
File size: 8.08 KB
MIME-type: text/html
Charset: utf-8

<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Consulta de Facturas – Solo Entradas</title>
  <link rel="icon" type="image/png" href="assets/img/icono.png">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <style>
    body { background:linear-gradient(225deg,#d0101d,#752b2a); min-height:100vh; padding:20px; }
    .card { border-radius:15px; box-shadow:0 5px 15px rgba(0,0,0,.2); margin-bottom:20px; }
    .card-header { background-color:#8d8c8c; color:#fff; border-radius:15px 15px 0 0!important; }
    .filter-section { background:#f1f1f1; padding:15px; border-radius:8px; margin-bottom:20px; }
    .filter-title { font-weight:bold; color:#d0101d; margin-bottom:10px; }
    .btn-buscar { background-color:#8d8c8c; color:#fff; border:none; }
    .btn-buscar:hover { background-color:#a9a9a9; color:#fff; }
  </style>
</head>
<body>
<div class="container">
  <div class="card">
    <div class="card-header">
      <div class="d-flex justify-content-between align-items-center">
        <h4 class="mb-0"><i class="fas fa-receipt me-2"></i>Consulta de Facturas – Solo Entradas</h4>
        <div class="d-flex gap-2">
          <a href="index.php?controller=Existencias&action=movimientos" class="btn btn-secondary btn-sm">
            <i class="fas fa-exchange-alt me-1"></i>Movimientos
          </a>
          <a href="index.php?controller=Existencias&action=index" class="btn btn-light btn-sm">
            <i class="fas fa-boxes me-1"></i>Existencias
          </a>
          <a href="index.php?controller=Dashboard&action=index" class="btn btn-light btn-sm">
            <i class="fas fa-home me-1"></i>Menú
          </a>
        </div>
      </div>
    </div>
    <div class="card-body">

      <div class="alert alert-info">
        <i class="fas fa-info-circle me-2"></i>
        Solo se muestran registros del inventario <strong>Nuevo</strong> con MOVIMIENTO = <strong>Entrada</strong>.
      </div>

      <form method="post" action="index.php?controller=Existencias&action=facturas" class="row g-3">
        <div class="col-12 filter-section">
          <div class="filter-title"><i class="fas fa-filter me-1"></i>Filtros de Búsqueda</div>
          <div class="row g-3">
            <div class="col-md-3">
              <label class="form-label">N° Factura</label>
              <input type="text" class="form-control" name="nfactura" value="<?= htmlspecialchars($filtros['nfactura'] ?? '') ?>" placeholder="Número de factura">
            </div>
            <div class="col-md-3">
              <label class="form-label">Proveedor</label>
              <select class="form-select" name="provedor">
                <option value="">Todos</option>
                <?php foreach ($filtros_disponibles['provedores'] as $p): ?>
                  <option value="<?= htmlspecialchars($p) ?>" <?= ($filtros['provedor'] ?? '') === $p ? 'selected' : '' ?>><?= htmlspecialchars($p) ?></option>
                <?php endforeach; ?>
              </select>
            </div>
            <div class="col-md-3">
              <label class="form-label">Código</label>
              <input type="text" class="form-control" name="codigo" value="<?= htmlspecialchars($filtros['CODIGO'] ?? '') ?>" placeholder="Código del item">
            </div>
            <div class="col-md-3">
              <label class="form-label">Usuario</label>
              <select class="form-select" name="usuario">
                <option value="">Todos</option>
                <?php foreach ($filtros_disponibles['usuarios'] as $u): ?>
                  <option value="<?= htmlspecialchars($u) ?>" <?= ($filtros['userEntrega'] ?? '') === $u ? 'selected' : '' ?>><?= htmlspecialchars($u) ?></option>
                <?php endforeach; ?>
              </select>
            </div>
            <div class="col-md-4">
              <label class="form-label">Fecha Inicio</label>
              <input type="date" class="form-control" name="fecha_inicio" value="<?= htmlspecialchars($filtros['fecha_inicio'] ?? '') ?>">
            </div>
            <div class="col-md-4">
              <label class="form-label">Fecha Fin</label>
              <input type="date" class="form-control" name="fecha_fin" value="<?= htmlspecialchars($filtros['fecha_fin'] ?? date('Y-m-d')) ?>">
            </div>
            <div class="col-md-4 d-flex align-items-end">
              <button type="submit" class="btn btn-buscar w-100">
                <i class="fas fa-search me-1"></i>Buscar Entradas
              </button>
            </div>
          </div>
        </div>
      </form>

      <?php if ($buscado): ?>
        <div class="alert alert-info">
          <strong><?= $total ?></strong> registro(s) de entrada encontrado(s).
        </div>

        <?php if ($total > 0): ?>
        <!-- Exportar -->
        <form method="post" action="index.php?controller=Existencias&action=facturas" class="mb-3">
          <input type="hidden" name="nfactura"    value="<?= htmlspecialchars($filtros['nfactura'] ?? '') ?>">
          <input type="hidden" name="provedor"    value="<?= htmlspecialchars($filtros['provedor'] ?? '') ?>">
          <input type="hidden" name="codigo"      value="<?= htmlspecialchars($filtros['CODIGO'] ?? '') ?>">
          <input type="hidden" name="usuario"     value="<?= htmlspecialchars($filtros['userEntrega'] ?? '') ?>">
          <input type="hidden" name="fecha_inicio" value="<?= htmlspecialchars($filtros['fecha_inicio'] ?? '') ?>">
          <input type="hidden" name="fecha_fin"   value="<?= htmlspecialchars($filtros['fecha_fin'] ?? '') ?>">
          <button type="submit" name="exportar" class="btn btn-success btn-sm">
            <i class="fas fa-file-excel me-1"></i>Exportar a Excel
          </button>
        </form>

        <div class="table-responsive">
          <table class="table table-striped table-bordered table-sm">
            <thead class="table-dark">
              <tr>
                <th>Fecha</th><th>N° Factura</th><th>Proveedor</th>
                <th>Código</th><th>Descripción</th><th>Cantidad</th>
                <th>Precio</th><th>Usuario</th><th>Mov.</th>
              </tr>
            </thead>
            <tbody>
              <?php foreach ($resultados as $row): ?>
              <tr>
                <td><?= date('d/m/Y H:i', strtotime($row['fechaIngreso'])) ?></td>
                <td class="fw-bold"><?= htmlspecialchars($row['nfactura']) ?></td>
                <td><?= htmlspecialchars($row['provedor']) ?></td>
                <td><?= htmlspecialchars($row['CODIGO']) ?></td>
                <td><?= htmlspecialchars($row['DESCRIPCION']) ?></td>
                <td class="text-center"><?= number_format($row['CANTIDAD']) ?></td>
                <td class="text-end">$<?= number_format($row['precio'] ?? 0, 2) ?></td>
                <td><?= htmlspecialchars($row['userEntrega']) ?></td>
                <td><span class="badge bg-success"><?= htmlspecialchars($row['MOVIMIENTO']) ?></span></td>
              </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>
        <?php else: ?>
          <div class="alert alert-warning"><i class="fas fa-exclamation-triangle me-2"></i>No se encontraron registros con los filtros aplicados.</div>
        <?php endif; ?>
      <?php endif; ?>

    </div>
  </div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
$(function(){
  const today = new Date().toISOString().split('T')[0];
  if (!$('input[name="fecha_fin"]').val())    $('input[name="fecha_fin"]').val(today);
  if (!$('input[name="fecha_inicio"]').val()) {
    const d = new Date(); d.setDate(d.getDate()-30);
    $('input[name="fecha_inicio"]').val(d.toISOString().split('T')[0]);
  }
});
</script>
</body></html>