diff --git a/pedidos.php b/pedidos.php index 1b987be..b02f741 100644 --- a/pedidos.php +++ b/pedidos.php @@ -1,296 +1,248 @@ quote($estado); } -$pdo = db(); - -$user_id = $_SESSION['user_id']; -$user_role = $_SESSION['user_role'] ?? 'Asesor'; - -// Fetch years for the filter -$years_query = "SELECT DISTINCT YEAR(created_at) as year FROM pedidos"; -if ($user_role === 'Asesor') { - $years_query .= " WHERE asesor_id = ?"; - $years_stmt = $pdo->prepare($years_query); - $years_stmt->execute([$user_id]); -} else { - $years_stmt = $pdo->query($years_query); -} -$years = $years_stmt->fetchAll(PDO::FETCH_COLUMN); - - -// Filter logic -$selected_month = $_GET['mes'] ?? ''; -$selected_year = $_GET['año'] ?? ''; -$search_query = $_GET['q'] ?? ''; - -$sql = "SELECT p.*, u.nombre_asesor as asesor_nombre FROM pedidos p LEFT JOIN users u ON p.asesor_id = u.id WHERE p.estado = 'ROTULADO 📦'"; -$params = []; - -if ($user_role === 'Asesor') { - $sql .= " AND p.asesor_id = ?"; - $params[] = $user_id; +// Filter by date +$fecha = isset($_GET['fecha']) ? $_GET['fecha'] : ''; +if ($fecha) { + $sql .= " AND p.fecha_pedido = " . $db->quote($fecha); } -if (!empty($search_query)) { - $sql .= " AND (p.nombre_completo LIKE ? OR p.dni_cliente LIKE ? OR p.celular LIKE ?)"; - $params[] = "%$search_query%"; - $params[] = "%$search_query%"; - $params[] = "%$search_query%"; +// Filter by search term +$search = isset($_GET['search']) ? $_GET['search'] : ''; +if ($search) { + $searchTerm = '%' . $search . '%'; + $sql .= " AND (p.nombre_cliente LIKE " . $db->quote($searchTerm) . " OR p.celular_cliente LIKE " . $db->quote($searchTerm) . " OR p.guia LIKE " . $db->quote($searchTerm) . ")"; } -if (!empty($selected_month)) { - $sql .= " AND MONTH(p.created_at) = ?"; - $params[] = $selected_month; -} -if (!empty($selected_year)) { - $sql .= " AND YEAR(p.created_at) = ?"; - $params[] = $selected_year; +// Filter by asesor for non-admin roles +if ($role !== 'admin') { + $sql .= " AND p.asesor_id = " . $db->quote($asesor_id); } -$sql .= " ORDER BY p.created_at DESC"; -$stmt = $pdo->prepare($sql); -$stmt->execute($params); -$pedidos = $stmt->fetchAll(); +$sql .= " ORDER BY p.id DESC"; -$months = [ - 1 => 'Enero', 2 => 'Febrero', 3 => 'Marzo', 4 => 'Abril', 5 => 'Mayo', 6 => 'Junio', - 7 => 'Julio', 8 => 'Agosto', 9 => 'Septiembre', 10 => 'Octubre', 11 => 'Noviembre', 12 => 'Diciembre' -]; - -?> -query($sql); ?> - -
| ID | +Fecha | +Asesor | +Guía | + +Estado Shalom | + +Cliente | +Celular | +Dirección | +Producto | +Total | +Estado | +Acciones | +
|---|---|---|---|---|---|---|---|---|---|---|---|
| + | + | + | + + | + + Verificando... + | + ++ | + 8) { + // The URL is prepared, but the link will be enabled via JS + $mensaje_whatsapp = "¡Hola " . htmlspecialchars($row['nombre_cliente']) . "! Tu pedido ha llegado a la agencia de destino y está listo para ser recogido. ¡Gracias por tu compra!"; + $whatsapp_url = "https://wa.me/" . $celular_limpio . "?text=" . urlencode($mensaje_whatsapp); + } + ?> + + + + | ++ | + | S/ | ++ | + Editar + | +
| No se encontraron pedidos. | +|||||||||||
| ID | -Cliente | -DNI | -Celular | -Producto | -Sede de Envío | -Cantidad | -Monto Total | -Monto Debe | -Nº De Orden | -Codigo De Orden | -CLAVE | -Estado | -Asesor | -Fecha Creación | -Voucher Restante | -Acciones | -
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - - Ver - - N/A - - | -- Editar - - Eliminar - - | -
No hay pedidos que coincidan con el filtro.
- - -