# DOC. SERVICIOS APP - SHALOM FAMILIA

# Modulo Inicial

# Login de usuario - [validate_user_active]

## 🧾 **Descripción**

**Valida si un usuario:**

1. *Existe y su contraseña es correcta*
2. *Está habilitado (**enabled = 1**) en el Doctype `User`*

Es un servicio simple de autenticación básica, expuesto como endpoint público vía `frappe.whitelist(allow_guest=True)`.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fapi%2Fmethod%2Fval"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**<span style="color: rgb(224, 62, 45);">`POST /api/method/validate_user_active`</span>**</div></div>> Nota: El nombre final depende del módulo donde esté definida la función.  
> Ejemplo típico Frappe:  
> `/api/method/app.module.doctype.file.validate_user_active`

---

# 🔐 **Seguridad**

- **allow\_guest=True** → cualquiera puede llamarlo sin token
- Solo valida credenciales usando <span style="color: rgb(224, 62, 45);">**`check_password()`**</span>

⚠️ Esto implica que el endpoint debe usarse únicamente desde un frontend controlado o un gateway seguro.

---

# 📥 **Request Body**

**Formato JSON:**

<table border="1" id="bkmrk-%7B-%22usr%22%3A-%22correo%40dom-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usr"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"correo@dominio.com"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pwd"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"contraseña"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 📤 **Responses**

### ✅ **200 – Usuario válido**

<table border="1" id="bkmrk-%7B-%22success%22%3A-true%2C-%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario válido y activo (check_password)."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ❌ **401 – Credenciales incorrectas**

(Realmente devuelve 200 con success=false, pero semánticamente es un error)

<table border="1" id="bkmrk-%7B-%22success%22%3A-false%2C-" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario o contraseña incorrectos."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ❌ **403 – Usuario deshabilitado**

<table border="1" id="bkmrk-%7B-%22success%22%3A-false%2C--1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El usuario está deshabilitado."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica Interna (resumen)**

1. Ejecuta <span style="color: rgb(224, 62, 45);">**`check_password(usr, pwd)`**</span>
    
    
    - Si falla → usuario o contraseña incorrectos
2. Consulta el campo `enabled`:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span style="color: rgb(224, 62, 45);"><strong>frappe.db.<span class="hljs-built_in">get_value</span>(<span class="hljs-string">"User"</span>, usr, <span class="hljs-string">"enabled"</span>)</strong></span>`</div></div>
3. Devuelve éxito solo si:
    
    
    - Contraseña correcta
    - Usuario habilitado

---

# 📚 **Schemas**

### **Entrada**

<table border="1" id="bkmrk-%7B-%22usr%22%3A-%22string%22%2C-%22-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usr"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pwd"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### **Salida**

<table border="1" id="bkmrk-%7B-%22success%22%3A-%22bool%22%2C-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"bool"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de uso (curl)**

<div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs" id="bkmrk-curl--x-post-https%3A%2F"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/method/app.validate_user_active \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"usr":"admin@example.com", "pwd":"123"}'</span>`</td></tr></tbody></table>

</div><div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--9"><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Guardar usuario - [saveUsersLogeds]

## 🧾 **Descripción**

*Registra y actualiza información de usuarios que inician sesión desde la aplicación móvil.*  
*Además, valida si la versión de la app instalada es compatible con la versión mínima definida en el servidor.*

**Funcionalidad:**

1. **Verifica la versión de la app** contra<span style="color: rgb(224, 62, 45);"> </span><span style="color: rgb(186, 55, 42);">`<strong><span style="color: rgb(224, 62, 45);">versiones.json</span></strong>`</span>.
2. **Crea o actualiza** el registro de un usuario en la base de datos `mysql2.users`.
3. Devuelve mensaje de éxito o error según el proceso.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fsave-users-log"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /save-users-logeds`**</span></div></div>> El nombre real depende del archivo de rutas de Laravel (web.php / api.php).

---

# 🔐 **Seguridad**

- Requiere enviar parámetros en el body (no hay autenticación nativa).
- Se recomienda usarlo en rutas **API protegidas**.

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22user%22%3A-%22string%22%2C-" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"user"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1320" data-start="1068"><thead data-end="1115" data-start="1068"><tr data-end="1115" data-start="1068"><th data-col-size="sm" data-end="1079" data-start="1068">Campo</th><th data-col-size="sm" data-end="1088" data-start="1079">Tipo</th><th data-col-size="sm" data-end="1100" data-start="1088">Requerido</th><th data-col-size="md" data-end="1115" data-start="1100">Descripción</th></tr></thead><tbody data-end="1320" data-start="1164"><tr data-end="1237" data-start="1164"><td data-col-size="sm" data-end="1175" data-start="1164">user</td><td data-col-size="sm" data-end="1184" data-start="1175">string</td><td data-col-size="sm" data-end="1196" data-start="1184">Sí</td><td data-col-size="md" data-end="1237" data-start="1196">Username que se registra o actualiza.</td></tr><tr data-end="1320" data-start="1238"><td data-col-size="sm" data-end="1249" data-start="1238">version</td><td data-col-size="sm" data-end="1258" data-start="1249">string</td><td data-col-size="sm" data-end="1270" data-start="1258">Sí</td><td data-col-size="md" data-end="1320" data-start="1270">Versión de la app instalada en el dispositivo.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

### ❗ Importante

En tu código actual, la primera línea retorna **inmediatamente**:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-return-%5B-%22valor%22%3D%3Etr" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">return</span> [   <span class="hljs-string">"valor"</span>=><span class="hljs-literal">true</span>,   <span class="hljs-string">"msn"</span>=> <span class="hljs-string">"Registro actualizado"</span>,];`</td></tr></tbody></table>

Por lo tanto **todo el servicio está anulado**.  
Si esto es accidental, debes eliminar ese `return`.

Aun así, la documentación refleja lo que *debería hacer* según el resto del código.

---

## ✔️ **Versión actualizada (200 OK)**

Si la versión enviada es igual o mayor que la versión mínima del archivo `versiones.json`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Registro Exitoso"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

o

<table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Registro actualizado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **Versión desactualizada**

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Actualize su aplicacion en Play Store"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version_app"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1.0.1"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version_service"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1.0.5"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **Error al registrar o actualizar usuario**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Registre un usuario"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

o

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Registro Actualizado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica Interna (detallada)**

### 1. Leer versión mínima del archivo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%2Fpublic%2Fversion-app%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`/<span class="hljs-built_in">public</span>/<span class="hljs-keyword">version</span>-app/versiones.json`**</span></div></div>**Campo utilizado:** `<span class="hljs-attribute">familia</span>`

### 2. Convertir versiones a enteros

**Ejemplo:**  
“1.2.3” → 123

Esto permite compararlas.

### 3. Validación:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-si-intversionapp-%3C-i"><div class="overflow-y-auto p-4" dir="ltr">**`<span class="hljs-built_in">Si</span> intVersionApp < intVersionDefine → debe actualizar`**</div></div>### 4. Registrar usuario:

- Si no existe → insertar username + primera sesión + última sesión
- Si existe → actualizar última sesión
- Base de datos usada: **mysql2**

Tablas y campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-users.username-users"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`users.usernameusers.fecha_primera_susers.fecha_ultima_s`</div></div>---

# 📚 **Esquema del JSON de version-app/versiones.json**

**Se utiliza solo el campo:**

<table border="1" id="bkmrk-%7B-%22familia%22%3A-%221.0.5%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"familia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1.0.5"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🗃 **Schemas**

### Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22user%22%3A-%22string%22%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22user%22%3A-%22string%22%2C--2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"user"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version_app"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string(optional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version_service"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string(optional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-curl--x-post-https%3A%2F-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/save-users-logeds \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"user":"jhon.doe","version":"1.0.2"}'</span>`</td></tr></tbody></table>

---

# ⚠️ Notas importantes para documentación

### 🔴 Problema detectado

**La primera línea del método cancela toda la lógica:**

<table border="1" id="bkmrk-return-%5B-%22valor%22%3D%3Etr-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">return</span> [   <span class="hljs-string">"valor"</span>=><span class="hljs-literal">true</span>,   <span class="hljs-string">"msn"</span>=> <span class="hljs-string">"Registro actualizado"</span>,];`</td></tr></tbody></table>

Si quieres que el servicio funcione como en la documentación, debes eliminar ese `return`.

# Términos y Condiciones - [setTermsAndConditions]

## 🧾 **Descripción**

*Registra la aceptación de los Términos y Condiciones por parte del usuario logueado en la aplicación.*  
*El proceso localiza al empleado asociado al `user_id` (email del usuario) y actualiza los campos:*

- `<span style="color: rgb(224, 62, 45);"><strong>terminos_y_condiciones_app = 1</strong></span>`
- **<span style="color: rgb(224, 62, 45);">`fecha_terminos_y_condiciones = fecha/hora actual`</span>**

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fset-terms-and-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /<span class="hljs-built_in">set-terms</span><span class="hljs-operator">-and</span><span class="hljs-literal">-conditions</span>`**</span></div></div>> La ruta exacta depende de cómo esté configurado en tus <span style="color: rgb(224, 62, 45);">**`routes/api.php`**</span>.

---

# 🔐 **Seguridad**

- No requiere token explícito aquí, pero el backend usa <span style="color: rgb(224, 62, 45);">**`apiService`**</span>, que probablemente **sí exige autenticación** hacia ERPNext.
- Se recomienda proteger este endpoint detrás de autenticación de la app.

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22email_logued%22%3A-%22s" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos requeridos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1248" data-start="991"><thead data-end="1043" data-start="991"><tr data-end="1043" data-start="991"><th data-col-size="sm" data-end="1007" data-start="991">Campo</th><th data-col-size="sm" data-end="1016" data-start="1007">Tipo</th><th data-col-size="sm" data-end="1028" data-start="1016">Requerido</th><th data-col-size="lg" data-end="1043" data-start="1028">Descripción</th></tr></thead><tbody data-end="1248" data-start="1097"><tr data-end="1248" data-start="1097"><td data-col-size="sm" data-end="1113" data-start="1097">email\_logued</td><td data-col-size="sm" data-end="1122" data-start="1113">string</td><td data-col-size="sm" data-end="1134" data-start="1122">Sí</td><td data-col-size="lg" data-end="1248" data-start="1134">Email del usuario con el que inició sesión en la app. Este email debe coincidir con el `user_id` del Employee.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

## ✔️ 200 – Términos aceptados correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Terminos y Condiciones Aceptadas Correctamente"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 400 – Falta el email

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es necesario el email con el que ha entrado a la app"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 404 – No existe Employee asociado al usuario

**Incluye ambos casos del código:**

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al traer el empleado asociado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 500 – Error al actualizar Employee

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al aceptar terminos y condiciones"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuesta ERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 500 – Error inesperado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--11"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error en el servicio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica Interna**

1. **Validación inicial**  
    Si <span style="color: rgb(224, 62, 45);">**`email_logued`**</span> viene vacío → error
2. **Buscar Employee asociado al usuario**  
    **Consulta en ERP:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`GET Employee?limit=None  &fields=[<span class="hljs-string">"name"</span>,<span class="hljs-string">"terminos_y_condiciones_app"</span>]  &filters=<span class="hljs-string">[["user_id","=", email_logued]]</span>`</td></tr></tbody></table>
    
    </div></div>
3. **Manejo de errores:**
    
    
    - Respuesta sin `<span style="color: rgb(224, 62, 45);"><strong>data</strong></span>`
    - Array vacío
4. **Actualizar Employee**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`PUT Employee/{employee_name}{  <span class="hljs-string">"terminos_y_condiciones_app"</span>: <span class="hljs-number">1</span>,  <span class="hljs-string">"fecha_terminos_y_condiciones"</span>: <span class="hljs-string">"Y-m-d H:i:s"</span>}`</td></tr></tbody></table>
    
    </div></div>
5. **Si el response incluye** `"<span style="color: rgb(224, 62, 45);"><strong>data</strong></span>"` → éxito  
    Si no → error

---

# 📚 **Schemas**

### Request Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22email_logued%22%3A-%22s-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--15"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"object (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de Uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/set-terms-and-conditions \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"email_logued":"user@example.com"}'</span>`</td></tr></tbody></table>

</div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Obtener Usuario (1,2,3,4) - [getUser3]

## 🧾 **Descripción**

*Retorna la información del usuario ingresado en la app (empleado o estudiante).*  
*El servicio consulta primero la tabla **Employee** del ERP.*  
*Si no existe o no está activo, consulta la tabla **Student**.*  
*Finalmente, devuelve la información personal, laboral/educativa, permisos y datos complementarios.*

*Funciona como un **servicio maestro de login/datos del usuario** para la aplicación móvil.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fget-user3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /get-user3`**</span></div></div>> El nombre real depende del archivo **<span style="color: rgb(224, 62, 45);">`routes/api.php`</span>**.

---

# 🔐 **Seguridad**

- No se ve autenticación explícita, pero las consultas al ERP (<span style="color: rgb(224, 62, 45);">**`dbErp`**</span>, <span style="color: rgb(224, 62, 45);">**`ServiceErp`**</span>) requieren token/credenciales internas.
- Se recomienda protegerlo con autenticación JWT o middleware.

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22username%22%3A-%22strin" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1231" data-start="1033"><thead data-end="1075" data-start="1033"><tr data-end="1075" data-start="1033"><th data-col-size="sm" data-end="1041" data-start="1033">Campo</th><th data-col-size="sm" data-end="1048" data-start="1041">Tipo</th><th data-col-size="sm" data-end="1060" data-start="1048">Requerido</th><th data-col-size="md" data-end="1075" data-start="1060">Descripción</th></tr></thead><tbody data-end="1231" data-start="1121"><tr data-end="1231" data-start="1121"><td data-col-size="sm" data-end="1132" data-start="1121">username</td><td data-col-size="sm" data-end="1141" data-start="1132">string</td><td data-col-size="sm" data-end="1146" data-start="1141">Sí</td><td data-col-size="md" data-end="1231" data-start="1146">Email o DNI/pasaporte. Si contiene “@” se asume email, de lo contrario documento.</td></tr></tbody></table>

</div></div>---

# 🧩 **Lógica Interna Detallada**

## 1️⃣ Determinar si buscar por email o documento

- Si el parámetro incluye “@” → buscar por <span style="color: rgb(224, 62, 45);">**`emp.user_id`**</span>
- Sino → buscar por <span style="color: rgb(224, 62, 45);">**`emp.passport_number`**</span>

## 2️⃣ Consultar información del empleado en ERP

Consulta SQL con múltiples JOIN:

**Tablas involucradas:**

- `tabEmployee` (principal)
- `tabUser`
- `tabBranch`
- `tabContrato de Trabajo`
- `tabDepartment`

Si no encuentra empleado → pasa a modo estudiante.

---

### ❌ Errores de empleado antes de consultar estudiante:

- No `valor` en la respuesta
- `response` vacío  
    → continuar con búsqueda en Student

---

## 3️⃣ Consultar información del estudiante (fallback)

**Si el usuario no es empleado, consulta en:**

- `tabStudent`
- `tabUser`
- `tabBranch`
- `tabJob Applicant`
- `tabRequerimiento de Personal`
- `tabDesignation`
- `tabDepartment`

### Validaciones de estudiante:

- Si no existe →
    
    <table border="1" style="border-collapse: collapse; width: 100%; height: 33.8px;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr style="height: 33.8px;"><td style="height: 33.8px;">`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sin Estudiante: ..."</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
- Si el usuario está deshabilitado (<span style="color: rgb(224, 62, 45);">**`us.enabled = 0`**</span>) →

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario Deshabilitado..."</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>...<span class="hljs-punctuation">]</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

Si todo está correcto → retorna data del estudiante.

---

## 4️⃣ Procesamiento final de empleado

### Validaciones

- Si <span style="color: rgb(224, 62, 45);">**`status = Inactive`**</span> → usuario no puede usar la app

### Ajustes en la data:

- Formato de fecha de nacimiento → <span style="color: rgb(224, 62, 45);">**`mm-dd`**</span>
- Si contrato indeterminado → reemplazar texto
- Detectar si es renovación o primer contrato (ServiceErp)
- Normalizar campos:
    
    
    - `bank_ac_no`
    - `pets`
    - `tipo_usuario = "Empleado"`

---

## 5️⃣ Respuesta final (Empleado o Estudiante)

Retorna la data enriquecida del usuario.

---

# 📤 **Responses**

## ✔️ 200 – Usuario encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Si hay data"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span> ... <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ Usuario no es empleado ni estudiante

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--12"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Este usuario no es empleado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ Usuario estudiante sin permisos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sin Estudiante: Su usuario no tiene permisos para acceder al aplicativo. Contactar con soporte."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ Usuario deshabilitado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--16"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario Deshabilitado: Comuníquese con su administrador"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span> ... <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ Empleado inactivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--18"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado Inactivo: Comuníquese con su administrador"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span> ... <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 📚 **Schemas**

### Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--20"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22username%22%3A-%22strin-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response (general)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--21"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"array"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--23"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-curl--x-post-https%3A%2F" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/get-user3 \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"username":"empleado@empresa.com"}'</span>`</td></tr></tbody></table>

---

# ✔️ Servicios ERP usados internamente

### 1. <span style="color: rgb(224, 62, 45);">**`send-query-database`**</span>

Método POST que ejecuta consultas SQL personalizadas en ERPNext.

### 2. `<span style="color: rgb(224, 62, 45);"><strong>resource/Contrato de Trabajo</strong></span>`

Consulta REST para obtener contratos de trabajo.

---

# 📝 Observaciones técnicas (reales)

- Código mezcla SQL dinámico en body con filtros JSON → validar inyección.
- Se usa <span style="color: rgb(224, 62, 45);">**`LIMIT 1`**</span> en employee, pero la consulta de contratos tiene <span style="color: rgb(224, 62, 45);">**`limit=None`**</span>.
- Campos duplicados en <span style="color: rgb(224, 62, 45);">**`sql_query`**</span> (ej. <span style="color: rgb(224, 62, 45);">**`emp.bank_ac_no`**</span> aparece 2 veces).
- Es un servicio **muy grande**, podría dividirse por responsabilidad.

# Obtener Version - [version]

## 🧾 **Descripción**

*Obtiene la versión actual de una aplicación móvil específica.*  
*El servicio valida si el identificador de la app existe y, de ser así, devuelve la versión correspondiente.*

**Este endpoint se usa para:**

- Mostrar la versión actual al usuario
- Verificar actualizaciones desde la app móvil
- Controlar múltiples aplicaciones dentro del mismo backend

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fversion"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /version`**</span></div></div>> La ruta final dependerá del archivo de rutas (**<span style="color: rgb(224, 62, 45);">`routes/api.php`</span>**).

---

# 🔐 **Seguridad**

- Sin autenticación explícita
- Normalmente accesible para todas las apps móviles

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22app%22%3A-%22string%22-%7D" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"app"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1046" data-start="860"><thead data-end="904" data-start="860"><tr data-end="904" data-start="860"><th data-col-size="sm" data-end="868" data-start="860">Campo</th><th data-col-size="sm" data-end="877" data-start="868">Tipo</th><th data-col-size="sm" data-end="889" data-start="877">Requerido</th><th data-col-size="md" data-end="904" data-start="889">Descripción</th></tr></thead><tbody data-end="1046" data-start="950"><tr data-end="1046" data-start="950"><td data-col-size="sm" data-end="958" data-start="950">app</td><td data-col-size="sm" data-end="967" data-start="958">string</td><td data-col-size="sm" data-end="979" data-start="967">Sí</td><td data-col-size="md" data-end="1046" data-start="979">Identificador de la aplicación cuya versión se desea consultar.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

## ✔️ 200 – App encontrada (Versión obtenida)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%; height: 33.8px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 33.8px;"><td style="height: 33.8px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Versión del app MiApp: 1.0.5"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1.0.5"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

*El nombre mostrado proviene de:* <span style="color: rgb(224, 62, 45);">**`<span class="hljs-variable">$name_app</span> = <span class="hljs-variable language_">$this</span>->apps[<span class="hljs-variable">$app</span>];`**</span>

*La versión proviene de:* <span style="color: rgb(224, 62, 45);">**`<span class="hljs-variable">$versiones</span> = <span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">data</span>();<span class="hljs-variable">$version</span> = <span class="hljs-variable">$versiones</span>[<span class="hljs-variable">$app</span>];`**</span>

---

## ❌ 404 / 200 – App no existente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No existe esa app"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>> Nota: El método devuelve **200 OK** incluso cuando la app no existe.  
> (Esto es comportamiento actual del código.)

---

# 🧩 **Lógica Interna**

1. Recibe el parámetro <span style="color: rgb(224, 62, 45);">**`app`**</span>.
2. Obtiene todas las versiones desde <span style="color: rgb(224, 62, 45);">**`$this->data()`**</span>  
    *(método interno que no está mostrado pero retorna un array asociativo)*.
3. Valida si la clave <span style="color: rgb(224, 62, 45);">**`app`**</span> existe en el array versiones:
    
    
    - **No existe** → error
    - **Existe** → procede
4. Obtiene el nombre de la app desde: <span style="color: rgb(224, 62, 45);">**`<span class="hljs-variable">$this</span>->apps[<span class="hljs-variable">$app</span>]`**</span>
5. Obtiene la versión asociada: `<span class="hljs-variable"><strong><span style="color: rgb(224, 62, 45);">$versiones</span></strong></span><strong><span style="color: rgb(224, 62, 45);">[<span class="hljs-variable">$app</span>]</span></strong>`
6. Devuelve la versión actual en el message.

---

# 📚 **Schema**

### Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--9"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22app%22%3A-%22string%22-%7D-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"app"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de Uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--12"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-curl--x-post-https%3A%2F" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/version \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"app":"shalom_app"}'</span>`</td></tr></tbody></table>

**Respuesta esperada:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Versión del app Shalom App: 3.1.4"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"version"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"3.1.4"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Rol de usuario - [rolUsuario]

## 🧾 **Descripción**

*Valida si un usuario tiene el rol **"Supervisor Nacional"** dentro del ERP.*  
*Busca en la tabla <span style="color: rgb(224, 62, 45);">**`tabHas Role`**</span> un registro cuya columna <span style="color: rgb(224, 62, 45);">**`role = 'Supervisor Nacional'`**</span> y <span style="color: rgb(224, 62, 45);">**`parent = {name_usuario}`**</span>.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Frol-usuario"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<strong><span style="color: rgb(224, 62, 45);">POST /rol-usuario</span></strong>`</div></div>> La ruta exacta depende de tu archivo `routes/api.php`.

---

# 🔐 **Seguridad**

- Recibe el nombre del usuario sin autenticación adicional.
- Se recomienda incluir autenticación JWT o token de aplicación para mayor seguridad.

---

# 📥 **Request Body**

### JSON

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22name%22%3A-%22string%22-%7D" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="928" data-start="757"><thead data-end="801" data-start="757"><tr data-end="801" data-start="757"><th data-col-size="sm" data-end="765" data-start="757">Campo</th><th data-col-size="sm" data-end="774" data-start="765">Tipo</th><th data-col-size="sm" data-end="786" data-start="774">Requerido</th><th data-col-size="md" data-end="801" data-start="786">Descripción</th></tr></thead><tbody data-end="928" data-start="847"><tr data-end="928" data-start="847"><td data-col-size="sm" data-end="855" data-start="847">name</td><td data-col-size="sm" data-end="864" data-start="855">string</td><td data-col-size="sm" data-end="876" data-start="864">Sí</td><td data-col-size="md" data-end="928" data-start="876">Nombre interno del usuario en ERPNext (us.name).</td></tr></tbody></table>

</div></div>---

# 🧩 **Lógica Interna del Servicio (resumen)**

1. Toma <span style="color: rgb(224, 62, 45);">**`name`**</span> desde el request.
2. Construye una consulta SQL hacia ERP que busca:
    
    
    - El usuario (<span style="color: rgb(224, 62, 45);">**`rol.parent`**</span>)
    - El rol <span style="color: rgb(224, 62, 45);">**`"Supervisor Nacional"`**</span> <span style="color: rgb(224, 62, 45);">**(`rol.role`)**</span>
3. Ejecuta:
    
    
    - `<span style="color: rgb(224, 62, 45);"><strong>dbErp("POST", body, method/send-query-database)</strong></span>`
4. Si encuentra el rol → retorna verdadero
5. Si no lo encuentra → indica que no es supervisor
6. Maneja errores con <span style="color: rgb(224, 62, 45);">**`try/catch`**</span>.

---

# 📤 **Responses**

## ✔️ 200 – Usuario es Supervisor Nacional

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22value%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Listado exitoso"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 200 – Usuario NO es supervisor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22value%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario no es supervisor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 500 – Error interno al procesar

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22value%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Mensaje de excepción"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 📚 **Schemas**

### Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--12"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22name%22%3A-%22string%22-%7D-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--13"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22value%22%3A-%22boolean%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean (solo en éxito o denegado)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 Ejemplo de uso (curl)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/rol-usuario \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"name":"jhon.doe@empresa.com"}'</span>`</td></tr></tbody></table>

</div></div>

# Permisos del modulo - [permissions-module]

## 🧾 **Descripción**

*Devuelve un listado de permisos de módulos habilitados para el usuario autenticado en la app.*  
*Además, determina si el usuario tiene acceso al módulo **“solicitudes\_de\_pagos”**, validándolo contra listas internas y datos del ERP (tabla <span style="color: rgb(224, 62, 45);">**`Validacion de Pagos Gerencia`**</span>).*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fpermissions-mo"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /permissions-modules`**</span></div></div>---

# 🔐 **Seguridad**

- Requiere usuario enviado en el body.
- No usa autenticación adicional dentro del servicio, pero sí consulta el ERP vía <span style="color: rgb(224, 62, 45);">**`dbErp()`**</span>.

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22usuario%22%3A-%22string" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="969" data-start="809"><thead data-end="856" data-start="809"><tr data-end="856" data-start="809"><th data-col-size="sm" data-end="820" data-start="809">Campo</th><th data-col-size="sm" data-end="829" data-start="820">Tipo</th><th data-col-size="sm" data-end="841" data-start="829">Requerido</th><th data-col-size="sm" data-end="856" data-start="841">Descripción</th></tr></thead><tbody data-end="969" data-start="905"><tr data-end="969" data-start="905"><td data-col-size="sm" data-end="916" data-start="905">usuario</td><td data-col-size="sm" data-end="925" data-start="916">string</td><td data-col-size="sm" data-end="937" data-start="925">Sí</td><td data-col-size="sm" data-end="969" data-start="937">Email del usuario de la app.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

## ✔️ 200 – Respuesta exitosa

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"lista de dni validacion módulos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"informacion_personal"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"marcaciones"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"otros_descuentos"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"capacitacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"contrato_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"boletas_de_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"solicitudes"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"reconocimiento_de_deuda"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"centro_de_ayuda"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"supervision"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"asistencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"contratacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"convocatoria"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"documentos_internos"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"solicitudes_de_pagos"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>> **Nota:** El valor de <span style="color: rgb(224, 62, 45);">**`solicitudes_de_pagos`**</span> depende del usuario.

---

## ❌ 400 – Falta el usuario en la solicitud

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe enviar el usuario"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica Interna**

### 1. Validar que se envíe el parámetro <span style="color: rgb(224, 62, 45);">**`usuario`**</span>

Si no existe → retorna error.

### 2. Lista inicial de usuarios con permiso en <span style="color: rgb(224, 62, 45);">**`solicitudes_de_pagos`**</span>

**Hardcoded en el código:**

<table border="1" id="bkmrk-%5B-%2245738484%40shalomco" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`[  <span class="hljs-string">"45738484@shalomcontrol.com"</span>,  <span class="hljs-string">"40650120@shalomcontrol.com"</span>,  <span class="hljs-string">"40377937@shalomcontrol.com"</span>]`</td></tr></tbody></table>

### 3. Consulta al ERP

**Consulta la tabla:** <span style="color: rgb(224, 62, 45);">**`<span class="hljs-attribute">tabValidacion</span> de Pagos Gerencia`**</span>

**Utiliza:** <span style="color: rgb(224, 62, 45);">**`<span class="hljs-keyword">SELECT</span> usuario <span class="hljs-keyword">FROM</span> `tabValidacion de Pagos Gerencia``**</span>

Si la respuesta contiene valores, se agregan a la lista general.

### 4. Mezcla de listas

**Se combinan:**

- Lista hardcodeada
- Lista proveniente del ERP

### 5. Validación final

**<span style="color: rgb(224, 62, 45);">`solicitudes_de_pagos = in_array(usuario, lista_combinada)`</span>**

### 6. Todos los demás permisos se marcan como `true`

---

# 📚 **Schema de Respuesta**

### <span style="color: rgb(224, 62, 45);">**`data`**</span> (permisos)

<table border="1" id="bkmrk-%7B-%22informacion_perso" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"informacion_personal"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"marcaciones"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"otros_descuentos"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"capacitacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"contrato_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"boletas_de_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"solicitudes"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"reconocimiento_de_deuda"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"centro_de_ayuda"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"supervision"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"asistencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"contratacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"convocatoria"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"documentos_internos"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"solicitudes_de_pagos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean dinámico"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/permissions-modules \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"usuario":"user@example.com"}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Verificar *** - [verifyDownloadSalary]

## 🧾 **Descripción**

*Valida si un trabajador ha descargado su boleta de pago correspondiente al mes anterior.*  
*La validación solo aplica del **día 1 al 7 de cada mes**; fuera de ese rango, se asume automáticamente como validación positiva.*

*El servicio consulta el registro de descargas en la tabla <span style="color: rgb(224, 62, 45);">**`historial_procesos_app`**</span>.*

---

# 🚀 Endpoint

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fverify-downloa"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**<span style="color: rgb(224, 62, 45);">`POST /verify-download-salary`</span>**</div></div>> La ruta final depende de cómo esté configurada en <span style="color: rgb(224, 62, 45);">**`routes/api.php`**</span>.

---

# 🔐 Seguridad

No se valida token en el controlador, pero se recomienda proteger el endpoint detrás de autenticación de la app.

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22employee%22%3A-%22strin" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fechaIngreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (YYYY-MM-DD)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1195" data-start="902"><thead data-end="956" data-start="902"><tr data-end="956" data-start="902"><th data-col-size="sm" data-end="918" data-start="902">Campo</th><th data-col-size="sm" data-end="927" data-start="918">Tipo</th><th data-col-size="sm" data-end="941" data-start="927">Obligatorio</th><th data-col-size="md" data-end="956" data-start="941">Descripción</th></tr></thead><tbody data-end="1195" data-start="1012"><tr data-end="1095" data-start="1012"><td data-col-size="sm" data-end="1028" data-start="1012">employee</td><td data-col-size="sm" data-end="1037" data-start="1028">string</td><td data-col-size="sm" data-end="1051" data-start="1037">Sí</td><td data-col-size="md" data-end="1095" data-start="1051">Código del empleado (ID del trabajador).</td></tr><tr data-end="1195" data-start="1096"><td data-col-size="sm" data-end="1112" data-start="1096">fechaIngreso</td><td data-col-size="sm" data-end="1121" data-start="1112">string</td><td data-col-size="sm" data-end="1135" data-start="1121">Sí</td><td data-col-size="md" data-end="1195" data-start="1135">Fecha de ingreso del trabajador en formato `YYYY-MM-DD`.</td></tr></tbody></table>

</div></div>---

# 🧠 Reglas de negocio

1. **Validación por fecha**  
    Si la fecha actual es mayor al día 7 del mes → **no corresponde validación**.
2. Obtiene el **mes anterior** y convierte el número en texto (ej. 01 → Enero).
3. Si <span style="color: rgb(224, 62, 45);">**`fechaIngreso >= primer día del mes actual`**</span>, entonces el trabajador ingresó recientemente → **no se valida descarga**.
4. Consulta en la BD (<span style="color: rgb(224, 62, 45);">**`mysql2.historial_procesos_app`**</span>) si existe un registro:
    
    
    - `proceso = 'NOMINA'`
    - `empleado = <employee>`
    - `month` y `year` del mes anterior
    - Registros con fecha ascendente
5. Si existe registro → sí descargó  
    Si no → debe descargar su boleta pendiente.

---

# 📤 Responses

### 🟦 Caso 1: Fuera del rango de fechas (después del día 7)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No corresponde validación, fuera de fecha."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### 🟥 Error: falta fecha de ingreso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe enviar la fecha de ingreso del trabajador"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### 🟥 Error: falta empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe enviar el código de empleado del trabajador"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### 🟦 Caso 2: Ingreso reciente (no se valida)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--12"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No corresponde validación"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### 🟩 Caso 3: El trabajador SÍ descargó su boleta

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Si descargó boleta."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### 🟥 Caso 4: El trabajador NO descargó su boleta

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--16"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Tiene pendiente descargar su boleta de pago del mes de <MesTexto> <Año>, descárguelo desde el módulo Boletas de Pago."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

**Ejemplo:**

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Tiene pendiente descargar su boleta de pago del mes de Enero 2025, descárguelo desde el módulo Boletas de Pago."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🔎 Ejemplo de consumo (curl)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/verify-download-salary \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"employee":"EMP-001","fechaIngreso":"2023-02-15"}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Obtener publicaciones - [obtainPosts2]

## 🧾 **Descripción**

*Obtiene publicaciones (posts) asociadas a un usuario y una categoría determinada.*  
*La lógica de filtrado, cacheo o búsqueda se realiza internamente mediante el método:*

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Epostscache%28%24u"><div class="overflow-y-auto p-4" dir="ltr">*`<span class="hljs-variable"><span style="color: rgb(224, 62, 45);"><strong>$this</strong></span></span><span style="color: rgb(224, 62, 45);"><strong>->postsCache(<span class="hljs-variable">$user</span>, <span class="hljs-variable">$category</span>)</strong></span>`*</div></div>*Este servicio únicamente recibe los parámetros, solicita la data a <span style="color: rgb(224, 62, 45);">**`postsCache()`**</span> y devuelve la respuesta.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fobtain-posts"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /obtain-posts`**</span></div></div>> El nombre final dependerá de tu archivo `routes/api.php`.

---

# 🔐 **Seguridad**

No realiza autenticación explícita.  
Si requieres seguridad, debe implementarse a nivel de ruta (middleware).

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22cookie%22%3A-%22string-" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"user"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"category"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1264" data-start="888"><thead data-end="936" data-start="888"><tr data-end="936" data-start="888"><th data-col-size="sm" data-end="900" data-start="888">Campo</th><th data-col-size="sm" data-end="909" data-start="900">Tipo</th><th data-col-size="sm" data-end="921" data-start="909">Requerido</th><th data-col-size="md" data-end="936" data-start="921">Descripción</th></tr></thead><tbody data-end="1264" data-start="986"><tr data-end="1094" data-start="986"><td data-col-size="sm" data-end="998" data-start="986">cookie</td><td data-col-size="sm" data-end="1007" data-start="998">string</td><td data-col-size="sm" data-end="1019" data-start="1007">No</td><td data-col-size="md" data-end="1094" data-start="1019">Cookie del usuario. En este servicio **no se usa**, pero está recibido.</td></tr><tr data-end="1186" data-start="1095"><td data-col-size="sm" data-end="1107" data-start="1095">user</td><td data-col-size="sm" data-end="1116" data-start="1107">string</td><td data-col-size="sm" data-end="1128" data-start="1116">Sí</td><td data-col-size="md" data-end="1186" data-start="1128">ID o email del usuario para obtener las publicaciones.</td></tr><tr data-end="1264" data-start="1187"><td data-col-size="sm" data-end="1199" data-start="1187">category</td><td data-col-size="sm" data-end="1208" data-start="1199">string</td><td data-col-size="sm" data-end="1220" data-start="1208">Sí</td><td data-col-size="md" data-end="1264" data-start="1220">Categoría de las publicaciones a listar.</td></tr></tbody></table>

</div></div>---

# 📤 **Respuesta (200 OK)**

### Ejemplo de respuesta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22data%22%3A-%5B-%2F%2F-conte" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-comment">// contenido devuelto por postsCache()</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

La estructura interna depende íntegramente de lo que retorne <span style="color: rgb(224, 62, 45);">**`postsCache()`**</span>.

---

# 🧩 **Lógica Interna (resumen)**

1. Recibe <span style="color: rgb(224, 62, 45);">**`cookie`**</span>, <span style="color: rgb(224, 62, 45);">**`user`**</span>, y <span style="color: rgb(224, 62, 45);">**`category`**</span>.
2. Llama a: `<span style="color: rgb(224, 62, 45);"><strong>postsCache(<span class="hljs-variable">$user</span>, <span class="hljs-variable">$category</span>)</strong></span>`
3. Devuelve un JSON simple:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`{ <span class="hljs-string">"data"</span>: <resultado> }`</td></tr></tbody></table>
    
    </div></div></div></div>

---

# 📚 **Schema de Respuesta**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22data%22%3A-%22array-%7C-o" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"array | object según postsCache()"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo en curl**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/obtain-posts \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"user":"user@example.com","category":"capacitacion"}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Página nueva - [registerLikeForPosts]

## 🧾 **Descripción**

*Permite registrar un **Like** o **Dislike** sobre una publicación del módulo Publicaciones en ERPNext.*  
*La acción se ejecuta usando el endpoint interno <span style="color: rgb(224, 62, 45);">**`frappe.desk.like.toggle_like`**</span>, el cual requiere un **cookie de sesión válido**.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fregister-like-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /<span class="hljs-keyword">register</span>-like-<span class="hljs-keyword">for</span>-posts`**</span></div></div>> La ruta exacta depende de tu archivo <span style="color: rgb(224, 62, 45);">**`routes/api.php`**</span>.

---

# 🔐 **Seguridad**

Este endpoint **requiere el cookie de sesión Frappe**, el cual se envía desde la aplicación móvil.  
Sin el cookie, el servicio **rechaza la operación**.

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22cookie%22%3A-%22string%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"marked"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos requeridos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1189" data-start="872"><thead data-end="918" data-start="872"><tr data-end="918" data-start="872"><th data-col-size="sm" data-end="881" data-start="872">Campo</th><th data-col-size="sm" data-end="891" data-start="881">Tipo</th><th data-col-size="sm" data-end="903" data-start="891">Requerido</th><th data-col-size="md" data-end="918" data-start="903">Descripción</th></tr></thead><tbody data-end="1189" data-start="966"><tr data-end="1029" data-start="966"><td data-col-size="sm" data-end="975" data-start="966">cookie</td><td data-col-size="sm" data-end="985" data-start="975">string</td><td data-col-size="sm" data-end="990" data-start="985">Sí</td><td data-col-size="md" data-end="1029" data-start="990">Cookie de sesión válido en ERPNext.</td></tr><tr data-end="1127" data-start="1030"><td data-col-size="sm" data-end="1039" data-start="1030">name</td><td data-col-size="sm" data-end="1049" data-start="1039">string</td><td data-col-size="sm" data-end="1054" data-start="1049">Sí</td><td data-col-size="md" data-end="1127" data-start="1054">Nombre del documento `Publicaciones` al que se aplicará Like/Dislike.</td></tr><tr data-end="1189" data-start="1128"><td data-col-size="sm" data-end="1137" data-start="1128">marked</td><td data-col-size="sm" data-end="1147" data-start="1137">boolean</td><td data-col-size="sm" data-end="1152" data-start="1147">Sí</td><td data-col-size="md" data-end="1189" data-start="1152">`true` = Like, `false` = Dislike.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

## ✔️ **200 – Like o Dislike registrado correctamente**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Like para publicación correcto"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

(El mensaje cambia dependiendo de `marked`)

---

## ❌ **400 – Falta de parámetros**

### Falta nombre

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es necesario el nombre de la publicación para dar like"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Falta marked

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es necesario el estado del like"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Falta cookie

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--9"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es necesario el cookie para dar like"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"cookie_recibida"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **500 – Error desde ERPNext**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--11"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al generar Servicio"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<detalle_del_error>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica Interna**

1. Valida parámetros obligatorios: <span style="color: rgb(224, 62, 45);">**`name`**</span>, <span style="color: rgb(224, 62, 45);">**`marked`**</span>, <span style="color: rgb(224, 62, 45);">**`cookie`**</span>.
2. Construye la propiedad <span style="color: rgb(224, 62, 45);">**`add`**</span>:
    
    
    - <span style="color: rgb(224, 62, 45);">**`marked = true`**</span> → `"<span style="color: rgb(224, 62, 45);"><strong>Yes</strong></span>"`
    - <span style="color: rgb(224, 62, 45);">**`marked = false`**</span> → `"<span style="color: rgb(224, 62, 45);"><strong>No</strong></span>"`
3. Construye la llamada a ERPNext:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /method/frappe.desk.like.toggle_likeHeaders:    Cookie: <cookie>    Content-Type: application/jsonBody:    {      <span class="hljs-string">"doctype"</span>: <span class="hljs-string">"Publicaciones"</span>,      <span class="hljs-string">"name"</span>: <span class="hljs-string">"<nombre>"</span>,      <span class="hljs-string">"add"</span>: <span class="hljs-string">"Yes/No"</span>    }`</div></td></tr></tbody></table>
    
    </div></div>
4. ERPNext registra o quita el Like.
5. Devuelve mensaje según operación: "Like" o "Dislike".

---

# 📚 **Schemas**

### Request Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22cookie%22%3A-%22string%22-1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"marked"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--15"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"array | object"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 Ejemplo de uso (curl)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/register-like-for-posts \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{  "cookie": "sid=12345abcde",  "name": "PUB-00012",  "marked": true}'</span>`</td></tr></tbody></table>

</div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Obtener Comentarios Post (1) - [obtain-comments2]

## 🧾 Descripción

*Obtiene los comentarios de una publicación específica del módulo **Publicaciones (Frappe/ERPNext)** junto con información adicional del empleado que realizó cada comentario.*  
*El servicio:*

1. *Consulta los comentarios del documento <span style="color: rgb(224, 62, 45);">**`Publicaciones/{post_name}`**</span>.*
2. *Obtiene la lista de empleados activos desde ERP para enlazar <span style="color: rgb(224, 62, 45);">**`owner → nombre_completo`**</span>.*
3. *Ordena todos los comentarios por fecha de creación en orden ascendente.*
4. *Devuelve la lista final enriquecida con el nombre completo del usuario comentador.*

---

# 🚀 Endpoint

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fobtain-comment"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /obtain-comments-by-post`**</span></div></div>*(La ruta final depende de la configuración en routes/api.php)*

---

# 🔐 Seguridad

- Requiere **cookie de sesión Frappe** válida (el usuario debe estar logueado).
- Sin cookie → fallo en la consulta al endpoint de ERP.

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22cookie%22%3A-%22string%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"post_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"start"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"limit"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">10</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1688" data-start="1204"><thead data-end="1255" data-start="1204"><tr data-end="1255" data-start="1204"><th data-col-size="sm" data-end="1218" data-start="1204">Campo</th><th data-col-size="sm" data-end="1228" data-start="1218">Tipo</th><th data-col-size="sm" data-end="1240" data-start="1228">Requerido</th><th data-col-size="md" data-end="1255" data-start="1240">Descripción</th></tr></thead><tbody data-end="1688" data-start="1308"><tr data-end="1418" data-start="1308"><td data-col-size="sm" data-end="1322" data-start="1308">cookie</td><td data-col-size="sm" data-end="1332" data-start="1322">string</td><td data-col-size="sm" data-end="1344" data-start="1332">Sí</td><td data-col-size="md" data-end="1418" data-start="1344">Cookie de sesión enviada por ERP para realizar consultas autenticadas.</td></tr><tr data-end="1519" data-start="1419"><td data-col-size="sm" data-end="1433" data-start="1419">post\_name</td><td data-col-size="sm" data-end="1443" data-start="1433">string</td><td data-col-size="sm" data-end="1455" data-start="1443">Sí</td><td data-col-size="md" data-end="1519" data-start="1455">Nombre (ID) de la publicación en ERP, ejemplo: `"PUB-0001"`.</td></tr><tr data-end="1606" data-start="1520"><td data-col-size="sm" data-end="1534" data-start="1520">start</td><td data-col-size="sm" data-end="1544" data-start="1534">number</td><td data-col-size="sm" data-end="1556" data-start="1544">No</td><td data-col-size="md" data-end="1606" data-start="1556">Índice inicial para paginación de comentarios.</td></tr><tr data-end="1688" data-start="1607"><td data-col-size="sm" data-end="1621" data-start="1607">limit</td><td data-col-size="sm" data-end="1631" data-start="1621">number</td><td data-col-size="sm" data-end="1643" data-start="1631">No</td><td data-col-size="md" data-end="1688" data-start="1643">Cantidad máxima de comentarios a obtener.</td></tr></tbody></table>

</div></div>---

# 📤 Responses

## ✔️ 200 – Comentarios obtenidos correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22data%22%3A-%5B-%7B-%22owner" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"owner"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"user@example.com"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"COM-0001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Buen trabajo equipo!"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-01 10:30:00"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 400/500 – Error en la solicitud a ERPNext

Si ocurre una excepción desde Guzzle (cookie inválida, publicación inexistente, etc.):

**Respuesta directa del error de ERPNext**, ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B%22exc%22%3A-%5B%22traceback." style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span><span class="hljs-attr">"exc"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"Traceback..."</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 Lógica Interna (Resumen Técnico)

1. **Validación de entradas**
    
    
    - Se extraen: <span style="color: rgb(224, 62, 45);">**`cookie`**</span>, <span style="color: rgb(224, 62, 45);">**`post_name`**</span>, <span style="color: rgb(224, 62, 45);">**`start`**</span>, <span style="color: rgb(224, 62, 45);">**`limit`**</span>.
2. **Consulta de comentarios**
    
    
    - **Endpoint Frappe llamado:** <span style="color: rgb(224, 62, 45);">**`GET APICAPACITACION/resource/Publicaciones/{post_name}`**</span>
    - **Envia parámetros:**
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-section">fields: []</span><span class="hljs-section">filters: []</span><span class="hljs-section">limit_start: start</span><span class="hljs-section">limit_page_length: limit</span>`</div></div>
3. **Consulta de empleados activos**
    
    
    - **Solicita:** <span style="color: rgb(224, 62, 45);">**`Employee?fields=[<span class="hljs-string">"name"</span>,<span class="hljs-string">"nombre_completo"</span>,<span class="hljs-string">"user_id"</span>]&filters=<span class="hljs-string">[["status","=","Active"]]</span>`**</span>
    - **Construye un mapa:** <span style="color: rgb(224, 62, 45);">**`<span class="hljs-attribute">user_id</span> → nombre_completo`**</span>
4. **Enriquecimiento de comentarios**
    
    
    - **A cada comentario se le agrega:** <span style="color: rgb(224, 62, 45);">**`<span class="hljs-attr">nombre_completo</span> = jsonEmployee[owner] ?? owner`**</span>
5. **Ordenamiento**
    
    
    - Orden ascendente por la fecha <span style="color: rgb(224, 62, 45);">**`creation`**</span>.
6. **Resultado final**

<table border="1" id="bkmrk-%7B-%22data%22%3A-%5B-...comen" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{ <span class="hljs-string">"data"</span>: [ ...comentarios_ordenados... ] }`</td></tr></tbody></table>

---

# 📚 Schema de respuesta final

### Comentario:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22owner%22%3A-%22string%22%2C" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"owner"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 Ejemplo de uso (curl)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/obtain-comments-by-post \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{  "cookie":"sid=abc123",  "post_name":"PUB-0005",  "start":0,  "limit":20}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Enviar Comentarios Post (1) - [sendComment]

## 🧾 **Descripción**

*Registra un nuevo comentario dentro de una publicación del módulo de “Publicaciones” en ERP/Capacitación.*

*El servicio envía la información del comentario a un endpoint del ERP mediante autenticación por cookie.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fsend-comment"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /send-comment`**</span></div></div>> La ruta real depende del archivo de rutas Laravel (<span style="color: rgb(224, 62, 45);">**`api.php`**</span>).

---

# 🔐 **Seguridad**

- Requiere **cookie de sesión ERP** enviada por el cliente.
- La cookie se usa directamente en la cabecera:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-cookie%3A-session_id%3D."><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-section">Cookie: session_id=...</span>`**</span></div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22content%22%3A-%22string" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### **Descripción de campos**

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1192" data-start="864"><thead data-end="912" data-start="864"><tr data-end="912" data-start="864"><th data-col-size="sm" data-end="876" data-start="864">Campo</th><th data-col-size="sm" data-end="885" data-start="876">Tipo</th><th data-col-size="sm" data-end="897" data-start="885">Requerido</th><th data-col-size="md" data-end="912" data-start="897">Descripción</th></tr></thead><tbody data-end="1192" data-start="962"><tr data-end="1020" data-start="962"><td data-col-size="sm" data-end="974" data-start="962">content</td><td data-col-size="sm" data-end="983" data-start="974">string</td><td data-col-size="sm" data-end="995" data-start="983">Sí</td><td data-col-size="md" data-end="1020" data-start="995">Texto del comentario.</td></tr><tr data-end="1122" data-start="1021"><td data-col-size="sm" data-end="1033" data-start="1021">parent</td><td data-col-size="sm" data-end="1042" data-start="1033">string</td><td data-col-size="sm" data-end="1054" data-start="1042">Sí</td><td data-col-size="md" data-end="1122" data-start="1054">ID del documento `Publicaciones` al que pertenece el comentario.</td></tr><tr data-end="1192" data-start="1123"><td data-col-size="sm" data-end="1135" data-start="1123">cookie</td><td data-col-size="sm" data-end="1144" data-start="1135">string</td><td data-col-size="sm" data-end="1156" data-start="1144">Sí</td><td data-col-size="md" data-end="1192" data-start="1156">Cookie de sesión válida del ERP.</td></tr></tbody></table>

</div></div>**Otros campos se envían de forma fija al backend:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22parenttype%22%3A-%22pub" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"parenttype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Publicaciones"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parentfield"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"comments"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 📤 **Responses**

## ✔️ **200 – Comentario creado correctamente**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Creado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **400 – Error en datos del cliente**

El servicio no valida explícitamente los campos, pero si backend rechaza:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22false%22%2C-" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"false"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Detalle del error del ERP"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **500 – Error al procesar la solicitud**

Cuando la API del ERP responde con error:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22false%22%2C--1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"false"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje de error>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica interna del servicio**

1. Crea un cliente <span style="color: rgb(224, 62, 45);">**`ApiRest`** </span>con manejo de cookies.
2. Construye los datos del comentario:
    
    
    - `content`
    - `parent` (publicación)
    - `parenttype = Publicaciones`
    - `parentfield = comments`
3. Envía un <span style="color: rgb(224, 62, 45);">**`POST`** </span>al endpoint del ERP:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span style="color: rgb(224, 62, 45);"><strong>{APICAPACITACION}/resource/postComend2</strong></span>`</div></div>
4. Maneja error HTTP (BadResponseException).
5. Si la respuesta contiene `data`, devuelve éxito.
6. Si no, marca error de creación.

---

# 🗃 **Schemas**

### Request Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--13"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22content%22%3A-%22string-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%7C" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean|string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"object"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/send-comment \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{  "content":"Excelente publicación",  "parent":"PUB-00045",  "cookie":"sid=cd2312fa..."}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Modulo Información Personal

# Obtener Usuario (2) - [get-user3]

## 🧾 Descripción

*Obtiene la información completa de un usuario del sistema, ya sea **Empleado** o **Estudiante**, de acuerdo al identificador enviado (email o DNI/pasaporte).*  
*Retorna datos personales, laborales, de contrato y estado del usuario.*  
*Si es empleado, consulta tablas de Employee —si no existe— consulta Student.*

---

# 🚀 Endpoint

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fget-user3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /get-user3`**</span></div></div>> La ruta final depende de tus archivos <span style="color: rgb(224, 62, 45);">**`api.php`**</span>.

---

# 🔐 Seguridad

- No valida token aquí, pero depende del mecanismo usado dentro de <span style="color: rgb(224, 62, 45);">**`general->dbErp`**</span> y <span style="color: rgb(224, 62, 45);">**`general->ServiceErp`**</span>.
- Debe ser usado desde una app autenticada.

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22username%22%3A-%22strin" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1062" data-start="877"><thead data-end="925" data-start="877"><tr data-end="925" data-start="877"><th data-col-size="sm" data-end="889" data-start="877">Campo</th><th data-col-size="sm" data-end="898" data-start="889">Tipo</th><th data-col-size="sm" data-end="910" data-start="898">Requerido</th><th data-col-size="md" data-end="925" data-start="910">Descripción</th></tr></thead><tbody data-end="1062" data-start="975"><tr data-end="1062" data-start="975"><td data-col-size="sm" data-end="987" data-start="975">username</td><td data-col-size="sm" data-end="996" data-start="987">string</td><td data-col-size="sm" data-end="1008" data-start="996">Sí</td><td data-col-size="md" data-end="1062" data-start="1008">Email del usuario o número de documento/pasaporte.</td></tr></tbody></table>

</div></div>---

# 📤 Respuestas

## ✔️ 200 – Usuario encontrado (Empleado)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Si hay data"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP000123"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"employee_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"tipo_usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Active"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"vigencia_contrato"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-01-01 hasta 2024-12-31"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"contratacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"primer_contrato"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"pets"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha_de_nacimiento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"05-12"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"..."</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"otros_campos"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ✔️ 200 – Usuario encontrado (Estudiante)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Si hay data"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"STU00234"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"employee_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Estudiante Ejemplo"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"tipo_usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Estudiante"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"statusUser"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha_de_nacimiento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"..."</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"otros_campos"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❌ Usuario no encontrado en Employee ni Student

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sin Estudiante: Su usuario no tiene permisos para acceder al aplicativo. Contactar con soporte."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ Empleado inactivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--9"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado Inactivo: Comuníquese con su administrador para que pueda verificar el estado de su empleado."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span> ... <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ Usuario estudiante deshabilitado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--11"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario Deshabilitado: Comuníquese con su administrador para que pueda verificar el estado de su empleado."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span> ... <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 Lógica del Servicio

### 1️⃣ Determinar tipo de búsqueda

Si el username contiene **@**, se busca por: <span style="color: rgb(224, 62, 45);">**`<span class="hljs-attr">Employee.user_id</span> = username`**</span>

Si no: <span style="color: rgb(224, 62, 45);">**`<span class="hljs-attr">Employee.passport_number</span> = username`**</span>

---

### 2️⃣ Consulta principal (Employee)

Usa <span style="color: rgb(224, 62, 45);">**`dbErp`** </span>con una consulta SQL dinámica unida a:

- tabEmployee
- tabUser
- tabBranch
- tabContrato de Trabajo
- tabDepartment

Si **no hay resultados** → se intenta en Student.

---

### 3️⃣ Consulta secundaria (Student)

**Busca en:**

- tabStudent
- tabUser
- tabBranch
- tabJob Applicant
- tabRequerimiento de Personal
- tabDesignation
- tabDepartment

Si no existe → usuario sin permisos.

---

### 4️⃣ Validaciones adicionales

- Employee con status <span style="color: rgb(224, 62, 45);">**`"Inactive"`**</span> → error.
- Student con <span style="color: rgb(224, 62, 45);">**`enabled = 0`**</span> → error.
- Formatear <span style="color: rgb(224, 62, 45);">**`fecha_de_nacimiento`**</span> → <span style="color: rgb(224, 62, 45);">**`"m-d"`**</span>.

---

### 5️⃣ Validación de contratos

**Se consulta:** `resource/Contrato de Trabajo`

**Se determina:**

- `"primer_contrato"` o
- `"renovacion"`

---

### 6️⃣ Ajuste final de campos

- pets → transformado a “0” si viene null.
- Se asignan alias y campos calculados.

---

# 📚 Response Schema

### Para Empleado

**Incluye (parcial):**

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-descripci%C3%B3n-na"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3972" data-start="3634"><thead data-end="3657" data-start="3634"><tr data-end="3657" data-start="3634"><th data-col-size="sm" data-end="3642" data-start="3634">Campo</th><th data-col-size="sm" data-end="3657" data-start="3642">Descripción</th></tr></thead><tbody data-end="3972" data-start="3682"><tr data-end="3708" data-start="3682"><td data-col-size="sm" data-end="3689" data-start="3682">name</td><td data-col-size="sm" data-end="3708" data-start="3689">ID del Employee</td></tr><tr data-end="3744" data-start="3709"><td data-col-size="sm" data-end="3725" data-start="3709">employee\_name</td><td data-col-size="sm" data-end="3744" data-start="3725">Nombre completo</td></tr><tr data-end="3774" data-start="3745"><td data-col-size="sm" data-end="3760" data-start="3745">tipo\_usuario</td><td data-col-size="sm" data-end="3774" data-start="3760">"Empleado"</td></tr><tr data-end="3815" data-start="3775"><td data-col-size="sm" data-end="3784" data-start="3775">status</td><td data-col-size="sm" data-end="3815" data-start="3784">Active, PreActivo, Inactive</td></tr><tr data-end="3855" data-start="3816"><td data-col-size="sm" data-end="3836" data-start="3816">vigencia\_contrato</td><td data-col-size="sm" data-end="3855" data-start="3836">Rango de fechas</td></tr><tr data-end="3903" data-start="3856"><td data-col-size="sm" data-end="3871" data-start="3856">contratacion</td><td data-col-size="sm" data-end="3903" data-start="3871">primer\_contrato / renovacion</td></tr><tr data-end="3940" data-start="3904"><td data-col-size="sm" data-end="3911" data-start="3904">pets</td><td data-col-size="sm" data-end="3940" data-start="3911">Valor convertido a string</td></tr><tr data-end="3972" data-start="3941"><td data-col-size="sm" data-end="3963" data-start="3941">fecha\_de\_nacimiento</td><td data-col-size="sm" data-end="3972" data-start="3963">mm-dd</td></tr></tbody></table>

</div></div>Más de 40 campos adicionales según tu SQL.

---

### Para Estudiante

**Incluye:**

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-descripci%C3%B3n-na-1"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="4277" data-start="4053"><thead data-end="4076" data-start="4053"><tr data-end="4076" data-start="4053"><th data-col-size="sm" data-end="4061" data-start="4053">Campo</th><th data-col-size="sm" data-end="4076" data-start="4061">Descripción</th></tr></thead><tbody data-end="4277" data-start="4101"><tr data-end="4126" data-start="4101"><td data-col-size="sm" data-end="4108" data-start="4101">name</td><td data-col-size="sm" data-end="4126" data-start="4108">ID del Student</td></tr><tr data-end="4162" data-start="4127"><td data-col-size="sm" data-end="4143" data-start="4127">employee\_name</td><td data-col-size="sm" data-end="4162" data-start="4143">Nombre completo</td></tr><tr data-end="4192" data-start="4163"><td data-col-size="sm" data-end="4178" data-start="4163">tipo\_usuario</td><td data-col-size="sm" data-end="4192" data-start="4178">Estudiante</td></tr><tr data-end="4215" data-start="4193"><td data-col-size="sm" data-end="4206" data-start="4193">statusUser</td><td data-col-size="sm" data-end="4215" data-start="4206">1 ó 0</td></tr><tr data-end="4237" data-start="4216"><td data-col-size="sm" data-end="4229" data-start="4216">user\_image</td><td data-col-size="sm" data-end="4237" data-start="4229">Foto</td></tr><tr data-end="4257" data-start="4238"><td data-col-size="sm" data-end="4247" data-start="4238">gender</td><td data-col-size="sm" data-end="4257" data-start="4247">Género</td></tr><tr data-end="4277" data-start="4258"><td data-col-size="sm" data-end="4264" data-start="4258">dni</td><td data-col-size="sm" data-end="4277" data-start="4264">Documento</td></tr></tbody></table>

</div></div>---

# 🧪 Ejemplo curl

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/get-user3 \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{"username": "juan.perez@empresa.com"}'</span>`</td></tr></tbody></table>

</div></div>

# Actualizar Datos del Usuario (1) - [update-perfil-info]

## 🧾 **Descripción**

*Actualiza la información de perfil del empleado dentro del ERP (doctype **Employee**) mediante una petición **PUT**, modificando uno o varios de los siguientes datos:*

- Número de celular (<span style="color: rgb(224, 62, 45);">**`cell_number`**</span>)
- Correo personal (<span style="color: rgb(224, 62, 45);">**`personal_email`**</span>)
- Dirección permanente (<span style="color: rgb(224, 62, 45);">**`permanent_address`**</span>)

*Solo actualiza los campos enviados; los no enviados no se modifican.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-put-%2Fupdate-date-per"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**<span style="color: rgb(224, 62, 45);">`PUT <span class="hljs-operator">/</span><span class="hljs-keyword">update</span><span class="hljs-operator">-</span><span class="hljs-type">date</span><span class="hljs-operator">-</span>perfil`</span>**</div></div>> La ruta real depende del archivo <span style="color: rgb(224, 62, 45);">**`routes/api.php`**</span>.

---

# 🔐 **Seguridad**

- Requiere que la app ya tenga autenticación o sesión aplicada.
- Internamente el servicio usa <span style="color: rgb(224, 62, 45);">**`ServiceErp`** </span>(ERPNext API con permiso necesario).

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22employe%22%3A-%22hr-emp" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employe"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"HR-EMP-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"celular"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"987654321"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"correo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"example@correo.com"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"direccion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Av. Los Olivos 123"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1455" data-start="1039"><thead data-end="1088" data-start="1039"><tr data-end="1088" data-start="1039"><th data-col-size="sm" data-end="1052" data-start="1039">Campo</th><th data-col-size="sm" data-end="1061" data-start="1052">Tipo</th><th data-col-size="sm" data-end="1073" data-start="1061">Requerido</th><th data-col-size="md" data-end="1088" data-start="1073">Descripción</th></tr></thead><tbody data-end="1455" data-start="1139"><tr data-end="1222" data-start="1139"><td data-col-size="sm" data-end="1152" data-start="1139">employe</td><td data-col-size="sm" data-end="1161" data-start="1152">string</td><td data-col-size="sm" data-end="1173" data-start="1161">✔️ Sí</td><td data-col-size="md" data-end="1222" data-start="1173">ID del empleado en ERPNext (`Employee.name`).</td></tr><tr data-end="1285" data-start="1223"><td data-col-size="sm" data-end="1236" data-start="1223">celular</td><td data-col-size="sm" data-end="1245" data-start="1236">string</td><td data-col-size="sm" data-end="1257" data-start="1245">No</td><td data-col-size="md" data-end="1285" data-start="1257">Nuevo número de celular.</td></tr><tr data-end="1376" data-start="1286"><td data-col-size="sm" data-end="1299" data-start="1286">correo</td><td data-col-size="sm" data-end="1308" data-start="1299">string</td><td data-col-size="sm" data-end="1320" data-start="1308">No</td><td data-col-size="md" data-end="1376" data-start="1320">Nuevo correo personal. (Actualiza `personal_email`).</td></tr><tr data-end="1455" data-start="1377"><td data-col-size="sm" data-end="1390" data-start="1377">direccion</td><td data-col-size="sm" data-end="1399" data-start="1390">string</td><td data-col-size="sm" data-end="1411" data-start="1399">No</td><td data-col-size="md" data-end="1455" data-start="1411">Nueva dirección permanente del empleado.</td></tr></tbody></table>

</div></div>---

# 🧩 **Validaciones**

1. **employe vacío** → se devuelve error mediante `responseValidate()`.
2. Los demás campos son opcionales.
3. Solo se actualizan los campos enviados.

---

# 📤 **Responses**

## ✔️ 200 – Actualización exitosa

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22value%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Actualizacion Exitosa"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    ...respuesta del ERPNext...  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>> Nota: El valor <span style="color: rgb(224, 62, 45);">**`"value": false`**</span> parece un bug en tu código, ya que indica éxito pero devuelve <span style="color: rgb(224, 62, 45);">**`false`**</span>.  
> Te lo dejo documentado según tu implementación real.

---

## ❌ 400 – Faltan parámetros requeridos

Ejemplo cuando no se envía <span style="color: rgb(224, 62, 45);">**`employe`**</span>:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe enviar el empleado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

*(Respuesta generada por <span style="color: rgb(224, 62, 45);">**`responseValidate()`**</span>)*

---

# 🧠 **Lógica Interna (Resumen)**

1. Recibe parámetros del request.
2. Si <span style="color: rgb(224, 62, 45);">**`employe`** </span>está vacío → error.
3. Crea un arreglo `updateKeys` solo con los campos enviados.
4. Llama a:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-put-%2Fapi%2Fresource%2Fem"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-type">PUT</span> <span class="hljs-regexp">/api/</span>resource<span class="hljs-regexp">/Employee/</span>{employe}`**</span></div></div>Con el body:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cell_number%22%3A-%22.."><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cell_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"personal_email"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"permanent_address"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>5. Devuelve la respuesta del ERP.

---

# 📚 **Schemas**

### Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22employe%22%3A-%22string" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employe"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"celular"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"correo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"direccion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22value%22%3A-%22boolean%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"object (respuesta del ERP)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🧪 **Ejemplo de Uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-put-https%3A%2F%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X PUT https://midominio.com/api/update-date-perfil \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{  "employe": "EMP-0005",  "celular": "987654321",  "correo": "nuevo@correo.com",  "direccion": "Calle 123"}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Actualizar Imagen de Perfil del Usuario (1) - [update-img-user]

## 🧾 Descripción

*Actualiza la imagen de perfil de un usuario en ERPNext.*  
*El proceso incluye:*

1. Recepción de un archivo enviado desde la app.
2. Subida del archivo al endpoint de ERPNext: <span style="color: rgb(224, 62, 45);">**`method/upload_file`**</span>.
3. Obtención de la URL generada del archivo.
4. Actualización del campo <span style="color: rgb(224, 62, 45);">**`user_image`** </span>del **User**.
5. Actualización del campo <span style="color: rgb(224, 62, 45);">**`image`** </span>en el **Employee** asociado (si existe).

---

# 🚀 Endpoint

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fupdate-img-use"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST <span class="hljs-operator">/</span><span class="hljs-keyword">update</span><span class="hljs-operator">-</span>img<span class="hljs-operator">-</span><span class="hljs-keyword">user</span>`**</span></div></div>> La ruta exacta dependerá del archivo de rutas Laravel (<span style="color: rgb(224, 62, 45);">**`api.php`**</span>).

---

# 🔐 Seguridad

- La función no valida sesión o token, pero el endpoint llamado en ERPNext usa **cookies de sesión Guest**, lo que indica que debe usarse desde un backend confiable.
- Se recomienda protegerla en la API propia.

---

# 📥 Request (Multipart / Form-Data)

### Campos requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1230" data-start="987"><thead data-end="1030" data-start="987"><tr data-end="1030" data-start="987"><th data-col-size="sm" data-end="996" data-start="987">Campo</th><th data-col-size="sm" data-end="1003" data-start="996">Tipo</th><th data-col-size="sm" data-end="1015" data-start="1003">Requerido</th><th data-col-size="md" data-end="1030" data-start="1015">Descripción</th></tr></thead><tbody data-end="1230" data-start="1075"><tr data-end="1138" data-start="1075"><td data-col-size="sm" data-end="1084" data-start="1075">file</td><td data-col-size="sm" data-end="1091" data-start="1084">file</td><td data-col-size="sm" data-end="1103" data-start="1091">Sí</td><td data-col-size="md" data-end="1138" data-start="1103">Imagen a subir (jpg, png, etc.)</td></tr><tr data-end="1230" data-start="1139"><td data-col-size="sm" data-end="1148" data-start="1139">user</td><td data-col-size="sm" data-end="1157" data-start="1148">string</td><td data-col-size="sm" data-end="1166" data-start="1157">Sí</td><td data-col-size="md" data-end="1230" data-start="1166">Nombre del usuario en ERPNext para actualizar (`User.name`).</td></tr></tbody></table>

</div></div>### Ejemplo (form-data)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">``</div></div><table border="1" id="bkmrk-file%3A-avatar.png-use" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`file: avatar.png<span class="hljs-keyword">user</span>: <span class="hljs-keyword">user</span><span class="hljs-variable">@example</span>.com`</td></tr></tbody></table>

---

# 📤 Responses

## ✔️ 200 – Imagen actualizada correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Imagen de usuario actualizado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 400 – Faltan datos o error al subir archivo

Ejemplo de error al no recibir archivo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22msn%22%3A-%22file-could" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"File could not be processed"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ 500 – Error de carga o actualización

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--9"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al actualizar la imagen de usuario"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 Lógica Interna

### 1. **Lectura del archivo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24cfile-%3D-new-%5Ccurlfi"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable">$cfile</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">\CURLFile</span>(<span class="hljs-variable">$_FILES</span>[<span class="hljs-string">"file"</span>][<span class="hljs-string">'tmp_name'</span>], <span class="hljs-variable">$_FILES</span>[<span class="hljs-string">"file"</span>][<span class="hljs-string">'type'</span>], <span class="hljs-variable">$_FILES</span>[<span class="hljs-string">"file"</span>][<span class="hljs-string">'name'</span>]);`</td></tr></tbody></table>

</div></div>### 2. **Subida a ERPNext**

- Endpoint usado: `POST /method/upload_file`

- Cabecera usada: `<span class="hljs-section">Cookie: full_name=Guest; sid=Guest; system_user=no; user_id=Guest; user_image=</span>`

> ⚠️ Se sube el archivo como usuario Guest.

### 3. **Validación de respuesta**

Debe existir: `message.file_url`

Si no existe → error.

### 4. **Actualizar información del User**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--11"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-put-resource%2Fuser%2F%7Bu" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`PUT resource/<span class="hljs-keyword">User</span>/{<span class="hljs-keyword">user</span>}{  "user_image": "<file_url>"}`</td></tr></tbody></table>

### 5. **Actualizar Employee si corresponde**

- Busca Employee cuyo <span style="color: rgb(224, 62, 45);">**`user_id`** </span>coincida:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-user_id%2C-name"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> user_id, name <span class="hljs-keyword">FROM</span> tabEmployee <span class="hljs-keyword">WHERE</span> user_id <span class="hljs-operator">=</span> {<span class="hljs-keyword">user</span>}`</div></div>Si existe:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-put-resource%2Femploye"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-type">PUT</span> resource<span class="hljs-regexp">/Employee/</span>{employee_id}{  <span class="hljs-string">"image"</span>: <span class="hljs-string">"<file_url>"</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Request/Response Schemas

### Request (multipart/form-data)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--13"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-file%3A-file-user%3A-str" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-symbol">file:</span> File<span class="hljs-symbol">user:</span> <span class="hljs-type">string</span>`</td></tr></tbody></table>

### Response (success)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Imagen de usuario actualizado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> <span class="hljs-attr">"user_image"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 Ejemplo de uso (curl)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/update-img-user \  -F <span class="hljs-string">"file=@/home/user/avatar.png"</span> \  -F <span class="hljs-string">"user=user@example.com"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Modulo de Asistencia y Marcaciones (Marcaciones)

# Obtiene descarga boleta de pago (1,2,3,4,5,6,7,8) - [getDownloadBoletaPago]

## 🧾 **Descripción General**

*Este servicio valida si un empleado debe descargar su boleta de pago (Salary Slip) correspondiente al mes anterior.*  
*La validación depende:*

- Del **día del mes actual**
- Del **estado del empleado**
- De si existe o no una boleta generada
- De si dicha boleta está habilitada
- De si ya registró una descarga previa

*La lógica se usa para **bloquear marcaciones o solicitudes** cuando un trabajador tiene una boleta pendiente por descargar.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fget-download-bo"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-keyword">GET</span> /<span class="hljs-keyword">get</span>-download-boleta-pago/{empleado}`**</span></div></div>**Parámetro Path:**

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-reque"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1013" data-start="833"><thead data-end="881" data-start="833"><tr data-end="881" data-start="833"><th data-col-size="sm" data-end="845" data-start="833">Parámetro</th><th data-col-size="sm" data-end="854" data-start="845">Tipo</th><th data-col-size="sm" data-end="866" data-start="854">Requerido</th><th data-col-size="md" data-end="881" data-start="866">Descripción</th></tr></thead><tbody data-end="1013" data-start="930"><tr data-end="1013" data-start="930"><td data-col-size="sm" data-end="941" data-start="930">empleado</td><td data-col-size="sm" data-end="950" data-start="941">string</td><td data-col-size="sm" data-end="962" data-start="950">Sí</td><td data-col-size="md" data-end="1013" data-start="962">Código del empleado (Employee.name en ERPNext).</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

No usa autenticación dentro de esta función, pero depende de endpoints internos ERPNext vía <span style="color: rgb(224, 62, 45);">**`dbErp`**</span>.  
Se recomienda incluirlo dentro de rutas protegidas.

---

# 🧠 **Flujo Lógico (Resumen Ejecutivo)**

1. **Validación de fechas**
    
    
    - Si el día actual es mayor a **3**, no se hace validación → se retorna éxito.
2. **Consultar datos del empleado**
    
    
    - Obtiene desde ERP:
        
        
        - <span style="color: rgb(224, 62, 45);">**`fecha_de_ingreso_real`**</span>
        - <span style="color: rgb(224, 62, 45);">**`status`**</span>
3. **Casos especiales por estado**
    
    
    - Si el empleado está en **PreActivo**, no se valida.
4. **Determinar si corresponde validar**
    
    
    - Calcula el **último día del mes anterior**.
    - Si el ingreso del trabajador es posterior a ese mes → no se valida.
5. **Validar si existe boleta generada**
    
    
    - Consulta Salary Slip del mes anterior.
    - Si no existe boleta → no corresponde validar.
6. **Validar si la boleta mensual está habilitada (Estado Boleta Mensual)**
    
    
    - Revisa si está habilitada para ese mes.
7. **Verificar si ya descargó boleta**
    
    
    - Revisa tabla <span style="color: rgb(224, 62, 45);">**`historial_procesos_app`** </span>en MySQL.
    - Si no descargó → retorna mensaje de pendiente.
8. **Caso final**
    
    
    - Si todo está correcto → retorna éxito.

---

# 📥 **Request**

Sin body.  
Solo recibe el parámetro <span style="color: rgb(224, 62, 45);">**`{empleado}`**</span> en la URL.

---

# 📤 **Responses**

### ✔️ 200 – No corresponde validación (día mayor a 3)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No está dentro del rango de fecha de validación"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – Empleado en PreActivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No validar descarga de boleta en PreActivo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – No corresponde validación (ingresó después)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--9"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No tiene boleta de pago por lo tanto no se valida"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ❌ 200 – Boleta pendiente por descargar (validación negativa)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--11"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-false%2C-%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su boleta pendiente del mes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – Boleta descargada previamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--13"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado la boleta de pago"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – Error capturado (retorna como éxito)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>> *Este mensaje parece incorrecto para el contexto (habla de contrato en vez de boleta), pero se documenta tal como el código lo retorna.*

---

# 📚 **Lógica de Consultas Usadas**

## 1. Obtener datos del empleado

Consulta a ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-fecha_de_ingr"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> fecha_de_ingreso_real, status<span class="hljs-keyword">FROM</span> `tabEmployee`<span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span> = %(<span class="hljs-type">name</span>)s`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>## 2. Validar Salary Slip del mes anterior

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-posting_date-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable constant_">SELECT</span> posting_date<span class="hljs-variable constant_">FROM</span> <span class="hljs-string">`tabSalary Slip`</span><span class="hljs-variable constant_">WHERE</span> employee = <span class="hljs-string">%(employee)</span>s  <span class="hljs-variable constant_">AND</span> posting_date <span class="hljs-variable constant_">BETWEEN</span> <span class="hljs-string">%(fecha_inicio)</span>s <span class="hljs-variable constant_">AND</span> <span class="hljs-string">%(fecha_fin)</span>s`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>## 3. Validar estado de boleta (habilitado)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-name-from-%60ta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> <span class="hljs-type">name</span><span class="hljs-keyword">FROM</span> `tabEstado Boleta Mensual`<span class="hljs-keyword">WHERE</span> mes = %(mes)s <span class="hljs-keyword">AND</span> año = %(año)s <span class="hljs-keyword">AND</span> habilitado = <span class="hljs-number">1</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>## 4. Validar si el empleado ya descargó su boleta

Tabla: **historial\_procesos\_app (mysql2)**  
Filtro:

- proceso = NOMINA
- employee
- month
- year

---

# 🧩 **Posibles Errores de Diseño (para tu control interno)**

- El `catch` retorna mensaje incorrecto: *“Se ha descargado el contrato de trabajo”*.
- En validación final siempre retorna “status: true” aunque haya fallas.
- Se usa `POST` en algunas consultas SQL cuando debería ser `GET`.

(Solo informativo; no se incluye en documentación oficial si no lo deseas.)

# Obtiene descarga Renovación de contrato (1,2,3,4,5,6,7,8) - [getRenovacionContrato]

## 🧾 **Descripción**

*Valida si un trabajador tiene pendiente la descarga de su **renovación de contrato**, lo cual puede bloquear el registro de marcaciones o solicitudes dentro del aplicativo.*  
*El servicio evalúa fechas, estado del trabajador y el registro interno en base MySQL donde se guarda el historial de descargas realizadas.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fget-renovacion-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-keyword">GET</span> /<span class="hljs-keyword">get</span>-renovacion-contrato/{empleado}`**</span></div></div>> <span style="color: rgb(224, 62, 45);">**`{empleado}`**</span> corresponde al código del empleado (Employee.name en ERPNext).

---

# 🔐 **Seguridad**

- Requiere que el cliente esté autenticado (según arquitectura de la app).
- Accede a ERP (Frappe) mediante un servicio interno (<span style="color: rgb(224, 62, 45);">**`dbErp`**</span>).

---

# 📥 **Parámetros**

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-reque"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1058" data-start="899"><thead data-end="945" data-start="899"><tr data-end="945" data-start="899"><th data-col-size="sm" data-end="911" data-start="899">Parámetro</th><th data-col-size="sm" data-end="918" data-start="911">Tipo</th><th data-col-size="sm" data-end="930" data-start="918">Requerido</th><th data-col-size="sm" data-end="945" data-start="930">Descripción</th></tr></thead><tbody data-end="1058" data-start="992"><tr data-end="1058" data-start="992"><td data-col-size="sm" data-end="1003" data-start="992">empleado</td><td data-col-size="sm" data-end="1012" data-start="1003">string</td><td data-col-size="sm" data-end="1017" data-start="1012">Sí</td><td data-col-size="sm" data-end="1058" data-start="1017">Código único del empleado en ERPNext.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

### ✔️ 200 – No corresponde validar renovación (fuera de fecha)

El proceso solo se ejecuta si **día &gt;= 26**.  
Si es antes, devuelve:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No es el día correcto para la renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – Validación NO necesaria (no aplica por antigüedad)

Si el empleado ingresó después del mes previo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ❌ 200 – Debe descargar el contrato de renovación (pendiente)

El empleado tiene renovación generada y habilitada, pero **no tiene registro de descarga**:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-false%2C-%22" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – Renovación ya descargada

La base MySQL registra descarga previa:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

### ✔️ 200 – Error controlado

Ante cualquier excepción:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--12"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-3" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Flujo del Servicio**

1. Verifica el **día actual**
    
    
    - Si día &lt; 26 → no corresponde validar
2. Obtiene datos del empleado desde ERP (`fecha_de_ingreso_real`)
3. Calcula:
    
    
    - Último día del mes anterior
    - Mes actual (texto)
4. Si el ingreso del empleado es **anterior al último día del mes previo**, aplica validación.
5. Consulta en ERP:
    
    
    - Solicitudes de renovación para este empleado
    - Con criterios:
        
        
        - Mes
        - Año
        - Código del empleado
        - `renueva = "Si"`
        - documento validado
6. Si tiene renovación pendiente:
    
    
    - Consulta base MySQL2 → tabla `historial_procesos_app`
    - Busca registro del proceso `descargaContratoRenovacion`
    - Si no existe → debe descargar renovación
7. Si ya está registrado → permitir normal funcionamiento.

---

# 📚 **Consultas utilizadas**

### A. Obtener datos del empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--15"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2">  
</div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><table border="1" id="bkmrk-select-fecha_de_ingr" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> fecha_de_ingreso_real<span class="hljs-keyword">FROM</span> `tabEmployee`<span class="hljs-keyword">WHERE</span> name <span class="hljs-operator">=</span> {empleado}`</td></tr></tbody></table>

### B. Consulta de renovaciones

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-doc.name-from"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> doc.name<span class="hljs-keyword">FROM</span> `tabSolicitud de Renovaciones` doc<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> `tabTrabajadores pendiete de renovar` tab <span class="hljs-keyword">ON</span> doc.name <span class="hljs-operator">=</span> tab.parent<span class="hljs-keyword">WHERE</span> doc.data_12 <span class="hljs-operator">=</span> {mes}  <span class="hljs-keyword">AND</span> doc.año <span class="hljs-operator">=</span> {<span class="hljs-keyword">year</span>}  <span class="hljs-keyword">AND</span> tab.codigo <span class="hljs-operator">=</span> {empleado}  <span class="hljs-keyword">AND</span> tab.renueva <span class="hljs-operator">=</span> <span class="hljs-string">'Si'</span>  <span class="hljs-keyword">AND</span> doc.estado_de_documento <span class="hljs-operator">=</span> <span class="hljs-string">'Validado'</span>`</td></tr></tbody></table>

</div></div></div></div>
### C. Validación de descarga

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-%2A-from-histor"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span><span class="hljs-keyword">FROM</span> historial_procesos_app<span class="hljs-keyword">WHERE</span> empleado <span class="hljs-operator">=</span> {empleado}  <span class="hljs-keyword">AND</span> proceso <span class="hljs-keyword">IN</span> (<span class="hljs-string">'descargaContratoRenovacion'</span>)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🧪 **Ejemplo de consumo (HTTP)**

### Request:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fget-renovacion--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-keyword">GET</span> <span class="hljs-operator">/</span><span class="hljs-keyword">get</span><span class="hljs-operator">-</span>renovacion<span class="hljs-operator">-</span>contrato<span class="hljs-operator">/</span>EMP<span class="hljs-number">-00045</span>`**</span></div></div>### Response (pendiente):

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Consulta si existe documento del puesto (1, 2,3) - [getDocumentPuesto]

## 🧾 **Descripción**

*Permite obtener el documento **MOF (Manual de Organización y Funciones)** asociado a un puesto específico registrado en el ERP, consultando el Doctype **Designation**.*

*Este servicio se utiliza para mostrar o validar documentación laboral relacionada al cargo del trabajador.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fget-document-pu"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-keyword">GET</span> /<span class="hljs-keyword">get</span>-document-puesto/{puesto}`**</span></div></div>> También puede enviarse como parámetro directo según cómo se defina en routes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fgetdocumentpues"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**<span style="color: rgb(224, 62, 45);">`GET /getDocumentPuesto?puesto=OPERADOR`</span>**</div></div>---

# 🔐 **Seguridad**

- El endpoint no exige autenticación explícita en el código.
- Se recomienda protegerlo mediante API Token o Middleware según la arquitectura.

---

# 📥 **Parámetros de Entrada**

### **Query / Path Parameter**

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-reque"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1129" data-start="947"><thead data-end="995" data-start="947"><tr data-end="995" data-start="947"><th data-col-size="sm" data-end="959" data-start="947">Parámetro</th><th data-col-size="sm" data-end="968" data-start="959">Tipo</th><th data-col-size="sm" data-end="980" data-start="968">Requerido</th><th data-col-size="md" data-end="995" data-start="980">Descripción</th></tr></thead><tbody data-end="1129" data-start="1044"><tr data-end="1129" data-start="1044"><td data-col-size="sm" data-end="1055" data-start="1044">puesto</td><td data-col-size="sm" data-end="1064" data-start="1055">string</td><td data-col-size="sm" data-end="1076" data-start="1064">Sí</td><td data-col-size="md" data-end="1129" data-start="1076">Nombre del Designation cuyo MOF se desea obtener.</td></tr></tbody></table>

</div></div>---

# 📤 **Responses**

## ✔️ **200 – Documento encontrado**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Documento encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<url_o_contenido_del_mof>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>- <span style="color: rgb(224, 62, 45);">**`data`** </span>contiene el valor del campo <span style="color: rgb(224, 62, 45);">**`mof`** </span>del Doctype **Designation**.

---

## ❌ **404 – Documento no encontrado**

Se devuelve cuando el puesto no existe o no tiene MOF asociado.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Documento no encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🧠 **Lógica Interna (Resumen)**

1. Verifica que se haya enviado un nombre de puesto.
2. Construye una consulta GET hacia: **`resource/Designation`**
    
    Con:
    
    
    - `filters`: `[["name","=", puesto]]`
    - `fields`: `["mof"]`
3. Envía la solicitud mediante: `ServiceErp(<span class="hljs-string">"GET"</span>, <span class="hljs-literal">null</span>, body, APICAPACITACION.<span class="hljs-string">"resource/Designation"</span>)`
4. Evalúa la respuesta:
    
    
    - Si encuentra registros → devuelve el `mof`.
    - Si no encuentra → error.

---

# 📚 **Schema**

### **Response**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🧪 **Ejemplo de Uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-get-%22https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X GET <span class="hljs-string">"https://midominio.com/getDocumentPuesto?puesto=OPERADOR"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>**Respuesta esperada:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Documento encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/mof_operador.pdf"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Verifica los documentos descargados (1, 2) - [verifyDownloadedDocuments]

## **Descripción**

*Este servicio valida si un empleado ha completado la **descarga obligatoria de documentos institucionales** dentro del aplicativo.*  
*Además, verifica si el empleado ha registrado previamente sus documentos de ingreso (elección de banco, declaración de AFP/ONP, etc.).*

*El proceso consulta tanto **ERPNext** como **la base de datos MySQL2** para construir un resumen de los documentos descargados y determinar si el empleado tiene **todos los documentos obligatorios** descargados.*

---

## **Parámetros**

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-descr"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1009" data-start="857"><thead data-end="891" data-start="857"><tr data-end="891" data-start="857"><th data-col-size="sm" data-end="869" data-start="857">Parámetro</th><th data-col-size="sm" data-end="876" data-start="869">Tipo</th><th data-col-size="md" data-end="891" data-start="876">Descripción</th></tr></thead><tbody data-end="1009" data-start="926"><tr data-end="1009" data-start="926"><td data-col-size="sm" data-end="940" data-start="926">`$employee`</td><td data-col-size="sm" data-end="949" data-start="940">string</td><td data-col-size="md" data-end="1009" data-start="949">Código del empleado (Employee.name) que se va a validar.</td></tr></tbody></table>

</div></div>---

## **Proceso general**

1. **Validación inicial de datos del empleado**
    
    
    - Realiza una consulta a ERPNext para obtener los campos:
        
        
        - `eleccion_banco`
        - `afiliado_fondo_pensiones`
        - `elección_fondo_pensiones`
    - Si el empleado no existe, devuelve un error.
2. **Validación de documentos de ingreso**
    
    
    - Antes de validar documentos descargados, se comprueba que el empleado ya **subió sus documentos de ingreso**.
    - Si falta alguno de estos:
        
        
        - Elección de banco
        - Si está afiliado o no al fondo de pensiones
        - Selección AFP u ONP
        
        → Se retorna:  
        **"Primero suba los documentos de ingreso"**
3. **Obtención del historial de descargas**
    
    
    - Consulta la tabla <span style="color: rgb(224, 62, 45);">**`historial_procesos_app`**</span> en MySQL2.
    - Se recuperan registros para los procesos:
        
        
        - descargaContratoTrabajo
        - descargaReglamentoInternoTrabajo
        - descargaRecomentacionesSST
        - descargaConvenioDescuento
        - descargaDeclaracionJuradaDomicilio
        - descargadeclaracionJuradaSNPSPP
        - descargaPoliticasSalariales
        - registroEPP
        - descargaPETSAlmacenamiento
        - descargaPETSManipulacion
        - descargaMOF
        - descargaPoliticasDescuentosPorDanios
4. **Construcción del resumen por empleado**
    
    
    - Cada documento es asignado como:
        
        
        - `1` → descargado
        - `0` → pendiente
5. **Validación del 100% de documentos**
    
    
    - Si todos los procesos están registrados → <span style="color: rgb(224, 62, 45);">**`total_documentos = true`**</span>
    - Si falta alguno → <span style="color: rgb(224, 62, 45);">**`total_documentos = false`**</span>
6. **Validación adicional: Cambio de modalidad**
    
    
    - Si el empleado tiene alguna "Solicitud de Cambio de Modalidad" aprobada (`docstatus != 2`), se considera **descargado automáticamente el contrato de trabajo**.
7. **Retorno final del estado del empleado**

---

## **Respuesta exitosa**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaContratoTrabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaReglamentoInternoTrabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaRecomendacionesSST"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaConvenioDescuento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaDeclaracionJuradaDomicilio"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaDeclaracionJuradaSNPSPP"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaPoliticasSalariales"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"registroEPP"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaPETSAlmacenamiento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaPETSManipulacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaMOF"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descargaPoliticasDescuentosPorDanios"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"total_documentos"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## **Posibles respuestas con error**

### ● Empleado no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado sin datos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ● Documentos de ingreso no completados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Primero suba los documentos de ingreso"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Lista de marcaciones generada (1) - [listMarkingsApp45]

### 🧾 Descripción

*Este servicio obtiene y consolida **todas las marcaciones de asistencia de un empleado en una fecha específica**, combinando información de:*

- **Employee Checkin** (Entradas, salidas, refrigerios)
- **Attendance** (Estado del día)
- **Cortes** (Fechas especiales donde cambia el criterio de consulta)
- **Turnos del empleado (Shift Type)**

*Entrega una estructura lista para mostrar en una app móvil o web con:*

- Entrada
- Salida a refrigerio
- Retorno de refrigerio
- Salida
- Estado del día (Presente, Ausente, Teletrabajo, etc.)
- Información del día: nombre, mes, fecha formateada.

*El servicio también calcula dinámicamente si debe tomar **estado\_reporte** o **status**, según si la fecha consultada pertenece al rango generado desde el último corte del mes.*

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/list-markings-app45`**</span>

---

# 📥 Parámetros de Entrada (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"token de sesión"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-MM-DD"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1545" data-start="1203"><thead data-end="1242" data-start="1203"><tr data-end="1242" data-start="1203"><th data-col-size="sm" data-end="1216" data-start="1203">Campo</th><th data-col-size="sm" data-end="1227" data-start="1216">Tipo</th><th data-col-size="md" data-end="1242" data-start="1227">Descripción</th></tr></thead><tbody data-end="1545" data-start="1282"><tr data-end="1372" data-start="1282"><td data-col-size="sm" data-end="1294" data-start="1282">usuario</td><td data-col-size="sm" data-end="1305" data-start="1294">string</td><td data-col-size="md" data-end="1372" data-start="1305">Usuario que solicita información (no se usa en lógica interna).</td></tr><tr data-end="1428" data-start="1373"><td data-col-size="sm" data-end="1385" data-start="1373">empleado</td><td data-col-size="sm" data-end="1396" data-start="1385">string</td><td data-col-size="md" data-end="1428" data-start="1396">ID del empleado a consultar.</td></tr><tr data-end="1495" data-start="1429"><td data-col-size="sm" data-end="1441" data-start="1429">cookie</td><td data-col-size="sm" data-end="1452" data-start="1441">string</td><td data-col-size="md" data-end="1495" data-start="1452">Cookie de sesión para consultas al ERP.</td></tr><tr data-end="1545" data-start="1496"><td data-col-size="sm" data-end="1508" data-start="1496">date</td><td data-col-size="sm" data-end="1519" data-start="1508">string</td><td data-col-size="md" data-end="1545" data-start="1519">Fecha de la marcación.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere cookie de sesión válida para ERPNext, ya que usa servicios internos vía:

- `dbErp()`
- `ServiceErp()`

---

# 🧠 Flujo del Servicio (Resumen Real)

### 1️⃣ Obtiene filtros según fecha

- Si la fecha es **&gt;= 2022-11-10**, consulta por <span style="color: rgb(224, 62, 45);">**`fecha_consolidado`**</span>.
- Si es menor, consulta por *rango horario* (00:00:00 – 23:59:59).

### 2️⃣ Trae las marcaciones del empleado

Consulta <span style="color: rgb(224, 62, 45);">**`tabEmployee Checkin`**</span> (Entrada, Refrigerio, Salida).

### 3️⃣ Consulta estado de asistencia

Desde `<span style="color: rgb(224, 62, 45);"><strong>tabAttendance</strong></span>`, validando solo documentos aprobados (`docstatus = 1`).

### 4️⃣ Obtiene configuración de cortes del mes

Sirve para determinar si el estado válido es:

- `estado_reporte` (cuando está dentro del rango posterior al corte), ó
- `status` (estado normal de Attendance)

### 5️⃣ Genera un rango de fechas desde el corte hasta fin de mes

Se usa para validar cambios de lógica.

### 6️⃣ Procesa marcaciones y las estructura así:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22entrada%22%3A-%7B...%7D%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"entrada"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"salida_refrigerio"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"llegada_refrigerio"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"salida"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"asistencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div></div>###  

### 7️⃣ Traduce estados a texto legible

Ejemplo:

<div class="_tableContainer_1rjym_1" id="bkmrk-erp-texto-entregado-"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2849" data-start="2688"><thead data-end="2713" data-start="2688"><tr data-end="2713" data-start="2688"><th data-col-size="sm" data-end="2694" data-start="2688">ERP</th><th data-col-size="sm" data-end="2713" data-start="2694">Texto entregado</th></tr></thead><tbody data-end="2849" data-start="2740"><tr data-end="2762" data-start="2740"><td data-col-size="sm" data-end="2750" data-start="2740">Present</td><td data-col-size="sm" data-end="2762" data-start="2750">Presente</td></tr><tr data-end="2783" data-start="2763"><td data-col-size="sm" data-end="2772" data-start="2763">Absent</td><td data-col-size="sm" data-end="2783" data-start="2772">Ausente</td></tr><tr data-end="2824" data-start="2784"><td data-col-size="sm" data-end="2801" data-start="2784">Work From Home</td><td data-col-size="sm" data-end="2824" data-start="2801">Trabajar desde casa</td></tr><tr data-end="2849" data-start="2825"><td data-col-size="sm" data-end="2836" data-start="2825">Half Day</td><td data-col-size="sm" data-end="2849" data-start="2836">Medio día</td></tr></tbody></table>

</div></div>---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de marcaciones generada correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"entrada"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"hora_marcacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"08:01 AM"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"existe"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"salida_refrigerio"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"llegada_refrigerio"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"salida"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>...<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"asistencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ENERO"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PRESENTE"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"nombre_fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"MIERCOLES 15 DE 2025"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Error al obtener marcaciones

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al traer asistencia"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error al consultar Attendance o Cortes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Fallo al traer asistencia."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Error interno del servidor

<table border="1" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error en listMarkingsApp45: <mensaje>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<stacktrace>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Tablas / Recursos Usados

### 🔹 `tabEmployee Checkin`

Campos:

- name
- employee
- employee\_name
- log\_type
- time
- tardanza
- salida\_temprana

### 🔹 `tabAttendance`

- status
- estado\_reporte
- attendance\_date
- employee

### 🔹 `tabCortes`

- dia\_inicio
- dia\_final

### 🔹 `tabShift Type`

- start\_time
- end\_time

---

# 🧩 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-input%3A-usuario%2C-empl"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`input: usuario, empleado, cookie, datecalcular inicio y fin del díasi date >= 2022-11-10:    buscar checkin por fecha_consolidadoelse:    buscar checkin por rango de horasconsultar Attendanceconsultar Cortes del messi cortes vacío → errorgenerar fechas posteriores al cortedeterminar estado (status o estado_reporte)crear estructura de salidaiterar marcaciones:    si log_type == Entrada → entrada    si log_type == Salida Refrigerio → salida_refrigerio    etc.retornar JSON con todas las marcaciones y estado`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Obtener Usuario (3) - [getUser3]

### 🧾 Descripción

*Este servicio permite **obtener la información completa de un usuario**, ya sea **Empleado** o **Estudiante**, usando cualquiera de los siguientes identificadores:*

- **Correo** (user\_id)
- **DNI / Pasaporte** (passport\_number)

*La función consulta múltiples tablas del ERP y retorna la información enriquecida del usuario, incluyendo:*

- Datos personales
- Datos laborales
- Contratos
- Imagen de usuario
- Estado actual
- Sucursal, puesto, departamento
- Datos adicionales (PETS, tipo de jornada, fondo de pensiones, etc.)

*Si el usuario no es empleado, se intenta validar como estudiante.*  
*El servicio aplica múltiples reglas de negocio internas sobre estado, tipo de usuario y permisos.*

---

# 🚀 Endpoint

**POST /get-user-3**

📥 *Body esperado*

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22username%22%3A-%22usuar"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"usuario@correo.com"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div></div>O también:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22username%22%3A-%2212345"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

Este servicio requiere autenticación interna contra el ERP mediante <span style="color: rgb(224, 62, 45);">**`dbErp()`**</span> y **<span style="color: rgb(224, 62, 45);">`ServiceErp()`</span>** con token válido del sistema.

---

# 🧠 Flujo del Servicio (Resumen Real)

### **1. Determinar tipo de búsqueda**

Si **`username`** contiene **@**, se asume que es *user\_id*.  
Si no contiene, se usa como **passport\_number** (DNI).

Se arma el filtro dinámicamente:

<div class="_tableContainer_1rjym_1" id="bkmrk-caso-campo-filtrado-"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1665" data-start="1547"><thead data-end="1572" data-start="1547"><tr data-end="1572" data-start="1547"><th data-col-size="sm" data-end="1554" data-start="1547">Caso</th><th data-col-size="sm" data-end="1572" data-start="1554">Campo filtrado</th></tr></thead><tbody data-end="1665" data-start="1599"><tr data-end="1623" data-start="1599"><td data-col-size="sm" data-end="1608" data-start="1599">Correo</td><td data-col-size="sm" data-end="1623" data-start="1608">emp.user\_id</td></tr><tr data-end="1665" data-start="1624"><td data-col-size="sm" data-end="1642" data-start="1624">DNI / Pasaporte</td><td data-col-size="sm" data-end="1665" data-start="1642">emp.passport\_number</td></tr></tbody></table>

</div></div>---

### **2. Buscar al usuario como *Empleado***

Consulta principal: `POST <span class="hljs-keyword">method</span>/send-query-<span class="hljs-keyword">database</span>`

Incluye joins a:

- tabUser
- tabBranch
- tabContrato de Trabajo
- tabDepartment

Si existe un registro válido:

- Se valida que NO esté inactivo.
- Se formatea fecha de nacimiento.
- Se determina si el contrato es renovación o primer contrato.
- Se normalizan campos (pets, cuenta haberes, vigencia del contrato, tipo\_usuario = "Empleado").

📌 **Si todo está correcto, el servicio termina aquí** retornando la data del empleado.

---

### **3. Si NO existe empleado → Buscar como *Estudiante***

Filtros dependen de correo o DNI.

Validaciones aplicadas:

- Debe estar habilitado (`enabled = 1`).
- Si no existe → acceso denegado.
- Si está deshabilitado → retorno con error.

Datos retornados incluyen:

- Nombre completo
- Sucursal, departamento
- Tipo de puesto (convertido desde convocatoria si aplica)
- Imagen de usuario
- Tipo\_usuario = “Estudiante”

---

### **4. Retornar la data final**

Si es empleado → retorna información laboral con contratos.  
Si es estudiante → retorna información básica educativa.

---

# 📤 Response 200 – Ejemplo (Empleado)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Si hay data"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"employee_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"user_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"juan.perez@empresa.com"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"gender"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Male"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Active"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"tipo_usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"vigencia_contrato"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-01-01 hasta 2024-12-31"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"contratacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"renovacion"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"pets"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"bank_ac_no"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1234567890"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### **1. No existe como empleado ni estudiante**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sin Estudiante: Su usuario no tiene permisos para acceder al aplicativo."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **2. Empleado Inactivo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado Inactivo: Comuníquese con su administrador..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **3. Usuario deshabilitado (estudiante)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario Deshabilitado..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div></div>###  

### **4. Error al consultar ERP**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al obtener la información"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Tablas consultadas

### **Empleado**

- `tabEmployee`
- `tabUser`
- `tabBranch`
- `tabContrato de Trabajo`
- `tabDepartment`

### **Estudiante**

- `tabStudent`
- `tabUser`
- `tabBranch`
- `tabJob Applicant`
- `tabRequerimiento de Personal`
- `tabDesignation`
- `tabDepartment`

---

# 🗃 Resultado Final (Estructura General)

### Para empleados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22emp-001%22%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"employee_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"user_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"gender"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"contratacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"primer_contrato | renovacion"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Active | PreActivo | Inactive"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pets"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"vigencia_contrato"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-string">"...otros campos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Para estudiantes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22st-001%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ST-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"employee_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"user_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Estudiante"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"statusUser"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-string">"...otros campos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🧩 Pseudocódigo del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-username-%3D-request.u"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`username = request.username<span class="hljs-keyword">if</span> username contains <span class="hljs-string">"@"</span>:    filter <span class="hljs-keyword">by</span> user_id<span class="hljs-keyword">else</span>:    filter <span class="hljs-keyword">by</span> passport_numberemployee = buscarEmpleado()<span class="hljs-keyword">if</span> existe empleado:    validar estado    cargar contratos    formatear datos    <span class="hljs-keyword">return</span> empleado<span class="hljs-keyword">else</span>:    student = buscarEstudiante()    si no existe o está deshabilitado:        error    <span class="hljs-keyword">return</span> student`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Lista de Sucursales - [listOfErpBranchs]

## 🧾 Descripción

*Obtiene la lista completa de **sucursales registradas en el ERP**, filtrando únicamente aquellas que:*

- No sean concesionarios (`concesionario = 0`)
- Tengan un identificador válido (`ideentificador != "0"`)

*El servicio consulta directamente el ERP a través del método `apiService()` y devuelve las sucursales ordenadas alfabéticamente por su nombre.*

*También realiza un post-proceso convirtiendo el campo `ideentificador` en **string**, garantizando consistencia en el frontend (evita problemas cuando el ERP envía valores numéricos).*

---

## 🚀 Endpoint

**GET** <span style="color: rgb(224, 62, 45);">**`/list-of-erp-branchs`**</span>

No recibe parámetros.

Toda la data proviene del ERP mediante:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-branch%3Flimit%3Dnon"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Branch?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>&order_by=<span class="hljs-type">name</span> <span class="hljs-keyword">asc</span>&fields=["name","ideentificador"]&filters=[["concesionario","=",<span class="hljs-number">0</span>],["ideentificador","!=","0"]]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

Requiere autenticación del ERP mediante <span style="color: rgb(224, 62, 45);">**`apiService()`**<span style="color: rgb(0, 0, 0);">.</span></span>  
El token se gestiona internamente (servicio backend–backend).

---

## 🧠 Flujo del Servicio

1. Llama al ERP solicitando todas las sucursales:
    
    
    - Sin límite (`limit=None`)
    - Ordenadas (`order_by=name asc`)
    - Filtradas por:
        
        
        - concesionario = 0
        - ideentificador ≠ "0"
    - Campos solicitados:
        
        
        - `name`
        - `ideentificador`
2. Decodifica la respuesta.
3. Valida que exista el campo `"data"` en la respuesta del ERP.
    
    
    - Si no existe, retorna error.
4. Recorre cada registro y convierte `ideentificador` a string.
5. Retorna la lista final de sucursales.

---

## 📥 Request Body

No tiene body.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de Sucursales generado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sucursal Lima"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ideentificador"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"101"</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sucursal Arequipa"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ideentificador"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"205"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. Error al obtener data del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al traer la lista de sucursales"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Excepción interna del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Esquema de datos (Branch)

### **Branch (GET)**

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ideentificador"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string | number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Pseudocódigo del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-response-%3D-apiservic"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`response = apiService(<span class="hljs-string">"Branch?limit=None&order_by=name asc&fields=[name,ideentificador]&filters=[[concesionario,=,0],[ideentificador,!=,0]]"</span>)<span class="hljs-keyword">if</span> !response.<span class="hljs-keyword">data</span>:    <span class="hljs-keyword">return</span> errorforeach branch <span class="hljs-keyword">in</span> response.<span class="hljs-keyword">data</span>:    branch.ideentificador = str(branch.ideentificador)<span class="hljs-keyword">return</span> success(branch)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Intento de Marcación (1) - [intentMarca]

### 🧾 Descripción

*Registra y actualiza los intentos de marcación que realiza un empleado en una agencia durante el día.*  
*Este servicio controla cuántas veces un colaborador intenta marcar asistencia, creando o actualizando un registro diario en el ERP.*

Se basa en el Doctype:

- **Intento de marcacion**

Y utiliza los campos:

- empleado
- agencia
- intento
- creacion (fecha del intento)

---

# 🚀 Endpoint

**<span style="color: rgb(224, 62, 45);">POST /intent-marca</span>**

El servicio recibe datos desde el body mediante <span style="color: rgb(224, 62, 45);">**`Request`**</span>.

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AG-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos requeridos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1166" data-start="907"><thead data-end="951" data-start="907"><tr data-end="951" data-start="907"><th data-col-size="sm" data-end="915" data-start="907">Campo</th><th data-col-size="sm" data-end="922" data-start="915">Tipo</th><th data-col-size="sm" data-end="936" data-start="922">Obligatorio</th><th data-col-size="sm" data-end="951" data-start="936">Descripción</th></tr></thead><tbody data-end="1166" data-start="999"><tr data-end="1046" data-start="999"><td data-col-size="sm" data-end="1010" data-start="999">empleado</td><td data-col-size="sm" data-end="1019" data-start="1010">string</td><td data-col-size="sm" data-end="1023" data-start="1019">✔</td><td data-col-size="sm" data-end="1046" data-start="1023">Código del empleado</td></tr><tr data-end="1106" data-start="1047"><td data-col-size="sm" data-end="1057" data-start="1047">agencia</td><td data-col-size="sm" data-end="1066" data-start="1057">string</td><td data-col-size="sm" data-end="1070" data-start="1066">✔</td><td data-col-size="sm" data-end="1106" data-start="1070">Agencia en la que intenta marcar</td></tr><tr data-end="1166" data-start="1107"><td data-col-size="sm" data-end="1117" data-start="1107">intento</td><td data-col-size="sm" data-end="1123" data-start="1117">int</td><td data-col-size="sm" data-end="1127" data-start="1123">✔</td><td data-col-size="sm" data-end="1166" data-start="1127">Intento actual enviado desde la app</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Utiliza autenticación interna del ERP a través de:

- **dbErp()** para consultas SQL
- **ServiceErp()** para creación y actualización de documentos en el ERP

Requiere credenciales internas del sistema.

---

# 🧠 Flujo del Servicio (resumen real)

1. **Valida que existan los parámetros obligatorios**: empleado, agencia e intento.  
    Si falta alguno → retorna error.
2. **Determina la fecha actual (`Y-m-d`)**.  
    Este valor se usa para registrar un intento por día.
3. **Consulta si el empleado ya tiene un registro de Intento de marcacion para el día actual**:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`tpr.empleado <span class="hljs-operator">=</span> empleado <span class="hljs-keyword">AND</span> tpr.creacion <span class="hljs-operator">=</span> fecha_actual`</div></div>
4. Si **existe un registro previo**:
    
    
    - Se suma el intento nuevo al intento existente:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">intento_total</span> = intento_enviado + intento_existente`</div></div>
    - Se actualiza el Doctype:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-type">PUT</span> resource<span class="hljs-regexp">/Intento de marcacion/</span>{name}`</div></div>
5. Si **NO existe un registro previo**:
    
    
    - Se crea un nuevo documento Intento de marcacion:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attribute">POST</span> resource/Intento de marcacion`</div></div>
6. Devuelve la respuesta directa del ERP.

---

# 📤 Response 200 – Ejemplo (actualizado)

### ✔ Caso actualización

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Actualizado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"INT-MAR-00045"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AG-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-10"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Caso creación

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Creado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"INT-MAR-00046"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AG-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-10"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Falta de parámetros requeridos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró al empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error en la consulta DB → dbErp

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 33.8px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 33.8px;"><td style="height: 33.8px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al consultar ERP"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Error en creación o actualización en ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al registrar intento"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuesta ERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Doctype utilizado

## Intento de marcacion

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-employee-%3D-request.e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`employee = request.empleadoagencia = request.agenciaintento = request.intentofecha = hoy (Y-m-d)if falta algún parámetro:    return errorconsulta = GET Intento de marcacion where empleado = employee and creacion = fechaif existe_registro:    nuevo_intento = intento + registro.intento    PUT Intento de marcacion/{name} con { empleado, agencia, intento: nuevo_intento, creacion }else:    POST Intento de marcacion con { empleado, agencia, intento, creacion }return respuesta`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Validar Marcación (1) - [validar]

### 🧾 Descripción

*Este servicio ejecuta **toda la lógica de validación previa** para permitir que un empleado realice una marcación (asistencia).*  
*El servicio centraliza más de **10 validaciones críticas**, verificando:*

- Campos obligatorios
- Licencias activas
- Restricciones por puesto
- Validación de firma de documentos obligatorios
- Descarga de contratos y documentos requeridos
- Datos incompletos del empleado
- Tipo de marcación permitido
- Esquema de fiscalización
- Reglas por empresa (Shalom Express vs Shalom Empresarial)

*Es un servicio de control que determina si el empleado puede realizar una marcación y qué mensaje debe mostrarse al usuario.*

---

# 🚀 Endpoint

**<span style="color: rgb(224, 62, 45);">POST /validar</span>**

---

# 📥 Request Body (resumen)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ingreso"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_asistencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-01"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fhingreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2023-01-10"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status_employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Active"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"OPERADOR"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIMA-01"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

- Requiere usuario autenticado.
- Usa datos precargados del empleado (`$this->employee_detail`).
- Internamente utiliza múltiples servicios ERP y validadores internos.

---

# 🧠 Flujo del Servicio (Resumen Real)

1️⃣ **Validar campos obligatorios**  
Llama a `verifyFields()`.  
Si falta algún parámetro → retorna error inmediato.

2️⃣ **Cargar datos principales**

- empleado
- tipo de marcación
- fecha de asistencia
- datos del empleado desde sesión previa

3️⃣ **Validar restricciones por puesto**  
Si el empleado NO es "PreActivo", llama a:  
`validateRestrictedDesignation(designation)`

4️⃣ **Validar licencia activa**  
`verifyLicencia(empleado, fechaIngreso)`

5️⃣ **Validar nuevos ingresos**  
Solo para empleados activos, ingreso reciente, y NO Express:  
`verifySignedNewAdmissionRegistrations()`

6️⃣ **Validar descarga de documentos obligatorios**  
Obtiene documentos descargados:  
`verifyDownloadedDocumentsBd()`  
Y valida contrato pendiente:  
`verifyContractDownload()`

7️⃣ **Validar documentos de cambio de modalidad**  
`verifyModalityChangeDocument()`

8️⃣ **Validar información del empleado (horarios, jornada, etc.)**  
`verifyEmployeeData()`

9️⃣ **Obtener últimas marcaciones**  
`getMarkingsByEmployee()`

🔟 **Validación de “No sujeto a fiscalización”**  
`verifyEmployeeNotSubjectToInspection()`

1️⃣1️⃣ **Validación de refrigerio**  
Si type == *llegada\_refrigerio*:  
`verifyStartOfLunch()`

1️⃣2️⃣ **Validar coherencia del tipo de marcación**  
Ejemplo: que no marque salida sin marcar ingreso.  
`verifyTypeOfMarking()`

📌 Si todas las validaciones son correctas → retorna éxito.

---

# 📤 Response 200 – Ejemplo (OK)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marcación permitida"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ingreso"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"valid"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores devueltos por este servicio

### 1. Campos obligatorios faltantes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta el campo empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Puesto restringido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Su puesto no permite realizar marcaciones"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Empleado con licencia activa

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Tiene licencia activa. No puede marcar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Documentos de ingreso no firmados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe firmar sus documentos de ingreso"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Contrato pendiente por descargar

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe descargar su contrato para continuar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 6. Error en la lógica de marcación (orden incorrecta)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No puede marcar salida sin haber marcado ingreso"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 7. No sujeto a fiscalización

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empleado no sujeto a fiscalización"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Funciones internas utilizadas

<div class="_tableContainer_1rjym_1" id="bkmrk-nombre-descripci%C3%B3n-v"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="4713" data-start="3917"><thead data-end="3937" data-start="3917"><tr data-end="3937" data-start="3917"><th data-col-size="sm" data-end="3924" data-start="3917">Nombre</th><th data-col-size="md" data-end="3937" data-start="3924">Descripción</th></tr></thead><tbody data-end="4713" data-start="3959"><tr data-end="4010" data-start="3959"><td data-col-size="sm" data-end="3972" data-start="3959">verifyFields</td><td data-col-size="md" data-end="4010" data-start="3972">Valida campos requeridos del request</td></tr><tr data-end="4077" data-start="4011"><td data-col-size="sm" data-end="4041" data-start="4011">validateRestrictedDesignation</td><td data-col-size="md" data-end="4077" data-start="4041">Controla puestos con restricciones</td></tr><tr data-end="4138" data-start="4078"><td data-col-size="sm" data-end="4093" data-start="4078">verifyLicencia</td><td data-col-size="md" data-end="4138" data-start="4093">Evalúa si el empleado tiene licencia activa</td></tr><tr data-end="4203" data-start="4139"><td data-col-size="sm" data-end="4177" data-start="4139">verifySignedNewAdmissionRegistrations</td><td data-col-size="md" data-end="4203" data-start="4177">Valida firmas de ingreso</td></tr><tr data-end="4263" data-start="4204"><td data-col-size="sm" data-end="4232" data-start="4204">verifyDownloadedDocumentsBd</td><td data-col-size="md" data-end="4263" data-start="4232">Valida documentos descargados</td></tr><tr data-end="4323" data-start="4264"><td data-col-size="sm" data-end="4287" data-start="4264">verifyContractDownload</td><td data-col-size="md" data-end="4323" data-start="4287">Revisa si falta descargar contrato</td></tr><tr data-end="4396" data-start="4324"><td data-col-size="sm" data-end="4353" data-start="4324">verifyModalityChangeDocument</td><td data-col-size="md" data-end="4396" data-start="4353">Valida documentos de cambios de modalidad</td></tr><tr data-end="4468" data-start="4397"><td data-col-size="sm" data-end="4416" data-start="4397">verifyEmployeeData</td><td data-col-size="md" data-end="4468" data-start="4416">Verifica datos del empleado necesarios para marcar</td></tr><tr data-end="4529" data-start="4469"><td data-col-size="sm" data-end="4491" data-start="4469">getMarkingsByEmployee</td><td data-col-size="md" data-end="4529" data-start="4491">Obtiene último registro de marcación</td></tr><tr data-end="4606" data-start="4530"><td data-col-size="sm" data-end="4567" data-start="4530">verifyEmployeeNotSubjectToInspection</td><td data-col-size="md" data-end="4606" data-start="4567">Revisa si está sujeto a fiscalización</td></tr><tr data-end="4656" data-start="4607"><td data-col-size="sm" data-end="4626" data-start="4607">verifyStartOfLunch</td><td data-col-size="md" data-end="4656" data-start="4626">Valida inicio del refrigerio</td></tr><tr data-end="4713" data-start="4657"><td data-col-size="sm" data-end="4677" data-start="4657">verifyTypeOfMarking</td><td data-col-size="md" data-end="4713" data-start="4677">Controla coherencia de marcaciones</td></tr></tbody></table>

</div></div>---

# 🗃 Pseudo-código real del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21verifyfields%28req"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span> !<span class="hljs-title function_ invoke__">verifyFields</span>(request): <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> puesto restringido: <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> licencia activa: <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> ingreso reciente y no Shalom Express:    validar documentos de ingresovalidar documentos descargadosvalidar contratovalidar cambio de modalidadvalidar información del empleadomarcacionesPrevias = <span class="hljs-title function_ invoke__">getMarkingsByEmployee</span>()<span class="hljs-keyword">if</span> no sujeto a fiscalización: <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> marcación es llegada_refrigerio:    validar inicio refrigeriovalidar secuencia de tipo de marcación<span class="hljs-keyword">return</span> OK`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Crear Marcación (1) - [crear]

## 🧾 Descripción

*Registra una **marcación de entrada o salida** para un empleado, validando previamente:*

- Datos obligatorios del request.
- Duplicidad de marcaciones.
- Estado del empleado (Activo / PreActivo).
- Horario asignado (tardanza y horas extra).
- Reglas especiales según modalidad (offline / online).
- Registro simultáneo en:
    
    
    - **ERP (Employee Checkin)**
    - **Base de datos interna (tabla marcaciones)**

*Es uno de los servicios centrales del módulo de asistencia.*

---

# 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">**`POST /marcaciones/store`**</span>

Este servicio **sí recibe parámetros en el request**.

---

# 📥 Request Body (Campos usados)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"image"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"https://.../foto.jpg"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_asistencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-03"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"entrada | salida"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"coordinates"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"-12.10, -77.05"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"isOfline"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos relevantes

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1559" data-start="1174"><thead data-end="1204" data-start="1174"><tr data-end="1204" data-start="1174"><th data-col-size="sm" data-end="1182" data-start="1174">Campo</th><th data-col-size="sm" data-end="1189" data-start="1182">Tipo</th><th data-col-size="sm" data-end="1204" data-start="1189">Descripción</th></tr></thead><tbody data-end="1559" data-start="1235"><tr data-end="1274" data-start="1235"><td data-col-size="sm" data-end="1246" data-start="1235">empleado</td><td data-col-size="sm" data-end="1255" data-start="1246">string</td><td data-col-size="sm" data-end="1274" data-start="1255">ID del empleado</td></tr><tr data-end="1323" data-start="1275"><td data-col-size="sm" data-end="1283" data-start="1275">image</td><td data-col-size="sm" data-end="1292" data-start="1283">string</td><td data-col-size="sm" data-end="1323" data-start="1292">URL base64 o imagen enviada</td></tr><tr data-end="1375" data-start="1324"><td data-col-size="sm" data-end="1343" data-start="1324">fecha\_asistencia</td><td data-col-size="sm" data-end="1350" data-start="1343">date</td><td data-col-size="sm" data-end="1375" data-start="1350">Fecha de la marcación</td></tr><tr data-end="1416" data-start="1376"><td data-col-size="sm" data-end="1383" data-start="1376">type</td><td data-col-size="sm" data-end="1392" data-start="1383">string</td><td data-col-size="sm" data-end="1416" data-start="1392">“entrada” o “salida”</td></tr><tr data-end="1470" data-start="1417"><td data-col-size="sm" data-end="1435" data-start="1417">passport\_number</td><td data-col-size="sm" data-end="1444" data-start="1435">string</td><td data-col-size="sm" data-end="1470" data-start="1444">Documento del empleado</td></tr><tr data-end="1514" data-start="1471"><td data-col-size="sm" data-end="1485" data-start="1471">coordinates</td><td data-col-size="sm" data-end="1494" data-start="1485">string</td><td data-col-size="sm" data-end="1514" data-start="1494">Lat/Lon opcional</td></tr><tr data-end="1559" data-start="1515"><td data-col-size="sm" data-end="1526" data-start="1515">isOfline</td><td data-col-size="sm" data-end="1532" data-start="1526">int</td><td data-col-size="sm" data-end="1559" data-start="1532">`1` si se marcó offline</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

El servicio requiere:

- Token válido via middleware Laravel.
- Acceso interno al ERP mediante <span style="color: rgb(224, 62, 45);">**`general->insertERPNew()`**</span> y <span style="color: rgb(224, 62, 45);">**`general->dbErp()`**</span>.

---

# 🧠 Flujo del Servicio (resumen real)

### **1. Validación de campos**

Se ejecuta `verifyFields($request)` y si falla, retorna de inmediato.

### **2. Prevención de fechas inválidas**

Si la marcación es online y la fecha es mayor al día actual → rechaza.

### **3. Validación de duplicidad**

Se construye:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%22employee%22-%3D%3E-empl"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`[  <span class="hljs-string">"employee"</span> => empleado,  <span class="hljs-string">"log_type"</span> => type_markings[type],  <span class="hljs-string">"fecha_de_consolidado"</span> => fecha_asistencia]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Luego: `validateDuplicateDialing()`

Si ya existe marcación → error.

---

### **4. Obtención del turno del empleado**

Consulta ERP:

- Hora de inicio (`start_time`)
- Hora de salida (`end_time`)
- Datos básicos del empleado

Si es “entrada” → valida que pase de PreActivo → Activo.

---

### **5. Cálculo de tardanza u horas extra**

- Si el empleado marca **entrada** más de 5 min tarde → genera tardanza `"HH:MM"`.
- Si marca **salida** con +60 minutos → horas extra.

---

### **6. Registro en ERP**

Crea documento:

**Employee Checkin**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%22employee%22-%3D%3E-empl-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`[  <span class="hljs-string">"employee"</span> => empleado,  <span class="hljs-string">"time"</span> => fecha,  <span class="hljs-string">"coordenadas"</span> => coordinates,  <span class="hljs-string">"log_type"</span> => Entrada/Salida,  <span class="hljs-string">"urlimagen2"</span> => image,  <span class="hljs-string">"offline"</span> => isOfline,  <span class="hljs-string">"late_time"</span> => tardanza calculada,  <span class="hljs-string">"overtime_time"</span> => horasExtras,]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### **7. Registro en base de datos interna**

Inserta en tabla `marcaciones`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-employee%2C-time%2C-log_"><div class="overflow-y-auto p-4" dir="ltr">`employee, <span class="hljs-selector-tag">time</span>, log_type, fecha_de_consolidado, urlimagen2, document...`</div></div>---

### **8. Generación de asistencia**

Si la marcación es **salida**, ejecuta: `storeAttendance($request)`

y devuelve datos adicionales.

---

# 📤 Response 200 – Ejemplo

### ✔ Entrada o salida registrada correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marcación registrada"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"time"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-03 08:03:00"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"late_time"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"00:03"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"overtime_time"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"offline"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Al registrar salida (incluye asistencia generada)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marcación registrada"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...checkin ERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data2"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...asistencia... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Campos inválidos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta completar campos obligatorios"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Marcación duplicada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al intentar realizar una marcación duplicada"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Fecha mayor al día actual

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La marcacion no puede ser mayor al día actual."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error creando Employee Checkin

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error al insertar marcación de salida."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Error servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor: <mensaje>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas utilizados

### **Employee**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-string%2C-%22d"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"name"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"default_shift"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"first_name"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"first_last_name"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"second_last_name"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"passport_number"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"id_sucursal"</span>: <span class="hljs-keyword">string</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Shift Type**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-string%2C-%22s"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"name"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"start_time"</span>: <span class="hljs-string">"HH:MM:SS"</span>,  <span class="hljs-string">"end_time"</span>: <span class="hljs-string">"HH:MM:SS"</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Employee Checkin (ERP)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"employee"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"time"</span>: datetime,  <span class="hljs-string">"log_type"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"late_time"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"overtime_time"</span>: <span class="hljs-keyword">string</span>,  <span class="hljs-string">"offline"</span>: <span class="hljs-keyword">int</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-verify-%3D-verifyfield"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`verify = verifyFields(request)if !verify.valor → return errorif fecha_asistencia > hoy AND online → return errorvalidateDuplicateDialing()if duplicado → return errorturno = GET turno del empleado en ERPif type == entrada:    validarPreActive()calcular tardanza / horas extrabodyCheckin = {...}insertERPNew("Employee Checkin", bodyCheckin)insert DB marcacionesif type == salida:    storeAttendance()    return respuesta con asistenciareturn respuesta normal`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Modulo de Asistencia y Marcaciones (Asistencia)

# Obtiene descarga boleta de pago (2) - [getDownloadBoletaPago]

### 🧾 Descripción

*Este servicio valida si un empleado **debe descargar obligatoriamente su boleta de pago del último mes** antes de poder realizar acciones como:*

- Registrar marcación
- Registrar solicitudes en la app
- Acceder a otros módulos operativos

*El servicio evalúa:*

1. Si está dentro del rango de validación (solo **del día 1 al 3** de cada mes).
2. La **fecha de ingreso del trabajador**.
3. Si tiene boleta generada el mes anterior.
4. Si el mes correspondiente está **habilitado para descarga**.
5. Si el empleado **ya descargó** la boleta (se revisa historial en MySQL).
6. Si el empleado está **PreActivo**, no se valida la descarga.

---

# 🚀 Endpoint

### GET /get-download-boleta-pago/{empleado}

📌 **Parámetro obligatorio:**

- **empleado** → ID del Employee (name)

---

# 🔐 Seguridad

- Requiere autenticación interna por el ERP mediante `dbErp()` y conexión MySQL interna.
- El servicio está pensado solo para uso interno de la aplicación móvil corporativa.

---

# 🧠 Flujo del Servicio (resumen)

### 1️⃣ Validación de fecha

Solo se ejecuta validación si el día actual está entre **1 y 3**.  
Si el día &gt; 3 → se omite toda validación:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No está dentro del rango de fecha de validación"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 2️⃣ Obtener información del empleado

Consulta ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-fecha_de_ingr"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> fecha_de_ingreso_real, status<span class="hljs-keyword">FROM</span> `tabEmployee`<span class="hljs-keyword">WHERE</span> name <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>empleado<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si el empleado está **PreActivo**, no se valida boleta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No validar descarga de boleta en PreActivo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3️⃣ Comparar fecha de ingreso vs fecha límite

Se calcula:

- Mes anterior
- Último día del mes anterior

Solo se valida si el empleado ingresó **antes del cierre del mes previo**.

---

### 4️⃣ Verificar en MySQL si ya descargó la boleta

Consulta tabla `historial_procesos_app`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-where-empleado-%3D-%3F-a"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">WHERE</span> empleado <span class="hljs-operator">=</span> ? <span class="hljs-keyword">AND</span> proceso <span class="hljs-operator">=</span> <span class="hljs-string">'NOMINA'</span><span class="hljs-keyword">AND</span> <span class="hljs-keyword">month</span> <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>mes_anterior<span class="hljs-operator">></span><span class="hljs-keyword">AND</span> <span class="hljs-keyword">year</span> <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>year_anterior<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no existe registro se sigue validación.

---

### 5️⃣ Validar si EXISTE boleta en ERP

Consulta Salary Slip del último mes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-posting_date-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> posting_date<span class="hljs-keyword">FROM</span> `tabSalary Slip`<span class="hljs-keyword">WHERE</span> employee <span class="hljs-operator">=</span> ?<span class="hljs-keyword">AND</span> posting_date <span class="hljs-keyword">between</span> <span class="hljs-operator"><</span>primer_día_mes_anterior<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> <span class="hljs-operator"><</span>último_día_mes_anterior<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no tiene boleta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No tiene boleta de pago por lo tanto no se valida"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 6️⃣ Validar si el mes está habilitado para descarga

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-name-from-%60ta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> name<span class="hljs-keyword">FROM</span> `tabEstado Boleta Mensual`<span class="hljs-keyword">WHERE</span> mes <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>mes_texto<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> año <span class="hljs-operator">=</span> <span class="hljs-operator"><</span><span class="hljs-keyword">year</span><span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> habilitado <span class="hljs-operator">=</span> <span class="hljs-number">1</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si está habilitado pero **el trabajador NO la descargó**, se bloquea:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su boleta pendiente del mes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 7️⃣ Si pasa todas las validaciones → OK

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado la boleta de pago"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📥 Request

**No usa body**, solo el parámetro de ruta: `<span class="hljs-symbol">empleado:</span> <span class="hljs-type">string</span>`

---

# 📤 Response – Ejemplos

### ✔ Caso permitido (día fuera de rango)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No está dentro del rango de fecha de validación"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Empleado en PreActivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No validar descarga de boleta en PreActivo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ No tiene boleta generada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No tiene boleta de pago por lo tanto no se valida"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ No ha descargado la boleta y es obligatoria

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su boleta pendiente del mes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Todo correcto

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado la boleta de pago"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles errores

<div class="_tableContainer_1rjym_1" id="bkmrk-error-descripci%C3%B3n-em"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="4308" data-start="4013"><thead data-end="4036" data-start="4013"><tr data-end="4036" data-start="4013"><th data-col-size="sm" data-end="4021" data-start="4013">Error</th><th data-col-size="sm" data-end="4036" data-start="4021">Descripción</th></tr></thead><tbody data-end="4308" data-start="4060"><tr data-end="4107" data-start="4060"><td data-col-size="sm" data-end="4081" data-start="4060">Empleado no existe</td><td data-col-size="sm" data-end="4107" data-start="4081">No se encuentra en ERP</td></tr><tr data-end="4173" data-start="4108"><td data-col-size="sm" data-end="4135" data-start="4108">No tiene boleta generada</td><td data-col-size="sm" data-end="4173" data-start="4135">Salary Slip del mes anterior vacío</td></tr><tr data-end="4248" data-start="4174"><td data-col-size="sm" data-end="4213" data-start="4174">Boleta habilitada pero no descargada</td><td data-col-size="sm" data-end="4248" data-start="4213">Bloquea marcación y solicitudes</td></tr><tr data-end="4308" data-start="4249"><td data-col-size="sm" data-end="4272" data-start="4249">Error en ERP o MySQL</td><td data-col-size="sm" data-end="4308" data-start="4272">Respuesta capturada por el catch</td></tr></tbody></table>

</div></div>---

# 🧩 Tablas consultadas

### ERP (Frappe/ERPNext)

- `tabEmployee`
- `tabSalary Slip`
- `tabEstado Boleta Mensual`

### MySQL externo

- `historial_procesos_app`

---

# 🗃 Pseudocódigo del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-day-%3E-3%3A-return-o"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-keyword">if</span> day > <span class="hljs-number">3</span>:    <span class="hljs-keyword">return</span> OK (no validar)empleado = GET Employee<span class="hljs-keyword">if</span> empleado.status == PreActivo:    <span class="hljs-keyword">return</span> OK<span class="hljs-keyword">if</span> fecha_ingreso < ultimo_dia_mes_anterior:    verificar si ya descargó boleta en MySQL    verificar si tiene boleta en ERP    <span class="hljs-keyword">if</span> no tiene:        <span class="hljs-keyword">return</span> OK    verificar si mes habilitado    <span class="hljs-keyword">if</span> habilitado y no descargado:        bloquear<span class="hljs-keyword">return</span> OK`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Obtiene descarga Renovación de contrato (2) - [getRenovacionContrato]

## 🧾 Descripción

*Valida si un empleado **debe descargar su renovación de contrato**, según reglas internas de fecha y estado en el ERP.*

Este servicio determina:

- Si hoy es la fecha válida para revisar renovaciones (solo a partir del día 26 de cada mes).
- Si el empleado ingresó antes del cierre del mes anterior (lo que lo vuelve candidato a renovación).
- Si el empleado tiene una solicitud de renovación aprobada y marcada como “Validado”.
- Si el empleado **ya descargó** su documento de renovación.
    
    
    - Caso contrario, se bloquean ciertas funcionalidades hasta que la descargue.

*Se combina información del **ERP** y del registro histórico en **MySQL2**.*

---

# 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">GET /get-renovacion-contrato/{empleado}</span>

📌 *El parámetro <span style="color: rgb(224, 62, 45);">**`empleado`** </span>es obligatorio (ID del Employee en ERP).*

---

# 🔐 Seguridad

✔ Requiere autenticación interna vía <span style="color: rgb(224, 62, 45);">**`dbErp()`** </span>y tokens del ERP.  
✔ Acceso restringido a servicios del backend.

---

# 🧠 Flujo del Servicio (Resumen)

1. **Verifica la fecha actual.**
    
    
    - Si el día del mes es menor a 26 → No corresponde validar renovaciones.
2. **Obtiene datos del empleado.**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> fecha_de_ingreso_real<span class="hljs-keyword">FROM</span> tabEmployee<span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span> = {empleado}`</div></div>
3. **Determina si el empleado aplica para renovación:**
    
    
    - Debe haber ingresado **antes del último día del mes anterior**.
4. **Busca renovaciones validadas del empleado:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">FROM</span> tabSolicitud de Renovaciones doc<span class="hljs-keyword">JOIN</span> tabTrabajadores pendiete de renovar tab<span class="hljs-keyword">WHERE</span>  doc.data_12 <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>mes_actual_texto<span class="hljs-operator">></span>  <span class="hljs-keyword">AND</span> doc.año <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>año<span class="hljs-operator">></span>  <span class="hljs-keyword">AND</span> tab.codigo <span class="hljs-operator">=</span> empleado  <span class="hljs-keyword">AND</span> tab.renueva <span class="hljs-operator">=</span> "Si"  <span class="hljs-keyword">AND</span> doc.estado_de_documento <span class="hljs-operator">=</span> "Validado"`</div></div>
5. **Si existe una renovación validada:**
    
    
    - Consulta MySQL2 → tabla `historial_procesos_app`
    - Revisa si el usuario **ya descargó su renovación**:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">proceso</span> = <span class="hljs-string">"descargaContratoRenovacion"</span>`</div></div>
6. **Si no la descargó → bloquea ciertas funciones.**
7. **Si todo está conforme → indica que la renovación fue descargada.**

---

# 📥 Request

### Parámetro de ruta

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2425" data-start="2277"><thead data-end="2321" data-start="2277"><tr data-end="2321" data-start="2277"><th data-col-size="sm" data-end="2285" data-start="2277">Campo</th><th data-col-size="sm" data-end="2292" data-start="2285">Tipo</th><th data-col-size="sm" data-end="2306" data-start="2292">Obligatorio</th><th data-col-size="sm" data-end="2321" data-start="2306">Descripción</th></tr></thead><tbody data-end="2425" data-start="2367"><tr data-end="2425" data-start="2367"><td data-col-size="sm" data-end="2378" data-start="2367">empleado</td><td data-col-size="sm" data-end="2387" data-start="2378">string</td><td data-col-size="sm" data-end="2391" data-start="2387">✔</td><td data-col-size="sm" data-end="2425" data-start="2391">ID del Employee dentro del ERP</td></tr></tbody></table>

</div></div>No tiene body.

---

# 📤 Response 200 – Ejemplos

### ✔ Caso 1 — No es día de validación

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No es el día correcto para la renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Caso 2 — Debe descargar renovación (bloqueo)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Caso 3 — Renovación descargada correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Caso 4 — Error controlado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles errores

<div class="_tableContainer_1rjym_1" id="bkmrk-c%C3%B3digo-significado-s"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3376" data-start="3095"><thead data-end="3119" data-start="3095"><tr data-end="3119" data-start="3095"><th data-col-size="sm" data-end="3104" data-start="3095">Código</th><th data-col-size="md" data-end="3119" data-start="3104">Significado</th></tr></thead><tbody data-end="3376" data-start="3145"><tr data-end="3219" data-start="3145"><td data-col-size="sm" data-end="3160" data-start="3145">status:false</td><td data-col-size="md" data-end="3219" data-start="3160">El empleado tiene renovación pendiente y no la descargó</td></tr><tr data-end="3287" data-start="3220"><td data-col-size="sm" data-end="3234" data-start="3220">status:true</td><td data-col-size="md" data-end="3287" data-start="3234">No aplica validación o ya cumplió con la descarga</td></tr><tr data-end="3376" data-start="3288"><td data-col-size="sm" data-end="3300" data-start="3288">Excepción</td><td data-col-size="md" data-end="3376" data-start="3300">Se devuelve un mensaje genérico indicando que el contrato fue descargado</td></tr></tbody></table>

</div></div>---

# 📚 Tablas / Datos utilizados

### ERP - `tabEmployee`

Campos usados:

- `fecha_de_ingreso_real`

### ERP - `tabSolicitud de Renovaciones`

Campos usados:

- `data_12`
- `año`
- `estado_de_documento`

### ERP - `tabTrabajadores pendiete de renovar`

Campos usados:

- `codigo`
- `renueva`

### MySQL2 - tabla `historial_procesos_app`

Procesos revisados:

- `descargaContratoRenovacion`

---

# 🗃 Lógica en Pseudo-Código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-day%28today%29-%3C-26%3A-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-keyword">if</span> day(today) < <span class="hljs-number">26</span>:    <span class="hljs-keyword">return</span> OK(<span class="hljs-string">"No es el día correcto"</span>)empleado = queryERP(Employee <span class="hljs-keyword">where</span> name=empleado)<span class="hljs-keyword">if</span> empleado.ingreso < ultimo_dia_mes_anterior:    renov = queryERP(Solicitud de Renovaciones <span class="hljs-keyword">where</span>         codigo=empleado AND renueva=<span class="hljs-string">"Si"</span> AND estado=<span class="hljs-string">"Validado"</span>    )    <span class="hljs-keyword">if</span> renov exists:        registro = queryMySQL(historial_procesos <span class="hljs-keyword">where</span> proceso=<span class="hljs-string">"descargaContratoRenovacion"</span>)        <span class="hljs-keyword">if</span> registro vacío:            <span class="hljs-keyword">return</span> ERROR(<span class="hljs-string">"Debe descargar la renovación"</span>)<span class="hljs-keyword">return</span> OK(<span class="hljs-string">"Se ha descargado el contrato de trabajo"</span>)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Lista de Asistencias (1) - [getMarkingsApp]

## 🧾 Descripción

*Este servicio obtiene y consolida **todas las asistencias** de un empleado en un mes específico, calculando:*

- Porcentaje de asistencia del mes.
- Total de días asistidos.
- Permisos.
- Faltas.
- Feriados.
- Días de descanso.
- Marcaciones incompletas.
- Fechas únicas de asistencia.

Además, toma en cuenta:

- Fecha de ingreso del trabajador (para no contar días previos como faltas).
- Domingos y feriados declarados en *holidays.json*.
- Validación de límites según el mes actual.

*Es un endpoint fundamental para el módulo de **Control de Asistencias** dentro del aplicativo.*

---

# 🚀 Endpoint

### **POST /get-markings-app**

📥 Requiere parámetros obligatorios en el body:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"02"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fechaIngreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-10-15"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🔐 Seguridad

Requiere autenticación interna del sistema ERP mediante:

- `dbErp()` para consultas SQL internas.
- Acceso a archivo local `/public/recursos_humanos/holidays.json`.

---

# 🧠 Flujo del Servicio (resumen real)

1. **Recibe parámetros del empleado y mes a consultar.**
    
    employee, month, anio, fechaIngreso
2. **Calcula rango real del mes a evaluar**, tomando en cuenta:
    
    
    - Si es el mes actual.
    - Si el empleado ingresó después del día 1.
    - Días previos al ingreso del trabajador.
3. **Carga feriados y domingos del archivo JSON:**
    
    `/public/recursos_humanos/holidays.json`
4. **Determina cuántos días del mes son feriados o domingos dentro del rango permitido.**
5. **Valida campos obligatorios.**
6. **Consulta en el ERP todas las asistencias del empleado en el mes:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-from-tabattendance-w"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">FROM</span> tabAttendance<span class="hljs-keyword">WHERE</span> employee <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>empleado<span class="hljs-operator">></span><span class="hljs-keyword">AND</span> attendance_date <span class="hljs-keyword">BETWEEN</span> <span class="hljs-number">1</span> y último día del mes<span class="hljs-keyword">AND</span> status <span class="hljs-keyword">IN</span> (<span class="hljs-string">'Present'</span>,<span class="hljs-string">'Marcacion Incompleta'</span>,<span class="hljs-string">'On Leave'</span>,<span class="hljs-string">'Absent'</span>,<span class="hljs-string">'Día de Descanso'</span>,<span class="hljs-string">'Feriado'</span>)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>7. **Recorre todas las asistencias y clasifica:**
    
    
    - Present → Suma asistencia
    - On Leave → Permisos
    - Absent → Faltas
    - Feriado → Feriados
    - Día de Descanso → Descansos
    - Marcacion Incompleta → Marcaciones incompletas
8. **Calcula porcentaje de asistencia**, considerando:
    
    
    - Días previos al ingreso.
    - Si el mes es el actual → hasta el día de hoy.
    - Casos especiales de permisos dominicales.
9. **Construye respuesta final con totales y fechas.**

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"03"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fechaIngreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-10-10"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>📌 **Todos son obligatorios.**

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LISTA DE ASISTENCIAS"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"porcentage"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"92.55"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_aistidos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"25"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_totales"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"27"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"permisos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"faltas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"marcacion_incompleta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fechas_asistidas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"2025-03-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"2025-03-02"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"2025-03-03"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"feriados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"descansos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"4"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_permisos"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"2025-03-08"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_tardanzas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"2025-03-15"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_faltas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_feriados"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"2025-03-29"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_descansos"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"2025-03-02"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"2025-03-09"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Faltan parámetros obligatorios

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Complete todos los campos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. No existe asistencia registrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LISTA DE ASISTENCIAS"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"porcentage"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_asistidos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dias_totales"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    ...  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. Error interno inesperado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error inesperado en el servicio"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Estructuras usadas

### **Attendance (tabAttendance)**

Campos consultados:

- `attendance_date`
- `status`
- `horas_trabajadas`
- `horas_extras`
- `name`

### **Archivo holidays.json**

Estructura:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22sunday%22%3A-%5B%222025-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"Sunday"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"2025-03-02"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"2025-03-09"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Holidays"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"2025-03-29"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🧩 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-input%3A-employee%2C-mon"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`input: employee, month, anio, fechaIngresovalidar campos requeridoscalcular fecha_inicio y fecha_fin según:    - mes actual    - fecha de ingreso del empleadocargar feriados y domingos (holidays.json)contar días dentro del rangoconsultar asistencias en ERP:    SELECT attendance_date, status    FROM tabAttendance    WHERE employee = employee    AND status IN (...)inicializar contadoresforeach asistencia in resultado:    clasificar según status    acumular días, permisos, faltas, descansos, feriadoscalcular porcentaje de asistenciareturn {    valor: true,    data: {...}}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Modulo de Asistencia y Marcaciones (Horas Extras)

# Obtiene descarga boleta de pago (3) - [getDownloadBoletaPago]

🧾 **Descripción**

*Valida si un empleado **debe descargar su boleta de pago del mes anterior** antes de poder registrar marcaciones o realizar solicitudes en el sistema.*  
*La validación se aplica únicamente dentro de un periodo permitido (del día 1 al 3 del mes).*

Este servicio combina datos entre:

- `Employee` (ERP)
- `Salary Slip` (Boleta de pago, ERP)
- `Estado Boleta Mensual` (ERP)
- `historial_procesos_app` (Base MySQL interna)

Permite determinar si el usuario:

- No debe validar nada.
- No tiene boleta para ese mes.
- Tiene boleta habilitada y aún **no la descargó** → Debe descargarla.
- Ya descargó → Se libera el acceso.

---

# 🚀 Endpoint

**<span style="color: rgb(224, 62, 45);">POST /get-download-boleta-pago</span>**

### 📥 Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1138" data-start="992"><thead data-end="1034" data-start="992"><tr data-end="1034" data-start="992"><th data-col-size="sm" data-end="1000" data-start="992">Campo</th><th data-col-size="sm" data-end="1007" data-start="1000">Tipo</th><th data-col-size="sm" data-end="1019" data-start="1007">Requerido</th><th data-col-size="sm" data-end="1034" data-start="1019">Descripción</th></tr></thead><tbody data-end="1138" data-start="1078"><tr data-end="1138" data-start="1078"><td data-col-size="sm" data-end="1089" data-start="1078">empleado</td><td data-col-size="sm" data-end="1098" data-start="1089">string</td><td data-col-size="sm" data-end="1103" data-start="1098">Sí</td><td data-col-size="sm" data-end="1138" data-start="1103">ID del empleado (Employee.name)</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

**El servicio requiere:**

- Acceso API válido al ERP (vía `dbErp()`).
- Acceso a la base interna MySQL (`mysql2`).

---

# 🧠 Flujo del Servicio (resumen real)

### 1️⃣ Verifica si está dentro del rango permitido

- Solo valida del **día 1 al 3**.
- Si el día es mayor a 3 → no valida nada.

### 2️⃣ Obtiene datos del empleado

Consulta:

<table border="1" id="bkmrk-get-tabemployee-fiel" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET <span class="hljs-type">tabEmployee</span><span class="hljs-variable">fields</span> <span class="hljs-operator">=</span> [<span class="hljs-string">"fecha_de_ingreso_real"</span>, <span class="hljs-string">"status"</span>]`</td></tr></tbody></table>

Si el empleado está **PreActivo**, no se valida boleta.

### 3️⃣ Determina el mes anterior

**Se calcula:**

- Primer día del mes anterior
- Último día del mes anterior

Se verifica que el empleado haya ingresado antes del fin del mes anterior.

### 4️⃣ Verifica si existe boleta del mes anterior

Consulta a ERP:

<table border="1" id="bkmrk-tabsalary-slip-where" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`tabSalary Slip<span class="hljs-keyword">WHERE</span> employee <span class="hljs-operator">=</span> empleado<span class="hljs-keyword">AND</span> posting_date <span class="hljs-keyword">BETWEEN</span> primer_día_mes_pasado <span class="hljs-keyword">AND</span> último_día_mes_pasado`</td></tr></tbody></table>

Si **no tiene boleta**, no se valida nada.

### 5️⃣ Valida si el mes está habilitado para descarga

Consulta:

<table border="1" id="bkmrk-tabestado-boleta-men" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`tabEstado Boleta Mensual<span class="hljs-type">WHERE</span> <span class="hljs-variable">mes</span> <span class="hljs-operator">=</span> <mes anterior en texto><span class="hljs-type">AND</span> <span class="hljs-variable">año</span> <span class="hljs-operator">=</span> <año><span class="hljs-type">AND</span> <span class="hljs-variable">habilitado</span> <span class="hljs-operator">=</span> <span class="hljs-number">1</span>`</td></tr></tbody></table>

### 6️⃣ Consulta si el usuario ya descargó la boleta

Busca en MySQL:

<table border="1" id="bkmrk-historial_procesos_a" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`historial_procesos_app<span class="hljs-type">WHERE</span> <span class="hljs-variable">empleado</span> <span class="hljs-operator">=</span> empleado<span class="hljs-type">AND</span> <span class="hljs-variable">proceso</span> <span class="hljs-operator">=</span> <span class="hljs-string">'NOMINA'</span><span class="hljs-type">AND</span> <span class="hljs-variable">month</span> <span class="hljs-operator">=</span> mes<span class="hljs-type">AND</span> <span class="hljs-variable">year</span> <span class="hljs-operator">=</span> año`</td></tr></tbody></table>

Si **no existe descarga previa** y el mes está habilitado → debe descargar.

---

# 📤 Respuestas Posibles

### ✔️ 1. No está en rango de validación

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No está dentro del rango de fecha de validación"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ✔️ 2. Empleado PreActivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No validar descarga de boleta en PreActivo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ✔️ 3. No tiene boleta del mes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No tiene boleta de pago por lo tanto no se valida"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ 4. Debe descargar la boleta (regla principal)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su boleta pendiente del mes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ✔️ 5. Ya descargó la boleta

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado la boleta de pago"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ✔️ 6. Error controlado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Tablas y esquemas usados

### 🔹 Employee (ERP)

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-fecha_de_ingreso_rea"><div class="overflow-y-auto p-4" dir="ltr">`fecha_de_ingreso_real<span class="hljs-built_in">status</span>`</div></div>### 🔹 Salary Slip (ERP)

Campo utilizado: `<span class="hljs-attribute">posting_date</span>`

### 🔹 Estado Boleta Mensual (ERP)

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-mes-a%C3%B1o-habilitado"><div class="overflow-y-auto p-4" dir="ltr">`mes<span class="hljs-selector-tag">a</span>ñohabilitado`</div></div>### 🔹 historial\_procesos\_app (MySQL)

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-empleado-proceso-mon"><div class="overflow-y-auto p-4" dir="ltr">`empleadoproceso<span class="hljs-keyword">month</span><span class="hljs-keyword">year</span>`</div></div>---

# 🗃 Lógica en pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-dia-%3E-3%3A-return-o"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if dia > 3:    return OKempleado = GET Employee[name]if empleado.status == PreActivo:    return OKfecha_ingreso < fin_mes_anterior ?if no tiene SalarySlip en mes anterior:    return OKmes_habilitado = GET EstadoBoletaMensual[mes,año]descarga = buscar en historial_procesos_appif mes_habilitado AND no descarga:    return OBLIGAR DESCARGAreturn OK`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Obtiene descarga Renovación de contrato (3) - [getRenovacionContrato]

🧾 **Descripción**

*Valida si un empleado debe **descargar la renovación de contrato** antes de poder registrar marcaciones o realizar solicitudes dentro del aplicativo.*

El servicio evalúa:

- La fecha actual (solo aplica desde el día **26 de cada mes**).
- La fecha de ingreso del empleado.
- Si el empleado tiene un proceso de renovación registrado y validado en ERP.
- Si ya existe un registro de descarga previo en `historial_procesos_app`.

*Este servicio actúa como una **regla de negocio obligatoria** para habilitar o bloquear el uso del aplicativo.*

---

# 🚀 Endpoint

**<span style="color: rgb(224, 62, 45);">POST /get-renovacion-contrato</span>**

📌 Recibe un único parámetro:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

- Requiere credenciales autorizadas para consumir la API del ERP.
- Utiliza internamente `dbErp()` para ejecutar consultas SQL seguras contra ERPNext.
- Accede a `mysql2` para verificar registros de descargas.

---

# 🧠 Flujo del Servicio (Resumen Real)

### 1️⃣ Validación inicial por fecha

- Solo permite validar renovación desde el **día 26** del mes.  
    Si es antes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No es el día correcto para la renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 2️⃣ Obtener fecha real de ingreso del empleado

Consulta al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-fecha_de_ingr"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> fecha_de_ingreso_real<span class="hljs-keyword">FROM</span> `tabEmployee`<span class="hljs-keyword">WHERE</span> name <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>empleado<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no existe → el servicio simplemente finaliza sin error.

---

### 3️⃣ Determinar si el empleado ya debería tener renovación

- Calcula el último día del **mes anterior**.
- Si el ingreso es anterior a ese período, el empleado califica para renovación.

---

### 4️⃣ Consultar renovación en ERP (contratos validados)

Busca registros de:

- Mes actual (en texto: Enero, Febrero…)
- Año del mes previo
- Código del empleado
- `renueva = Si`
- `estado_de_documento = Validado`

Consulta ejecutada:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-doc.name-from"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> doc.name<span class="hljs-keyword">FROM</span> `tabSolicitud de Renovaciones` doc<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> `tabTrabajadores pendiete de renovar` tab <span class="hljs-keyword">ON</span> doc.name <span class="hljs-operator">=</span> tab.parent<span class="hljs-keyword">WHERE</span>     doc.data_12 <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>mes_actual_texto<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span>    doc.año <span class="hljs-operator">=</span> <span class="hljs-operator"><</span><span class="hljs-keyword">year</span><span class="hljs-operator">></span> <span class="hljs-keyword">AND</span>    tab.codigo <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>empleado<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span>    tab.renueva <span class="hljs-operator">=</span> <span class="hljs-string">'Si'</span> <span class="hljs-keyword">AND</span>    doc.estado_de_documento <span class="hljs-operator">=</span> <span class="hljs-string">'Validado'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 5️⃣ Validar si el empleado YA descargó la renovación

Consulta en base de datos interna:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-historial_procesos_a"><div class="overflow-y-auto p-4" dir="ltr">`historial_procesos_app<span class="hljs-type">WHERE</span> <span class="hljs-variable">proceso</span> <span class="hljs-operator">=</span> <span class="hljs-string">'descargaContratoRenovacion'</span>  <span class="hljs-type">AND</span> <span class="hljs-variable">empleado</span> <span class="hljs-operator">=</span> <empleado>`</div></div>- Si **NO la descargó** → Bloquea acciones del app:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 6️⃣ Si todo está correcto

Retorna éxito:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 Response 200 – Ejemplos

### ✔ Caso correcto (ya descargó renovación)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se ha descargado el contrato de trabajo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Debe descargar renovación antes de usar el app

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Para poder registrar su marcación o realizar alguna solicitud, descargar su renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ Aún no es día válido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No es el día correcto para la renovación de contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

<div class="_tableContainer_1rjym_1" id="bkmrk-error-respuesta-d%C3%ADa-"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3937" data-start="3547"><thead data-end="3568" data-start="3547"><tr data-end="3568" data-start="3547"><th data-col-size="sm" data-end="3555" data-start="3547">Error</th><th data-col-size="md" data-end="3568" data-start="3555">Respuesta</th></tr></thead><tbody data-end="3937" data-start="3590"><tr data-end="3683" data-start="3590"><td data-col-size="sm" data-end="3623" data-start="3590">Día inválido para la operación</td><td data-col-size="md" data-end="3683" data-start="3623">`"No es el día correcto para la renovación de contrato"`</td></tr><tr data-end="3763" data-start="3684"><td data-col-size="sm" data-end="3719" data-start="3684">Empleado sin renovación validada</td><td data-col-size="md" data-end="3763" data-start="3719">`"Para poder registrar su marcación..."`</td></tr><tr data-end="3859" data-start="3764"><td data-col-size="sm" data-end="3796" data-start="3764">Error inesperado en ejecución</td><td data-col-size="md" data-end="3859" data-start="3796">Se devuelve mensaje genérico, pero siempre con status: true</td></tr><tr data-end="3937" data-start="3860"><td data-col-size="sm" data-end="3884" data-start="3860">No existe el empleado</td><td data-col-size="md" data-end="3937" data-start="3884">El flujo simplemente finaliza sin error explícito</td></tr></tbody></table>

</div></div>---

# 📚 Consultas y estructuras usadas

### ✔ ERP — Employee

Campos consultados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22fecha_de_ingreso_"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"fecha_de_ingreso_real"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ✔ ERP — Solicitud de Renovaciones

Consulta combinada mediante JOIN:

- `data_12` (mes)
- `año`
- `codigo`
- `renueva`
- `estado_de_documento`

### ✔ Base interna MySQL (mysql2)

Tabla: `<span class="hljs-attribute">historial_procesos_app</span>`

Campo crítico: `<span class="hljs-attr">proceso</span> = <span class="hljs-string">'descargaContratoRenovacion'</span>`

---

# 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%28dia_actual-%3C-26%29"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span> (dia_actual < <span class="hljs-number">26</span>)    <span class="hljs-keyword">return</span> <span class="hljs-string">"No es el día correcto"</span>empleado = GET fecha_ingreso_real FROM Employee<span class="hljs-keyword">if</span> fecha_ingreso < ultimo_dia_mes_anterior:    renovacion = GET renovacion_validada FROM SolicitudRenovaciones    <span class="hljs-keyword">if</span> renovacion existe:        descarga = buscar en historial_procesos_app        <span class="hljs-keyword">if</span> no hay descarga:            <span class="hljs-keyword">return</span> <span class="hljs-string">"Debe descargar renovación"</span><span class="hljs-keyword">return</span> <span class="hljs-string">"OK"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Horas Extras del Mes (1) - [getMarkingsForEmployeePerMonth2]

🧾 **Descripción**

Obtiene y calcula todas las **horas extras registradas** para un empleado en un mes específico, detallando:

- Horas al **25%**
- Horas al **35%**
- Horas al **100%** (domingos y feriados)
- Listado detallado por día
- Total acumulado del periodo de corte mensual

El servicio consulta información desde varios recursos del ERP:

- **Cortes (tabCortes)** → para determinar el rango mensual válido
- **Horas Extras (tabHoras Extras)** → totales por mes
- **Marcaciones (tabMarcaciones)** → registros por día
- Archivo local de feriados: `holidays.json`

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/get-markings-employee-month`**</span>

📥 **Parámetros en el body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"02"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

- Requiere token interno del ERP (autenticación manejada por <span style="color: rgb(224, 62, 45);">**`ServiceErp()`**</span>).
- Validación del request vía Laravel.

---

# 🧠 Flujo del Servicio (resumen real)

### 1️⃣ Obtiene el corte mensual

Consulta el recurso:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fresource%2Fcortes"><div class="overflow-y-auto p-4" dir="ltr"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> <span class="hljs-operator">/</span>resource<span class="hljs-operator">/</span>Cortesfilters: año <span class="hljs-operator">=</span> <span class="hljs-keyword">year</span>, mes <span class="hljs-operator">=</span> <span class="hljs-keyword">month</span>`</td></tr></tbody></table>

</div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no existe corte → retorna error `"No hay corte mensual para este mes"`.

---

### 2️⃣ Obtiene las horas extras acumuladas del mes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fresource%2Fhoras-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 68.1375px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 68.1375px;"><td style="height: 68.1375px;">`<span class="hljs-keyword">GET</span> /resource/Horas Extras<span class="hljs-symbol">fields:</span> [<span class="hljs-string">"hhee_al_25"</span>,<span class="hljs-string">"hhee_al_35"</span>,<span class="hljs-string">"hhee_al_100"</span>]<span class="hljs-symbol">filters:</span> año, mes, empleado`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3️⃣ Obtiene las marcaciones dentro del periodo del corte

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fresource%2Fmarcac"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> <span class="hljs-operator">/</span>resource<span class="hljs-operator">/</span>Marcacionesfilters:     user_id <span class="hljs-operator">=</span> employee    <span class="hljs-type">date</span> <span class="hljs-keyword">BETWEEN</span> corte.inicio <span class="hljs-keyword">AND</span> corte.fin    hours <span class="hljs-operator">!=</span> <span class="hljs-number">0</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no hay marcaciones → retorna mensaje informativo.

---

### 4️⃣ Carga feriados desde archivo local

`public/recursos_humanos/holidays.json`

Feriados + domingos se consideran jornada **al 100%**.

---

### 5️⃣ Procesa cada marcación

Por cada registro:

- Si es feriado/domingo → 100%
- Si horas ≤ 2 → 25%
- Si horas &gt; 2
    
    
    - primeras 2h → 25%
    - resto → 35%

Cada día se estructura como:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22fecha%22%3A-%2205-de-en"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"05 DE ENERO"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"porcentaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"35%"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"horas_completadas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"3H"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 6️⃣ Arma la respuesta final:

Incluye:

- `marcaciones`: detalle por día
- `horas25`, `horas35`, `horas100`: de la tabla Horas Extras
- `horas_acumuladas`: sumatoria real de horas del mes

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de horas extras generado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"marcaciones"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-punctuation">{</span>        <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"03 DE ENERO"</span><span class="hljs-punctuation">,</span>        <span class="hljs-attr">"porcentaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"25%"</span><span class="hljs-punctuation">,</span>        <span class="hljs-attr">"horas_completadas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2H"</span>      <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>      <span class="hljs-punctuation">{</span>        <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"03 DE ENERO"</span><span class="hljs-punctuation">,</span>        <span class="hljs-attr">"porcentaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"35%"</span><span class="hljs-punctuation">,</span>        <span class="hljs-attr">"horas_completadas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1H"</span>      <span class="hljs-punctuation">}</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas25"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas35"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"4"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas100"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas_acumuladas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"15"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Corte mensual no configurado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No hay corte mensual para este mes"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error al traer horas extras

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error, al obtener las horas extras"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Marcaciones vacías

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No hay horas extras registradas para este mes"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"marcaciones"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas25"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas35"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas100"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"horas_acumuladas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error en servicio del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error, al obtener las marcaciones."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas utilizados**

### **Cortes**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dia_inicio%22%3A-%22202"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dia_inicio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-01"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dia_final"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-31"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Horas Extras**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22hhee_al_25%22%3A-%2210%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"hhee_al_25"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"10"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"hhee_al_35"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"5"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"hhee_al_100"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Marcaciones**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22fecha%22%3A-%222025-01-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-03"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"horas"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-corte-%3D-get-cortes-w"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`corte = GET Cortes where año=year and mes=monthif corte empty → return errorhours = GET Horas Extras where año, mes, empleadomarkings = GET Marcaciones where user_id=employee and date between corteferiados = cargar holidays.jsonforeach marking:    if fecha in feriados → 100%    else if horas <= 2 → 25%    else:        agregar 2h al 25%        agregar horas-2 al 35%sumar horas acumuladasreturn {    marcaciones procesadas,    horas25, horas35, horas100,    horas_acumuladas}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Modulo Otros Descuentos

# Otros descuentos de Nomina (1, 2) - [listar]

🧾 **Descripción**

*Obtiene y lista los otros descuentos de nómina registrados para un empleado en un año y mes específicos.*  
*El servicio consulta la información en el ERP (Doctype: **Otros Descuentos Nomina**) y devuelve únicamente los registros que coinciden con el mes y año enviados.*

*Permite también filtrar por **todos los meses del año** enviando `"TODOS"` en el parámetro `month`.*

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/listar-descuentos`**</span>

---

# 📥 Parámetros (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marzo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Campos requeridos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1129" data-start="793"><thead data-end="845" data-start="793"><tr data-end="845" data-start="793"><th data-col-size="sm" data-end="807" data-start="793">Campo</th><th data-col-size="sm" data-end="816" data-start="807">Tipo</th><th data-col-size="sm" data-end="830" data-start="816">Obligatorio</th><th data-col-size="md" data-end="845" data-start="830">Descripción</th></tr></thead><tbody data-end="1129" data-start="899"><tr data-end="960" data-start="899"><td data-col-size="sm" data-end="913" data-start="899">employee</td><td data-col-size="sm" data-end="922" data-start="913">string</td><td data-col-size="sm" data-end="937" data-start="922">✔️ Sí</td><td data-col-size="md" data-end="960" data-start="937">Código del empleado</td></tr><tr data-end="1016" data-start="961"><td data-col-size="sm" data-end="975" data-start="961">year</td><td data-col-size="sm" data-end="984" data-start="975">string</td><td data-col-size="sm" data-end="999" data-start="984">✔️ Sí</td><td data-col-size="md" data-end="1016" data-start="999">Año a filtrar</td></tr><tr data-end="1129" data-start="1017"><td data-col-size="sm" data-end="1031" data-start="1017">month</td><td data-col-size="sm" data-end="1040" data-start="1031">string</td><td data-col-size="sm" data-end="1055" data-start="1040">✔️ Sí</td><td data-col-size="md" data-end="1129" data-start="1055">Mes a filtrar. Si se envía `"TODOS"` devuelve todos los meses del año.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere token válido del ERP.  
La comunicación se realiza mediante **ServiceErp()**, usando cabeceras internas de autenticación.

---

# 🧠 Flujo del Servicio (Resumen real)

1. **Valida que el parámetro employee exista.**
2. **Valida que el parámetro year exista.**
3. Consulta al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-otros-descuentos"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-variable constant_">GET</span> <span class="hljs-title class_">Otros</span> <span class="hljs-title class_">Descuentos</span> <span class="hljs-title class_">Nomina</span>/<employee><span class="hljs-string">?f</span>ields=[<span class="hljs-string">"table_22"</span>]`</div></div>4. Verifica que exista información.
5. Recorre la tabla interna `table_22` (donde vienen los descuentos mensuales):
    
    
    - Compara:
        
        
        - `item.mes` == mes enviado
        - `item.ano` == año enviado
    - Si `month == "TODOS"`, ignora el filtro del mes.
6. Para cada coincidencia arma un objeto con:
    
    
    - motivo
    - monto
    - año
    - mes
    - creation (en formato `"d de Mes"`)
7. Si no hay coincidencias, retorna "Sin Descuentos".
8. Si hay registros, los devuelve ordenados por creación.

---

# 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Adelanto"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">150.00</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marzo"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"05 de Marzo"</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Descuento EPS"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">35.00</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marzo"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12 de Marzo"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ⚠️ Respuestas de Error

### 1. Falta employee

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta employee"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Falta año

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese un año"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. El ERP no devuelve información

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sin Descuentos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. No existen descuentos para el filtro solicitado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sin Descuentos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Estructuras usadas (Schemas)

### **Otros Descuentos Nomina**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22table_22%22%3A-%5B-%7B-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"table_22"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"float"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ano"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🧩 Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-employee-is-null-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`if employee <span class="hljs-keyword">is</span> <span class="hljs-keyword">null</span> → errorif <span class="hljs-keyword">year</span> <span class="hljs-keyword">is</span> <span class="hljs-keyword">null</span> → errorotros_desc <span class="hljs-operator">=</span> <span class="hljs-keyword">GET</span> Otros Descuentos Nomina<span class="hljs-operator">/</span>employeeif <span class="hljs-keyword">no</span> data → errorforeach item <span class="hljs-keyword">in</span> table_22:    if (mes <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">month</span> <span class="hljs-keyword">AND</span> ano <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">year</span>) <span class="hljs-keyword">OR</span> (<span class="hljs-keyword">month</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> "TODOS" <span class="hljs-keyword">AND</span> ano <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">year</span>):        agregar item a listaif lista vacía → error<span class="hljs-keyword">return</span> lista formateada`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Módulo Capacitación(Cursos)

# Matricula Estudiante (1) - [enrollStudent]

## 🧾 Descripción

*Este servicio **matricula automáticamente a un estudiante** en todos los programas de capacitación correspondientes a su **puesto actual (designation)**.*

El flujo toma como origen:

- **Student** (por DNI)
- **Program**
- **Course**
- **Program Enrollment**

*El servicio determina **qué cursos pertenecen al puesto del estudiante**, identifica **qué programas contienen esos cursos** y finalmente crea **matrículas individuales** para cada programa en el ERP.*

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/enroll-student`**</span>

---

# 📥 Parámetros (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dni%22%3A-%22string%22-%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="964" data-start="809"><thead data-end="853" data-start="809"><tr data-end="853" data-start="809"><th data-col-size="sm" data-end="817" data-start="809">Campo</th><th data-col-size="sm" data-end="824" data-start="817">Tipo</th><th data-col-size="sm" data-end="838" data-start="824">Obligatorio</th><th data-col-size="md" data-end="853" data-start="838">Descripción</th></tr></thead><tbody data-end="964" data-start="898"><tr data-end="964" data-start="898"><td data-col-size="sm" data-end="904" data-start="898">dni</td><td data-col-size="sm" data-end="913" data-start="904">string</td><td data-col-size="sm" data-end="918" data-start="913">Sí</td><td data-col-size="md" data-end="964" data-start="918">DNI del estudiante para buscarlo en el ERP</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere autenticación interna mediante:

- `dbErp()` para consultas SQL
- `ServiceErp()` para consumo REST de recursos del ERP

---

# 🧠 Flujo del Servicio (resumen)

### 1. Validar parámetro `dni`

Si no se envía DNI:  
→ retorna error inmediato.

---

### 2. Buscar al estudiante en `tabStudent`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-name%2C-puesto%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> name, puesto, joining_date<span class="hljs-keyword">FROM</span> tabStudent<span class="hljs-keyword">WHERE</span> dni <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>dni<span class="hljs-operator">></span><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> joining_date <span class="hljs-keyword">DESC</span>LIMIT <span class="hljs-number">1</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no existe:  
→ retorna *"no se encontró al estudiante"*.

---

### 3. Obtener todos los Programas del ERP

GET `/resource/Program?fields=["name"]&limit=None`

Por cada programa:

- Se consulta `/resource/Program/<program_name>`
- Se leen los cursos incluidos en ese programa
- Se construye el mapa:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curso-%E2%86%92-%5Bprogramas-d"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`curso → <span class="hljs-selector-attr">[programas donde aparece]</span>`</div></div>---

### 4. Obtener todos los Cursos del ERP

GET `/resource/Course?fields=["name"]`

Por cada curso:

- Se consulta `/resource/Course/<course_name>`
- Se revisan los `designation` asociados al curso
- Se construye el mapa:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-puesto-%E2%86%92-%5Bcursos-hab"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`puesto → <span class="hljs-selector-attr">[cursos habilitados para ese puesto]</span>`</div></div>---

### 5. Validar si el puesto del estudiante tiene cursos asignados

Si no tiene cursos asociados:  
→ retorna *"No se encontró programas para este puesto"*.

---

### 6. Determinar los programas finales

Para cada curso del puesto, buscar en qué programas aparece y construir la lista final:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-programas_finales-%3D-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">programas_finales</span> = unique(programas_permitidos)`</div></div>Si la lista queda vacía:  
→ no existen programas asignados a este puesto.

---

### 7. Registrar las matrículas (Program Enrollment)

Para cada programa identificado:

1. Validar si ya existe matrícula:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-program-enrollme"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET Program Enrollment?filters=<span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">[</span><span class="hljs-string">"student"</span><span class="hljs-punctuation">,</span><span class="hljs-string">"="</span><span class="hljs-punctuation">,</span><id_student><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">[</span><span class="hljs-string">"program"</span><span class="hljs-punctuation">,</span><span class="hljs-string">"="</span><span class="hljs-punctuation">,</span><program><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>2. Si **existe**, se almacena como encontrado.
3. Si **no existe**, se crea:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-program-enrollm"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST Program Enrollment<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"student"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<student_id>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"program"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<program>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"enrollment_date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<fecha_hoy>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"academic_year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<año>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"docstatus"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>El servicio separa:

- Matrículas creadas
- Matrículas ya existentes
- Errores durante el registro

---

# 📤 Respuesta 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de programas"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"PROG-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"PROG-005"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"enrollment"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ENR-0001"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ENR-0002"</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"errors"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Falta DNI

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta enviar \"student\""</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Estudiante no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"no se encontró al estudiante"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Puesto sin cursos asociados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se Encontró programas para este puesto"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error al registrar un enrollment

Se devuelve en `errors`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22errors%22%3A-%5B-%22mensa"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"errors"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"mensaje del error interno"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Esquemas usados en el ERP

### **Student**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"puesto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Program**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"courses"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"course"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Course**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Program Enrollment**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22student%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"student"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"program"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"enrollment_date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"academic_year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"docstatus"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🧩 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-dni-%3D-request.dni-if"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`dni = request.dniif empty(dni):    return errorstudent = query Student where dni=dni order by joining_date desc limit 1if not found:    return errordesignation = student.puestoprogramas = GET all programsmapProgramas = generar mapa curso → programascursos = GET all coursesmapCursos = generar mapa puesto → cursosif designation not in mapCursos:    return errorprogramas_final = programas donde cursos del puesto están incluidosforeach programa in programas_final:    if enrollment existe:        agregar a enrollments encontrados    else:        crear enrollment        agregar respuesta a enrollments`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Listar Cursos (1) - [listar]

### 🧾 Descripción

*Este servicio obtiene **todos los cursos asignados** a un empleado o estudiante, basándose en su **puesto** (designation / puesto académico).*

*El flujo evalúa primero si el DNI pertenece a un **Empleado**, y si no, valida si pertenece a un **Estudiante**.*  
*Con el puesto encontrado, se consultan los cursos vinculados y finalmente se retornan los detalles del curso desde `tabCourse`.*

El servicio interactúa con:

- `tabEmployee`
- `tabStudent`
- `tabPuesto Curso`
- `tabCourse`

---

# 🚀 Endpoint

**POST** `<span style="color: rgb(224, 62, 45);"><strong>/listar</strong></span>`

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dni%22%3A-%22string%22-%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1036" data-start="866"><thead data-end="910" data-start="866"><tr data-end="910" data-start="866"><th data-col-size="sm" data-end="874" data-start="866">Campo</th><th data-col-size="sm" data-end="881" data-start="874">Tipo</th><th data-col-size="sm" data-end="895" data-start="881">Obligatorio</th><th data-col-size="md" data-end="910" data-start="895">Descripción</th></tr></thead><tbody data-end="1036" data-start="956"><tr data-end="1036" data-start="956"><td data-col-size="sm" data-end="962" data-start="956">dni</td><td data-col-size="sm" data-end="971" data-start="962">string</td><td data-col-size="sm" data-end="975" data-start="971">✔</td><td data-col-size="md" data-end="1036" data-start="975">DNI del empleado o estudiante para identificar su puesto.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

- Requiere autenticación interna del ERP vía `dbErp()`.
- No requiere token externo del cliente.

---

# 🧠 Flujo del Servicio (Resumen real)

### 1. Buscar si el DNI pertenece a un **Empleado** activo

Consulta a: `<span class="hljs-attribute">tabEmployee</span>`

con filtros:

- passport\_number = DNI
- status = Active
- designation IS NOT NULL

Si se encuentra → extrae el `designation`.

---

### 2. Si no es empleado, verificar si es **Estudiante activo**

Consulta a: `<span class="hljs-attribute">tabStudent</span>`

con filtros:

- dni = DNI
- enabled = 1

Si se encuentra → extrae el campo `puesto`.

---

### 3. Si no existe puesto asignado

Retorna mensaje:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%22valor%22%3A-false-%22msn%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontro el puesto de empleado"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 4. Buscar cursos asignados al puesto

Consulta a: `<span class="hljs-attribute">tabPuesto</span> Curso`

filtrando por:

- designation = puestoEmpleado

Obtiene los `parent` → IDs de los cursos asignados.

---

### 5. Obtener información de los cursos

Consulta a: `<span class="hljs-attribute">tabCourse</span>`

Retorna campos:

- name
- hero\_image

---

### 6. Respuesta final

Se devuelve el listado de cursos con sus imágenes.

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CURS-001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"hero_image"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/curso_001.png"</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CURS-002"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"hero_image"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/curso_002.png"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. No existe empleado NI estudiante con ese DNI

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontro el puesto de empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 2. Puesto sin cursos configurados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Su usuario no tiene cursos asignados"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 3. Error al obtener datos del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al consultar datos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Tablas y Campos utilizados

### 🔸 **tabEmployee**

Campos:

- passport\_number
- designation
- status

### 🔸 **tabStudent**

Campos:

- dni
- enabled
- puesto

### 🔸 **tabPuesto Curso**

Campos:

- designation
- parent (ID del curso)

### 🔸 **tabCourse**

Campos:

- name
- hero\_image

---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-dni-%3D-request.dni-em"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`dni = request.dniemployee = GET tabEmployee            WHERE passport_number = dni            AND status = 'Active'if employee exists:    puesto = employee.designationelse:    student = GET tabStudent               WHERE dni = dni AND enabled = 1    if student exists:        puesto = student.puesto    else:        return error("No se encontro el puesto de empleado")cursosAsignados = GET tabPuesto Curso WHERE designation = puestoif cursosAsignados empty:    return error("Su usuario no tiene cursos asignados")idsCursos = cursosAsignados.parentsinfoCursos = GET tabCourse WHERE name IN idsCursosreturn infoCursos`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Cursos Temas (1, 2, 3, 4, 5, 6, 7) - CAPACITACIÓN ATC (II FASE) - [temas]

## 🧾 Descripción

*Obtiene los **temas (topics)** de un curso específico y calcula cuántos **videos** y **artículos** contiene cada tema.*

*Este servicio consulta:*

- La información completa del **Course**
- El detalle de cada **Topic**
- Cuenta los contenidos según su tipo: *Video* o *Article*

*Está diseñado para mostrar al usuario un resumen claro del material disponible por tema.*

---

## 🚀 Endpoint

**GET /temas**

### 📥 Parámetros (Request)

Se recibe un único valor desde el request:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22curso%22%3A-%22id_del_c"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"curso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ID_DEL_CURSO"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🔐 Seguridad

Este servicio requiere autenticación válida hacia el ERP mediante:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-serviceerp%28%22get%22%2C-.."><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">ServiceErp</span>("GET", ...)`</div></div>El token o cookies activos son manejados internamente por la clase `general`.

---

# 🧠 Flujo del Servicio (resumen real)

1. **Recibe el curso** por parámetro.
2. Consulta al ERP el recurso:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-resource%2Fcourse%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-type">GET</span> resource<span class="hljs-regexp">/Course/</span>{curso}`</div></div>3. Verifica que el curso exista; si no, devuelve error:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attribute">Su</span> usuario <span class="hljs-literal">no</span> tiene cursos asignados`</div></div>
4. Extrae la lista de **topics** del curso.
5. Para cada topic:
    
    
    - Inicializa sus contadores:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">videos</span> = <span class="hljs-number">0</span><span class="hljs-attr">articulos</span> = <span class="hljs-number">0</span>`</div></div>
    - Consulta el contenido del tópico:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-type">GET</span> resource<span class="hljs-regexp">/Topic/</span>{topic_id}`</div></div>
    - Recorre el contenido (`topic_content`):
        
        
        - Si `content_type == Video` → incrementa contador de videos
        - Si `content_type == Article` → incrementa contador de artículos
6. Retorna la lista de temas con sus conteos.

---

## 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"topic"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"TP-001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Introducción"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"videos"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"articulos"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"topic"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"TP-002"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Conceptos Básicos"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"videos"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"articulos"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## ❗ Posibles Errores

### 1. Curso no existe o no tiene permisos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Su usuario no tiene cursos asignados"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. El tópico no contiene información (se ignora sin romper el flujo)

No retorna error, simplemente no se contabiliza.

### 3. Fallo de conexión con ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al consultar datos del ERP"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 📚 Schemas Consultados

### **Course**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22topics%22%3A-%5B-%7B-%22top"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"topics"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"topic"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Topic**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22topic_content%22%3A-%5B"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"topic_content"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"content_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Video | Article"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curso-%3D-request.curs"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curso = request.cursocourseData = GET Course/{curso}if !courseData.exists:    return error("Su usuario no tiene cursos asignados")topics = courseData.topicsfor each topic in topics:    topic.videos = 0    topic.articulos = 0    topicContent = GET Topic/{topic.id}    for content in topicContent:        if content.type == "Video":            topic.videos++        if content.type == "Article":            topic.articulos++return topics`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Cursos Temas Contenido (1, 2, 3, 4, 5, 6, 7) - [temas_contenido]

## 🧾 Descripción

*Obtiene **todo el contenido asociado a un Tema de Capacitación**, enriqueciendo la información con:*

- URL del **video** (si el contenido es Video)
- Texto o enlace procesado del **artículo** (si el contenido es Article)
- Cantidad de intentos realizados en un **quiz** por un estudiante (si corresponde)

*El servicio puede opcionalmente recibir el **DNI del estudiante**, para verificar su progreso (intentos de quiz).*

*Este servicio integra información desde varios recursos del ERP:*

- **Topic**
- **Video**
- **Article**
- **Student**
- **Quiz Activity**

---

# 🚀 Endpoint

### **GET /temas-contenido**

📌 **Parámetros vía request:**

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-oblig"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1068" data-start="846"><thead data-end="894" data-start="846"><tr data-end="894" data-start="846"><th data-col-size="sm" data-end="858" data-start="846">Parámetro</th><th data-col-size="sm" data-end="865" data-start="858">Tipo</th><th data-col-size="sm" data-end="879" data-start="865">Obligatorio</th><th data-col-size="md" data-end="894" data-start="879">Descripción</th></tr></thead><tbody data-end="1068" data-start="943"><tr data-end="996" data-start="943"><td data-col-size="sm" data-end="950" data-start="943">tema</td><td data-col-size="sm" data-end="959" data-start="950">string</td><td data-col-size="sm" data-end="964" data-start="959">✔️</td><td data-col-size="md" data-end="996" data-start="964">Nombre del Topic a consultar</td></tr><tr data-end="1068" data-start="997"><td data-col-size="sm" data-end="1003" data-start="997">dni</td><td data-col-size="sm" data-end="1012" data-start="1003">string</td><td data-col-size="sm" data-end="1016" data-start="1012">❌</td><td data-col-size="md" data-end="1068" data-start="1016">DNI del estudiante para obtener intentos de quiz</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere autenticación interna vía:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Egeneral-%3Eserv"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-variable language_">$this</span>->general-><span class="hljs-title function_ invoke__">ServiceErp</span>(...)`</div></div>No necesita token del cliente, se usa credencial del backend.

---

# 🧠 Flujo del Servicio (Resumen real)

### 1️⃣ Si viene DNI → Obtener datos del estudiante

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-student-%3Flimit%3Dn"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Student?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>&fields=["name","puesto"]&filters=[["enabled","=",<span class="hljs-number">1</span>],["dni","like","%{dni}%"]]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Guarda `name` del estudiante si existe.

---

### 2️⃣ Obtener el tema solicitado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-topic%2F%7Btema%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">GET</span> Topic/{tema}`</div></div>Debe existir; si no, devuelve: `<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el tema del curso"</span> <span class="hljs-punctuation">}</span>`

---

### 3️⃣ Recorrer cada elemento de “topic\_content”

Para cada ítem:

#### **📽 Si es Video:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-video%2F%7Bcontent_i"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`GET <span class="hljs-selector-tag">Video</span>/{content_id}`</div></div>Agrega: `<span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<url del video>"</span>`

---

#### **📄 Si es Article:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-article%2F%7Bcontent"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`GET <span class="hljs-selector-tag">Article</span>/{content_id}`</div></div>- Se extrae contenido sin HTML (`strip_tags`)
- Si dentro del texto hay un link, se devuelve solo ese link
- Se agrega:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%22url%22%3A-%22%3Ctexto-proce"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<texto procesado o link>"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

#### **❓ Si es Quiz y hay estudiante:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-quiz-activity-%3Ff"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET Quiz Activity?filters=<span class="hljs-string">[["quiz","=",content_id],["student","=", estudiante]]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Agrega: `<span class="hljs-attr">"quiz_attempts"</span><span class="hljs-punctuation">:</span> <numero_de_intentos>`

Si no hay estudiante o no es quiz: `<span class="hljs-attr">"quiz_attempts"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>`

---

### 4️⃣ Retornar todos los contenidos enriquecidos

---

# 📥 Request Body (ejemplo)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22tema%22%3A-%22topic-001"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"tema"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"TOPIC-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"content_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Video"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"VID-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"https://erp/video1.mp4"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"quiz_attempts"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"content_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Article"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ART-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"https://articulo.com/content"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"quiz_attempts"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"content_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Quiz"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"QUIZ-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"quiz_attempts"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Tema no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el tema del curso"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Estudiante no existe (cuando se envía DNI)

No genera error, simplemente no agrega intentos de quiz.

### 3. Contenido sin URL o datos incompletos

El servicio ignora valores faltantes y continúa procesando.

### 4. Error del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<detalle>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Recursos / Esquemas usados

### **Topic**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22topic_content%22%3A-%5B"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"topic_content"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"content_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Video | Article | Quiz"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Video**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22url%22%3A-%22string%22-%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Article**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22content%22%3A-%22html%7Cs"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"html|string"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Student**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"puesto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Quiz Activity**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22quiz%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"quiz"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"student"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Pseudocódigo del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-dni%3A-estudiante-%3D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attr">if DNI:</span>    <span class="hljs-string">estudiante</span> <span class="hljs-string">=</span> <span class="hljs-string">GET</span> <span class="hljs-string">Student</span> <span class="hljs-string">by</span> <span class="hljs-string">DNI</span><span class="hljs-string">topic</span> <span class="hljs-string">=</span> <span class="hljs-string">GET</span> <span class="hljs-string">Topic/{tema}</span><span class="hljs-attr">foreach content in topic.topic_content:</span>    <span class="hljs-string">if</span> <span class="hljs-string">content_type</span> <span class="hljs-string">==</span> <span class="hljs-attr">Video:</span>        <span class="hljs-string">obtener</span> <span class="hljs-string">url</span> <span class="hljs-string">del</span> <span class="hljs-string">video</span>    <span class="hljs-string">if</span> <span class="hljs-string">content_type</span> <span class="hljs-string">==</span> <span class="hljs-attr">Article:</span>        <span class="hljs-string">obtener</span> <span class="hljs-string">contenido,</span> <span class="hljs-string">limpiar</span> <span class="hljs-string">html,</span> <span class="hljs-string">buscar</span> <span class="hljs-string">link</span>    <span class="hljs-string">if</span> <span class="hljs-string">content_type</span> <span class="hljs-string">==</span> <span class="hljs-attr">Quiz and estudiante existe:</span>        <span class="hljs-string">obtener</span> <span class="hljs-string">intentos</span> <span class="hljs-string">realizados</span><span class="hljs-string">return</span> <span class="hljs-string">lista</span> <span class="hljs-string">enriquecida</span> <span class="hljs-string">de</span> <span class="hljs-string">contenidos</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Examen del Curso (1, 2, 3) - EXAMEN ATC - Agregar contacto - [preguntas]

### 🧾 Descripción

*Obtiene todas las preguntas de un examen (Quiz) registrado en el ERP, junto con sus opciones, respuestas correctas y metadatos.*

El servicio se encarga de:

- Consultar el examen (*Quiz*) en la base ERP.
- Traer todas las preguntas asociadas.
- Traer todas las opciones de cada pregunta.
- Reorganizar los resultados del SQL (que vienen aplanados) en una estructura jerárquica:
    
    
    - **Pregunta**
        
        
        - **Opciones**
- Convertir el contenido HTML de la pregunta a texto plano.
- Detectar si la pregunta incluye una **imagen** embebida.
- Preparar la respuesta final en un formato limpio y listo para usar en la app.

---

# 🚀 Endpoint

**POST** `<span style="color: rgb(224, 62, 45);"><strong>/preguntas</strong></span>`

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22examen%22%3A-%22quiz-00"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"examen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"QUIZ-0001"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>**Parámetros**

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1209" data-start="1062"><thead data-end="1106" data-start="1062"><tr data-end="1106" data-start="1062"><th data-col-size="sm" data-end="1070" data-start="1062">Campo</th><th data-col-size="sm" data-end="1077" data-start="1070">Tipo</th><th data-col-size="sm" data-end="1091" data-start="1077">Obligatorio</th><th data-col-size="sm" data-end="1106" data-start="1091">Descripción</th></tr></thead><tbody data-end="1209" data-start="1151"><tr data-end="1209" data-start="1151"><td data-col-size="sm" data-end="1160" data-start="1151">examen</td><td data-col-size="sm" data-end="1169" data-start="1160">string</td><td data-col-size="sm" data-end="1174" data-start="1169">✔️</td><td data-col-size="sm" data-end="1209" data-start="1174">ID del cuestionario (Quiz.name)</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Este servicio requiere acceso a la API interna del ERP a través de:

- `dbErp()` → Consulta SQL interna  
    No usa token del usuario final. La autenticación es interna del servidor.

---

# 🧠 Flujo del Servicio (Explicación Real)

### 1. Construye consulta SQL

El servicio arma un query que une:

- `tabQuiz`
- `tabQuiz Question`
- `tabQuestion`
- `tabOptions`

De esta manera obtiene:

- Datos de la **pregunta**
- Datos de **cada opción**
- Datos del examen

### 2. Envía la consulta

Se ejecuta: `POST <span class="hljs-keyword">method</span>/send-query-<span class="hljs-keyword">database</span>`

### 3. Reorganiza la data

El ERP devuelve una fila por cada opción.  
El servicio agrupa todo por: `question.name`

Generando esta estructura:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%7B-question%3A-%22...%22%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`[  {    <span class="hljs-attr">question:</span> <span class="hljs-string">"..."</span>,    <span class="hljs-attr">question_link:</span> <span class="hljs-string">"..."</span>,    <span class="hljs-attr">options:</span> [      { <span class="hljs-attr">option:</span> <span class="hljs-string">"..."</span>, <span class="hljs-attr">is_correct:</span> <span class="hljs-number">0</span><span class="hljs-string">/1</span> }    ]  }]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. Convierte HTML → texto

Las preguntas vienen como HTML.  
El servicio:

- Analiza el HTML con `html_to_obj()`
- Extrae texto plano (`strip_tags`)
- Busca imágenes incrustadas y genera la URL completa.

### 5. Construye la respuesta final

Para cada pregunta:

- `name`
- `question` (texto plano)
- `imagen` (si existe)
- `options` (lista de alternativas)

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PREG-001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"owner"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"admin@example"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"modified"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"modified_by"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"admin@example"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"idx"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"docstatus"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"question"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"¿Cuál es la capital de Francia?"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"question_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Opciones"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"question_link"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PREG-001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"options"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>        <span class="hljs-punctuation">{</span>          <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"OPT-001"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"option"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Madrid"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"is_correct"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"doctype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Options"</span>        <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>        <span class="hljs-punctuation">{</span>          <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"OPT-002"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"option"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"París"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"is_correct"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"doctype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Options"</span>        <span class="hljs-punctuation">}</span>      <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"imagen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Examen no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No existe información del examen"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Error en consulta SQL

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al obtener preguntas"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje_de_error>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. Examen sin preguntas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Schemas Usados

### 🔸 Quiz

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-name-stri"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3596" data-start="3545"><thead data-end="3561" data-start="3545"><tr data-end="3561" data-start="3545"><th data-col-size="sm" data-end="3553" data-start="3545">Campo</th><th data-col-size="sm" data-end="3561" data-start="3553">Tipo</th></tr></thead><tbody data-end="3596" data-start="3579"><tr data-end="3596" data-start="3579"><td data-col-size="sm" data-end="3586" data-start="3579">name</td><td data-col-size="sm" data-end="3596" data-start="3586">string</td></tr></tbody></table>

</div></div>---

### 🔸 Question

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-name-stri-1"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3717" data-start="3619"><thead data-end="3635" data-start="3619"><tr data-end="3635" data-start="3619"><th data-col-size="sm" data-end="3627" data-start="3619">Campo</th><th data-col-size="sm" data-end="3635" data-start="3627">Tipo</th></tr></thead><tbody data-end="3717" data-start="3653"><tr data-end="3670" data-start="3653"><td data-col-size="sm" data-end="3660" data-start="3653">name</td><td data-col-size="sm" data-end="3670" data-start="3660">string</td></tr><tr data-end="3690" data-start="3671"><td data-col-size="sm" data-end="3682" data-start="3671">question</td><td data-col-size="sm" data-end="3690" data-start="3682">HTML</td></tr><tr data-end="3717" data-start="3691"><td data-col-size="sm" data-end="3707" data-start="3691">question\_type</td><td data-col-size="sm" data-end="3717" data-start="3707">string</td></tr></tbody></table>

</div></div>---

### 🔸 Options

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-name-stri-2"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3866" data-start="3739"><thead data-end="3755" data-start="3739"><tr data-end="3755" data-start="3739"><th data-col-size="sm" data-end="3747" data-start="3739">Campo</th><th data-col-size="sm" data-end="3755" data-start="3747">Tipo</th></tr></thead><tbody data-end="3866" data-start="3773"><tr data-end="3790" data-start="3773"><td data-col-size="sm" data-end="3780" data-start="3773">name</td><td data-col-size="sm" data-end="3790" data-start="3780">string</td></tr><tr data-end="3810" data-start="3791"><td data-col-size="sm" data-end="3800" data-start="3791">option</td><td data-col-size="sm" data-end="3810" data-start="3800">string</td></tr><tr data-end="3839" data-start="3811"><td data-col-size="sm" data-end="3824" data-start="3811">is\_correct</td><td data-col-size="sm" data-end="3839" data-start="3824">int (0 o 1)</td></tr><tr data-end="3866" data-start="3840"><td data-col-size="sm" data-end="3849" data-start="3840">parent</td><td data-col-size="sm" data-end="3866" data-start="3849">question.name</td></tr></tbody></table>

</div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-examen-%3D-request.exa"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`examen = request.examenrows = SQL:    SELECT preguntas + opciones    FROM Quiz JOIN Quiz Question JOIN Question JOIN Options    WHERE qz.name = examengrouped = <span class="hljs-title function_ invoke__">reorganizarPorPregunta</span>(rows)<span class="hljs-keyword">foreach</span> pregunta in grouped:    procesar HTML    extraer texto e imagen<span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">JSON</span>(valor=<span class="hljs-literal">true</span>, data=preguntasProcesadas)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Evaluar Examen del Curso (1, 2, 3) - EXAMEN ATC - Agregar contacto - [guardar_examen_old]

## 🧾 Descripción

*Este servicio registra las respuestas de un examen enviado por un estudiante.*

La función:

1. **Recibe** el DNI del estudiante, el identificador del examen y las respuestas.
2. **Valida** que el estudiante exista en el ERP.
3. **Obtiene** la definición completa del examen (Quiz) desde el ERP.
4. **Obtiene** la información detallada de cada pregunta usando los `question_link`.
5. **Devuelve** el listado de preguntas del examen, incluyendo su estructura completa.

⚠ **Importante:**  
Este servicio *no guarda las respuestas* del examen.  
Solo valida al estudiante y retorna las preguntas del examen consultado.

---

# 🚀 Endpoint

**POST /guardar-examen-old**

---

# 📥 Request Body (JSON)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dni%22%3A-%22string%22%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"examen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"respuestas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json_string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Ejemplo:

<table border="1" id="bkmrk-%7B-%22dni%22%3A-%2212345678%22%2C" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"examen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"QUIZ-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"respuestas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"{\"P1\":\"A\",\"P2\":\"C\"}"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--2"><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🔐 Seguridad

- Requiere autenticación ERP (a través de `ServiceErp()` ).
- No utiliza tokens externos.

---

# 🧠 Flujo del Servicio (Explicación detallada)

1. **Recibe datos del request:**
    
    
    - `$dni`
    - `$examen`
    - `$respuestas` (JSON string → array)
2. **Decodifica las respuestas del examen:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-variable">$respuestas</span> = <span class="hljs-title function_ invoke__">json_decode</span>(<span class="hljs-variable">$respuestas</span>, <span class="hljs-literal">true</span>);`</div></div>
3. **Busca al estudiante por DNI (solo estudiantes habilitados):**
    
    GET Student  
    `filters=[["Student","enabled","=",1],["Student","dni","like","%<dni>%"]]`
    
    
    - Si no encuentra coincidencias → ❌ devuelve error:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Su usuario no tiene cursos asignados"</span> <span class="hljs-punctuation">}</span>`</div></div>
4. **Obtiene la definición del examen (Quiz) desde el ERP:**
    
    GET Quiz/&lt;examen&gt;
    
    
    - Trae todas las preguntas vinculadas.
5. **Por cada pregunta del examen:**
    
    
    - Consulta la API:  
        GET Question/{question\_link}
    - Agrega la información completa al arreglo final.
6. **Devuelve todas las preguntas consultadas.**

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%7B-%22name%22%3A-%22questio"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">[</span>  <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"QUESTION-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"question"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"¿Cuál es la capital de Perú?"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"options"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-punctuation">{</span><span class="hljs-attr">"option"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lima"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"is_correct"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>      <span class="hljs-punctuation">{</span><span class="hljs-attr">"option"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Cusco"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"is_correct"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">}</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"QUESTION-002"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"question"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Seleccione la opción correcta..."</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"options"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span> ... <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Estudiante no existe o no está habilitado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Su usuario no tiene cursos asignados"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Error consultando Quiz o Preguntas

(NOT IMPLEMENTED, pero puede ocurrir internamente)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al obtener examen"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. Respuestas mal formateadas

Si el JSON no es válido:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Formato inválido de respuestas"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>(Nota: El código actual **no valida** esto, pero debería.)

---

# 📚 Schemas usados

### Student (GET)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"enabled"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Quiz (GET)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"question"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"question_link"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"QUESTION-001"</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Question (GET)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"question"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"options"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"option"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"is_correct"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>|<span class="hljs-number">1</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-dni-%3D-request.dni-ex"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`dni = request.dniexamen = request.examenrespuestas = json_decode(request.respuestas)student = GET Student WHERE enabled=1 AND dni LIKE %dni%if student not found:    return errorquiz = GET Quiz/{examen}preguntas = []foreach link in quiz.question:    p = GET Question/{question_link}    preguntas.append(p)return preguntas`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Módulo Capacitación (Evaluaciones)

# Evaluaciones (1) - [serviceForNotesPerEmployee_old]

### 🧾 Descripción

*Servicio que consulta y consolida los **resultados de evaluaciones (exámenes)** rendidos por un empleado durante un mes específico.*

El servicio obtiene:

- Datos del empleado por su **email corporativo**.
- Los **exámenes asignados** según su puesto (`Designation`).
- Los **resultados obtenidos** en el mes solicitado (`Quiz Activity`).
- Devuelve un resumen con:
    
    
    - Lista de todos los exámenes esperados
    - Puntajes obtenidos
    - Estado (Pass / No Pass / No rindió)

> Esta es una versión antigua del servicio, mantenida por compatibilidad.

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/service-for-notes-employee-old`**</span>

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22email%22%3A-%22usuario%40"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"email"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"usuario@empresa.com"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-05-01"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1237" data-start="993"><thead data-end="1037" data-start="993"><tr data-end="1037" data-start="993"><th data-col-size="sm" data-end="1001" data-start="993">Campo</th><th data-col-size="sm" data-end="1008" data-start="1001">Tipo</th><th data-col-size="sm" data-end="1022" data-start="1008">Obligatorio</th><th data-col-size="md" data-end="1037" data-start="1022">Descripción</th></tr></thead><tbody data-end="1237" data-start="1083"><tr data-end="1150" data-start="1083"><td data-col-size="sm" data-end="1091" data-start="1083">email</td><td data-col-size="sm" data-end="1100" data-start="1091">string</td><td data-col-size="sm" data-end="1105" data-start="1100">✔️</td><td data-col-size="md" data-end="1150" data-start="1105">Email corporativo del empleado (user\_id).</td></tr><tr data-end="1237" data-start="1151"><td data-col-size="sm" data-end="1158" data-start="1151">date</td><td data-col-size="sm" data-end="1180" data-start="1158">string (YYYY-MM-DD)</td><td data-col-size="sm" data-end="1185" data-start="1180">✔️</td><td data-col-size="md" data-end="1237" data-start="1185">Fecha usada para identificar el mes a consultar.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Utiliza autenticación interna mediante **apiService()** (token ERP interno).

No requiere autenticación del cliente (uso interno backend → ERP).

---

# 🧠 Flujo del Servicio (Explicación Real)

### **1) Validación inicial**

- El email es obligatorio.  
    Si falta, responde:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Email necesario para la busqueda"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **2) Obtener empleado por email**

Consulta al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-employee-%3Flimit%3D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Employee?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>&fields=["name","passport_number","designation","fecha_de_ingreso_real"]&filters=[["user_id","=", "<email>"]]`</td></tr></tbody></table>

</div></div></div></div>Validaciones:

- Si no devuelve datos → error.
- Si el empleado no tiene **designation** → error.

---

### **3) Obtener información del puesto (Designation)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-designation%2F%3Cdes"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="language-xml">GET Designation/<span class="hljs-tag"><<span class="hljs-name">designation</span></span></span>>`**</span></div></div>- Trae la lista de exámenes asignados al puesto.
- Transformación especial si el puesto contiene espacios (caso HR).

---

### **4) Rango de fechas del mes**

A partir del parámetro `date`:

- Primer día del mes
- Último día del mes

Ejemplo: `<span class="hljs-number">2024-05-01 </span><span class="hljs-string">to</span> <span class="hljs-number">2024-05-31</span>`

---

### **5) Obtener evaluaciones del mes**

Consulta al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-quiz-activity-%3Fl"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Quiz Activity?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>&fields=["dni","quiz","status","score","activity_date"]&filters=[    ["dni","=", "<employee.passport_number>"],    ["creation","Between", ["<firstDay>", "<lastDay>"]]]&order_by=activity_date <span class="hljs-keyword">asc</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **6) Construcción del resultado**

- Se genera una lista con **todos los exámenes del puesto**, con estado inicial:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">puntaje</span> = <span class="hljs-string">"-"</span><span class="hljs-attr">estado</span> = <span class="hljs-string">"No rindió"</span>`</div></div>
- Se recorren las evaluaciones rendidas:
    
    
    - Se conserva la **mejor nota** por examen.
    - Se asigna estado:
        
        
        - Pass → "Pass"
        - Fail → "No Pass"

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Resultados de los examenes generado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"EXAMEN 1"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> <span class="hljs-attr">"examen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EXAMEN 1"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"puntaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"85"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Pass"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"EXAMEN 2"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> <span class="hljs-attr">"examen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EXAMEN 2"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"puntaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"-"</span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No rindió"</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"list_test"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"EXAMEN 1"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"EXAMEN 2"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Email vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Email necesario para la busqueda"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error buscando empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al buscar empleado"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Sin puesto asignado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El empleado no tiene un puesto asociado"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error obteniendo exámenes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error traer los examenes"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Error obteniendo resultados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error traer los resultados de los examenes"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 6. Error interno del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al generar Servicio"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas

### **Employee**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_ingreso_real"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Designation**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22exa%22%3A-%5B-%7B-%22examen"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"exa"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span> <span class="hljs-attr">"examen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span> <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Quiz Activity**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dni%22%3A-%22string%22%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"quiz"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Pass|Fail"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"score"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"activity_date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-email-%3D-request.emai"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`email = request.emaildate = request.dateif email is empty:    return erroremployee = GET Employee by user_id=emailif empty:    return errordesignation = employee.designationif empty:    return errorexams = GET Designation/examsrange = firstDayOfMonth(date), lastDayOfMonth(date)quizResults = GET QuizActivity where dni = employee.passport_number and creation between rangeprepare response:    for each exam:        set puntaje = "-"        set estado = "No rindió"    for each quizResult:        keep best score        set estado based on Pass/Failreturn json`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo Contratación

# Documento de Ingresos (Subir Documentos de ingresos (1)) - [documentosIngreso]

## 🧾 Descripción

*Registra y actualiza los **documentos obligatorios de ingreso** de un empleado dentro del ERP, así como su información bancaria y de fondo de pensiones.*

*Este servicio valida la información mínima necesaria antes de actualizar el documento Employee en el ERP.*

👉 Es un servicio crítico para el proceso de onboarding, ya que sin este registro el empleado no continúa con otros procesos internos.

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/documentos-ingreso`**</span>

---

# 📥 Parámetros de entrada (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-00123"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"banco"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"BCP"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"copia_dni_de_hijos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"certificado_de_estudios"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cv"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"copia_dni_de_conyuge"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"certificado_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"certijoven"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"copia_de_recibo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fondo_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AFP"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"afiliado_fondo_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

Requiere token válido del ERP (la autenticación se maneja internamente mediante `ServiceErp()`).

---

# 🧠 Flujo del Servicio (Resumen Real)

1. **Valida que existan campos obligatorios**:
    
    
    - employee
    - banco
    - fondo\_pensiones
    - afiliado\_fondo\_pensiones (“SI” o “NO”)
2. Construye un arreglo con los datos a actualizar:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24data-%3D-%5B-%22eleccion_"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable">$data</span> = [  <span class="hljs-string">"eleccion_banco"</span> => banco,  <span class="hljs-string">"elección_fondo_pensiones"</span> => fondo_pensiones,  <span class="hljs-string">"afiliado_fondo_pensiones"</span> => afiliado_fondo_pensiones,  ...];`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>3. Si el fondo de pensiones es **ONP**, también actualiza:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%22fondo_de_pensiones%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-string">"fondo_de_pensiones"</span> => <span class="hljs-string">"ONP"</span>`</div></div>4. Si se envían documentos opcionales (DNI, copia de DNI de hijos, CV, certificado de trabajo, etc.), también se agregan al payload.
5. Realiza la actualización del empleado:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-put-%2Fresource%2Femploy"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`PUT /resource/Employee/{employee}`</div></div>6. Devuelve la respuesta del ERP junto con los datos enviados.

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Documentos registrados correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"eleccion_banco"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"BCP"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"elección_fondo_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AFP"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"afiliado_fondo_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cv"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"certificado_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url_file"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Falta el employee

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta key employee"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Falta banco

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El banco es obligatorio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Falta fondo de pensiones

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El fondo de pensiones es obligatorio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Afiliado fondo pensiones inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Valor no permitido en Afiliado a Fondo de Pensiones"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Error del ERP al actualizar

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al actualizar documentos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuesta del ERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Data Model Usado

### Employee (PUT)

Campos actualizables:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22eleccion_banco%22%3A-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"eleccion_banco"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"elección_fondo_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AFP|ONP"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"afiliado_fondo_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI|NO"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"copia_dni_de_hijos"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"certificado_de_estudios"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"certijoven"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cv"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"copia_dni_de_conyuge"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"certificado_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"copia_de_recibo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|fileurl"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"asignacion_familiar_2"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span>|<span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fondo_de_pensiones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AFP|ONP"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Pseudocódigo de la lógica

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-employee-is-empty"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if employee is empty → errorif banco is empty → errorif fondo_pensiones is empty → errorif afiliado_fondo_pensiones not in ("SI","NO") → errordata = {    eleccion_banco: banco,    elección_fondo_pensiones: fondo_pensiones,    afiliado_fondo_pensiones: afiliado_fondo_pensiones}if fondo_pensiones == "ONP":    data["fondo_de_pensiones"] = "ONP"Agregar campos opcionales si existenPUT Employee/{employee} with datareturn respuesta del ERP + msn "Documentos registrados correctamente"`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Documento de Ingresos (Formulario Ficha de Personal (1)) - [formFichaPersonal]

### 🧾 Descripción

*Registra la **Ficha Personal** del trabajador, permitiendo actualizar:*

- Datos de contacto de emergencia
- Información del cónyuge/conviviente según estado civil
- Registro del proceso en el módulo *historial\_procesos\_app*

*Es un servicio utilizado por la aplicación para completar los datos obligatorios que el trabajador debe registrar para continuar con otros procesos internos.*

*Este servicio actualiza directamente el documento **Employee** en el ERP.*

---

# 🚀 Endpoint

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fform-ficha-per"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /form-ficha-personal`**</span></div></div>---

# 📥 Request Body (JSON)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"contactoEmergencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"nombreCompleto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Perez"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"parentesco"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Hermano"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"telefono"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"987654321"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estadoCivil"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"nombreCompleto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ana Torres"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fechaNacimiento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1990-01-01"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"ocupacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Administradora"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"centroTrabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empresa X"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"direccion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Av. Los Olivos 123"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"datosFamiliares"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>...<span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Los campos **contactoEmergencia** y **estadoCivil** vienen como JSON string y se decodifican dentro del servicio.

---

# 🔐 Seguridad

- Requiere autenticación interna ERP vía `ServiceErp()`.
- Solo accesible para usuarios autenticados en la app.
- Valida que el Employee exista antes de actualizar.

---

# 🧠 Flujo del Servicio (Paso a Paso)

### 1️⃣ Validaciones iniciales

- Verifica que **estadoCivil** exista.
- Verifica que **contactoEmergencia** exista.
- Si faltan datos, devuelve error.

### 2️⃣ Obtiene información del empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fresource%2Femploy"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**<span style="color: rgb(224, 62, 45);">`GET /resource/Employee/{empleado}`</span>**</div></div>Valida que el empleado exista y revisa si tiene estado civil registrado en el ERP:

- Si es **Casado/a** o **Conviviente**, revisa que toda la información del cónyuge esté completa.

### 3️⃣ Determina nuevo estado civil

Si el ERP no tiene estado civil registrado:

- Si `estadoCivil["nombreCompleto"]` existe → **Casado/a**
- Si no existe → **Soltero/a**

### 4️⃣ Construye el body para actualizar Employee

Campos incluidos:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22person_to_be_cont"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"person_to_be_contacted"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"relation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emergency_phone_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo_conyugue"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_nacimiento_conyugue"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ocupación_conyugue"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"centro_de_trabajo_conyugue"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dirección_actual_conyugue"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado_civil_personal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Casado/a"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Todos los textos se envían en mayúsculas.

### 5️⃣ Actualiza Employee

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-put-%2Fresource%2Femploy"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`PUT /resource/Employee/{empleado}`**</span></div></div>### 6️⃣ Registra proceso de Ficha Personal

Inserta un registro en MySQL (`historial_procesos_app`) con:

- proceso = "registerFichaPersonal"
- fecha actual
- empleado

Sirve para el tracking de documentos obligatorios.

### 7️⃣ Respuesta exitosa

Devuelve:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se registró correctamente"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 Response 200 – Ejemplo

### ✔️ Caso exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se registró correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error: falta información del estado civil

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No tiene su información de estado civil, debe comunicarse con Soporte"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error: datos incompletos del cónyuge

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Complete la información del cónyugue o conviviente. Información faltante: fechaNacimiento"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error al actualizar en el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al actualizar la información del trabajador."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuestaERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores Detallados

<div class="_tableContainer_1rjym_1" id="bkmrk-error-descripci%C3%B3n-mi"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="4321" data-start="3819"><thead data-end="3842" data-start="3819"><tr data-end="3842" data-start="3819"><th data-col-size="sm" data-end="3827" data-start="3819">Error</th><th data-col-size="md" data-end="3842" data-start="3827">Descripción</th></tr></thead><tbody data-end="4321" data-start="3866"><tr data-end="3932" data-start="3866"><td data-col-size="sm" data-end="3888" data-start="3866">Missing estadoCivil</td><td data-col-size="md" data-end="3932" data-start="3888">No se envió estado civil o JSON inválido</td></tr><tr data-end="4014" data-start="3933"><td data-col-size="sm" data-end="3962" data-start="3933">Missing contactoEmergencia</td><td data-col-size="md" data-end="4014" data-start="3962">Falta información mínima para completar la ficha</td></tr><tr data-end="4088" data-start="4015"><td data-col-size="sm" data-end="4040" data-start="4015">Employee no encontrado</td><td data-col-size="md" data-end="4088" data-start="4040">GET Employee/{empleado} no encontró registro</td></tr><tr data-end="4199" data-start="4089"><td data-col-size="sm" data-end="4126" data-start="4089">Información incompleta del cónyuge</td><td data-col-size="md" data-end="4199" data-start="4126">Falta un campo requerido cuando el estado civil es casado/conviviente</td></tr><tr data-end="4247" data-start="4200"><td data-col-size="sm" data-end="4225" data-start="4200">Error de actualización</td><td data-col-size="md" data-end="4247" data-start="4225">PUT Employee falló</td></tr><tr data-end="4321" data-start="4248"><td data-col-size="sm" data-end="4276" data-start="4248">Error registrando proceso</td><td data-col-size="md" data-end="4321" data-start="4276">Inserción en historial\_procesos\_app falló</td></tr></tbody></table>

</div></div>---

# 📚 Schemas (Estructuras Utilizadas)

### Employee (GET y PUT)

Campos usados:

<table border="1" id="bkmrk-person_to_be_contact" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attribute">person_to_be_contacted</span>relationemergency_phone_numbernombre_completo_conyuguefecha_de_nacimiento_conyugueocupación_conyuguecentro_de_trabajo_conyuguedirección_actual_conyugueestado_civil_personal`</td></tr></tbody></table>

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--7"><div class="overflow-y-auto p-4" dir="ltr"></div></div>### historial\_procesos\_app (INSERT)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-usuario-empleado-pro"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attribute">usuario</span>empleadoprocesofechaestado`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-empleado-%3D-request.e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`empleado = request.empleadocontacto = json_decode(request.contactoEmergencia)civil = json_decode(request.estadoCivil)<span class="hljs-keyword">if</span> civil <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span> or empty:    <span class="hljs-keyword">return</span> error(<span class="hljs-string">"No tiene información de estado civil"</span>)<span class="hljs-keyword">if</span> contacto <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span>:    <span class="hljs-keyword">return</span> error(<span class="hljs-string">"Falta información de contacto de emergencia"</span>)employee = GET Employee/{empleado}<span class="hljs-keyword">if</span> civil.previous == Casado or Conviviente:    validar campos completos de cónyugenewCivil = employee.estadoCivil != <span class="hljs-string">""</span> ? employee.estadoCivil :           (civil.nombreCompleto ? <span class="hljs-string">"Casado/a"</span> : <span class="hljs-string">"Soltero/a"</span>)bodyPUT = construir campos del contacto + cónyugeupdate = PUT Employee/{empleado}<span class="hljs-keyword">if</span> update.ok:    insertar registro en historial_procesos_app    <span class="hljs-keyword">return</span> success<span class="hljs-keyword">else</span>:    <span class="hljs-keyword">return</span> error(<span class="hljs-string">"Ocurrió un error al actualizar"</span>)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Documento de Ingresos (Verificar Registro de Postulación (1)) - [validatePersonalRequirement]

## 🧾 Descripción

*Este servicio valida si un postulante (que ya es empleado o está en proceso de contratación) **cumple con las condiciones necesarias para continuar el proceso de Alta y Requerimiento de Personal**.*

La validación se basa en:

- Información del **Employee**
- Su **postulación (Job Applicant)**
- Su **Convocatoria (Job Opening)**
- Su **Terminal / Sucursal (Branch)**
- El **Requerimiento de Personal** asociado a la convocatoria

Este servicio permite determinar si se puede generar su trámite de contratación y qué parámetros corresponden a su modalidad de trabajo y tipo de jornada.

---

# 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">**POST /validate-personal-requirement**</span>

### 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22document%22%3A-%2212345"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>**`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"document"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">}</span>`**  
</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Parámetros:

- **document**: DNI o pasaporte del postulante.

---

# 🔐 Seguridad

Requiere autenticación interna hacia el ERP mediante `dbErp()` y rutas definidas en `APICAPACITACION`.

---

# 🧠 Flujo del Servicio (Resumen)

### 1️⃣ Validar si el documento pertenece a un *Employee*

Consulta en `tabEmployee`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-employment_ty"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> employment_type, tipo_de_jornada<span class="hljs-keyword">FROM</span> tabEmployee<span class="hljs-keyword">WHERE</span> passport_number <span class="hljs-operator">=</span> :document`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Si no existe → ❌ devuelve error.

---

### 2️⃣ Buscar su postulación más reciente (Job Applicant)

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-job_title-fro"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> job_title<span class="hljs-keyword">FROM</span> tabJob Applicant<span class="hljs-keyword">WHERE</span> numero_de_documento <span class="hljs-operator">=</span> :document <span class="hljs-keyword">AND</span> docstatus <span class="hljs-operator">!=</span> <span class="hljs-number">2</span><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> creation <span class="hljs-keyword">DESC</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Si no tiene postulación → ❌ retorna error.

---

### 3️⃣ Obtener información de la Convocatoria (Job Opening)

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-modalidad_de_"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> modalidad_de_trabajo, modalidad, sucursal<span class="hljs-keyword">FROM</span> tabJob Opening<span class="hljs-keyword">WHERE</span> name <span class="hljs-operator">=</span> :job_title <span class="hljs-keyword">AND</span> docstatus <span class="hljs-operator">!=</span> <span class="hljs-number">2</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Determina:
    
    
    - **Tipo de jornada / modalidad** de la convocatoria.
    - **Sucursal asignada** al postulante.

---

### 4️⃣ Obtener información de la Sucursal (Branch)

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-division_naci"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> division_nacional<span class="hljs-keyword">FROM</span> tabBranch<span class="hljs-keyword">WHERE</span> name <span class="hljs-operator">=</span> :sucursal <span class="hljs-keyword">AND</span> docstatus <span class="hljs-operator">!=</span> <span class="hljs-number">2</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Determina la zona RRHH responsable.
- Según la zona, define qué tabla usar para el Requerimiento de Personal:
    
    
    - **Lima → `tabRequerimiento de Personal Lima`**
    - **Otros → `tabRequerimiento de Personal`**

---

### 5️⃣ Obtener el Requerimiento de Personal asociado a la convocatoria

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-tipo_de_jorna"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> tipo_de_jornada<span class="hljs-keyword">FROM</span> {RequerimientoTabla}<span class="hljs-keyword">WHERE</span> documento_convocatoria <span class="hljs-operator">=</span> :job_title <span class="hljs-keyword">AND</span> docstatus <span class="hljs-operator">!=</span> <span class="hljs-number">2</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Si no existe RP → ❌ el proceso de contratación debe repetirse.

---

### 6️⃣ Respuesta exitosa

Devuelve:

- Tipo de jornada
- Modalidad del puesto
- Código de convocatoria

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22me"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Exito."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"tipo_jornada"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Tiempo completo"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"modalidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Presencial"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"convocatoria"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JOB-2025-00123"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. No existe empleado con el documento

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error, contactar con soporte."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 2. No existen postulaciones válidas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró un registró de su postulación a una de nuestras convocatorias, comuniquese con su administrador."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3. Convocatoria no encontrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la convocatoria vinculada a su postulación, comuniquese con su administrador."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 4. Sucursal/Terminal inexistente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No existe la terminal del usuario."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 5. Requerimiento de Personal no creado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La convocatoria del postulante no tiene REQUERIMIENTO DE PERSONAL creada, realizar nuevamente el proceso de contratación."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 6. Error del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error en el servidor."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Esquemas utilizados

### **Employee**

Campos consultados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employment_type%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employment_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_de_jornada"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### **Job Applicant**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22job_title%22%3A-%22stri"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"job_title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **Job Opening**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22modalidad_de_trab"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"modalidad_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"modalidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **Branch**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22division_nacional"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"division_nacional"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **Requerimiento de Personal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22tipo_de_jornada%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"tipo_de_jornada"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-employee-%3D-get-emplo"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`employee = GET Employee WHERE passport_number = documentif not employee:    error("Empleado no encontrado")postulacion = GET Job Applicant WHERE document = document ORDER BY creation DESCif not postulacion:    error("Postulación no encontrada")convocatoria = GET Job Opening WHERE name = postulacion.job_titleif not convocatoria:    error("Convocatoria no encontrada")branch = GET Branch WHERE name = convocatoria.sucursalselect RP_table = Branch.zone == Lima ? RP_Lima : RP_Normalrp = GET RP_table WHERE documento_convocatoria = job_titleif not rp:    error("RP no creada")return {    tipo_jornada: rp.tipo_de_jornada,    modalidad: convocatoria.modalidad || modalidad_de_trabajo,    convocatoria: job_title}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Documento de Ingresos (Registrar Proceso de Descarga (1)) - [registerProcessApp]

## 🧾 Descripción

*Registra en la tabla `historial_procesos_app` cada evento o proceso realizado por un usuario dentro de la aplicación móvil.*  
*Además, dependiendo del tipo de proceso, realiza validaciones adicionales como:*

- Validación de renovación de contrato
- Validación de cambio de modalidad
- Creación automática de usuario conductor en sistema externo
- Validación de existencia del empleado en ERP

Este servicio funciona como logger centralizado de acciones críticas del trabajador.

---

## 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/register-process-app`**</span>

---

## 📥 Parámetros de Entrada (Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"latitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"longitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🔐 Seguridad

- Acceso interno del sistema
- Requiere conexión válida a BD secundaria (`mysql2`)
- Valida datos contra API ERP mediante `dbErp` y `ServiceErp`

---

## 🧠 Flujo del Servicio (Resumen Real)

### 1️⃣ Obtiene parámetros principales del request:

- usuario
- empleado
- agencia
- lat/long
- proceso
- month / year

---

### 2️⃣ Si el proceso es **descargaContratoReingreso**

- Ejecuta validación de renovación del contrato:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Evalidateproce"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">validateProcessContractRenovation</span>(<span class="hljs-variable">$request</span>, <span class="hljs-variable">$connection</span>);`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>- Ejecuta validación de cambio de modalidad:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Evalidateproce-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">validateProcessContractChangeModality</span>(<span class="hljs-variable">$request</span>,<span class="hljs-variable">$connection</span>);`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 3️⃣ Si el proceso es **descargaContratoTrabajo**

#### a) Obtiene datos del empleado en el ERP

(Documento, sucursal, nombre y puesto)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-passport_numb"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> passport_number, id_sucursal, nombre_completo, designation <span class="hljs-keyword">FROM</span> `tabEmployee``</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>#### b) Si el puesto contiene la palabra **CONDUCTOR**

El sistema crea un **usuario conductor** en un sistema externo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-empresarial%2Fapi"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-string">POST</span> <span class="hljs-string">EMPRESARIAL/api/crearUsuarioConductor</span>{   <span class="hljs-attr">documento:</span> <span class="hljs-string">DNI</span>,   <span class="hljs-attr">ter_id:</span> <span class="hljs-string">id_sucursal</span>,   <span class="hljs-attr">nombre:</span> <span class="hljs-string">nombre_completo</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Cualquier error en este paso retorna:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al registrar el proceso."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 4️⃣ Inserta el registro del proceso en `historial_procesos_app`

Campos insertados:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-descripci%C3%B3n-us"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2783" data-start="2443"><thead data-end="2466" data-start="2443"><tr data-end="2466" data-start="2443"><th data-col-size="sm" data-end="2451" data-start="2443">Campo</th><th data-col-size="sm" data-end="2466" data-start="2451">Descripción</th></tr></thead><tbody data-end="2783" data-start="2491"><tr data-end="2535" data-start="2491"><td data-col-size="sm" data-end="2501" data-start="2491">usuario</td><td data-col-size="sm" data-end="2535" data-start="2501">Usuario que ejecuta el proceso</td></tr><tr data-end="2570" data-start="2536"><td data-col-size="sm" data-end="2547" data-start="2536">empleado</td><td data-col-size="sm" data-end="2570" data-start="2547">Código del empleado</td></tr><tr data-end="2601" data-start="2571"><td data-col-size="sm" data-end="2581" data-start="2571">agencia</td><td data-col-size="sm" data-end="2601" data-start="2581">ID de la agencia</td></tr><tr data-end="2624" data-start="2602"><td data-col-size="sm" data-end="2613" data-start="2602">latitude</td><td data-col-size="sm" data-end="2624" data-start="2613">Latitud</td></tr><tr data-end="2649" data-start="2625"><td data-col-size="sm" data-end="2637" data-start="2625">longitude</td><td data-col-size="sm" data-end="2649" data-start="2637">Longitud</td></tr><tr data-end="2692" data-start="2650"><td data-col-size="sm" data-end="2660" data-start="2650">proceso</td><td data-col-size="sm" data-end="2692" data-start="2660">Nombre del proceso ejecutado</td></tr><tr data-end="2724" data-start="2693"><td data-col-size="sm" data-end="2701" data-start="2693">fecha</td><td data-col-size="sm" data-end="2724" data-start="2701">Fecha y hora actual</td></tr><tr data-end="2752" data-start="2725"><td data-col-size="sm" data-end="2734" data-start="2725">estado</td><td data-col-size="sm" data-end="2752" data-start="2734">1 (registrado)</td></tr><tr data-end="2768" data-start="2753"><td data-col-size="sm" data-end="2761" data-start="2753">month</td><td data-col-size="sm" data-end="2768" data-start="2761">Mes</td></tr><tr data-end="2783" data-start="2769"><td data-col-size="sm" data-end="2776" data-start="2769">year</td><td data-col-size="sm" data-end="2783" data-start="2776">Año</td></tr></tbody></table>

</div></div>---

### 5️⃣ Devuelve respuesta exitosa

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Proceso registrado con éxito."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 📤 Respuestas

### ✔ **200 – Éxito**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Proceso registrado con éxito."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### ❗ Error al insertar registro

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al registrar el proceso."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### ❗ Empleado no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró al empleado."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### ❗ Error de creación de usuario conductor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al registrar el proceso."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 📚 Estructuras utilizadas

### Tabla: historial\_procesos\_app

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"latitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"longitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ERP: Employee

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22passport_number%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-leer-usuario%2C-emplea"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`leer usuario, empleado, proceso, month, year, lat, longsi proceso == "descargaContratoReingreso":    validar renovación de contrato    validar cambio de modalidadsi proceso == "descargaContratoTrabajo":    traer datos del empleado    si puesto incluye "CONDUCTOR":        crear usuario conductor en sistema externoinsertar registro en historial_procesos_appsi inserción falla:    retornar errorretornar éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Documento de Ingresos (Registrar Equipamiento (1)) - [store_equipament]

## 🧾 Descripción

*Registra o actualiza las tallas de **equipamiento de EPP** (botas, polo, pantalón) para un postulante, validando previamente:*

- Que el documento exista en el sistema.
- Que las tallas enviadas sean válidas según los rangos permitidos.
- Que el postulante exista.
- Que ya tenga o no un registro previo en **Triaje de Postulante 2**, para decidir entre **crear (POST)** o **actualizar (PUT)**.

*Es un servicio que integra:*

- Validaciones locales.
- Consulta de postulantes.
- Inserción o actualización en el ERP vía **ServiceErp()**.

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/store-equipament`**</span>

---

# 🔐 Seguridad

Requiere autenticación interna contra el ERP mediante:

- `ServiceErp()`
- `searchPostulanteByDocument()`

No hace validaciones de token en el controlador; se maneja internamente por los métodos usados.

---

# 🧠 Flujo del Servicio (explicación real)

1. **Lee los parámetros enviados en la petición**:
    
    
    - documento
    - botas
    - polo
    - pantalon
2. **Valida la estructura y tallas permitidas**:
    
    <div class="_tableContainer_1rjym_1"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1432" data-start="1287"><thead data-end="1319" data-start="1287"><tr data-end="1319" data-start="1287"><th data-col-size="sm" data-end="1298" data-start="1287">Elemento</th><th data-col-size="sm" data-end="1319" data-start="1298">Tallas permitidas</th></tr></thead><tbody data-end="1432" data-start="1359"><tr data-end="1376" data-start="1359"><td data-col-size="sm" data-end="1367" data-start="1359">botas</td><td data-col-size="sm" data-end="1376" data-start="1367">36–45</td></tr><tr data-end="1402" data-start="1380"><td data-col-size="sm" data-end="1387" data-start="1380">polo</td><td data-col-size="sm" data-end="1402" data-start="1387">S, M, L, XL</td></tr><tr data-end="1432" data-start="1406"><td data-col-size="sm" data-end="1417" data-start="1406">pantalón</td><td data-col-size="sm" data-end="1432" data-start="1417">S, M, L, XL</td></tr></tbody></table>
    
    </div></div>
3. **Busca al postulante por documento**:  
    Llama a:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">searchPostulanteByDocument</span>($documento)`</div></div>Si no existe → retorna error.
4. **Busca si ya existe un registro de triaje activo en el ERP**:
    
    GET  
    `/resource/Triaje de Postulante 2`  
    con filtros:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attribute">documento</span> = <span class="hljs-variable">$documento</span>docstatus != <span class="hljs-number">2</span>`</div></div>
5. Dependiendo del resultado:
    
    
    - **No existe registro → crea uno (POST)**
    - **Sí existe → actualiza el existente (PUT)**
6. **Realiza el POST o PUT correspondiente** hacia el ERP.
7. **Si ERP devuelve error**, intenta decodificar `_server_messages` para obtener error real del ERP.
8. **Retorna respuesta final** indicando éxito o error.

---

# 📥 Request Body

Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22documento%22%3A-%221234"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"botas"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">42</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"polo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"M"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pantalon"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"L"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 Response 200 – Ejemplos

### ✔️ Registro/Actualización exitosa

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Equipamiento registrado con éxito"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Documento no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta enviar el documento"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Talla inválida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese una talla de botas válida"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Postulante no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No existe postulante con ese documento"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al registrar el triaje del postulante"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"PUT"</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span> ...body... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"URL del recurso usado"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores del Servicio

<div class="_tableContainer_1rjym_1" id="bkmrk-tipo-ejemplo-documen"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3343" data-start="2950"><thead data-end="2968" data-start="2950"><tr data-end="2968" data-start="2950"><th data-col-size="sm" data-end="2957" data-start="2950">Tipo</th><th data-col-size="md" data-end="2968" data-start="2957">Ejemplo</th></tr></thead><tbody data-end="3343" data-start="2988"><tr data-end="3044" data-start="2988"><td data-col-size="sm" data-end="3011" data-start="2988">Documento no enviado</td><td data-col-size="md" data-end="3044" data-start="3011">`"Falta enviar el documento"`</td></tr><tr data-end="3104" data-start="3045"><td data-col-size="sm" data-end="3063" data-start="3045">Talla no válida</td><td data-col-size="md" data-end="3104" data-start="3063">`"Ingrese una talla de botas válida"`</td></tr><tr data-end="3195" data-start="3105"><td data-col-size="sm" data-end="3132" data-start="3105">Postulante no encontrado</td><td data-col-size="md" data-end="3195" data-start="3132">respuesta directa del servicio `searchPostulanteByDocument`</td></tr><tr data-end="3284" data-start="3196"><td data-col-size="sm" data-end="3231" data-start="3196">Error al crear/actualizar en ERP</td><td data-col-size="md" data-end="3284" data-start="3231">Mensaje del `_server_messages` o mensaje genérico</td></tr><tr data-end="3343" data-start="3285"><td data-col-size="sm" data-end="3304" data-start="3285">Error inesperado</td><td data-col-size="md" data-end="3343" data-start="3304">Devuelve el error capturado del ERP</td></tr></tbody></table>

</div></div>---

# 🗃 ERP: Documentos involucrados

### **Triaje de Postulante 2 (GET / POST / PUT)**

Campos usados:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-documento"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3600" data-start="3453"><thead data-end="3469" data-start="3453"><tr data-end="3469" data-start="3453"><th data-col-size="sm" data-end="3461" data-start="3453">Campo</th><th data-col-size="sm" data-end="3469" data-start="3461">Tipo</th></tr></thead><tbody data-end="3600" data-start="3487"><tr data-end="3509" data-start="3487"><td data-col-size="sm" data-end="3499" data-start="3487">documento</td><td data-col-size="sm" data-end="3509" data-start="3499">string</td></tr><tr data-end="3525" data-start="3510"><td data-col-size="sm" data-end="3518" data-start="3510">botas</td><td data-col-size="sm" data-end="3525" data-start="3518">int</td></tr><tr data-end="3543" data-start="3526"><td data-col-size="sm" data-end="3533" data-start="3526">polo</td><td data-col-size="sm" data-end="3543" data-start="3533">string</td></tr><tr data-end="3565" data-start="3544"><td data-col-size="sm" data-end="3555" data-start="3544">pantalon</td><td data-col-size="sm" data-end="3565" data-start="3555">string</td></tr><tr data-end="3600" data-start="3566"><td data-col-size="sm" data-end="3573" data-start="3566">name</td><td data-col-size="sm" data-end="3600" data-start="3573">string (clave para PUT)</td></tr></tbody></table>

</div></div>---

# 🧩 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-read-document%2C-botas"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`read document, botas, polo, pantalonvalidate documentvalidate botas in [<span class="hljs-number">36.</span><span class="hljs-number">.45</span>]validate polo in [S,M,L,XL]validate pantalon in [S,M,L,XL]postulante = searchPostulanteByDocument(document)<span class="hljs-keyword">if</span> postulante.invalid:    <span class="hljs-keyword">return</span> <span class="hljs-type">error</span><span class="hljs-variable">triaje</span> <span class="hljs-operator">=</span> GET TriajeDePostulante2 where documento=document and docstatus != <span class="hljs-number">2</span><span class="hljs-keyword">if</span> triaje exists:    method = <span class="hljs-type">PUT</span>    <span class="hljs-variable">url</span> <span class="hljs-operator">=</span> recurso + <span class="hljs-string">"/"</span> + triaje.name<span class="hljs-keyword">else</span>:    method = <span class="hljs-type">POST</span>    <span class="hljs-variable">url</span> <span class="hljs-operator">=</span> <span class="hljs-type">recurso</span><span class="hljs-variable">body</span> <span class="hljs-operator">=</span> {    documento, botas, polo, pantalon}result = CALL ERP with method, body, url<span class="hljs-keyword">if</span> result.error:    <span class="hljs-keyword">return</span> readable ERP error<span class="hljs-keyword">return</span> success`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Documento de Ingresos (Registrar Proceso de Descarga (1, 2,3,4,5)) - [registerProcessApp]

### 🧾 Descripción

*Registra en la tabla `historial_procesos_app` todas las acciones (procesos) que el usuario realiza dentro del aplicativo móvil, como descargas de documentos, validación de contratos, marcaciones, entre otros.*

Antes de registrar el proceso:

1. **Valida si corresponde un proceso de Reingreso o Renovación de Contrato.**
2. **Procesa el registro especial para Conductores**, creando su usuario en el sistema empresarial cuando descarga su contrato.
3. **Guarda la información del evento** (geolocalización, mes, año, proceso, etc.) en la base de datos MySQL2.

Este servicio constituye una pieza clave para los módulos de:

- Marcación
- Documentos obligatorios
- Control de procesos del trabajador
- Contratos / renovaciones

---

# 🚀 Endpoint

### `<span style="color: rgb(224, 62, 45);"><strong>POST /register-process-app</strong></span>`

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"latitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|float"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"longitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|float"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🔐 Seguridad

- Requiere **token válido** para consumir servicios internos del ERP.
- Conexión interna a MySQL2 para registrar procesos.
- Algunos procesos hacen integración con APIs externas (como Empresarial → creación de usuario conductor).

---

# 🧠 Flujo del Servicio (resumen real)

### 1️⃣ Obtiene los parámetros enviados desde la App

Usuario, empleado, agencia, geolocalización, proceso, mes y año.

### 2️⃣ Si el proceso es **descargaContratoReingreso**

Ejecuta:

- **validateProcessContractRenovation()**
- **validateProcessContractChangeModality()**

Estas funciones validan:

- Si el empleado tiene renovación pendiente
- Si debe descargar documentos obligatorios
- Si existen cambios de modalidad pendientes

### 3️⃣ Si el proceso es **descargaContratoTrabajo**

1. Obtiene datos del empleado desde ERP:
    
    
    - DNI (passport\_number)
    - Sucursal
    - Nombre completo
    - Puesto (designation)
2. Si el puesto contiene `"CONDUCTOR"`, registra el usuario en el sistema empresarial:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-empresarial%2Fapi"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST EMPRESARIAL/api/crearUsuarioConductor`</div></div>Enviando:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22documento%22%3A-%22%3Cpas"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<passport_number>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<id_sucursal>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<nombre_completo>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4️⃣ Inserta el proceso en la tabla MySQL:

Tabla: **historial\_procesos\_app**

Campos guardados:

- usuario
- empleado
- agencia
- latitude
- longitude
- proceso
- fecha
- estado
- month
- year

### 5️⃣ Retorna la respuesta del proceso

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Proceso registrado con éxito."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. No se puede registrar el proceso en MySQL

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al registrar el proceso."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. No se encuentra el empleado en el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró al empleado."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. Error creando usuario conductor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al registrar el proceso."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. Error genérico

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno del servidor."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Schemas – Objetos usados

### 🗂 Employee (GET ERP)

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22passport_number%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 🗂 Registro MySQL – historial\_procesos\_app

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"latitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|float"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"longitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|float"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-leer-parametros-del-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`leer parametros del requestif proceso == "descargaContratoReingreso":    validar renovación    validar cambio modalidadif proceso == "descargaContratoTrabajo":    traer datos del empleado desde ERP    if designation contiene "CONDUCTOR":        crear usuario conductor via API Empresarialinsertar registro en historial_procesos_appsi insert falla:    devolver errorreturn éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Contrato de Trabajo(Url Contrato de trabajo PDF (1)) - [printContractPerDesignation]

## 🧾 Descripción

*Genera y descarga el **Contrato de Trabajo** correspondiente a un empleado, seleccionando de forma automática el **formato de contrato correcto** según:*

- Tipo de documento del empleado (DNI / PAS / CE)
- Modalidad laboral (Full time, Part time, Teletrabajo)
- Tipo de puesto (Ej. Conductor, Vigilante)
- Número de contratos previos
- Funciones asociadas al contrato (solo extranjeros)

El servicio determina internamente qué plantilla PDF debe usarse y devuelve el archivo final generado.

Es un servicio interno que consulta múltiples recursos del ERP:

- Employee
- Contrato de Trabajo
- Funciones del Contrato
- Otros contratos previos

---

## 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">**`GET /print-contract-per-designation/{employee}`**</span>

### 📥 Parámetros de ruta

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-oblig"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1197" data-start="1017"><thead data-end="1070" data-start="1017"><tr data-end="1070" data-start="1017"><th data-col-size="sm" data-end="1030" data-start="1017">Parámetro</th><th data-col-size="sm" data-end="1041" data-start="1030">Tipo</th><th data-col-size="sm" data-end="1055" data-start="1041">Obligatorio</th><th data-col-size="sm" data-end="1070" data-start="1055">Descripción</th></tr></thead><tbody data-end="1197" data-start="1124"><tr data-end="1197" data-start="1124"><td data-col-size="sm" data-end="1136" data-start="1124">employee</td><td data-col-size="sm" data-end="1147" data-start="1136">string</td><td data-col-size="sm" data-end="1161" data-start="1147">Sí</td><td data-col-size="sm" data-end="1197" data-start="1161">Código único del empleado en ERP</td></tr></tbody></table>

</div></div>---

## 🔐 Seguridad

Requiere autenticación interna:

- Consulta ERP vía `dbErp()`
- Obtención de PDF vía `PDF::loadView()`

---

## 🧠 Flujo del Servicio (Resumen Real)

### **1️⃣ Validación del empleado**

Consulta al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-send-query-data"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST send-query-<span class="hljs-keyword">database</span><span class="hljs-keyword">FROM</span> tabEmployee<span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span> = employee<span class="hljs-keyword">SELECT</span> fecha_de_ingreso_real`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si no existe → retorna error: *"No existe empleado"*.

---

### **2️⃣ Obtiene el contrato activo más reciente**

Se buscan contratos con:

- `empleado = employee`
- `docstatus = 1`
- `fecha_de_ingreso_real = fecha_ingreso_empleado`
- Ordenado por creación descendente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-send-query-data-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST send<span class="hljs-operator">-</span>query<span class="hljs-operator">-</span>database<span class="hljs-keyword">FROM</span> tabContrato de Trabajo<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> tabEmployee`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si no existe contrato → retorna *"No cuenta con Contrato"*.

---

### **3️⃣ Obtiene funciones asociadas (solo extranjeros)**

Busca funciones del contrato:

<table border="1" id="bkmrk-from-tabtabla_funcio" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">FROM</span> tabtabla_funcion_extranjero<span class="hljs-keyword">WHERE</span> parent = contrato.name`</td></tr></tbody></table>

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--5"><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Estas funciones se agregan al contrato en el PDF.

---

### **4️⃣ Determina el número de contratos previos**

Solo aplica a empleados con documento **PAS** o **CE**.

Consulta cantidad de contratos registrados después del ingreso real.

Esto permite determinar si el contrato es:

- Primer contrato
- Segundo contrato
- Tercer contrato
- Etc. (usando arreglo ordinal: primero, segundo, tercero, …)

---

### **5️⃣ Selección automática de la plantilla PDF**

En base a reglas:

<div class="_tableContainer_1rjym_1" id="bkmrk-condici%C3%B3n-plantilla-"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3167" data-start="2587"><thead data-end="2612" data-start="2587"><tr data-end="2612" data-start="2587"><th data-col-size="md" data-end="2599" data-start="2587">Condición</th><th data-col-size="md" data-end="2612" data-start="2599">Plantilla</th></tr></thead><tbody data-end="3167" data-start="2639"><tr data-end="2700" data-start="2639"><td data-col-size="md" data-end="2676" data-start="2639">modalidad\_de\_trabajo = Teletrabajo</td><td data-col-size="md" data-end="2700" data-start="2676">contrato\_teletrabajo</td></tr><tr data-end="2768" data-start="2701"><td data-col-size="md" data-end="2730" data-start="2701">labor contiene "CONDUCTOR"</td><td data-col-size="md" data-end="2768" data-start="2730">contrato\_conductor\_interprovincial</td></tr><tr data-end="2823" data-start="2769"><td data-col-size="md" data-end="2791" data-start="2769">labor = "VIGILANTE"</td><td data-col-size="md" data-end="2823" data-start="2791">contrato\_full\_time\_vigilante</td></tr><tr data-end="2888" data-start="2824"><td data-col-size="md" data-end="2865" data-start="2824">tipo\_doc PAS o CE, **primer contrato**</td><td data-col-size="md" data-end="2888" data-start="2865">contrato\_extranjero</td></tr><tr data-end="2979" data-start="2889"><td data-col-size="md" data-end="2932" data-start="2889">tipo\_doc PAS o CE, **más de 1 contrato**</td><td data-col-size="md" data-end="2979" data-start="2932">contrato\_extranjero\_mas\_de\_segundo\_contrato</td></tr><tr data-end="3065" data-start="2980"><td data-col-size="md" data-end="3031" data-start="2980">tipo\_contrato = PART TIME, labor=CALL CENTER ATC</td><td data-col-size="md" data-end="3065" data-start="3031">contrato\_call\_center\_part\_time</td></tr><tr data-end="3116" data-start="3066"><td data-col-size="md" data-end="3094" data-start="3066">tipo\_contrato = PART TIME</td><td data-col-size="md" data-end="3116" data-start="3094">contrato\_part\_time</td></tr><tr data-end="3167" data-start="3117"><td data-col-size="md" data-end="3145" data-start="3117">tipo\_contrato = FULL TIME</td><td data-col-size="md" data-end="3167" data-start="3145">contrato\_full\_time</td></tr></tbody></table>

</div></div>El método retorna el PDF con:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-pdf%3A%3Aloadview%28...%29-%3E"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`PDF::<span class="hljs-title function_ invoke__">loadView</span>(...)-><span class="hljs-title function_ invoke__">download</span>();`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 📤 Response – Archivo PDF

Retorna directamente la descarga del contrato correspondiente.

Si ocurre algún error, retorna un JSON:

### ✔️ Empleado válido, pero sin contrato

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No cuenta con Contrato"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ Empleado no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No existe empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## ❗ Posibles Errores

<div class="_tableContainer_1rjym_1" id="bkmrk-error-descripci%C3%B3n-em"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3906" data-start="3617"><thead data-end="3640" data-start="3617"><tr data-end="3640" data-start="3617"><th data-col-size="sm" data-end="3625" data-start="3617">Error</th><th data-col-size="sm" data-end="3640" data-start="3625">Descripción</th></tr></thead><tbody data-end="3906" data-start="3665"><tr data-end="3719" data-start="3665"><td data-col-size="sm" data-end="3686" data-start="3665">Empleado no existe</td><td data-col-size="sm" data-end="3719" data-start="3686">No se encontró en tabEmployee</td></tr><tr data-end="3790" data-start="3720"><td data-col-size="sm" data-end="3750" data-start="3720">No tiene contratos vigentes</td><td data-col-size="sm" data-end="3790" data-start="3750">No existe Contrato de Trabajo activo</td></tr><tr data-end="3839" data-start="3791"><td data-col-size="sm" data-end="3806" data-start="3791">Error DB ERP</td><td data-col-size="sm" data-end="3839" data-start="3806">Respuesta inesperada en dbErp</td></tr><tr data-end="3906" data-start="3840"><td data-col-size="sm" data-end="3866" data-start="3840">Plantilla no encontrada</td><td data-col-size="sm" data-end="3906" data-start="3866">Error al cargar vista PDF (muy raro)</td></tr></tbody></table>

</div></div>---

## 📚 Tablas y Campos Utilizados

### **Employee (GET)**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22fecha_de_ingreso_"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"fecha_de_ingreso_real"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Contrato de Trabajo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_ingreso_real"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"labor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_de_documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"modalidad_de_trabajo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_de_contrato"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Funciones del Contrato (Extranjeros)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22funcion%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"funcion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-employeedata-%3D-get-e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`employeeData = GET Employee where name = employeeif not exists: return errorcontract = GET Contrato where empleado=employee and activoif not exists: return errorfunciones = GET Funciones where parent=contractif doc PAS/CE:    countPrevious = GET Contratos after ingreso real    determinar ordinalseleccionar plantilla PDF según reglasreturn descargar PDF`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Módulo Boletas de Pago

# Boleta Mensual(Obtener Proceso de Descarga (1)) - [obtener]

### 🧾 Descripción

*Este servicio permite **buscar y obtener información detallada de una denuncia** registrada en el ERP, usando un **código aleatorio** generado para consulta pública.*

La función:

- Busca la denuncia usando el campo `codigo_aleatorio`.
- Retorna información clave como:
    
    
    - estado de la denuncia,
    - fecha de creación,
    - fecha de atención,
    - fecha de proceso,
    - respuesta,
    - y un archivo asociado (si existe).
- Construye la URL completa del archivo para ser descargado por el cliente.

Es un servicio de consulta directa, sin dependencias entre módulos.

---

# 🚀 Endpoint

### **POST /obtener**

### 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22codigo%22%3A-%22abc1234"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"codigo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ABC12345"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

No requiere token especial más allá del utilizado internamente por `apiService()` o `ServiceErp()`.  
La autenticación se maneja dentro del sistema ERP.

---

# 🧠 Flujo del Servicio (resumen real)

1. Recibe el parámetro: `<span class="hljs-attr">codigo</span> = <span class="hljs-variable">$request</span>->codigo`
2. Construye un request hacia el ERP: `GET Denuncias?fields=[...]&filters=<span class="hljs-string">[["codigo_aleatorio","=",codigo]]</span>`

Campos obtenidos:

- name
- creation
- estado\_denuncias
- fecha\_atendido
- fecha\_proceso
- archivo\_denuncia
- respuesta\_de\_denuncia\_atendido

3. Si no existe la denuncia → se responde:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la denuncia"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>4. Si existe y tiene archivo, se concatena la URL base:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-archivo_denuncia-%3D-b"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">archivo_denuncia</span> = BASE_CAPACITACION . archivo_denuncia`</div></div>5. Se devuelve la **primera denuncia encontrada**, ya que el código es único.

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DEN-00045"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15 09:12:20"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"estado_denuncias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Atendido"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-20"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha_proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-18"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"archivo_denuncia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"https://servidor.com/files/denuncias/archivo.pdf"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"respuesta_de_denuncia_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se revisó la información y se procedió..."</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. No se encuentra la denuncia

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la denuncia"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error message from ERP"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Código vacío o inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la denuncia"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas Usados

### **Denuncias (GET)**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado_denuncias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"archivo_denuncia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"respuesta_de_denuncia_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica del Servicio (Pseudo-código)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-codigo-%3D-request.cod"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 30.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 30.6px;"><td style="height: 30.6px;">`codigo = request.codigobody = {    limit = None    fields = [name, creation, estado_denuncias, fecha_atendido, fecha_proceso, archivo_denuncia, respuesta...]    filters = [["codigo_aleatorio", "=", codigo]]}response = GET Denuncias using ServiceErpif !response.valor or response.response is empty:    return error "No se encontró la denuncia"denuncia = response.response[0]if denuncia.archivo_denuncia != "":    denuncia.archivo_denuncia = BASE_CAPACITACION + denuncia.archivo_denunciareturn success with denuncia`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Utilidades(Consultar Utilidades (1)) - [getYearUtilidades]

## 🧾 Descripción

Este servicio obtiene:

1. **La lista de años registrados en el ERP** (tabla *Year*), ordenados de forma descendente.
2. **Valida si el empleado tiene utilidades asignadas** para al menos un año (tabla *Utilidades*).

El objetivo es determinar si el empleado cuenta con utilidades cargadas y retornar la lista de años disponibles para consulta.

---

## 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">**`POST /get-year-utilidades`**</span>

---

## 📥 Parámetros de entrada (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="949" data-start="782"><thead data-end="826" data-start="782"><tr data-end="826" data-start="782"><th data-col-size="sm" data-end="790" data-start="782">Campo</th><th data-col-size="sm" data-end="797" data-start="790">Tipo</th><th data-col-size="sm" data-end="811" data-start="797">Obligatorio</th><th data-col-size="md" data-end="826" data-start="811">Descripción</th></tr></thead><tbody data-end="949" data-start="872"><tr data-end="949" data-start="872"><td data-col-size="sm" data-end="883" data-start="872">employee</td><td data-col-size="sm" data-end="892" data-start="883">string</td><td data-col-size="sm" data-end="896" data-start="892">✔</td><td data-col-size="md" data-end="949" data-start="896">ID del empleado para validar si tiene utilidades.</td></tr></tbody></table>

</div></div>---

## 🔐 Seguridad

Utiliza autenticación mediante `ServiceErp()` (token interno del ERP).  
No requiere permisos adicionales, ya que solo consulta información.

---

## 🧠 Flujo del Servicio (explicación real)

### 1️⃣ Obtener los años disponibles (tabla Year)

Llama al ERP: `<span class="hljs-keyword">GET</span> <span class="hljs-keyword">Year</span>?limit<span class="hljs-operator">=</span><span class="hljs-keyword">None</span><span class="hljs-operator">&</span>fields<span class="hljs-operator">=</span>["name"]`

- Extrae todos los registros.
- Toma únicamente la columna `name`.
- Ordena los años de forma descendente.

---

### 2️⃣ Validar si el empleado tiene utilidades registradas

Consulta al ERP: `GET Utilidades?limit=None&fields=[<span class="hljs-string">"name"</span>]&filters=<span class="hljs-string">[["empleado","=", employee]]</span>`

- Si no existe ningún registro → El empleado **no tiene utilidades asignadas**.
- Si existe al menos un registro → El empleado **sí tiene utilidades asignadas**.

---

## 📤 Response 200 – Ejemplo

### Caso 1 — El empleado **NO tiene utilidades**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Hemos verificado que no tiene utilidades asignadas. Para más detalles, consultar con el área de RRHH"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"2023"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"2022"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Caso 2 — El empleado **SÍ tiene utilidades**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Hemos verificado que no tiene utilidades asignadas. Para más detalles, consultar con el área de RRHH"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"2023"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"2022"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>📌 *Nota:* El mensaje es el mismo en ambos escenarios, siguiendo el comportamiento del código original.

---

## ❗ Posibles Errores

<div class="_tableContainer_1rjym_1" id="bkmrk-caso-respuesta-error"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2614" data-start="2350"><thead data-end="2370" data-start="2350"><tr data-end="2370" data-start="2350"><th data-col-size="sm" data-end="2357" data-start="2350">Caso</th><th data-col-size="sm" data-end="2370" data-start="2357">Respuesta</th></tr></thead><tbody data-end="2614" data-start="2392"><tr data-end="2458" data-start="2392"><td data-col-size="sm" data-end="2424" data-start="2392">Error al obtener años del ERP</td><td data-col-size="sm" data-end="2458" data-start="2424">years → \[\] (no rompe el flujo)</td></tr><tr data-end="2504" data-start="2459"><td data-col-size="sm" data-end="2490" data-start="2459">Error de conexión con el ERP</td><td data-col-size="sm" data-end="2504" data-start="2490">years → \[\]</td></tr><tr data-end="2559" data-start="2505"><td data-col-size="sm" data-end="2539" data-start="2505">El empleado no tiene utilidades</td><td data-col-size="sm" data-end="2559" data-start="2539">`"valor": false`</td></tr><tr data-end="2614" data-start="2560"><td data-col-size="sm" data-end="2594" data-start="2560">El empleado sí tiene utilidades</td><td data-col-size="sm" data-end="2614" data-start="2594">`"valor": true"`</td></tr></tbody></table>

</div></div>---

## 📚 Tablas usadas (schemas)

### 📄 Year (GET)

Campos usados: `<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`

### 📄 Utilidades (GET)

Campos usados: `<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`

---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-employee-%3D-request.e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`employee = request.employeeyears = GET Yearyears = list of namessort years descutilidades = GET Utilidades where empleado = employeeif utilidades.count == 0:    return { valor: false, msn: "...", data: years }return { valor: true, msn: "...", data: years }`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Utilidades(Obtener Proceso de Descarga (1, 2, 3,4,5)) - [show]

## 🧾 Descripción

*Este servicio permite **consultar el último registro** almacenado en la tabla `historial_procesos_app` según:*

- Empleado
- Proceso
- (Opcional) Año
- (Opcional) Mes

Es usado para validar si un empleado ya realizó o no un proceso específico dentro del aplicativo.

---

# 🚀 Endpoint

**POST** `<span style="color: rgb(224, 62, 45);"><strong>/show</strong></span>`

---

# 📥 Parámetros de Entrada (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"descargaContratoTrabajo"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2025</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 🔎 Descripción de parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-oblig"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1133" data-start="809"><thead data-end="857" data-start="809"><tr data-end="857" data-start="809"><th data-col-size="sm" data-end="821" data-start="809">Parámetro</th><th data-col-size="sm" data-end="828" data-start="821">Tipo</th><th data-col-size="sm" data-end="842" data-start="828">Obligatorio</th><th data-col-size="sm" data-end="857" data-start="842">Descripción</th></tr></thead><tbody data-end="1133" data-start="906"><tr data-end="965" data-start="906"><td data-col-size="sm" data-end="917" data-start="906">empleado</td><td data-col-size="sm" data-end="926" data-start="917">string</td><td data-col-size="sm" data-end="930" data-start="926">✔</td><td data-col-size="sm" data-end="965" data-start="930">Código del empleado a consultar</td></tr><tr data-end="1020" data-start="966"><td data-col-size="sm" data-end="976" data-start="966">proceso</td><td data-col-size="sm" data-end="985" data-start="976">string</td><td data-col-size="sm" data-end="989" data-start="985">✔</td><td data-col-size="sm" data-end="1020" data-start="989">Nombre del proceso a buscar</td></tr><tr data-end="1077" data-start="1021"><td data-col-size="sm" data-end="1028" data-start="1021">anio</td><td data-col-size="sm" data-end="1034" data-start="1028">int</td><td data-col-size="sm" data-end="1038" data-start="1034">✖</td><td data-col-size="sm" data-end="1077" data-start="1038">Año del proceso (filtrado opcional)</td></tr><tr data-end="1133" data-start="1078"><td data-col-size="sm" data-end="1084" data-start="1078">mes</td><td data-col-size="sm" data-end="1090" data-start="1084">int</td><td data-col-size="sm" data-end="1094" data-start="1090">✖</td><td data-col-size="sm" data-end="1133" data-start="1094">Mes del proceso (filtrado opcional)</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Utiliza conexión directa a la base de datos `dbapp`.  
No requiere token ERP, pero depende de la autenticación interna del backend.

---

# 🧠 Flujo del Servicio (Resumen real)

1. **Validar parámetros obligatorios**
    
    
    - Si no se envía *empleado* → retorna error
    - Si no se envía *proceso* → retorna error
2. **Construir filtros dinámicos**
    
    
    - Base: empleado + proceso
    - Si llega año → se agrega al `WHERE`
    - Si llega mes → se agrega al `WHERE`
3. **Consultar la tabla interna**  
    Query sobre:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`historial_procesos_app<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> fecha <span class="hljs-keyword">DESC</span><span class="hljs-keyword">LIMIT</span> <span class="hljs-number">1</span>`</div></div>Utiliza `first()` para obtener el último registro.
4. **Validar si existe registro**
    
    
    - Si no existe, devuelve mensaje informando que no se encontró el proceso.
5. **Retornar información del proceso encontrado**  
    Incluye toda la fila obtenida desde la base de datos.

---

# 📤 Response 200 – Ejemplos

### ✅ Caso exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Proceso encontrado."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1524</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"descargaContratoTrabajo"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2025</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-03 09:32:11"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ Faltan parámetros

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta empleado."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta proceso."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ No existe el proceso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el proceso."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

1. **No se envía `empleado`**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta empleado."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
2. **No se envía `proceso`**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta proceso."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
3. **No se encontró el registro**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el proceso."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
4. **Error interno de base de datos**  
    (Puede retornar error 500 desde DB, manejado por Laravel)

---

# 📚 Estructura usada (historial\_procesos\_app)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-empleado-is-empty"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if empleado is empty → return errorif proceso is empty → return errorwhere = [    empleado = input.empleado,    proceso  = input.proceso]if anio present:    where.year = input.anioif mes present:    where.month = input.mesresult = DB.historial_procesos_app            .where(where)            .orderBy(fecha desc)            .first()if result is null:    return error "No se encontró el proceso"return success + result`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# CTS(Url CTS PDF (1)) - [pdfCTS]

### 🧾 Descripción

*Genera el **PDF de la Compensación por Tiempo de Servicios (CTS)** de un empleado para un periodo específico (mes y año).*  
*El servicio consulta la información almacenada en el ERP y retorna el archivo PDF ya renderizado desde una vista Blade (`pdf/cts`).*

También valida si la descarga está habilitada según la fecha definida por la empresa:

- CTS de **Mayo** se habilita **desde el 16 de mayo**
- CTS de **Noviembre** se habilita **desde el 16 de noviembre**

Si el usuario intenta descargar antes de esas fechas, el servicio lo bloquea.

---

# 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">**GET /pdf-cts/{employee}/{month}/{year}**</span>

### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-descr"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1038" data-start="835"><thead data-end="869" data-start="835"><tr data-end="869" data-start="835"><th data-col-size="sm" data-end="847" data-start="835">Parámetro</th><th data-col-size="sm" data-end="854" data-start="847">Tipo</th><th data-col-size="sm" data-end="869" data-start="854">Descripción</th></tr></thead><tbody data-end="1038" data-start="904"><tr data-end="943" data-start="904"><td data-col-size="sm" data-end="915" data-start="904">employee</td><td data-col-size="sm" data-end="924" data-start="915">string</td><td data-col-size="sm" data-end="943" data-start="924">ID del empleado</td></tr><tr data-end="994" data-start="944"><td data-col-size="sm" data-end="952" data-start="944">month</td><td data-col-size="sm" data-end="965" data-start="952">string/int</td><td data-col-size="sm" data-end="994" data-start="965">5 ó 11 (Mayo / Noviembre)</td></tr><tr data-end="1038" data-start="995"><td data-col-size="sm" data-end="1002" data-start="995">year</td><td data-col-size="sm" data-end="1015" data-start="1002">string/int</td><td data-col-size="sm" data-end="1038" data-start="1015">Año del cálculo CTS</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Este servicio requiere una **autenticación interna** mediante `apiService()` para consumir los datos del ERP.  
No necesita token del cliente, pero sí credenciales válidas para el ERP.

---

# 🧠 Flujo del Servicio (resumen real)

### 1️⃣ Validación del Mes

Convierte el mes recibido:

<div class="_tableContainer_1rjym_1" id="bkmrk-valor-recibido-se-in"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1472" data-start="1346"><thead data-end="1385" data-start="1346"><tr data-end="1385" data-start="1346"><th data-col-size="sm" data-end="1363" data-start="1346">Valor recibido</th><th data-col-size="sm" data-end="1385" data-start="1363">Se interpreta como</th></tr></thead><tbody data-end="1472" data-start="1425"><tr data-end="1445" data-start="1425"><td data-col-size="sm" data-end="1433" data-start="1425">`"5"`</td><td data-col-size="sm" data-end="1445" data-start="1433">`"MAYO"`</td></tr><tr data-end="1472" data-start="1446"><td data-col-size="sm" data-end="1455" data-start="1446">`"11"`</td><td data-col-size="sm" data-end="1472" data-start="1455">`"NOVIEMBRE"`</td></tr></tbody></table>

</div></div>### 2️⃣ Validación de Fecha de Bloqueo

El servicio verifica si la fecha actual está dentro del periodo permitido:

- Para **Mayo**:  
    📅 Debe ser **a partir del 16-05-&lt;año&gt;**
- Para **Noviembre**:  
    📅 Debe ser **a partir del 16-11-&lt;año&gt;**

Si aún no llega la fecha → se retorna:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CTS no habilitado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3️⃣ Obtiene la CTS del ERP

Se consulta la API del ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-compensacion-por-tie"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`Compensacion por Tiempo de Servicios?limit<span class="hljs-operator">=</span><span class="hljs-keyword">None</span><span class="hljs-operator">&</span>order_by<span class="hljs-operator">=</span>creation <span class="hljs-keyword">desc</span><span class="hljs-operator">&</span>filters<span class="hljs-operator">=</span>[   ["empleado","=","<employee>"],   ["mes","=","<MAYO/NOVIEMBRE>"],   ["año","=","<year>"]]<span class="hljs-operator">&</span>fields<span class="hljs-operator">=</span>[ ...campos... ]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Se recuperan campos como:

- remuneración computable
- días computables
- banco del empleado
- CTS total a pagar
- datos personales

Si no existen registros → retorna:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No cuenta con CTS para ese Periodo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 4️⃣ Genera el PDF

Si existe el registro, el servicio envía la información a la vista:

`resources/views/pdf/cts.blade.php`

Luego devuelve el PDF:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-return-pdf%3A%3Aloadview"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">return</span> PDF::<span class="hljs-title function_ invoke__">loadView</span>(<span class="hljs-string">"pdf/cts"</span>, <span class="hljs-variable">$dataPdf</span>)    -><span class="hljs-title function_ invoke__">setPaper</span>(<span class="hljs-string">'a4'</span>, <span class="hljs-string">'wrapper'</span>)    -><span class="hljs-title function_ invoke__">stream</span>();`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📥 Request Body

No utiliza body.

---

# 📤 Response – Ejemplo exitoso

El servicio no retorna JSON cuando es exitoso, sino un **PDF vía stream**, por lo que la respuesta es un archivo.

Ejemplo conceptual: `<PDF STREAM - <span class="hljs-built_in">CTS</span> Mayo <span class="hljs-number">2024</span>>`

---

# ❗ Posibles Errores

### 1. CTS no habilitado por fecha

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CTS no habilitado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. CTS inexistente para el periodo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No cuenta con CTS para ese Periodo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Parámetros mal enviados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Parametros No Validos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error interno del ERP

Retorna el error capturado del servicio `apiService()`.

---

# 📚 Schemas involucrados

### **Compensación por Tiempo de Servicios (CTS)**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dias_ausencias%22%3A-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dias_ausencias"</span><span class="hljs-punctuation">:</span> int<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dias_de_licencia_sin_goce"</span><span class="hljs-punctuation">:</span> int<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dias_de_descanso_medico"</span><span class="hljs-punctuation">:</span> int<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"descuento_de_dias_de_ausencia"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"promedio_remunerativo"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_de_compañia"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ruc"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ubicacion"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"MAYO/NOVIEMBRE"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"año"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cuenta_de_banco"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_de_banco"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"asignacion_familiar"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"gratificacion_entre_seis"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"horas_extras_entre_seis"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"horas_nocturnas_entre_seis"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"remuneracion_computable_cts"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"meses_computables_cts"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pago_meses"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dias_computables_cts"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pago_dias"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cts_total_a_pagar"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_de_documento"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-convert-month-to-may"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`convert month to MAYO/NOVIEMBREfechaBloqueo = (month == MAYO) ? "year-05-15" : "year-11-15"if hoy <= fechaBloqueo:    return CTS no habilitadodata = GET CTS where empleado, mes, añoif data empty:    return no CTS availablepdf = render view pdf/cts with datareturn pdf stream`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Reconocimiento de deuda( Url Reconocimiento de deuda PDF (1) ) - [debtRecognition]

## 🧾 Descripción

*Este servicio valida si un empleado tiene un **Reconocimiento de Deuda pendiente de firma**, y en caso afirmativo, **genera y descarga el archivo PDF del documento**, incluyendo el detalle de cuotas asociadas.*

*El servicio consume directamente información del ERP, consultando tanto el documento principal como sus tablas hijas (detalles de deuda por mes).*

---

## 🚀 Endpoint

<span style="color: rgb(224, 62, 45);">**POST /debt-recognition**</span>

### 📥 Parámetros

Recibe como parámetro directo el **ID del empleado**:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

El servicio requiere autenticación interna vía `dbErp()` para consultas SQL y usa `PDF::loadView()` para generar el documento final.

---

## 🧠 Flujo del Servicio (resumen real)

### 1. **Verifica si existe un Reconocimiento de Deuda pendiente**

Consulta en el ERP:

- Documento: **Reconociemientos de Deuda**
- Condiciones:
    
    
    - `docstatus = 0` (borrador)
    - `empleado = <employee>`
    - El archivo firmado **no existe** → `reconocimiento_escaneado_firmado IS NULL or = ''`

Si no encuentra ningún registro:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted no cuenta con un reconocimiento de deuda pendiente de firmar."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 2. **Obtiene los datos del Reconocimiento de Deuda**

Si existe un documento pendiente:

- Recupera el primer registro encontrado.
- Extrae datos generales del reconocimiento.

---

### 3. **Obtiene el detalle (tabla hija) del reconocimiento**

Consulta:

- Tabla hija: **tabtable\_reconocimiento\_deuda**
- Llaves:
    
    
    - `parent`: ID del reconocimiento
    - `parentfield = table_21`
    - `parenttype = Reconociemientos de Deuda`

Los campos recuperados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ano%22%3A-%22%22%2C-%22mes%22%3A-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ano"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">""</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 4. **Construye la data final**

Une:

- Información principal del reconocimiento (`dataEmployee`)
- Detalle de cuotas (`dataTable`)

---

### 5. **Genera el documento PDF**

Renderiza la vista:

**pdf/Doctype/ReconocimientoDeDeuda/reconocimiento\_de\_deuda.blade.php**

Y retorna la descarga del PDF.

---

## 📤 Response – Archivo PDF

El servicio retorna directamente un PDF generado con domPDF:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-content-type%3A-applic"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`Content-Type: application/pdfContent-Disposition: attachment; filename=<span class="hljs-string">"ReconocimientoDeDeuda.pdf"</span>`</div></div>No devuelve un JSON en caso de éxito, sino **una descarga directa del documento**.

---

## ❗ Posibles Errores

### 1. No existe reconocimiento pendiente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted no cuenta con un reconocimiento de deuda pendiente de firmar."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error en la consulta ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al obtener datos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Error inesperado en PDF o datos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error inesperado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schemas usados

### Reconociemientos de Deuda (principal)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"monto_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"decimal"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"reconocimiento_escaneado_firmado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### table\_reconocimiento\_deuda (detalle)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ano%22%3A-%22number%22%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ano"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"decimal"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Pseudocódigo del Servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-filters-%3D-%7B-docstatu"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`filters = { docstatus: <span class="hljs-number">0</span>, empleado: employee }recognition = GET ReconociemientosDeDeuda WHERE sin archivo firmado<span class="hljs-keyword">if</span> recognition vacío:    <span class="hljs-keyword">return</span> <span class="hljs-type">error</span><span class="hljs-variable">detail</span> <span class="hljs-operator">=</span> GET table_reconocimiento_deuda <span class="hljs-type">WHERE</span> <span class="hljs-variable">parent</span> <span class="hljs-operator">=</span> recognition.<span class="hljs-type">name</span><span class="hljs-variable">dataComplete</span> <span class="hljs-operator">=</span> {   dataEmployee: recognition,   dataTable: detail}<span class="hljs-keyword">return</span> PDF(dataComplete)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo de Solicitudes

# Solicitud de Adelanto( Solicitar de adelanto de sueldo (1) ) - [guardarAdelantosMensual]

## 🧾 Descripción

*Registra la **solicitud de adelanto salarial mensual** para un empleado, validando una serie de reglas de negocio relacionadas con:*

- Fecha permitida para solicitar adelanto
- Tipo de trabajador
- Área, puesto y compañía
- Situación laboral (activo/licencia)
- Contratos y antigüedad mínima
- Restricciones internas por área o cargo
- Estructura mensual del ERP (“Solicitud de Adelanto Mensual”)

El servicio crea o actualiza el registro correspondiente al empleado dentro del documento mensual de adelantos.

---

# 🚀 Endpoint

**POST** /guardar-adelantos-mensual/{employee}/{amount}

✔ **Recibe:**

- `employee` (string) — ID del empleado
- `amount` (int/string) — Monto seleccionado

---

# 🔐 Seguridad

Requiere autenticación del ERP (realizada internamente vía `ServiceErp()`).

---

# 🧠 Flujo del Servicio (lógica real)

### 1️⃣ Validación inicial del monto

- Si el monto es `"Seleccionar"` → **error**

### 2️⃣ Obtiene la ficha del empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-employee%2F%7Bemploy"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword"><span style="color: rgb(224, 62, 45);"><strong>GET</strong></span></span><span style="color: rgb(224, 62, 45);"><strong> Employee/{employee}</strong></span>`</div></div>Se validan:

- Compañía = "Shalom Empresarial"
- Estado = "Active"

### 3️⃣ Validaciones por fecha

- Solo se puede solicitar entre el **día 1 y 14**
- Excepción especial: julio 2023 (solo hasta el día 13)
- Si el empleado ingresó este mes y su día de ingreso ≥ 5 → no puede solicitar

### 4️⃣ Validaciones por tipo de trabajo

- Part time → máximo S/ 100
- Gerencia → no permitido
- Jefes o Supervisores (excepto Atención al cliente - SE)
- Administrativos (excepto Atención al cliente - SE)
- Conductores → prohibido solicitar

### 5️⃣ Validación de asistencia

Se verifica si hoy está con licencia:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-attendance%3Ffilte"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET Attendance?filters=[    employee=...,    <span class="hljs-built_in">status</span>=<span class="hljs-string">"On Leave"</span>,    attendance_date=hoy,    docstatus=<span class="hljs-number">1</span>]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si está con licencia → **no puede solicitar adelanto**.

### 6️⃣ Ubica o crea el documento mensual tipo "Solicitud de Adelanto Mensual"

Se busca:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-solicitud-de-ade"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Solicitud de Adelanto Mensual?filters<span class="hljs-operator">=</span>[  ["id","=",employee.id_sucursal],  ["mes","=",mesTexto],  ["anio","=",anio]]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Si **no existe**, se crea un nuevo documento para el mes

### 7️⃣ Registra o actualiza al trabajador dentro de la tabla interna `table_12`

- Si el empleado **no existe** → se crea un nuevo registro (POST)
- Si ya existe → se actualiza solo el campo `monto` (PUT)

### 8️⃣ Devuelve la respuesta con todos los registros procesados.

---

# 📥 Request Body

No recibe body (los parámetros son por URL).

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solicitud de adelanto registrado correctamente."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"SAL-MENS-0001"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"id_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">150</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"from_app"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Monto inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Seleccione un monto valido."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Empresa no permitida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solo se pueden solicitar los trabajadores de la compañia Shalom Empresarial"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Empleado deshabilitado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Su empleado se encuentra deshabilitado"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Fecha fuera de rango

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solo se pueden realizar solicitudes desde el día 01 hasta el 14 del mismo mes."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Restricción por área o tipo de empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Los conductores no pueden solicitar adelanto salarial."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 6. Empleado con licencia

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted se encuentra de licencia, no puede solicitar adelanto salarial."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 7. Error al crear documento mensual

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al registrar su solicitud de adelanto"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas utilizados

## Employee (GET Employee/{id})

Campos relevantes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22company%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"company"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"employment_type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"department"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_de_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"employee_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"branch"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_ingreso_real"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Y-m-d"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>## Solicitud de Adelanto Mensual (GET/POST)

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22int%22%2C-%22mes%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"departamento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>## Registro en tabla interna (table\_12)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id_empleado%22%3A-%22st"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_ingreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Y-m-d"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"from_app"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🧠 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-amount-%3D%3D-%22selecc"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if amount == "Seleccionar":    return erroremployeeData = GET Employee/{employee}validar empresa, estado, fecha, tipo, área, puesto...if falla alguna regla:    return errorvalidar licencia del díabuscar documento mensual de adelantosif no existe:    crear nuevo documentoobtener tabla interna del documentosi empleado no existe en table_12:    crear registroelse:    actualizar montoreturn éxito + registros modificados`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Solicitud de Adelanto(Estado solicitud (1,2,3,4) - Adelante de sueldo) - [show]

🧾 **Descripción**

*Este servicio permite obtener el **estado actual** de distintos procesos vinculados a un trabajador, tales como:*

- Cambio de cuenta bancaria
- Solicitud de licencia
- Asignación familiar
- Adelanto salarial del mes en curso

El servicio analiza dinámicamente el tipo de proceso solicitado.  
Si se envía un tipo de proceso específico, consulta su última solicitud pendiente.  
Si **no** se envía proceso, valida automáticamente si el trabajador tiene **adelanto salarial** en el mes actual y devuelve su estado.

📌 Es un servicio que depende totalmente de la API del ERP para obtener la información.

---

# 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/estado-solicitud`**</span>

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"licencia"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1588" data-start="1276"><thead data-end="1320" data-start="1276"><tr data-end="1320" data-start="1276"><th data-col-size="sm" data-end="1284" data-start="1276">Campo</th><th data-col-size="sm" data-end="1291" data-start="1284">Tipo</th><th data-col-size="sm" data-end="1305" data-start="1291">Obligatorio</th><th data-col-size="lg" data-end="1320" data-start="1305">Descripción</th></tr></thead><tbody data-end="1588" data-start="1365"><tr data-end="1420" data-start="1365"><td data-col-size="sm" data-end="1376" data-start="1365">empleado</td><td data-col-size="sm" data-end="1385" data-start="1376">string</td><td data-col-size="sm" data-end="1390" data-start="1385">✔️</td><td data-col-size="lg" data-end="1420" data-start="1390">Código del empleado en ERP</td></tr><tr data-end="1588" data-start="1421"><td data-col-size="sm" data-end="1431" data-start="1421">proceso</td><td data-col-size="sm" data-end="1440" data-start="1431">string</td><td data-col-size="sm" data-end="1451" data-start="1440">opcional</td><td data-col-size="lg" data-end="1588" data-start="1451">Tipo de solicitud a consultar (“cambio de cuenta”, “licencia”, “asignación familiar”). Si no se envía, se valida “adelanto salarial”.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere autenticación interna y comunicación con el ERP vía `dbErp()` y `ServiceErp()`.

---

# 🧠 Flujo del Servicio (resumen real)

### 🔸 1. Validación Inicial

Obtiene:

- mes actual
- año actual
- día actual

Define tablas ERP según el proceso solicitado.

---

### 🔸 2. Cuando **se envía un proceso específico**

Los procesos admitidos son:

<div class="_tableContainer_1rjym_1" id="bkmrk-proceso-enviado-tabl"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2283" data-start="1964"><thead data-end="2022" data-start="1964"><tr data-end="2022" data-start="1964"><th data-col-size="sm" data-end="1982" data-start="1964">Proceso enviado</th><th data-col-size="sm" data-end="2001" data-start="1982">Tabla consultada</th><th data-col-size="sm" data-end="2022" data-start="2001">Campo de relación</th></tr></thead><tbody data-end="2283" data-start="2081"><tr data-end="2147" data-start="2081"><td data-col-size="sm" data-end="2102" data-start="2081">"cambio de cuenta"</td><td data-col-size="sm" data-end="2135" data-start="2102">`tabCambio de Cuenta Bancaria`</td><td data-col-size="sm" data-end="2147" data-start="2135">empleado</td></tr><tr data-end="2206" data-start="2148"><td data-col-size="sm" data-end="2161" data-start="2148">"licencia"</td><td data-col-size="sm" data-end="2191" data-start="2161">`tabSolicitud de Licencias`</td><td data-col-size="sm" data-end="2206" data-start="2191">id\_empleado</td></tr><tr data-end="2283" data-start="2207"><td data-col-size="sm" data-end="2231" data-start="2207">"asignación familiar"</td><td data-col-size="sm" data-end="2268" data-start="2231">`tabSolicitud Asignacion Familiar`</td><td data-col-size="sm" data-end="2283" data-start="2268">id\_empleado</td></tr></tbody></table>

</div></div>El servicio:

1. Construye los filtros del ERP.
2. Busca la **última solicitud activa** (`docstatus < 2`).
3. Si no encuentra registros → devuelve un mensaje indicando que no existe solicitud.
4. Si existe:
    
    
    - Lee `motivo`
    - Lee `validacion_solicitud`
    - Lee `docstatus`
    - Devuelve estado traducido a texto.

Estados interpretados:

<div class="_tableContainer_1rjym_1" id="bkmrk-docstatus-estado-0-e"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2741" data-start="2628"><thead data-end="2650" data-start="2628"><tr data-end="2650" data-start="2628"><th data-col-size="sm" data-end="2640" data-start="2628">docstatus</th><th data-col-size="sm" data-end="2650" data-start="2640">Estado</th></tr></thead><tbody data-end="2741" data-start="2673"><tr data-end="2691" data-start="2673"><td data-col-size="sm" data-end="2677" data-start="2673">0</td><td data-col-size="sm" data-end="2691" data-start="2677">En proceso</td></tr><tr data-end="2708" data-start="2692"><td data-col-size="sm" data-end="2696" data-start="2692">1</td><td data-col-size="sm" data-end="2708" data-start="2696">Aprobado</td></tr><tr data-end="2723" data-start="2709"><td data-col-size="sm" data-end="2713" data-start="2709">2</td><td data-col-size="sm" data-end="2723" data-start="2713">Pagado</td></tr><tr data-end="2741" data-start="2724"><td data-col-size="sm" data-end="2728" data-start="2724">3</td><td data-col-size="sm" data-end="2741" data-start="2728">Rechazado</td></tr></tbody></table>

</div></div>---

### 🔸 3. Cuando **NO se envía proceso: Validación de adelanto salarial**

1. Obtiene el **adelanto salarial del mes** (`tabSolicitud de Adelanto Mensual` + tabla interna hija).
2. Si no existe solicitud → devuelve mensaje correspondiente.
3. Si existe, continúa:
    
    
    - Revisa si existe **Solicitud de Pagos** pagada relacionada al mes.
    - Si se encuentra, asigna estado "Pagado".
    - Si docstatus = 0 y el día es &gt;= 17, se marca como "Rechazado".
    - Caso contrario usa el estado según docstatus.

---

# 📤 Response 200 – Ejemplo de solicitud por proceso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Estado de la solicitud encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Actualización de datos"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"validacion_solicitud"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Pendiente"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-22 12:30:00"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"En proceso"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📤 Response 200 – Ejemplo para adelanto salarial

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Estado de la solicitud encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">300</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-18 15:04:22"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Pagado"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Proceso enviado no existe

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted no cuenta con una solicitud"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. No existen solicitudes del tipo indicado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted no cuenta con una solicitud de licencia"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. No existe adelanto salarial para el mes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted no ha solicitado un adelanto salarial para este mes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. Falla consultando al ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Hubo un inconveniente al consultar los datos."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Schemas (Estructuras utilizadas)

### Solicitud de Licencias

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"modified"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"docstatus"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"validacion_solicitud"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Solicitud Adelanto Mensual

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22mes%22%3A-%22string%22%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"docstatus"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"modified"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en pseudo-código simplificada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-request.proceso-e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if request.proceso exists:    tabla, where = procesos_config[proceso]    data = dbErp(tabla, where)    if empty(data):        return sin solicitud    estado = traducir_docstatus(data.docstatus)    return estado, motivo, fechaelse:    adelanto = dbErp(Solicitud Adelanto Mensual)    if no adelanto:        return "no ha solicitado"    if solicitud_pagos_pagada AND adelanto.docstatus == 1:        estado = Pagado    else if docstatus==0 AND día >=17:        estado = Rechazado    else:        estado = según tabla    return monto, fecha, estado`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Cambio de cuenta bancaria(Solicitar cambio de cuenta (1)) - [store]

## 🧾 Descripción

*Registra una nueva **solicitud de cambio de cuenta bancaria** para un empleado, validando previamente:*

- Que la información esté completa.
- Que el formato del número de cuenta coincida con las reglas del banco seleccionado.
- Que el empleado **no tenga ya una solicitud en estado Borrador**.
- Que se adjunte el documento de acreditación de la nueva cuenta bancaria.

*Si todo es correcto, crea un nuevo documento en el ERP: **`Cambio de Cuenta Bancaria`***

---

## 🚀 Endpoint

### **POST** `/cambio-cuenta-bancaria/store`

---

## 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nuevo_banco"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Banco de Crédito del Perú"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nueva_cuenta_bancaria"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678901234"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"documento_cuenta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/archivo.pdf"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1425" data-start="1093"><thead data-end="1137" data-start="1093"><tr data-end="1137" data-start="1093"><th data-col-size="sm" data-end="1101" data-start="1093">Campo</th><th data-col-size="sm" data-end="1108" data-start="1101">Tipo</th><th data-col-size="sm" data-end="1122" data-start="1108">Obligatorio</th><th data-col-size="sm" data-end="1137" data-start="1122">Descripción</th></tr></thead><tbody data-end="1425" data-start="1182"><tr data-end="1226" data-start="1182"><td data-col-size="sm" data-end="1193" data-start="1182">empleado</td><td data-col-size="sm" data-end="1202" data-start="1193">string</td><td data-col-size="sm" data-end="1207" data-start="1202">✔️</td><td data-col-size="sm" data-end="1226" data-start="1207">ID del empleado</td></tr><tr data-end="1278" data-start="1227"><td data-col-size="sm" data-end="1241" data-start="1227">nuevo\_banco</td><td data-col-size="sm" data-end="1250" data-start="1241">string</td><td data-col-size="sm" data-end="1255" data-start="1250">✔️</td><td data-col-size="sm" data-end="1278" data-start="1255">Nuevo banco elegido</td></tr><tr data-end="1353" data-start="1279"><td data-col-size="sm" data-end="1303" data-start="1279">nueva\_cuenta\_bancaria</td><td data-col-size="sm" data-end="1312" data-start="1303">string</td><td data-col-size="sm" data-end="1317" data-start="1312">✔️</td><td data-col-size="sm" data-end="1353" data-start="1317">Número de cuenta del nuevo banco</td></tr><tr data-end="1425" data-start="1354"><td data-col-size="sm" data-end="1373" data-start="1354">documento\_cuenta</td><td data-col-size="sm" data-end="1382" data-start="1373">string</td><td data-col-size="sm" data-end="1387" data-start="1382">✔️</td><td data-col-size="sm" data-end="1425" data-start="1387">Archivo previamente cargado en ERP</td></tr></tbody></table>

</div></div>---

## 🔐 Seguridad

Requiere autenticación interna mediante `ServiceErp()` y `dbErp()` hacia el ERP corporativo.

---

## 🧠 Flujo del Servicio (resumen real)

### **1. Validaciones iniciales**

- Verifica que todos los campos obligatorios estén presentes.
- Valida longitud del número de cuenta según el banco:

<div class="_tableContainer_1rjym_1" id="bkmrk-banco-longitudes-v%C3%A1l"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1882" data-start="1741"><thead data-end="1771" data-start="1741"><tr data-end="1771" data-start="1741"><th data-col-size="sm" data-end="1749" data-start="1741">Banco</th><th data-col-size="sm" data-end="1771" data-start="1749">Longitudes válidas</th></tr></thead><tbody data-end="1882" data-start="1803"><tr data-end="1820" data-start="1803"><td data-col-size="sm" data-end="1809" data-start="1803">BCP</td><td data-col-size="sm" data-end="1820" data-start="1809">14 o 20</td></tr><tr data-end="1843" data-start="1821"><td data-col-size="sm" data-end="1828" data-start="1821">BBVA</td><td data-col-size="sm" data-end="1843" data-start="1828">16, 18 o 20</td></tr><tr data-end="1867" data-start="1844"><td data-col-size="sm" data-end="1856" data-start="1844">Interbank</td><td data-col-size="sm" data-end="1867" data-start="1856">18 o 20</td></tr><tr data-end="1882" data-start="1868"><td data-col-size="sm" data-end="1876" data-start="1868">Otros</td><td data-col-size="sm" data-end="1882" data-start="1876">20</td></tr></tbody></table>

</div></div>Si no cumple → devuelve error.

---

### **2. Verifica si el empleado ya tiene una solicitud en estado Borrador**

Se consulta en el ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-cambio-de-cuenta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET Cambio de Cuenta <span class="hljs-type">Bancaria</span><span class="hljs-variable">filters</span> <span class="hljs-operator">=</span> [[<span class="hljs-string">"empleado"</span>,<span class="hljs-string">"="</span>, empleado],[<span class="hljs-string">"docstatus"</span>,<span class="hljs-string">"="</span>,<span class="hljs-number">0</span>]]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si ya existe un documento en borrador → error.

---

### **3. Registrar la nueva solicitud**

Si no existe borrador, crea el documento:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-resource%2Fcambio"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST resource/Cambio de Cuenta Bancaria{  <span class="hljs-string">"empleado"</span>: empleado,  <span class="hljs-string">"nombre_de_banco_nuevo"</span>: nuevo_banco,  <span class="hljs-string">"nuevo_num_de_cuenta_bancaria"</span>: nueva_cuenta_bancaria,  <span class="hljs-string">"documento_cuenta"</span>: documento_cuenta}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📤 Response 200 – Éxitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Registrado con éxito"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"response"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CCB-000123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"nombre_de_banco_nuevo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Banco de Crédito del Perú"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"nuevo_num_de_cuenta_bancaria"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678901234"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. Falta un dato obligatorio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe adjuntar un documento de acreditación de cuenta bancaria"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Número de cuenta inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Cantidad de dígitos de número de cuenta incorrecto"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Ya existe solicitud en borrador

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ya cuenta con una solicitud en Borrador pendiente de validar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error al registrar en ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al registrar el cambio de cuenta bancaria"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schemas utilizados

### **Cambio de Cuenta Bancaria (POST)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_de_banco_nuevo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nuevo_num_de_cuenta_bancaria"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"documento_cuenta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Consulta de solicitudes**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22-%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-faltan_datos%3A-ret"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if faltan_datos:    return errorvalidar_longitud_segun_banco()buscar_borrador = GET CambioCuentaBancaria where empleado and docstatus=0if existe_borrador:    return error "Ya cuenta con una solicitud"crear_documento = POST CambioCuentaBancaria {    empleado,    banco,    cuenta,    documento}return éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Solicitud de Licencias(Combo tipos de licencias (1)) - [combos]

## 🧾 Descripción

*Servicio que devuelve los valores preconfigurados para el combo **tipos\_licencias**, utilizado por el frontend o aplicación móvil para poblar listas desplegables relacionadas a licencias.*

*Este servicio **no realiza operaciones en base de datos**, no consume ERP ni APIs externas.*  
*Simplemente retorna valores estáticos cargados en la propiedad `$this->tipos_licencias`.*

---

## 🚀 Endpoint

**POST /combos**

No requiere parámetros.

---

## 🔐 Seguridad

No requiere validación adicional.  
El servicio solo retorna data estática, sin acceso a información sensible del ERP.

---

## 🧠 Flujo del Servicio (resumen real)

1. Obtiene el array interno `$this->tipos_licencias`, previamente definido en el controlador.
2. Construye un arreglo `combos` con la estructura:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24combos%5B%22tipos_licen"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable">$combos</span>[<span class="hljs-string">"tipos_licencias"</span>] = <span class="hljs-variable language_">$this</span>->tipos_licencias;`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>3. Retorna una respuesta JSON estándar:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"tipos_licencias"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>...<span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📥 Request Body

No requiere parámetros.  
Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</div></div>---

## 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"tipos_licencias"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"LICENCIA A1"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"LICENCIA A2A"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"LICENCIA A2B"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"LICENCIA A3A"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"LICENCIA A3B"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"LICENCIA A3C"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(La estructura real depende del contenido de `$this->tipos_licencias`.)*

---

## ❗ Posibles Errores

Este servicio **no genera errores internos**, pues no consulta APIs externas.  
Solo pueden ocurrir fallas del servidor:

### 1. Error por variable no definida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno: tipos_licencias no declarado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error inesperado del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor: <mensaje>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schemas (estructuras usadas)

### Response

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%7Cfals"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>|<span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"tipos_licencias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"array"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-function-combos%28requ"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`function combos(request):    combos = {}    combos["tipos_licencias"] = this.tipos_licencias    return {        valor: true,        data: combos    }`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Solicitud de Licencias(Solicitar solicitud de licencia (1)) - [store]

🧾 **Descripción**

*Crea una **Solicitud de Licencias** para un empleado, validando previamente:*

- Tipo de licencia permitido
- Fechas y rangos máximos establecidos por normativa interna
- Archivos obligatorios según el tipo de licencia
- Que el empleado no tenga otra solicitud en borrador

El servicio registra en el ERP un nuevo documento **"Solicitud de Licencias"** si cumple todas las reglas definidas.

---

# 🚀 Endpoint

### **POST /solicitud-licencias/store**

---

# 📥 Request Body – Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1609" data-start="821"><thead data-end="865" data-start="821"><tr data-end="865" data-start="821"><th data-col-size="sm" data-end="829" data-start="821">Campo</th><th data-col-size="sm" data-end="836" data-start="829">Tipo</th><th data-col-size="sm" data-end="850" data-start="836">Obligatorio</th><th data-col-size="md" data-end="865" data-start="850">Descripción</th></tr></thead><tbody data-end="1609" data-start="910"><tr data-end="954" data-start="910"><td data-col-size="sm" data-end="921" data-start="910">empleado</td><td data-col-size="sm" data-end="930" data-start="921">string</td><td data-col-size="sm" data-end="935" data-start="930">sí</td><td data-col-size="md" data-end="954" data-start="935">ID del empleado</td></tr><tr data-end="1047" data-start="955"><td data-col-size="sm" data-end="970" data-start="955">tip\_licencia</td><td data-col-size="sm" data-end="979" data-start="970">string</td><td data-col-size="sm" data-end="984" data-start="979">sí</td><td data-col-size="md" data-end="1047" data-start="984">Tipo de licencia (validado contra `$this->tipos_licencias`)</td></tr><tr data-end="1106" data-start="1048"><td data-col-size="sm" data-end="1060" data-start="1048">fecha\_ini</td><td data-col-size="sm" data-end="1067" data-start="1060">date</td><td data-col-size="sm" data-end="1072" data-start="1067">sí</td><td data-col-size="md" data-end="1106" data-start="1072">Fecha de inicio de la licencia</td></tr><tr data-end="1159" data-start="1107"><td data-col-size="sm" data-end="1119" data-start="1107">fecha\_fin</td><td data-col-size="sm" data-end="1126" data-start="1119">date</td><td data-col-size="sm" data-end="1131" data-start="1126">sí</td><td data-col-size="md" data-end="1159" data-start="1131">Fecha fin de la licencia</td></tr><tr data-end="1254" data-start="1160"><td data-col-size="sm" data-end="1181" data-start="1160">declaracion\_jurada</td><td data-col-size="sm" data-end="1192" data-start="1181">file/url</td><td data-col-size="sm" data-end="1202" data-start="1192">depende</td><td data-col-size="md" data-end="1254" data-start="1202">Obligatorio si tip\_licencia = "Familiar Enfermo"</td></tr><tr data-end="1351" data-start="1255"><td data-col-size="sm" data-end="1278" data-start="1255">hoja\_hospitalizacion</td><td data-col-size="sm" data-end="1289" data-start="1278">file/url</td><td data-col-size="sm" data-end="1299" data-start="1289">depende</td><td data-col-size="md" data-end="1351" data-start="1299">Obligatorio si tip\_licencia = "Familiar Enfermo"</td></tr><tr data-end="1431" data-start="1352"><td data-col-size="sm" data-end="1358" data-start="1352">uci</td><td data-col-size="sm" data-end="1369" data-start="1358">file/url</td><td data-col-size="sm" data-end="1379" data-start="1369">depende</td><td data-col-size="md" data-end="1431" data-start="1379">Obligatorio si tip\_licencia = "Familiar Enfermo"</td></tr><tr data-end="1517" data-start="1432"><td data-col-size="sm" data-end="1450" data-start="1432">acta\_nacimiento</td><td data-col-size="sm" data-end="1461" data-start="1450">file/url</td><td data-col-size="sm" data-end="1471" data-start="1461">depende</td><td data-col-size="md" data-end="1517" data-start="1471">Obligatorio si tip\_licencia = "Paternidad"</td></tr><tr data-end="1609" data-start="1518"><td data-col-size="sm" data-end="1535" data-start="1518">acta\_defuncion</td><td data-col-size="sm" data-end="1546" data-start="1535">file/url</td><td data-col-size="sm" data-end="1556" data-start="1546">depende</td><td data-col-size="md" data-end="1609" data-start="1556">Obligatorio si tip\_licencia = "Licencia Por Luto"</td></tr></tbody></table>

</div></div>---

# 🧠 Flujo del Servicio (resumen real)

1. **Validación de campos obligatorios**
    
    
    - Verifica empleado, tipo de licencia válido, fecha\_ini y fecha\_fin.
2. **Cálculo de días de licencia**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-variable">$dias</span> = (<span class="hljs-keyword">new</span> <span class="hljs-title class_">DateTime</span>(fecha_ini))-><span class="hljs-title function_ invoke__">diff</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">DateTime</span>(fecha_fin))->days;`</div></div>
3. **Validaciones específicas por tipo de licencia**
    
    <div class="_tableContainer_1rjym_1"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2265" data-start="1954"><thead data-end="2001" data-start="1954"><tr data-end="2001" data-start="1954"><th data-col-size="sm" data-end="1973" data-start="1954">Tipo de licencia</th><th data-col-size="md" data-end="1986" data-start="1973">Requisitos</th><th data-col-size="sm" data-end="2001" data-start="1986">Máximo días</th></tr></thead><tbody data-end="2265" data-start="2056"><tr data-end="2132" data-start="2056"><td data-col-size="sm" data-end="2079" data-start="2056">**Familiar Enfermo**</td><td data-col-size="md" data-end="2127" data-start="2079">declaracion\_jurada, hoja\_hospitalizacion, uci</td><td data-col-size="sm" data-end="2132" data-start="2127">7</td></tr><tr data-end="2177" data-start="2136"><td data-col-size="sm" data-end="2153" data-start="2136">**Paternidad**</td><td data-col-size="md" data-end="2171" data-start="2153">acta\_nacimiento</td><td data-col-size="sm" data-end="2177" data-start="2171">10</td></tr><tr data-end="2227" data-start="2181"><td data-col-size="sm" data-end="2205" data-start="2181">**Licencia Por Luto**</td><td data-col-size="md" data-end="2222" data-start="2205">acta\_defuncion</td><td data-col-size="sm" data-end="2227" data-start="2222">5</td></tr><tr data-end="2265" data-start="2231"><td data-col-size="sm" data-end="2255" data-start="2231">**Licencia sin goce**</td><td data-col-size="md" data-end="2259" data-start="2255">—</td><td data-col-size="sm" data-end="2265" data-start="2259">30</td></tr></tbody></table>
    
    </div></div>
4. **Validación: El empleado no debe tener una solicitud en borrador**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-selector-tag">GET</span> <span class="hljs-selector-tag">Solicitud</span> <span class="hljs-selector-tag">de</span> <span class="hljs-selector-tag">Licencias</span><span class="hljs-selector-tag">filters</span>: <span class="hljs-selector-attr">[[<span class="hljs-string">"id_empleado"</span></span>,<span class="hljs-string">"="</span>,empleado],<span class="hljs-selector-attr">[<span class="hljs-string">"docstatus"</span></span>,<span class="hljs-string">"="</span>,0]]`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
5. **Construcción del body para enviar al ERP**
    
    
    - Incluye campos adicionales dependiendo del tipo de licencia.
6. **Creación de la solicitud**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attribute">POST</span> resource/Solicitud de Licencias`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
7. **Retorno de respuesta estándar**

---

# 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solicitud de licencias enviada"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(El campo data retorna el borrador encontrado, si existía.)*

---

# ⚠️ Posibles Errores

### 1. Falta de parámetros

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Envie el empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Tipo de licencia inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Envie el tipo de licencia válido"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Fechas incompletas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Envie la fecha de inicio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Exceso de días permitidos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El rango de fecha no debe sobrepasar los 7 dias"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Documentación obligatoria faltante

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Suba su hoja de hospitalizacion"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 6. Solicitud duplicada en borrador

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se puede crear, Ya tiene una solicitud en borrador"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 7. Error al registrar en ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al crear la Solicitud de Licencias"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-empleado-vac%C3%ADo-%E2%86%92-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if empleado vacío → errorif tipo no permitido → errorif fechas vacías → errordias = fecha_fin - fecha_iniswitch tipo_licencia:    Familiar Enfermo:        validar documentos        validar dias <= 7    Paternidad:        validar acta_nacimiento        validar dias <= 10    Luto:        validar acta_defuncion        validar dias <= 5    Licencia sin goce:        validar dias <= 30buscar borradores:    GET Solicitud de Licencias where empleado & docstatus=0    si existe → errorbody = { empleado, tipo, fechas, documentos }crear solicitud:    POST Solicitud de Licenciassi ERP responde error → retornar errorretornar éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Estructuras usadas

### **Solicitud de Licencias (POST)**

Campos enviados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id_empleado%22%3A-%22st"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tip_licencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_ini"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-mm-dd"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_fin"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-mm-dd"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"declaracion_jurada"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"hoja_hospitalizacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"uci"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url (optional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"acta_nacimiento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url (optional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"acta_defuncion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url (optional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Asignación Familiar(Buscar dni empleado (1)) - [searchJobApplicant]

## 🧾 Descripción

*Este servicio consulta información de un postulante (Job Applicant) enviando su número de documento a un endpoint externo.*  
*El servicio actúa como un **proxy directo**: recibe un documento, llama por cURL al endpoint de EMPRESARIAL y retorna la respuesta tal cual viene de la API.*

No realiza validaciones ni transformaciones adicionales.

---

## 🚀 Endpoint interno

<span style="color: rgb(224, 62, 45);">**POST /search-job-applicant**</span>

---

## 📥 Parámetros de entrada (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22document%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"document"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campo | Tipo | Obligatorio | Descripción

\---|---|---|---  
document | string | Sí | Número de documento del postulante a buscar.

---

## 🔐 Seguridad

No usa autenticación interna ni tokens propios.  
El servicio simplemente reenvía el dato al endpoint: `POST {EMPRESARIAL}/api/search_job_applicant`

---

## 🧠 Flujo del Servicio (Resumen Real)

1. Recibe el campo `document` desde la solicitud.
2. Prepara una petición **cURL** hacia:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`{EMPRESARIAL}/api/search_job_applicant`</div></div>
3. Envía el documento como parámetro form-data:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">document</span> = <valor recibido>`</div></div>
4. Ejecuta la llamada.
5. Decodifica la respuesta JSON.
6. Retorna la data al cliente sin modificaciones.

---

## 📤 Respuesta 200 – Ejemplo

Respuesta depende totalmente del servicio externo.  
Un ejemplo típico puede ser:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JOB-00045"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"first_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Carlos"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"last_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Rojas"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Open"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"document"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"74581236"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. No se puede conectar con EMPRESARIAL

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se pudo conectar con el servicio externo"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. EMPRESARIAL devuelve error interno

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error desde API Empresarial"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...detalle del error... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Respuesta no válida o JSON corrupto

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Respuesta inesperada del servidor externo"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<response>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Esquema esperado desde el API externo (referencial)

El API no está documentado en tu código, pero normalmente una estructura de Job Applicant incluye:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"first_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"last_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"document"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*La estructura real depende 100% del sistema EMPRESARIAL.*

---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-document-%3D-request.d"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`document = request.documentcurl = init()curl.url = EMPRESARIAL + "api/search_job_applicant"curl.method = POSTcurl.postfields = { document: document }response = curl.execute()return json_decode(response)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🧩 Código documentado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%2F%2A%2A-%2A-servicio%3A-sear"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-comment">/** * Servicio: searchJobApplicant * * Descripción: * Busca información de un postulante enviando su documento al API externo EMPRESARIAL. * Este servicio actúa como un puente: manda el documento vía cURL y retorna la respuesta * sin transformaciones adicionales. * * Endpoint interno: * POST /search-job-applicant * * Parámetros: * - document (string): Documento de identidad del postulante. * * Flujo: * 1. Recibe el documento del request. * 2. Ejecuta cURL hacia EMPRESARIAL/api/search_job_applicant enviando el documento. * 3. Obtiene y decodifica la respuesta JSON. * 4. Retorna directamente la respuesta del servicio externo. * * Posibles errores: * - Fallo en la conexión cURL * - Respuesta inválida del servidor externo */</span><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span></span> <span class="hljs-title">searchJobApplicant</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>){    <span class="hljs-variable">$curl</span> = <span class="hljs-title function_ invoke__">curl_init</span>();    <span class="hljs-title function_ invoke__">curl_setopt_array</span>(<span class="hljs-variable">$curl</span>, <span class="hljs-keyword">array</span>(        CURLOPT_URL => EMPRESARIAL.<span class="hljs-string">'api/search_job_applicant'</span>,        CURLOPT_RETURNTRANSFER => <span class="hljs-literal">true</span>,        CURLOPT_ENCODING => <span class="hljs-string">''</span>,        CURLOPT_MAXREDIRS => <span class="hljs-number">10</span>,        CURLOPT_TIMEOUT => <span class="hljs-number">0</span>,        CURLOPT_FOLLOWLOCATION => <span class="hljs-literal">true</span>,        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,        CURLOPT_CUSTOMREQUEST => <span class="hljs-string">'POST'</span>,        CURLOPT_POSTFIELDS => <span class="hljs-keyword">array</span>(<span class="hljs-string">'document'</span> => <span class="hljs-variable">$request</span>->document),    ));    <span class="hljs-variable">$response</span> = <span class="hljs-title function_ invoke__">curl_exec</span>(<span class="hljs-variable">$curl</span>);    <span class="hljs-title function_ invoke__">curl_close</span>(<span class="hljs-variable">$curl</span>);    <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">json_decode</span>(<span class="hljs-variable">$response</span>,<span class="hljs-literal">true</span>);}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Asignación Familiar(Solicitar asignacion familiar (1)) - [store]

## 🧾 Descripción

Este servicio registra una **Solicitud de Asignación Familiar** para un empleado, validando previamente que:

1. Se hayan enviado las **dos imágenes del DNI** (anverso y reverso).
2. El empleado tenga un género válido y registrado.
3. No exista ya una asignación familiar duplicada para el mismo hijo (DNI del menor).
4. No existan más de dos solicitudes asociadas al mismo DNI de hijo (límite máximo permitido).

El registro se almacena directamente en el ERP mediante el recurso **Solicitud Asignacion Familiar**.

---

## 🚀 Endpoint

**POST** **<span style="color: rgb(224, 62, 45);">`/solicitud-asignacion-familiar`</span>**

---

## 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22dni%22%3A-%22string%22%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-MM-DD"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"edad"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">10</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"img_dni"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ruta/archivo1.png"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"reverso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ruta/archivo2.png"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Nombre del hijo"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"afiliacion_al_essalud"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

✔ Requiere autenticación interna vía `ServiceErp()` del ERP.  
✔ Se validan datos del empleado antes de crear la solicitud.

---

## 🧠 Flujo del Servicio (Resumen)

1. **Validación de archivos obligatorios**  
    Verifica que se envíen `img_dni` y `reverso`.  
    Si falta uno → retorna error.
2. **Obtiene datos del empleado**  
    Usa el método `verifyEmployeeGender($empleado)` para traer:
    
    
    - género
    - fecha de ingreso real
3. **Revisa si ya existe una solicitud similar**  
    Busca solicitudes para:
    
    
    - el mismo DNI del hijo
    - la misma fecha de ingreso del empleado
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">GET</span> Solicitud Asignacion Familiar<span class="hljs-symbol">filters:</span> dni_hijo, fecha_ingreso`</div></div>
4. **Valida duplicidades según reglas**
    
    
    - Si existe **1 solicitud previa**, compara géneros:
        
        
        - Si el género coincide → ❌ ya tiene asignación familiar.
    - Si existen **2 solicitudes previas** → ❌ no puede registrar más.
5. **Crea la nueva solicitud**  
    Realiza un POST hacia: `POST /resource/Solicitud Asignacion Familiar`
    
    Con los campos:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"edad_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni_doc"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"reverso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"afiliacion_al_essalud"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"..."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
6. **Retorna respuesta final**

---

## 📤 Response 200 – Ejemplos

### ✔ Registro exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Asignacion familiar registrada con exito"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Faltan imágenes del DNI

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe de enviar la 2 imagenes del DNI"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Asignación ya existente para el DNI del menor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Este dni ya cuenta con una asignacion familiar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ DNI ya usado en dos asignaciones previas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Este dni ya cuenta con dos asignaciones familiares"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error al registrar en el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al registrar la solicitud de asignacion familiar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schemas utilizados

### 🔹 Solicitud Asignacion Familiar (POST)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id_empleado%22%3A-%22st"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"edad_hijo"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-MM-DD"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni_doc"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"reverso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"afiliacion_al_essalud"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI/NO"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 🔹 Solicitud Asignacion Familiar (GET/FILTER)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"dni_hijo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_ingreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-MM-DD"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 🔹 Datos del empleado (verifyEmployeeGender)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22gender%22%3A-%22m%2Ff%22%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"gender"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"M/F"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_ingreso_real"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-MM-DD"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-falta-img_dni-o-r"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span> falta img_dni o reverso:    <span class="hljs-keyword">return</span> <span class="hljs-type">error</span>genderEmployee = verifyEmployeeGender(empleado)solicitudesPrevias = Buscar solicitudes por dni_hijo y fecha_ingreso<span class="hljs-keyword">if</span> count == <span class="hljs-number">1</span>:    otherGender = verifyEmployeeGender(solicitudesPrevias.id_empleado)    <span class="hljs-keyword">if</span> same gender:        <span class="hljs-keyword">return</span> <span class="hljs-type">error</span>: ya tiene asignación<span class="hljs-keyword">if</span> count >= <span class="hljs-number">2</span>:    <span class="hljs-keyword">return</span> <span class="hljs-type">error</span>: límite alcanzadobody = datos de asignación familiarguardar = POST Solicitud Asignacion Familiar<span class="hljs-keyword">if</span> <span class="hljs-type">error</span>:    <span class="hljs-keyword">return</span> <span class="hljs-type">error</span><span class="hljs-keyword">return</span> éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Solicitudes de Pagos(Obtener Lista de Solicitudes (1)) - [paymentRequestList]

## 🧾 Descripción

*Este servicio obtiene la **lista de solicitudes de pago** realizadas en el ERP, aplicando restricciones dependientes del usuario, su departamento y reglas de validación definidas por el área de Gerencia.*

El módulo:

- Valida si el usuario tiene configuraciones de **validación personalizadas** (`Validacion de Pagos Gerencia`).
- Filtra solicitudes de pago según:
    
    
    - Estado de validación
    - Concepto
    - Montos permitidos según reglas del usuario
    - Solicitudes de los últimos 6 meses
- Obtiene y agrupa los **archivos transados** (imágenes, documentos y archivos) asociados a cada solicitud.

Si el usuario **no está autorizado**, el módulo devuelve un mensaje de bloqueo.

---

# 🚀 Endpoint

### **POST /payment-request-list**

---

# 📥 Request Body

Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22department%22%3A-%22log"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"department"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LOGISTICA"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"concepto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Compras abastecimiento interno"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"usuario@empresa.com"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Validado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1471" data-start="1166"><thead data-end="1196" data-start="1166"><tr data-end="1196" data-start="1166"><th data-col-size="sm" data-end="1174" data-start="1166">Campo</th><th data-col-size="sm" data-end="1181" data-start="1174">Tipo</th><th data-col-size="md" data-end="1196" data-start="1181">Descripción</th></tr></thead><tbody data-end="1471" data-start="1228"><tr data-end="1278" data-start="1228"><td data-col-size="sm" data-end="1241" data-start="1228">department</td><td data-col-size="sm" data-end="1250" data-start="1241">string</td><td data-col-size="md" data-end="1278" data-start="1250">Departamento del usuario</td></tr><tr data-end="1331" data-start="1279"><td data-col-size="sm" data-end="1290" data-start="1279">concepto</td><td data-col-size="sm" data-end="1299" data-start="1290">string</td><td data-col-size="md" data-end="1331" data-start="1299">Concepto filtrado (opcional)</td></tr><tr data-end="1362" data-start="1332"><td data-col-size="sm" data-end="1342" data-start="1332">usuario</td><td data-col-size="sm" data-end="1351" data-start="1342">string</td><td data-col-size="md" data-end="1362" data-start="1351">User ID</td></tr><tr data-end="1471" data-start="1363"><td data-col-size="sm" data-end="1372" data-start="1363">status</td><td data-col-size="sm" data-end="1381" data-start="1372">string</td><td data-col-size="md" data-end="1471" data-start="1381">Estado de validación (opcional). Si es vacío, se excluyen "No requiere" y "Rechazado".</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere conexión válida con el ERP vía `dbErp()` y `ServiceErp()`.

---

# 🧠 Flujo del Servicio (resumen funcional)

### 1️⃣ Validación de permisos del usuario

Se consulta: `<span class="hljs-attribute">tabValidacion</span> de Pagos Gerencia`

Si no existe configuración para ese usuario:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El modulo esta inhabilitado para su departamento"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2️⃣ Construcción de filtros principales

- Se restringe a solicitudes con:
    
    
    - `estado_documento NOT IN ('Pago Rechazado')`
    - Fecha dentro de los últimos 6 meses.

Si existen reglas personalizadas:

- Se aplican límites de **concepto/monto** por cada configuración.
- Se agregan múltiples filtros OR en el WHERE.

### 3️⃣ Filtrado por estado

- Si se envía un estado explícito → búsqueda exacta.
- Si no → se excluyen `"No requiere"` y `"Rechazado"`.

### 4️⃣ Filtrado por concepto

Si el body incluye un concepto → se agrega un `WHERE concepto = X`.

### 5️⃣ Consulta principal

Se obtiene:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-name%2C-fecha%2C-estado_"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-type">name</span>, fecha, estado_de_validación, moneda,departamento, proveedor, ruc, concepto, monto,number_factura, voucher`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Desde: `tabSolicitud de Pagos`

### 6️⃣ Obtención de archivos transados

Por cada solicitud encontrada se consultan los archivos: `<span class="hljs-attribute">tabArchivos</span> Transados`

Clasifica:

- **Imagen** (.jpg, .jpeg, .png)
- **Documento** (.pdf, .xlsx, .xls)
- **Archivo** (otros)

Y asigna nombres:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-imagen-1-documento-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attribute">Imagen</span> <span class="hljs-number">1</span>Documento <span class="hljs-number">1</span>Archivo <span class="hljs-number">1</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 7️⃣ Construcción de la respuesta final

Cada solicitud incluye:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22archivos_transado"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"archivos_transados"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>...<span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"documento_factura"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"url o vacío"</span><span class="hljs-punctuation">,</span>  ...<span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de Solicitudes generada correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SP-0001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-10"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Validado"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"moneda"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PEN"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"departamento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LOGISTICA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"proveedor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Proveedor SAC"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ruc"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"20123456789"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"concepto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Transacción / Compensaciones"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1500</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"numero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"F001-12345"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"documento_factura"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/factura.pdf"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"archivos_transados"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>        <span class="hljs-punctuation">{</span>          <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ARCH-001"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SP-0001"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/file-download/123.jpg"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"nombre_archivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Imagen 1"</span>        <span class="hljs-punctuation">}</span>      <span class="hljs-punctuation">]</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❌ Posibles Errores

### 1️⃣ Usuario sin permisos para usar el módulo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El modulo esta inhabilitado para su departamento"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2️⃣ Error al cargar solicitudes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error al cargar la lista de solicitudes, intente nuevamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3️⃣ No existen solicitudes dentro de los filtros

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No existen solicitudes"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Tablas / Recursos Usados

### ✔ `tabValidacion de Pagos Gerencia`

Campos usados:

- usuario
- concepto
- monto

### ✔ `tabSolicitud de Pagos`

Campos:

- name, fecha, estado\_de\_validación, moneda, proveedor, ruc, concepto
- monto, number\_factura, voucher

### ✔ `tabArchivos Transados`

Campos:

- name, url, parent

---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-usuario_rules-%3D-get-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`usuario_rules = GET ValidacionPagos where usuario = Xif empty(usuario_rules):    return módulo inhabilitadobuild base filters:    estado_documento NOT IN ('Pago Rechazado')    fecha >= hoy - 6 mesesif usuario_rules exist:    for each rule:        add OR (concepto = rule.concepto AND monto > rule.monto)if status enviado:    add estado_de_validación = Xelse:    exclude ['No requiere', 'Rechazado']if concepto enviado:    add concepto = Xrequests = query SolicitudPagos with filtersif no requests:    return lista vacíaget archivos_transados for all requestsgroup and classify archivos by typereturn lista final con archivos agrupados`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Solicitudes de Pagos(Obtener Combos Conceptos (1)) - [getComboSolicitudPago]

🧾 **Descripción**

*Obtiene la lista de **conceptos permitidos** para un usuario específico, basándose en la tabla del ERP **"Validación de Pagos Gerencia"**.*

*El servicio filtra los registros por el usuario ingresado y retorna un **array único de conceptos** asociados a dicho usuario.*  
*Se utiliza para validar qué tipos de pagos puede solicitar un trabajador.*

---

# 🚀 Endpoint

### **POST /get-combo-solicitud-pago**

---

# 📥 Request Body

Debe incluir el campo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22correo"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"correo_o_user_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❗ Validación

Si **no se envía usuario**, responde:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe de ingresar el usuario correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🔐 Seguridad

El servicio usa el método interno `dbErp()` que requiere autenticación interna vía ERPNext.  
Por ello, se asume que el cliente ya cuenta con **token/credenciales válidas**.

---

# 🧠 Flujo del Servicio (Explicación Real)

1. **Validar parámetro usuario**
    
    
    - Si está vacío → responde error de validación.
2. **Construir filtros para ERP**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">WHERE</span> usuario <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>usuario<span class="hljs-operator">></span>`</div></div>
3. **Consultar al ERP**  
    Usando:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attribute">tabValidacion</span> de Pagos Gerencia`</div></div>con el SQL:
    
    
    - **SELECT** concepto
    - **FROM** `tabValidacion de Pagos Gerencia`
    - **WHERE** usuario = %(usuario)s
4. **Obtener resultados**
    
    
    - Se extrae la columna `concepto` de la respuesta.
    - Se eliminan duplicados mediante `array_unique`.
5. **Retornar los conceptos permitidos.**

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se encontró los conceptos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"Bonificación"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Viáticos"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Movilidad"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Pago Extraordinario"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Usuario no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe de ingresar el usuario correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Usuario sin conceptos asignados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se encontró los conceptos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>*(El servicio no devuelve error — solo retorna lista vacía.)*

### 3. Error del ERP

Si `dbErp()` falla internamente, el servicio responderá una lista vacía debido a su estructura actual.

---

# 📚 Tablas y Estructuras Usadas

### Tabla: `tabValidacion de Pagos Gerencia`

**Campos utilizados:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"concepto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-usuario-est%C3%A1-vac%C3%AD"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`IF usuario está vacío:    return errorfiltros = { usuario: usuario }data = ERP.dbErp(    table = "Validacion de Pagos Gerencia",    select = "concepto",    where usuario = usuario)conceptos = extraer columna "concepto"conceptos = eliminar duplicadosreturn { valor: true, data: conceptos }`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Solicitudes de Pagos(Validar Solicitud (1)) - [validatePaymentRequest]

## 🧾 Descripción

*Servicio encargado de **validar o rechazar** una Solicitud de Pagos en el ERP.*  
*Actualiza el campo **estado\_de\_validación** del documento Solicitud de Pagos y devuelve una respuesta indicando si la operación fue exitosa.*

*El servicio no procesa lógica adicional más allá de actualizar el estado del documento y devolver el resultado.*

---

## 🚀 Endpoint

### **PUT /validate-payment-request**

📩 **Recibe parámetros mediante el body del Request (Laravel Request)**:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22sp-00012%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SP-00012"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Validado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

Requiere autenticación contra el ERP, manejada internamente mediante: `<span class="hljs-variable language_">$this</span>->general-><span class="hljs-title function_ invoke__">ServiceErp</span>()`

No requiere headers adicionales desde el lado del cliente.

---

## 🧠 Flujo del Servicio (explicación real)

1. Recibe:
    
    
    - **name** → ID del documento (*Solicitud de Pagos*)
    - **status** → Puede ser `"Validado"` o `"Rechazado"`
2. Determina internamente mensajes para usuario según status:
    
    
    - `"Validado"` → aprobar
    - `"Rechazado"` → rechazar
3. Construye el body con el nuevo estado:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`[<span class="hljs-string">"estado_de_validación"</span> => <span class="hljs-variable">$request</span>->status]`</div></div>
4. Envía:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`PUT /resource/Solicitud de Pagos/{name}`</div></div>
5. Si el ERP responde con error → devuelve mensaje indicando fallo al aprobar o rechazar.
6. Si la operación es correcta → responde con:
    
    
    - valor = true
    - mensaje: "Solicitud de Pago Aprobado/Rechazado correctamente"
    - data → respuesta del ERP

---

## 📥 Request Body (Laravel)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string-%28i"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (ID del documento)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Validado | Rechazado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📤 Response 200 – Ejemplo (Aprobado)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solicitud de Pago Aprobado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SP-00012"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"estado_de_validación"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Validado"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Ejemplo (Rechazado)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solicitud de Pago Rechazado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SP-00012"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"estado_de_validación"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Rechazado"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. Error durante el PUT

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error al aprobar la Solicitud de Pago"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. El ERP responde con "valor = false"

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error al rechazar la Solicitud de Pago"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuesta del ERP... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Excepción inesperada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Surgió un error al aprobar la Solicitud de Pago"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ErrorException detail"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schema del documento afectado

### Solicitud de Pagos (PUT)

Campos utilizados: `<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"estado_de_validación"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`

---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-name-%3D-request.name-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`name = request.name<span class="hljs-built_in">status</span> = request.<span class="hljs-built_in">status</span>body = { estado_de_validación: <span class="hljs-built_in">status</span> }try:    response = PUT <span class="hljs-string">"Solicitud de Pagos/{name}"</span> with bodyexcept:    <span class="hljs-keyword">return</span> <span class="hljs-built_in">error</span> message<span class="hljs-keyword">if</span> response.valor == <span class="hljs-literal">false</span>:    <span class="hljs-keyword">return</span> <span class="hljs-built_in">error</span> message<span class="hljs-keyword">return</span> success response with custom message`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Cambio Salarial Administrativo(Empleados Activos (1)) - [getEmployeeActive]

## 🧾 Descripción

Servicio que obtiene el listado completo de **empleados activos** desde el ERP.  
Solo devuelve empleados cuyo `status = "active"` y expone información básica:

- `nombre_completo`
- `passport_number` (DNI u otro documento)
- `name` (ID interno del empleado)

Este servicio se utiliza para obtener la lista de empleados habilitados dentro del sistema.

---

## 🚀 Endpoint

**POST /get-employee-active**

📌 *El método es POST, pero internamente realiza una consulta GET al ERP.*

---

## 📥 Request Body

El servicio **no requiere parámetros en el body**.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</div></div>Todo se obtiene directamente del ERP mediante `ServiceErp()`.

---

## 🔐 Seguridad

Requiere conexión autorizada al ERP.  
La autenticación se maneja internamente mediante: `<span class="hljs-variable language_">$this</span>->general-><span class="hljs-title function_ invoke__">ServiceErp</span>(...)`

---

## 🧠 Flujo del Servicio (Resumen Real)

1. Construye la solicitud hacia el ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-employee-%3Flimit%3D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Employee?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>&fields=["nombre_completo","passport_number","name"]&filters=[["status","=","active"]]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>2. Envía la solicitud al ERP mediante:

<table border="1" id="bkmrk-%24this-%3Egeneral-%3Eserv" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable language_">$this</span>->general-><span class="hljs-title function_ invoke__">ServiceErp</span>(<span class="hljs-string">'GET'</span>, <span class="hljs-literal">null</span>, <span class="hljs-variable">$body</span>, APICAPACITACION . <span class="hljs-string">'resource/Employee'</span>);`</td></tr></tbody></table>

3. Verifica:
    
    
    - Si el ERP respondió con error.
    - Si no existen registros de empleados activos.
4. En caso de éxito:
    
    
    - Devuelve la lista completa de empleados encontrados.

---

## 📤 Response 200 – Ejemplo

### ✅ Caso exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Busqueda Existosa"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez López"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"45382910"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"HR-EMP-00231"</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ana Torres"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"72839201"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"HR-EMP-00412"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❗ Error interno del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno, cominique con soporte"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❗ Sin registros encontrados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron Registros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. Error en la llamada al ERP

Ocurre cuando `ServiceErp()` devuelve `valor = false`.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno, cominique con soporte"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. No existen empleados activos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron Registros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Error inesperado del servidor

*(si se implementara un try/catch)*

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor: <detalle>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schemas utilizados

### Employee (GET)

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td><div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</div></div></td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## 🗃 Lógica en Pseudo-Código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-body-%3D-%7B-limit-%3D-non"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`body = {    limit = none    fields = ["nombre_completo","passport_number","name"]    filters = [["status","=","active"]]}response = GET ERP Employee with bodyif response.valor == false:    return errorif response.data.count == 0:    return "No se encontraron registros"return {    valor: true,    msn: "Busqueda Existosa",    data: response.data}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Cambio Salarial Administrativo(Obtener Salario (1)) - [getEmployeeActive]

### 🧾 Descripción

Este servicio obtiene **todos los empleados activos** desde el ERP, retornando únicamente la información básica necesaria para listarlos:

- **nombre\_completo**
- **passport\_number**
- **name** (ID interno del empleado)

Es un servicio de consulta que solo consume los datos de la API del ERP usando `ServiceErp()`.

---

# 🚀 Endpoint

**GET /get-employee-active**

No recibe parámetros en el body; todo se obtiene del ERP.

---

# 🔐 Seguridad

Requiere autenticación válida hacia el ERP (manejada internamente por `ServiceErp()`).

---

# 🧠 Flujo del Servicio (Resumen Real)

1. Construye el body de consulta para el ERP:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"limit"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"none"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fields"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"nombre_completo"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"passport_number"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"name"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"filters"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">[</span><span class="hljs-string">"status"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"="</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"active"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
2. Realiza el request: `<span class="hljs-keyword">GET</span> Employee`
3. Valida:
    
    
    - Si hubo error en el ERP → retorna error.
    - Si la respuesta está vacía → retorna mensaje "No se encontraron registros".
4. Si hay resultados, retorna:
    
    
    - valor = true
    - msn = "Busqueda Exitosa"
    - data = lista de empleados activos

---

# 📥 Request Body

Este endpoint **no recibe body**.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</div></div>---

# 📤 Response 200 – Ejemplo

### ✔️ Con empleados encontrados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Busqueda Existosa"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ana Torres"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"87654321"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0002"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❗ Sin registros

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron Registros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error interno

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno, cominique con soporte"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1️⃣ Error del ERP

Ocurre cuando `ServiceErp()` retorna `"valor" => false`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno, cominique con soporte"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 2️⃣ No hay registros activos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{  <span class="hljs-attr">"valor"</span>: <span class="hljs-literal"><span class="hljs-keyword">false</span></span>,  <span class="hljs-attr">"msn"</span>: <span class="hljs-string">"No se encontraron Registros"</span>,  <span class="hljs-attr">"data"</span>: []}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3️⃣ Error inesperado en servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas Usados

## 📄 Employee (GET)

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-body-%3D-%7B-limit%3A-none"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`body = {    limit: none    fields: ["nombre_completo", "passport_number", "name"]    filters: [["status","=","active"]]}response = GET ERP Employeeif response.valor == false:    return errorif response.data is empty:    return no registrosreturn {    valor: true    msn: "Busqueda Exitosa"    data: response.data}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Cambio Salarial Administrativo(Actualizar Salario (1)) - [updateSalarialbyEmployee]

## 🧾 Descripción

Este servicio registra una **solicitud de actualización salarial** para un empleado.  
Envía al ERP los nuevos valores de:

- Sueldo
- Movilidad
- Bono nocturno
- Fecha de actualización

*El servicio **solo valida la estructura y los datos requeridos**, mientras que el proceso interno de aprobación o registro es manejado por el ERP a través del recurso **Cambio Salarial Administrativo**.*

---

## 🚀 Endpoint

**POST** **<span style="color: rgb(224, 62, 45);">`/update-salarial-by-employee`</span>**

---

## 📥 Request Body (JSON)

Todos los campos son **obligatorios**.

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1174" data-start="852"><thead data-end="882" data-start="852"><tr data-end="882" data-start="852"><th data-col-size="sm" data-end="860" data-start="852">Campo</th><th data-col-size="sm" data-end="867" data-start="860">Tipo</th><th data-col-size="sm" data-end="882" data-start="867">Descripción</th></tr></thead><tbody data-end="1174" data-start="914"><tr data-end="953" data-start="914"><td data-col-size="sm" data-end="925" data-start="914">empleado</td><td data-col-size="sm" data-end="934" data-start="925">string</td><td data-col-size="sm" data-end="953" data-start="934">ID del empleado</td></tr><tr data-end="998" data-start="954"><td data-col-size="sm" data-end="963" data-start="954">sueldo</td><td data-col-size="sm" data-end="972" data-start="963">number</td><td data-col-size="sm" data-end="998" data-start="972">Nuevo sueldo propuesto</td></tr><tr data-end="1048" data-start="999"><td data-col-size="sm" data-end="1011" data-start="999">movilidad</td><td data-col-size="sm" data-end="1020" data-start="1011">number</td><td data-col-size="sm" data-end="1048" data-start="1020">Nuevo monto de movilidad</td></tr><tr data-end="1100" data-start="1049"><td data-col-size="sm" data-end="1065" data-start="1049">bono\_nocturno</td><td data-col-size="sm" data-end="1074" data-start="1065">number</td><td data-col-size="sm" data-end="1100" data-start="1074">Monto de bono nocturno</td></tr><tr data-end="1174" data-start="1101"><td data-col-size="sm" data-end="1109" data-start="1101">fecha</td><td data-col-size="sm" data-end="1131" data-start="1109">string (YYYY-MM-DD)</td><td data-col-size="sm" data-end="1174" data-start="1131">Fecha de aplicación del cambio salarial</td></tr></tbody></table>

</div></div>### Ejemplo de entrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-00123"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sueldo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1500"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"movilidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"200"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"bono_nocturno"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"150"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

Requiere token válido del ERP (interno), administrado desde:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Egeneral-%3Eserv"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable language_">$this</span>->general-><span class="hljs-title function_ invoke__">ServiceErp</span>()`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🧠 Flujo del Servicio (resumen real)

1. **Valida que se hayan enviado todos los campos requeridos.**  
    Si falta alguno, retorna error.
2. **Valida formato de fecha** usando `validateDate()`.
3. **Construye el body** que será enviado al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22%3Cid%3E%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<id>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nuevo_sueldo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<sueldo>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nueva_movilidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<movilidad>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nuevo_bono_nocturno"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<bono nocturno>"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_actualizacion_date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<fecha>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>4. **Envía la solicitud al ERP**: `<span class="hljs-attribute">POST</span> resource/Cambio Salarial Administrativo`

5. **Devuelve al cliente el resultado**, incluyendo la respuesta del ERP.

---

## 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"¡Excelente! Se ha registrado exitosamente tu solicitud."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CSA-00045"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-00123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"nuevo_sueldo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1500"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"nueva_movilidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"200"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"nuevo_bono_nocturno"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"150"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha_de_actualizacion_date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. Campos faltantes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese los campos requeridos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Empleado vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese el empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Sueldo vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese el sueldo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Movilidad vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese la movilidad"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Bono nocturno vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese el Bono Nocturno"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 6. Fecha inválida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ingrese la fecha de actualizacion"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Schemas

### Cambio Salarial Administrativo (ERP)

Body enviado:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nuevo_sueldo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nueva_movilidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nuevo_bono_nocturno"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_de_actualizacion_date"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"YYYY-MM-DD"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-required-%3D-%5Bempleado"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`required = [empleado, sueldo, movilidad, bono_nocturno, fecha]<span class="hljs-keyword">if</span> falta alguno:    <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> fecha no válida:    <span class="hljs-keyword">return</span> errorbody = {    empleado,    nuevo_sueldo: sueldo,    nueva_movilidad: movilidad,    nuevo_bono_nocturno: bono_nocturno,    fecha_de_actualizacion_date: fecha}response = POST ERP Cambio Salarial Administrativo<span class="hljs-keyword">return</span> success with response`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Cambio de Sistema Pensionario(Sistema de Pension Combos (1)) - [combos]

## 🧾 Descripción

*Este servicio retorna un conjunto de listas predefinidas utilizadas en la aplicación móvil, específicamente los **tipos de AFP** disponibles para selección en formularios o procesos del sistema.*

*No realiza consultas a base de datos ni al ERP; solo devuelve información estática utilizada para poblar combos (selects) en la interfaz.*

*Es un servicio simple y de uso general dentro del módulo de onboarding o actualización de datos personales.*

---

## 🚀 Endpoint

**POST /combos**

Este servicio **no requiere parámetros** en el body ni en la URL.

---

## 🔐 Seguridad

Utiliza el flujo regular del controlador.  
No solicita autenticación directa dentro de la función, pero su acceso depende de la configuración del backend (middleware del módulo).

No realiza llamadas externas al ERP.

---

## 🧠 Flujo del Servicio (resumen real)

1. Define internamente una lista fija con los tipos de AFP:
    
    
    - AFP Habitat
    - AFP Profuturo
    - AFP Prima
    - AFP Integra
2. Organiza los datos dentro de un arreglo asociado a la clave `"tipos_afp"`.
3. Retorna un JSON con:
    
    
    - `valor: true`
    - `data: { "tipos_afp": [...] }`

---

## 📥 Request Body

Este servicio **no recibe parámetros**.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</div></div>---

## 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"tipos_afp"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"AFP Habitat"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"AFP Profuturo"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"AFP Prima"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"AFP Integra"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

Este servicio **no genera errores**, dado que devuelve datos estáticos.  
Sin embargo, errores genéricos podrían producirse por:

1. **Error interno del servidor**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno del servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

---

## 📚 Schemas usados

### **Respuesta del servicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"tipos_afp"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span> ...<span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-combos-%3D-%7B-%22tipos_af"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`combos = {    <span class="hljs-string">"tipos_afp"</span>: [        <span class="hljs-string">"AFP Habitat"</span>,        <span class="hljs-string">"AFP Profuturo"</span>,        <span class="hljs-string">"AFP Prima"</span>,        <span class="hljs-string">"AFP Integra"</span>    ]}<span class="hljs-keyword">return</span> {    valor: <span class="hljs-literal">true</span>,    <span class="hljs-keyword">data</span>: combos}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Cambio de Sistema Pensionario(Enviar solicitud cambio AFP (1)) - [store]

## 🧾 Descripción

Este servicio registra una **solicitud de cambio de sistema pensionario** para un empleado, validando previamente:

- Que el empleado exista.
- Que el sistema pensionario seleccionado sea válido (ONP o AFP).
- Que el tipo de AFP sea correcto cuando corresponda.
- Que no se intente cambiar al mismo sistema actual.
- Regla especial: si el empleado está en **ONP**, solo puede migrar a **AFP Integra**.
- Que no exista un documento previo en estado “Borrador”.
- Validación de estructura del **CUSPP** cuando aplica.

El servicio crea un nuevo documento en el ERP: `<span class="hljs-attribute">Solicitud</span> de Cambio de Sistema Pensionario`

---

# 🚀 Endpoint

**POST** `/cambio-sistema-pensionario/store`

---

# 🔐 Seguridad

- Requiere autenticación interna vía `ServiceErp()`.
- Solo accesible desde el backend con credenciales del ERP.

---

# 🧠 Flujo del Servicio (resumen real)

### 1. Validación de parámetros

El servicio valida:

- `empleado` obligatorio.
- `sistema_pensionario` debe ser `AFP` u `ONP`.
- Si es AFP → validar AFP válida.
- `tipo_cambio` debe estar dentro de:
    
    
    - `"ENTRE AFP"`
    - `"DE ONP A AFP"`
    - `"DE AFP A ONP"`

### 2. Trae los datos del empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-employee%2F%7Bemplea"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">GET</span> Employee/{empleado}`</div></div>Si el empleado no existe → error.

### 3. Determina si el cambio es permitido

Reglas del negocio:

- No puede cambiar al mismo sistema.
- Si está en ONP, solo puede pasar a AFP Integra.
- Cuando el cambio involucra AFP, se valida el **CUSPP**:
    
    
    - Longitud 12
    - Primeros 6 caracteres numéricos
    - Último caracter numérico

### 4. Verifica si ya existe una solicitud "Borrador"

Consulta a la base ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-name-from-%60ta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> <span class="hljs-type">name</span><span class="hljs-keyword">FROM</span> `tabSolicitud de Cambio de Sistema Pensionario`<span class="hljs-keyword">WHERE</span> id_empleado = <empleado> <span class="hljs-keyword">AND</span> docstatus = <span class="hljs-number">0</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si existe una, retorna error.

### 5. Crea la solicitud de cambio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-resource%2Fsolici"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST resource/Solicitud de Cambio de Sistema Pensionario{  <span class="hljs-string">"id_empleado"</span>: <empleado>,  <span class="hljs-string">"sistema_pensionario"</span>: <span class="hljs-string">"AFP"</span>|<span class="hljs-string">"ONP"</span>,  <span class="hljs-string">"tipo_de_afp"</span>: <span class="hljs-string">"..."</span>,  <span class="hljs-string">"tipo_cambio"</span>: <span class="hljs-string">"..."</span>,  <span class="hljs-string">"cuspp"</span>: <span class="hljs-string">"..."</span> <span class="hljs-comment">// cuando aplica</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📥 Request Body (ejemplo)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sistema_pensionario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AFP"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_afp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AFP Integra"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cuspp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"123456789012"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_cambio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DE ONP A AFP"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📤 Response 200 – Ejemplo

### ✔ Cambio enviado correctamente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solicitud de cambio de sistema pensionario enviada"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ Tipo de cambio inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La opción del tipo de cambio no es una opción valida (\"ENTRE AFP\",\"DE ONP A AFP\",\"DE AFP A ONP\")"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ Ya existe solicitud en borrador

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ya cuenta con una solicitud en Borrador pendiente de validar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ No puede cambiar al mismo sistema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No puede hacer el cambio al mismo sistema pensionario"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### ❌ Error al crear solicitud

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al crear la solicitud de cambio de sistema pensionario"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Validaciones importantes del servicio

### ✔ Validación de CUSPP

- Debe medir 12 caracteres.
- Primeros 6 numéricos.
- Último carácter numérico.

### ✔ Validación de sistema pensionario

- Solo **AFP** o **ONP**.
- Tipos válidos AFP:  
    `"AFP Habitat","AFP Profuturo","AFP Prima","AFP Integra"`.

### ✔ Regla especial ONP → AFP

Si el empleado está en ONP, solo puede migrar a AFP Integra:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if%28%24employee%5B%22respon"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span>(<span class="hljs-variable">$employee</span>[<span class="hljs-string">"response"</span>][<span class="hljs-string">"fondo_de_pensiones"</span>] == <span class="hljs-string">"ONP"</span> &&   <span class="hljs-variable">$sistema_pensionario</span> == <span class="hljs-string">"AFP"</span> &&   <span class="hljs-variable">$tipo_afp</span> != <span class="hljs-string">"AFP Integra"</span>)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-validar-par%C3%A1metros-e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`validar parámetrosemployee = GET Employee/{empleado}<span class="hljs-built_in">si</span> no existe -> error<span class="hljs-built_in">si</span> cambio no permitido -> errorbuscar solicitudes en Borrador para el empleado<span class="hljs-built_in">si</span> existe -> errorvalidar CUSPP <span class="hljs-built_in">si</span> aplicacrear documento:POST Solicitud de Cambio de Sistema Pensionarioretornar éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Módulo Centro de Ayuda

# Denuncias(Consultar Sucursal (1,2)) - [getBranchsDesignations]

🧾 **Descripción**

Servicio que obtiene dinámicamente:

- **La lista de sucursales activas con más de 1 empleado asignado**, o
- **La lista de puestos (Designations)** disponibles en el ERP,

dependiendo del parámetro `type` recibido en la solicitud.

Este servicio consulta directamente al ERP mediante los métodos internos `dbErp()` y `ServiceErp()`.

---

# 🚀 **Endpoint**

**POST** `/get-branchs-designations`

---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22type%22%3A-%22sucursal%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"type"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Sucursal"</span> | <span class="hljs-string">"Puesto"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Valores permitidos:

<div class="_tableContainer_1rjym_1" id="bkmrk-type-acci%C3%B3n-%22sucursa"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="929" data-start="759"><thead data-end="782" data-start="759"><tr data-end="782" data-start="759"><th data-col-size="sm" data-end="772" data-start="759">type</th><th data-col-size="md" data-end="782" data-start="772">Acción</th></tr></thead><tbody data-end="929" data-start="806"><tr data-end="868" data-start="806"><td data-col-size="sm" data-end="821" data-start="806">`"Sucursal"`</td><td data-col-size="md" data-end="868" data-start="821">Retorna sucursales con empleados asociados.</td></tr><tr data-end="929" data-start="869"><td data-col-size="sm" data-end="885" data-start="869">`"Puesto"`</td><td data-col-size="md" data-end="929" data-start="885">Retorna todos los puestos (Designation).</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

- Requiere autenticación interna del ERP.
- Las consultas se realizan vía `dbErp()` (SQL ERPNext) o `ServiceErp()` (REST del ERP).

---

# 🧠 **Flujo del Servicio**

## ✔️ Si type = `"Sucursal"`

1. Construye la consulta SQL:
    
    
    - Selecciona sucursales (`tabBranch`).
    - Hace JOIN con empleados (`tabEmployee`).
    - Agrupa y retorna solo sucursales con **más de 1 empleado registrado**.
2. Ejecuta la consulta vía:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`dbErp("POST", body, /<span class="hljs-keyword">method</span>/send-query-<span class="hljs-keyword">database</span>)`</div></div>
3. Si encuentra resultados:
    
    
    - Devuelve solo el nombre de la sucursal (`br.name`).
4. Si ocurre error:
    
    
    - Retorna mensaje de error controlado.

---

## ✔️ Si type = `"Puesto"`

1. Solicita al ERP la lista completa de Designations:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">GET</span> resource/Designation?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>`</div></div>
2. Extrae solo el nombre del puesto (`name`).
3. Devuelve la lista al cliente.

---

## ❌ Si type ≠ “Sucursal” ni “Puesto”

Retorna error indicando que la opción no es válida.

---

# 📤 **Response 200 – Ejemplos**

## ✔️ Respuesta para type = `"Sucursal"`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se encontraron sucursales"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"Sucursal Lima"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Sucursal Arequipa"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Sucursal Trujillo"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>## ✔️ Respuesta para type = `"Puesto"`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se encontraron puestos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"Asistente Administrativo"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Operario de Almacén"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"Jefe de Sucursal"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>## ❌ Opción no válida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Opcion no valida"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>## ❌ Error del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<detalle_del_error>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 **Schemas que utiliza**

### **Branch (SQL ERP)**

Campos relevantes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-br.name"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`br.name`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Employee**

Relacionada solo para contar empleados por sucursal:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-emp.branch-emp.name"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`emp.branchemp.name`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Designation**

Campos relevantes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22-%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 **Lógica en Pseudocódigo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-tipo-%3D-request%5B%22type"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`tipo = request["type"]if tipo == "Sucursal":    response = SQL:        SELECT br.name        FROM Branch br        LEFT JOIN Employee emp ON emp.branch = br.name        GROUP BY br.name        HAVING COUNT(emp.name) > 1    return nombres de sucursaleselse if tipo == "Puesto":    response = GET Designation    return lista de nameelse:    return error "Opción no válida"`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Denuncias(Crear demanda (1)) - [store]

## 🧾 Descripción

*Este servicio crea un registro oficial de una **denuncia interna** realizada por un colaborador o usuario del sistema.*  
*Permite registrar denuncias anónimas o identificadas, incluir detalles del hecho, denunciados, fechas, archivos adjuntos y otros campos relevantes.*

La información se almacena directamente en el ERP, creando un nuevo documento del tipo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-doctype%3A-denuncias"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-section">DocType: Denuncias</span>`</div></div>Incluye reglas de validación para asegurar que los datos enviados cumplan los requisitos mínimos según la normativa interna del área de cumplimiento.

---

## 🚀 Endpoint

**POST** `/denuncias/store`

---

## 🔐 Seguridad

Requiere autenticación interna:

- La creación se realiza vía `ServiceErp()`, que requiere un token válido del ERP.
- No se permiten denuncias sin validar los campos obligatorios.

---

## 🧠 Flujo del Servicio (Resumen Real)

1. **Lee parámetros del request:**
    
    
    - Identificación del denunciante
    - Datos de contacto (si aplica)
    - Motivo de denuncia
    - Fechas del hecho
    - Sucursal
    - Denunciados (en JSON)
    - Archivo adjunto
    - Otros detalles relacionados
2. **Valida que el JSON de denunciados sea correcto.**
3. **Ejecuta múltiples validaciones obligatorias:**
    
    
    - Si se identifica → celular y correo son obligatorios.
    - Campos `motivo`, `sucursal`, `desde`, `hasta`, `detalle` deben existir.
    - Si conoce involucrados → mínimo 1 y máximo 3 denunciados.
    - Cada denunciado debe tener nombre, sucursal y área.
4. **Valida y arma estructura del archivo adjunto** si se envía.
5. **Genera un código aleatorio único** que identificará la denuncia.
6. **Crea el documento Denuncias en el ERP:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /resource/Denuncias`</div></div>
7. **Guarda los denunciados como tabla hija (table\_16).**
8. **Devuelve confirmación y el código de seguimiento.**

---

## 📥 Request Body (Ejemplo)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22identificar%22%3A-1%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"identificar"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"celular"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"987654321"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"correo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"user@example.com"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Acoso laboral"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"continua_ocurriendo"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SUC-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"desde"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-01"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"hasta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"conoce_involucrados"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"denunciados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"[{\"nombre\":\"Juan Perez\",\"sucursal\":\"Lima\",\"area\":\"Operaciones\"}]"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"detalle"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Descripción detallada del hecho..."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"compromiso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ninguno"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"archivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"codigo-archivo.pdf"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🧪 Validaciones Importantes

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-requerido-cond"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3069" data-start="2643"><thead data-end="2676" data-start="2643"><tr data-end="2676" data-start="2643"><th data-col-size="sm" data-end="2651" data-start="2643">Campo</th><th data-col-size="sm" data-end="2663" data-start="2651">Requerido</th><th data-col-size="md" data-end="2676" data-start="2663">Condición</th></tr></thead><tbody data-end="3069" data-start="2711"><tr data-end="2748" data-start="2711"><td data-col-size="sm" data-end="2725" data-start="2711">identificar</td><td data-col-size="sm" data-end="2730" data-start="2725">Sí</td><td data-col-size="md" data-end="2748" data-start="2730">Debe ser 0 o 1</td></tr><tr data-end="2806" data-start="2749"><td data-col-size="sm" data-end="2767" data-start="2749">celular, correo</td><td data-col-size="sm" data-end="2801" data-start="2767">Obligatorios si identificar = 1</td><td data-col-size="md" data-end="2806" data-start="2801">—</td></tr><tr data-end="2826" data-start="2807"><td data-col-size="sm" data-end="2816" data-start="2807">motivo</td><td data-col-size="sm" data-end="2821" data-start="2816">Sí</td><td data-col-size="md" data-end="2826" data-start="2821">—</td></tr><tr data-end="2848" data-start="2827"><td data-col-size="sm" data-end="2838" data-start="2827">sucursal</td><td data-col-size="sm" data-end="2843" data-start="2838">Sí</td><td data-col-size="md" data-end="2848" data-start="2843">—</td></tr><tr data-end="2894" data-start="2849"><td data-col-size="sm" data-end="2871" data-start="2849">continua\_ocurriendo</td><td data-col-size="sm" data-end="2876" data-start="2871">Sí</td><td data-col-size="md" data-end="2894" data-start="2876">Debe ser 0 o 1</td></tr><tr data-end="2936" data-start="2895"><td data-col-size="sm" data-end="2911" data-start="2895">desde / hasta</td><td data-col-size="sm" data-end="2916" data-start="2911">Sí</td><td data-col-size="md" data-end="2936" data-start="2916">Fechas del hecho</td></tr><tr data-end="2973" data-start="2937"><td data-col-size="sm" data-end="2959" data-start="2937">conoce\_involucrados</td><td data-col-size="sm" data-end="2964" data-start="2959">Sí</td><td data-col-size="md" data-end="2973" data-start="2964">0 o 1</td></tr><tr data-end="3048" data-start="2974"><td data-col-size="sm" data-end="2988" data-start="2974">denunciados</td><td data-col-size="sm" data-end="3002" data-start="2988">Condicional</td><td data-col-size="md" data-end="3048" data-start="3002">1 a 3 registros si conoce\_involucrados = 1</td></tr><tr data-end="3069" data-start="3049"><td data-col-size="sm" data-end="3059" data-start="3049">detalle</td><td data-col-size="sm" data-end="3064" data-start="3059">Sí</td><td data-col-size="md" data-end="3069" data-start="3064">—</td></tr></tbody></table>

</div></div>Si el archivo existe, se formatea a: `https:<span class="hljs-comment">//fileserver.shalomcontrol.com/file-view/<archivo></span>`

---

## 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td><div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se registró correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"codigo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ABC123"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</div></div></td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

## ❗ Posibles Errores

### 1. JSON malformado en denunciados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El campo denunciados debe ser un json codificado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Campos obligatorios faltantes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe ingresar un celular"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Número incorrecto de denunciados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solo puede ingresar hasta 3 denunciados como máximo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error al registrar en el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al registrar"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"response"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Error inesperado del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al registrar"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"exception"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Esquema del DocType Denuncias (Campos usados)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22identificar%22%3A-%220%7C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"identificar"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0|1"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"celular"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"correo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"continua_ocurriendo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0|1"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"desde"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"hasta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"conoce_involucrados"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"detalle"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"compromiso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"archivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado_denuncias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PENDIENTE"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"doctype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Denuncias"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"table_16"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"codigo_aleatorio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-leer-todos-los-campo"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`leer todos los campos <span class="hljs-built_in">del</span> requestvalidar denunciados (JSON)validar campos uno por uno<span class="hljs-built_in">si</span> identificar == <span class="hljs-number">1</span>:    validar celular & correo<span class="hljs-built_in">si</span> conoce_involucrados == <span class="hljs-number">1</span>:    validar entre <span class="hljs-number">1</span> a <span class="hljs-number">3</span> denunciados<span class="hljs-built_in">si</span> hay archivo:    generar url públicagenerar codigo aleatorioarmar payload <span class="hljs-built_in">del</span> ERPinsert = POST /resource/Denuncias<span class="hljs-built_in">si</span> insert falla:    retornar errorretornar success + codigo`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Denuncias(Url Demanda PDF (1)) - [pdf]

## 🧾 Descripción

*Este servicio obtiene la información completa de una denuncia registrada en el ERP (Frappe/ERPNext), validando primero que exista una denuncia cuyo **código aleatorio** coincida con el parámetro enviado.*

Una vez encontrada:

1. Obtiene la información principal de la denuncia.
2. Consulta nuevamente la denuncia para traer sus tablas hijas (por ejemplo table\_16).
3. Construye un array final con los datos completos.
4. Genera un **PDF oficial de la denuncia** usando una plantilla Blade.
5. Retorna el archivo descargable **Demanda.pdf**.

Este servicio se utiliza para permitir a los usuarios descargar un reporte o constancia oficial de la denuncia registrada.

---

## 🚀 Endpoint

**GET /pdf/{codigo}**

📌 *El parámetro `{codigo}` corresponde al campo `codigo_aleatorio` de la denuncia.*

---

## 📥 Parámetros

### URL Params

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-oblig"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1277" data-start="1109"><thead data-end="1157" data-start="1109"><tr data-end="1157" data-start="1109"><th data-col-size="sm" data-end="1121" data-start="1109">Parámetro</th><th data-col-size="sm" data-end="1128" data-start="1121">Tipo</th><th data-col-size="sm" data-end="1142" data-start="1128">Obligatorio</th><th data-col-size="md" data-end="1157" data-start="1142">Descripción</th></tr></thead><tbody data-end="1277" data-start="1206"><tr data-end="1277" data-start="1206"><td data-col-size="sm" data-end="1217" data-start="1206">`codigo`</td><td data-col-size="sm" data-end="1226" data-start="1217">string</td><td data-col-size="sm" data-end="1230" data-start="1226">✔</td><td data-col-size="md" data-end="1277" data-start="1230">Código aleatorio que identifica la denuncia</td></tr></tbody></table>

</div></div>📌 *No recibe parámetros en el body.*

---

## 🔐 Seguridad

El servicio realiza llamadas internas al ERP a través de **ServiceErp()**, por lo que requiere autenticación válida configurada internamente.  
No necesita token desde el cliente.

---

## 🧠 Flujo del Servicio (Resumen real)

### 1️⃣ Buscar denuncia por código aleatorio

Realiza un GET al recurso: `GET Denuncias?filters=<span class="hljs-string">[["codigo_aleatorio","=",<codigo>]]</span>`

Si no encuentra coincidencias → retorna error.

---

### 2️⃣ Para cada denuncia encontrada

Hace un GET para traer la información completa del documento con sus tablas hijas: `<span class="hljs-keyword">GET</span> Denuncias/{<span class="hljs-type">name</span>}`

Guarda el contenido de la tabla `table_16` y arma un arreglo final.

---

### 3️⃣ Generar el PDF

Usa: `<span class="hljs-variable constant_">PDF</span><span class="hljs-symbol">:</span><span class="hljs-symbol">:loadView</span>(<span class="hljs-string">"pdf/demanda"</span>, [<span class="hljs-string">"data"</span> => <span class="hljs-variable">$demandas_final</span>[<span class="hljs-number">0</span>]])`

Lo genera en tamaño **A5**, orientación **portrait**, y lo retorna como descarga: `Demanda.pdf`

---

## 📤 Response – Ejemplo exitoso (PDF descargable)

El navegador descargará directamente: `Demanda.pdf`

Con el contenido renderizado desde la vista `pdf/demanda.blade.php`.

---

## ❗ Posibles Errores

### 1. No existe la denuncia

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la denuncia"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error consultando el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje de la excepción>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. La denuncia existe, pero falla la obtención completa

(No rompe el flujo; simplemente ignora la denuncia afectada.)

---

## 📚 Schemas utilizados

### Denuncias (GET)

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"name"</span>: <span class="hljs-string">"string"</span>,  <span class="hljs-string">"codigo_aleatorio"</span>: <span class="hljs-string">"string"</span>,  <span class="hljs-string">"table_16"</span>: [ ... ],  ...otros campos}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### PDF Output

Basado en la vista: `resources/views/pdf/demanda.blade.php`

---

## 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-body-%3D-%7B-filters%3A-%5B%5B"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`body = {    filters: <span class="hljs-string">[["codigo_aleatorio", "=", codigo]]</span>,    fields: [<span class="hljs-string">"*"</span>]}demandas = GET Denuncias WHERE codigo_aleatorio=codigo<span class="hljs-keyword">if</span> demandas is empty:    <span class="hljs-keyword">return</span> <span class="hljs-built_in">error</span><span class="hljs-built_in">foreach</span> denuncia <span class="hljs-keyword">in</span> demandas:    detalle = GET Denuncias/{name}    agregar table_16 al resultado finalgenerar PDF usando vista <span class="hljs-string">"pdf/demanda"</span>retornar archivo: Demanda.pdf`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Denuncias(Consultar demanda (1)) - [obtener]

### 🧾 Descripción

Permite **consultar una denuncia registrada** en el ERP usando un **código aleatorio** como identificador de búsqueda.

El servicio:

- Recibe un código único (`codigo`) enviado al usuario.
- Busca en el ERP la denuncia asociada.
- Retorna sus datos principales (estado, creación, fechas de proceso, archivo adjunto, etc.)
- Ajusta la URL del archivo si existe.

Es un servicio utilizado para que un usuario pueda revisar:

- El estado de su denuncia,
- La respuesta del área responsable,
- Y descargar el archivo asociado (si lo tiene).

---

# 🚀 Endpoint

### **POST /obtener**

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22codigo%22%3A-%22string%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"codigo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1107" data-start="925"><thead data-end="972" data-start="925"><tr data-end="972" data-start="925"><th data-col-size="sm" data-end="934" data-start="925">Campo</th><th data-col-size="sm" data-end="943" data-start="934">Tipo</th><th data-col-size="sm" data-end="957" data-start="943">Obligatorio</th><th data-col-size="md" data-end="972" data-start="957">Descripción</th></tr></thead><tbody data-end="1107" data-start="1021"><tr data-end="1107" data-start="1021"><td data-col-size="sm" data-end="1030" data-start="1021">codigo</td><td data-col-size="sm" data-end="1039" data-start="1030">string</td><td data-col-size="sm" data-end="1053" data-start="1039">✔️ Sí</td><td data-col-size="md" data-end="1107" data-start="1053">Código aleatorio generado al registrar la denuncia</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere autenticación interna mediante  
`$this->general->ServiceErp()`  
(usa cookies o token ya configurado en el backend).

---

# 🧠 Flujo del Servicio (resumen real)

1. **Obtiene el código** enviado en el request.
2. Construye el body para consultar la denuncia en el ERP:
    
    
    - fields: name, creation, estado\_denuncias, fechas, archivo, respuesta.
    - filters: `[["codigo_aleatorio","=", $codigo]]`
3. Llama al ERP:  
    `GET resource/Denuncias`
4. Si **no existe denuncia**, retorna error.
5. Si existe:
    
    
    - Verifica si `archivo_denuncia` no está vacío.
    - Si tiene archivo, le agrega la URL base del servidor.
6. Retorna toda la información encontrada.

---

# 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td><div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Encontrado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DEN-00012"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-10 12:40:15"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"estado_denuncias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Atendido"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-18"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha_proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"archivo_denuncia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"https://dominio.com/files/denuncia_12.pdf"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"respuesta_de_denuncia_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se realizó la evaluación correspondiente."</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</div></div></td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1️⃣ Denuncia no encontrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la denuncia"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2️⃣ Error en la comunicación con el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor: <detalle>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3️⃣ Respuesta vacía del ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró la denuncia"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Esquema utilizado (Denuncias – GET)

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado_denuncias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"archivo_denuncia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"respuesta_de_denuncia_atendido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-codigo-%3D-request.cod"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`codigo = request.codigobody = {    limit: None,    fields: [name, creation, estado_denuncias, fecha_atendido, fecha_proceso, archivo_denuncia, respuesta_de_denuncia_atendido],    filters: [["codigo_aleatorio", "=", codigo]]}response = GET Denuncias(body)if response is error or empty:    return error "No se encontró la denuncia"denuncia = response[0]if denuncia.archivo_denuncia != "":    denuncia.archivo_denuncia = BASE_CAPACITACION + denuncia.archivo_denunciareturn success data = denuncia`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo Convocatorias

# Lista de convocatorias internas (1) - [getInternalCalls]

🧾 **Descripción**

*Obtiene todas las **convocatorias internas vigentes** dentro del ERP, incluyendo información del puesto, sede y su archivo adjunto (PDF u otro documento del Job Opening).*  
El servicio cruza información entre:

- **Job Opening**
- **File** (archivos adjuntos al Job Opening)

Solo trae convocatorias internas **activas (status = "Open")** y marcadas como **convocatoria interna = 1**.

---

# 🚀 Endpoint

**GET /get-internal-calls**

> No recibe parámetros.  
> Toda la información se obtiene mediante apiService() hacia el ERP.

---

# 🔐 Seguridad

Requiere conexión autorizada vía `apiService()`, usando token interno del ERP.

---

# 🧠 Flujo del Servicio (Resumen)

1. **Obtener todos los Job Openings internos activos**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Job Opening?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>    &fields=["name","designation","sucursal"]    &filters=[        ["convocatoria_interna","=",<span class="hljs-number">1</span>],        ["status","=","Open"]    ]`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
2. **Obtener todos los archivos relacionados al Job Opening**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> File?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>    &fields=["name","attached_to_name","file_url"]    &filters=[["attached_to_doctype","=","Job Opening"]]`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
3. Si alguno de los endpoints devuelve error, se retorna:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al buscar las convocatorias internas."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
4. Si no hay convocatorias abiertas:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"En este momento no hay convocatorias internas..."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
5. Para cada convocatoria se agrega:
    
    
    - La descripción de la sede: `"PARA LA SEDE {sucursal}"`
    - El archivo correspondiente (`file_url`), si existe.
6. Se retorna listado de convocatorias internas enriquecidas.

---

# 📥 Request Body

No tiene body.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</div></div>---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Convocatorias internas encontradas"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JOB-0001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Analista de Operaciones"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIMA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"sede"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PARA LA SEDE LIMA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"file"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"https://dominio.com/files/job_0001.pdf"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Error en consulta de Job Opening

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al buscar las convocatorias internas."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Error en consulta de archivos File

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al buscar las convocatorias internas."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. No existen convocatorias internas activas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"En este momento no hay convocatorias internas, Estar atento a las proximas convocatorias"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. Error inesperado del servidor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<error completo>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Esquemas (estructuras utilizadas)

### Job Opening

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### File

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"attached_to_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"file_url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Pseudo-código de la lógica

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-jobs-%3D-get-job-openi"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`jobs = GET Job Opening internas y abiertasif jobs vacío → return no hay convocatoriasfiles = GET File adjuntos a Job Openingfor job in jobs:    job.sede = "PARA LA SEDE " + job.sucursal    job.file = ""    for file in files:        if file.attached_to_name == job.name:            job.file = BASE_CAPACITACION + file.file_urlreturn lista de jobs con su archivo si existe`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Obtiene combos (1) - [combosJobApplicant]

🧾 **Descripción**

*Este servicio obtiene y devuelve todos los combos (listas de valores) necesarios para el registro o postulación de un **Job Applicant** (Postulante) dentro del sistema.*

*Los datos se obtienen directamente desde el ERP mediante el método interno `getCombo()`, que consulta tablas maestras como Country, Branch, Department y Gender.*

*Además, incluye una lista estática de tipos de documentos admitidos (DNI, Pasaporte, Carnet de Extranjería)*.

---

# 🚀 Endpoint

**GET /combos-job-applicant**

No requiere parámetros.

---

# 🔐 Seguridad

Requiere autenticación válida en la API del ERP, ya que las consultas internas se realizan mediante: `$<span class="hljs-keyword">this</span>->getCombo(<span class="hljs-string">"<Doctype>"</span>)`

---

# 🧠 Flujo del Servicio (resumen real)

1. Inicializa un arreglo vacío `$combo`.
2. Obtiene desde el ERP las siguientes listas:
    
    
    - Países → Doctype: `Country`
    - Sucursales → Doctype: `Branch`
    - Departamentos → Doctype: `Department`
    - Género → Doctype: `Gender`
3. Agrega una lista fija de tipos de documentos:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-selector-attr">[<span class="hljs-string">"DNI"</span></span>, <span class="hljs-string">"Pasaporte"</span>, <span class="hljs-string">"Carnet de Extranjeria"</span>]`</div></div>
4. Retorna la estructura completa con todos los combos.
5. En caso de error, devuelve una respuesta controlada.

---

# 📥 Request Body

Este servicio **no recibe body**, ni parámetros.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span><span class="hljs-punctuation">}</span>`</div></div>---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Combos generados correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"paises"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Peru"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>      <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Chile"</span> <span class="hljs-punctuation">}</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"sucursales"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lima"</span> <span class="hljs-punctuation">}</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"departamento"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Recursos Humanos"</span> <span class="hljs-punctuation">}</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"genero"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Masculino"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>      <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Femenino"</span> <span class="hljs-punctuation">}</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"documentos"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"DNI"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"Pasaporte"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"Carnet de Extranjeria"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Error de ejecución o conexión con el ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error del servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"detalle del error"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas (estructuras usadas)

### Resultado de getCombo()

El servicio asume que `getCombo()` devuelve una estructura similar a:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%7B-%22name%22%3A-%22string%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">[</span>  <span class="hljs-punctuation">{</span> <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span> <span class="hljs-punctuation">}</span><span class="hljs-punctuation">]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Lista fija de tipos de documentos:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%22dni%22%2C-%22pasaporte%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">[</span>  <span class="hljs-string">"DNI"</span><span class="hljs-punctuation">,</span>  <span class="hljs-string">"Pasaporte"</span><span class="hljs-punctuation">,</span>  <span class="hljs-string">"Carnet de Extranjeria"</span><span class="hljs-punctuation">]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-combo-%3D-%7B%7D-combo%5B%22pa"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`combo = {}combo[<span class="hljs-string">"paises"</span>] = getCombo(<span class="hljs-string">"Country"</span>)combo[<span class="hljs-string">"sucursales"</span>] = getCombo(<span class="hljs-string">"Branch"</span>)combo[<span class="hljs-string">"departamento"</span>] = getCombo(<span class="hljs-string">"Department"</span>)combo[<span class="hljs-string">"genero"</span>] = getCombo(<span class="hljs-string">"Gender"</span>)combo[<span class="hljs-string">"documentos"</span>] = [<span class="hljs-string">"DNI"</span>, <span class="hljs-string">"Pasaporte"</span>, <span class="hljs-string">"Carnet de Extranjeria"</span>]<span class="hljs-keyword">return</span> {   valor: <span class="hljs-literal">true</span>,   msn: <span class="hljs-string">"Combos generados correctamente"</span>,   <span class="hljs-keyword">data</span>: combo}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Aplicar convocatoria (1) - [setJobApplicantPerApp]

## 🧾 Descripción

Registra una nueva **solicitud de postulación (Job Applicant)** desde la aplicación móvil, validando previamente:

- Que el usuario autenticado no tenga ya una solicitud creada para el mismo puesto.
- Que exista un empleado vinculado al email de sesión.
- Que los campos obligatorios del formulario estén correctamente enviados.
- Que la información personal del empleado se complemente para generar el registro.

Este servicio crea un documento `Job Applicant` en el ERP y también registra un `Error Log` con la data enviada al ERP (para auditoría).

---

## 🚀 Endpoint

**POST /set-job-applicant-per-app**

---

## 📥 Parámetros requeridos (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22email_logued%22%3A-%22s"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (obligatorio)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"job_title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (obligatorio)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"email_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (obligatorio, debe contener @)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"direccion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"adjuntar_copia_de_documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (file url)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"resume_attachment"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (file url)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"grado_instruccion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"phone_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"country"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ciudad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nacionalidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"carrera_profesional"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

- Requiere usuario autenticado en la app.
- La comunicación con el ERP se realiza mediante `apiService()`.
- No requiere token específico del usuario final, es un servicio interno controlado.

---

## 🧠 Flujo del Servicio (Explicación Detallada)

### 1️⃣ Validaciones iniciales

- Verifica que exista `email_logued`.
- Verifica que el email del formulario (`email_id`) sea válido y contenga “@”.
- Valida campos obligatorios: dirección, documentos, sucursal, CV, grado de instrucción, job\_title.

### 2️⃣ Verifica si ya existe una postulación previa

Consulta en el ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-job-applicant-%3Fl"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Job Applicant?<span class="hljs-keyword">limit</span>=<span class="hljs-keyword">None</span>&filters=[["email_logued","=","<email_logued>"], ["job_title","=","<job_title>"]]`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si ya existe un registro → **retorna error**.

### 3️⃣ Obtiene datos del empleado

Busca el empleado vinculado al email logueado:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-employee-%3Ffields"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET Employee?fields=[<span class="hljs-string">"*"</span>]&filters=<span class="hljs-string">[["user_id","=","<email_logued>"]]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no existe → **retorna error**.

### 4️⃣ Calcula la edad del postulante

Usando la fecha de nacimiento del empleado mediante `DateTime::diff`.

### 5️⃣ Construye el cuerpo del nuevo Job Applicant

Incluye:

- Datos del empleado (nombres, apellidos, género, fecha de nacimiento, DNI, nacionalidad).
- Datos enviados desde la app (CV, copia de documento, email, sucursal, carrera, etc.).
- Estado inicial del proceso: `"status": "Open"`
- Email logueado para relacionarlo a la cuenta APP.

### 6️⃣ Crea el registro Job Applicant

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-job-applicant-b"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST Job Applicant<span class="hljs-selector-tag">BODY</span>: { ..<span class="hljs-selector-class">.data</span> }`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 7️⃣ Registra error interno en Error Log (auditoría)

La respuesta del ERP se envía también a: `<span class="hljs-variable constant_">POST</span> <span class="hljs-title class_">Error</span> <span class="hljs-title class_">Log</span>`

### 8️⃣ Retorna la respuesta al cliente

Si se creó correctamente:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"valor"</span>: <span class="hljs-literal">true</span>,  <span class="hljs-string">"msn"</span>: <span class="hljs-string">"Solicitud insertada correctamente"</span>,  <span class="hljs-string">"data"</span>: { ... }}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si falló:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"valor"</span>: <span class="hljs-literal">false</span>,  <span class="hljs-string">"msn"</span>: <span class="hljs-string">"Solicitud no se puede insertar correctamente"</span>,  <span class="hljs-string">"data"</span>: { ... }}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📤 Respuesta 200 – Ejemplo (Éxito)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Solicitud insertada correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JOB-APP-000123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Open"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"applicant_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Juan Pérez"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"job_title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"VAC-2025-005"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"empleado@empresa.com"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>## ❌ Respuesta 200 – Ejemplo (Error)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ya existe una solicitud para su usuario"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores Comunes

### 1. Falta email\_logued

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es necesario el email con el que ha entrado a la app"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Email sin “@”

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El email debe contener @"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Empleado no existe

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al traer el empleado asociado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Solicitud duplicada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ya existe una solicitud para su usuario"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Error al crear Job Applicant

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`{  <span class="hljs-string">"valor"</span>: <span class="hljs-literal">false</span>,  <span class="hljs-string">"msn"</span>: <span class="hljs-string">"Solicitud no se puede insertar correctamente"</span>,  <span class="hljs-string">"data"</span>: { ...ERP response... }}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Estructuras usadas (Schemas)

### ▶ Employee (GET)

Campos consultados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22first_name%22%3A-%22str"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"first_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"middle_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"first_last_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"second_last_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"gender"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"date_of_birth"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"place_of_issue"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ▶ Job Applicant (POST)

Campos enviados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22grado%22%3A-%22string%22%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"grado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"job_title"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"applicant_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"numero_de_documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"email_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"resume_attachment"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Open"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"email_logued"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🧩 Pseudocódigo del Servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21email_logued%3A-er"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span> !email_logued: error<span class="hljs-comment">// validar duplicados</span>list = GET Job Applicant <span class="hljs-keyword">by</span> email_logued & job_title<span class="hljs-keyword">if</span> list > <span class="hljs-number">0</span>: erroremployee = GET Employee <span class="hljs-keyword">by</span> user_id=email_logued<span class="hljs-keyword">if</span> not exists: errorvalidar campos obligatoriosedad = calcular edad(employee.date_of_birth)body = construir Job ApplicantcreateJob = POST Job Applicantregistrar Error Log con createJob<span class="hljs-keyword">if</span> createJob.<span class="hljs-keyword">data</span>:    <span class="hljs-keyword">return</span> success<span class="hljs-keyword">else</span>:    <span class="hljs-keyword">return</span> error`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo Documentos Internos

# Lista de categorias - documentos (1) - [getInternalDocuments]

## 🧾 Descripción

Obtiene **todos los documentos internos del ERP**, los agrupa por categoría y devuelve cuáles corresponden a un puesto específico (si aplica).

Este servicio combina información procedente de:

- `tabDocumentos Internos`
- `tabDocumentos especificos` (relación hijo por puesto)

También determina dinámicamente qué archivo debe adjuntarse para la categoría **IPERC**, según el puesto del trabajador.

📌 **Es un servicio de consulta sin paginación.**  
📌 **No requiere parámetros en el body (solo el parámetro $puesto en la URL).**

---

# 🚀 Endpoint

### **GET /internal-documents/{puesto}**

- `{puesto}` → Nombre del puesto (Designation).
- Si no se envía o es null, el servicio igualmente devolverá las categorías, pero sin personalizar la categoría IPERC.

---

# 🔐 Seguridad

Requiere autenticación válida vía `dbErp` usando el token del ERP.  
El servicio accede directamente a vistas y tablas internas del ERP.

---

# 🧠 Flujo del Servicio

### **1. Consulta documentos internos**

Ejecuta la sentencia SQL:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-di.name%2C-di.n"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span>    di.name,    di.nombre_del_archivo,    di.categoria,    di.campo_para_adjuntar,    de.puesto,    de.adjuntar<span class="hljs-keyword">FROM</span> `tabDocumentos Internos` di<span class="hljs-keyword">LEFT JOIN</span> `tabDocumentos especificos` de    <span class="hljs-keyword">ON</span> di.name = de.parent`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si falla la consulta → devuelve error 500 del servicio.

---

### **2. Normaliza categorías**

Si un documento no tiene categoría, se asigna por defecto: `<span class="hljs-attr">categoria</span> = <span class="hljs-string">"POLITICAS"</span>`

---

### **3. Agrupa documentos por categoría**

Genera una estructura como:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22politicas%22%3A-%5B...%5D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  <span class="hljs-string">"POLITICAS"</span>: [...],  <span class="hljs-string">"IPERC"</span>: [...],  <span class="hljs-string">"MOF"</span>: [...],  ...}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **4. Caso especial: categoría IPERC**

Para IPERC:

- Se toma el adjunto por defecto → `campo_para_adjuntar`
- Si el puesto recibido coincide con algún registro hijo (`tabDocumentos especificos`)  
    → se usa el archivo personalizado (`adjuntar`)

Ejemplo lógica:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-adjunto-%3D-campo_para"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`adjunto = campo_para_adjuntar_default<span class="hljs-keyword">foreach</span> item <span class="hljs-keyword">in</span> detalles:    <span class="hljs-keyword">if</span> item.puesto == puesto AND item.adjuntar != <span class="hljs-string">""</span>:         adjunto = item.adjuntar`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### **5. Construye la respuesta final**

La respuesta incluye:

- Lista de categorías
- Lista agrupada con sus documentos y el archivo a adjuntar según la lógica

---

# 📤 Response 200 – Ejemplo Real

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de categorias generado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"categorias"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"POLITICAS"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"IPERC"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"MOF"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"categorias_registro"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"POLITICAS"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>        <span class="hljs-punctuation">{</span>          <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DOC-001"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"nombre_del_archivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"reglamento_interno.pdf"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"campo_para_adjuntar"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/reglamento_interno.pdf"</span>        <span class="hljs-punctuation">}</span>      <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"IPERC"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>        <span class="hljs-punctuation">{</span>          <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"IPERC-001"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"nombre_del_archivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"iperc_almacen.pdf"</span><span class="hljs-punctuation">,</span>          <span class="hljs-attr">"campo_para_adjuntar"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/iperc_almacen.pdf"</span>        <span class="hljs-punctuation">}</span>      <span class="hljs-punctuation">]</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles errores

### **1. Error de servicio ERP**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servicio"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>...<span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **2. Error interno**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Estructuras de datos utilizadas

### **Documentos Internos (`tabDocumentos Internos`)**

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_del_archivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"categoria"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"campo_para_adjuntar"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Documentos Específicos (`tabDocumentos especificos`)**

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22puesto%22%3A-%22string%7C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"puesto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"adjuntar"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Pseudocódigo del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-sql-%3D-select-documen"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`sql = SELECT documentos internos + documentos especificosdocs = dbErp(sql)foreach doc in docs:    if categoria is null:        categoria = "POLITICAS"grouped = group docs by categoriaforeach categoria in grouped:    group by name (padre)        if categoria == 'IPERC':        adjunto = campo_para_adjuntar_default        if puesto matches child:            adjunto = child.adjuntar    else:        adjunto = campo_para_adjuntarreturn {  categorias: keys(grouped),  categorias_registro: grouped}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Guardar documento (1) - [saveInternalDocuments]

## 🧾 Descripción

*Registra internamente un documento aceptado o gestionado por un usuario dentro de una terminal específica.*

Este servicio guarda un log en la tabla **documentos\_internos**, permitiendo rastrear:

- Qué usuario aceptó o gestionó un documento.
- Desde qué terminal lo realizó.
- Qué tipo de documento fue.
- En qué fecha y hora se registró.

Es utilizado para auditoría y trazabilidad dentro del sistema.

---

# 🚀 Endpoint

**POST** `/save-internal-documents`

---

# 📥 Parámetros (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1216" data-start="864"><thead data-end="914" data-start="864"><tr data-end="914" data-start="864"><th data-col-size="sm" data-end="876" data-start="864">Campo</th><th data-col-size="sm" data-end="887" data-start="876">Tipo</th><th data-col-size="sm" data-end="899" data-start="887">Requerido</th><th data-col-size="md" data-end="914" data-start="899">Descripción</th></tr></thead><tbody data-end="1216" data-start="966"><tr data-end="1052" data-start="966"><td data-col-size="sm" data-end="978" data-start="966">usuario</td><td data-col-size="sm" data-end="989" data-start="978">string</td><td data-col-size="sm" data-end="1001" data-start="989">✔️ Sí</td><td data-col-size="md" data-end="1052" data-start="1001">ID o username del usuario que realiza la acción</td></tr><tr data-end="1140" data-start="1053"><td data-col-size="sm" data-end="1065" data-start="1053">terminal</td><td data-col-size="sm" data-end="1076" data-start="1065">string</td><td data-col-size="sm" data-end="1088" data-start="1076">✔️ Sí</td><td data-col-size="md" data-end="1140" data-start="1088">Código de la terminal donde se ejecuta la acción</td></tr><tr data-end="1216" data-start="1141"><td data-col-size="sm" data-end="1153" data-start="1141">tipo</td><td data-col-size="sm" data-end="1164" data-start="1153">string</td><td data-col-size="sm" data-end="1175" data-start="1164">❌ No</td><td data-col-size="md" data-end="1216" data-start="1175">Tipo de documento o acción registrada</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

No requiere token de ERP.  
Acceso interno del backend usando conexión directa a la base de datos **mysql2**.

---

# 🧠 Flujo del Servicio (resumen)

1. Valida que **usuario** y **terminal** existan en la solicitud.
2. Establece zona horaria **America/Lima**.
3. Inserta un registro en la tabla `documentos_internos` con:
    
    
    - usuario
    - terminal
    - tipo
    - fecha actual
4. Si el registro falla, retorna un error.
5. Si todo es exitoso, responde confirmación de inserción.

---

# 🗃 Base de Datos Utilizada

**Tabla:** `documentos_internos` (BD: mysql2)

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2104" data-start="1800"><thead data-end="1842" data-start="1800"><tr data-end="1842" data-start="1800"><th data-col-size="sm" data-end="1811" data-start="1800">Campo</th><th data-col-size="sm" data-end="1827" data-start="1811">Tipo</th><th data-col-size="sm" data-end="1842" data-start="1827">Descripción</th></tr></thead><tbody data-end="2104" data-start="1886"><tr data-end="1937" data-start="1886"><td data-col-size="sm" data-end="1897" data-start="1886">usuario</td><td data-col-size="sm" data-end="1913" data-start="1897">varchar</td><td data-col-size="sm" data-end="1937" data-start="1913">Usuario que registra</td></tr><tr data-end="1998" data-start="1938"><td data-col-size="sm" data-end="1949" data-start="1938">terminal</td><td data-col-size="sm" data-end="1965" data-start="1949">varchar</td><td data-col-size="sm" data-end="1998" data-start="1965">Terminal desde donde registra</td></tr><tr data-end="2047" data-start="1999"><td data-col-size="sm" data-end="2010" data-start="1999">tipo</td><td data-col-size="sm" data-end="2026" data-start="2010">varchar</td><td data-col-size="sm" data-end="2047" data-start="2026">Tipo de documento</td></tr><tr data-end="2104" data-start="2048"><td data-col-size="sm" data-end="2059" data-start="2048">fecha</td><td data-col-size="sm" data-end="2075" data-start="2059">datetime</td><td data-col-size="sm" data-end="2104" data-start="2075">Fecha y hora del registro</td></tr></tbody></table>

</div></div>---

# 🔎 Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-usuario-vac%C3%ADo-%E2%86%92-r"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span> usuario vacío → retornar <span class="hljs-built_in">error</span> “te olvidaste el usuario”<span class="hljs-keyword">if</span> terminal vacío → retornar <span class="hljs-built_in">error</span> <span class="hljs-string">"te olvidaste la terminal"</span>fecha = now()<span class="hljs-built_in">insert</span> into documentos_internos (usuario, terminal, tipo, fecha)<span class="hljs-keyword">if</span> <span class="hljs-built_in">insert</span> falla → retornar <span class="hljs-string">"Ocurrió un error"</span><span class="hljs-keyword">else</span> → retornar <span class="hljs-string">"Insertado con éxito"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 Respuestas del Servicio

### ✅ **200 – Inserción exitosa**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Insertado con éxito"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❗ Error: Falta usuario

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"te olvidaste el usuario"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❗ Error: Falta terminal

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"te olvidaste la terminal"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❗ Error al insertar

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Ejemplo completo de Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22user%40e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"user@example.com"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"236"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"descarga_politicas"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Examen Medico (1) - [obtain]

## 🧾 Descripción

*Este servicio permite **consultar los resultados del examen EMO** (Evaluación Médica Ocupacional) de un empleado utilizando su **DNI (passport\_number)**.*

*El servicio valida que el DNI haya sido enviado, busca la información correspondiente mediante el método interno `getExamenEmo()` y retorna los resultados si existen.*

*Es un servicio de consulta rápida y directa.*

---

## 🚀 Endpoint

### **POST /obtain**

---

## 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22passport_number%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Campos:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="922" data-start="750"><thead data-end="794" data-start="750"><tr data-end="794" data-start="750"><th data-col-size="sm" data-end="758" data-start="750">Campo</th><th data-col-size="sm" data-end="765" data-start="758">Tipo</th><th data-col-size="sm" data-end="779" data-start="765">Obligatorio</th><th data-col-size="md" data-end="794" data-start="779">Descripción</th></tr></thead><tbody data-end="922" data-start="841"><tr data-end="922" data-start="841"><td data-col-size="sm" data-end="859" data-start="841">passport\_number</td><td data-col-size="sm" data-end="868" data-start="859">string</td><td data-col-size="sm" data-end="873" data-start="868">✔️</td><td data-col-size="md" data-end="922" data-start="873">DNI del empleado para consultar su examen EMO</td></tr></tbody></table>

</div></div>---

## 🔐 Seguridad

Este servicio **no requiere autenticación externa**, pero su funcionamiento depende de un método interno:

- `getExamenEmo(passport_number)` → Consulta la información del examen EMO.

---

## 🧠 Flujo del Servicio (Explicación)

1. **Validación inicial del DNI**
    
    
    - Si el parámetro `passport_number` no está presente, el servicio responde con error.
2. **Consulta del examen EMO**
    
    
    - Se llama al método interno `getExamenEmo($passport_number)`.
3. **Validación del resultado**
    
    
    - Si el método no retorna datos, se responde con un mensaje indicando que no se encontraron resultados.
4. **Respuesta exitosa**
    
    
    - Si sí existen resultados, se retorna el contenido del examen EMO.

---

## 📤 Response 200 – Ejemplos

### ✔️ Caso exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se encontraron resultados"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"resultado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Apto"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-12"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"observaciones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ninguna"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❗ Error: DNI no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El dni del empelado es obligatorio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❗ Error: Sin resultados EMO

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron resultados"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

<div class="_tableContainer_1rjym_1" id="bkmrk-c%C3%B3digo-motivo-descri"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2374" data-start="2117"><thead data-end="2150" data-start="2117"><tr data-end="2150" data-start="2117"><th data-col-size="sm" data-end="2126" data-start="2117">Código</th><th data-col-size="sm" data-end="2135" data-start="2126">Motivo</th><th data-col-size="md" data-end="2150" data-start="2135">Descripción</th></tr></thead><tbody data-end="2374" data-start="2185"><tr data-end="2242" data-start="2185"><td data-col-size="sm" data-end="2191" data-start="2185">400</td><td data-col-size="sm" data-end="2206" data-start="2191">DNI faltante</td><td data-col-size="md" data-end="2242" data-start="2206">No se envió el `passport_number`</td></tr><tr data-end="2312" data-start="2243"><td data-col-size="sm" data-end="2249" data-start="2243">404</td><td data-col-size="sm" data-end="2266" data-start="2249">Sin resultados</td><td data-col-size="md" data-end="2312" data-start="2266">El empleado no tiene examen EMO registrado</td></tr><tr data-end="2374" data-start="2313"><td data-col-size="sm" data-end="2319" data-start="2313">500</td><td data-col-size="sm" data-end="2345" data-start="2319">Error en método interno</td><td data-col-size="md" data-end="2374" data-start="2345">Fallo en `getExamenEmo()`</td></tr></tbody></table>

</div></div>---

## 📚 Schemas

### **Request Schema**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22passport_number%22%3A-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Response Schema (éxito)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se encontraron resultados"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...examen_emo <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Response Schema (error)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Descripción del error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21passport_number%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span> !passport_number:    <span class="hljs-keyword">return</span> error(<span class="hljs-string">"El dni del empleado es obligatorio"</span>)examen = getExamenEmo(passport_number)<span class="hljs-keyword">if</span> !examen:    <span class="hljs-keyword">return</span> error(<span class="hljs-string">"No se encontraron resultados"</span>)<span class="hljs-keyword">return</span> success(examen)`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo QR

# Verificar QR (1) - [verifyQR]

### 🧾 Descripción

Este servicio permite **validar si un empleado tiene permitido registrarse** (por ejemplo, marcar asistencia) **en función del último escaneo de QR del bus** registrado en el ERP.

La lógica se basa en verificar si el empleado escaneó su QR dentro de las **últimas 4 horas (14400 segundos)**.

El servicio consulta la tabla:

- `Registro de Escaneres de Bus`
- `Tabla Lista Blanca`

Mediante `dbErp()` para obtener el escaneo más reciente disponible.

---

# 🚀 Endpoint

### **POST /verify-qr**

---

# 📥 Request Body (Ejemplo)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%22%3A-%22hr-em"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"HR-EMP-00045"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="956" data-start="809"><thead data-end="853" data-start="809"><tr data-end="853" data-start="809"><th data-col-size="sm" data-end="817" data-start="809">Campo</th><th data-col-size="sm" data-end="824" data-start="817">Tipo</th><th data-col-size="sm" data-end="838" data-start="824">Obligatorio</th><th data-col-size="sm" data-end="853" data-start="838">Descripción</th></tr></thead><tbody data-end="956" data-start="899"><tr data-end="956" data-start="899"><td data-col-size="sm" data-end="910" data-start="899">employee</td><td data-col-size="sm" data-end="919" data-start="910">string</td><td data-col-size="sm" data-end="924" data-start="919">✔️</td><td data-col-size="sm" data-end="956" data-start="924">Código de empleado a validar</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

El servicio usa comunicación interna con ERP mediante:

- `dbErp()`
- Autenticación interna utilizando cookies o token del ERP.

No requiere autenticación adicional desde el cliente.

---

# 🧠 Flujo del Servicio (Explicación real)

1. **Validación inicial del parámetro**
    
    
    - Si `employee` está vacío → se devuelve error.
2. **Consulta del último escaneo registrado en ERP**
    
    Se ejecuta:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> tpr.name, teas.empleado, teas.fecha<span class="hljs-keyword">FROM</span> `tabRegistro de Escaneres de Bus` tpr<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> `tabTabla Lista Blanca` teas <span class="hljs-keyword">ON</span> teas.parent <span class="hljs-operator">=</span> tpr.name<span class="hljs-keyword">WHERE</span> teas.empleado <span class="hljs-operator">=</span> employee<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> teas.fecha <span class="hljs-keyword">DESC</span>LIMIT <span class="hljs-number">1</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
3. **Si no existen registros**
    
    
    - Se retorna mensaje indicando que no se encontró escaneo.
4. **Cálculo de la diferencia de tiempo**
    
    Se obtiene el tiempo transcurrido entre:
    
    
    - Fecha del escaneo (`fecha`)
    - Fecha actual
    
    Se obtiene con:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-variable">$diff</span> = <span class="hljs-variable">$fechaEscaneoCarbon</span>-><span class="hljs-title function_ invoke__">diffInSeconds</span>(<span class="hljs-title function_ invoke__">now</span>());`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
5. **Aplicación de la regla de validación**
    
    
    - Si la diferencia es **menor a 4 horas (14400 segundos)** → **permitido**
    - Si es mayor → **denegado**
6. **Manejo de excepciones**  
    Si ocurre un error interno, se retorna el mensaje de error.

---

# 📤 Response 200 – Ejemplos

### ✔️ Caso permitido (último escaneo dentro de 4 horas)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"permitido"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ✔️ Caso denegado (más de 4 horas sin escanear)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"denegado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❌ No existe escaneo asociado al empleado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se ha encontrado un escaner de bus para el empleado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❌ Parámetro inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El empleado no puede estar vacio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### ❌ Error interno

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno: <mensaje>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas utilizados

### **Registro de Escaneres de Bus (consulta)**

Campos consultados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-employee-is-empty"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if employee is empty:    return error("El empleado no puede estar vacio")data = GET ultimo registro de escaneo del bus para employeeif no data:    return error("No se ha encontrado un escaneo")fechaEscaneo = data.fechadiferencia = now() - fechaEscaneo (en segundos)if diferencia < 14400:    return permitidoelse:    return denegado`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Leer QR (1) - [leerCodigoQR]

## 🧾 Descripción

Este servicio valida un **código QR de acceso a buses internos** y determina si un empleado puede registrar un nuevo escaneo.  
El flujo consulta los registros previos, controla tiempos de reescaneo (mínimo 4 horas) y registra un nuevo ingreso si corresponde.

El servicio interactúa con:

- **Tabla “Registro de Escaneres de Bus”** (documento principal con el QR)
- **Tabla “Tabla Lista Blanca”** (registros de escaneo por empleado)
- **ERP vía dbErp() y ServiceErp()**
- **Carbon** para manejo de fechas

---

## 🚀 Endpoint

**POST** `/leer-codigo-qr`

---

## 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22qr%22%3A-%22string%22%2C-%22e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"qr"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1168" data-start="910"><thead data-end="961" data-start="910"><tr data-end="961" data-start="910"><th data-col-size="sm" data-end="923" data-start="910">Campo</th><th data-col-size="sm" data-end="932" data-start="923">Tipo</th><th data-col-size="sm" data-end="946" data-start="932">Obligatorio</th><th data-col-size="md" data-end="961" data-start="946">Descripción</th></tr></thead><tbody data-end="1168" data-start="1014"><tr data-end="1074" data-start="1014"><td data-col-size="sm" data-end="1027" data-start="1014">qr</td><td data-col-size="sm" data-end="1036" data-start="1027">string</td><td data-col-size="sm" data-end="1051" data-start="1036">✔️</td><td data-col-size="md" data-end="1074" data-start="1051">Código QR escaneado</td></tr><tr data-end="1168" data-start="1075"><td data-col-size="sm" data-end="1088" data-start="1075">employee</td><td data-col-size="sm" data-end="1097" data-start="1088">string</td><td data-col-size="sm" data-end="1112" data-start="1097">✔️</td><td data-col-size="md" data-end="1168" data-start="1112">Código del empleado que intenta registrar el escaneo</td></tr></tbody></table>

</div></div>---

## 🔐 Seguridad

Requiere autenticación interna del ERP (vía `dbErp()` y `ServiceErp()`).

---

## 🧠 Flujo del Servicio (resumen real)

### 1️⃣ Validaciones iniciales

- El QR no puede venir vacío
- El código de empleado tampoco

Si falla, retorna error inmediato.

---

### 2️⃣ Buscar el documento del QR

Consulta el ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-registro-de-esca"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> Registro de Escaneres de Bus <span class="hljs-keyword">JOIN</span> Tabla Lista Blanca<span class="hljs-keyword">WHERE</span> qr = <qr><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> fecha <span class="hljs-keyword">DESC</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Campos devueltos:

- `name` (documento padre)
- `empleado`
- `fecha` del escaneo

Si no hay resultados: **QR inválido**.

---

### 3️⃣ Filtrar último registro por empleado

Construye una lista de empleados únicos y toma el último escaneo para cada uno.

Si el empleado actual tiene un registro:

- Calcula diferencia de horas entre el último registro y ahora.
- Si es **menor a 4 horas**, se retorna:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"denegado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 4️⃣ Registrar nuevo escaneo

Si cumple la validación, inserta un registro en la tabla:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-tabla-lista-bla"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST Tabla Lista Blanca{  fecha,  parent,  empleado,  parentlink: Registro de Escaneres de Bus}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si falla el registro → error  
Si se registra correctamente → "permitido"

---

## 📤 Response 200 – Ejemplos

### ✔️ Permitido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"permitido"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ⛔ Denegado por escaneo reciente

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"denegado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ QR sin registros

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron registros para el QR escaneado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error interno

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno: <mensaje>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

1. **QR vacío**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El QR no puede estar vacio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>2. **Empleado vacío**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El empleado no puede estar vacio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>3. **QR inexistente en ERP**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron registros para el QR escaneado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>4. **Error al insertar registro**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se pudo registrar el escaner de bus"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>5. **Error interno (try–catch)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%2C-%22-6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno: <mensaje>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Tablas / Schemas utilizados

### **Registro de Escaneres de Bus (tpr)**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"qr"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Tabla Lista Blanca (teas)**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Registro Insertado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22fecha%22%3A-%22datetime"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parentfield"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"table_1"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parenttype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Registro de Escaneres de Bus"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🧩 Pseudocódigo del flujo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-qr-is-empty-%E2%86%92-err"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if qr is empty → errorif employee is empty → error// Buscar registros del QRdataQR = SELECT * FROM RegistroEscaneresBus JOIN TablaListaBlanca WHERE qr = qr ORDER BY fecha DESCif dataQR is empty → error// Obtener últimos registros por empleadoempleadosUnicos = agrupar_por_empleado(dataQR)if empleadosUnicos[employee] existe:    diffHoras = horas_entre(último registro, ahora)    if diffHoras < 4:        return "denegado"// Registrar nuevo escaneoinsert = POST TablaListaBlanca {    fecha: now,    empleado,    parent: documentoPrincipal}if insert.error:    return errorreturn "permitido"`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo Supervision

# Lista Sucursales (1) - [listSucursalSupervition]

## 🧾 Descripción

Este servicio obtiene todas las supervisiones realizadas por un **Supervisor Nacional**, junto con información adicional relacionada a:

- Las sucursales supervisadas
- La fecha de registro
- El documento generado
- La programación de supervisión vinculada
- La fecha real en la que se ejecutó dicha supervisión

El servicio consolida datos procedentes de:

- `Check List del Supervisor Nacional 2`
- `Tabla supervisores`
- `Programación de Supervisores`

y devuelve una lista enriquecida de supervisiones.

---

## 🚀 Endpoint

**POST** `/list-sucursal-supervition`

---

## 📥 Parámetros de Entrada (Request)

### Body / FormData

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-oblig"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1130" data-start="924"><thead data-end="972" data-start="924"><tr data-end="972" data-start="924"><th data-col-size="sm" data-end="936" data-start="924">Parámetro</th><th data-col-size="sm" data-end="943" data-start="936">Tipo</th><th data-col-size="sm" data-end="957" data-start="943">Obligatorio</th><th data-col-size="md" data-end="972" data-start="957">Descripción</th></tr></thead><tbody data-end="1130" data-start="1021"><tr data-end="1130" data-start="1021"><td data-col-size="sm" data-end="1033" data-start="1021">`Employe`</td><td data-col-size="sm" data-end="1042" data-start="1033">string</td><td data-col-size="sm" data-end="1047" data-start="1042">✔️</td><td data-col-size="md" data-end="1130" data-start="1047">Código del empleado supervisor cuyo historial de supervisiones será consultado.</td></tr></tbody></table>

</div></div>Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employe%22%3A-%22emp-00"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"Employe"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-001245"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

- Requiere autenticación interna del ERP (token manejado por `ServiceErp()` y `dbErp()`).
- Solo accesible para usuarios válidos dentro del entorno de capacitación.

---

## 🧠 Flujo del Servicio (Resumen Detallado)

### **1️⃣ Validar parámetro recibido**

Si `Employe` viene vacío, se retorna un mensaje de validación.

### **2️⃣ Listar supervisiones creadas por el supervisor**

Consulta en el ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-resource%2Fcheck-l"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">GET</span> resource/Check List del Supervisor Nacional <span class="hljs-number">2</span><span class="hljs-symbol">Filters:</span> supervisor = Employe<span class="hljs-symbol">Fields:</span> sucursal, fecha, name`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Si no hay resultados → Retorna mensaje indicando ausencia de registros.

### **3️⃣ Obtener la relación con Tabla Supervisores**

Con los `name` obtenidos, se consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-send-query-data"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST send<span class="hljs-operator">-</span>query<span class="hljs-operator">-</span>database<span class="hljs-keyword">FROM</span> tabCheck List del Supervisor Nacional <span class="hljs-number">2</span> spr<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> tabTabla supervisores tab <span class="hljs-keyword">ON</span> spr.name <span class="hljs-operator">=</span> tab.id_doctype<span class="hljs-keyword">WHERE</span> spr.name <span class="hljs-keyword">IN</span> (...)<span class="hljs-keyword">SELECT</span> spr.name, tab.parent`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Construye:

- `$datanew[parent] = name`
- `$data_alrevez[name] = parent`

### **4️⃣ Obtener programación de supervisores**

Si existen supervisiones relacionadas, consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-send-query-data-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`POST send-query-<span class="hljs-keyword">database</span><span class="hljs-keyword">FROM</span> tabProgramacion de Supervisores<span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span> <span class="hljs-keyword">IN</span> parents<span class="hljs-keyword">SELECT</span> <span class="hljs-type">name</span>, prog_supervisores, fecha_real_de_la_supervicion`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Se agrega esta información a cada supervisión detectada.

### **5️⃣ Unir los datos**

Cada supervisión final contendrá:

- sucursal
- fecha del checklist
- nombre del documento checklist
- programación de supervisión (`prog_supervisores`)
- fecha real de supervisión (`fecha_real_de_la_supervicion`)

---

## 📤 Response (200 – Ejemplo)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de Sucursales"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SUC-014"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-10-03"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHK-SUP-00045"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"supervision"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SUP-NACIONAL-05"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fechaSupervision"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024-10-04"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

### 1. Supervisor no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El campo empleado es obligatorio"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error del servicio ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al listar"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Supervisor sin supervisiones registradas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No hay ningun registro creado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Tablas / Recursos involucrados

### **Check List del Supervisor Nacional 2**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22sucursal%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"supervisor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **Tabla supervisores**

Relación entre registros checklist y programaciones.

### **Programación de Supervisores**

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"prog_supervisores"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_real_de_la_supervicion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Pseudocódigo del Servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-employe-is-empty%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if Employe is empty:    return errorlistName = GET Check List supervisor where supervisor=Employeif listName empty:    return sin registrosnames = extract "name" from listNamerelations = QUERY tabla supervisores WHERE spr.name IN namesparents = extract unique parentprogramaciones = QUERY programacion supervisores WHERE name IN parentsmerge programaciones into listNamereturn listName enriched`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Informacion de sucursal (1) - [infosupervitionName]

### 🧾 Descripción

Obtiene la información general de un checklist del **Supervisor Nacional**, incluyendo:

- Datos principales de la cabecera del checklist
- Promedio de progreso de todas las categorías evaluadas
- Puntaje total acumulado

El servicio combina información proveniente de:

- ERP (doc: *Check List del Supervisor Nacional 2*)
- Servicio interno `listCategory()` (el cual obtiene las secciones/categorías del checklist)

---

# 🚀 Endpoint

### POST /infosupervition-name

🔸 **Recibe un parámetro obligatorio en el body:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22id-del-ch"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ID del checklist"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🔐 Seguridad

Requiere autenticación interna mediante `ServiceErp()` y dependencias del módulo `general`.

---

# 🧠 Flujo del Servicio (resumen real)

1. **Valida parámetro `name`**  
    Si viene vacío, retorna error utilizando `responseValidate()`.
2. **Obtiene todas las categorías** asociadas al checklist  
    Usa:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">listCategory</span>($request)`</div></div>
3. **Valida respuesta de categorías**
    
    
    - Si ocurre error → retorna mensaje de fallo.
    - Si la data viene vacía → indica que no existen registros creados.
4. **Calcula progresos y puntajes totales**  
    Recorre cada categoría para:
    
    
    - Sumar `section_puntaje`
    - Sumar `progreso`
    - Contar categorías
    
    Luego obtiene:
    
    
    - `all_progress = total_progreso / cantidad_categorias`
    - `all_point = round(total_puntaje)`
5. **Consulta información de cabecera del checklist en ERP**
    
    Realiza:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`GET Check List del Supervisor Nacional <span class="hljs-number">2</span>?filters=<span class="hljs-string">[["name","=",<name>]]</span>`</div></div>Campos obtenidos:
    
    
    - sucursal
    - fecha
    - name
6. **Agrega métricas calculadas** al resultado:
    
    
    - `all_progress`
    - `all_point`
7. **Retorna respuesta final con la información consolidada**

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22chk-00045"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHK-00045"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Informacion obtenida"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIMA-01"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHK-00045"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"all_progress"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">82.5</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"all_point"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">120</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. name vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Campo requerido vacío"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error al obtener categorías

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al obtener la informacion"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. No existen registros en categorías

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No hay ningun registro creado"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Error consultando al ERP

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al obtener informacion"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Schemas usados

### Categoría (respuesta de listCategory)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22section_puntaje%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"section_puntaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"progreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Check List del Supervisor Nacional 2 (ERP)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22sucursal%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 33.8px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 33.8px;"><td style="height: 33.8px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-name-%3D%3D-%22%22%3A-retur"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if name == "":    return errorcategorias = listCategory(request)if categorias.error:    return errorif categorias.data empty:    return no registrosfor categoria in categorias:    total_puntaje += categoria.section_puntaje    total_progreso += categoria.progreso    cantidad += 1GET checklistHeader FROM ERP WHERE name = <name>header.all_progress = total_progreso / cantidadheader.all_point = round(total_puntaje)return header`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Puntajes de las categorias (1) - [listCategory]

## 🧾 Descripción

Obtiene y procesa dinámicamente todas las **categorías**, **preguntas** y **porcentajes de avance** del **Check List del Supervisor Nacional 2**, basándose en su estructura de campos del DocType y los valores registrados en un documento específico.

Este servicio:

1. Lee la estructura del DocType para identificar:
    
    
    - Secciones (categorías).
    - Preguntas tipo **Check**, **Data**, **Attach Image**.
2. Recupera los valores reales del documento filtrado por `name`.
3. Agrupa los campos por categoría.
4. Calcula el avance (%) y puntaje por sección.
5. Devuelve un resumen por categoría con:
    
    
    - Total de campos.
    - Campos completados.
    - Progreso (%).
    - Puntaje asignado.

---

# 🚀 Endpoint

**POST /list-category**

---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22%3Cid-del-d"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<id del documento Check List del Supervisor Nacional 2>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1254" data-start="1101"><thead data-end="1143" data-start="1101"><tr data-end="1143" data-start="1101"><th data-col-size="sm" data-end="1109" data-start="1101">Campo</th><th data-col-size="sm" data-end="1116" data-start="1109">Tipo</th><th data-col-size="sm" data-end="1128" data-start="1116">Requerido</th><th data-col-size="md" data-end="1143" data-start="1128">Descripción</th></tr></thead><tbody data-end="1254" data-start="1187"><tr data-end="1254" data-start="1187"><td data-col-size="sm" data-end="1194" data-start="1187">name</td><td data-col-size="sm" data-end="1203" data-start="1194">string</td><td data-col-size="sm" data-end="1207" data-start="1203">✔</td><td data-col-size="md" data-end="1254" data-start="1207">ID del documento cuyo checklist se evaluará</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

El servicio utiliza autenticación interna mediante: `$<span class="hljs-keyword">this</span>->general->ServiceErp()`

Por lo tanto, requiere credenciales válidas para consumir el ERP.

---

# 🧠 Flujo del Servicio (Explicación Técnica Real)

### 1️⃣ Obtener estructura del DocType

Se consulta: `<span class="hljs-keyword">GET</span> resource<span class="hljs-operator">/</span>DocType<span class="hljs-operator">/</span><span class="hljs-keyword">Check</span> List del Supervisor Nacional <span class="hljs-number">2</span>`

Esto trae **todos los campos** del formulario.  
El servicio filtra únicamente:

- Section Break → marca inicio de categoría
- Check
- Data
- Attach Image

También **omite** los campos de puntaje global:

- porcentaje\_de\_imagen\_y\_presentación
- puntaje\_de\_imagen\_y\_presentación

---

### 2️⃣ Construcción dinámica de categorías y preguntas

Ejemplo de agrupación generada:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22gesti%C3%B3n-documenta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"Gestión Documentaria"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"documentos_autoridades"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"imagen_14"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"comentario_14"</span><span class="hljs-punctuation">,</span>    ...  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"Presentación del almacén"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-string">"foto_area"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"check_orden"</span><span class="hljs-punctuation">,</span>    <span class="hljs-string">"comentario_orden"</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3️⃣ Recuperar valores del documento

Se unen todos los fields encontrados y se hace:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-resource%2Fcheck-l"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`GET resource/Check List del Supervisor Nacional <span class="hljs-number">2</span>?fields=[...fields]&filters=<span class="hljs-string">[["name","=",name]]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Esto trae los valores registrados del documento.

---

### 4️⃣ Agrupar los valores por categoría

El servicio arma una estructura:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22gesti%C3%B3n-documenta-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"Gestión Documentaria"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>     <span class="hljs-attr">"documentos_autoridades"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>     <span class="hljs-attr">"imagen_14"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/img.png"</span><span class="hljs-punctuation">,</span>     <span class="hljs-attr">"comentario_14"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"OK"</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 5️⃣ Calcular puntajes y progreso

Para cada categoría:

- Se cuenta el total de campos (Check, Data, Imagen)
- Se cuentan los completados:
    
    
    - Check → valor 1
- Se asigna un puntaje:
    
    
    - Cada check activo suma **1.82**
- Se calcula:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-progreso-%3D-%28complete"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">progreso</span> = (complete_fields / total_fields_categoria) * <span class="hljs-number">100</span>`</div></div>⚠ Nota: El servicio divide el total de campos entre 3 (`$maxFields = $maxFields / 3`) para compensar que cada pregunta tiene 3 tipos de fields (check, data, image).

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista De Categorias"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"category"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Gestión Documentaria"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"progreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">67</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"total_fields"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">6</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"complete_fields"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">4</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"section_puntaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">7.28</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"category"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Áreas Críticas"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"progreso"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">50</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"total_fields"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">4</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"complete_fields"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"section_puntaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3.64</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. No se puede obtener el DocType

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22value%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al consular"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Documento no encontrado

(El servicio devolverá valores vacíos por categoría)

---

# 🗃 Estructuras Utilizadas

### DocType (GET)

Campos analizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22fieldname%22%3A-%22stri"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"fieldname"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"label"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fieldtype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Section Break | Check | Data | Attach Image"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🧩 Lógica en pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-doctype-%3D-get-doctyp"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`doctype = GET DocType fieldscategorias = {}<span class="hljs-keyword">foreach</span> field <span class="hljs-keyword">in</span> doctype.fields:    <span class="hljs-keyword">if</span> field is Section <span class="hljs-keyword">Break</span>:         categoria_actual = field.label    <span class="hljs-keyword">if</span> field is Check/<span class="hljs-keyword">Data</span>/Image:         categorias[<span class="hljs-type">categoria_actual</span>].append(field.fieldname)<span class="hljs-comment"># Obtener valores reales del documento</span>values = GET Check List <span class="hljs-built_in">del</span> Supervisor Nacional <span class="hljs-number">2</span> <span class="hljs-built_in">where</span> name = request.name<span class="hljs-comment"># Agrupar valores por categoría</span><span class="hljs-keyword">foreach</span> categoria <span class="hljs-keyword">in</span> categorias:    newQuestions[<span class="hljs-type">categoria</span>] = tomar valores según fieldname<span class="hljs-comment"># Calcular porcentaje y puntaje</span><span class="hljs-keyword">foreach</span> categoria <span class="hljs-keyword">in</span> newQuestions:    total = count(fields) / <span class="hljs-number">3</span>    completos = fields con valor <span class="hljs-number">1</span>    puntaje = completos * <span class="hljs-number">1.82</span>    agregar resultado al response`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Respuestas formulario (1) - [missing_questions_form]

### 🧾 Descripción

Este servicio identifica **qué preguntas no han sido completadas** dentro de un formulario del DocType:

**Check List del Supervisor Nacional 2**

El servicio analiza:

- Una **categoría** específica del formulario (Section Break).
- Un documento del Doctype, identificado por **name**.
- Obtiene **todos los campos relevantes** (Check, Data, Attach Image).
- Compara estos campos con los valores del documento
- Devuelve **solo los campos incompletos**, agrupados por categoría.

Se usa principalmente para:

✔ Validar formularios incompletos  
✔ Mostrar al usuario qué preguntas faltan llenar  
✔ Controlar flujos de supervisión/inspecciones

---

# 🚀 Endpoint

**POST** `/missing-questions-form`

---

# 📥 Parámetros del Request

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1386" data-start="1071"><thead data-end="1122" data-start="1071"><tr data-end="1122" data-start="1071"><th data-col-size="sm" data-end="1084" data-start="1071">Campo</th><th data-col-size="sm" data-end="1093" data-start="1084">Tipo</th><th data-col-size="sm" data-end="1107" data-start="1093">Obligatorio</th><th data-col-size="md" data-end="1122" data-start="1107">Descripción</th></tr></thead><tbody data-end="1386" data-start="1175"><tr data-end="1277" data-start="1175"><td data-col-size="sm" data-end="1188" data-start="1175">category</td><td data-col-size="sm" data-end="1197" data-start="1188">string</td><td data-col-size="sm" data-end="1211" data-start="1197">✔ Sí</td><td data-col-size="md" data-end="1277" data-start="1211">Nombre de la sección del formulario (label del Section Break).</td></tr><tr data-end="1386" data-start="1278"><td data-col-size="sm" data-end="1291" data-start="1278">name</td><td data-col-size="sm" data-end="1300" data-start="1291">string</td><td data-col-size="sm" data-end="1314" data-start="1300">✔ Sí</td><td data-col-size="md" data-end="1386" data-start="1314">ID del documento del Doctype "Check List del Supervisor Nacional 2".</td></tr></tbody></table>

</div></div>### Ejemplo de request:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22category%22%3A-%22limpi"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"category"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Limpieza y Orden"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHK-SUP-00015"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🔐 Seguridad

Utiliza autenticación interna a través de:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Egeneral-%3Eserv"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`$<span class="hljs-keyword">this</span>->general->ServiceErp()`</div></div>No requiere autenticación externa del usuario final.  
Toda la data se obtiene desde el ERP.

---

# 🧠 Flujo del Servicio (Resumen Técnico)

### 1️⃣ Validaciones iniciales

- Verifica que **category** no esté vacío.
- Verifica que **name** no esté vacío.

Si falta un campo → retorna error inmediato.

---

### 2️⃣ Obtiene estructura del formulario

GET al Doctype: `<span class="hljs-keyword">GET</span> <span class="hljs-operator">/</span>resource<span class="hljs-operator">/</span>DocType<span class="hljs-operator">/</span><span class="hljs-keyword">Check</span> List del Supervisor Nacional <span class="hljs-number">2</span>`

De ahí obtiene:

- Section Breaks
- Campos tipo Check
- Campos tipo Data
- Campos tipo Attach Image

Y construye un arreglo organizado por secciones:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22nombre-de-secci%C3%B3n"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`{  "Nombre de Sección": {      "fields_name": { fieldname : label },      "data_name":   { fieldname : label },      "img_name":    { fieldname : label }  }}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>**Se excluyen automáticamente:**

- porcentaje\_de\_imagen\_y\_presentación
- puntaje\_de\_imagen\_y\_presentación

---

### 3️⃣ Filtra solo la categoría solicitada

Busca dentro de todas las secciones y selecciona solo: `questions<span class="hljs-selector-attr">[category]</span>`

Si no existe → retorna vacío.

---

### 4️⃣ Obtiene valores del documento filtrado por name

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-%2Fresource%2Fcheck-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`GET /resource/Check List del Supervisor Nacional <span class="hljs-number">2</span>?filters=<span class="hljs-string">[["name","=",<name>]]</span>`</div></div>Aquí obtiene los valores reales del formulario.

---

### 5️⃣ Determina qué preguntas faltan completar

Compara para cada campo: `<span class="hljs-built_in">si</span> campo == <span class="hljs-number">0</span> → está incompleto → se agrega a la lista`

Guarda:

- fieldnames faltantes
- Texto de la pregunta
- Identificación por sección

---

### 6️⃣ Retorna solo las preguntas faltantes

---

# 📤 Response 200 – Ejemplo Real

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Missing Questions"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"Limpieza y Orden"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"pregunta_1"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"pregunta_3"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"questions"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"¿Los ambientes se encuentran limpios?"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"¿El personal cumple con el orden establecido?"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1️⃣ category vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El campo category es requerido"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 2️⃣ name vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El campo name es requerido"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 3️⃣ El Doctype no responde

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al consular"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 4️⃣ Error en consulta de valores del documento

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error durante el proceso, intente de nuevo."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Estructuras Usadas

### 📌 DocType: Check List del Supervisor Nacional 2

Campos analizados:

- Section Break
- Check
- Data
- Attach Image

Se ignoran:

- porcentaje\_de\_imagen\_y\_presentación
- puntaje\_de\_imagen\_y\_presentación

---

# 🧩 Algoritmo en Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-validar%28category%29-va"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`validar(category)validar(name)doctype = GET DocType structurepreguntas = extraer_secciones_y_campos(doctype)selectedCategory = preguntas[category]campos = obtener_fieldnames(selectedCategory)valores = GET Documento ERP con esos camposmissing = []para cada campo en selectedCategory:    si valor == 0:        agregar a missingreturn missing`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Respuestas (1) - [missing_questions]

## 🧾 Descripción

Este servicio obtiene las **preguntas incompletas y completas** de una categoría específica del Doctype **“Check List del Supervisor Nacional 2”**, basándose en un registro identificado por su `name`.

El servicio:

1. Obtiene toda la estructura de campos del Doctype.
2. Identifica qué campos pertenecen a cada categoría (Section Break).
3. Filtra únicamente los campos tipo:
    
    
    - **Check**
    - **Data** *(comentado actualmente)*
    - **Attach Image** *(comentado actualmente)*
4. Consulta los valores reales del formulario (`0` o `1`).
5. Determina qué preguntas están completas o incompletas.
6. Devuelve solo la categoría solicitada.

Es un servicio orientado a auditorías y evaluación operacional.

---

# 🚀 Endpoint

**POST /missing-questions**

---

# 📥 Parámetros (Request Body)

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1325" data-start="1046"><thead data-end="1090" data-start="1046"><tr data-end="1090" data-start="1046"><th data-col-size="sm" data-end="1054" data-start="1046">Campo</th><th data-col-size="sm" data-end="1061" data-start="1054">Tipo</th><th data-col-size="sm" data-end="1075" data-start="1061">Obligatorio</th><th data-col-size="md" data-end="1090" data-start="1075">Descripción</th></tr></thead><tbody data-end="1325" data-start="1137"><tr data-end="1243" data-start="1137"><td data-col-size="sm" data-end="1146" data-start="1137">`name`</td><td data-col-size="sm" data-end="1155" data-start="1146">string</td><td data-col-size="sm" data-end="1160" data-start="1155">✔️</td><td data-col-size="md" data-end="1243" data-start="1160">Identificador del documento del Doctype “Check List del Supervisor Nacional 2”.</td></tr><tr data-end="1325" data-start="1244"><td data-col-size="sm" data-end="1257" data-start="1244">`category`</td><td data-col-size="sm" data-end="1266" data-start="1257">string</td><td data-col-size="sm" data-end="1271" data-start="1266">✔️</td><td data-col-size="md" data-end="1325" data-start="1271">Nombre de la categoría (Section Break) a analizar.</td></tr></tbody></table>

</div></div>Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22name%22%3A-%22chk-sup-0"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHK-SUP-00045"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"category"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Gestión Documentaria"</span><span class="hljs-punctuation">}</span>`</div></div>---

# 🔐 Seguridad

Requiere autenticación ERP válida, manejada internamente por **ServiceErp()**.

---

# 🧠 Flujo del Servicio (Resumen)

1. **Validación de parámetros**  
    Si `name` o `category` vienen vacíos → error inmediato.
2. **Obtener estructura del Doctype**  
    GET `/resource/DocType/Check List del Supervisor Nacional 2`
    
    
    - Extrae los campos agrupados por sección (Section Break).
    - Identifica solo campos tipo **Check**.
3. **Agrupar preguntas por categoría**
    
    
    - Mapea `category` → lista de campos (fieldname → label).
4. **Construir lista total de fields para consultar sus valores**  
    Ejemplo:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`[<span class="hljs-string">"documentos_autoridades"</span>, <span class="hljs-string">"imagen_14"</span>, <span class="hljs-string">"comentario_14"</span>, ...]`</div></div>
5. **Consultar valores reales del registro**  
    GET `/resource/Check List del Supervisor Nacional 2?fields=[...]&filters=[["name","=",name]]`
6. **Clasificar por categoría**:
    
    
    - Si campo = `0` → **Incompleta**
    - Si campo = `1` → **Completa**
7. **Retornar solo la categoría solicitada.**

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Missing Questions"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"Incompletas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"Falta documento de autoridades"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"Informe integrado no subido"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"Completas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"Imagen de fachada"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"Checklist SST completado"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</div></div>---

# ❗ Posibles Errores

### 1. Parámetro vacío

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El campo name es obligatorio"</span><span class="hljs-punctuation">}</span>`</div></div>### 2. Error al consultar el DocType

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22value%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"value"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error al consultar"</span><span class="hljs-punctuation">}</span>`</div></div>### 3. Error consultando los valores del registro

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrio un error durante el proceso"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</div></div>---

# 📚 Estructuras utilizadas

### ✔️ Doctype: **Check List del Supervisor Nacional 2**

Campos relevantes:

<div class="_tableContainer_1rjym_1" id="bkmrk-tipo-uso-section-bre"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="3466" data-start="3233"><thead data-end="3247" data-start="3233"><tr data-end="3247" data-start="3233"><th data-col-size="sm" data-end="3240" data-start="3233">Tipo</th><th data-col-size="sm" data-end="3247" data-start="3240">Uso</th></tr></thead><tbody data-end="3466" data-start="3263"><tr data-end="3314" data-start="3263"><td data-col-size="sm" data-end="3279" data-start="3263">Section Break</td><td data-col-size="sm" data-end="3314" data-start="3279">Agrupar preguntas por categoría</td></tr><tr data-end="3356" data-start="3315"><td data-col-size="sm" data-end="3323" data-start="3315">Check</td><td data-col-size="sm" data-end="3356" data-start="3323">Representa preguntas de Sí/No</td></tr><tr data-end="3407" data-start="3357"><td data-col-size="sm" data-end="3364" data-start="3357">Data</td><td data-col-size="sm" data-end="3407" data-start="3364">*(comentado, no procesado actualmente)*</td></tr><tr data-end="3466" data-start="3408"><td data-col-size="sm" data-end="3423" data-start="3408">Attach Image</td><td data-col-size="sm" data-end="3466" data-start="3423">*(comentado, no procesado actualmente)*</td></tr></tbody></table>

</div></div>Ejemplo de estructura procesada:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-%22gesti%C3%B3n-documenta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`[  <span class="hljs-string">"Gestión Documentaria"</span> => [      <span class="hljs-string">"documentos_autoridades"</span> => <span class="hljs-string">"1. Documentos de autoridades"</span>,      <span class="hljs-string">"informativo_integrado"</span>  => <span class="hljs-string">"2. Informativo integrado"</span>,  ],  <span class="hljs-string">"Seguridad Operacional"</span> => [      <span class="hljs-string">"extintores"</span> => <span class="hljs-string">"1. Extintores en regla"</span>,  ]]`</div></div>---

# 🧠 Pseudocódigo Real

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-validate-name%2C-categ"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`validate name, categorydoctypeFields = GET DocType Check Listquestions = group fields by Section Break (only Check fields)allFields = extract all fieldnames used in questionsvalues = GET Check List record where name = request.nameFor each category:    For each field:        if value == 0 → add to Incompletas        if value == 1 → add to Completasreturn data of selected category`</div></div>

# Adjuntar imagen (1) - [uploadFileErp]

### 🧾 Descripción

Este servicio permite **subir un archivo al ERP** utilizando el endpoint interno `method/upload_file`.

Funciona enviando el archivo recibido desde el request PHP (`$_FILES["file"]`) mediante **cURL** hacia el servicio de carga del ERP y devuelve los metadatos del archivo subido:

- URL pública
- Fecha de creación
- Nombre del archivo
- Tamaño del archivo

Es un servicio auxiliar utilizado por funcionalidades que requieren cargar documentos o imágenes hacia el servidor del ERP.

---

# 🚀 Endpoint

### POST `/upload-file-erp`

📌 **Requiere enviar un archivo en el campo `file` del formulario.**

---

# 🔐 Seguridad

No utiliza el token del usuario.  
El servicio realiza la subida como **Guest**, usando los headers de cookie:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-cookie%3A-full_name%3Dgu"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-section">Cookie: full_name=Guest; sid=Guest; system_user=no; user_id=Guest; user_image=</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>➡️ Esto significa que la API de ERP ya está configurada para permitir carga de archivos desde clientes externos bajo permisos Guest.

---

# 🧠 Flujo del Servicio (resumen)

1. Captura el archivo enviado en `$_FILES["file"]`.
2. Crea un objeto `CURLFile` con:
    
    
    - ruta temporal (`tmp_name`)
    - tipo MIME
    - nombre original
3. Envía el archivo al endpoint:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /method/upload_file`</div></div>
4. Espera la respuesta del ERP.
5. Decodifica la respuesta JSON.
6. Retorna un objeto con:
    
    
    - url del archivo
    - fecha de creación
    - nombre
    - tamaño

---

# 📥 Request Body

Debe enviarse como `multipart/form-data`.

### Ejemplo (form-data):

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1779" data-start="1683"><thead data-end="1713" data-start="1683"><tr data-end="1713" data-start="1683"><th data-col-size="sm" data-end="1691" data-start="1683">Campo</th><th data-col-size="sm" data-end="1698" data-start="1691">Tipo</th><th data-col-size="sm" data-end="1713" data-start="1698">Descripción</th></tr></thead><tbody data-end="1779" data-start="1746"><tr data-end="1779" data-start="1746"><td data-col-size="sm" data-end="1753" data-start="1746">file</td><td data-col-size="sm" data-end="1760" data-start="1753">File</td><td data-col-size="sm" data-end="1779" data-start="1760">Archivo a subir</td></tr></tbody></table>

</div></div>Ejemplo en HTML:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%3Cform-method%3D%22post%22-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-tag"><<span class="hljs-name">form</span></span> <span class="hljs-attr">method</span>=<span class="hljs-string">"POST"</span> <span class="hljs-attr">enctype</span>=<span class="hljs-string">"multipart/form-data"</span>>   <span class="hljs-tag"><<span class="hljs-name">input</span></span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"file"</span>><span class="hljs-tag"></<span class="hljs-name">form</span></span>>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22url%22%3A-%22%2Ffiles%2Fdoc"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/documento.pdf"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-14 09:43:55.12893"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"file_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"documento.pdf"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"file_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">120394</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ Posibles Errores

### 1. Error al procesar el archivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22msn%22%3A-%22failed-to-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Failed to open stream..."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error en cURL

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22msn%22%3A-%22curl-error"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"cURL Error #:Timeout..."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. El ERP no devuelve estructura válida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22msn%22%3A-%22error-al-p"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al procesar respuesta del ERP"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 Estructura de respuesta del ERP

El ERP retorna algo como:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22message%22%3A-%7B-%22file"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"file_url"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"/files/image.png"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15 10:45:00.12584"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"file_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"image.png"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"file_size"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">48204</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-try%3A-file-%3D-new-curl"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`try:    file = new CURLFile(tmp, type, name)catch error:    return errorsend file to ERP via cURL → POST /method/upload_fileif error in curl:    return errorparse responsereturn {    url: response.message.file_url,    creation: response.message.creation,    file_name: response.message.file_name,    file_size: response.message.file_size}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Actualizar terminos de supervision (1) - [updatequestion]

## 🧾 Descripción

Actualiza los campos (preguntas) de un documento del Doctype **“Check List del Supervisor Nacional 2”** dentro del ERP, permitiendo modificar dinámicamente cualquier grupo de preguntas o valores enviados desde la aplicación.

El servicio **solo actualiza los campos enviados**, y valida previamente que realmente existan cambios antes de ejecutar la operación.

---

## 🚀 Endpoint

### **POST /updatequestion**

---

## 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22questions%22%3A-%22%7B..."><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"questions"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"{...}"</span><span class="hljs-punctuation">,</span>   <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHK-LIST-0001"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 📌 Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1040" data-start="754"><thead data-end="807" data-start="754"><tr data-end="807" data-start="754"><th data-col-size="sm" data-end="769" data-start="754">Campo</th><th data-col-size="sm" data-end="778" data-start="769">Tipo</th><th data-col-size="sm" data-end="792" data-start="778">Obligatorio</th><th data-col-size="md" data-end="807" data-start="792">Descripción</th></tr></thead><tbody data-end="1040" data-start="862"><tr data-end="954" data-start="862"><td data-col-size="sm" data-end="878" data-start="862">**questions**</td><td data-col-size="sm" data-end="906" data-start="878">string (JSON-stringified)</td><td data-col-size="sm" data-end="911" data-start="906">✔️</td><td data-col-size="md" data-end="954" data-start="911">Objeto JSON con los campos a modificar.</td></tr><tr data-end="1040" data-start="955"><td data-col-size="sm" data-end="971" data-start="955">**name**</td><td data-col-size="sm" data-end="980" data-start="971">string</td><td data-col-size="sm" data-end="985" data-start="980">✔️</td><td data-col-size="md" data-end="1040" data-start="985">ID del documento del check list que se actualizará.</td></tr></tbody></table>

</div></div>Ejemplo del campo **questions**:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22pregunta_1%22%3A-%22si%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"pregunta_1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pregunta_2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"NO"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"observacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Todo conforme"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🔐 Seguridad

Requiere autenticación interna mediante: `<span class="hljs-variable language_">$this</span>->general-><span class="hljs-title function_ invoke__">ServiceErp</span>(...)`

➡️ Se usa el token y contexto configurado internamente para comunicarse con el ERP.

---

## 🧠 Flujo del Servicio (resumen real)

1. **Valida parámetros obligatorios**  
    Si `questions` o `name` viene vacío, retorna error de validación.
2. **Valida que existan cambios reales**  
    Si `questions == '{}'`, se considera que no hubo modificación.
3. **Convierte a array el JSON recibido**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-variable">$questions</span> = <span class="hljs-title function_ invoke__">json_decode</span>(<span class="hljs-variable">$questionsForm</span>, <span class="hljs-literal">true</span>);`</div></div>
4. **Genera el payload a actualizar**  
    Todos los campos recibidos se envían directamente al ERP.
5. **Realiza la actualización mediante API ERP**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`PUT resource/Check List del Supervisor Nacional <span class="hljs-number">2</span>/{name}`</div></div>
6. **Retorna el resultado de la operación**

---

## 📤 Response 200 – Ejemplos

### ✅ Actualización correcta

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Actualizado Correctamente"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ⚠️ No hubo cambios enviados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usted no realizo ningun cambio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Error de validación

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El campo questions es obligatorio"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### ❌ Falla en el PUT

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al actualizar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## ❗ Posibles Errores

<div class="_tableContainer_1rjym_1" id="bkmrk-error-descripci%C3%B3n-pa"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2819" data-start="2485"><thead data-end="2508" data-start="2485"><tr data-end="2508" data-start="2485"><th data-col-size="sm" data-end="2493" data-start="2485">Error</th><th data-col-size="md" data-end="2508" data-start="2493">Descripción</th></tr></thead><tbody data-end="2819" data-start="2533"><tr data-end="2596" data-start="2533"><td data-col-size="sm" data-end="2557" data-start="2533">**Parámetros vacíos**</td><td data-col-size="md" data-end="2596" data-start="2557">Si `questions` o `name` está vacío.</td></tr><tr data-end="2652" data-start="2597"><td data-col-size="sm" data-end="2615" data-start="2597">**Sin cambios**</td><td data-col-size="md" data-end="2652" data-start="2615">Cuando el JSON está vacío (`{}`).</td></tr><tr data-end="2751" data-start="2653"><td data-col-size="sm" data-end="2672" data-start="2653">**Error en ERP**</td><td data-col-size="md" data-end="2751" data-start="2672">Si el PUT falla por permisos, campos inexistentes o problemas del servidor.</td></tr><tr data-end="2819" data-start="2752"><td data-col-size="sm" data-end="2775" data-start="2752">**Error inesperado**</td><td data-col-size="md" data-end="2819" data-start="2775">Respuesta falsa o nula desde ServiceErp.</td></tr></tbody></table>

</div></div>---

## 📚 Schemas (datos usados)

### ✔ Check List del Supervisor Nacional 2 (PUT)

Campos dinámicos según las preguntas.  
Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22pregunta_1%22%3A-%22si%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"pregunta_1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SI"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pregunta_2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"NO"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"observacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Correcto"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-questionsform-%3D-requ"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`questionsForm = request.questions<span class="hljs-type">name</span> = request.name<span class="hljs-keyword">if</span> questionsForm empty → <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> <span class="hljs-type">name</span> empty → <span class="hljs-keyword">return</span> error<span class="hljs-keyword">if</span> questionsForm == "{}" → <span class="hljs-keyword">return</span> "no hizo cambios"questions = decode(questionsForm)fields = questions<span class="hljs-keyword">update</span> = PUT /resource/<span class="hljs-keyword">Check</span> List del Supervisor Nacional <span class="hljs-number">2</span>/{<span class="hljs-type">name</span>} <span class="hljs-keyword">with</span> fields<span class="hljs-keyword">if</span> <span class="hljs-keyword">update</span> fails → <span class="hljs-keyword">return</span> error<span class="hljs-keyword">return</span> success`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# Módulo Auth

# Autenticacion por dos (1) - [generateCodeAuthenticator]

## 🧾 Descripción

Genera un **código de verificación de 6 dígitos** para un usuario y lo envía al servicio externo encargado del sistema de **autenticación de doble factor (2FA)**.

Este servicio:

1. Recibe el número de documento del usuario.
2. Genera un código aleatorio numérico de 6 dígitos.
3. Envía ese código al servicio `https://sistema.shalomcontrol.com/api/generate_code_two_factor`.
4. Devuelve la respuesta del servicio externo.

Es usado para validar la identidad del usuario durante procesos de autenticación reforzada.

---

## 🚀 Endpoint

**POST** `/generate-code-authenticator`

---

## 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22username%22%3A-%2212345"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1130" data-start="969"><thead data-end="1013" data-start="969"><tr data-end="1013" data-start="969"><th data-col-size="sm" data-end="977" data-start="969">Campo</th><th data-col-size="sm" data-end="984" data-start="977">Tipo</th><th data-col-size="sm" data-end="998" data-start="984">Obligatorio</th><th data-col-size="sm" data-end="1013" data-start="998">Descripción</th></tr></thead><tbody data-end="1130" data-start="1061"><tr data-end="1130" data-start="1061"><td data-col-size="sm" data-end="1074" data-start="1061">`username`</td><td data-col-size="sm" data-end="1083" data-start="1074">string</td><td data-col-size="sm" data-end="1088" data-start="1083">✔️</td><td data-col-size="sm" data-end="1130" data-start="1088">DNI, pasaporte o documento del usuario</td></tr></tbody></table>

</div></div>---

## 🔐 Seguridad

No requiere token del ERP.  
Sin embargo, el envío del código es gestionado mediante una llamada a un **servicio externo** con autenticación interna del cliente `Piero()`.

---

## 🧠 Flujo del Servicio (resumen real)

1. **Valida** que el request incluya `username`.
    
    
    - Si no existe, retorna error.
2. **Genera un código numérico aleatorio de 6 dígitos**, cada uno seleccionado de `"0123456789"`.
3. **Envía el código** al servicio:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attribute">POST</span> https://sistema.shalomcontrol.com/api/generate_code_two_factor`</div></div>Con los parámetros:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">document</span> = <username><span class="hljs-attr">code</span> = <<span class="hljs-number">6</span>-digit code>`</div></div>
4. **Recibe y retorna** la respuesta proporcionada por el servicio externo.
5. Si ocurre un error en la solicitud HTTP (BadResponseException), devuelve:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al enviar al servicio"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<detalle del error>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Código generado y enviado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"document"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12345678"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div></div>*(La estructura exacta depende del servicio externo `sistema.shalomcontrol.com`.)*

---

## ❗ Posibles Errores

### 1. Falta el número de documento

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Enviar numero de documento"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Error del servicio externo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error al enviar al servicio"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje del servidor externo>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Error inesperado (validación interna)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error inesperado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

## 📚 Código que genera el servicio (resumen simplificado)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if%28%21%24document%29-retur"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">if</span>(!<span class="hljs-variable">$document</span>) <span class="hljs-keyword">return</span> error;code = <span class="hljs-title function_ invoke__">random_numeric</span>(<span class="hljs-number">6</span>);POST https:<span class="hljs-comment">//sistema.shalomcontrol.com/api/generate_code_two_factor</span>{  document: <username>,  code: <<span class="hljs-number">6</span>-digit code>}<span class="hljs-keyword">return</span> response_from_service;`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>