302 lines
19 KiB
PHP
302 lines
19 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Simulamos que eres la asesora con ID 1 (puedes cambiarlo luego por el ID real de la sesión)
|
|
$mi_id_asesora = $_SESSION['user_id'] ?? 1;
|
|
|
|
$db = db();
|
|
|
|
// 1. Obtener estadísticas rápidas para la asesora
|
|
$stmt_stats = $db->prepare("SELECT
|
|
COUNT(*) as total,
|
|
SUM(CASE WHEN estado = 'Gestion' THEN 1 ELSE 0 END) as pendientes,
|
|
SUM(CASE WHEN estado = 'NO CONTESTO, DEVOLVER LLAMADA' THEN 1 ELSE 0 END) as reintentos,
|
|
SUM(CASE WHEN estado = 'COMPLETADO ✅' THEN 1 ELSE 0 END) as cerrados
|
|
FROM pedidos WHERE asesor_id = ?");
|
|
$stmt_stats->execute([$mi_id_asesora]);
|
|
$stats = $stmt_stats->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// 2. Determinar qué vista mostrar
|
|
$view = $_GET['view'] ?? 'pendientes';
|
|
$where_clause = "AND estado = 'Gestion'";
|
|
$titulo_tabla = "Pedidos Pendientes de Atención";
|
|
|
|
if ($view === 'reintentos') {
|
|
$where_clause = "AND estado = 'NO CONTESTO, DEVOLVER LLAMADA'";
|
|
$titulo_tabla = "Reintentos (No contestaron)";
|
|
} elseif ($view === 'cerrados') {
|
|
$where_clause = "AND estado = 'COMPLETADO ✅'";
|
|
$titulo_tabla = "Ventas Cerradas (Confirmadas)";
|
|
} elseif ($view === 'todos') {
|
|
$where_clause = "";
|
|
$titulo_tabla = "Todos mis Pedidos Asignados";
|
|
}
|
|
|
|
// 3. Obtener la lista de pedidos según el filtro
|
|
$stmt_pedidos = $db->prepare("SELECT * FROM pedidos
|
|
WHERE asesor_id = ?
|
|
$where_clause
|
|
ORDER BY created_at DESC");
|
|
$stmt_pedidos->execute([$mi_id_asesora]);
|
|
$pedidos = $stmt_pedidos->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
include 'layout_header.php';
|
|
?>
|
|
|
|
<div class="container-fluid mt-4">
|
|
<div class="row mb-4">
|
|
<div class="col-12">
|
|
<h2 class="fw-bold"><i class="bi bi-headset text-primary"></i> Mi Panel de Gestión (Call Center)</h2>
|
|
<p class="text-muted">Haz clic en las tarjetas para filtrar los pedidos por estado.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tarjetas de Resumen -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-3">
|
|
<a href="?view=todos" class="text-decoration-none">
|
|
<div class="card border-0 shadow-sm <?php echo $view == 'todos' ? 'ring-active bg-dark text-white' : 'bg-white text-dark'; ?>">
|
|
<div class="card-body">
|
|
<h6 class="card-title opacity-75">Total Asignados</h6>
|
|
<h2 class="mb-0 fw-bold"><?php echo $stats['total'] ?? 0; ?></h2>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<a href="?view=pendientes" class="text-decoration-none">
|
|
<div class="card border-0 shadow-sm <?php echo $view == 'pendientes' ? 'ring-active bg-warning text-dark' : 'bg-white text-dark border-start border-warning border-4'; ?>">
|
|
<div class="card-body">
|
|
<h6 class="card-title opacity-75">Por Llamar</h6>
|
|
<h2 class="mb-0 fw-bold"><?php echo $stats['pendientes'] ?? 0; ?></h2>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<a href="?view=reintentos" class="text-decoration-none">
|
|
<div class="card border-0 shadow-sm <?php echo $view == 'reintentos' ? 'ring-active bg-info text-white' : 'bg-white text-dark border-start border-info border-4'; ?>">
|
|
<div class="card-body">
|
|
<h6 class="card-title opacity-75">Reintentos</h6>
|
|
<h2 class="mb-0 fw-bold"><?php echo $stats['reintentos'] ?? 0; ?></h2>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<a href="?view=cerrados" class="text-decoration-none">
|
|
<div class="card border-0 shadow-sm <?php echo $view == 'cerrados' ? 'ring-active bg-success text-white' : 'bg-white text-dark border-start border-success border-4'; ?>">
|
|
<div class="card-body">
|
|
<h6 class="card-title opacity-75">Ventas Cerradas</h6>
|
|
<h2 class="mb-0 fw-bold"><?php echo $stats['cerrados'] ?? 0; ?></h2>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.ring-active { box-shadow: 0 0 0 3px rgba(0,0,0,0.1), 0 8px 15px rgba(0,0,0,0.1) !important; transform: translateY(-2px); transition: all 0.3s; }
|
|
.card:hover { transform: translateY(-3px); transition: all 0.3s; }
|
|
</style>
|
|
|
|
<!-- Tabla de Gestión -->
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0 fw-bold"><?php echo $titulo_tabla; ?></h5>
|
|
<span class="badge bg-light text-dark border"><?php echo count($pedidos); ?> registros</span>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Cliente / Celular</th>
|
|
<th>Ubicación</th>
|
|
<th>Producto</th>
|
|
<th>Monto</th>
|
|
<th>Estado Actual</th>
|
|
<th class="text-center">Acciones de Gestión</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($pedidos)): ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center py-5 text-muted">
|
|
<i class="bi bi-inbox fs-1 d-block mb-2"></i>
|
|
No hay pedidos en esta categoría.
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($pedidos as $p): ?>
|
|
<tr>
|
|
<td>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['nombre_completo'] ?? 'Sin nombre'); ?></div>
|
|
<div class="small text-muted">DNI: <?php echo htmlspecialchars($p['dni_cliente'] ?: ($p['dni'] ?: 'N/A')); ?></div>
|
|
<a href="tel:<?php echo $p['celular']; ?>" class="text-decoration-none">
|
|
<i class="bi bi-telephone-fill small"></i> <?php echo htmlspecialchars($p['celular']); ?>
|
|
</a>
|
|
</td>
|
|
<td>
|
|
<div class="small fw-bold text-primary"><?php echo htmlspecialchars($p['sede_envio'] ?? 'N/A'); ?></div>
|
|
<div class="small text-truncate" style="max-width: 150px;" title="<?php echo htmlspecialchars($p['direccion_exacta'] ?? ''); ?>">
|
|
<?php echo htmlspecialchars($p['direccion_exacta'] ?? '-'); ?>
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<div class="small"><?php echo htmlspecialchars($p['producto'] ?? '-'); ?></div>
|
|
<div class="badge bg-light text-dark border">Cant: <?php echo $p['cantidad'] ?? 1; ?></div>
|
|
</td>
|
|
<td>
|
|
<span class="fw-bold text-success">S/ <?php echo number_format($p['monto_total'], 2); ?></span>
|
|
</td>
|
|
<td>
|
|
<?php
|
|
$badge_class = 'bg-secondary';
|
|
if ($p['estado'] == 'Gestion') $badge_class = 'bg-warning text-dark';
|
|
if ($p['estado'] == 'NO CONTESTO, DEVOLVER LLAMADA') $badge_class = 'bg-info';
|
|
if ($p['estado'] == 'COMPLETADO ✅') $badge_class = 'bg-success';
|
|
?>
|
|
<span class="badge <?php echo $badge_class; ?>">
|
|
<?php echo htmlspecialchars($p['estado']); ?>
|
|
</span>
|
|
</td>
|
|
<td class="text-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#modalDetalle<?php echo $p['id']; ?>" title="Ver Detalles">
|
|
<i class="bi bi-eye"></i>
|
|
</button>
|
|
<?php if ($p['estado'] != 'COMPLETADO ✅'): ?>
|
|
<button onclick="cambiarEstado(<?php echo $p['id']; ?>, 'COMPLETADO ✅')" class="btn btn-sm btn-success" title="Venta Confirmada">
|
|
<i class="bi bi-check-circle"></i> Confirmar
|
|
</button>
|
|
<?php endif; ?>
|
|
|
|
<button onclick="cambiarEstado(<?php echo $p['id']; ?>, 'NO CONTESTO, DEVOLVER LLAMADA')" class="btn btn-sm btn-outline-info" title="No contestó">
|
|
<i class="bi bi-telephone-x"></i> No contestó
|
|
</button>
|
|
|
|
<button onclick="cambiarEstado(<?php echo $p['id']; ?>, 'CANCELADO')" class="btn btn-sm btn-outline-danger" title="Rechazado">
|
|
<i class="bi bi-x-circle"></i> Rechazar
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Modal de Detalles -->
|
|
<div class="modal fade" id="modalDetalle<?php echo $p['id']; ?>" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header bg-light">
|
|
<h5 class="modal-title fw-bold">Detalles del Pedido #<?php echo $p['id']; ?></h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body text-start">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="text-muted small d-block">Nombre del Cliente</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['nombre_completo']); ?></div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="text-muted small d-block">DNI</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['dni_cliente'] ?: ($p['dni'] ?: 'N/A')); ?></div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="text-muted small d-block">Celular</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['celular']); ?></div>
|
|
</div>
|
|
|
|
<hr class="my-2">
|
|
|
|
<div class="col-md-4">
|
|
<label class="text-muted small d-block">Ciudad / Sede</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['sede_envio'] ?? 'N/A'); ?></div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="text-muted small d-block">Provincia / Distrito</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['codigo_rastreo'] ?? 'N/A'); ?></div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="text-muted small d-block">Método / Agencia</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['agencia'] ?? 'N/A'); ?></div>
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
<label class="text-muted small d-block">Dirección Exacta</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['direccion_exacta'] ?? 'N/A'); ?></div>
|
|
</div>
|
|
<div class="col-md-12">
|
|
<label class="text-muted small d-block">Referencia</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['referencia_domicilio'] ?? 'N/A'); ?></div>
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
<label class="text-muted small d-block">Coordenadas / Link Maps</label>
|
|
<?php if (!empty($p['coordenadas'])): ?>
|
|
<a href="<?php echo htmlspecialchars($p['coordenadas']); ?>" target="_blank" class="btn btn-sm btn-link p-0">Ver en Google Maps</a>
|
|
<?php else: ?>
|
|
<div class="fw-bold">N/A</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<hr class="my-2">
|
|
|
|
<div class="col-md-6">
|
|
<label class="text-muted small d-block">Producto</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['producto']); ?></div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="text-muted small d-block">Cantidad</label>
|
|
<div class="fw-bold"><?php echo htmlspecialchars($p['cantidad'] ?? 1); ?></div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="text-muted small d-block">Precio Total</label>
|
|
<div class="fw-bold text-success">S/ <?php echo number_format($p['monto_total'], 2); ?></div>
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
<label class="text-muted small d-block">Observaciones / Notas</label>
|
|
<div class="p-2 bg-light rounded small">
|
|
<?php echo nl2br(htmlspecialchars($p['notas'] ?: ($p['nota_adicional'] ?: ($p['observacion'] ?: 'Sin observaciones')))); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
|
|
<a href="pedido_form.php?id=<?php echo $p['id']; ?>" class="btn btn-warning">Editar Pedido</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function cambiarEstado(id, nuevoEstado) {
|
|
if (!confirm('¿Estás seguro de cambiar el estado a ' + nuevoEstado + '?')) return;
|
|
|
|
fetch('update_estado.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: 'id=' + id + '&estado=' + encodeURIComponent(nuevoEstado)
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
location.reload();
|
|
})
|
|
.catch(error => {
|
|
alert('Error al actualizar: ' + error);
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<?php include 'layout_footer.php'; ?>
|