cambios atorados

This commit is contained in:
2025-06-26 10:14:26 -06:00
parent b9ecdd4bfa
commit 4416fe6f20
25 changed files with 811 additions and 644 deletions

View File

@@ -22,11 +22,6 @@ function dashboard()
include __DIR__ . '/../../views/agencias/dashboard_agencias.php';
}
function solicitudesVinculacion()
{
include __DIR__ . '/../../views/agencias/solicitudes_vinculacion.php';
}
function alta()
{
if (!isset($_SESSION['usuario_id']) || $_SESSION['tipo_usuario'] !== 'admin_agencia') {
@@ -34,6 +29,76 @@ function alta()
exit;
}
$conn = getConnection();
// DEBUG: Verificar conexión
if (!$conn) {
die("Error de conexión: " . print_r(sqlsrv_errors(), true));
}
// Obtener la agencia del administrador actual
$sqlAgencia = "SELECT id_agencia FROM agencias_aduanales WHERE id_administrador = ?";
$stmtAgencia = sqlsrv_query($conn, $sqlAgencia, [$_SESSION['usuario_id']]);
// DEBUG: Verificar query de agencia
if ($stmtAgencia === false) {
die("Error en consulta de agencia: " . print_r(sqlsrv_errors(), true));
}
$rowAgencia = sqlsrv_fetch_array($stmtAgencia, SQLSRV_FETCH_ASSOC);
// DEBUG: Verificar si se encontró la agencia
if (!$rowAgencia) {
die("No se encontró agencia para el administrador ID: " . $_SESSION['usuario_id']);
}
$id_agencia = $rowAgencia['id_agencia'];
// === CONSULTA DE AGENTES ADUANALES ===
// Verificar si hay registros en la tabla agente_agencia
$sqlCount = "SELECT COUNT(*) as total FROM agente_agencia WHERE id_agencia = ?";
$stmtCount = sqlsrv_query($conn, $sqlCount, [$id_agencia]);
$rowCount = sqlsrv_fetch_array($stmtCount, SQLSRV_FETCH_ASSOC);
// Verificar registros activos
$sqlCountActive = "SELECT COUNT(*) as total FROM agente_agencia WHERE id_agencia = ? AND activo = 1";
$stmtCountActive = sqlsrv_query($conn, $sqlCountActive, [$id_agencia]);
$rowCountActive = sqlsrv_fetch_array($stmtCountActive, SQLSRV_FETCH_ASSOC);
// Consulta de agentes vinculados ACTIVOS a MI agencia
$sql = "
SELECT
u.id_usuario,
u.nombre,
u.email,
u.tipo_usuario as tipo_usuario_sistema,
u.activo,
u.creado_en,
u.creado_por,
aa.fecha_asignacion as fecha_vinculacion,
aa.id_relacion,
'agente' as tipo_vinculacion
FROM agente_agencia aa
INNER JOIN usuarios_sistema u ON aa.id_agente = u.id_usuario
WHERE aa.id_agencia = ?
AND aa.activo = 1
AND u.activo = 1
ORDER BY aa.fecha_asignacion DESC
";
$stmt = sqlsrv_query($conn, $sql, [$id_agencia]);
// DEBUG: Verificar query de agentes
if ($stmt === false) {
die("Error en consulta de agentes: " . print_r(sqlsrv_errors(), true));
}
$agentes = [];
if ($stmt !== false) {
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$agentes[] = $row;
}
}
include __DIR__ . '/../../views/agencias/alta_agentes.php';
}