# 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>