Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Nieto2020/portalhub/llms.txt

Use this file to discover all available pages before exploring further.

The Assignments API manages the cliente_asesor pivot table, which is the authoritative record of which Asesor is responsible for each Cliente at any point in time. Every assignment has an estado of either activo or inactivo. When a client is reassigned, the previous activo row has its estado set to inactivo and a new activo row is inserted — the full history is therefore always preserved and queryable. Only Admin users may create or change assignments. Asesores may read their own active portfolios and audit history. Clientes have no direct access to these endpoints.
Role IDs: Admin = 1, Asesor = 2, Cliente = 3. All assignment changes automatically trigger a NotificationService alert to the affected Client.

Assignment record fields

The following fields appear across multiple endpoints. They map directly to the cliente_asesor table columns.
FieldTypeDescription
id_asignacionintPrimary key. Auto-incremented.
id_clienteintFK → usuarios.id_usuario (must have id_rol = 3)
id_asesorintFK → usuarios.id_usuario (must have id_rol = 2)
id_asignadorintFK → usuarios.id_usuario — the Admin who created this row
fecha_asignaciontimestampUTC timestamp set automatically on INSERT
fecha_fintimestamp | nullSet when the assignment becomes inactivo
estadoenumactivo or inactivo
motivo_cambiotext | nullOptional reason for the assignment or reassignment

GET /backend/modules/asignaciones/listar.php

Returns all currently active assignments (estado = 'activo'). Admins see every active assignment across all advisors; Asesores see only assignments where they are the advisor. The response joins usuarios and perfiles for both the client and the advisor, so display names and contact details are included inline. Required role: Admin or Asesor (id_rol = 1 or 2) Query parameters: None
id_asignacion
integer
Primary key of the assignment.
fecha_asignacion
timestamp
UTC timestamp when this assignment was created.
id_cliente
integer
User ID of the assigned client.
correo_cliente
string
Email address of the client.
numero_cliente
string | null
Client number (e.g. CLI-0042), if set.
nombre_cliente
string | null
Full name from perfiles.nombre_completo for the client.
telefono_cliente
string | null
Phone number from perfiles.telefono for the client.
id_asesor
integer
User ID of the assigned advisor.
nombre_asesor
string | null
Full name from perfiles.nombre_completo for the advisor.
curl -s \
  --cookie "PHPSESSID=<admin_session_id>" \
  "https://your-domain.com/backend/modules/asignaciones/listar.php"
Response 200
{
  "status": 200,
  "message": "Cartera de clientes obtenida",
  "data": [
    {
      "id_asignacion": 12,
      "fecha_asignacion": "2024-06-01 10:00:00",
      "id_cliente": 9,
      "correo_cliente": "empresa@example.com",
      "numero_cliente": "CLI-0009",
      "nombre_cliente": "Empresa Modelo S.A. de C.V.",
      "telefono_cliente": "555-1234",
      "id_asesor": 7,
      "nombre_asesor": "Ana García"
    }
  ]
}
Error responses
CodeMessage
403Acceso denegado
500Error en el servidor

POST /backend/modules/asignaciones/asignar.php

Creates a new active assignment between a client and an advisor. If the client already has an active assignment, it is automatically closed (estado = 'inactivo', fecha_fin = CURRENT_TIMESTAMP) before the new row is inserted. The entire operation runs inside a database transaction. After committing, the server calls NotificationService::notify() to send an "Asignación" notification to the client. Required role: Admin (id_rol = 1)
id_cliente
integer
required
User ID of the client to assign. The server validates that this user exists and has id_rol = 3 (Cliente).
id_asesor
integer
required
User ID of the advisor to assign. The server validates that this user exists and has id_rol = 2 (Asesor).
motivo_cambio
string
Human-readable reason for the assignment or reassignment. Defaults to "Asignación inicial" when omitted.
Calling this endpoint for a client who already has an active assignment will close the existing assignment before creating the new one. The old assignment record is retained in the database with estado = 'inactivo' and is fully visible through the history endpoint.
The id_asignador column is set automatically from the session — the Admin who makes the HTTP request is recorded as the assigner and cannot be overridden in the request body.
curl -s -X POST \
  --cookie "PHPSESSID=<admin_session_id>" \
  -H "Content-Type: application/json" \
  -d '{
    "id_cliente": 9,
    "id_asesor": 7
  }' \
  "https://your-domain.com/backend/modules/asignaciones/asignar.php"
Response 201
{
  "status": 201,
  "message": "Asesor asignado exitosamente",
  "data": null
}
Error responses
CodeMessage
400Faltan campos requeridos (id_cliente, id_asesor)
400El usuario destino no es un Cliente
400El usuario asignado no es un Asesor
403Acceso denegado
404Uno o ambos usuarios no existen
405Método no permitido
500Error en el servidor (with rollback)

GET /backend/modules/asignaciones/historial.php

Returns the complete assignment history for a given client (and optionally filtered to what the Asesor has access to). Results are ordered by fecha_asignacion DESC so the most recent assignment appears first. Admins may query history for any client. Asesores may only retrieve history for clients they have a current or past assignment with. Asesores must supply id_cliente. Required role: Admin or Asesor (id_rol = 1 or 2) Query parameters
id_cliente
integer
Filter history to a specific client. Required for Asesor callers. Optional for Admins — when omitted by an Admin the full history across all clients is returned.
id_asignacion
integer
Primary key of the historical assignment row.
fecha_asignacion
timestamp
UTC timestamp when this assignment was created.
fecha_fin
timestamp | null
UTC timestamp when this assignment was closed. null for the currently active row.
estado
string
activo for the current assignment, inactivo for all prior assignments.
motivo_cambio
string | null
Reason recorded at the time of assignment.
correo_asesor
string
Email of the Asesor in this historical row.
nombre_asesor
string | null
Full name from perfiles.nombre_completo for that Asesor.
correo_asignador
string
Email of the Admin who created this assignment row.
An Admin can retrieve the full timeline for any client, or omit id_cliente to retrieve every assignment row across the entire platform (useful for audit exports).
curl -s \
  --cookie "PHPSESSID=<admin_session_id>" \
  "https://your-domain.com/backend/modules/asignaciones/historial.php?id_cliente=9"
Response 200
{
  "status": 200,
  "message": "Historial de asignaciones obtenido",
  "data": [
    {
      "id_asignacion": 15,
      "fecha_asignacion": "2024-08-20 08:30:00",
      "fecha_fin": null,
      "estado": "activo",
      "motivo_cambio": "El cliente solicitó un asesor con especialidad en IEPS.",
      "correo_asesor": "asesor2@example.com",
      "nombre_asesor": "Carlos López",
      "correo_asignador": "admin@example.com"
    },
    {
      "id_asignacion": 12,
      "fecha_asignacion": "2024-06-01 10:00:00",
      "fecha_fin": "2024-08-20 08:29:55",
      "estado": "inactivo",
      "motivo_cambio": "Asignación inicial",
      "correo_asesor": "asesor@example.com",
      "nombre_asesor": "Ana García",
      "correo_asignador": "admin@example.com"
    }
  ]
}
Error responses
CodeMessage
400Debe especificar un id_cliente
403Acceso denegado
500Error en el servidor

Build docs developers (and LLMs) love