panel admin: gestion de pedidos
This commit is contained in:
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
include("../db.php");
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
if (!isset($_SESSION['rol']) || $_SESSION['rol'] !== 'admin') {
|
||||
header("Location: ../login.php?error=acceso_denegado");
|
||||
exit();
|
||||
}
|
||||
|
||||
$busqueda = mysqli_real_escape_string($conexion, $_GET['query'] ?? '');
|
||||
$modo = $_GET['modo'] ?? '';
|
||||
$usuario_id_fijo = (int)($_GET['usuario_id'] ?? 0);
|
||||
|
||||
if ($usuario_id_fijo > 0) {
|
||||
$query_u = "SELECT id_usuario, nombre FROM usuarios WHERE id_usuario = $usuario_id_fijo";
|
||||
$res_u = mysqli_query($conexion, $query_u);
|
||||
$usuario = mysqli_fetch_assoc($res_u);
|
||||
$coincidencias_usuarios = [$usuario];
|
||||
} else {
|
||||
$query_u = "SELECT id_usuario, nombre FROM usuarios WHERE id_usuario = '$busqueda' OR nombre LIKE '%$busqueda%'";
|
||||
$res_u = mysqli_query($conexion, $query_u);
|
||||
$coincidencias_usuarios = mysqli_fetch_all($res_u, MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
// Buscamos el pedido por ID
|
||||
$query_p = "SELECT id_pedido, id_usuario FROM pedidos WHERE id_pedido = '$busqueda'";
|
||||
$res_p = mysqli_query($conexion, $query_p);
|
||||
$pedido = mysqli_fetch_assoc($res_p);
|
||||
|
||||
$cantidad_usuarios = count($coincidencias_usuarios);
|
||||
|
||||
$mostrar_decision_bicefala = ($cantidad_usuarios === 1 && $pedido && empty($modo));
|
||||
|
||||
if ($pedido && $cantidad_usuarios === 0 && empty($modo)) {
|
||||
header("Location: ver_detalle.php?id=" . $pedido['id_pedido']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Si solo hubo una coincidencia de usuario y no hay conflicto con ID de pedido, lo marcamos para mostrar directo
|
||||
$usuario_unico = null;
|
||||
if ($cantidad_usuarios === 1 && !$mostrar_decision_bicefala) {
|
||||
$usuario_unico = $coincidencias_usuarios[0];
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Resultados de Búsqueda - La Pecosa</title>
|
||||
<link rel="stylesheet" href="../css/all.min.css">
|
||||
<link rel="stylesheet" href="admin_style.css">
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
body { font-family: 'Segoe UI', sans-serif; background: #f4f6f9; color: #1e293b; margin: 0; }
|
||||
|
||||
.main-content { padding: 40px; flex: 1; min-height: 100vh; }
|
||||
.page-title { font-size: 1.8rem; font-weight: 700; color: #0f172a; margin-bottom: 25px; margin-top: 0; }
|
||||
|
||||
.btn-action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 22px;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
text-decoration: none;
|
||||
border-radius: 50px;
|
||||
transition: all 0.2s ease;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
}
|
||||
.btn-dark { background: #334155; color: white; margin-bottom: 25px; box-shadow: 0 4px 10px rgba(51,65,85,0.1); }
|
||||
.btn-dark:hover { background: #1e293b; transform: translateY(-1px); }
|
||||
|
||||
.card-bicefala {
|
||||
background: white;
|
||||
max-width: 680px;
|
||||
margin: 40px auto;
|
||||
padding: 40px 30px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 10px 30px rgba(15,23,42,0.04);
|
||||
border-top: 4px solid #e02828;
|
||||
text-align: center;
|
||||
}
|
||||
.card-bicefala h2 { color: #0f172a; font-size: 1.5rem; font-weight: 700; margin-bottom: 10px; }
|
||||
.card-bicefala p { color: #64748b; font-size: 1rem; margin-bottom: 30px; }
|
||||
.bicefala-actions { display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; }
|
||||
|
||||
.btn-choice-user { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
|
||||
.btn-choice-user:hover { background: #d1fae5; transform: translateY(-2px); }
|
||||
.btn-choice-order { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
|
||||
.btn-choice-order:hover { background: #dbeafe; transform: translateY(-2px); }
|
||||
|
||||
.panel-container { background: white; padding: 30px; border-radius: 20px; box-shadow: 0 4px 25px rgba(0,0,0,0.02); }
|
||||
.panel-subtitle { font-size: 1.2rem; font-weight: 600; color: #1e293b; margin-top: 0; margin-bottom: 15px; display: flex; align-items: center; gap: 8px; }
|
||||
|
||||
.coincidencias-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-top: 20px; }
|
||||
.card-cliente { background: #f8fafc; padding: 20px; border-radius: 15px; border: 1px solid #e2e8f0; transition: all 0.2s; text-decoration: none; color: inherit; display: block; }
|
||||
.card-cliente:hover { border-color: #e02828; background: white; transform: translateY(-2px); box-shadow: 0 6px 15px rgba(224,40,40,0.06); }
|
||||
.card-cliente h3 { margin: 0 0 6px 0; color: #0f172a; font-size: 1.1rem; }
|
||||
|
||||
.cliente-info-box { background: white; padding: 25px; border-radius: 15px; box-shadow: 0 4px 20px rgba(0,0,0,0.02); margin-bottom: 25px; display: flex; align-items: center; justify-content: space-between; }
|
||||
.cliente-info-box h2 { margin: 0; color: #0f172a; font-size: 1.4rem; font-weight: 700; }
|
||||
.cliente-badge { background: #fff1f2; color: #e02828; padding: 6px 14px; border-radius: 50px; font-weight: 600; font-size: 0.85rem; }
|
||||
|
||||
.admin-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
|
||||
.admin-table th { background: #f8fafc; color: #64748b; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; padding: 14px; text-align: left; border-bottom: 2px solid #edf2f7; }
|
||||
.admin-table td { padding: 14px; border-bottom: 1px solid #f1f5f9; font-size: 0.9rem; color: #334155; vertical-align: middle; }
|
||||
.admin-table tr:hover td { background-color: #f8fafc; }
|
||||
.detalle-item { font-size: 0.8rem; color: #64748b; display: block; padding: 3px 0; }
|
||||
.status-badge { font-weight: 700; color: #e02828; font-size: 0.85rem; background: #fff1f2; padding: 4px 10px; border-radius: 50px; display: inline-block; }
|
||||
|
||||
.alert-error { padding: 20px; background: #fef2f2; border: 1px solid #fee2e2; color: #991b1b; border-radius: 15px; display: flex; align-items: center; gap: 10px; font-weight: 500; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php include("sidebar.php"); ?>
|
||||
|
||||
<div class="main-content">
|
||||
|
||||
<h1 class="page-title">Módulo de Búsqueda</h1>
|
||||
|
||||
<a href="pedidos.php" class="btn-action btn-dark"><i class="fa-solid fa-arrow-left"></i> Volver al panel</a>
|
||||
|
||||
<?php if ($mostrar_decision_bicefala): ?>
|
||||
<div class="card-bicefala">
|
||||
<div style="font-size: 2.5rem; color: #e02828; margin-bottom: 15px;"><i class="fa-solid fa-circle-question"></i></div>
|
||||
<h2>Coincidencia doble detectada</h2>
|
||||
<p>El número <strong>"<?php echo htmlspecialchars($busqueda); ?>"</strong> pertenece a un ID de Pedido y también al ID del usuario <strong><?php echo htmlspecialchars($coincidencias_usuarios[0]['nombre']); ?></strong>.</p>
|
||||
|
||||
<div class="bicefala-actions">
|
||||
<a href="buscar_clientes.php?query=<?php echo urlencode($busqueda); ?>&modo=usuario" class="btn-action btn-choice-user">
|
||||
<i class="fa-solid fa-user-clock"></i> Ver Historial del Usuario
|
||||
</a>
|
||||
<a href="ver_detalle.php?id=<?php echo $busqueda; ?>" class="btn-action btn-choice-order">
|
||||
<i class="fa-solid fa-receipt"></i> Ver Detalle del Pedido
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php elseif ($cantidad_usuarios > 1 && $usuario_id_fijo === 0): ?>
|
||||
<div class="panel-container">
|
||||
<h2 class="panel-subtitle"><i class="fa-solid fa-users" style="color: #e02828;"></i> Se encontraron <?php echo $cantidad_usuarios; ?> clientes</h2>
|
||||
<p style="color: #64748b; margin-top: 0; font-size: 0.95rem;">Seleccioná el cliente correcto para auditar su historial completo de comandas:</p>
|
||||
|
||||
<div class="coincidencias-container">
|
||||
<?php foreach ($coincidencias_usuarios as $u): ?>
|
||||
<a href="buscar_clientes.php?query=<?php echo urlencode($busqueda); ?>&usuario_id=<?php echo $u['id_usuario']; ?>" class="card-cliente">
|
||||
<h3><?php echo htmlspecialchars($u['nombre']); ?></h3>
|
||||
<span style="font-size: 0.8rem; color: #64748b; font-weight: 500;">
|
||||
<i class="fa-solid fa-id-card" style="color: #94a3b8;"></i> ID Cliente: #<?php echo $u['id_usuario']; ?>
|
||||
</span>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php elseif ($usuario_unico || $usuario_id_fijo > 0):
|
||||
$u_actual = $usuario_unico ?? $coincidencias_usuarios[0];
|
||||
?>
|
||||
<div class="cliente-info-box">
|
||||
<div>
|
||||
<h2 style="color: #0f172a; font-weight: 700;"><?php echo htmlspecialchars($u_actual['nombre']); ?></h2>
|
||||
<p style="margin: 5px 0 0 0; font-size: 0.9rem; color: #64748b;"><i class="fa-solid fa-clock-rotate-left"></i> Historial completo de compras en el local</p>
|
||||
</div>
|
||||
<div class="cliente-badge">
|
||||
<i class="fa-solid fa-id-badge"></i> ID Usuario: #<?php echo $u_actual['id_usuario']; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-container" style="padding: 10px 20px 25px 20px;">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>NRO Pedido</th>
|
||||
<th>Fecha</th>
|
||||
<th>Detalle de Productos</th>
|
||||
<th>Monto Total</th>
|
||||
<th>Dirección de Envío</th>
|
||||
<th>Teléfono</th>
|
||||
<th>Estado Actual</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$pedidos_sql = "SELECT * FROM pedidos WHERE id_usuario = '{$u_actual['id_usuario']}' ORDER BY fecha DESC";
|
||||
$pedidos = mysqli_query($conexion, $pedidos_sql);
|
||||
|
||||
if(mysqli_num_rows($pedidos) > 0):
|
||||
while ($p = mysqli_fetch_assoc($pedidos)):
|
||||
?>
|
||||
<tr>
|
||||
<td><strong style="color: #0f172a;">#<?php echo $p['id_pedido']; ?></strong></td>
|
||||
<td style="color: #64748b; font-weight: 500;"><?php echo date('d/m H:i', strtotime($p['fecha'])); ?> hs</td>
|
||||
<td>
|
||||
<?php
|
||||
$det_sql = "SELECT p.nombre AS producto, d.cantidad
|
||||
FROM detalle_pedido d
|
||||
JOIN productos p ON d.producto_id = p.id
|
||||
WHERE d.pedido_id = '{$p['id_pedido']}'";
|
||||
$detalles = mysqli_query($conexion, $det_sql);
|
||||
while ($d = mysqli_fetch_assoc($detalles)):
|
||||
echo "<span class='detalle-item'><i class='fa-solid fa-circle-dot' style='font-size:0.5rem; color:#cbd5e1; margin-right:5px;'></i>{$d['producto']} (x{$d['cantidad']})</span>";
|
||||
endwhile;
|
||||
?>
|
||||
</td>
|
||||
<td><strong style="color: #0f172a; font-size: 1rem;">$<?php echo number_format($p['total'], 0, ',', '.'); ?></strong></td>
|
||||
<td style="color: #64748b;"><?php echo htmlspecialchars($p['direccion_envio'] ?? 'Retira en local'); ?></td>
|
||||
<td style="color: #64748b; font-weight: 500;"><?php echo htmlspecialchars($p['telefono_contacto'] ?? 'S/N'); ?></td>
|
||||
<td><span class="status-badge"><?php echo $p['estado']; ?></span></td>
|
||||
</tr>
|
||||
<?php
|
||||
endwhile;
|
||||
else:
|
||||
?>
|
||||
<tr><td colspan="7" style="text-align: center; color: #94a3b8; padding: 40px 0;"><i class="fa-solid fa-folder-open" style="font-size: 1.5rem; display:block; margin-bottom:10px;"></i> Este usuario no registra pedidos históricos en el sistema.</td></tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php else: ?>
|
||||
<div class="alert-error">
|
||||
<i class="fa-solid fa-circle-exclamation" style="font-size: 1.2rem;"></i>
|
||||
<span>No se encontraron clientes ni pedidos registrados asociados a la búsqueda: <strong>"<?php echo htmlspecialchars($busqueda); ?>"</strong></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user